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/>.
19 #include "tool_new_vertex.h"
20 #include "tool_draw_prim.h"
22 #include "displayer_visual_group.h"
24 #include "nel/misc/i18n.h"
30 using namespace NLMISC
;
36 // *********************************************************************************************************
37 CToolNewVertex::CToolNewVertex() : CToolChoosePos(-1, "curs_create.tga", "curs_create_vertex_invalid.tga"), _CurrEdge(-1), _CurrPos(CVector::Null
)
42 // *********************************************************************************************************
43 bool CToolNewVertex::isValidChoosePos(const CVector2f
&pos
) const
45 //H_AUTO(R2_CToolNewVertex_isValidChoosePos)
46 if (!isValid2DPos(pos
)) return false;
47 // pos must be on one edge of the road
48 CInstance
*selection
= getEditor().getSelectedInstance();
49 if (!selection
) return false;
50 IDisplayerUIHandle
*miniMapHandle
;
51 CInstance
*underMouse
= checkInstanceUnderMouse(&miniMapHandle
);
52 if (underMouse
!= selection
) return false;
55 if (miniMapHandle
->isEdge())
57 _CurrEdge
= (sint
) miniMapHandle
->getEdgeIndex();
65 CDisplayerVisualGroup
*dvg
= dynamic_cast<CDisplayerVisualGroup
*>(selection
->getDisplayerVisual());
66 if (!dvg
) return false;
67 _CurrEdge
= dvg
->isOnEdge(CVector2f(pos
.x
, pos
.y
));
69 return _CurrEdge
!= -1;
72 // *********************************************************************************************************
73 void CToolNewVertex::commit(const NLMISC::CVector
&createPosition
, float /* createAngle */)
75 //H_AUTO(R2_CToolNewVertex_commit)
76 CInstance
*selection
= getEditor().getSelectedInstance();
77 if (!selection
) return;
78 // check that there is room left for a new vertex
79 CObject
*points
= selection
->getObjectTable()->getAttr("Points");
81 if (points
->getSize() >= CToolDrawPrim::PrimMaxNumPoints
)
83 getEditor().callEnvMethod("noMoreRoomLeftInPrimitveMsg", 0, 0);
87 if (!selection
->getDisplayerVisual()) return;
88 getDMC().newAction(NLMISC::CI18N::get(selection
->isKindOf("Road") ? "uiR2EDInsertNewWayPointAction" : "uiR2EDInsertNewZoneVertexAction"));
89 CObject
*wp
= getDMC().newComponent(selection
->isKindOf("Road") ? "WayPoint" : "RegionVertex");
91 wp
->setObject("Position", buildVector(CVectorD(createPosition
- selection
->getDisplayerVisual()->getWorldPos())));
92 if (_CurrEdge
== (sint
) (points
->getSize() - 1))
94 getDMC().requestInsertNode(selection
->getId(), "Points", -1, "", wp
);
98 getDMC().requestInsertNode(selection
->getId(), "Points", _CurrEdge
+ 1, "", wp
);
103 // *********************************************************************************************************
104 const char *CToolNewVertex::getToolUIName() const
106 //H_AUTO(R2_CToolNewVertex_getToolUIName)
110 // *********************************************************************************************************
111 bool CToolNewVertex::onDeleteCmd()
113 //H_AUTO(R2_CToolNewVertex_onDeleteCmd)
114 CTool::TSmartPtr
hold(this);
115 getEditor().setCurrentTool(NULL
);
116 return false; // don't handle event because the current zone will be deleted