summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/mapedit/src/frame.cpp37
-rw-r--r--tools/mapedit/src/frame.h10
-rw-r--r--tools/mapedit/src/main.cpp4
3 files changed, 41 insertions, 10 deletions
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 @@
3#include "tile_widget.h" 3#include "tile_widget.h"
4#include <wx/splitter.h> 4#include <wx/splitter.h>
5#include "panel.h" 5#include "panel.h"
6#include <list>
7
8static std::list<wxWindow*> openWindows;
6 9
7enum { 10enum {
8 MENU_VIEW_ZOOM_IN, 11 MENU_VIEW_ZOOM_IN,
@@ -102,6 +105,8 @@ void MapeditFrame::OnExit(wxCloseEvent& event)
102 } 105 }
103 } 106 }
104 107
108 *closer = nullptr;
109
105 event.Skip(); 110 event.Skip();
106} 111}
107 112
@@ -122,8 +127,7 @@ void MapeditFrame::ZoomOut(wxCommandEvent& event)
122 127
123void MapeditFrame::OnNew(wxCommandEvent& event) 128void MapeditFrame::OnNew(wxCommandEvent& event)
124{ 129{
125 MapeditFrame* frame = new MapeditFrame(); 130 NewMap();
126 frame->Show(true);
127} 131}
128 132
129void MapeditFrame::OnOpen(wxCommandEvent& event) 133void MapeditFrame::OnOpen(wxCommandEvent& event)
@@ -134,9 +138,7 @@ void MapeditFrame::OnOpen(wxCommandEvent& event)
134 return; 138 return;
135 } 139 }
136 140
137 std::string filename = openFileDialog.GetPath().ToStdString(); 141 OpenMap(openFileDialog.GetPath().c_str());
138 MapeditFrame* frame = new MapeditFrame(Map(filename), filename);
139 frame->Show(true);
140} 142}
141 143
142void MapeditFrame::OnSave(wxCommandEvent& event) 144void MapeditFrame::OnSave(wxCommandEvent& event)
@@ -162,10 +164,33 @@ void MapeditFrame::OnClose(wxCommandEvent& event)
162 164
163void MapeditFrame::OnQuit(wxCommandEvent& event) 165void MapeditFrame::OnQuit(wxCommandEvent& event)
164{ 166{
165 // TODO 167 for (auto window : openWindows)
168 {
169 if (window != nullptr)
170 {
171 window->Close(false);
172 }
173 }
166} 174}
167 175
168void MapeditFrame::OnTitleChange(wxCommandEvent& event) 176void MapeditFrame::OnTitleChange(wxCommandEvent& event)
169{ 177{
170 map.setTitle(titleBox->GetLineText(0).ToStdString()); 178 map.setTitle(titleBox->GetLineText(0).ToStdString());
171} 179}
180
181void MapeditFrame::NewMap()
182{
183 LaunchWindow(Map(), "");
184}
185
186void MapeditFrame::OpenMap(const char* filename)
187{
188 LaunchWindow(Map(filename), filename);
189}
190
191void MapeditFrame::LaunchWindow(Map map, const char* filename)
192{
193 MapeditFrame* frame = new MapeditFrame(map, filename);
194 frame->closer = openWindows.insert(end(openWindows), frame);
195 frame->Show(true);
196}
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 @@
10#include "map.h" 10#include "map.h"
11#include "widget.h" 11#include "widget.h"
12#include "tile_widget.h" 12#include "tile_widget.h"
13#include <list>
13 14
14class MapeditFrame : public wxFrame { 15class MapeditFrame : public wxFrame {
15 public: 16 public:
16 MapeditFrame() : MapeditFrame(Map(), "") {} 17 MapeditFrame() {}
17 MapeditFrame(Map map, std::string filename); 18 MapeditFrame(Map map, std::string filename);
18 19
19 MapeditWidget* GetMapEditor(); 20 MapeditWidget* GetMapEditor();
21
22 static void NewMap();
23 static void OpenMap(const char* filename);
24
25 std::list<wxWindow*>::iterator closer;
20 26
21 private: 27 private:
28 static void LaunchWindow(Map map, const char* filename);
29
22 void ZoomIn(wxCommandEvent& event); 30 void ZoomIn(wxCommandEvent& event);
23 void ZoomOut(wxCommandEvent& event); 31 void ZoomOut(wxCommandEvent& event);
24 void OnNew(wxCommandEvent& event); 32 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()
18{ 18{
19 wxInitAllImageHandlers(); 19 wxInitAllImageHandlers();
20 20
21 MapeditFrame* frame = new MapeditFrame(); 21 MapeditFrame::NewMap();
22 SetTopWindow(frame);
23 frame->Show(true);
24 22
25 return true; 23 return true;
26} 24}