From 8b61d93fc869ea39a78cdc134002ef11bf3e69d3 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Mar 2015 17:20:03 -0400 Subject: Opening a file in the map editor closes the current window if the current window is a blank slate --- tools/mapedit/src/frame.cpp | 14 ++++++++++++-- tools/mapedit/src/frame.h | 2 +- tools/mapedit/src/world.cpp | 7 +++++++ tools/mapedit/src/world.h | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) (limited to 'tools') 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&) return; } - OpenWorld(openFileDialog.GetPath().ToStdString()); + if (OpenWorld(openFileDialog.GetPath().ToStdString())) + { + if (world->getEmpty()) + { + Close(true); + } + } } void MapeditFrame::OnSave(wxCommandEvent&) @@ -429,17 +435,21 @@ void MapeditFrame::NewWorld() LaunchWindow(std::unique_ptr(new World())); } -void MapeditFrame::OpenWorld(std::string filename) +bool MapeditFrame::OpenWorld(std::string filename) { try { auto world = std::unique_ptr(new World(filename)); LaunchWindow(std::move(world)); + + return true; } catch (std::exception& ex) { wxMessageBox(ex.what(), "Error loading world", wxOK | wxCENTRE | wxICON_ERROR); } + + return false; } void MapeditFrame::LaunchWindow(std::unique_ptr 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 { void MapDirtyDidChange(bool dirty); static void NewWorld(); - static void OpenWorld(std::string filename); + static bool OpenWorld(std::string filename); std::list::iterator closer; 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() newMap(); rootChildren.push_back(0); + empty = true; } World::World(std::string filename) @@ -170,6 +171,7 @@ std::shared_ptr World::getMap(int id) const void World::setDirty(bool dirty) { + if (dirty) empty = false; this->dirty = dirty; parent->MapDirtyDidChange(dirty); } @@ -372,3 +374,8 @@ void World::setLastMap(Map* map) { lastmap = map->getID(); } + +bool World::getEmpty() const +{ + return empty; +} 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 { void setLastMap(Map* map); std::list> getRootMaps() const; const std::map> getMaps() const; + bool getEmpty() const; private: MapeditFrame* parent; @@ -41,6 +42,7 @@ class World { std::string filename; int lastmap = 0; std::list rootChildren; + bool empty = false; }; #endif -- cgit 1.4.1