From 22a2c4fef01c13c9f67dc1bfd1016158c355f959 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 5 Feb 2010 21:53:00 +0000 Subject: [PATCH] Editor button for placing trees --- images/icons/tree.png | Bin 0 -> 544 bytes include/IMap.hpp | 4 ++ layouts/editor.xml | 3 +- src/Editor.cpp | 86 +++++++++++++++++++++++++----------------- src/LTree.cpp | 14 ++++++- 5 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 images/icons/tree.png diff --git a/images/icons/tree.png b/images/icons/tree.png new file mode 100644 index 0000000000000000000000000000000000000000..73591633c140b43605195d13cca7cb95c4b0f0dd GIT binary patch literal 544 zcmV+*0^j|KP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igJ! z6(|Oryj;Hk000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0004dNklp9vK(GO4+? zfn!;_peGvfq6J$ymlM=T!) zO3Zm2q$xiM #include @@ -111,6 +112,9 @@ public: // Get the height above ground at a particular point virtual float heightAt(float x, float y) const = 0; + + // Place a tree, etc. at a location + virtual void addScenery(Point where, ISceneryPtr s) = 0; }; diff --git a/layouts/editor.xml b/layouts/editor.xml index c5f18f0..6942bc9 100644 --- a/layouts/editor.xml +++ b/layouts/editor.xml @@ -5,7 +5,7 @@ dropShadow="true" size="14" /> - diff --git a/src/Editor.cpp b/src/Editor.cpp index 3542349..0e5eb12 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -52,6 +52,7 @@ public: enum Tool { TRACK_TOOL, RAISE_TOOL, LOWER_TOOL, DELETE_TOOL, LEVEL_TOOL, START_TOOL, STATION_TOOL, BUILDING_TOOL, + TREE_TOOL }; void setTool(Tool aTool) { myTool = aTool; } @@ -68,6 +69,7 @@ private: const Point& aSecondPoint) const; void dragBoxBounds(int& xMin, int& xMax, int &yMin, int& yMax) const; void deleteObjects(); + void plantTrees(); void save(); IMapPtr map; @@ -88,16 +90,16 @@ private: }; Editor::Editor(IMapPtr aMap) - : map(aMap), myPosition(4.5, -17.5, -21.5), - myTool(TRACK_TOOL), amScrolling(false), amDragging(false) + : map(aMap), myPosition(4.5, -17.5, -21.5), + myTool(TRACK_TOOL), amScrolling(false), amDragging(false) { - mySun = makeSunLight(); - - buildGUI(); - - map->setGrid(true); - - log() << "Editing " << aMap->name(); + mySun = makeSunLight(); + + buildGUI(); + + map->setGrid(true); + + log() << "Editing " << aMap->name(); } Editor::~Editor() @@ -107,31 +109,33 @@ Editor::~Editor() void Editor::buildGUI() { - using namespace placeholders; - - layout = gui::makeLayout("layouts/editor.xml"); - - layout->get("/tool_wnd/tools/track").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, TRACK_TOOL)); - layout->get("/tool_wnd/tools/raise").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, RAISE_TOOL)); - layout->get("/tool_wnd/tools/lower").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, LOWER_TOOL)); - layout->get("/tool_wnd/tools/level").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, LEVEL_TOOL)); - layout->get("/tool_wnd/tools/delete").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, DELETE_TOOL)); - layout->get("/tool_wnd/tools/start").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, START_TOOL)); - layout->get("/tool_wnd/tools/station").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, STATION_TOOL)); - layout->get("/tool_wnd/tools/building").connect(gui::Widget::SIG_CLICK, - bind(&Editor::setTool, this, BUILDING_TOOL)); - - layout->get("/lower/action_wnd/save").connect(gui::Widget::SIG_CLICK, - bind(&Editor::save, this)); - - buildingPicker = makeBuildingPicker(layout); + using namespace placeholders; + + layout = gui::makeLayout("layouts/editor.xml"); + + layout->get("/tool_wnd/tools/track").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, TRACK_TOOL)); + layout->get("/tool_wnd/tools/raise").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, RAISE_TOOL)); + layout->get("/tool_wnd/tools/lower").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, LOWER_TOOL)); + layout->get("/tool_wnd/tools/level").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, LEVEL_TOOL)); + layout->get("/tool_wnd/tools/delete").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, DELETE_TOOL)); + layout->get("/tool_wnd/tools/start").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, START_TOOL)); + layout->get("/tool_wnd/tools/station").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, STATION_TOOL)); + layout->get("/tool_wnd/tools/building").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, BUILDING_TOOL)); + layout->get("/tool_wnd/tools/tree").connect(gui::Widget::SIG_CLICK, + bind(&Editor::setTool, this, TREE_TOOL)); + + layout->get("/lower/action_wnd/save").connect(gui::Widget::SIG_CLICK, + bind(&Editor::save, this)); + + buildingPicker = makeBuildingPicker(layout); } void Editor::setMap(IMapPtr aMap) @@ -445,6 +449,17 @@ void Editor::deleteObjects() } } +void Editor::plantTrees() +{ + int xmin, xmax, ymin, ymax; + dragBoxBounds(xmin, xmax, ymin, ymax); + + for (int x = xmin; x <= xmax; x++) { + for (int y = ymin; y <= ymax; y++) + map->addScenery(makePoint(x, y), makeLTree()); + } +} + void Editor::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, int xrel, int yrel) { @@ -540,6 +555,9 @@ void Editor::onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, map->placeBuilding(dragBegin, building, angle); } break; + case TREE_TOOL: + plantTrees(); + break; } amDragging = false; diff --git a/src/LTree.cpp b/src/LTree.cpp index 0628496..e63ca2a 100644 --- a/src/LTree.cpp +++ b/src/LTree.cpp @@ -18,6 +18,7 @@ #include "IScenery.hpp" #include "ILogger.hpp" #include "Random.hpp" +#include "OpenGLHelper.hpp" #include #include @@ -141,6 +142,7 @@ private: void interpret(Token t, RenderState& rs) const; LSystem ls; + Vector position; static const Rule rules[]; }; @@ -187,7 +189,7 @@ void LTree::interpret(Token t, RenderState& rs) const glVertex3f(LEAF_LEN, 0.0f, 0.0f); glVertex3f(0.0f, -LEAF_LEN, LEAF_LEN); glEnd(); - glPopAttrib(); */ + glPopAttrib();*/ break; case '-': glRotatef(25.0, 0.0f, 0.0f, 1.0f); @@ -218,16 +220,24 @@ void LTree::render() const { using namespace placeholders; + glPushMatrix(); + + gl::translate(position); + glColor3f(0.0f, 0.0f, 0.0f); RenderState rs; for_each(ls.state.begin(), ls.state.end(), bind(<ree::interpret, this, _1, rs)); + + glPopMatrix(); } void LTree::setPosition(float x, float y, float z) { - + position.x = x; + position.y = y; + position.z = z; } ISceneryPtr makeLTree() -- 2.39.2