diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-16 21:28:46 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-16 21:28:46 -0400 |
commit | 29f818c314f86f9a842840c20d9634f0711507a6 (patch) | |
tree | 46f6445f336cc2b7c5dfc64b6f99459a97a8bc03 /tools/mapedit/src/frame.cpp | |
parent | 8b61d93fc869ea39a78cdc134002ef11bf3e69d3 (diff) | |
download | therapy-29f818c314f86f9a842840c20d9634f0711507a6.tar.gz therapy-29f818c314f86f9a842840c20d9634f0711507a6.tar.bz2 therapy-29f818c314f86f9a842840c20d9634f0711507a6.zip |
Added tool to map editor to set game starting position
Diffstat (limited to 'tools/mapedit/src/frame.cpp')
-rw-r--r-- | tools/mapedit/src/frame.cpp | 120 |
1 files changed, 72 insertions, 48 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 94be15e..66775e1 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp | |||
@@ -6,6 +6,7 @@ | |||
6 | #include "panel.h" | 6 | #include "panel.h" |
7 | #include <list> | 7 | #include <list> |
8 | #include <exception> | 8 | #include <exception> |
9 | #include <sstream> | ||
9 | 10 | ||
10 | static std::list<wxWindow*> openWindows; | 11 | static std::list<wxWindow*> openWindows; |
11 | 12 | ||
@@ -27,7 +28,9 @@ enum { | |||
27 | MAP_EDITOR_TREE, | 28 | MAP_EDITOR_TREE, |
28 | MAP_TITLE_TEXTBOX, | 29 | MAP_TITLE_TEXTBOX, |
29 | ADD_ENTITY_BUTTON, | 30 | ADD_ENTITY_BUTTON, |
30 | CANCEL_ENTITY_BUTTON | 31 | CANCEL_ENTITY_BUTTON, |
32 | SET_STARTPOS_BUTTON, | ||
33 | CANCEL_STARTPOS_BUTTON | ||
31 | }; | 34 | }; |
32 | 35 | ||
33 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | 36 | wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) |
@@ -56,6 +59,8 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) | |||
56 | EVT_TEXT(MAP_TITLE_TEXTBOX, MapeditFrame::OnTitleChange) | 59 | EVT_TEXT(MAP_TITLE_TEXTBOX, MapeditFrame::OnTitleChange) |
57 | EVT_BUTTON(ADD_ENTITY_BUTTON, MapeditFrame::OnAddEntity) | 60 | EVT_BUTTON(ADD_ENTITY_BUTTON, MapeditFrame::OnAddEntity) |
58 | EVT_BUTTON(CANCEL_ENTITY_BUTTON, MapeditFrame::OnCancelAddEntity) | 61 | EVT_BUTTON(CANCEL_ENTITY_BUTTON, MapeditFrame::OnCancelAddEntity) |
62 | EVT_BUTTON(SET_STARTPOS_BUTTON, MapeditFrame::OnSetStartpos) | ||
63 | EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos) | ||
59 | wxEND_EVENT_TABLE() | 64 | wxEND_EVENT_TABLE() |
60 | 65 | ||
61 | MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*2+TILE_WIDTH*6*6+10+10+150, GAME_HEIGHT*3)) | 66 | MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*2+TILE_WIDTH*6*6+10+10+150, GAME_HEIGHT*3)) |
@@ -114,14 +119,27 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN | |||
114 | // Set up property editor | 119 | // Set up property editor |
115 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); | 120 | wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); |
116 | titleBox = new wxTextCtrl(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle()); | 121 | titleBox = new wxTextCtrl(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle()); |
122 | titleBox->SetMaxLength(40); | ||
117 | 123 | ||
118 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); | 124 | wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); |
119 | 125 | ||
126 | startposLabel = new wxStaticText(propertyEditor, wxID_ANY, "Starting Position:"); | ||
127 | SetStartposLabel(); | ||
128 | |||
129 | setStartposButton = new wxButton(propertyEditor, SET_STARTPOS_BUTTON, "Set Starting Position"); | ||
130 | cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); | ||
131 | cancelStartposButton->Disable(); | ||
132 | |||
120 | wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); | 133 | wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); |
121 | wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); | 134 | wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); |
122 | propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); | 135 | propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); |
123 | propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); | 136 | propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); |
124 | propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); | 137 | propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); |
138 | wxBoxSizer* propertySizer2 = new wxBoxSizer(wxHORIZONTAL); | ||
139 | propertySizer2->Add(startposLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); | ||
140 | propertySizer2->Add(setStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); | ||
141 | propertySizer2->Add(cancelStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); | ||
142 | propertySizer->Add(propertySizer2, 1, wxEXPAND | wxTOP, 10); | ||
125 | propertyEditor->SetSizer(propertySizer); | 143 | propertyEditor->SetSizer(propertySizer); |
126 | propertySizer->SetSizeHints(propertyEditor); | 144 | propertySizer->SetSizeHints(propertyEditor); |
127 | 145 | ||
@@ -386,22 +404,13 @@ void MapeditFrame::OnDidSelectMap(wxTreeEvent& event) | |||
386 | 404 | ||
387 | void MapeditFrame::OnWillSelectMap(wxTreeEvent& event) | 405 | void MapeditFrame::OnWillSelectMap(wxTreeEvent& event) |
388 | { | 406 | { |
389 | if (addingEntity) | ||
390 | { | ||
391 | event.Veto(); | ||
392 | return; | ||
393 | } | ||
394 | |||
395 | event.Skip(); | 407 | event.Skip(); |
396 | } | 408 | } |
397 | 409 | ||
398 | void MapeditFrame::OnWillDragMap(wxTreeEvent& event) | 410 | void MapeditFrame::OnWillDragMap(wxTreeEvent& event) |
399 | { | 411 | { |
400 | if (!addingEntity) | 412 | event.Allow(); |
401 | { | 413 | dragMap = event.GetItem(); |
402 | event.Allow(); | ||
403 | dragMap = event.GetItem(); | ||
404 | } | ||
405 | } | 414 | } |
406 | 415 | ||
407 | void MapeditFrame::OnDidDragMap(wxTreeEvent& event) | 416 | void MapeditFrame::OnDidDragMap(wxTreeEvent& event) |
@@ -430,6 +439,18 @@ void MapeditFrame::OnRightClickTree(wxTreeEvent& event) | |||
430 | } | 439 | } |
431 | } | 440 | } |
432 | 441 | ||
442 | void MapeditFrame::OnSetStartpos(wxCommandEvent&) | ||
443 | { | ||
444 | SetIsSettingStart(true); | ||
445 | mapEditor->SetIsSettingStart(true); | ||
446 | } | ||
447 | |||
448 | void MapeditFrame::OnCancelSetStartpos(wxCommandEvent&) | ||
449 | { | ||
450 | SetIsSettingStart(false); | ||
451 | mapEditor->SetIsSettingStart(false); | ||
452 | } | ||
453 | |||
433 | void MapeditFrame::NewWorld() | 454 | void MapeditFrame::NewWorld() |
434 | { | 455 | { |
435 | LaunchWindow(std::unique_ptr<World>(new World())); | 456 | LaunchWindow(std::unique_ptr<World>(new World())); |
@@ -459,43 +480,18 @@ void MapeditFrame::LaunchWindow(std::unique_ptr<World> world) | |||
459 | frame->Show(true); | 480 | frame->Show(true); |
460 | } | 481 | } |
461 | 482 | ||
462 | void MapeditFrame::StartAddingEntity() | 483 | void MapeditFrame::SetIsAddingEntity(bool isAddingEntity) |
463 | { | ||
464 | addingEntity = true; | ||
465 | addEntityButton->Disable(); | ||
466 | cancelEntityButton->Enable(); | ||
467 | |||
468 | toolbar->EnableTool(TOOL_FILE_NEW, false); | ||
469 | toolbar->EnableTool(TOOL_FILE_OPEN, false); | ||
470 | toolbar->EnableTool(TOOL_FILE_SAVE, false); | ||
471 | toolbar->EnableTool(TOOL_MAP_ADD_ROOT, false); | ||
472 | toolbar->EnableTool(TOOL_MAP_ADD_CHILD, false); | ||
473 | |||
474 | menuFile->Enable(MENU_FILE_NEW, false); | ||
475 | menuFile->Enable(MENU_FILE_OPEN, false); | ||
476 | menuFile->Enable(MENU_FILE_SAVE, false); | ||
477 | menuFile->Enable(MENU_MAP_ADD_ROOT, false); | ||
478 | menuFile->Enable(MENU_MAP_ADD_CHILD, false); | ||
479 | } | ||
480 | |||
481 | void MapeditFrame::FinishAddingEntity() | ||
482 | { | 484 | { |
483 | addingEntity = false; | 485 | if (isAddingEntity) |
484 | addEntityButton->Enable(); | 486 | { |
485 | cancelEntityButton->Disable(); | 487 | addingEntity = true; |
486 | toolbar->Enable(); | 488 | addEntityButton->Disable(); |
487 | 489 | cancelEntityButton->Enable(); | |
488 | toolbar->EnableTool(TOOL_FILE_NEW, true); | 490 | } else { |
489 | toolbar->EnableTool(TOOL_FILE_OPEN, true); | 491 | addingEntity = false; |
490 | toolbar->EnableTool(TOOL_FILE_SAVE, world->getDirty()); | 492 | addEntityButton->Enable(); |
491 | toolbar->EnableTool(TOOL_MAP_ADD_ROOT, true); | 493 | cancelEntityButton->Disable(); |
492 | toolbar->EnableTool(TOOL_MAP_ADD_CHILD, true); | 494 | } |
493 | |||
494 | menuFile->Enable(MENU_FILE_NEW, true); | ||
495 | menuFile->Enable(MENU_FILE_OPEN, true); | ||
496 | menuFile->Enable(MENU_FILE_SAVE, world->getDirty()); | ||
497 | menuFile->Enable(MENU_MAP_ADD_ROOT, true); | ||
498 | menuFile->Enable(MENU_MAP_ADD_CHILD, true); | ||
499 | } | 495 | } |
500 | 496 | ||
501 | void MapeditFrame::MapDirtyDidChange(bool dirty) | 497 | void MapeditFrame::MapDirtyDidChange(bool dirty) |
@@ -568,3 +564,31 @@ wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newPar | |||
568 | 564 | ||
569 | return copied; | 565 | return copied; |
570 | } | 566 | } |
567 | |||
568 | void MapeditFrame::SetIsSettingStart(bool isSettingStart) | ||
569 | { | ||
570 | if (isSettingStart) | ||
571 | { | ||
572 | setStartposButton->Disable(); | ||
573 | cancelStartposButton->Enable(); | ||
574 | } else { | ||
575 | SetStartposLabel(); | ||
576 | |||
577 | setStartposButton->Enable(); | ||
578 | cancelStartposButton->Disable(); | ||
579 | } | ||
580 | } | ||
581 | |||
582 | void MapeditFrame::SetStartposLabel() | ||
583 | { | ||
584 | std::ostringstream mappos_out; | ||
585 | mappos_out << "Starting Position: "; | ||
586 | mappos_out << world->getStartingMap()->getTitle(); | ||
587 | mappos_out << " ("; | ||
588 | mappos_out << (int) world->getStartingPosition().first; | ||
589 | mappos_out << ","; | ||
590 | mappos_out << (int) world->getStartingPosition().second; | ||
591 | mappos_out << ")"; | ||
592 | |||
593 | startposLabel->SetLabel(mappos_out.str()); | ||
594 | } | ||