diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-15 17:20:42 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-15 17:20:42 -0400 |
commit | 91640f2f35d703898edb14abaae7dd63f5346027 (patch) | |
tree | 35bdcfd4a61fa54f70c5b44d567a0fdd665e0129 /tools/mapedit/src/frame.cpp | |
parent | 3d24adb1162c4ce1b5030b73ea72873a2b14f6f9 (diff) | |
download | therapy-91640f2f35d703898edb14abaae7dd63f5346027.tar.gz therapy-91640f2f35d703898edb14abaae7dd63f5346027.tar.bz2 therapy-91640f2f35d703898edb14abaae7dd63f5346027.zip |
Added file management to map editor (only edits environment at current time)
Diffstat (limited to 'tools/mapedit/src/frame.cpp')
-rw-r--r-- | tools/mapedit/src/frame.cpp | 93 |
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 | ||
7 | enum { | 7 | enum { |
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 | ||
12 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | 16 | wxBEGIN_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) | ||
16 | wxEND_EVENT_TABLE() | 25 | wxEND_EVENT_TABLE() |
17 | 26 | ||
18 | MapeditFrame::MapeditFrame(Map map) : wxFrame(NULL, wxID_ANY, "Map Editor", wxPoint(50, 50), wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map) | 27 | MapeditFrame::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 | ||
57 | void MapeditFrame::OnExit(wxCommandEvent& event) | 70 | void 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 | ||
62 | MapeditWidget* MapeditFrame::GetMapEditor() | 100 | MapeditWidget* MapeditFrame::GetMapEditor() |
@@ -73,3 +111,48 @@ void MapeditFrame::ZoomOut(wxCommandEvent& event) | |||
73 | { | 111 | { |
74 | mapEditor->ZoomOut(); | 112 | mapEditor->ZoomOut(); |
75 | } | 113 | } |
114 | |||
115 | void MapeditFrame::OnNew(wxCommandEvent& event) | ||
116 | { | ||
117 | MapeditFrame* frame = new MapeditFrame(); | ||
118 | frame->Show(true); | ||
119 | } | ||
120 | |||
121 | void 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 | |||
134 | void 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 | |||
150 | void MapeditFrame::OnClose(wxCommandEvent& event) | ||
151 | { | ||
152 | Close(false); | ||
153 | } | ||
154 | |||
155 | void MapeditFrame::OnQuit(wxCommandEvent& event) | ||
156 | { | ||
157 | // TODO | ||
158 | } | ||