summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-16 10:57:03 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-16 10:57:03 -0400
commit36536297aac5c07e3d5fb96abed74570fc7615e9 (patch)
tree51e51ade3bb8804ac63fd625374ea7b6098b3539 /tools
parent54b664622737740bbb42c13d594b66a21d58ca5f (diff)
downloadtherapy-36536297aac5c07e3d5fb96abed74570fc7615e9.tar.gz
therapy-36536297aac5c07e3d5fb96abed74570fc7615e9.tar.bz2
therapy-36536297aac5c07e3d5fb96abed74570fc7615e9.zip
Added toolbar with file buttons to map editor
Diffstat (limited to 'tools')
-rw-r--r--tools/mapedit/src/frame.cpp23
-rw-r--r--tools/mapedit/src/frame.h2
-rw-r--r--tools/mapedit/src/map.cpp28
-rw-r--r--tools/mapedit/src/map.h7
4 files changed, 54 insertions, 6 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 0b03448..a38b861 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp
@@ -14,7 +14,10 @@ enum {
14 MENU_FILE_NEW, 14 MENU_FILE_NEW,
15 MENU_FILE_OPEN, 15 MENU_FILE_OPEN,
16 MENU_FILE_SAVE, 16 MENU_FILE_SAVE,
17 MENU_FILE_CLOSE 17 MENU_FILE_CLOSE,
18 TOOL_FILE_NEW,
19 TOOL_FILE_OPEN,
20 TOOL_FILE_SAVE
18}; 21};
19 22
20wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame) 23wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
@@ -24,12 +27,17 @@ wxBEGIN_EVENT_TABLE(MapeditFrame, wxFrame)
24 EVT_MENU(MENU_FILE_NEW, MapeditFrame::OnNew) 27 EVT_MENU(MENU_FILE_NEW, MapeditFrame::OnNew)
25 EVT_MENU(MENU_FILE_OPEN, MapeditFrame::OnOpen) 28 EVT_MENU(MENU_FILE_OPEN, MapeditFrame::OnOpen)
26 EVT_MENU(MENU_FILE_SAVE, MapeditFrame::OnSave) 29 EVT_MENU(MENU_FILE_SAVE, MapeditFrame::OnSave)
30 EVT_TOOL(TOOL_FILE_NEW, MapeditFrame::OnNew)
31 EVT_TOOL(TOOL_FILE_OPEN, MapeditFrame::OnOpen)
32 EVT_TOOL(TOOL_FILE_SAVE, MapeditFrame::OnSave)
27 EVT_MENU(MENU_FILE_CLOSE, MapeditFrame::OnClose) 33 EVT_MENU(MENU_FILE_CLOSE, MapeditFrame::OnClose)
28 EVT_CLOSE(MapeditFrame::OnExit) 34 EVT_CLOSE(MapeditFrame::OnExit)
29wxEND_EVENT_TABLE() 35wxEND_EVENT_TABLE()
30 36
31MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map), filename(filename) 37MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_ANY, "Map Editor", wxDefaultPosition, wxSize(GAME_WIDTH*3, GAME_HEIGHT*2)), map(map), filename(filename)
32{ 38{
39 this->map.frame = this;
40
33 wxMenu* menuFile = new wxMenu; 41 wxMenu* menuFile = new wxMenu;
34 menuFile->Append(MENU_FILE_NEW, "New\tCtrl-N"); 42 menuFile->Append(MENU_FILE_NEW, "New\tCtrl-N");
35 menuFile->Append(MENU_FILE_OPEN, "Open\tCtrl-O"); 43 menuFile->Append(MENU_FILE_OPEN, "Open\tCtrl-O");
@@ -137,6 +145,14 @@ MapeditFrame::MapeditFrame(Map map, std::string filename) : wxFrame(NULL, wxID_A
137 splitterSizer->Add(propertyEditor, 0, wxALIGN_TOP, wxALIGN_LEFT, 0); 145 splitterSizer->Add(propertyEditor, 0, wxALIGN_TOP, wxALIGN_LEFT, 0);
138 layout3->SetSizer(splitterSizer); 146 layout3->SetSizer(splitterSizer);
139 splitterSizer->SetSizeHints(layout3); 147 splitterSizer->SetSizeHints(layout3);
148
149 // Toolbar time!
150 toolbar = CreateToolBar();
151 toolbar->AddTool(TOOL_FILE_NEW, "New", wxBitmap(wxImage("res/page_add.png")));
152 toolbar->AddTool(TOOL_FILE_OPEN, "Open", wxBitmap(wxImage("res/folder_page.png")));
153 toolbar->AddTool(TOOL_FILE_SAVE, "Save", wxBitmap(wxImage("res/disk.png")));
154 toolbar->EnableTool(TOOL_FILE_SAVE, this->map.getDirty());
155 toolbar->Realize();
140} 156}
141 157
142void MapeditFrame::OnExit(wxCloseEvent& event) 158void MapeditFrame::OnExit(wxCloseEvent& event)
@@ -314,3 +330,8 @@ void MapeditFrame::FinishAddingEntity()
314 addEntityButton->Enable(); 330 addEntityButton->Enable();
315 cancelEntityButton->Disable(); 331 cancelEntityButton->Disable();
316} 332}
333
334void MapeditFrame::MapDirtyDidChange(bool dirty)
335{
336 toolbar->EnableTool(TOOL_FILE_SAVE, dirty);
337}
diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index 1cce4f3..4aa44c5 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h
@@ -21,6 +21,7 @@ class MapeditFrame : public wxFrame {
21 MapeditWidget* GetMapEditor(); 21 MapeditWidget* GetMapEditor();
22 void StartAddingEntity(); 22 void StartAddingEntity();
23 void FinishAddingEntity(); 23 void FinishAddingEntity();
24 void MapDirtyDidChange(bool dirty);
24 25
25 static void NewMap(); 26 static void NewMap();
26 static void OpenMap(const char* filename); 27 static void OpenMap(const char* filename);
@@ -53,6 +54,7 @@ class MapeditFrame : public wxFrame {
53 wxChoice* entityTypeBox; 54 wxChoice* entityTypeBox;
54 wxButton* addEntityButton; 55 wxButton* addEntityButton;
55 wxButton* cancelEntityButton; 56 wxButton* cancelEntityButton;
57 wxToolBar* toolbar;
56 58
57 bool addingEntity = false; 59 bool addingEntity = false;
58 60
diff --git a/tools/mapedit/src/map.cpp b/tools/mapedit/src/map.cpp index 2799a4e..f9c07fc 100644 --- a/tools/mapedit/src/map.cpp +++ b/tools/mapedit/src/map.cpp
@@ -2,6 +2,7 @@
2#include <libxml/parser.h> 2#include <libxml/parser.h>
3#include <libxml/xmlwriter.h> 3#include <libxml/xmlwriter.h>
4#include <sstream> 4#include <sstream>
5#include "frame.h"
5 6
6Map::Map() 7Map::Map()
7{ 8{
@@ -96,6 +97,7 @@ Map::Map(const Map& map)
96 rightmap = map.rightmap; 97 rightmap = map.rightmap;
97 dirty = map.dirty; 98 dirty = map.dirty;
98 objects = map.objects; 99 objects = map.objects;
100 frame = map.frame;
99} 101}
100 102
101Map::Map(Map&& map) : Map() 103Map::Map(Map&& map) : Map()
@@ -123,6 +125,7 @@ void swap(Map& first, Map& second)
123 std::swap(first.rightmap, second.rightmap); 125 std::swap(first.rightmap, second.rightmap);
124 std::swap(first.dirty, second.dirty); 126 std::swap(first.dirty, second.dirty);
125 std::swap(first.objects, second.objects); 127 std::swap(first.objects, second.objects);
128 std::swap(first.frame, second.frame);
126} 129}
127 130
128#define MY_ENCODING "ISO-8859-1" 131#define MY_ENCODING "ISO-8859-1"
@@ -197,7 +200,7 @@ void Map::save(std::string name)
197 200
198 xmlFreeTextWriter(writer); 201 xmlFreeTextWriter(writer);
199 202
200 dirty = false; 203 setDirty(false);
201} 204}
202 205
203bool Map::hasUnsavedChanges() const 206bool Map::hasUnsavedChanges() const
@@ -207,7 +210,7 @@ bool Map::hasUnsavedChanges() const
207 210
208void Map::setTileAt(int x, int y, int tile) 211void Map::setTileAt(int x, int y, int tile)
209{ 212{
210 dirty = true; 213 setDirty(true);
211 mapdata[x+y*MAP_WIDTH] = tile; 214 mapdata[x+y*MAP_WIDTH] = tile;
212} 215}
213 216
@@ -223,7 +226,7 @@ std::string Map::getTitle() const
223 226
224void Map::setTitle(std::string title) 227void Map::setTitle(std::string title)
225{ 228{
226 dirty = true; 229 setDirty(true);
227 this->title = title; 230 this->title = title;
228} 231}
229 232
@@ -234,12 +237,27 @@ const std::list<std::shared_ptr<MapObjectEntry>>& Map::getObjects() const
234 237
235void Map::addObject(std::shared_ptr<MapObjectEntry>& obj) 238void Map::addObject(std::shared_ptr<MapObjectEntry>& obj)
236{ 239{
237 dirty = true; 240 setDirty(true);
238 objects.push_back(obj); 241 objects.push_back(obj);
239} 242}
240 243
241void Map::removeObject(std::shared_ptr<MapObjectEntry>& obj) 244void Map::removeObject(std::shared_ptr<MapObjectEntry>& obj)
242{ 245{
243 dirty = true; 246 setDirty(true);
244 objects.remove(obj); 247 objects.remove(obj);
245} 248}
249
250bool Map::getDirty() const
251{
252 return dirty;
253}
254
255void Map::setDirty(bool dirty)
256{
257 this->dirty = dirty;
258
259 if (frame != nullptr)
260 {
261 frame->MapDirtyDidChange(dirty);
262 }
263}
diff --git a/tools/mapedit/src/map.h b/tools/mapedit/src/map.h index 16bbb4c..a2b9cb8 100644 --- a/tools/mapedit/src/map.h +++ b/tools/mapedit/src/map.h
@@ -8,6 +8,8 @@
8#include "object.h" 8#include "object.h"
9#include <memory> 9#include <memory>
10 10
11class MapeditFrame;
12
11const int TILE_WIDTH = 8; 13const int TILE_WIDTH = 8;
12const int TILE_HEIGHT = 8; 14const int TILE_HEIGHT = 8;
13const int GAME_WIDTH = 320; 15const int GAME_WIDTH = 320;
@@ -72,8 +74,13 @@ class Map {
72 const std::list<std::shared_ptr<MapObjectEntry>>& getObjects() const; 74 const std::list<std::shared_ptr<MapObjectEntry>>& getObjects() const;
73 void addObject(std::shared_ptr<MapObjectEntry>& obj); 75 void addObject(std::shared_ptr<MapObjectEntry>& obj);
74 void removeObject(std::shared_ptr<MapObjectEntry>& obj); 76 void removeObject(std::shared_ptr<MapObjectEntry>& obj);
77 bool getDirty() const;
78
79 MapeditFrame* frame;
75 80
76 private: 81 private:
82 void setDirty(bool dirty);
83
77 std::list<std::shared_ptr<MapObjectEntry>> objects; 84 std::list<std::shared_ptr<MapObjectEntry>> objects;
78 int* mapdata; 85 int* mapdata;
79 std::string title; 86 std::string title;