1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "tool_draw_road.h"
21 #include "game_share/object.h"
25 #include "nel/misc/vectord.h"
28 using namespace NLMISC;
33 // ***************************************************************
34 CToolDrawRoad::CToolDrawRoad()
40 // ***************************************************************
41 void CToolDrawRoad::updateAfterRender()
45 void CToolDrawRoad::cancel()
51 // ***************************************************************
52 void CToolDrawRoad::updateBeforeRender()
54 // Build vector for direction pointed by mouse in world
55 sint32 mouseX, mouseY;
56 getMousePos(mouseX, mouseY);
57 if (!isInScreen(mouseX, mouseY))
59 // mouse not in screen so don't display the last way point
60 _WayPoints.resize(_NumWayPoints);
61 _Road.setWayPoints(_WayPoints, true);
65 CTool::CWorldViewRay worldViewRay;
67 computeWorldViewRay(mouseX, mouseY, worldViewRay);
69 CVector wpPos; // the pos where the ghost will be shown
70 CVector inter; // intersection of view ray with landscape
72 switch(computeLandscapeRayIntersection(worldViewRay, inter))
75 if (worldViewRay.OnMiniMap)
77 _WayPoints.resize(_NumWayPoints);
78 _Road.setWayPoints(_WayPoints, true);
81 // no collision, can't drop entity
82 wpPos = worldViewRay.Origin + 3.f * worldViewRay.Dir;
86 _ValidPos = true; // good pos to drop entity
96 _WayPoints.resize(_NumWayPoints + 1);
97 _WayPoints.back() = wpPos;
98 _Road.setWayPoints(_WayPoints, _ValidPos);
99 // change mouse depending on result
102 setMouseCursor(_ValidPos ? "curs_create.tga" : "curs_stop.tga");
106 setMouseCursor("curs_create.tga");
110 // ***************************************************************
111 bool CToolDrawRoad::onMouseLeftButtonClicked()
117 startDoubleClickCheck();
121 // ***************************************************************
122 bool CToolDrawRoad::onMouseLeftButtonDown()
124 if (!checkDoubleClick()) return false;
125 _WayPoints.resize(_NumWayPoints);
126 if (_WayPoints.empty()) return true;
127 // send network command to create a new road
128 CObject *desc = getDMC().newComponent("Road");
131 static volatile bool wantDump = false;
136 CObject *points = desc->getAttr("Points");
139 for(uint k = 0; k < _WayPoints.size(); ++k)
141 CObject *wp = getDMC().newComponent("WayPoint");
143 wp->setObject("Position", buildVector(CVectorD(_WayPoints[k])));
144 points->insert("", wp, -1);
151 // send creation command
152 // tmp : static npc counter
153 static int roadCounter = 0;
154 // add in component list of default feature
155 if (getEditor().getDefaultFeature())
157 getDMC().requestInsertNode(getEditor().getDefaultFeature()->getId(),
160 toString("ROAD_%d", roadCounter++),
166 getEditor().setCurrentTool(NULL);
171 // ***************************************************************
172 bool CToolDrawRoad::onMouseRightButtonClicked()
174 // cancel the drawing
175 getEditor().setCurrentTool(NULL);