1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "tool_pick.h"
25 #include "nel/gui/lua_ihm.h"
31 using namespace NLMISC
;
36 // **********************************************
37 CToolPick::CToolPick(const std::string
&cursCanPickInstance
,
38 const std::string
&cursCannotPickInstance
,
39 const std::string
&cursCanPickPos
,
40 const std::string
&cursCannotPickPos
,
44 _CursCanPickInstance
= cursCanPickInstance
;
45 _CursCannotPickInstance
= cursCannotPickInstance
;
46 _CursCanPickPos
= cursCanPickPos
;
47 _CursCannotPickPos
= cursCannotPickPos
;
49 _WantMouseUp
= wantMouseUp
;
52 // **********************************************
53 void CToolPick::setIgnoreInstances(const std::string
& ignoreInstances
)
55 //H_AUTO(R2_CToolPick_setIgnoreInstances)
56 string allKind
= ignoreInstances
;
57 while (!allKind
.empty())
59 std::string::size_type e
= allKind
.find(',');
61 if (e
== std::string::npos
|| e
== 0)
68 tmp
= allKind
.substr(0,e
);
69 allKind
= allKind
.substr(e
+1,allKind
.size());
72 while(!tmp
.empty() && tmp
[0]==' ')
77 tmp
= tmp
.substr(1,tmp
.size());
79 while(!tmp
.empty() && tmp
[tmp
.size()]==' ')
84 tmp
= tmp
.substr(0,tmp
.size()-1);
86 _IgnoreInstances
.push_back(tmp
);
90 // **********************************************
91 void CToolPick::updateAfterRender()
93 //H_AUTO(R2_CToolPick_updateAfterRender)
94 // See if the mouse is over a valid position
96 sint32 mouseX
, mouseY
;
97 getMousePos(mouseX
, mouseY
);
98 if (!isInScreen(mouseX
, mouseY
))
100 getEditor().setFocusedInstance(NULL
);
101 setMouseCursor(_CursCannotPickPos
);
104 _CandidateInstance
= NULL
;
105 CInstance
*instanceUnder
= checkInstanceUnderMouse();
106 bool ignoreInstanceUnder
= false;
107 if(instanceUnder
&& !_IgnoreInstances
.empty())
109 for(uint i
=0; i
<_IgnoreInstances
.size(); i
++)
111 if(instanceUnder
->isKindOf(_IgnoreInstances
[i
]))
113 ignoreInstanceUnder
= true;
118 if (!instanceUnder
|| ignoreInstanceUnder
)
120 if (isMouseOnUI() && !isMouseOnContainer())
122 setMouseCursor(DEFAULT_CURSOR
);
126 CTool::CWorldViewRay worldViewRay
;
127 computeWorldViewRay(mouseX
, mouseY
, worldViewRay
);
129 _ValidPos
= (ValidPacsPos
== computeLandscapeRayIntersection(worldViewRay
, _Intersection
));
130 setMouseCursor(_ValidPos
? _CursCanPickPos
: _CursCannotPickPos
);
131 getEditor().setFocusedInstance(NULL
);
135 getEditor().setFocusedInstance(instanceUnder
);
136 if (canPick(*instanceUnder
))
138 _CandidateInstance
= instanceUnder
;
139 setMouseCursor(_CursCanPickInstance
);
143 setMouseCursor(_CursCannotPickInstance
);
147 // **********************************************
148 bool CToolPick::onMouseRightButtonClicked()
150 //H_AUTO(R2_CToolPick_onMouseRightButtonClicked)
151 TSmartPtr holdThis
= this; // for safety, prevent real deletion of this before this method is exited
156 // **********************************************
157 bool CToolPick::validate()
159 //H_AUTO(R2_CToolPick_validate)
160 if (!_CandidateInstance
)
168 return false; // ... else, do not handle, this allow to control the camera
170 if (!_WantMouseUp
) captureMouse();
171 pick(*_CandidateInstance
);
175 // **********************************************
176 bool CToolPick::onMouseLeftButtonDown()
178 //H_AUTO(R2_CToolPick_onMouseLeftButtonDown)
179 if (_WantMouseUp
) return false;
183 // **********************************************
184 bool CToolPick::onMouseLeftButtonClicked()
186 //H_AUTO(R2_CToolPick_onMouseLeftButtonClicked)
187 if (!_WantMouseUp
) return false;
191 // **********************************************
192 int CToolPick::luaPick(CLuaState
&ls
)
194 //H_AUTO(R2_CToolPick_luaPick)
195 CLuaIHM::checkArgCount(ls
, "pick", 0);
200 // **********************************************
201 int CToolPick::luaCanPick(CLuaState
&ls
)
203 //H_AUTO(R2_CToolPick_luaCanPick)
204 CLuaIHM::checkArgCount(ls
, "canPick", 0);
205 if (_CandidateInstance
) ls
.push(canPick(*_CandidateInstance
));