Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / r2 / tool_draw_road.cpp
blobf0348708e8c9e9c5a3fb6b33a0f99e2bbeb5d060
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "stdpch.h"
20 #include "tool_draw_road.h"
21 #include "game_share/object.h"
22 #include "dmc/idmc.h"
23 #include "editor.h"
25 #include "nel/misc/vectord.h"
28 using namespace NLMISC;
30 namespace R2
33 // ***************************************************************
34 CToolDrawRoad::CToolDrawRoad()
36 _NumWayPoints = 0;
37 _ValidPos = false;
40 // ***************************************************************
41 void CToolDrawRoad::updateAfterRender()
45 void CToolDrawRoad::cancel()
47 // no-op there
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);
62 return;
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
71 _ValidPos = false;
72 switch(computeLandscapeRayIntersection(worldViewRay, inter))
74 case NoIntersection:
75 if (worldViewRay.OnMiniMap)
77 _WayPoints.resize(_NumWayPoints);
78 _Road.setWayPoints(_WayPoints, true);
79 return;
81 // no collision, can't drop entity
82 wpPos = worldViewRay.Origin + 3.f * worldViewRay.Dir;
83 break;
84 case ValidPacsPos:
85 wpPos = inter;
86 _ValidPos = true; // good pos to drop entity
87 break;
88 case InvalidPacsPos:
89 wpPos = inter;
90 break;
91 default:
92 nlassert(0);
93 break;
96 _WayPoints.resize(_NumWayPoints + 1);
97 _WayPoints.back() = wpPos;
98 _Road.setWayPoints(_WayPoints, _ValidPos);
99 // change mouse depending on result
100 if (!isMouseOnUI())
102 setMouseCursor(_ValidPos ? "curs_create.tga" : "curs_stop.tga");
104 else
106 setMouseCursor("curs_create.tga");
110 // ***************************************************************
111 bool CToolDrawRoad::onMouseLeftButtonClicked()
113 if (_ValidPos)
115 ++ _NumWayPoints;
117 startDoubleClickCheck();
118 return true;
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");
129 if (desc)
131 static volatile bool wantDump = false;
132 if (wantDump)
134 desc->dump();
136 CObject *points = desc->getAttr("Points");
137 if (points)
139 for(uint k = 0; k < _WayPoints.size(); ++k)
141 CObject *wp = getDMC().newComponent("WayPoint");
142 if (!wp) continue;
143 wp->setObject("Position", buildVector(CVectorD(_WayPoints[k])));
144 points->insert("", wp, -1);
145 if (wantDump)
147 desc->dump();
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(),
158 "Components",
160 toString("ROAD_%d", roadCounter++),
161 desc);
164 delete desc;
166 getEditor().setCurrentTool(NULL);
167 return true;
171 // ***************************************************************
172 bool CToolDrawRoad::onMouseRightButtonClicked()
174 // cancel the drawing
175 getEditor().setCurrentTool(NULL);
176 return true;
180 } // R2