summary refs log tree commit diff stats
path: root/tools/mapedit/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-16 17:20:03 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-16 17:20:03 -0400
commit8b61d93fc869ea39a78cdc134002ef11bf3e69d3 (patch)
treec2aca3668c058cbdc7dfd9537802750f9c4f6600 /tools/mapedit/src
parent82fb304e61191f27403b5dbfaa90f24d625dee87 (diff)
downloadtherapy-8b61d93fc869ea39a78cdc134002ef11bf3e69d3.tar.gz
therapy-8b61d93fc869ea39a78cdc134002ef11bf3e69d3.tar.bz2
therapy-8b61d93fc869ea39a78cdc134002ef11bf3e69d3.zip
Opening a file in the map editor closes the current window if the current window is a blank slate
Diffstat (limited to 'tools/mapedit/src')
-rw-r--r--tools/mapedit/src/frame.cpp14
-rw-r--r--tools/mapedit/src/frame.h2
-rw-r--r--tools/mapedit/src/world.cpp7
-rw-r--r--tools/mapedit/src/world.h2
4 files changed, 22 insertions, 3 deletions
diff --git a/tools/mapedit/src/frame.cpp b/tools/mapedit/src/frame.cpp index 934e0f8..94be15e 100644 --- a/tools/mapedit/src/frame.cpp +++ b/tools/mapedit/src/frame.cpp
@@ -265,7 +265,13 @@ void MapeditFrame::OnOpen(wxCommandEvent&)
265 return; 265 return;
266 } 266 }
267 267
268 OpenWorld(openFileDialog.GetPath().ToStdString()); 268 if (OpenWorld(openFileDialog.GetPath().ToStdString()))
269 {
270 if (world->getEmpty())
271 {
272 Close(true);
273 }
274 }
269} 275}
270 276
271void MapeditFrame::OnSave(wxCommandEvent&) 277void MapeditFrame::OnSave(wxCommandEvent&)
@@ -429,17 +435,21 @@ void MapeditFrame::NewWorld()
429 LaunchWindow(std::unique_ptr<World>(new World())); 435 LaunchWindow(std::unique_ptr<World>(new World()));
430} 436}
431 437
432void MapeditFrame::OpenWorld(std::string filename) 438bool MapeditFrame::OpenWorld(std::string filename)
433{ 439{
434 try 440 try
435 { 441 {
436 auto world = std::unique_ptr<World>(new World(filename)); 442 auto world = std::unique_ptr<World>(new World(filename));
437 443
438 LaunchWindow(std::move(world)); 444 LaunchWindow(std::move(world));
445
446 return true;
439 } catch (std::exception& ex) 447 } catch (std::exception& ex)
440 { 448 {
441 wxMessageBox(ex.what(), "Error loading world", wxOK | wxCENTRE | wxICON_ERROR); 449 wxMessageBox(ex.what(), "Error loading world", wxOK | wxCENTRE | wxICON_ERROR);
442 } 450 }
451
452 return false;
443} 453}
444 454
445void MapeditFrame::LaunchWindow(std::unique_ptr<World> world) 455void MapeditFrame::LaunchWindow(std::unique_ptr<World> world)
diff --git a/tools/mapedit/src/frame.h b/tools/mapedit/src/frame.h index 4844485..6085eb2 100644 --- a/tools/mapedit/src/frame.h +++ b/tools/mapedit/src/frame.h
@@ -33,7 +33,7 @@ class MapeditFrame : public wxFrame {
33 void MapDirtyDidChange(bool dirty); 33 void MapDirtyDidChange(bool dirty);
34 34
35 static void NewWorld(); 35 static void NewWorld();
36 static void OpenWorld(std::string filename); 36 static bool OpenWorld(std::string filename);
37 37
38 std::list<wxWindow*>::iterator closer; 38 std::list<wxWindow*>::iterator closer;
39 39
diff --git a/tools/mapedit/src/world.cpp b/tools/mapedit/src/world.cpp index f7b541d..c30f76c 100644 --- a/tools/mapedit/src/world.cpp +++ b/tools/mapedit/src/world.cpp
@@ -9,6 +9,7 @@ World::World()
9 newMap(); 9 newMap();
10 10
11 rootChildren.push_back(0); 11 rootChildren.push_back(0);
12 empty = true;
12} 13}
13 14
14World::World(std::string filename) 15World::World(std::string filename)
@@ -170,6 +171,7 @@ std::shared_ptr<Map> World::getMap(int id) const
170 171
171void World::setDirty(bool dirty) 172void World::setDirty(bool dirty)
172{ 173{
174 if (dirty) empty = false;
173 this->dirty = dirty; 175 this->dirty = dirty;
174 parent->MapDirtyDidChange(dirty); 176 parent->MapDirtyDidChange(dirty);
175} 177}
@@ -372,3 +374,8 @@ void World::setLastMap(Map* map)
372{ 374{
373 lastmap = map->getID(); 375 lastmap = map->getID();
374} 376}
377
378bool World::getEmpty() const
379{
380 return empty;
381}
diff --git a/tools/mapedit/src/world.h b/tools/mapedit/src/world.h index c30f4b4..a2b5235 100644 --- a/tools/mapedit/src/world.h +++ b/tools/mapedit/src/world.h
@@ -32,6 +32,7 @@ class World {
32 void setLastMap(Map* map); 32 void setLastMap(Map* map);
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 36
36 private: 37 private:
37 MapeditFrame* parent; 38 MapeditFrame* parent;
@@ -41,6 +42,7 @@ class World {
41 std::string filename; 42 std::string filename;
42 int lastmap = 0; 43 int lastmap = 0;
43 std::list<int> rootChildren; 44 std::list<int> rootChildren;
45 bool empty = false;
44}; 46};
45 47
46#endif 48#endif