diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-19 11:42:54 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-19 11:42:54 -0400 |
commit | 281bdf956a646fd8c9944e9a44f867c984792216 (patch) | |
tree | ba0297d2125ac22d22c873e012a8f0604e9e3a86 /tools/mapedit/src/frame.cpp | |
parent | 103587c2d5f9deb20e549a86cdf5023b429cc6a1 (diff) | |
download | therapy-281bdf956a646fd8c9944e9a44f867c984792216.tar.gz therapy-281bdf956a646fd8c9944e9a44f867c984792216.tar.bz2 therapy-281bdf956a646fd8c9944e9a44f867c984792216.zip |
Map editor can now edit properties for objects (breaks main game build)
Diffstat (limited to 'tools/mapedit/src/frame.cpp')
-rw-r--r-- | tools/mapedit/src/frame.cpp | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 06102f7..aad3294 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp | |||
@@ -2,6 +2,7 @@ | |||
2 | #include "mapselect_combo.h" | 2 | #include "mapselect_combo.h" |
3 | #include <wx/statline.h> | 3 | #include <wx/statline.h> |
4 | #include <list> | 4 | #include <list> |
5 | #include <wx/valgen.h> | ||
5 | #include <exception> | 6 | #include <exception> |
6 | #include <sstream> | 7 | #include <sstream> |
7 | #include "widget.h" | 8 | #include "widget.h" |
@@ -29,6 +30,7 @@ enum { | |||
29 | TOOL_FILE_SAVE, | 30 | TOOL_FILE_SAVE, |
30 | TOOL_MAP_ADD_ROOT, | 31 | TOOL_MAP_ADD_ROOT, |
31 | TOOL_MAP_ADD_CHILD, | 32 | TOOL_MAP_ADD_CHILD, |
33 | MAP_EDITOR_WIDGET, | ||
32 | MAP_EDITOR_NOTEBOOK, | 34 | MAP_EDITOR_NOTEBOOK, |
33 | MAP_EDITOR_TREE, | 35 | MAP_EDITOR_TREE, |
34 | MAP_TITLE_TEXTBOX, | 36 | MAP_TITLE_TEXTBOX, |
@@ -45,7 +47,10 @@ enum { | |||
45 | UPMAP_TYPE_CHOICE, | 47 | UPMAP_TYPE_CHOICE, |
46 | UPMAP_MAP_CHOICE, | 48 | UPMAP_MAP_CHOICE, |
47 | DOWNMAP_TYPE_CHOICE, | 49 | DOWNMAP_TYPE_CHOICE, |
48 | DOWNMAP_MAP_CHOICE | 50 | DOWNMAP_MAP_CHOICE, |
51 | ENTITY_EDITOR, | ||
52 | ENTITY_PROPERTY_EDITOR, | ||
53 | PROPERTY_EDITOR | ||
49 | }; | 54 | }; |
50 | 55 | ||
51 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | 56 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) |
@@ -87,6 +92,7 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | |||
87 | EVT_COMBOBOX_CLOSEUP(RIGHTMAP_MAP_CHOICE, MapeditFrame::OnSetRightmapMap) | 92 | EVT_COMBOBOX_CLOSEUP(RIGHTMAP_MAP_CHOICE, MapeditFrame::OnSetRightmapMap) |
88 | EVT_COMBOBOX_CLOSEUP(UPMAP_MAP_CHOICE, MapeditFrame::OnSetUpmapMap) | 93 | EVT_COMBOBOX_CLOSEUP(UPMAP_MAP_CHOICE, MapeditFrame::OnSetUpmapMap) |
89 | EVT_COMBOBOX_CLOSEUP(DOWNMAP_MAP_CHOICE, MapeditFrame::OnSetDownmapMap) | 94 | EVT_COMBOBOX_CLOSEUP(DOWNMAP_MAP_CHOICE, MapeditFrame::OnSetDownmapMap) |
95 | EVT_COMMAND(wxID_ANY, EVT_MAP_SELECTED_ENTITY, MapeditFrame::OnSelectEntity) | ||
90 | wxEND_EVENT_TABLE() | 96 | wxEND_EVENT_TABLE() |
91 | 97 | ||
92 | MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | 98 | MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") |
@@ -171,7 +177,7 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
171 | tileEditor = new TileWidget(notebook, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*6,TILE_HEIGHT*10*6)); | 177 | tileEditor = new TileWidget(notebook, wxID_ANY, 6, 6, wxPoint(0,0), wxSize(TILE_WIDTH*6*6,TILE_HEIGHT*10*6)); |
172 | notebook->AddPage(tileEditor, "Tile Chooser", false); | 178 | notebook->AddPage(tileEditor, "Tile Chooser", false); |
173 | 179 | ||
174 | mapEditor = new MapeditWidget(layout3, wxID_ANY, currentMap, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); | 180 | mapEditor = new MapeditWidget(layout3, MAP_EDITOR_WIDGET, currentMap, tileEditor, wxPoint(0,0), wxSize(GAME_WIDTH*2, GAME_HEIGHT*2)); |
175 | mapEditor->frame = this; | 181 | mapEditor->frame = this; |
176 | 182 | ||
177 | // Set up property editor | 183 | // Set up property editor |
@@ -181,7 +187,7 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
181 | 187 | ||
182 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); | 188 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); |
183 | 189 | ||
184 | startposLabel = new wxStaticText(propertyEditor, wxID_ANY, "Starting Position:"); | 190 | startposLabel = new wxStaticText(propertyEditor, PROPERTY_EDITOR, "Starting Position:"); |
185 | 191 | ||
186 | setStartposButton = new wxButton(propertyEditor, SET_STARTPOS_BUTTON, "Set Starting Position"); | 192 | setStartposButton = new wxButton(propertyEditor, SET_STARTPOS_BUTTON, "Set Starting Position"); |
187 | cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); | 193 | cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); |
@@ -264,7 +270,7 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
264 | propertySizer->SetSizeHints(propertyEditor); | 270 | propertySizer->SetSizeHints(propertyEditor); |
265 | 271 | ||
266 | // Set up entity editor | 272 | // Set up entity editor |
267 | wxPanel* entityEditor = new wxPanel(notebook, wxID_ANY); | 273 | wxPanel* entityEditor = new wxPanel(notebook, ENTITY_EDITOR); |
268 | notebook->AddPage(entityEditor, "Entity Manager", false); | 274 | notebook->AddPage(entityEditor, "Entity Manager", false); |
269 | 275 | ||
270 | wxStaticText* entityHeader = new wxStaticText(entityEditor, wxID_ANY, "Add Entity"); | 276 | wxStaticText* entityHeader = new wxStaticText(entityEditor, wxID_ANY, "Add Entity"); |
@@ -275,9 +281,9 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
275 | wxStaticText* entityTypeLabel = new wxStaticText(entityEditor, wxID_ANY, "Entity Type:"); | 281 | wxStaticText* entityTypeLabel = new wxStaticText(entityEditor, wxID_ANY, "Entity Type:"); |
276 | 282 | ||
277 | entityTypeBox = new wxChoice(entityEditor, wxID_ANY); | 283 | entityTypeBox = new wxChoice(entityEditor, wxID_ANY); |
278 | for (auto entry : MapObject::getAllObjects()) | 284 | for (auto& entry : MapObject::getAllObjects()) |
279 | { | 285 | { |
280 | entityTypeBox->Append(entry.second->getType(), entry.second.get()); | 286 | entityTypeBox->Append(entry.second.getName(), (void*) &entry.second); |
281 | } | 287 | } |
282 | 288 | ||
283 | addEntityButton = new wxButton(entityEditor, ADD_ENTITY_BUTTON, "Add Entity"); | 289 | addEntityButton = new wxButton(entityEditor, ADD_ENTITY_BUTTON, "Add Entity"); |
@@ -286,6 +292,8 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
286 | 292 | ||
287 | wxStaticText* entityInfoLabel = new wxStaticText(entityEditor, wxID_ANY, "Click and drag an entity to move it.\nRight click an entity to delete it."); | 293 | wxStaticText* entityInfoLabel = new wxStaticText(entityEditor, wxID_ANY, "Click and drag an entity to move it.\nRight click an entity to delete it."); |
288 | 294 | ||
295 | wxPanel* entityPropertyEditor = new wxPanel(entityEditor, ENTITY_PROPERTY_EDITOR); | ||
296 | |||
289 | wxBoxSizer* entitySizer = new wxBoxSizer(wxVERTICAL); | 297 | wxBoxSizer* entitySizer = new wxBoxSizer(wxVERTICAL); |
290 | entitySizer->Add(entityHeader, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | 298 | entitySizer->Add(entityHeader, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5); |
291 | wxBoxSizer* entitySizer1 = new wxBoxSizer(wxHORIZONTAL); | 299 | wxBoxSizer* entitySizer1 = new wxBoxSizer(wxHORIZONTAL); |
@@ -298,6 +306,12 @@ MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") | |||
298 | entitySizer->Add(entitySizer2, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | 306 | entitySizer->Add(entitySizer2, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); |
299 | entitySizer->Add(new wxStaticLine(entityEditor), 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | 307 | entitySizer->Add(new wxStaticLine(entityEditor), 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); |
300 | entitySizer->Add(entityInfoLabel, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); | 308 | entitySizer->Add(entityInfoLabel, 0, wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALL, 5); |
309 | entitySizer->Add(entityPropertyEditor, 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxALL, 5); | ||
310 | wxBoxSizer* entityPropertySizer = new wxBoxSizer(wxVERTICAL); | ||
311 | entityPropertySizer->Add(new wxStaticLine(entityPropertyEditor), 1, wxEXPAND, 0); | ||
312 | entityPropertyEditor->SetSizer(entityPropertySizer); | ||
313 | entityPropertySizer->SetSizeHints(entityPropertyEditor); | ||
314 | //entitySizer->Add(entityPropertySizer, 1, wxEXPAND, 0); | ||
301 | entityEditor->SetSizer(entitySizer); | 315 | entityEditor->SetSizer(entitySizer); |
302 | entitySizer->SetSizeHints(entityEditor); | 316 | entitySizer->SetSizeHints(entityEditor); |
303 | 317 | ||
@@ -840,6 +854,62 @@ void MapeditFrame::OnSetDownmapMap(wxCommandEvent&) | |||
840 | })); | 854 | })); |
841 | } | 855 | } |
842 | 856 | ||
857 | void MapeditFrame::OnSelectEntity(wxCommandEvent& event) | ||
858 | { | ||
859 | MapObjectEntry* entry = (MapObjectEntry*) event.GetClientData(); | ||
860 | wxPanel* entityPropertyEditor = (wxPanel*) wxWindow::FindWindowById(ENTITY_PROPERTY_EDITOR, this); | ||
861 | |||
862 | if (entry == nullptr) | ||
863 | { | ||
864 | entityPropertyEditor->GetSizer()->Clear(); | ||
865 | entityPropertyEditor->DestroyChildren(); | ||
866 | } else { | ||
867 | wxSizer* sizer = entityPropertyEditor->GetSizer(); | ||
868 | for (auto input : entry->getObject().getInputs()) | ||
869 | { | ||
870 | wxStaticText* inputText = new wxStaticText(entityPropertyEditor, wxID_ANY, input.second.name + ":"); | ||
871 | sizer->Add(inputText, 0, wxEXPAND | wxALIGN_LEFT | wxBOTTOM, 0); | ||
872 | |||
873 | MapObjectEntry::Item& item = entry->getItem(input.first); | ||
874 | |||
875 | wxWindow* inputObject = nullptr; | ||
876 | switch (input.second.type) | ||
877 | { | ||
878 | case MapObject::Input::Type::Choice: | ||
879 | { | ||
880 | UndoableChoice* thechoice = new UndoableChoice(entityPropertyEditor, wxID_ANY, this, wxDefaultPosition, wxDefaultSize, 0, NULL, 0, VariableChoiceValidator(*world, item), input.second.name); | ||
881 | int selected = 0; | ||
882 | for (auto choice : input.second.choices) | ||
883 | { | ||
884 | thechoice->Append(choice.second, (void*) choice.first); | ||
885 | |||
886 | if (item.intvalue == choice.first) | ||
887 | { | ||
888 | selected = thechoice->GetCount()-1; | ||
889 | } | ||
890 | } | ||
891 | |||
892 | thechoice->SetSelection(selected); | ||
893 | inputObject = thechoice; | ||
894 | break; | ||
895 | } | ||
896 | |||
897 | case MapObject::Input::Type::Slider: | ||
898 | { | ||
899 | if (item.intvalue < input.second.minvalue) item.intvalue = input.second.minvalue; | ||
900 | if (item.intvalue > input.second.maxvalue) item.intvalue = input.second.maxvalue; | ||
901 | inputObject = new UndoableSlider(entityPropertyEditor, wxID_ANY, this, item.intvalue, input.second.minvalue, input.second.maxvalue, wxDefaultPosition, wxDefaultSize, wxHORIZONTAL | wxSL_LABELS, SliderItemValidator(*world, item), input.second.name); | ||
902 | break; | ||
903 | } | ||
904 | } | ||
905 | |||
906 | sizer->Add(inputObject, 0, wxEXPAND | wxALIGN_LEFT | wxBOTTOM, 10); | ||
907 | } | ||
908 | |||
909 | entityPropertyEditor->Layout(); | ||
910 | } | ||
911 | } | ||
912 | |||
843 | void MapeditFrame::NewWorld() | 913 | void MapeditFrame::NewWorld() |
844 | { | 914 | { |
845 | LaunchWindow(new World()); | 915 | LaunchWindow(new World()); |