From fc93f11f6e0352107ed3e7863a73f538c7ea8a79 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 26 Jul 2009 21:23:26 +0100 Subject: [PATCH] Tidy up building dialog a bit --- include/IBuilding.hpp | 1 + src/Building.cpp | 1 + src/Editor.cpp | 54 ++++++++++++++++++++++++++++++++++++++----- src/Map.cpp | 11 +++++---- src/Resource.cpp | 3 ++- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/include/IBuilding.hpp b/include/IBuilding.hpp index 074004a..8947052 100644 --- a/include/IBuilding.hpp +++ b/include/IBuilding.hpp @@ -28,6 +28,7 @@ struct IBuilding { virtual ~IBuilding() {} virtual IModelPtr model() const = 0; + virtual const string& name() const = 0; }; typedef shared_ptr IBuildingPtr; diff --git a/src/Building.cpp b/src/Building.cpp index 92de197..8260bbd 100644 --- a/src/Building.cpp +++ b/src/Building.cpp @@ -28,6 +28,7 @@ public: // IBuildingInterface IModelPtr model() const { return myModel; } + const string& name() const { return myName; } // IXMLCallback interface void text(const string& localName, const string& aString); diff --git a/src/Editor.cpp b/src/Editor.cpp index 651aa2f..1c449a2 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -109,17 +109,45 @@ namespace { Editor* theEditor = NULL; - static IBuildingPtr REMOVE_ME; + // Data related to the building picking dialog + struct BuildingPicker { + BuildingPicker() + { + enumResources("buildings", all); + + if (all.empty()) + warn() << "No buildings found"; + } + + void switchTo() + { + if (!active) { + active = loadBuilding(all.front()->name()); + theModelViewer->setModel(active->model()); + } + } + + void next() + { + + } + + void prev() + { + + } + + IBuildingPtr active; + ResourceList all; + } *theBuildingPicker; void changeTool(Fl_Widget* aWidget, Editor::Tool aTool) { theToolMenu->label(theToolMenu->text()); theEditor->setTool(aTool); - if (aTool == Editor::BUILDING_TOOL) { - REMOVE_ME = loadBuilding("white_house"); - theModelViewer->setModel(REMOVE_ME->model()); - } + if (aTool == Editor::BUILDING_TOOL) + theBuildingPicker->switchTo(); } void onSaveClick(Fl_Widget* aWidget) @@ -131,6 +159,16 @@ namespace { { theModelViewer->rotate(90.0f); } + + void onBldNextClick(Fl_Widget* aWidget) + { + theBuildingPicker->next(); + } + + void onBldPrevClick(Fl_Widget* aWidget) + { + theBuildingPicker->prev(); + } } // Add the editor panel to the FLTK window @@ -145,11 +183,15 @@ void addEditorGUI() theModelViewer = new ModelViewer(0, 40, panelW, 200); theBldPrevButton = new Fl_Button(0, 240, 60, 25, "Prev"); + theBldRotateButton->callback(onBldPrevClick); theBldNextButton = new Fl_Button(60, 240, 60, 25, "Next"); + theBldRotateButton->callback(onBldNextClick); theBldRotateButton = new Fl_Button(120, 240, 60, 25, "Rotate"); theBldRotateButton->callback(onBldRotateClick); + + theBuildingPicker = new BuildingPicker; theSaveButton = new Fl_Button(0, 273, panelW, 25, "Save"); theSaveButton->callback(onSaveClick); @@ -558,7 +600,7 @@ void Editor::onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, myMap->extendStation(myDragBegin, myDragEnd); break; case BUILDING_TOOL: - myMap->placeBuilding(myDragBegin, REMOVE_ME); + myMap->placeBuilding(myDragBegin, theBuildingPicker->active); break; } diff --git a/src/Map.cpp b/src/Map.cpp index 232c491..41e3924 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -959,7 +959,10 @@ void Map::lowerArea(const Point& aStartPos, void Map::placeBuilding(Point aPoint, IBuildingPtr aBuilding) { - tileAt(aPoint.x, aPoint.y).building = aBuilding; + if (tileAt(aPoint.x, aPoint.y).track) + warn() << "Cannot place building on track"; + else + tileAt(aPoint.x, aPoint.y).building = aBuilding; } // Either extend an existing station which borders this area @@ -1173,7 +1176,7 @@ void Map::save() if (tile.building) { tileXml.addChild (xml::element("building") - .addText("white_house")); + .addText(tile.building->name())); useful = true; } @@ -1240,10 +1243,8 @@ public: else if (localName == "building") myMap->placeBuilding(makePoint(myXPtr, myYPtr), loadBuilding(aString)); else if (myActiveStation) { - if (localName == "name") { - debug() << "Saw station " << aString; + if (localName == "name") myActiveStation->setName(aString); - } } } diff --git a/src/Resource.cpp b/src/Resource.cpp index 4a164eb..e3da47d 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -130,7 +130,8 @@ void initResources() // Find all the resources of the given type void enumResources(const string& aClass, ResourceList& aList) { - + ResourceList& lst = resClassList(aClass); + copy(lst.begin(), lst.end(), back_inserter(aList)); } namespace { -- 2.39.2