summary refs log tree commit diff stats
path: root/tools/mapedit/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mapedit/src')
-rw-r--r--tools/mapedit/src/frame.cpp120
-rw-r--r--tools/mapedit/src/frame.h10
-rw-r--r--tools/mapedit/src/map.cpp5
-rw-r--r--tools/mapedit/src/map.h8
-rw-r--r--tools/mapedit/src/widget.cpp138
-rw-r--r--tools/mapedit/src/widget.h3
-rw-r--r--tools/mapedit/src/world.cpp45
-rw-r--r--tools/mapedit/src/world.h5
8 files changed, 249 insertions, 85 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 94be15e..66775e1 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp
@@ -6,6 +6,7 @@
6#include "panel.h" 6#include "panel.h"
7#include <list> 7#include <list>
8#include <exception> 8#include <exception>
9#include <sstream>
9 10
10static std::list<wxWindow*> openWindows; 11static std::list<wxWindow*> openWindows;
11 12
@@ -27,7 +28,9 @@ enum {
27 MAP_EDITOR_TREE, 28 MAP_EDITOR_TREE,
28 MAP_TITLE_TEXTBOX, 29 MAP_TITLE_TEXTBOX,
29 ADD_ENTITY_BUTTON, 30 ADD_ENTITY_BUTTON,
30 CANCEL_ENTITY_BUTTON 31 CANCEL_ENTITY_BUTTON,
32 SET_STARTPOS_BUTTON,
33 CANCEL_STARTPOS_BUTTON
31}; 34};
32 35
33wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) 36wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
@@ -56,6 +59,8 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
56 EVT_TEXT(MAP_TITLE_TEXTBOX, MapeditFrame::OnTitleChange) 59 EVT_TEXT(MAP_TITLE_TEXTBOX, MapeditFrame::OnTitleChange)
57 EVT_BUTTON(ADD_ENTITY_BUTTON, MapeditFrame::OnAddEntity) 60 EVT_BUTTON(ADD_ENTITY_BUTTON, MapeditFrame::OnAddEntity)
58 EVT_BUTTON(CANCEL_ENTITY_BUTTON, MapeditFrame::OnCancelAddEntity) 61 EVT_BUTTON(CANCEL_ENTITY_BUTTON, MapeditFrame::OnCancelAddEntity)
62 EVT_BUTTON(SET_STARTPOS_BUTTON, MapeditFrame::OnSetStartpos)
63 EVT_BUTTON(CANCEL_STARTPOS_BUTTON, MapeditFrame::OnCancelSetStartpos)
59wxEND_EVENT_TABLE() 64wxEND_EVENT_TABLE()
60 65
61MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*2+TILE_WIDTH*6*6+10+10+150, GAME_HEIGHT*3)) 66MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*2+TILE_WIDTH*6*6+10+10+150, GAME_HEIGHT*3))
@@ -114,14 +119,27 @@ MapeditFrame::MapeditFrame(std::unique_ptr<World> world) : wxFrame(NULL, wxID_AN
114 // Set up property editor 119 // Set up property editor
115 wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY); 120 wxPanel* propertyEditor = new wxPanel(layout3, wxID_ANY);
116 titleBox = new wxTextCtrl(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle()); 121 titleBox = new wxTextCtrl(propertyEditor, MAP_TITLE_TEXTBOX, currentMap->getTitle());
122 titleBox->SetMaxLength(40);
117 123
118 wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:"); 124 wxStaticText* titleLabel = new wxStaticText(propertyEditor, wxID_ANY, "Title:");
119 125
126 startposLabel = new wxStaticText(propertyEditor, wxID_ANY, "Starting Position:");
127 SetStartposLabel();
128
129 setStartposButton = new wxButton(propertyEditor, SET_STARTPOS_BUTTON, "Set Starting Position");
130 cancelStartposButton = new wxButton(propertyEditor, CANCEL_STARTPOS_BUTTON, "Cancel");
131 cancelStartposButton->Disable();
132
120 wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL); 133 wxBoxSizer* propertySizer = new wxBoxSizer(wxVERTICAL);
121 wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL); 134 wxBoxSizer* propertySizer1 = new wxBoxSizer(wxHORIZONTAL);
122 propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10); 135 propertySizer1->Add(titleLabel, 0, wxALIGN_RIGHT | wxLEFT, 10);
123 propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10); 136 propertySizer1->Add(titleBox, 1, wxALIGN_LEFT | wxLEFT | wxRIGHT, 10);
124 propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10); 137 propertySizer->Add(propertySizer1, 1, wxEXPAND | wxTOP, 10);
138 wxBoxSizer* propertySizer2 = new wxBoxSizer(wxHORIZONTAL);
139 propertySizer2->Add(startposLabel, 0, wxALIGN_RIGHT | wxLEFT, 10);
140 propertySizer2->Add(setStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10);
141 propertySizer2->Add(cancelStartposButton, 0, wxALIGN_LEFT | wxLEFT, 10);
142 propertySizer->Add(propertySizer2, 1, wxEXPAND | wxTOP, 10);
125 propertyEditor->SetSizer(propertySizer); 143 propertyEditor->SetSizer(propertySizer);
126 propertySizer->SetSizeHints(propertyEditor); 144 propertySizer->SetSizeHints(propertyEditor);
127 145
@@ -386,22 +404,13 @@ void MapeditFrame::OnDidSelectMap(wxTreeEvent& event)
386 404
387void MapeditFrame::OnWillSelectMap(wxTreeEvent& event) 405void MapeditFrame::OnWillSelectMap(wxTreeEvent& event)
388{ 406{
389 if (addingEntity)
390 {
391 event.Veto();
392 return;
393 }
394
395 event.Skip(); 407 event.Skip();
396} 408}
397 409
398void MapeditFrame::OnWillDragMap(wxTreeEvent& event) 410void MapeditFrame::OnWillDragMap(wxTreeEvent& event)
399{ 411{
400 if (!addingEntity) 412 event.Allow();
401 { 413 dragMap = event.GetItem();
402 event.Allow();
403 dragMap = event.GetItem();
404 }
405} 414}
406 415
407void MapeditFrame::OnDidDragMap(wxTreeEvent& event) 416void MapeditFrame::OnDidDragMap(wxTreeEvent& event)
@@ -430,6 +439,18 @@ void MapeditFrame::OnRightClickTree(wxTreeEvent& event)
430 } 439 }
431} 440}
432 441
442void MapeditFrame::OnSetStartpos(wxCommandEvent&)
443{
444 SetIsSettingStart(true);
445 mapEditor->SetIsSettingStart(true);
446}
447
448void MapeditFrame::OnCancelSetStartpos(wxCommandEvent&)
449{
450 SetIsSettingStart(false);
451 mapEditor->SetIsSettingStart(false);
452}
453
433void MapeditFrame::NewWorld() 454void MapeditFrame::NewWorld()
434{ 455{
435 LaunchWindow(std::unique_ptr<World>(new World())); 456 LaunchWindow(std::unique_ptr<World>(new World()));
@@ -459,43 +480,18 @@ void MapeditFrame::LaunchWindow(std::unique_ptr<World> world)
459 frame->Show(true); 480 frame->Show(true);
460} 481}
461 482
462void MapeditFrame::StartAddingEntity() 483void MapeditFrame::SetIsAddingEntity(bool isAddingEntity)
463{
464 addingEntity = true;
465 addEntityButton->Disable();
466 cancelEntityButton->Enable();
467
468 toolbar->EnableTool(TOOL_FILE_NEW, false);
469 toolbar->EnableTool(TOOL_FILE_OPEN, false);
470 toolbar->EnableTool(TOOL_FILE_SAVE, false);
471 toolbar->EnableTool(TOOL_MAP_ADD_ROOT, false);
472 toolbar->EnableTool(TOOL_MAP_ADD_CHILD, false);
473
474 menuFile->Enable(MENU_FILE_NEW, false);
475 menuFile->Enable(MENU_FILE_OPEN, false);
476 menuFile->Enable(MENU_FILE_SAVE, false);
477 menuFile->Enable(MENU_MAP_ADD_ROOT, false);
478 menuFile->Enable(MENU_MAP_ADD_CHILD, false);
479}
480
481void MapeditFrame::FinishAddingEntity()
482{ 484{
483 addingEntity = false; 485 if (isAddingEntity)
484 addEntityButton->Enable(); 486 {
485 cancelEntityButton->Disable(); 487 addingEntity = true;
486 toolbar->Enable(); 488 addEntityButton->Disable();
487 489 cancelEntityButton->Enable();
488 toolbar->EnableTool(TOOL_FILE_NEW, true); 490 } else {
489 toolbar->EnableTool(TOOL_FILE_OPEN, true); 491 addingEntity = false;
490 toolbar->EnableTool(TOOL_FILE_SAVE, world->getDirty()); 492 addEntityButton->Enable();
491 toolbar->EnableTool(TOOL_MAP_ADD_ROOT, true); 493 cancelEntityButton->Disable();
492 toolbar->EnableTool(TOOL_MAP_ADD_CHILD, true); 494 }
493
494 menuFile->Enable(MENU_FILE_NEW, true);
495 menuFile->Enable(MENU_FILE_OPEN, true);
496 menuFile->Enable(MENU_FILE_SAVE, world->getDirty());
497 menuFile->Enable(MENU_MAP_ADD_ROOT, true);
498 menuFile->Enable(MENU_MAP_ADD_CHILD, true);
499} 495}
500 496
501void MapeditFrame::MapDirtyDidChange(bool dirty) 497void MapeditFrame::MapDirtyDidChange(bool dirty)
@@ -568,3 +564,31 @@ wxTreeItemId MapeditFrame::MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newPar
568 564
569 return copied; 565 return copied;
570} 566}
567
568void MapeditFrame::SetIsSettingStart(bool isSettingStart)
569{
570 if (isSettingStart)
571 {
572 setStartposButton->Disable();
573 cancelStartposButton->Enable();
574 } else {
575 SetStartposLabel();
576
577 setStartposButton->Enable();
578 cancelStartposButton->Disable();
579 }
580}
581
582void MapeditFrame::SetStartposLabel()
583{
584 std::ostringstream mappos_out;
585 mappos_out << "Starting Position: ";
586 mappos_out << world->getStartingMap()->getTitle();
587 mappos_out << " (";
588 mappos_out << (int) world->getStartingPosition().first;
589 mappos_out << ",";
590 mappos_out << (int) world->getStartingPosition().second;
591 mappos_out << ")";
592
593 startposLabel->SetLabel(mappos_out.str());
594}
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 {
28 MapeditFrame(std::unique_ptr<World> world); 28 MapeditFrame(std::unique_ptr<World> world);
29 29
30 MapeditWidget* GetMapEditor(); 30 MapeditWidget* GetMapEditor();
31 void StartAddingEntity(); 31 void SetIsAddingEntity(bool isAddingEntity);
32 void FinishAddingEntity();
33 void MapDirtyDidChange(bool dirty); 32 void MapDirtyDidChange(bool dirty);
33 void SetIsSettingStart(bool isSettingStart);
34 34
35 static void NewWorld(); 35 static void NewWorld();
36 static bool OpenWorld(std::string filename); 36 static bool OpenWorld(std::string filename);
@@ -42,6 +42,7 @@ class MapeditFrame : public wxFrame {
42 void populateMapTree(wxTreeItemId node, std::list<std::shared_ptr<Map>> maps); 42 void populateMapTree(wxTreeItemId node, std::list<std::shared_ptr<Map>> maps);
43 void SelectMap(Map* map); 43 void SelectMap(Map* map);
44 wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent); 44 wxTreeItemId MoveTreeNode(wxTreeItemId toCopy, wxTreeItemId newParent);
45 void SetStartposLabel();
45 46
46 void ZoomIn(wxCommandEvent& event); 47 void ZoomIn(wxCommandEvent& event);
47 void ZoomOut(wxCommandEvent& event); 48 void ZoomOut(wxCommandEvent& event);
@@ -63,6 +64,8 @@ class MapeditFrame : public wxFrame {
63 void OnWillDragMap(wxTreeEvent& event); 64 void OnWillDragMap(wxTreeEvent& event);
64 void OnDidDragMap(wxTreeEvent& event); 65 void OnDidDragMap(wxTreeEvent& event);
65 void OnRightClickTree(wxTreeEvent& event); 66 void OnRightClickTree(wxTreeEvent& event);
67 void OnSetStartpos(wxCommandEvent& event);
68 void OnCancelSetStartpos(wxCommandEvent& event);
66 69
67 std::unique_ptr<World> world; 70 std::unique_ptr<World> world;
68 Map* currentMap; 71 Map* currentMap;
@@ -79,6 +82,9 @@ class MapeditFrame : public wxFrame {
79 wxTreeCtrl* mapTree; 82 wxTreeCtrl* mapTree;
80 wxTreeItemId dragMap; 83 wxTreeItemId dragMap;
81 wxMenu* mapTreePopup; 84 wxMenu* mapTreePopup;
85 wxStaticText* startposLabel;
86 wxButton* setStartposButton;
87 wxButton* cancelStartposButton;
82 88
83 bool addingEntity = false; 89 bool addingEntity = false;
84 90
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
113 return expanded; 113 return expanded;
114} 114}
115 115
116World* Map::getWorld() const
117{
118 return world;
119}
120
116void Map::setTitle(std::string title, bool dirty) 121void Map::setTitle(std::string title, bool dirty)
117{ 122{
118 this->title = title; 123 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;
20const int GAME_HEIGHT = 200; 20const int GAME_HEIGHT = 200;
21const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH; 21const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH;
22const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1; 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};
23 25
24class MapLoadException: public std::exception 26class MapLoadException: public std::exception
25{ 27{
@@ -57,6 +59,11 @@ struct MapObjectEntry {
57 { 59 {
58 return (object == other.object) && (position == other.position); 60 return (object == other.object) && (position == other.position);
59 } 61 }
62
63 bool operator!=(MapObjectEntry& other) const
64 {
65 return (object != other.object) && (position != other.position);
66 }
60}; 67};
61 68
62class Map { 69class Map {
@@ -77,6 +84,7 @@ class Map {
77 wxTreeItemId getTreeItemId() const; 84 wxTreeItemId getTreeItemId() const;
78 std::list<std::shared_ptr<Map>> getChildren() const; 85 std::list<std::shared_ptr<Map>> getChildren() const;
79 bool getExpanded() const; 86 bool getExpanded() const;
87 World* getWorld() const;
80 88
81 void setTitle(std::string title, bool dirty = true); 89 void setTitle(std::string title, bool dirty = true);
82 void setTileAt(int x, int y, int tile, bool dirty = true); 90 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&)
66 wxBitmap sprite = object->object->getSprite(); 66 wxBitmap sprite = object->object->getSprite();
67 tiles_dc.SelectObject(sprite); 67 tiles_dc.SelectObject(sprite);
68 68
69 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()); 69 wxPoint pos {(int) object->position.first*scale-vX, (int) object->position.second*scale-vY};
70 wxSize size {object->object->getWidth()*scale, object->object->getHeight()*scale};
71 dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, object->object->getWidth(), object->object->getHeight());
70 72
71 if ((editMode == EditEntities) && (selectedEntity) && (object == selectedEntity)) 73 if (editMode == EditEntities)
72 { 74 {
73 wxPen pen(*wxGREEN, 2); 75 if (!selectedEntity)
74 dc.SetPen(pen); 76 {
75 dc.SetBrush(*wxTRANSPARENT_BRUSH); 77 wxPen pen(*wxYELLOW, 2);
76 dc.DrawRectangle(object->position.first*scale-vX, object->position.second*scale-vY, object->object->getWidth()*scale, object->object->getHeight()*scale); 78 dc.SetPen(pen);
79 dc.SetBrush(*wxTRANSPARENT_BRUSH);
80 dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight());
81 } else if (object == selectedEntity)
82 {
83 wxPen pen(*wxGREEN, 2);
84 dc.SetPen(pen);
85 dc.SetBrush(*wxTRANSPARENT_BRUSH);
86 dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight());
87 }
77 } 88 }
78 } 89 }
79 90
80 if (editMode == EditTiles) 91 if (map->getWorld()->getStartingMap()->getID() == map->getID())
92 {
93 wxBitmap sprite = wxImage("res/Starla.png");
94 tiles_dc.SelectObject(wxNullBitmap);
95 tiles_dc.SelectObject(sprite);
96
97 std::pair<double, double> startPos = map->getWorld()->getStartingPosition();
98
99 wxPoint pos {(int) startPos.first*scale-vX, (int) startPos.second*scale-vY};
100 wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale};
101
102 dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]);
103 }
104
105 if (mouseIsIn)
81 { 106 {
82 if (mouseIsIn) 107 if (isSettingPos)
108 {
109 wxBitmap sprite = wxImage("res/Starla.png");
110 tiles_dc.SelectObject(wxNullBitmap);
111 tiles_dc.SelectObject(sprite);
112
113 wxPoint pos {mousePos.x - PLAYER_WIDTH[currentPlayer]/2*scale, mousePos.y - PLAYER_HEIGHT[currentPlayer]/2*scale};
114 wxSize size {PLAYER_WIDTH[currentPlayer]*scale, PLAYER_HEIGHT[currentPlayer]*scale};
115
116 dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, PLAYER_WIDTH[currentPlayer], PLAYER_HEIGHT[currentPlayer]);
117
118 wxPen pen(*wxGREEN, 2);
119 dc.SetPen(pen);
120 dc.SetBrush(*wxTRANSPARENT_BRUSH);
121 dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight());
122 } else if (editMode == EditTiles)
83 { 123 {
84 int tile = tileWidget->getSelected(); 124 int tile = tileWidget->getSelected();
85 int x = (mousePos.x + vX) / (TILE_WIDTH * scale); 125 int x = (mousePos.x + vX) / (TILE_WIDTH * scale);
86 int y = (mousePos.y + vY) / (TILE_HEIGHT * scale); 126 int y = (mousePos.y + vY) / (TILE_HEIGHT * scale);
87 127
128 wxPoint pos {x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY};
129 wxSize size {TILE_WIDTH*scale, TILE_HEIGHT*scale};
130
88 tiles_dc.SelectObject(wxNullBitmap); 131 tiles_dc.SelectObject(wxNullBitmap);
89 tiles_dc.SelectObject(tiles); 132 tiles_dc.SelectObject(tiles);
90 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); 133 dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, tile%8*TILE_WIDTH, tile/8*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
91 134
92 wxPen pen(*wxGREEN, 2); 135 wxPen pen(*wxGREEN, 2);
93 dc.SetPen(pen); 136 dc.SetPen(pen);
94 dc.SetBrush(*wxTRANSPARENT_BRUSH); 137 dc.SetBrush(*wxTRANSPARENT_BRUSH);
95 dc.DrawRectangle(x*TILE_WIDTH*scale-vX, y*TILE_HEIGHT*scale-vY, TILE_WIDTH*scale, TILE_HEIGHT*scale); 138 dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight());
96 } 139 } else if ((editMode == EditEntities) && (addingEntity != nullptr))
97 } else if (editMode == EditEntities)
98 {
99 if ((addingEntity != nullptr) && (mouseIsIn))
100 { 140 {
101 wxBitmap sprite = addingEntity->getSprite(); 141 wxBitmap sprite = addingEntity->getSprite();
102 tiles_dc.SelectObject(wxNullBitmap); 142 tiles_dc.SelectObject(wxNullBitmap);
103 tiles_dc.SelectObject(sprite); 143 tiles_dc.SelectObject(sprite);
104 144
105 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()); 145 wxPoint pos {mousePos.x - addingEntity->getWidth()/2*scale, mousePos.y - addingEntity->getHeight()/2*scale};
106 146 wxSize size {addingEntity->getWidth()*scale, addingEntity->getHeight()*scale};
147
148 dc.StretchBlit(pos.x, pos.y, size.GetWidth(), size.GetHeight(), &tiles_dc, 0, 0, addingEntity->getWidth(), addingEntity->getHeight());
149
107 wxPen pen(*wxGREEN, 2); 150 wxPen pen(*wxGREEN, 2);
108 dc.SetPen(pen); 151 dc.SetPen(pen);
109 dc.SetBrush(*wxTRANSPARENT_BRUSH); 152 dc.SetBrush(*wxTRANSPARENT_BRUSH);
110 dc.DrawRectangle(mousePos.x - addingEntity->getWidth()/2*scale, mousePos.y - addingEntity->getHeight()/2*scale, addingEntity->getWidth()*scale, addingEntity->getHeight()*scale); 153 dc.DrawRectangle(pos.x, pos.y, size.GetWidth(), size.GetHeight());
111 } 154 }
112 } 155 }
113} 156}
@@ -132,6 +175,13 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
132{ 175{
133 mouseIsDown = true; 176 mouseIsDown = true;
134 177
178 int vX, vY;
179 GetViewStart(&vX, &vY);
180 int vXX, vYX;
181 GetScrollPixelsPerUnit(&vXX, &vYX);
182 vX *= vXX;
183 vY *= vYX;
184
135 if (editMode == EditTiles) 185 if (editMode == EditTiles)
136 { 186 {
137 SetTile(event.GetPosition()); 187 SetTile(event.GetPosition());
@@ -139,13 +189,6 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
139 { 189 {
140 if (addingEntity != nullptr) 190 if (addingEntity != nullptr)
141 { 191 {
142 int vX, vY;
143 GetViewStart(&vX, &vY);
144 int vXX, vYX;
145 GetScrollPixelsPerUnit(&vXX, &vYX);
146 vX *= vXX;
147 vY *= vYX;
148
149 int x = (event.GetPosition().x + vX) / scale - (addingEntity->getWidth() / 2); 192 int x = (event.GetPosition().x + vX) / scale - (addingEntity->getWidth() / 2);
150 int y = (event.GetPosition().y + vY) / scale - (addingEntity->getHeight() / 2); 193 int y = (event.GetPosition().y + vY) / scale - (addingEntity->getHeight() / 2);
151 194
@@ -156,17 +199,10 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
156 199
157 addingEntity = nullptr; 200 addingEntity = nullptr;
158 201
159 frame->FinishAddingEntity(); 202 frame->SetIsAddingEntity(false);
160 203
161 Refresh(); 204 Refresh();
162 } else { 205 } else {
163 int vX, vY;
164 GetViewStart(&vX, &vY);
165 int vXX, vYX;
166 GetScrollPixelsPerUnit(&vXX, &vYX);
167 vX *= vXX;
168 vY *= vYX;
169
170 int x = (event.GetPosition().x + vX) / scale; 206 int x = (event.GetPosition().x + vX) / scale;
171 int y = (event.GetPosition().y + vY) / scale; 207 int y = (event.GetPosition().y + vY) / scale;
172 208
@@ -178,7 +214,7 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
178 addingEntity = selectedEntity->object; 214 addingEntity = selectedEntity->object;
179 map->removeObject(selectedEntity); 215 map->removeObject(selectedEntity);
180 selectedEntity.reset(); 216 selectedEntity.reset();
181 frame->StartAddingEntity(); 217 frame->SetIsAddingEntity(true);
182 } else { 218 } else {
183 selectedEntity.reset(); 219 selectedEntity.reset();
184 } 220 }
@@ -201,6 +237,18 @@ void MapeditWidget::OnClick(wxMouseEvent& event)
201 } 237 }
202 } 238 }
203 239
240 if (isSettingPos)
241 {
242 int x = (event.GetPosition().x + vX) / scale - (PLAYER_WIDTH[currentPlayer] / 2);
243 int y = (event.GetPosition().y + vY) / scale - (PLAYER_HEIGHT[currentPlayer] / 2);
244
245 map->getWorld()->setStart(map, {x, y});
246 isSettingPos = false;
247 frame->SetIsSettingStart(false);
248
249 Refresh();
250 }
251
204 event.Skip(); 252 event.Skip();
205} 253}
206 254
@@ -225,6 +273,8 @@ void MapeditWidget::OnRightClick(wxMouseEvent& event)
225 { 273 {
226 map->removeObject(selectedEntity); 274 map->removeObject(selectedEntity);
227 selectedEntity.reset(); 275 selectedEntity.reset();
276
277 Refresh();
228 } 278 }
229 } 279 }
230 } 280 }
@@ -290,7 +340,11 @@ void MapeditWidget::SetEditMode(EditMode editMode)
290void MapeditWidget::StartAddingEntity(MapObject* object) 340void MapeditWidget::StartAddingEntity(MapObject* object)
291{ 341{
292 addingEntity = object; 342 addingEntity = object;
343
344 // Turn everything else off
293 selectedEntity = nullptr; 345 selectedEntity = nullptr;
346 isSettingPos = false;
347 frame->SetIsSettingStart(false);
294} 348}
295 349
296void MapeditWidget::CancelAddingEntity() 350void MapeditWidget::CancelAddingEntity()
@@ -298,6 +352,20 @@ void MapeditWidget::CancelAddingEntity()
298 addingEntity = nullptr; 352 addingEntity = nullptr;
299} 353}
300 354
355void MapeditWidget::SetIsSettingStart(bool isSetting)
356{
357 if (isSetting)
358 {
359 isSettingPos = true;
360
361 frame->SetIsAddingEntity(false);
362 addingEntity = nullptr;
363 selectedEntity = nullptr;
364 } else {
365 isSettingPos = false;
366 }
367}
368
301void MapeditWidget::SetMap(Map* map) 369void MapeditWidget::SetMap(Map* map)
302{ 370{
303 this->map = map; 371 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 {
30 void StartAddingEntity(MapObject* object); 30 void StartAddingEntity(MapObject* object);
31 void CancelAddingEntity(); 31 void CancelAddingEntity();
32 void SetMap(Map* map); 32 void SetMap(Map* map);
33 void SetIsSettingStart(bool isSetting);
33 34
34 MapeditFrame* frame; 35 MapeditFrame* frame;
35 36
@@ -55,6 +56,8 @@ class MapeditWidget : public wxScrolledWindow {
55 wxPoint mousePos; 56 wxPoint mousePos;
56 bool mouseIsIn = false; 57 bool mouseIsIn = false;
57 EditMode editMode = EditTiles; 58 EditMode editMode = EditTiles;
59 int currentPlayer = 0;
60 bool isSettingPos = false;
58 61
59 MapObject* addingEntity = nullptr; 62 MapObject* addingEntity = nullptr;
60 std::shared_ptr<MapObjectEntry> selectedEntity; 63 std::shared_ptr<MapObjectEntry> 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)
59 rootChildren.push_back(atoi((char*) key)); 59 rootChildren.push_back(atoi((char*) key));
60 } 60 }
61 xmlFree(key); 61 xmlFree(key);
62 } else if (!xmlStrcmp(node->name, (const xmlChar*) "startpos"))
63 {
64 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
65 if (idKey == 0) throw MapLoadException(filename);
66 startingMap = atoi((char*) idKey);
67 xmlFree(idKey);
68
69 xmlChar* posKey = xmlGetProp(node, (xmlChar*) "pos");
70 if (posKey == 0) throw MapLoadException(filename);
71 sscanf((char*) posKey, "%d,%d", &startingPosition.first, &startingPosition.second);
72 xmlFree(posKey);
62 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map")) 73 } else if (!xmlStrcmp(node->name, (const xmlChar*) "map"))
63 { 74 {
64 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id"); 75 xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
@@ -237,6 +248,22 @@ void World::save(std::string name, wxTreeCtrl* mapTree)
237 if (rc < 0) throw MapWriteException(name); 248 if (rc < 0) throw MapWriteException(name);
238 } 249 }
239 250
251 // <startpos>
252 rc = xmlTextWriterStartElement(writer, (xmlChar*) "startpos");
253 if (rc < 0) throw MapWriteException(name);
254
255 // id=
256 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "id", "%d", startingMap);
257 if (rc < 0) throw MapWriteException(name);
258
259 // pos=
260 rc = xmlTextWriterWriteFormatAttribute(writer, (xmlChar*) "pos", "%d,%d", startingPosition.first, startingPosition.second);
261 if (rc < 0) throw MapWriteException(name);
262
263 // </startpos>
264 rc = xmlTextWriterEndElement(writer);
265 if (rc < 0) throw MapWriteException(name);
266
240 for (auto mapPair : maps) 267 for (auto mapPair : maps)
241 { 268 {
242 Map& map = *mapPair.second; 269 Map& map = *mapPair.second;
@@ -379,3 +406,21 @@ bool World::getEmpty() const
379{ 406{
380 return empty; 407 return empty;
381} 408}
409
410Map* World::getStartingMap() const
411{
412 return getMap(startingMap).get();
413}
414
415std::pair<double, double> World::getStartingPosition() const
416{
417 return startingPosition;
418}
419
420void World::setStart(Map* map, std::pair<double, double> startPos)
421{
422 startingMap = map->getID();
423 startingPosition = startPos;
424
425 setDirty(true);
426}
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 {
33 std::list<std::shared_ptr<Map>> getRootMaps() const; 33 std::list<std::shared_ptr<Map>> getRootMaps() const;
34 const std::map<int, std::shared_ptr<Map>> getMaps() const; 34 const std::map<int, std::shared_ptr<Map>> getMaps() const;
35 bool getEmpty() const; 35 bool getEmpty() const;
36 Map* getStartingMap() const;
37 std::pair<double, double> getStartingPosition() const;
38 void setStart(Map* map, std::pair<double, double> startPos);
36 39
37 private: 40 private:
38 MapeditFrame* parent; 41 MapeditFrame* parent;
@@ -43,6 +46,8 @@ class World {
43 int lastmap = 0; 46 int lastmap = 0;
44 std::list<int> rootChildren; 47 std::list<int> rootChildren;
45 bool empty = false; 48 bool empty = false;
49 int startingMap = 0;
50 std::pair<int, int> startingPosition {100, 100};
46}; 51};
47 52
48#endif 53#endif