From 29f818c314f86f9a842840c20d9634f0711507a6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Mar 2015 21:28:46 -0400 Subject: Added tool to map editor to set game starting position --- tools/mapedit/src/frame.cpp | 120 ++++++++++++++++++++++--------------- tools/mapedit/src/frame.h | 10 +++- tools/mapedit/src/map.cpp | 5 ++ tools/mapedit/src/map.h | 8 +++ tools/mapedit/src/widget.cpp | 138 ++++++++++++++++++++++++++++++++----------- tools/mapedit/src/widget.h | 3 + tools/mapedit/src/world.cpp | 45 ++++++++++++++ tools/mapedit/src/world.h | 5 ++ 8 files changed, 249 insertions(+), 85 deletions(-) (limited to 'tools') diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 94be15e..66775e1 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp @@ -6,6 +6,7 @@ #include "panel.h" #include #include +#include static std::list openWindows; @@ -27,7 +28,9 @@ enum { MAP_EDITOR_TREE, MAP_TITLE_TEXTBOX, ADD_ENTITY_BUTTON, - CANCEL_ENTITY_BUTTON + CANCEL_ENTITY_BUTTON, + SET_STARTPOS_BUTTON, + CANCEL_STARTPOS_BUTTON }; wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) @@ -56,6 +59,8 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) EVT_TEXT(MAP_TITLE_TEXTBOX, MapeditFrame::OnTitleChange) EVT_BUTTON(ADD_ENTITY_BUTTON, MapeditFrame::OnAddEntity) EVT_BUTTON(CANCEL_ENTITY_BUTTON, MapeditFrame::OnCancelAddEntity) + EVT_BUTTON(SET_STARTPOS_BUTTON, MapeditFrame::OnSetStartpos) + EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos) wxEND_EVENT_TABLE() MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*2+TILE_WIDTH*6*6+10+10+150, GAME_HEIGHT*3)) @@ -114,14 +119,27 @@ MapeditFrame::MapeditFrame(std::unique_ptr world) : wxFrame(NULL, wxID_AN // Set up property editor wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); titleBox = new wxTextCtrl(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle()); + titleBox->SetMaxLength(40); wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); + startposLabel = new wxStaticText(propertyEditor, wxID_ANY, "Starting Position:"); + SetStartposLabel(); + + setStartposButton = new wxButton(propertyEditor, SET_STARTPOS_BUTTON, "Set Starting Position"); + cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel"); + cancelStartposButton->Disable(); + wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); + wxBoxSizer* propertySizer2 = new wxBoxSizer(wxHORIZONTAL); + 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, 1, wxEXPAND | wxTOP, 10); propertyEditor->SetSizer(propertySizer); propertySizer->SetSizeHints(propertyEditor); @@ -386,22 +404,13 @@ void MapeditFrame::OnDidSelectMap(wxTreeEvent& event) void MapeditFrame::OnWillSelectMap(wxTreeEvent& event) { - if (addingEntity) - { - event.Veto(); - return; - } - event.Skip(); } void MapeditFrame::OnWillDragMap(wxTreeEvent& event) { - if (!addingEntity) - { - event.Allow(); - dragMap = event.GetItem(); - } + event.Allow(); + dragMap = event.GetItem(); } void MapeditFrame::OnDidDragMap(wxTreeEvent& event) @@ -430,6 +439,18 @@ void MapeditFrame::OnRightClickTree(wxTreeEvent& event) } } +void MapeditFrame::OnSetStartpos(wxCommandEvent&) +{ + SetIsSettingStart(true); + mapEditor->SetIsSettingStart(true); +} + +void MapeditFrame::OnCancelSetStartpos(wxCommandEvent&) +{ + SetIsSettingStart(false); + mapEditor->SetIsSettingStart(false); +} + void MapeditFrame::NewWorld() { LaunchWindow(std::unique_ptr(new World())); @@ -459,43 +480,18 @@ void MapeditFrame::LaunchWindow(std::unique_ptr world) frame->Show(true); } -void MapeditFrame::StartAddingEntity() -{ - addingEntity = true; - addEntityButton->Disable(); - cancelEntityButton->Enable(); - - toolbar->EnableTool(TOOL_FILE_NEW, false); - toolbar->EnableTool(TOOL_FILE_OPEN, false); - toolbar->EnableTool(TOOL_FILE_SAVE, false); - toolbar->EnableTool(TOOL_MAP_ADD_ROOT, false); - toolbar->EnableTool(TOOL_MAP_ADD_CHILD, false); - - menuFile->Enable(MENU_FILE_NEW, false); - menuFile->Enable(MENU_FILE_OPEN, false); - menuFile->Enable(MENU_FILE_SAVE, false); - menuFile->Enable(MENU_MAP_ADD_ROOT, false); - menuFile->Enable(MENU_MAP_ADD_CHILD, false); -} - -void MapeditFrame::FinishAddingEntity() +void MapeditFrame::SetIsAddingEntity(bool isAddingEntity) { - addingEntity = false; - addEntityButton->Enable(); - cancelEntityButton->Disable(); - toolbar->Enable(); - - toolbar->EnableTool(TOOL_FILE_NEW, true); - toolbar->EnableTool(TOOL_FILE_OPEN, true); - toolbar->EnableTool(TOOL_FILE_SAVE, world->getDirty()); - toolbar->EnableTool(TOOL_MAP_ADD_ROOT, true); - toolbar->EnableTool(TOOL_MAP_ADD_CHILD, true); - - menuFile->Enable(MENU_FILE_NEW, true); - menuFile->Enable(MENU_FILE_OPEN, true); - menuFile->Enable(MENU_FILE_SAVE, world->getDirty()); - menuFile->Enable(MENU_MAP_ADD_ROOT, true); - menuFile->Enable(MENU_MAP_ADD_CHILD, true); + if (isAddingEntity) + { + addingEntity = true; + addEntityButton->Disable(); + cancelEntityButton->Enable(); + } else { + addingEntity = false; + addEntityButton->Enable(); + cancelEntityButton->Disable(); + } } void MapeditFrame::MapDirtyDidChange(bool dirty) @@ -568,3 +564,31 @@ wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newPar return copied; } + +void MapeditFrame::SetIsSettingStart(bool isSettingStart) +{ + if (isSettingStart) + { + setStartposButton->Disable(); + cancelStartposButton->Enable(); + } else { + SetStartposLabel(); + + setStartposButton->Enable(); + cancelStartposButton->Disable(); + } +} + +void MapeditFrame::SetStartposLabel() +{ + std::ostringstream mappos_out; + mappos_out << "Starting Position: "; + mappos_out << world->getStartingMap()->getTitle(); + mappos_out << " ("; + mappos_out << (int) world->getStartingPosition().first; + mappos_out << ","; + mappos_out << (int) world->getStartingPosition().second; + mappos_out << ")"; + + startposLabel->SetLabel(mappos_out.str()); +} diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index 6085eb2..067c848 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h @@ -28,9 +28,9 @@ class MapeditFrame : public wxFrame { MapeditFrame(std::unique_ptr world); MapeditWidget* GetMapEditor(); - void StartAddingEntity(); - void FinishAddingEntity(); + void SetIsAddingEntity(bool isAddingEntity); void MapDirtyDidChange(bool dirty); + void SetIsSettingStart(bool isSettingStart); static void NewWorld(); static bool OpenWorld(std::string filename); @@ -42,6 +42,7 @@ class MapeditFrame : public wxFrame { void populateMapTree(wxTreeItemId node, std::list> maps); void SelectMap(Map* map); wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent); + void SetStartposLabel(); void ZoomIn(wxCommandEvent& event); void ZoomOut(wxCommandEvent& event); @@ -63,6 +64,8 @@ class MapeditFrame : public wxFrame { void OnWillDragMap(wxTreeEvent& event); void OnDidDragMap(wxTreeEvent& event); void OnRightClickTree(wxTreeEvent& event); + void OnSetStartpos(wxCommandEvent& event); + void OnCancelSetStartpos(wxCommandEvent& event); std::unique_ptr world; Map* currentMap; @@ -79,6 +82,9 @@ class MapeditFrame : public wxFrame { wxTreeCtrl* mapTree; wxTreeItemId dragMap; wxMenu* mapTreePopup; + wxStaticText* startposLabel; + wxButton* setStartposButton; + wxButton* cancelStartposButton; bool addingEntity = false; diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 32541e6..0f8826c 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp @@ -113,6 +113,11 @@ bool Map::getExpanded() const return expanded; } +World* Map::getWorld() const +{ + return world; +} + void Map::setTitle(std::string title, bool dirty) { this->title = title; diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 5753cae..df3e237 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h @@ -20,6 +20,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 { @@ -57,6 +59,11 @@ struct MapObjectEntry { { return (object == other.object) && (position == other.position); } + + bool operator!=(MapObjectEntry& other) const + { + return (object != other.object) && (position != other.position); + } }; class Map { @@ -77,6 +84,7 @@ class Map { wxTreeItemId getTreeItemId() const; std::list> getChildren() const; bool getExpanded() const; + World* getWorld() const; void setTitle(std::string title, bool dirty = true); void setTileAt(int x, int y, int tile, bool dirty = true); diff --git a/tools/mapedit/src/widget.cpp b/tools/mapedit/src/widget.cpp index d50cf91..6cbedcd 100644 --- a/tools/mapedit/src/widget.cpp +++ b/tools/mapedit/src/widget.cpp @@ -66,48 +66,91 @@ void MapeditWidget::OnPaint(wxPaintEvent&) wxBitmap sprite = object->object->getSprite(); tiles_dc.SelectObject(sprite); - dc.StretchBlit(object->position.first*scale-vX, object->position.second*scale-vY, object->object->getWidth()*scale, object->object->getHeight()*scale, &tiles_dc, 0, 0, object->object->getWidth(), object->object->getHeight()); + wxPoint pos {(int) object->position.first*scale-vX, (int) object->position.second*scale-vY}; + wxSize size {object->object->getWidth()*scale, object->object->getHeight()*scale}; + dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, object->object->getWidth(), object->object->getHeight()); - if ((editMode == EditEntities) && (selectedEntity) && (object == selectedEntity)) + if (editMode == EditEntities) { - wxPen pen(*wxGREEN, 2); - dc.SetPen(pen); - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(object->position.first*scale-vX, object->position.second*scale-vY, object->object->getWidth()*scale, object->object->getHeight()*scale); + if (!selectedEntity) + { + wxPen pen(*wxYELLOW, 2); + dc.SetPen(pen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight()); + } else if (object == selectedEntity) + { + wxPen pen(*wxGREEN, 2); + dc.SetPen(pen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight()); + } } } - if (editMode == EditTiles) + if (map->getWorld()->getStartingMap()->getID() == map->getID()) + { + wxBitmap sprite = wxImage("res/Starla.png"); + tiles_dc.SelectObject(wxNullBitmap); + tiles_dc.SelectObject(sprite); + + std::pair startPos = map->getWorld()->getStartingPosition(); + + wxPoint pos {(int) startPos.first*scale-vX, (int) startPos.second*scale-vY}; + wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale}; + + dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]); + } + + if (mouseIsIn) { - if (mouseIsIn) + if (isSettingPos) + { + wxBitmap sprite = wxImage("res/Starla.png"); + tiles_dc.SelectObject(wxNullBitmap); + tiles_dc.SelectObject(sprite); + + wxPoint pos {mousePos.x - PLAYER_WIDTH[currentPlayer]/2*scale, mousePos.y - PLAYER_HEIGHT[currentPlayer]/2*scale}; + wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale}; + + dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]); + + wxPen pen(*wxGREEN, 2); + dc.SetPen(pen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight()); + } else if (editMode == EditTiles) { int tile = tileWidget->getSelected(); int x = (mousePos.x + vX) / (TILE_WIDTH * scale); int y = (mousePos.y + vY) / (TILE_HEIGHT * scale); + wxPoint pos {x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY}; + wxSize size {TILE_WIDTH*scale, TILE_HEIGHT*scale}; + tiles_dc.SelectObject(wxNullBitmap); tiles_dc.SelectObject(tiles); - dc.StretchBlit(x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale, &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); - + dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT); + wxPen pen(*wxGREEN, 2); dc.SetPen(pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale); - } - } else if (editMode == EditEntities) - { - if ((addingEntity != nullptr) && (mouseIsIn)) + dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight()); + } else if ((editMode == EditEntities) && (addingEntity != nullptr)) { wxBitmap sprite = addingEntity->getSprite(); tiles_dc.SelectObject(wxNullBitmap); tiles_dc.SelectObject(sprite); - - dc.StretchBlit(mousePos.x - addingEntity->getWidth()/2*scale, mousePos.y - addingEntity->getHeight()/2*scale, addingEntity->getWidth()*scale, addingEntity->getHeight()*scale, &tiles_dc, 0, 0, addingEntity->getWidth(), addingEntity->getHeight()); - + + wxPoint pos {mousePos.x - addingEntity->getWidth()/2*scale, mousePos.y - addingEntity->getHeight()/2*scale}; + wxSize size {addingEntity->getWidth()*scale, addingEntity->getHeight()*scale}; + + dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, addingEntity->getWidth(), addingEntity->getHeight()); + wxPen pen(*wxGREEN, 2); dc.SetPen(pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(mousePos.x - addingEntity->getWidth()/2*scale, mousePos.y - addingEntity->getHeight()/2*scale, addingEntity->getWidth()*scale, addingEntity->getHeight()*scale); + dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight()); } } } @@ -132,6 +175,13 @@ void MapeditWidget::OnClick(wxMouseEvent& event) { mouseIsDown = true; + int vX, vY; + GetViewStart(&vX, &vY); + int vXX, vYX; + GetScrollPixelsPerUnit(&vXX, &vYX); + vX *= vXX; + vY *= vYX; + if (editMode == EditTiles) { SetTile(event.GetPosition()); @@ -139,13 +189,6 @@ void MapeditWidget::OnClick(wxMouseEvent& event) { if (addingEntity != nullptr) { - int vX, vY; - GetViewStart(&vX, &vY); - int vXX, vYX; - GetScrollPixelsPerUnit(&vXX, &vYX); - vX *= vXX; - vY *= vYX; - int x = (event.GetPosition().x + vX) / scale - (addingEntity->getWidth() / 2); int y = (event.GetPosition().y + vY) / scale - (addingEntity->getHeight() / 2); @@ -156,17 +199,10 @@ void MapeditWidget::OnClick(wxMouseEvent& event) addingEntity = nullptr; - frame->FinishAddingEntity(); + frame->SetIsAddingEntity(false); Refresh(); } else { - int vX, vY; - GetViewStart(&vX, &vY); - int vXX, vYX; - GetScrollPixelsPerUnit(&vXX, &vYX); - vX *= vXX; - vY *= vYX; - int x = (event.GetPosition().x + vX) / scale; int y = (event.GetPosition().y + vY) / scale; @@ -178,7 +214,7 @@ void MapeditWidget::OnClick(wxMouseEvent& event) addingEntity = selectedEntity->object; map->removeObject(selectedEntity); selectedEntity.reset(); - frame->StartAddingEntity(); + frame->SetIsAddingEntity(true); } else { selectedEntity.reset(); } @@ -201,6 +237,18 @@ void MapeditWidget::OnClick(wxMouseEvent& event) } } + if (isSettingPos) + { + int x = (event.GetPosition().x + vX) / scale - (PLAYER_WIDTH[currentPlayer] / 2); + int y = (event.GetPosition().y + vY) / scale - (PLAYER_HEIGHT[currentPlayer] / 2); + + map->getWorld()->setStart(map, {x, y}); + isSettingPos = false; + frame->SetIsSettingStart(false); + + Refresh(); + } + event.Skip(); } @@ -225,6 +273,8 @@ void MapeditWidget::OnRightClick(wxMouseEvent& event) { map->removeObject(selectedEntity); selectedEntity.reset(); + + Refresh(); } } } @@ -290,7 +340,11 @@ void MapeditWidget::SetEditMode(EditMode editMode) void MapeditWidget::StartAddingEntity(MapObject* object) { addingEntity = object; + + // Turn everything else off selectedEntity = nullptr; + isSettingPos = false; + frame->SetIsSettingStart(false); } void MapeditWidget::CancelAddingEntity() @@ -298,6 +352,20 @@ void MapeditWidget::CancelAddingEntity() addingEntity = nullptr; } +void MapeditWidget::SetIsSettingStart(bool isSetting) +{ + if (isSetting) + { + isSettingPos = true; + + frame->SetIsAddingEntity(false); + addingEntity = nullptr; + selectedEntity = nullptr; + } else { + isSettingPos = false; + } +} + void MapeditWidget::SetMap(Map* map) { this->map = map; diff --git a/tools/mapedit/src/widget.h b/tools/mapedit/src/widget.h index 34627bc..67ebc01 100644 --- a/tools/mapedit/src/widget.h +++ b/tools/mapedit/src/widget.h @@ -30,6 +30,7 @@ class MapeditWidget : public wxScrolledWindow { void StartAddingEntity(MapObject* object); void CancelAddingEntity(); void SetMap(Map* map); + void SetIsSettingStart(bool isSetting); MapeditFrame* frame; @@ -55,6 +56,8 @@ class MapeditWidget : public wxScrolledWindow { wxPoint mousePos; bool mouseIsIn = false; EditMode editMode = EditTiles; + int currentPlayer = 0; + bool isSettingPos = false; MapObject* addingEntity = nullptr; std::shared_ptr selectedEntity; diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index c30f76c..3145e4e 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp @@ -59,6 +59,17 @@ World::World(std::string filename) rootChildren.push_back(atoi((char*) key)); } xmlFree(key); + } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos")) + { + xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); + if (idKey == 0) throw MapLoadException(filename); + startingMap = atoi((char*) idKey); + xmlFree(idKey); + + xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos"); + if (posKey == 0) throw MapLoadException(filename); + sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second); + xmlFree(posKey); } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) { xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); @@ -237,6 +248,22 @@ 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); + + // id= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap); + if (rc < 0) throw MapWriteException(name); + + // pos= + rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second); + if (rc < 0) throw MapWriteException(name); + + // + rc = xmlTextWriterEndElement(writer); + if (rc < 0) throw MapWriteException(name); + for (auto mapPair : maps) { Map& map = *mapPair.second; @@ -379,3 +406,21 @@ bool World::getEmpty() const { return empty; } + +Map* World::getStartingMap() const +{ + return getMap(startingMap).get(); +} + +std::pair World::getStartingPosition() const +{ + return startingPosition; +} + +void World::setStart(Map* map, std::pair startPos) +{ + startingMap = map->getID(); + startingPosition = startPos; + + setDirty(true); +} diff --git a/tools/mapedit/src/world.h b/tools/mapedit/src/world.h index a2b5235..68c960f 100644 --- a/tools/mapedit/src/world.h +++ b/tools/mapedit/src/world.h @@ -33,6 +33,9 @@ class World { std::list> getRootMaps() const; const std::map> getMaps() const; bool getEmpty() const; + Map* getStartingMap() const; + std::pair getStartingPosition() const; + void setStart(Map* map, std::pair startPos); private: MapeditFrame* parent; @@ -43,6 +46,8 @@ class World { int lastmap = 0; std::list rootChildren; bool empty = false; + int startingMap = 0; + std::pair startingPosition {100, 100}; }; #endif -- cgit 1.4.1