From f732cdaf7374fde737b503ec6966fb8cd8f4c32b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 17 Mar 2015 23:53:55 -0400 Subject: Map editor can now define actions to occur when the player goes off a specified edge of the map --- tools/mapedit/CMakeLists.txt | 3 +- tools/mapedit/src/consts.h | 13 ++ tools/mapedit/src/frame.cpp | 287 ++++++++++++++++++++++++++++++++-- tools/mapedit/src/frame.h | 32 ++-- tools/mapedit/src/main.cpp | 1 - tools/mapedit/src/map.cpp | 216 ++++++++++++++++++++----- tools/mapedit/src/map.h | 72 ++++++--- tools/mapedit/src/mapselect_combo.cpp | 91 +++++++++++ tools/mapedit/src/mapselect_combo.h | 36 +++++ tools/mapedit/src/tile_widget.cpp | 2 +- tools/mapedit/src/tile_widget.h | 2 - tools/mapedit/src/widget.cpp | 4 + tools/mapedit/src/widget.h | 8 +- tools/mapedit/src/world.cpp | 139 +++++++++++++--- tools/mapedit/src/world.h | 2 +- 15 files changed, 801 insertions(+), 107 deletions(-) create mode 100644 tools/mapedit/src/consts.h create mode 100644 tools/mapedit/src/mapselect_combo.cpp create mode 100644 tools/mapedit/src/mapselect_combo.h (limited to 'tools') 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) # selecting the build mode in their IDE if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -g -O0") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2") elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]") @@ -46,6 +46,7 @@ add_executable(AromatherapyMapEditor src/object.cpp src/world.cpp src/undo.cpp + src/mapselect_combo.cpp ) target_link_libraries(AromatherapyMapEditor ${ALL_LIBS}) install(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 @@ +#ifndef CONSTS_H +#define CONSTS_H + +const int TILE_WIDTH = 8; +const int TILE_HEIGHT = 8; +const int GAME_WIDTH = 320; +const int GAME_HEIGHT = 200; +const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH; +const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1; +const int PLAYER_WIDTH[5] = {10, 0, 0, 0, 0}; +const int PLAYER_HEIGHT[5] = {12, 0, 0, 0, 0}; + +#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 @@ #include "frame.h" -#include "widget.h" -#include "tile_widget.h" +#include "mapselect_combo.h" #include -#include "panel.h" #include #include #include +#include "widget.h" +#include "tile_widget.h" +#include "panel.h" +#include "map.h" +#include "undo.h" +#include "object.h" static std::list openWindows; @@ -33,7 +37,15 @@ enum { SET_STARTPOS_BUTTON, CANCEL_STARTPOS_BUTTON, LAYOUT_ONE_SPLITTER, - LAYOUT_THREE_SPLITTER + LAYOUT_THREE_SPLITTER, + LEFTMAP_TYPE_CHOICE, + LEFTMAP_MAP_CHOICE, + RIGHTMAP_TYPE_CHOICE, + RIGHTMAP_MAP_CHOICE, + UPMAP_TYPE_CHOICE, + UPMAP_MAP_CHOICE, + DOWNMAP_TYPE_CHOICE, + DOWNMAP_MAP_CHOICE }; wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) @@ -67,9 +79,17 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos) EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_ONE_SPLITTER, MapeditFrame::OnOneMovingSash) EVT_SPLITTER_SASH_POS_CHANGING(LAYOUT_THREE_SPLITTER, MapeditFrame::OnThreeMovingSash) + EVT_CHOICE(LEFTMAP_TYPE_CHOICE, MapeditFrame::OnSetLeftmapType) + EVT_CHOICE(RIGHTMAP_TYPE_CHOICE, MapeditFrame::OnSetRightmapType) + EVT_CHOICE(UPMAP_TYPE_CHOICE, MapeditFrame::OnSetUpmapType) + EVT_CHOICE(DOWNMAP_TYPE_CHOICE, MapeditFrame::OnSetDownmapType) + EVT_COMBOBOX_CLOSEUP(LEFTMAP_MAP_CHOICE, MapeditFrame::OnSetLeftmapMap) + EVT_COMBOBOX_CLOSEUP(RIGHTMAP_MAP_CHOICE, MapeditFrame::OnSetRightmapMap) + EVT_COMBOBOX_CLOSEUP(UPMAP_MAP_CHOICE, MapeditFrame::OnSetUpmapMap) + EVT_COMBOBOX_CLOSEUP(DOWNMAP_MAP_CHOICE, MapeditFrame::OnSetDownmapMap) wxEND_EVENT_TABLE() -MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_ANY, "Map Editor") +MapeditFrame::MapeditFrame(World* world) : wxFrame(NULL, wxID_ANY, "Map Editor") { int screenWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X); int screenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y); @@ -97,7 +117,7 @@ MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_AN Maximize(); } - this->world = std::move(world); + this->world = world; this->world->setParent(this); currentMap = this->world->getLastMap(); @@ -167,6 +187,34 @@ MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_AN cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); cancelStartposButton->Disable(); + wxStaticText* leftmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Leftmap Action:"); + wxChoice* leftmapChoice = new wxChoice(propertyEditor, LEFTMAP_TYPE_CHOICE); + wxComboCtrl* leftmapCombo = new wxComboCtrl(propertyEditor, LEFTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); + leftmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getLeftMoveMapID())); + + wxStaticText* rightmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Rightmap Action:"); + wxChoice* rightmapChoice = new wxChoice(propertyEditor, RIGHTMAP_TYPE_CHOICE); + wxComboCtrl* rightmapCombo = new wxComboCtrl(propertyEditor, RIGHTMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); + rightmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getRightMoveMapID())); + + wxStaticText* upmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Upmap Action:"); + wxChoice* upmapChoice = new wxChoice(propertyEditor, UPMAP_TYPE_CHOICE); + wxComboCtrl* upmapCombo = new wxComboCtrl(propertyEditor, UPMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); + upmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getUpMoveMapID())); + + wxStaticText* downmapLabel = new wxStaticText(propertyEditor, wxID_ANY, "Downmap Action:"); + wxChoice* downmapChoice = new wxChoice(propertyEditor, DOWNMAP_TYPE_CHOICE); + wxComboCtrl* downmapCombo = new wxComboCtrl(propertyEditor, DOWNMAP_MAP_CHOICE, "", wxDefaultPosition, wxDefaultSize, wxCB_READONLY); + downmapCombo->SetPopupControl(new MapSelectComboPopup(mapTree, currentMap->getDownMoveMapID())); + + for (auto type : Map::listMoveTypes()) + { + leftmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type)); + rightmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type)); + upmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type)); + downmapChoice->Append(Map::stringForMoveType(type), new MoveTypeCtr(type)); + } + wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); @@ -176,7 +224,42 @@ MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_AN propertySizer2->Add(startposLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); propertySizer2->Add(setStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); propertySizer2->Add(cancelStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10); - propertySizer->Add(propertySizer2, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); + propertySizer->Add(propertySizer2, 0, wxEXPAND | wxTOP, 10); + + wxBoxSizer* propertySizer3 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer* leftmapSizer = new wxBoxSizer(wxHORIZONTAL); + leftmapSizer->Add(leftmapLabel, 0, wxALIGN_RIGHT, 0); + wxBoxSizer* leftmapToolsSizer = new wxBoxSizer(wxVERTICAL); + leftmapToolsSizer->Add(leftmapChoice, 0, wxEXPAND, 0); + leftmapToolsSizer->Add(leftmapCombo, 0, wxEXPAND | wxTOP, 10); + leftmapSizer->Add(leftmapToolsSizer, 1, wxEXPAND | wxLEFT, 10); + propertySizer3->Add(leftmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10); + wxBoxSizer* rightmapSizer = new wxBoxSizer(wxHORIZONTAL); + rightmapSizer->Add(rightmapLabel, 0, wxALIGN_RIGHT, 0); + wxBoxSizer* rightmapToolsSizer = new wxBoxSizer(wxVERTICAL); + rightmapToolsSizer->Add(rightmapChoice, 0, wxEXPAND, 0); + rightmapToolsSizer->Add(rightmapCombo, 0, wxEXPAND | wxTOP, 10); + rightmapSizer->Add(rightmapToolsSizer, 1, wxEXPAND | wxLEFT, 10); + propertySizer3->Add(rightmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10); + propertySizer->Add(propertySizer3, 0, wxEXPAND | wxTOP, 10); + + wxBoxSizer* propertySizer4 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer* upmapSizer = new wxBoxSizer(wxHORIZONTAL); + upmapSizer->Add(upmapLabel, 0, wxALIGN_RIGHT, 0); + wxBoxSizer* upmapToolsSizer = new wxBoxSizer(wxVERTICAL); + upmapToolsSizer->Add(upmapChoice, 0, wxEXPAND, 0); + upmapToolsSizer->Add(upmapCombo, 0, wxEXPAND | wxTOP, 10); + upmapSizer->Add(upmapToolsSizer, 1, wxEXPAND | wxLEFT, 10); + propertySizer4->Add(upmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10); + wxBoxSizer* downmapSizer = new wxBoxSizer(wxHORIZONTAL); + downmapSizer->Add(downmapLabel, 0, wxALIGN_RIGHT, 0); + wxBoxSizer* downmapToolsSizer = new wxBoxSizer(wxVERTICAL); + downmapToolsSizer->Add(downmapChoice, 0, wxEXPAND, 0); + downmapToolsSizer->Add(downmapCombo, 0, wxEXPAND | wxTOP, 10); + downmapSizer->Add(downmapToolsSizer, 1, wxEXPAND | wxLEFT, 10); + propertySizer4->Add(downmapSizer, 1, wxALIGN_LEFT | wxLEFT, 10); + propertySizer->Add(propertySizer4, 0, wxEXPAND | wxTOP | wxBOTTOM, 10); + propertyEditor->SetSizer(propertySizer); propertySizer->SetSizeHints(propertyEditor); @@ -588,18 +671,174 @@ void MapeditFrame::OnThreeMovingSash(wxSplitterEvent& event) layout3->SetSashPosition(event.GetSashPosition(), true); } +void MapeditFrame::OnSetLeftmapType(wxCommandEvent&) +{ + wxChoice* leftmapChoice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this); + wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); + + Map::MoveType old = currentMap->getLeftMoveType(); + Map::MoveType newt = ((MoveTypeCtr*) leftmapChoice->GetClientData(leftmapChoice->GetSelection()))->type; + + commitAction(std::make_shared("Set Leftmap Action", [=] () { + leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(newt))); + currentMap->setLeftMoveType(newt); + leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); + }, [=] () { + leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(old))); + currentMap->setLeftMoveType(old); + leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); + })); +} + +void MapeditFrame::OnSetLeftmapMap(wxCommandEvent&) +{ + wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); + MapSelectComboPopup* popup = (MapSelectComboPopup*) leftmapCombo->GetPopupControl(); + int old = currentMap->getLeftMoveMapID(); + int newt = popup->GetSelectedMapID(); + + if (old == newt) return; + + commitAction(std::make_shared("Set Leftmap Map", [=] () { + popup->SetSelectedMapID(newt); + leftmapCombo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setLeftMoveMapID(newt); + }, [=] () { + popup->SetSelectedMapID(old); + leftmapCombo->SetValue(world->getMap(old)->getTitle()); + currentMap->setLeftMoveMapID(old); + })); +} + +void MapeditFrame::OnSetRightmapType(wxCommandEvent&) +{ + wxChoice* rightmapChoice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this); + wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); + + Map::MoveType old = currentMap->getRightMoveType(); + Map::MoveType newt = ((MoveTypeCtr*) rightmapChoice->GetClientData(rightmapChoice->GetSelection()))->type; + + commitAction(std::make_shared("Set Rightmap Action", [=] () { + rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(newt))); + currentMap->setRightMoveType(newt); + rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); + }, [=] () { + rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(old))); + currentMap->setRightMoveType(old); + rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); + })); +} + +void MapeditFrame::OnSetRightmapMap(wxCommandEvent&) +{ + wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); + MapSelectComboPopup* popup = (MapSelectComboPopup*) rightmapCombo->GetPopupControl(); + int old = currentMap->getRightMoveMapID(); + int newt = popup->GetSelectedMapID(); + + if (old == newt) return; + + commitAction(std::make_shared("Set Rightmap Map", [=] () { + popup->SetSelectedMapID(newt); + rightmapCombo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setRightMoveMapID(newt); + }, [=] () { + popup->SetSelectedMapID(old); + rightmapCombo->SetValue(world->getMap(old)->getTitle()); + currentMap->setRightMoveMapID(old); + })); +} + +void MapeditFrame::OnSetUpmapType(wxCommandEvent&) +{ + wxChoice* upmapChoice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this); + wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); + + Map::MoveType old = currentMap->getUpMoveType(); + Map::MoveType newt = ((MoveTypeCtr*) upmapChoice->GetClientData(upmapChoice->GetSelection()))->type; + + commitAction(std::make_shared("Set Upmap Action", [=] () { + upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(newt))); + currentMap->setUpMoveType(newt); + upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); + }, [=] () { + upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(old))); + currentMap->setUpMoveType(old); + upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); + })); +} + +void MapeditFrame::OnSetUpmapMap(wxCommandEvent&) +{ + wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); + MapSelectComboPopup* popup = (MapSelectComboPopup*) upmapCombo->GetPopupControl(); + int old = currentMap->getUpMoveMapID(); + int newt = popup->GetSelectedMapID(); + + if (old == newt) return; + + commitAction(std::make_shared("Set Upmap Map", [=] () { + popup->SetSelectedMapID(newt); + upmapCombo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setUpMoveMapID(newt); + }, [=] () { + popup->SetSelectedMapID(old); + upmapCombo->SetValue(world->getMap(old)->getTitle()); + currentMap->setUpMoveMapID(old); + })); +} + +void MapeditFrame::OnSetDownmapType(wxCommandEvent&) +{ + wxChoice* downmapChoice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this); + wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); + + Map::MoveType old = currentMap->getDownMoveType(); + Map::MoveType newt = ((MoveTypeCtr*) downmapChoice->GetClientData(downmapChoice->GetSelection()))->type; + + commitAction(std::make_shared("Set Downmap Action", [=] () { + downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(newt))); + currentMap->setDownMoveType(newt); + downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + }, [=] () { + downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(old))); + currentMap->setDownMoveType(old); + downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + })); +} + +void MapeditFrame::OnSetDownmapMap(wxCommandEvent&) +{ + wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); + MapSelectComboPopup* popup = (MapSelectComboPopup*) downmapCombo->GetPopupControl(); + int old = currentMap->getDownMoveMapID(); + int newt = popup->GetSelectedMapID(); + + if (old == newt) return; + + commitAction(std::make_shared("Set Downmap Map", [=] () { + popup->SetSelectedMapID(newt); + downmapCombo->SetValue(world->getMap(newt)->getTitle()); + currentMap->setDownMoveMapID(newt); + }, [=] () { + popup->SetSelectedMapID(old); + downmapCombo->SetValue(world->getMap(old)->getTitle()); + currentMap->setDownMoveMapID(old); + })); +} + void MapeditFrame::NewWorld() { - LaunchWindow(std::unique_ptr(new World())); + LaunchWindow(new World()); } bool MapeditFrame::OpenWorld(std::string filename) { try { - auto world = std::unique_ptr(new World(filename)); + auto world = new World(filename); - LaunchWindow(std::move(world)); + LaunchWindow(world); return true; } catch (std::exception& ex) @@ -610,9 +849,9 @@ bool MapeditFrame::OpenWorld(std::string filename) return false; } -void MapeditFrame::LaunchWindow(std::unique_ptr world) +void MapeditFrame::LaunchWindow(World* world) { - MapeditFrame* frame = new MapeditFrame(std::move(world)); + MapeditFrame* frame = new MapeditFrame(world); frame->closer = openWindows.insert(end(openWindows), frame); frame->Show(true); } @@ -674,6 +913,30 @@ void MapeditFrame::SelectMap(Map* map) titleBox->ChangeValue(map->getTitle()); world->setLastMap(map); + + wxChoice* leftmapChoice = (wxChoice*) wxWindow::FindWindowById(LEFTMAP_TYPE_CHOICE, this); + wxChoice* rightmapChoice = (wxChoice*) wxWindow::FindWindowById(RIGHTMAP_TYPE_CHOICE, this); + wxChoice* upmapChoice = (wxChoice*) wxWindow::FindWindowById(UPMAP_TYPE_CHOICE, this); + wxChoice* downmapChoice = (wxChoice*) wxWindow::FindWindowById(DOWNMAP_TYPE_CHOICE, this); + wxComboCtrl* leftmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(LEFTMAP_MAP_CHOICE, this); + wxComboCtrl* rightmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(RIGHTMAP_MAP_CHOICE, this); + wxComboCtrl* upmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(UPMAP_MAP_CHOICE, this); + wxComboCtrl* downmapCombo = (wxComboCtrl*) wxWindow::FindWindowById(DOWNMAP_MAP_CHOICE, this); + + leftmapChoice->SetSelection(leftmapChoice->FindString(Map::stringForMoveType(currentMap->getLeftMoveType()))); + rightmapChoice->SetSelection(rightmapChoice->FindString(Map::stringForMoveType(currentMap->getRightMoveType()))); + upmapChoice->SetSelection(upmapChoice->FindString(Map::stringForMoveType(currentMap->getUpMoveType()))); + downmapChoice->SetSelection(downmapChoice->FindString(Map::stringForMoveType(currentMap->getDownMoveType()))); + + leftmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getLeftMoveType())); + rightmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getRightMoveType())); + upmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getUpMoveType())); + downmapCombo->Enable(Map::moveTypeTakesMap(currentMap->getDownMoveType())); + + leftmapCombo->SetValue(world->getMap(currentMap->getLeftMoveMapID())->getTitle()); + rightmapCombo->SetValue(world->getMap(currentMap->getRightMoveMapID())->getTitle()); + upmapCombo->SetValue(world->getMap(currentMap->getUpMoveMapID())->getTitle()); + downmapCombo->SetValue(world->getMap(currentMap->getDownMoveMapID())->getTitle()); } wxTreeItemId 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 @@ #include #endif -#include "map.h" -#include "widget.h" -#include "tile_widget.h" #include #include #include #include #include -#include "undo.h" -class MapPtrCtr : public wxTreeItemData { - public: - Map* map; - - MapPtrCtr(Map* map) : map(map) {} -}; +class Map; +class MapeditWidget; +class TileWidget; +class Undoable; +class UndoableTextBox; + +#include "world.h" class MapeditFrame : public wxFrame { public: MapeditFrame() {} - MapeditFrame(std::unique_ptr world); + MapeditFrame(World* world); + ~MapeditFrame() { delete world; } MapeditWidget* GetMapEditor(); void SetIsAddingEntity(bool isAddingEntity); @@ -39,7 +37,7 @@ class MapeditFrame : public wxFrame { std::list::iterator closer; - static void LaunchWindow(std::unique_ptr world); + static void LaunchWindow(World* world); void populateMapTree(wxTreeItemId node, std::list> maps); void SelectMap(Map* map); wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent); @@ -68,8 +66,16 @@ class MapeditFrame : public wxFrame { void OnCancelSetStartpos(wxCommandEvent& event); void OnOneMovingSash(wxSplitterEvent& event); void OnThreeMovingSash(wxSplitterEvent& event); + void OnSetLeftmapType(wxCommandEvent& event); + void OnSetLeftmapMap(wxCommandEvent& event); + void OnSetRightmapType(wxCommandEvent& event); + void OnSetRightmapMap(wxCommandEvent& event); + void OnSetUpmapType(wxCommandEvent& event); + void OnSetUpmapMap(wxCommandEvent& event); + void OnSetDownmapType(wxCommandEvent& event); + void OnSetDownmapMap(wxCommandEvent& event); - std::unique_ptr world; + World* world; Map* currentMap; 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 @@ #include #endif -#include "map.h" #include "frame.h" class 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 @@ #include "map.h" #include "frame.h" +#include "object.h" +#include "world.h" +#include "consts.h" Map::Map(int id, World* world) : id(id), world(world) { @@ -13,13 +16,19 @@ Map::Map(const Map& map) id = map.id; title = map.title; - leftmap = map.leftmap; - rightmap = map.rightmap; objects = map.objects; world = map.world; treeItemId = map.treeItemId; children = map.children; hidden = map.hidden; + leftType = map.leftType; + rightType = map.rightType; + upType = map.upType; + downType = map.downType; + leftMap = map.leftMap; + rightMap = map.rightMap; + downMap = map.downMap; + upMap = map.upMap; } Map::Map(Map&& map) : Map(-1, map.world) @@ -43,14 +52,67 @@ void swap(Map& first, Map& second) { std::swap(first.mapdata, second.mapdata); std::swap(first.title, second.title); - std::swap(first.leftmap, second.leftmap); - std::swap(first.rightmap, second.rightmap); std::swap(first.objects, second.objects); std::swap(first.id, second.id); std::swap(first.world, second.world); std::swap(first.treeItemId, second.treeItemId); std::swap(first.children, second.children); std::swap(first.hidden, second.hidden); + std::swap(first.leftType, second.leftType); + std::swap(first.rightType, second.rightType); + std::swap(first.upType, second.upType); + std::swap(first.downType, second.downType); + std::swap(first.leftMap, second.leftMap); + std::swap(first.rightMap, second.rightMap); + std::swap(first.downMap, second.downMap); + std::swap(first.upMap, second.upMap); +} + +std::list Map::listMoveTypes() +{ + return {MoveType::Wall, MoveType::Wrap, MoveType::Warp, MoveType::ReverseWarp}; +} + +std::string Map::stringForMoveType(MoveType type) +{ + switch (type) + { + case MoveType::Wall: return "Wall"; + case MoveType::Warp: return "Warp"; + case MoveType::Wrap: return "Wrap"; + case MoveType::ReverseWarp: return "Reverse Warp"; + } +} + +bool Map::moveTypeTakesMap(MoveType type) +{ + switch (type) + { + case MoveType::Wall: return false; + case MoveType::Wrap: return false; + case MoveType::Warp: return true; + case MoveType::ReverseWarp: return true; + } +} + +std::string Map::shortForMoveType(MoveType type) +{ + switch (type) + { + case MoveType::Wall: return "wall"; + case MoveType::Wrap: return "wrap"; + case MoveType::Warp: return "warp"; + case MoveType::ReverseWarp: return "reverseWarp"; + } +} + +Map::MoveType Map::moveTypeForShort(std::string str) +{ + if (str == "wrap") return MoveType::Wrap; + if (str == "warp") return MoveType::Warp; + if (str == "reverseWarp") return MoveType::ReverseWarp; + + return MoveType::Wall; } int Map::getID() const @@ -73,26 +135,6 @@ const std::list>& Map::getObjects() const return objects; } -std::shared_ptr Map::getLeftmap() const -{ - if (leftmap == -1) - { - return std::shared_ptr(); - } else { - return world->getMap(leftmap); - } -} - -std::shared_ptr Map::getRightmap() const -{ - if (rightmap == -1) - { - return std::shared_ptr(); - } else { - return world->getMap(rightmap); - } -} - wxTreeItemId Map::getTreeItemId() const { return treeItemId; @@ -125,6 +167,47 @@ bool Map::getHidden() const return hidden; } +Map::MoveType Map::getLeftMoveType() const +{ + return leftType; +} + +Map::MoveType Map::getRightMoveType() const +{ + return rightType; +} + +Map::MoveType Map::getUpMoveType() const +{ + return upType; +} + +Map::MoveType Map::getDownMoveType() const +{ + return downType; +} + +int Map::getLeftMoveMapID() const +{ + return leftMap; +} + +int Map::getRightMoveMapID() const +{ + return rightMap; +} + +int Map::getUpMoveMapID() const +{ + return upMap; +} + +int Map::getDownMoveMapID() const +{ + return downMap; +} + + void Map::setTitle(std::string title, bool dirty) { this->title = title; @@ -176,9 +259,39 @@ void Map::removeObject(std::shared_ptr obj, bool dirty) } } -void Map::setLeftmap(int id, bool dirty) +void Map::setTreeItemId(wxTreeItemId id) +{ + this->treeItemId = id; +} + +void Map::addChild(int id) +{ + children.push_back(id); +} + +void Map::setExpanded(bool exp) +{ + expanded = exp; +} + +void Map::setHidden(bool hid) +{ + hidden = hid; +} + +void Map::setLeftMoveType(Map::MoveType move, bool dirty) +{ + leftType = move; + + if (dirty) + { + world->setDirty(true); + } +} + +void Map::setRightMoveType(Map::MoveType move, bool dirty) { - leftmap = id; + rightType = move; if (dirty) { @@ -186,9 +299,9 @@ void Map::setLeftmap(int id, bool dirty) } } -void Map::setRightmap(int id, bool dirty) +void Map::setUpMoveType(Map::MoveType move, bool dirty) { - rightmap = id; + upType = move; if (dirty) { @@ -196,22 +309,53 @@ void Map::setRightmap(int id, bool dirty) } } -void Map::setTreeItemId(wxTreeItemId id) +void Map::setDownMoveType(Map::MoveType move, bool dirty) { - this->treeItemId = id; + downType = move; + + if (dirty) + { + world->setDirty(true); + } } -void Map::addChild(int id) +void Map::setLeftMoveMapID(int id, bool dirty) { - children.push_back(id); + leftMap = id; + + if (dirty) + { + world->setDirty(true); + } } -void Map::setExpanded(bool exp) +void Map::setRightMoveMapID(int id, bool dirty) { - expanded = exp; + rightMap = id; + + if (dirty) + { + world->setDirty(true); + } } -void Map::setHidden(bool hid) +void Map::setUpMoveMapID(int id, bool dirty) { - hidden = hid; + upMap = id; + + if (dirty) + { + world->setDirty(true); + } } + +void Map::setDownMoveMapID(int id, bool dirty) +{ + downMap = id; + + if (dirty) + { + world->setDirty(true); + } +} + 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 @@ #ifndef MAP_H #define MAP_H -class Map; - #include #include #include #include -#include "object.h" #include -#include "world.h" #include +class MapObject; +class World; class MapeditFrame; -const int TILE_WIDTH = 8; -const int TILE_HEIGHT = 8; -const int GAME_WIDTH = 320; -const int GAME_HEIGHT = 200; -const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH; -const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1; -const int PLAYER_WIDTH[5] = {10, 0, 0, 0, 0}; -const int PLAYER_HEIGHT[5] = {12, 0, 0, 0, 0}; - class MapLoadException: public std::exception { public: @@ -75,29 +64,54 @@ class Map { Map& operator= (Map other); friend void swap(Map& first, Map& second); + enum class MoveType { + Wall, + Wrap, + Warp, + ReverseWarp + }; + + static std::list listMoveTypes(); + static std::string stringForMoveType(MoveType type); + static bool moveTypeTakesMap(MoveType type); + static std::string shortForMoveType(MoveType type); + static MoveType moveTypeForShort(std::string str); + int getID() const; std::string getTitle() const; int getTileAt(int x, int y) const; const std::list>& getObjects() const; - std::shared_ptr getLeftmap() const; - std::shared_ptr getRightmap() const; wxTreeItemId getTreeItemId() const; std::list> getChildren() const; bool getExpanded() const; World* getWorld() const; bool getHidden() const; + MoveType getLeftMoveType() const; + MoveType getRightMoveType() const; + MoveType getUpMoveType() const; + MoveType getDownMoveType() const; + int getLeftMoveMapID() const; + int getRightMoveMapID() const; + int getUpMoveMapID() const; + int getDownMoveMapID() const; void setTitle(std::string title, bool dirty = true); void setTileAt(int x, int y, int tile, bool dirty = true); void setMapdata(int* mapdata, bool dirty = true); void addObject(std::shared_ptr obj, bool dirty = true); void removeObject(std::shared_ptr obj, bool dirty = true); - void setLeftmap(int id, bool dirty = true); - void setRightmap(int id, bool dirty = true); void setTreeItemId(wxTreeItemId id); void addChild(int id); void setExpanded(bool exp); void setHidden(bool hid); + void setLeftMoveType(MoveType move, bool dirty = true); + void setRightMoveType(MoveType move, bool dirty = true); + void setUpMoveType(MoveType move, bool dirty = true); + void setDownMoveType(MoveType move, bool dirty = true); + void setLeftMoveMapID(int id, bool dirty = true); + void setRightMoveMapID(int id, bool dirty = true); + void setUpMoveMapID(int id, bool dirty = true); + void setDownMoveMapID(int id, bool dirty = true); private: int id; @@ -106,11 +120,31 @@ class Map { int* mapdata; std::string title {"Untitled Map"}; std::list children; - int leftmap = -1; - int rightmap = -1; wxTreeItemId treeItemId; bool expanded = false; bool hidden = false; + MoveType leftType = MoveType::Wall; + MoveType rightType = MoveType::Wall; + MoveType upType = MoveType::Wall; + MoveType downType = MoveType::Wall; + int leftMap = 0; + int rightMap = 0; + int upMap = 0; + int downMap = 0; +}; + +class MapPtrCtr : public wxTreeItemData { + public: + Map* map; + + MapPtrCtr(Map* map) : map(map) {} +}; + +class MoveTypeCtr { + public: + Map::MoveType type; + + MoveTypeCtr(Map::MoveType type) : type(type) {} }; #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 @@ +#include "mapselect_combo.h" +#include "map.h" + +wxBEGIN_EVENT_TABLE(MapSelectComboPopup, wxTreeCtrl) + EVT_LEFT_UP(MapSelectComboPopup::OnMouseClick) +wxEND_EVENT_TABLE() + +MapSelectComboPopup::MapSelectComboPopup(wxTreeCtrl* tree, int initial) +{ + mapTree = tree; + lastSelected = initial; + + Init(); +} + +void MapSelectComboPopup::Init() +{ + +} + +bool MapSelectComboPopup::Create(wxWindow* parent) +{ + return wxTreeCtrl::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT); +} + +wxWindow* MapSelectComboPopup::GetControl() +{ + return this; +} + +wxString MapSelectComboPopup::GetStringValue() const +{ + return ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getTitle(); +} + +void MapSelectComboPopup::OnPopup() +{ + DeleteAllItems(); + + wxTreeItemId newRoot = AddRoot("root"); + wxTreeItemId oldRoot = mapTree->GetRootItem(); + wxTreeItemIdValue cookie; + for (wxTreeItemId it = mapTree->GetFirstChild(oldRoot, cookie); it.IsOk(); it = mapTree->GetNextChild(newRoot, cookie)) + { + CopyNodes(it, newRoot); + } +} + +void MapSelectComboPopup::CopyNodes(wxTreeItemId from, wxTreeItemId to) +{ + MapPtrCtr* ctl1 = (MapPtrCtr*) mapTree->GetItemData(from); + MapPtrCtr* ctl2 = nullptr; + if (ctl1 != nullptr) + { + ctl2 = new MapPtrCtr(ctl1->map); + } + + wxTreeItemId copied = mapTree->AppendItem(to, mapTree->GetItemText(from), -1, -1, ctl2); + if (mapTree->ItemHasChildren(from)) + { + wxTreeItemIdValue cookie; + for (wxTreeItemId it = mapTree->GetFirstChild(from, cookie); it.IsOk(); it = mapTree->GetNextChild(from, cookie)) + { + CopyNodes(it, copied); + } + } + + if (ctl1->map->getID() == lastSelected) + { + SelectItem(copied); + } + + Expand(copied); +} + +void MapSelectComboPopup::OnMouseClick(wxMouseEvent&) +{ + lastSelected = ((MapPtrCtr*) GetItemData(GetFocusedItem()))->map->getID(); + + Dismiss(); +} + +int MapSelectComboPopup::GetSelectedMapID() const +{ + return lastSelected; +} + +void MapSelectComboPopup::SetSelectedMapID(int id) +{ + lastSelected = id; +} 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 @@ +#ifndef MAPSELECT_COMBO_H +#define MAPSELECT_COMBO_H + +#include + +#ifndef WX_PRECOMP +#include +#endif + +#include +#include + +class MapeditFrame; + +class MapSelectComboPopup : public wxTreeCtrl, public wxComboPopup { + public: + MapSelectComboPopup(wxTreeCtrl* mapTree, int initial); + void Init(); + bool Create(wxWindow* parent); + wxWindow* GetControl(); + wxString GetStringValue() const; + void OnPopup(); + void OnMouseClick(wxMouseEvent& event); + int GetSelectedMapID() const; + void SetSelectedMapID(int id); + + private: + void CopyNodes(wxTreeItemId from, wxTreeItemId to); + + wxTreeCtrl* mapTree; + int lastSelected = 0; + + wxDECLARE_EVENT_TABLE(); +}; + +#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 @@ #include "tile_widget.h" -#include "map.h" +#include "consts.h" IMPLEMENT_DYNAMIC_CLASS(TileWidget,wxScrolledCanvas) 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 @@ #include #endif -#include "map.h" - class TileWidget : public wxScrolledCanvas { public: 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 @@ #include "widget.h" #include "frame.h" +#include "map.h" +#include "tile_widget.h" +#include "object.h" +#include "undo.h" const int EDITOR_SPACING_X = MAP_WIDTH * TILE_WIDTH / 2; const 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 @@ #include #endif -#include "map.h" -#include "tile_widget.h" #include #include #include #include class MapeditFrame; +class TileWidget; +class Map; +class MapObject; +struct MapObjectEntry; + +#include "consts.h" enum EditMode { 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 @@ #include "world.h" #include #include -#include "frame.h" #include +#include "frame.h" +#include "map.h" +#include "object.h" +#include "consts.h" World::World() { @@ -103,20 +106,60 @@ World::World(std::string filename) xmlFree(key); } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "leftmap")) { - xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); - if (key != 0) + xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + if (typeKey == 0) throw MapLoadException(filename); + map->setLeftMoveType(Map::moveTypeForShort((char*) typeKey), false); + xmlFree(typeKey); + + if (Map::moveTypeTakesMap(map->getLeftMoveType())) { - map->setLeftmap(atoi((char*) key), false); + xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); + if (idKey == 0) throw MapLoadException(filename); + map->setLeftMoveMapID(atoi((char*) idKey), false); + xmlFree(idKey); } - xmlFree(key); } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "rightmap")) { - xmlChar* key = xmlNodeListGetString(doc, mapNode->xmlChildrenNode, 1); - if (key != 0) + xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + if (typeKey == 0) throw MapLoadException(filename); + map->setRightMoveType(Map::moveTypeForShort((char*) typeKey), false); + xmlFree(typeKey); + + if (Map::moveTypeTakesMap(map->getRightMoveType())) { - map->setRightmap(atoi((char*) key), false); + xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); + if (idKey == 0) throw MapLoadException(filename); + map->setRightMoveMapID(atoi((char*) idKey), false); + xmlFree(idKey); + } + } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "upmap")) + { + xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + if (typeKey == 0) throw MapLoadException(filename); + map->setUpMoveType(Map::moveTypeForShort((char*) typeKey), false); + xmlFree(typeKey); + + if (Map::moveTypeTakesMap(map->getUpMoveType())) + { + xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); + if (idKey == 0) throw MapLoadException(filename); + map->setUpMoveMapID(atoi((char*) idKey), false); + xmlFree(idKey); + } + } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "downmap")) + { + xmlChar* typeKey = xmlGetProp(mapNode, (xmlChar*) "type"); + if (typeKey == 0) throw MapLoadException(filename); + map->setDownMoveType(Map::moveTypeForShort((char*) typeKey), false); + xmlFree(typeKey); + + if (Map::moveTypeTakesMap(map->getDownMoveType())) + { + xmlChar* idKey = xmlGetProp(mapNode, (xmlChar*) "map"); + if (idKey == 0) throw MapLoadException(filename); + map->setDownMoveMapID(atoi((char*) idKey), false); + xmlFree(idKey); } - xmlFree(key); } else if (!xmlStrcmp(mapNode->name, (const xmlChar*) "entities")) { for (xmlNodePtr entityNode = mapNode->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next) @@ -248,7 +291,7 @@ void World::save(std::string name, wxTreeCtrl* mapTree) if (rc < 0) throw MapWriteException(name); } - // + // rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos"); if (rc < 0) throw MapWriteException(name); @@ -300,21 +343,79 @@ void World::save(std::string name, wxTreeCtrl* mapTree) if (rc < 0) throw MapWriteException(name); // - std::ostringstream leftmap_out; - if (map.getLeftmap()) + rc = xmlTextWriterStartElement(writer, (xmlChar*) "leftmap"); + if (rc < 0) throw MapWriteException(name); + + // type= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getLeftMoveType()).c_str()); + if (rc < 0) throw MapWriteException(name); + + if (Map::moveTypeTakesMap(map.getLeftMoveType())) { - leftmap_out << map.getLeftmap()->getID(); + // map= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getLeftMoveMapID()); + if (rc < 0) throw MapWriteException(name); } - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "leftmap", (xmlChar*) leftmap_out.str().c_str()); + + // + rc = xmlTextWriterEndElement(writer); if (rc < 0) throw MapWriteException(name); - + // - std::ostringstream rightmap_out; - if (map.getRightmap()) + rc = xmlTextWriterStartElement(writer, (xmlChar*) "rightmap"); + if (rc < 0) throw MapWriteException(name); + + // type= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getRightMoveType()).c_str()); + if (rc < 0) throw MapWriteException(name); + + if (Map::moveTypeTakesMap(map.getRightMoveType())) + { + // map= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getRightMoveMapID()); + if (rc < 0) throw MapWriteException(name); + } + + // + rc = xmlTextWriterEndElement(writer); + if (rc < 0) throw MapWriteException(name); + + // + rc = xmlTextWriterStartElement(writer, (xmlChar*) "upmap"); + if (rc < 0) throw MapWriteException(name); + + // type= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getUpMoveType()).c_str()); + if (rc < 0) throw MapWriteException(name); + + if (Map::moveTypeTakesMap(map.getUpMoveType())) { - rightmap_out << map.getRightmap()->getID(); + // map= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getUpMoveMapID()); + if (rc < 0) throw MapWriteException(name); + } + + // + rc = xmlTextWriterEndElement(writer); + if (rc < 0) throw MapWriteException(name); + + // + rc = xmlTextWriterStartElement(writer, (xmlChar*) "downmap"); + if (rc < 0) throw MapWriteException(name); + + // type= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "type", "%s", Map::shortForMoveType(map.getDownMoveType()).c_str()); + if (rc < 0) throw MapWriteException(name); + + if (Map::moveTypeTakesMap(map.getDownMoveType())) + { + // map= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "map", "%d", map.getDownMoveMapID()); + if (rc < 0) throw MapWriteException(name); } - rc = xmlTextWriterWriteElement(writer, (xmlChar*) "rightmap", (xmlChar*) rightmap_out.str().c_str()); + + // + rc = xmlTextWriterEndElement(writer); if (rc < 0) throw MapWriteException(name); // 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; #include #include #include -#include "map.h" #include class MapeditFrame; +class Map; class World { public: -- cgit 1.4.1