Reworked game board layout opening and its starting in MainFrame

This commit is contained in:
Dmitriy Shishkov 2022-05-26 22:45:26 +03:00
parent 7b436c15c4
commit 43c90fc63b
No known key found for this signature in database
GPG Key ID: 26720CB2A9608C97
2 changed files with 21 additions and 18 deletions

View File

@ -20,7 +20,8 @@ MainFrame::MainFrame()
panel = new GamePanel(this);
panel->SetFocus();
openLayout();
if (openLayout())
panel->Start(layoutPath, solveable);
}
void MainFrame::initMenu() {
@ -53,7 +54,8 @@ void MainFrame::bindMenu() {
}, IDM_Exit);
Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void {
openLayout();
if (openLayout())
panel->Start(layoutPath, solveable);
}, IDM_Open);
Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void {
@ -69,16 +71,14 @@ void MainFrame::bindMenu() {
}, IDM_Rules);
Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void {
if (layoutPath.IsEmpty())
openLayout();
else
if (!layoutPath.IsEmpty() || openLayout()) {
panel->Start(layoutPath, solveable);
Refresh();
Refresh();
}
}, IDM_New_Game);
Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void {
solveable = _.IsChecked();
Bind(wxEVT_MENU, [this](wxCommandEvent& evt) -> void {
solveable = evt.IsChecked();
}, IDM_Solveable);
Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void {
@ -90,13 +90,16 @@ void MainFrame::bindMenu() {
}, IDM_Reshuffle);
}
void MainFrame::openLayout() {
wxFileDialog openFileDlg(this, "Открыть карту", dataDirPath + wxFileName::GetPathSeparator() + _("layouts"), "Turtle.smlf", "Файлы Mahjong карт (*.smlf)|*.smlf", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
/**
* Shows a file opening dialog asking for .smlf file if succed, sets its path to layoutPath
* @return true if user have chosen a file, false if cancelled
*/
bool MainFrame::openLayout() {
wxFileDialog openFileDlg(this, _("Открыть карту"), dataDirPath + wxFileName::GetPathSeparator() + _("layouts"), _("Turtle.smlf"), _("Файлы Mahjong карт (*.smlf)|*.smlf"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDlg.ShowModal() == wxID_CANCEL)
return;
return false;
layoutPath = openFileDlg.GetPath();
panel->Start(layoutPath, solveable);
layoutPath = openFileDlg.GetPath();
return true;
}

View File

@ -18,14 +18,14 @@ private:
void initMenu();
void bindMenu();
void openLayout();
GamePanel *panel;
bool openLayout();
const wxString dataDirPath;
wxString layoutPath;
bool solveable = false;
bool solveable = false; // determites wether to generate solveable or completely random map
};
enum