summary refs log tree commit diff stats
path: root/tools/mapedit/src/frame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mapedit/src/frame.cpp')
-rw-r--r--tools/mapedit/src/frame.cpp93
1 files changed, 88 insertions, 5 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 537cd16..3cd1c15 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp
@@ -6,18 +6,31 @@
6 6
7enum { 7enum {
8 MENU_VIEW_ZOOM_IN, 8 MENU_VIEW_ZOOM_IN,
9 MENU_VIEW_ZOOM_OUT 9 MENU_VIEW_ZOOM_OUT,
10 MENU_FILE_NEW,
11 MENU_FILE_OPEN,
12 MENU_FILE_SAVE,
13 MENU_FILE_CLOSE
10}; 14};
11 15
12wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) 16wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
13 EVT_MENU(wxID_EXIT, MapeditFrame::OnExit) 17 EVT_MENU(wxID_EXIT, MapeditFrame::OnQuit)
14 EVT_MENU(MENU_VIEW_ZOOM_IN, MapeditFrame::ZoomIn) 18 EVT_MENU(MENU_VIEW_ZOOM_IN, MapeditFrame::ZoomIn)
15 EVT_MENU(MENU_VIEW_ZOOM_OUT, MapeditFrame::ZoomOut) 19 EVT_MENU(MENU_VIEW_ZOOM_OUT, MapeditFrame::ZoomOut)
20 EVT_MENU(MENU_FILE_NEW, MapeditFrame::OnNew)
21 EVT_MENU(MENU_FILE_OPEN, MapeditFrame::OnOpen)
22 EVT_MENU(MENU_FILE_SAVE, MapeditFrame::OnSave)
23 EVT_MENU(MENU_FILE_CLOSE, MapeditFrame::OnClose)
24 EVT_CLOSE(MapeditFrame::OnExit)
16wxEND_EVENT_TABLE() 25wxEND_EVENT_TABLE()
17 26
18MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map) 27MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map), filename(filename)
19{ 28{
20 wxMenu* menuFile = new wxMenu; 29 wxMenu* menuFile = new wxMenu;
30 menuFile->Append(MENU_FILE_NEW, "New\tCtrl-N");
31 menuFile->Append(MENU_FILE_OPEN, "Open\tCtrl-O");
32 menuFile->Append(MENU_FILE_SAVE, "Save\tCtrl-S");
33 menuFile->Append(MENU_FILE_CLOSE, "Close\tCtrl-W");
21 menuFile->Append(wxID_EXIT); 34 menuFile->Append(wxID_EXIT);
22 35
23 wxMenu* menuView = new wxMenu; 36 wxMenu* menuView = new wxMenu;
@@ -54,9 +67,34 @@ MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPo
54 sizermain->SetSizeHints(this); 67 sizermain->SetSizeHints(this);
55} 68}
56 69
57void MapeditFrame::OnExit(wxCommandEvent& event) 70void MapeditFrame::OnExit(wxCloseEvent& event)
58{ 71{
59 Close(true); 72 if (event.CanVeto() && map.hasUnsavedChanges())
73 {
74 switch (wxMessageBox("Current map has unsaved changes. Save before closing?", "Please confirm", wxICON_QUESTION|wxYES_NO|wxCANCEL, this))
75 {
76 case wxYES:
77 if (filename == "")
78 {
79 wxFileDialog saveFileDialog(this, "Save map", "", "", "XML files (*.xml)|*.xml", wxFD_SAVE);
80 if (saveFileDialog.ShowModal() == wxID_CANCEL)
81 {
82 return;
83 }
84
85 filename = saveFileDialog.GetPath().ToStdString();
86 }
87
88 map.save(filename);
89 break;
90
91 case wxCANCEL:
92 event.Veto(true);
93 return;
94 }
95 }
96
97 event.Skip();
60} 98}
61 99
62MapeditWidget* MapeditFrame::GetMapEditor() 100MapeditWidget* MapeditFrame::GetMapEditor()
@@ -73,3 +111,48 @@ void MapeditFrame::ZoomOut(wxCommandEvent& event)
73{ 111{
74 mapEditor->ZoomOut(); 112 mapEditor->ZoomOut();
75} 113}
114
115void MapeditFrame::OnNew(wxCommandEvent& event)
116{
117 MapeditFrame* frame = new MapeditFrame();
118 frame->Show(true);
119}
120
121void MapeditFrame::OnOpen(wxCommandEvent& event)
122{
123 wxFileDialog openFileDialog(this, "Open map", "", "", "XML files (*.xml)|*.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
124 if (openFileDialog.ShowModal() == wxID_CANCEL)
125 {
126 return;
127 }
128
129 std::string filename = openFileDialog.GetPath().ToStdString();
130 MapeditFrame* frame = new MapeditFrame(Map(filename), filename);
131 frame->Show(true);
132}
133
134void MapeditFrame::OnSave(wxCommandEvent& event)
135{
136 if (filename == "")
137 {
138 wxFileDialog saveFileDialog(this, "Save map", "", "", "XML files (*.xml)|*.xml", wxFD_SAVE);
139 if (saveFileDialog.ShowModal() == wxID_CANCEL)
140 {
141 return;
142 }
143
144 filename = saveFileDialog.GetPath().ToStdString();
145 }
146
147 map.save(filename);
148}
149
150void MapeditFrame::OnClose(wxCommandEvent& event)
151{
152 Close(false);
153}
154
155void MapeditFrame::OnQuit(wxCommandEvent& event)
156{
157 // TODO
158}