From dca2aea57957c6af1af535f23ae392e7517ebd51 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 15 Mar 2015 19:27:55 -0400 Subject: Fixed functionality of quit menu item in map editor --- tools/mapedit/src/frame.cpp | 37 +++++++++++++++++++++++++++++++------ tools/mapedit/src/frame.h | 10 +++++++++- tools/mapedit/src/main.cpp | 4 +--- 3 files changed, 41 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index b3808e2..e0df030 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp @@ -3,6 +3,9 @@ #include "tile_widget.h" #include #include "panel.h" +#include + +static std::list openWindows; enum { MENU_VIEW_ZOOM_IN, @@ -102,6 +105,8 @@ void MapeditFrame::OnExit(wxCloseEvent& event) } } + *closer = nullptr; + event.Skip(); } @@ -122,8 +127,7 @@ void MapeditFrame::ZoomOut(wxCommandEvent& event) void MapeditFrame::OnNew(wxCommandEvent& event) { - MapeditFrame* frame = new MapeditFrame(); - frame->Show(true); + NewMap(); } void MapeditFrame::OnOpen(wxCommandEvent& event) @@ -134,9 +138,7 @@ void MapeditFrame::OnOpen(wxCommandEvent& event) return; } - std::string filename = openFileDialog.GetPath().ToStdString(); - MapeditFrame* frame = new MapeditFrame(Map(filename), filename); - frame->Show(true); + OpenMap(openFileDialog.GetPath().c_str()); } void MapeditFrame::OnSave(wxCommandEvent& event) @@ -162,10 +164,33 @@ void MapeditFrame::OnClose(wxCommandEvent& event) void MapeditFrame::OnQuit(wxCommandEvent& event) { - // TODO + for (auto window : openWindows) + { + if (window != nullptr) + { + window->Close(false); + } + } } void MapeditFrame::OnTitleChange(wxCommandEvent& event) { map.setTitle(titleBox->GetLineText(0).ToStdString()); } + +void MapeditFrame::NewMap() +{ + LaunchWindow(Map(), ""); +} + +void MapeditFrame::OpenMap(const char* filename) +{ + LaunchWindow(Map(filename), filename); +} + +void MapeditFrame::LaunchWindow(Map map, const char* filename) +{ + MapeditFrame* frame = new MapeditFrame(map, filename); + frame->closer = openWindows.insert(end(openWindows), frame); + frame->Show(true); +} diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index 11990b1..5e119f3 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h @@ -10,15 +10,23 @@ #include "map.h" #include "widget.h" #include "tile_widget.h" +#include class MapeditFrame : public wxFrame { public: - MapeditFrame() : MapeditFrame(Map(), "") {} + MapeditFrame() {} MapeditFrame(Map map, std::string filename); MapeditWidget* GetMapEditor(); + + static void NewMap(); + static void OpenMap(const char* filename); + + std::list::iterator closer; private: + static void LaunchWindow(Map map, const char* filename); + void ZoomIn(wxCommandEvent& event); void ZoomOut(wxCommandEvent& event); void OnNew(wxCommandEvent& event); diff --git a/tools/mapedit/src/main.cpp b/tools/mapedit/src/main.cpp index cfc5a46..91dd98f 100644 --- a/tools/mapedit/src/main.cpp +++ b/tools/mapedit/src/main.cpp @@ -18,9 +18,7 @@ bool MapeditApp::OnInit() { wxInitAllImageHandlers(); - MapeditFrame* frame = new MapeditFrame(); - SetTopWindow(frame); - frame->Show(true); + MapeditFrame::NewMap(); return true; } -- cgit 1.4.1