summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/mapedit/CMakeLists.txt3
-rw-r--r--tools/mapedit/src/consts.h13
-rw-r--r--tools/mapedit/src/frame.cpp287
-rw-r--r--tools/mapedit/src/frame.h32
-rw-r--r--tools/mapedit/src/main.cpp1
-rw-r--r--tools/mapedit/src/map.cpp216
-rw-r--r--tools/mapedit/src/map.h72
-rw-r--r--tools/mapedit/src/mapselect_combo.cpp91
-rw-r--r--tools/mapedit/src/mapselect_combo.h36
-rw-r--r--tools/mapedit/src/tile_widget.cpp2
-rw-r--r--tools/mapedit/src/tile_widget.h2
-rw-r--r--tools/mapedit/src/widget.cpp4
-rw-r--r--tools/mapedit/src/widget.h8
-rw-r--r--tools/mapedit/src/world.cpp139
-rw-r--r--tools/mapedit/src/world.h2
15 files changed, 801 insertions, 107 deletions
diff --git a/tools/mapedit/CMakeLists.txt b/tools/mapedit/CMakeLists.txt index ca44fc5..b225834 100644 --- a/tools/mapedit/CMakeLists.txt +++ b/tools/mapedit/CMakeLists.txt
@@ -10,7 +10,7 @@ set(BIN_DIR ${AromatherapyMapEditor_SOURCE_DIR}/bin)
10# selecting the build mode in their IDE 10# selecting the build mode in their IDE
11if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 11if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
12 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11") 12 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11")
13 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g") 13 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
14 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2") 14 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2")
15elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") 15elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
16 if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 16 if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
@@ -46,6 +46,7 @@ add_executable(AromatherapyMapEditor
46 src/object.cpp 46 src/object.cpp
47 src/world.cpp 47 src/world.cpp
48 src/undo.cpp 48 src/undo.cpp
49 src/mapselect_combo.cpp
49) 50)
50target_link_libraries(AromatherapyMapEditor ${ALL_LIBS}) 51target_link_libraries(AromatherapyMapEditor ${ALL_LIBS})
51install(TARGETS AromatherapyMapEditor RUNTIME DESTINATION ${BIN_DIR}) 52install(TARGETS AromatherapyMapEditor RUNTIME DESTINATION ${BIN_DIR})
diff --git a/tools/mapedit/src/consts.h b/tools/mapedit/src/consts.h new file mode 100644 index 0000000..5e99136 --- /dev/null +++ b/tools/mapedit/src/consts.h
@@ -0,0 +1,13 @@
1#ifndef CONSTS_H
2#define CONSTS_H
3
4const int TILE_WIDTH = 8;
5const int TILE_HEIGHT = 8;
6const int GAME_WIDTH = 320;
7const int GAME_HEIGHT = 200;
8const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH;
9const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1;
10const int PLAYER_WIDTH[5] = {10, 0, 0, 0, 0};
11const int PLAYER_HEIGHT[5] = {12, 0, 0, 0, 0};
12
13#endif
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 2f85905..b8b4326 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp
@@ -1,11 +1,15 @@
1#include "frame.h" 1#include "frame.h"
2#include "widget.h" 2#include "mapselect_combo.h"
3#include "tile_widget.h"
4#include <wx/statline.h> 3#include <wx/statline.h>
5#include "panel.h"
6#include <list> 4#include <list>
7#include <exception> 5#include <exception>
8#include <sstream> 6#include <sstream>
7#include "widget.h"
8#include "tile_widget.h"
9#include "panel.h"
10#include "map.h"
11#include "undo.h"
12#include "object.h"
9 13
10static std::list<wxWindow*> openWindows; 14static std::list<wxWindow*> openWindows;
11 15
@@ -33,7 +37,15 @@ enum {
33 SET_STARTPOS_BUTTON, 37 SET_STARTPOS_BUTTON,
34 CANCEL_STARTPOS_BUTTON, 38 CANCEL_STARTPOS_BUTTON,
35 LAYOUT_ONE_SPLITTER, 39 LAYOUT_ONE_SPLITTER,
36 LAYOUT_THREE_SPLITTER 40 LAYOUT_THREE_SPLITTER,
41 LEFTMAP_TYPE_CHOICE,
42 LEFTMAP_MAP_CHOICE,
43 RIGHTMAP_TYPE_CHOICE,
44 RIGHTMAP_MAP_CHOICE,
45 UPMAP_TYPE_CHOICE,
46 UPMAP_MAP_CHOICE,
47 DOWNMAP_TYPE_CHOICE,
48 DOWNMAP_MAP_CHOICE
37}; 49};
38 50
39wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) 51wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
@@ -67,9 +79,17 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
67 EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos) 79 EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos)
68 EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_ONE_SPLITTER, MapeditFrame::OnOneMovingSash) 80 EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_ONE_SPLITTER, MapeditFrame::OnOneMovingSash)
69 EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_THREE_SPLITTER, MapeditFrame::OnThreeMovingSash) 81 EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_THREE_SPLITTER, MapeditFrame::OnThreeMovingSash)
82 EVT_CHOICE(LEFTMAP_TYPE_CHOICE, MapeditFrame::OnSetLeftmapType)
83 EVT_CHOICE(RIGHTMAP_TYPE_CHOICE, MapeditFrame::OnSetRightmapType)
84 EVT_CHOICE(UPMAP_TYPE_CHOICE, MapeditFrame::OnSetUpmapType)
85 EVT_CHOICE(DOWNMAP_TYPE_CHOICE, MapeditFrame::OnSetDownmapType)
86 EVT_COMBOBOX_CLOSEUP(LEFTMAP_MAP_CHOICE, MapeditFrame::OnSetLeftmapMap)
87 EVT_COMBOBOX_CLOSEUP(RIGHTMAP_MAP_CHOICE, MapeditFrame::OnSetRightmapMap)
88 EVT_COMBOBOX_CLOSEUP(UPMAP_MAP_CHOICE, MapeditFrame::OnSetUpmapMap)
89 EVT_COMBOBOX_CLOSEUP(DOWNMAP_MAP_CHOICE, MapeditFrame::OnSetDownmapMap)
70wxEND_EVENT_TABLE() 90wxEND_EVENT_TABLE()
71 91
72MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_ANY, "Map Editor") 92MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor")
73{ 93{
74 int screenWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X); 94 int screenWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
75 int screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y); 95 int screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
@@ -97,7 +117,7 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN
97 Maximize(); 117 Maximize();
98 } 118 }
99 119
100 this->world = std::move(world); 120 this->world = world;
101 this->world->setParent(this); 121 this->world->setParent(this);
102 currentMap = this->world->getLastMap(); 122 currentMap = this->world->getLastMap();
103 123
@@ -167,6 +187,34 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN
167 cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); 187 cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel");
168 cancelStartposButton->Disable(); 188 cancelStartposButton->Disable();
169 189
190 wxStaticText* leftmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Leftmap Action:");
191 wxChoice* leftmapChoice = new wxChoice(propertyEditor, LEFTMAP_TYPE_CHOICE);
192 wxComboCtrl* leftmapCombo = new wxComboCtrl(propertyEditor, LEFTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
193 leftmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getLeftMoveMapID()));
194
195 wxStaticText* rightmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Rightmap Action:");
196 wxChoice* rightmapChoice = new wxChoice(propertyEditor, RIGHTMAP_TYPE_CHOICE);
197 wxComboCtrl* rightmapCombo = new wxComboCtrl(propertyEditor, RIGHTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
198 rightmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getRightMoveMapID()));
199
200 wxStaticText* upmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Upmap Action:");
201 wxChoice* upmapChoice = new wxChoice(propertyEditor, UPMAP_TYPE_CHOICE);
202 wxComboCtrl* upmapCombo = new wxComboCtrl(propertyEditor, UPMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
203 upmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getUpMoveMapID()));
204
205 wxStaticText* downmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Downmap Action:");
206 wxChoice* downmapChoice = new wxChoice(propertyEditor, DOWNMAP_TYPE_CHOICE);
207 wxComboCtrl* downmapCombo = new wxComboCtrl(propertyEditor, DOWNMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
208 downmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getDownMoveMapID()));
209
210 for (auto type : Map::listMoveTypes())
211 {
212 leftmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type));
213 rightmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type));
214 upmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type));
215 downmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type));
216 }
217
170 wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); 218 wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL);
171 wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); 219 wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL);
172 propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); 220 propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10);
@@ -176,7 +224,42 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN
176 propertySizer2->Add(startposLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); 224 propertySizer2->Add(startposLabel, 0, wxALIGN_RIGHT | wxLEFT, 10);
177 propertySizer2->Add(setStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); 225 propertySizer2->Add(setStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10);
178 propertySizer2->Add(cancelStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); 226 propertySizer2->Add(cancelStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10);
179 propertySizer->Add(propertySizer2, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); 227 propertySizer->Add(propertySizer2, 0, wxEXPAND | wxTOP, 10);
228
229 wxBoxSizer* propertySizer3 = new wxBoxSizer(wxHORIZONTAL);
230 wxBoxSizer* leftmapSizer = new wxBoxSizer(wxHORIZONTAL);
231 leftmapSizer->Add(leftmapLabel, 0, wxALIGN_RIGHT, 0);
232 wxBoxSizer* leftmapToolsSizer = new wxBoxSizer(wxVERTICAL);
233 leftmapToolsSizer->Add(leftmapChoice, 0, wxEXPAND, 0);
234 leftmapToolsSizer->Add(leftmapCombo, 0, wxEXPAND | wxTOP, 10);
235 leftmapSizer->Add(leftmapToolsSizer, 1, wxEXPAND | wxLEFT, 10);
236 propertySizer3->Add(leftmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10);
237 wxBoxSizer* rightmapSizer = new wxBoxSizer(wxHORIZONTAL);
238 rightmapSizer->Add(rightmapLabel, 0, wxALIGN_RIGHT, 0);
239 wxBoxSizer* rightmapToolsSizer = new wxBoxSizer(wxVERTICAL);
240 rightmapToolsSizer->Add(rightmapChoice, 0, wxEXPAND, 0);
241 rightmapToolsSizer->Add(rightmapCombo, 0, wxEXPAND | wxTOP, 10);
242 rightmapSizer->Add(rightmapToolsSizer, 1, wxEXPAND | wxLEFT, 10);
243 propertySizer3->Add(rightmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10);
244 propertySizer->Add(propertySizer3, 0, wxEXPAND | wxTOP, 10);
245
246 wxBoxSizer* propertySizer4 = new wxBoxSizer(wxHORIZONTAL);
247 wxBoxSizer* upmapSizer = new wxBoxSizer(wxHORIZONTAL);
248 upmapSizer->Add(upmapLabel, 0, wxALIGN_RIGHT, 0);
249 wxBoxSizer* upmapToolsSizer = new wxBoxSizer(wxVERTICAL);
250 upmapToolsSizer->Add(upmapChoice, 0, wxEXPAND, 0);
251 upmapToolsSizer->Add(upmapCombo, 0, wxEXPAND | wxTOP, 10);
252 upmapSizer->Add(upmapToolsSizer, 1, wxEXPAND | wxLEFT, 10);
253 propertySizer4->Add(upmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10);
254 wxBoxSizer* downmapSizer = new wxBoxSizer(wxHORIZONTAL);
255 downmapSizer->Add(downmapLabel, 0, wxALIGN_RIGHT, 0);
256 wxBoxSizer* downmapToolsSizer = new wxBoxSizer(wxVERTICAL);
257 downmapToolsSizer->Add(downmapChoice, 0, wxEXPAND, 0);
258 downmapToolsSizer->Add(downmapCombo, 0, wxEXPAND | wxTOP, 10);
259 downmapSizer->Add(downmapToolsSizer, 1, wxEXPAND | wxLEFT, 10);
260 propertySizer4->Add(downmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10);
261 propertySizer->Add(propertySizer4, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
262
180 propertyEditor->SetSizer(propertySizer); 263 propertyEditor->SetSizer(propertySizer);
181 propertySizer->SetSizeHints(propertyEditor); 264 propertySizer->SetSizeHints(propertyEditor);
182 265
@@ -588,18 +671,174 @@ void MapeditFrame::OnThreeMovingSash(wxSplitterEvent& event)
588 layout3->SetSashPosition(event.GetSashPosition(), true); 671 layout3->SetSashPosition(event.GetSashPosition(), true);
589} 672}
590 673
674void MapeditFrame::OnSetLeftmapType(wxCommandEvent&)
675{
676 wxChoice* leftmapChoice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this);
677 wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this);
678
679 Map::MoveType old = currentMap->getLeftMoveType();
680 Map::MoveType newt = ((MoveTypeCtr*) leftmapChoice->GetClientData(leftmapChoice->GetSelection()))->type;
681
682 commitAction(std::make_shared<Undoable>("Set Leftmap Action", [=] () {
683 leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(newt)));
684 currentMap->setLeftMoveType(newt);
685 leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType()));
686 }, [=] () {
687 leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(old)));
688 currentMap->setLeftMoveType(old);
689 leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType()));
690 }));
691}
692
693void MapeditFrame::OnSetLeftmapMap(wxCommandEvent&)
694{
695 wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this);
696 MapSelectComboPopup* popup = (MapSelectComboPopup*) leftmapCombo->GetPopupControl();
697 int old = currentMap->getLeftMoveMapID();
698 int newt = popup->GetSelectedMapID();
699
700 if (old == newt) return;
701
702 commitAction(std::make_shared<Undoable>("Set Leftmap Map", [=] () {
703 popup->SetSelectedMapID(newt);
704 leftmapCombo->SetValue(world->getMap(newt)->getTitle());
705 currentMap->setLeftMoveMapID(newt);
706 }, [=] () {
707 popup->SetSelectedMapID(old);
708 leftmapCombo->SetValue(world->getMap(old)->getTitle());
709 currentMap->setLeftMoveMapID(old);
710 }));
711}
712
713void MapeditFrame::OnSetRightmapType(wxCommandEvent&)
714{
715 wxChoice* rightmapChoice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this);
716 wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this);
717
718 Map::MoveType old = currentMap->getRightMoveType();
719 Map::MoveType newt = ((MoveTypeCtr*) rightmapChoice->GetClientData(rightmapChoice->GetSelection()))->type;
720
721 commitAction(std::make_shared<Undoable>("Set Rightmap Action", [=] () {
722 rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(newt)));
723 currentMap->setRightMoveType(newt);
724 rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType()));
725 }, [=] () {
726 rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(old)));
727 currentMap->setRightMoveType(old);
728 rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType()));
729 }));
730}
731
732void MapeditFrame::OnSetRightmapMap(wxCommandEvent&)
733{
734 wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this);
735 MapSelectComboPopup* popup = (MapSelectComboPopup*) rightmapCombo->GetPopupControl();
736 int old = currentMap->getRightMoveMapID();
737 int newt = popup->GetSelectedMapID();
738
739 if (old == newt) return;
740
741 commitAction(std::make_shared<Undoable>("Set Rightmap Map", [=] () {
742 popup->SetSelectedMapID(newt);
743 rightmapCombo->SetValue(world->getMap(newt)->getTitle());
744 currentMap->setRightMoveMapID(newt);
745 }, [=] () {
746 popup->SetSelectedMapID(old);
747 rightmapCombo->SetValue(world->getMap(old)->getTitle());
748 currentMap->setRightMoveMapID(old);
749 }));
750}
751
752void MapeditFrame::OnSetUpmapType(wxCommandEvent&)
753{
754 wxChoice* upmapChoice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this);
755 wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this);
756
757 Map::MoveType old = currentMap->getUpMoveType();
758 Map::MoveType newt = ((MoveTypeCtr*) upmapChoice->GetClientData(upmapChoice->GetSelection()))->type;
759
760 commitAction(std::make_shared<Undoable>("Set Upmap Action", [=] () {
761 upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(newt)));
762 currentMap->setUpMoveType(newt);
763 upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType()));
764 }, [=] () {
765 upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(old)));
766 currentMap->setUpMoveType(old);
767 upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType()));
768 }));
769}
770
771void MapeditFrame::OnSetUpmapMap(wxCommandEvent&)
772{
773 wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this);
774 MapSelectComboPopup* popup = (MapSelectComboPopup*) upmapCombo->GetPopupControl();
775 int old = currentMap->getUpMoveMapID();
776 int newt = popup->GetSelectedMapID();
777
778 if (old == newt) return;
779
780 commitAction(std::make_shared<Undoable>("Set Upmap Map", [=] () {
781 popup->SetSelectedMapID(newt);
782 upmapCombo->SetValue(world->getMap(newt)->getTitle());
783 currentMap->setUpMoveMapID(newt);
784 }, [=] () {
785 popup->SetSelectedMapID(old);
786 upmapCombo->SetValue(world->getMap(old)->getTitle());
787 currentMap->setUpMoveMapID(old);
788 }));
789}
790
791void MapeditFrame::OnSetDownmapType(wxCommandEvent&)
792{
793 wxChoice* downmapChoice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this);
794 wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this);
795
796 Map::MoveType old = currentMap->getDownMoveType();
797 Map::MoveType newt = ((MoveTypeCtr*) downmapChoice->GetClientData(downmapChoice->GetSelection()))->type;
798
799 commitAction(std::make_shared<Undoable>("Set Downmap Action", [=] () {
800 downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(newt)));
801 currentMap->setDownMoveType(newt);
802 downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType()));
803 }, [=] () {
804 downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(old)));
805 currentMap->setDownMoveType(old);
806 downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType()));
807 }));
808}
809
810void MapeditFrame::OnSetDownmapMap(wxCommandEvent&)
811{
812 wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this);
813 MapSelectComboPopup* popup = (MapSelectComboPopup*) downmapCombo->GetPopupControl();
814 int old = currentMap->getDownMoveMapID();
815 int newt = popup->GetSelectedMapID();
816
817 if (old == newt) return;
818
819 commitAction(std::make_shared<Undoable>("Set Downmap Map", [=] () {
820 popup->SetSelectedMapID(newt);
821 downmapCombo->SetValue(world->getMap(newt)->getTitle());
822 currentMap->setDownMoveMapID(newt);
823 }, [=] () {
824 popup->SetSelectedMapID(old);
825 downmapCombo->SetValue(world->getMap(old)->getTitle());
826 currentMap->setDownMoveMapID(old);
827 }));
828}
829
591void MapeditFrame::NewWorld() 830void MapeditFrame::NewWorld()
592{ 831{
593 LaunchWindow(std::unique_ptr<World>(new World())); 832 LaunchWindow(new World());
594} 833}
595 834
596bool MapeditFrame::OpenWorld(std::string filename) 835bool MapeditFrame::OpenWorld(std::string filename)
597{ 836{
598 try 837 try
599 { 838 {
600 auto world = std::unique_ptr<World>(new World(filename)); 839 auto world = new World(filename);
601 840
602 LaunchWindow(std::move(world)); 841 LaunchWindow(world);
603 842
604 return true; 843 return true;
605 } catch (std::exception& ex) 844 } catch (std::exception& ex)
@@ -610,9 +849,9 @@ bool MapeditFrame::OpenWorld(std::string filename)
610 return false; 849 return false;
611} 850}
612 851
613void MapeditFrame::LaunchWindow(std::unique_ptr<World> world) 852void MapeditFrame::LaunchWindow(World* world)
614{ 853{
615 MapeditFrame* frame = new MapeditFrame(std::move(world)); 854 MapeditFrame* frame = new MapeditFrame(world);
616 frame->closer = openWindows.insert(end(openWindows), frame); 855 frame->closer = openWindows.insert(end(openWindows), frame);
617 frame->Show(true); 856 frame->Show(true);
618} 857}
@@ -674,6 +913,30 @@ void MapeditFrame::SelectMap(Map* map)
674 913
675 titleBox->ChangeValue(map->getTitle()); 914 titleBox->ChangeValue(map->getTitle());
676 world->setLastMap(map); 915 world->setLastMap(map);
916
917 wxChoice* leftmapChoice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this);
918 wxChoice* rightmapChoice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this);
919 wxChoice* upmapChoice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this);
920 wxChoice* downmapChoice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this);
921 wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this);
922 wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this);
923 wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this);
924 wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this);
925
926 leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(currentMap->getLeftMoveType())));
927 rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(currentMap->getRightMoveType())));
928 upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(currentMap->getUpMoveType())));
929 downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(currentMap->getDownMoveType())));
930
931 leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType()));
932 rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType()));
933 upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType()));
934 downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType()));
935
936 leftmapCombo->SetValue(world->getMap(currentMap->getLeftMoveMapID())->getTitle());
937 rightmapCombo->SetValue(world->getMap(currentMap->getRightMoveMapID())->getTitle());
938 upmapCombo->SetValue(world->getMap(currentMap->getUpMoveMapID())->getTitle());
939 downmapCombo->SetValue(world->getMap(currentMap->getDownMoveMapID())->getTitle());
677} 940}
678 941
679wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent) 942wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent)
diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index d201e86..dd8424c 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h
@@ -7,27 +7,25 @@
7#include <wx/wx.h> 7#include <wx/wx.h>
8#endif 8#endif
9 9
10#include "map.h"
11#include "widget.h"
12#include "tile_widget.h"
13#include <list> 10#include <list>
14#include <wx/notebook.h> 11#include <wx/notebook.h>
15#include <memory> 12#include <memory>
16#include <wx/treectrl.h> 13#include <wx/treectrl.h>
17#include <wx/splitter.h> 14#include <wx/splitter.h>
18#include "undo.h"
19 15
20class MapPtrCtr : public wxTreeItemData { 16class Map;
21 public: 17class MapeditWidget;
22 Map* map; 18class TileWidget;
23 19class Undoable;
24 MapPtrCtr(Map* map) : map(map) {} 20class UndoableTextBox;
25}; 21
22#include "world.h"
26 23
27class MapeditFrame : public wxFrame { 24class MapeditFrame : public wxFrame {
28 public: 25 public:
29 MapeditFrame() {} 26 MapeditFrame() {}
30 MapeditFrame(std::unique_ptr<World> world); 27 MapeditFrame(World* world);
28 ~MapeditFrame() { delete world; }
31 29
32 MapeditWidget* GetMapEditor(); 30 MapeditWidget* GetMapEditor();
33 void SetIsAddingEntity(bool isAddingEntity); 31 void SetIsAddingEntity(bool isAddingEntity);
@@ -39,7 +37,7 @@ class MapeditFrame : public wxFrame {
39 37
40 std::list<wxWindow*>::iterator closer; 38 std::list<wxWindow*>::iterator closer;
41 39
42 static void LaunchWindow(std::unique_ptr<World> world); 40 static void LaunchWindow(World* world);
43 void populateMapTree(wxTreeItemId node, std::list<std::shared_ptr<Map>> maps); 41 void populateMapTree(wxTreeItemId node, std::list<std::shared_ptr<Map>> maps);
44 void SelectMap(Map* map); 42 void SelectMap(Map* map);
45 wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent); 43 wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent);
@@ -68,8 +66,16 @@ class MapeditFrame : public wxFrame {
68 void OnCancelSetStartpos(wxCommandEvent& event); 66 void OnCancelSetStartpos(wxCommandEvent& event);
69 void OnOneMovingSash(wxSplitterEvent& event); 67 void OnOneMovingSash(wxSplitterEvent& event);
70 void OnThreeMovingSash(wxSplitterEvent& event); 68 void OnThreeMovingSash(wxSplitterEvent& event);
69 void OnSetLeftmapType(wxCommandEvent& event);
70 void OnSetLeftmapMap(wxCommandEvent& event);
71 void OnSetRightmapType(wxCommandEvent& event);
72 void OnSetRightmapMap(wxCommandEvent& event);
73 void OnSetUpmapType(wxCommandEvent& event);
74 void OnSetUpmapMap(wxCommandEvent& event);
75 void OnSetDownmapType(wxCommandEvent& event);
76 void OnSetDownmapMap(wxCommandEvent& event);
71 77
72 std::unique_ptr<World> world; 78 World* world;
73 Map* currentMap; 79 Map* currentMap;
74 80
75 MapeditWidget* mapEditor; 81 MapeditWidget* mapEditor;
diff --git a/tools/mapedit/src/main.cpp b/tools/mapedit/src/main.cpp index b09ee9a..6220562 100644 --- a/tools/mapedit/src/main.cpp +++ b/tools/mapedit/src/main.cpp
@@ -4,7 +4,6 @@
4#include <wx/wx.h> 4#include <wx/wx.h>
5#endif 5#endif
6 6
7#include "map.h"
8#include "frame.h" 7#include "frame.h"
9 8
10class MapeditApp : public wxApp { 9class MapeditApp : public wxApp {
diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 0db7031..fb675e8 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp
@@ -1,5 +1,8 @@
1#include "map.h" 1#include "map.h"
2#include "frame.h" 2#include "frame.h"
3#include "object.h"
4#include "world.h"
5#include "consts.h"
3 6
4Map::Map(int id, World* world) : id(id), world(world) 7Map::Map(int id, World* world) : id(id), world(world)
5{ 8{
@@ -13,13 +16,19 @@ Map::Map(const Map& map)
13 16
14 id = map.id; 17 id = map.id;
15 title = map.title; 18 title = map.title;
16 leftmap = map.leftmap;
17 rightmap = map.rightmap;
18 objects = map.objects; 19 objects = map.objects;
19 world = map.world; 20 world = map.world;
20 treeItemId = map.treeItemId; 21 treeItemId = map.treeItemId;
21 children = map.children; 22 children = map.children;
22 hidden = map.hidden; 23 hidden = map.hidden;
24 leftType = map.leftType;
25 rightType = map.rightType;
26 upType = map.upType;
27 downType = map.downType;
28 leftMap = map.leftMap;
29 rightMap = map.rightMap;
30 downMap = map.downMap;
31 upMap = map.upMap;
23} 32}
24 33
25Map::Map(Map&& map) : Map(-1, map.world) 34Map::Map(Map&& map) : Map(-1, map.world)
@@ -43,14 +52,67 @@ void swap(Map& first, Map& second)
43{ 52{
44 std::swap(first.mapdata, second.mapdata); 53 std::swap(first.mapdata, second.mapdata);
45 std::swap(first.title, second.title); 54 std::swap(first.title, second.title);
46 std::swap(first.leftmap, second.leftmap);
47 std::swap(first.rightmap, second.rightmap);
48 std::swap(first.objects, second.objects); 55 std::swap(first.objects, second.objects);
49 std::swap(first.id, second.id); 56 std::swap(first.id, second.id);
50 std::swap(first.world, second.world); 57 std::swap(first.world, second.world);
51 std::swap(first.treeItemId, second.treeItemId); 58 std::swap(first.treeItemId, second.treeItemId);
52 std::swap(first.children, second.children); 59 std::swap(first.children, second.children);
53 std::swap(first.hidden, second.hidden); 60 std::swap(first.hidden, second.hidden);
61 std::swap(first.leftType, second.leftType);
62 std::swap(first.rightType, second.rightType);
63 std::swap(first.upType, second.upType);
64 std::swap(first.downType, second.downType);
65 std::swap(first.leftMap, second.leftMap);
66 std::swap(first.rightMap, second.rightMap);
67 std::swap(first.downMap, second.downMap);
68 std::swap(first.upMap, second.upMap);
69}
70
71std::list<Map::MoveType> Map::listMoveTypes()
72{
73 return {MoveType::Wall, MoveType::Wrap, MoveType::Warp, MoveType::ReverseWarp};
74}
75
76std::string Map::stringForMoveType(MoveType type)
77{
78 switch (type)
79 {
80 case MoveType::Wall: return "Wall";
81 case MoveType::Warp: return "Warp";
82 case MoveType::Wrap: return "Wrap";
83 case MoveType::ReverseWarp: return "Reverse Warp";
84 }
85}
86
87bool Map::moveTypeTakesMap(MoveType type)
88{
89 switch (type)
90 {
91 case MoveType::Wall: return false;
92 case MoveType::Wrap: return false;
93 case MoveType::Warp: return true;
94 case MoveType::ReverseWarp: return true;
95 }
96}
97
98std::string Map::shortForMoveType(MoveType type)
99{
100 switch (type)
101 {
102 case MoveType::Wall: return "wall";
103 case MoveType::Wrap: return "wrap";
104 case MoveType::Warp: return "warp";
105 case MoveType::ReverseWarp: return "reverseWarp";
106 }
107}
108
109Map::MoveType Map::moveTypeForShort(std::string str)
110{
111 if (str == "wrap") return MoveType::Wrap;
112 if (str == "warp") return MoveType::Warp;
113 if (str == "reverseWarp") return MoveType::ReverseWarp;
114
115 return MoveType::Wall;
54} 116}
55 117
56int Map::getID() const 118int Map::getID() const
@@ -73,26 +135,6 @@ const std::list<std::shared_ptr<MapObjectEntry>>& Map::getObjects() const
73 return objects; 135 return objects;
74} 136}
75 137
76std::shared_ptr<Map> Map::getLeftmap() const
77{
78 if (leftmap == -1)
79 {
80 return std::shared_ptr<Map>();
81 } else {
82 return world->getMap(leftmap);
83 }
84}
85
86std::shared_ptr<Map> Map::getRightmap() const
87{
88 if (rightmap == -1)
89 {
90 return std::shared_ptr<Map>();
91 } else {
92 return world->getMap(rightmap);
93 }
94}
95
96wxTreeItemId Map::getTreeItemId() const 138wxTreeItemId Map::getTreeItemId() const
97{ 139{
98 return treeItemId; 140 return treeItemId;
@@ -125,6 +167,47 @@ bool Map::getHidden() const
125 return hidden; 167 return hidden;
126} 168}
127 169
170Map::MoveType Map::getLeftMoveType() const
171{
172 return leftType;
173}
174
175Map::MoveType Map::getRightMoveType() const
176{
177 return rightType;
178}
179
180Map::MoveType Map::getUpMoveType() const
181{
182 return upType;
183}
184
185Map::MoveType Map::getDownMoveType() const
186{
187 return downType;
188}
189
190int Map::getLeftMoveMapID() const
191{
192 return leftMap;
193}
194
195int Map::getRightMoveMapID() const
196{
197 return rightMap;
198}
199
200int Map::getUpMoveMapID() const
201{
202 return upMap;
203}
204
205int Map::getDownMoveMapID() const
206{
207 return downMap;
208}
209
210
128void Map::setTitle(std::string title, bool dirty) 211void Map::setTitle(std::string title, bool dirty)
129{ 212{
130 this->title = title; 213 this->title = title;
@@ -176,9 +259,39 @@ void Map::removeObject(std::shared_ptr<MapObjectEntry> obj, bool dirty)
176 } 259 }
177} 260}
178 261
179void Map::setLeftmap(int id, bool dirty) 262void Map::setTreeItemId(wxTreeItemId id)
263{
264 this->treeItemId = id;
265}
266
267void Map::addChild(int id)
268{
269 children.push_back(id);
270}
271
272void Map::setExpanded(bool exp)
273{
274 expanded = exp;
275}
276
277void Map::setHidden(bool hid)
278{
279 hidden = hid;
280}
281
282void Map::setLeftMoveType(Map::MoveType move, bool dirty)
283{
284 leftType = move;
285
286 if (dirty)
287 {
288 world->setDirty(true);
289 }
290}
291
292void Map::setRightMoveType(Map::MoveType move, bool dirty)
180{ 293{
181 leftmap = id; 294 rightType = move;
182 295
183 if (dirty) 296 if (dirty)
184 { 297 {
@@ -186,9 +299,9 @@ void Map::setLeftmap(int id, bool dirty)
186 } 299 }
187} 300}
188 301
189void Map::setRightmap(int id, bool dirty) 302void Map::setUpMoveType(Map::MoveType move, bool dirty)
190{ 303{
191 rightmap = id; 304 upType = move;
192 305
193 if (dirty) 306 if (dirty)
194 { 307 {
@@ -196,22 +309,53 @@ void Map::setRightmap(int id, bool dirty)
196 } 309 }
197} 310}
198 311
199void Map::setTreeItemId(wxTreeItemId id) 312void Map::setDownMoveType(Map::MoveType move, bool dirty)
200{ 313{
201 this->treeItemId = id; 314 downType = move;
315
316 if (dirty)
317 {
318 world->setDirty(true);
319 }
202} 320}
203 321
204void Map::addChild(int id) 322void Map::setLeftMoveMapID(int id, bool dirty)
205{ 323{
206 children.push_back(id); 324 leftMap = id;
325
326 if (dirty)
327 {
328 world->setDirty(true);
329 }
207} 330}
208 331
209void Map::setExpanded(bool exp) 332void Map::setRightMoveMapID(int id, bool dirty)
210{ 333{
211 expanded = exp; 334 rightMap = id;
335
336 if (dirty)
337 {
338 world->setDirty(true);
339 }
212} 340}
213 341
214void Map::setHidden(bool hid) 342void Map::setUpMoveMapID(int id, bool dirty)
215{ 343{
216 hidden = hid; 344 upMap = id;
345
346 if (dirty)
347 {
348 world->setDirty(true);
349 }
217} 350}
351
352void Map::setDownMoveMapID(int id, bool dirty)
353{
354 downMap = id;
355
356 if (dirty)
357 {
358 world->setDirty(true);
359 }
360}
361
diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 34dcb33..46e5790 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h
@@ -1,28 +1,17 @@
1#ifndef MAP_H 1#ifndef MAP_H
2#define MAP_H 2#define MAP_H
3 3
4class Map;
5
6#include <string> 4#include <string>
7#include <exception> 5#include <exception>
8#include <utility> 6#include <utility>
9#include <list> 7#include <list>
10#include "object.h"
11#include <memory> 8#include <memory>
12#include "world.h"
13#include <wx/treectrl.h> 9#include <wx/treectrl.h>
14 10
11class MapObject;
12class World;
15class MapeditFrame; 13class MapeditFrame;
16 14
17const int TILE_WIDTH = 8;
18const int TILE_HEIGHT = 8;
19const int GAME_WIDTH = 320;
20const int GAME_HEIGHT = 200;
21const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH;
22const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1;
23const int PLAYER_WIDTH[5] = {10, 0, 0, 0, 0};
24const int PLAYER_HEIGHT[5] = {12, 0, 0, 0, 0};
25
26class MapLoadException: public std::exception 15class MapLoadException: public std::exception
27{ 16{
28 public: 17 public:
@@ -75,29 +64,54 @@ class Map {
75 Map& operator= (Map other); 64 Map& operator= (Map other);
76 friend void swap(Map& first, Map& second); 65 friend void swap(Map& first, Map& second);
77 66
67 enum class MoveType {
68 Wall,
69 Wrap,
70 Warp,
71 ReverseWarp
72 };
73
74 static std::list<MoveType> listMoveTypes();
75 static std::string stringForMoveType(MoveType type);
76 static bool moveTypeTakesMap(MoveType type);
77 static std::string shortForMoveType(MoveType type);
78 static MoveType moveTypeForShort(std::string str);
79
78 int getID() const; 80 int getID() const;
79 std::string getTitle() const; 81 std::string getTitle() const;
80 int getTileAt(int x, int y) const; 82 int getTileAt(int x, int y) const;
81 const std::list<std::shared_ptr<MapObjectEntry>>& getObjects() const; 83 const std::list<std::shared_ptr<MapObjectEntry>>& getObjects() const;
82 std::shared_ptr<Map> getLeftmap() const;
83 std::shared_ptr<Map> getRightmap() const;
84 wxTreeItemId getTreeItemId() const; 84 wxTreeItemId getTreeItemId() const;
85 std::list<std::shared_ptr<Map>> getChildren() const; 85 std::list<std::shared_ptr<Map>> getChildren() const;
86 bool getExpanded() const; 86 bool getExpanded() const;
87 World* getWorld() const; 87 World* getWorld() const;
88 bool getHidden() const; 88 bool getHidden() const;
89 MoveType getLeftMoveType() const;
90 MoveType getRightMoveType() const;
91 MoveType getUpMoveType() const;
92 MoveType getDownMoveType() const;
93 int getLeftMoveMapID() const;
94 int getRightMoveMapID() const;
95 int getUpMoveMapID() const;
96 int getDownMoveMapID() const;
89 97
90 void setTitle(std::string title, bool dirty = true); 98 void setTitle(std::string title, bool dirty = true);
91 void setTileAt(int x, int y, int tile, bool dirty = true); 99 void setTileAt(int x, int y, int tile, bool dirty = true);
92 void setMapdata(int* mapdata, bool dirty = true); 100 void setMapdata(int* mapdata, bool dirty = true);
93 void addObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true); 101 void addObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true);
94 void removeObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true); 102 void removeObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true);
95 void setLeftmap(int id, bool dirty = true);
96 void setRightmap(int id, bool dirty = true);
97 void setTreeItemId(wxTreeItemId id); 103 void setTreeItemId(wxTreeItemId id);
98 void addChild(int id); 104 void addChild(int id);
99 void setExpanded(bool exp); 105 void setExpanded(bool exp);
100 void setHidden(bool hid); 106 void setHidden(bool hid);
107 void setLeftMoveType(MoveType move, bool dirty = true);
108 void setRightMoveType(MoveType move, bool dirty = true);
109 void setUpMoveType(MoveType move, bool dirty = true);
110 void setDownMoveType(MoveType move, bool dirty = true);
111 void setLeftMoveMapID(int id, bool dirty = true);
112 void setRightMoveMapID(int id, bool dirty = true);
113 void setUpMoveMapID(int id, bool dirty = true);
114 void setDownMoveMapID(int id, bool dirty = true);
101 115
102 private: 116 private:
103 int id; 117 int id;
@@ -106,11 +120,31 @@ class Map {
106 int* mapdata; 120 int* mapdata;
107 std::string title {"Untitled Map"}; 121 std::string title {"Untitled Map"};
108 std::list<int> children; 122 std::list<int> children;
109 int leftmap = -1;
110 int rightmap = -1;
111 wxTreeItemId treeItemId; 123 wxTreeItemId treeItemId;
112 bool expanded = false; 124 bool expanded = false;
113 bool hidden = false; 125 bool hidden = false;
126 MoveType leftType = MoveType::Wall;
127 MoveType rightType = MoveType::Wall;
128 MoveType upType = MoveType::Wall;
129 MoveType downType = MoveType::Wall;
130 int leftMap = 0;
131 int rightMap = 0;
132 int upMap = 0;
133 int downMap = 0;
134};
135
136class MapPtrCtr : public wxTreeItemData {
137 public:
138 Map* map;
139
140 MapPtrCtr(Map* map) : map(map) {}
141};
142
143class MoveTypeCtr {
144 public:
145 Map::MoveType type;
146
147 MoveTypeCtr(Map::MoveType type) : type(type) {}
114}; 148};
115 149
116#endif 150#endif
diff --git a/tools/mapedit/src/mapselect_combo.cpp b/tools/mapedit/src/mapselect_combo.cpp new file mode 100644 index 0000000..c8315b8 --- /dev/null +++ b/tools/mapedit/src/mapselect_combo.cpp
@@ -0,0 +1,91 @@
1#include "mapselect_combo.h"
2#include "map.h"
3
4wxBEGIN_EVENT_TABLE(MapSelectComboPopup, wxTreeCtrl)
5 EVT_LEFT_UP(MapSelectComboPopup::OnMouseClick)
6wxEND_EVENT_TABLE()
7
8MapSelectComboPopup::MapSelectComboPopup(wxTreeCtrl* tree, int initial)
9{
10 mapTree = tree;
11 lastSelected = initial;
12
13 Init();
14}
15
16void MapSelectComboPopup::Init()
17{
18
19}
20
21bool MapSelectComboPopup::Create(wxWindow* parent)
22{
23 return wxTreeCtrl::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT);
24}
25
26wxWindow* MapSelectComboPopup::GetControl()
27{
28 return this;
29}
30
31wxString MapSelectComboPopup::GetStringValue() const
32{
33 return ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getTitle();
34}
35
36void MapSelectComboPopup::OnPopup()
37{
38 DeleteAllItems();
39
40 wxTreeItemId newRoot = AddRoot("root");
41 wxTreeItemId oldRoot = mapTree->GetRootItem();
42 wxTreeItemIdValue cookie;
43 for (wxTreeItemId it = mapTree->GetFirstChild(oldRoot, cookie); it.IsOk(); it = mapTree->GetNextChild(newRoot, cookie))
44 {
45 CopyNodes(it, newRoot);
46 }
47}
48
49void MapSelectComboPopup::CopyNodes(wxTreeItemId from, wxTreeItemId to)
50{
51 MapPtrCtr* ctl1 = (MapPtrCtr*) mapTree->GetItemData(from);
52 MapPtrCtr* ctl2 = nullptr;
53 if (ctl1 != nullptr)
54 {
55 ctl2 = new MapPtrCtr(ctl1->map);
56 }
57
58 wxTreeItemId copied = mapTree->AppendItem(to, mapTree->GetItemText(from), -1, -1, ctl2);
59 if (mapTree->ItemHasChildren(from))
60 {
61 wxTreeItemIdValue cookie;
62 for (wxTreeItemId it = mapTree->GetFirstChild(from, cookie); it.IsOk(); it = mapTree->GetNextChild(from, cookie))
63 {
64 CopyNodes(it, copied);
65 }
66 }
67
68 if (ctl1->map->getID() == lastSelected)
69 {
70 SelectItem(copied);
71 }
72
73 Expand(copied);
74}
75
76void MapSelectComboPopup::OnMouseClick(wxMouseEvent&)
77{
78 lastSelected = ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getID();
79
80 Dismiss();
81}
82
83int MapSelectComboPopup::GetSelectedMapID() const
84{
85 return lastSelected;
86}
87
88void MapSelectComboPopup::SetSelectedMapID(int id)
89{
90 lastSelected = id;
91}
diff --git a/tools/mapedit/src/mapselect_combo.h b/tools/mapedit/src/mapselect_combo.h new file mode 100644 index 0000000..9f0fe25 --- /dev/null +++ b/tools/mapedit/src/mapselect_combo.h
@@ -0,0 +1,36 @@
1#ifndef MAPSELECT_COMBO_H
2#define MAPSELECT_COMBO_H
3
4#include <wx/wxprec.h>
5
6#ifndef WX_PRECOMP
7#include <wx/wx.h>
8#endif
9
10#include <wx/combo.h>
11#include <wx/treectrl.h>
12
13class MapeditFrame;
14
15class MapSelectComboPopup : public wxTreeCtrl, public wxComboPopup {
16 public:
17 MapSelectComboPopup(wxTreeCtrl* mapTree, int initial);
18 void Init();
19 bool Create(wxWindow* parent);
20 wxWindow* GetControl();
21 wxString GetStringValue() const;
22 void OnPopup();
23 void OnMouseClick(wxMouseEvent& event);
24 int GetSelectedMapID() const;
25 void SetSelectedMapID(int id);
26
27 private:
28 void CopyNodes(wxTreeItemId from, wxTreeItemId to);
29
30 wxTreeCtrl* mapTree;
31 int lastSelected = 0;
32
33 wxDECLARE_EVENT_TABLE();
34};
35
36#endif
diff --git a/tools/mapedit/src/tile_widget.cpp b/tools/mapedit/src/tile_widget.cpp index 7ffaf30..e07099a 100644 --- a/tools/mapedit/src/tile_widget.cpp +++ b/tools/mapedit/src/tile_widget.cpp
@@ -1,5 +1,5 @@
1#include "tile_widget.h" 1#include "tile_widget.h"
2#include "map.h" 2#include "consts.h"
3 3
4IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledCanvas) 4IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledCanvas)
5 5
diff --git a/tools/mapedit/src/tile_widget.h b/tools/mapedit/src/tile_widget.h index ff45a37..320726f 100644 --- a/tools/mapedit/src/tile_widget.h +++ b/tools/mapedit/src/tile_widget.h
@@ -7,8 +7,6 @@
7#include <wx/wx.h> 7#include <wx/wx.h>
8#endif 8#endif
9 9
10#include "map.h"
11
12class TileWidget : public wxScrolledCanvas { 10class TileWidget : public wxScrolledCanvas {
13 public: 11 public:
14 TileWidget(); 12 TileWidget();
diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index 3b96281..c74b194 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp
@@ -1,5 +1,9 @@
1#include "widget.h" 1#include "widget.h"
2#include "frame.h" 2#include "frame.h"
3#include "map.h"
4#include "tile_widget.h"
5#include "object.h"
6#include "undo.h"
3 7
4const int EDITOR_SPACING_X = MAP_WIDTH * TILE_WIDTH / 2; 8const int EDITOR_SPACING_X = MAP_WIDTH * TILE_WIDTH / 2;
5const int EDITOR_SPACING_Y = MAP_HEIGHT * TILE_HEIGHT / 2; 9const int EDITOR_SPACING_Y = MAP_HEIGHT * TILE_HEIGHT / 2;
diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h index 77b840e..b019088 100644 --- a/tools/mapedit/src/widget.h +++ b/tools/mapedit/src/widget.h
@@ -7,14 +7,18 @@
7#include <wx/wx.h> 7#include <wx/wx.h>
8#endif 8#endif
9 9
10#include "map.h"
11#include "tile_widget.h"
12#include <list> 10#include <list>
13#include <memory> 11#include <memory>
14#include <utility> 12#include <utility>
15#include <set> 13#include <set>
16 14
17class MapeditFrame; 15class MapeditFrame;
16class TileWidget;
17class Map;
18class MapObject;
19struct MapObjectEntry;
20
21#include "consts.h"
18 22
19enum EditMode { 23enum EditMode {
20 EditTiles, 24 EditTiles,
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index fb0bb36..043cf8a 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp
@@ -1,8 +1,11 @@
1#include "world.h" 1#include "world.h"
2#include <libxml/parser.h> 2#include <libxml/parser.h>
3#include <libxml/xmlwriter.h> 3#include <libxml/xmlwriter.h>
4#include "frame.h"
5#include <sstream> 4#include <sstream>
5#include "frame.h"
6#include "map.h"
7#include "object.h"
8#include "consts.h"
6 9
7World::World() 10World::World()
8{ 11{
@@ -103,20 +106,60 @@ World::World(std::string filename)
103 xmlFree(key); 106 xmlFree(key);
104 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) 107 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap"))
105 { 108 {
106 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); 109 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
107 if (key != 0) 110 if (typeKey == 0) throw MapLoadException(filename);
111 map->setLeftMoveType(Map::moveTypeForShort((char*) typeKey), false);
112 xmlFree(typeKey);
113
114 if (Map::moveTypeTakesMap(map->getLeftMoveType()))
108 { 115 {
109 map->setLeftmap(atoi((char*) key), false); 116 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map");
117 if (idKey == 0) throw MapLoadException(filename);
118 map->setLeftMoveMapID(atoi((char*) idKey), false);
119 xmlFree(idKey);
110 } 120 }
111 xmlFree(key);
112 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap")) 121 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap"))
113 { 122 {
114 xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); 123 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
115 if (key != 0) 124 if (typeKey == 0) throw MapLoadException(filename);
125 map->setRightMoveType(Map::moveTypeForShort((char*) typeKey), false);
126 xmlFree(typeKey);
127
128 if (Map::moveTypeTakesMap(map->getRightMoveType()))
116 { 129 {
117 map->setRightmap(atoi((char*) key), false); 130 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map");
131 if (idKey == 0) throw MapLoadException(filename);
132 map->setRightMoveMapID(atoi((char*) idKey), false);
133 xmlFree(idKey);
134 }
135 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "upmap"))
136 {
137 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
138 if (typeKey == 0) throw MapLoadException(filename);
139 map->setUpMoveType(Map::moveTypeForShort((char*) typeKey), false);
140 xmlFree(typeKey);
141
142 if (Map::moveTypeTakesMap(map->getUpMoveType()))
143 {
144 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map");
145 if (idKey == 0) throw MapLoadException(filename);
146 map->setUpMoveMapID(atoi((char*) idKey), false);
147 xmlFree(idKey);
148 }
149 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "downmap"))
150 {
151 xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type");
152 if (typeKey == 0) throw MapLoadException(filename);
153 map->setDownMoveType(Map::moveTypeForShort((char*) typeKey), false);
154 xmlFree(typeKey);
155
156 if (Map::moveTypeTakesMap(map->getDownMoveType()))
157 {
158 xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map");
159 if (idKey == 0) throw MapLoadException(filename);
160 map->setDownMoveMapID(atoi((char*) idKey), false);
161 xmlFree(idKey);
118 } 162 }
119 xmlFree(key);
120 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) 163 } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities"))
121 { 164 {
122 for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) 165 for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next)
@@ -248,7 +291,7 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
248 if (rc < 0) throw MapWriteException(name); 291 if (rc < 0) throw MapWriteException(name);
249 } 292 }
250 293
251 // <startpos> 294 // <startpos/>
252 rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); 295 rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos");
253 if (rc < 0) throw MapWriteException(name); 296 if (rc < 0) throw MapWriteException(name);
254 297
@@ -300,21 +343,79 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
300 if (rc < 0) throw MapWriteException(name); 343 if (rc < 0) throw MapWriteException(name);
301 344
302 // <leftmap/> 345 // <leftmap/>
303 std::ostringstream leftmap_out; 346 rc = xmlTextWriterStartElement(writer, (xmlChar*) "leftmap");
304 if (map.getLeftmap()) 347 if (rc < 0) throw MapWriteException(name);
348
349 // type=
350 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getLeftMoveType()).c_str());
351 if (rc < 0) throw MapWriteException(name);
352
353 if (Map::moveTypeTakesMap(map.getLeftMoveType()))
305 { 354 {
306 leftmap_out << map.getLeftmap()->getID(); 355 // map=
356 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getLeftMoveMapID());
357 if (rc < 0) throw MapWriteException(name);
307 } 358 }
308 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "leftmap", (xmlChar*) leftmap_out.str().c_str()); 359
360 // </leftmap>
361 rc = xmlTextWriterEndElement(writer);
309 if (rc < 0) throw MapWriteException(name); 362 if (rc < 0) throw MapWriteException(name);
310 363
311 // <rightmap/> 364 // <rightmap/>
312 std::ostringstream rightmap_out; 365 rc = xmlTextWriterStartElement(writer, (xmlChar*) "rightmap");
313 if (map.getRightmap()) 366 if (rc < 0) throw MapWriteException(name);
367
368 // type=
369 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getRightMoveType()).c_str());
370 if (rc < 0) throw MapWriteException(name);
371
372 if (Map::moveTypeTakesMap(map.getRightMoveType()))
373 {
374 // map=
375 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getRightMoveMapID());
376 if (rc < 0) throw MapWriteException(name);
377 }
378
379 // </rightmap>
380 rc = xmlTextWriterEndElement(writer);
381 if (rc < 0) throw MapWriteException(name);
382
383 // <upmap/>
384 rc = xmlTextWriterStartElement(writer, (xmlChar*) "upmap");
385 if (rc < 0) throw MapWriteException(name);
386
387 // type=
388 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getUpMoveType()).c_str());
389 if (rc < 0) throw MapWriteException(name);
390
391 if (Map::moveTypeTakesMap(map.getUpMoveType()))
314 { 392 {
315 rightmap_out << map.getRightmap()->getID(); 393 // map=
394 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getUpMoveMapID());
395 if (rc < 0) throw MapWriteException(name);
396 }
397
398 // </upmap>
399 rc = xmlTextWriterEndElement(writer);
400 if (rc < 0) throw MapWriteException(name);
401
402 // <downmap/>
403 rc = xmlTextWriterStartElement(writer, (xmlChar*) "downmap");
404 if (rc < 0) throw MapWriteException(name);
405
406 // type=
407 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getDownMoveType()).c_str());
408 if (rc < 0) throw MapWriteException(name);
409
410 if (Map::moveTypeTakesMap(map.getDownMoveType()))
411 {
412 // map=
413 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getDownMoveMapID());
414 if (rc < 0) throw MapWriteException(name);
316 } 415 }
317 rc = xmlTextWriterWriteElement(writer, (xmlChar*) "rightmap", (xmlChar*) rightmap_out.str().c_str()); 416
417 // </downmap>
418 rc = xmlTextWriterEndElement(writer);
318 if (rc < 0) throw MapWriteException(name); 419 if (rc < 0) throw MapWriteException(name);
319 420
320 // <entities> 421 // <entities>
diff --git a/tools/mapedit/src/world.h b/tools/mapedit/src/world.h index 68c960f..ff6ebcc 100644 --- a/tools/mapedit/src/world.h +++ b/tools/mapedit/src/world.h
@@ -12,10 +12,10 @@ class World;
12#include <wx/treectrl.h> 12#include <wx/treectrl.h>
13#include <map> 13#include <map>
14#include <memory> 14#include <memory>
15#include "map.h"
16#include <list> 15#include <list>
17 16
18class MapeditFrame; 17class MapeditFrame;
18class Map;
19 19
20class World { 20class World {
21 public: 21 public: