diff --git a/MainFrame.cpp b/MainFrame.cpp index e907f2d..4e5318c 100644 --- a/MainFrame.cpp +++ b/MainFrame.cpp @@ -1,23 +1,31 @@ -#include "./MainFrame.h" +#include "MainFrame.h" -#include "./HelpDlg.h" -#include "./RulesDlg.h" -#include "./AboutDlg.h" +#include "HelpDlg.h" +#include "RulesDlg.h" +#include "AboutDlg.h" MainFrame::MainFrame() - : wxFrame(nullptr, wxID_ANY, _("Маджонг (пасьянс)")) + : wxFrame(nullptr, wxID_ANY, _("Маджонг (пасьянс)")), + dataDirPath(wxStandardPaths::Get().GetUserDataDir()) { InitMenu(); BindMenu(); + CreateStatusBar(); + panel = new GamePanel(this); panel->SetFocus(); panel->Start(); } +MainFrame::~MainFrame() { + delete panel; +} + void MainFrame::InitMenu() { wxMenu *menuGame = new wxMenu; menuGame->Append(IDM_New_Game, _("Начать сначала")); + menuGame->Append(IDM_Open, _("Открыть карту")); menuGame->AppendSeparator(); menuGame->Append(IDM_Exit, _("Выход")); @@ -38,6 +46,8 @@ void MainFrame::BindMenu() { Close(); }, IDM_Exit); + Bind(wxEVT_MENU, &MainFrame::OnOpen, this, IDM_Open); + Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void { (new HelpDlg(this, -1))->Show(); }, IDM_Help); @@ -54,3 +64,12 @@ void MainFrame::BindMenu() { panel->Start(); }, IDM_New_Game); } + +void MainFrame::OnOpen(wxCommandEvent& _) { + wxFileDialog openFileDlg(this, "Открыть карту", dataDirPath + wxFileName::GetPathSeparator() + _("layouts"), "Turtle.smlf", "Файлы Mahjong карт (*.smlf)|*.smlf", wxFD_OPEN | wxFD_FILE_MUST_EXIST); + + if (openFileDlg.ShowModal() == wxID_CANCEL) + return; + + GetStatusBar()->PushStatusText(openFileDlg.GetPath()); +} \ No newline at end of file diff --git a/MainFrame.h b/MainFrame.h index dbed839..df9ea5c 100644 --- a/MainFrame.h +++ b/MainFrame.h @@ -1,25 +1,34 @@ #ifndef MainFrame_H_ #define MainFrame_H_ -#include "./wxw.h" +#include "wxw.h" -#include "./GamePanel.h" +#include "GamePanel.h" + +#include +#include /// @uml{style[#line.dotted:blue]} class MainFrame : public wxFrame { public: MainFrame(); + ~MainFrame(); private: void InitMenu(); void BindMenu(); + void OnOpen(wxCommandEvent& _); + GamePanel *panel; + + const wxString dataDirPath; }; enum { + IDM_Open = wxID_OPEN, IDM_Exit = wxID_EXIT, IDM_Help = wxID_HELP, IDM_About = wxID_ABOUT,