Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / action_handler_base.cpp
blob925fc78279540ab46fddd572d9ceb60702d9767e
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
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/>.
20 #include "stdpch.h"
21 #include "action_handler_base.h"
22 #include "action_handler_misc.h"
24 #include "nel/gui/interface_expr.h"
25 #include "interface_manager.h"
27 #include "nel/gui/group_container.h"
28 #include "nel/gui/group_editbox.h"
29 #include "nel/gui/group_menu.h"
30 #include "dbctrl_sheet.h"
31 #include "interface_3d_scene.h"
32 #include "character_3d.h"
33 #include "nel/gui/group_container.h"
34 #include "people_interraction.h"
36 #include "../r2/editor.h"
38 using namespace std;
39 using namespace NLMISC;
41 // ------------------------------------------------------------------------------------------------
42 class CAHActiveMenu : public IActionHandler
44 virtual void execute (CCtrlBase *pCaller, const string &Params)
46 CInterfaceManager *im = CInterfaceManager::getInstance();
48 // get the parent container
49 CGroupContainer *gc = NULL;
50 CCtrlBase *cb = pCaller;
51 while (cb)
53 gc = dynamic_cast<CGroupContainer *>(cb);
54 if (gc) break;
55 cb = cb->getParent();
58 // update GC_POPUP flag
59 if (gc)
61 NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:GC_POPUP")->setValue64((gc->isPopuped() || gc->getLayerSetup() == 0) ? 1 : 0);
63 else
65 NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:GC_POPUP")->setValue64(0);
68 // update GC_HAS_HELP flag
69 if(gc && !gc->getHelpPage().empty())
71 NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:GC_HAS_HELP")->setValue64(1);
73 else
75 NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:GC_HAS_HELP")->setValue64(0);
78 // open the menu
79 if (CDBCtrlSheet::getDraggedSheet() == NULL)
81 std::string menuId = getParam(Params, "menu");
82 CGroupMenu *groupMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId(menuId));
83 if (groupMenu)
85 bool pushModal;
86 // default = false
87 fromString(getParam(Params, "pushmodal"), pushModal);
89 if (pushModal)
91 // if false, then close all modal window when groupMenu deactivates
92 bool popModal;
93 if (!fromString(getParam(Params, "popmodal"), popModal))
95 popModal = true;
97 groupMenu->setCloseSubMenuUsingPopModal(popModal);
98 CWidgetManager::getInstance()->pushModalWindow(pCaller, groupMenu);
100 else
102 groupMenu->setCloseSubMenuUsingPopModal(false);
103 CWidgetManager::getInstance()->enableModalWindow(pCaller, groupMenu);
109 REGISTER_ACTION_HANDLER (CAHActiveMenu, "active_menu");
111 // ------------------------------------------------------------------------------------------------
112 class CAHSetKeyboardFocus : public IActionHandler
114 public:
115 virtual void execute (CCtrlBase *pCaller, const string &Params)
117 CInterfaceManager *pIM = CInterfaceManager::getInstance();
118 string target = getParam (Params, "target");
119 CGroupEditBox *geb;
120 if (pCaller == NULL)
121 geb = dynamic_cast<CGroupEditBox *>(CWidgetManager::getInstance()->getElementFromId (target));
122 else
123 geb = dynamic_cast<CGroupEditBox *>(CWidgetManager::getInstance()->getElementFromId (pCaller->getId(), target));
124 if (geb == NULL)
126 nlwarning("<CAHSetKeyboardFocus::execute> Can't get target edit box %s, or bad type", target.c_str());
127 return;
129 CWidgetManager::getInstance()->setCaptureKeyboard(geb);
130 string selectAllStr = getParam (Params, "select_all");
131 bool selectAll = CInterfaceElement::convertBool(selectAllStr.c_str());
132 if (selectAll)
134 geb->setSelectionAll();
138 REGISTER_ACTION_HANDLER (CAHSetKeyboardFocus, "set_keyboard_focus");
140 // ------------------------------------------------------------------------------------------------
141 class CAHResetKeyboardFocus : public IActionHandler
143 public:
144 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
146 CWidgetManager::getInstance()->resetCaptureKeyboard();
149 REGISTER_ACTION_HANDLER (CAHResetKeyboardFocus, "reset_keyboard_focus");
151 // ------------------------------------------------------------------------------------------------
152 class CAHSetEditBoxCommand : public IActionHandler
154 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
156 CGroupEditBox *menuEB = CGroupEditBox::getMenuFather();
157 if (menuEB) menuEB->setCommand(getParam(Params, "value"), nlstricmp(getParam(Params, "execute"), "true") ? true : false);
160 REGISTER_ACTION_HANDLER (CAHSetEditBoxCommand, "set_edit_box_command");
162 // ------------------------------------------------------------------------------------------------
163 class CAHSetServerString : public IActionHandler
165 virtual void execute (CCtrlBase *pCaller, const string &Params)
167 string sValue = getParam(Params,"value");
168 string sTarget = getParam(Params,"target");
170 if (sTarget.empty()) return;
172 if (sTarget.rfind(':') == string::npos)
174 if (pCaller == NULL) return;
175 sTarget = pCaller->getId() + ":" + sTarget;
177 else
179 CInterfaceManager *pIM = CInterfaceManager::getInstance();
180 string elt = sTarget.substr(0,sTarget.rfind(':'));
181 CInterfaceElement *pIE;
182 if (pCaller != NULL)
183 pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), elt);
184 else
185 pIE = CWidgetManager::getInstance()->getElementFromId(elt);
186 if (pIE == NULL) return;
187 sTarget = pIE->getId() + ":" + sTarget.substr(sTarget.rfind(':')+1,sTarget.size());
190 CInterfaceExprValue evValue;
191 if (CInterfaceExpr::eval(sValue, evValue, NULL))
193 CInterfaceManager *pIM = CInterfaceManager::getInstance();
194 if (evValue.toInteger())
195 pIM->addServerString (sTarget, (uint32)evValue.getInteger());
199 REGISTER_ACTION_HANDLER (CAHSetServerString, "set_server_string");
201 // ------------------------------------------------------------------------------------------------
202 class CAHSetServerID : public IActionHandler
204 virtual void execute (CCtrlBase *pCaller, const string &Params)
206 string sValue = getParam(Params,"value");
207 string sTarget = getParam(Params,"target");
208 string sRemoveTitle = getParam(Params,"remove_title");
210 if (sTarget.empty()) return;
212 if (sTarget.rfind(':') == string::npos)
214 if (pCaller == NULL) return;
215 sTarget = pCaller->getId() + ":" + sTarget;
217 else
219 CInterfaceManager *pIM = CInterfaceManager::getInstance();
220 string elt = sTarget.substr(0,sTarget.rfind(':'));
221 CInterfaceElement *pIE;
222 if (pCaller != NULL)
223 pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), elt);
224 else
225 pIE = CWidgetManager::getInstance()->getElementFromId(elt);
226 if (pIE == NULL) return;
227 sTarget = pIE->getId() + ":" + sTarget.substr(sTarget.rfind(':')+1,sTarget.size());
230 CInterfaceExprValue evValue;
231 if (CInterfaceExpr::eval(sValue, evValue, NULL))
233 bool bRemoveTitle = false;
234 if (!sRemoveTitle.empty())
235 fromString(sRemoveTitle, bRemoveTitle);
237 CInterfaceManager *pIM = CInterfaceManager::getInstance();
239 if (bRemoveTitle)
241 CStringPostProcessRemoveTitle *pSPPRT = new CStringPostProcessRemoveTitle;
243 if (evValue.toInteger())
244 pIM->addServerID (sTarget, (uint32)evValue.getInteger(), pSPPRT);
246 else
248 if (evValue.toInteger())
249 pIM->addServerID (sTarget, (uint32)evValue.getInteger(), NULL);
254 REGISTER_ACTION_HANDLER (CAHSetServerID, "set_server_id");
256 // ------------------------------------------------------------------------------------------------
257 class CAHResetCamera : public IActionHandler
259 virtual void execute (CCtrlBase *pCaller, const string &Params)
261 string sTarget = getParam(Params,"target");
263 if (sTarget.empty()) return;
265 CInterfaceManager *pIM = CInterfaceManager::getInstance();
266 CInterfaceElement *pIE;
267 if (pCaller != NULL)
268 pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), sTarget);
269 else
270 pIE = CWidgetManager::getInstance()->getElementFromId(sTarget);
271 CInterface3DCamera *pCam = dynamic_cast<CInterface3DCamera*>(pIE);
272 if (pCam == NULL) return;
273 pCam->reset();
276 REGISTER_ACTION_HANDLER (CAHResetCamera, "reset_camera");
278 ///////////////////////////////
279 // VIRTUAL DESKTOP MANAGMENT //
280 ///////////////////////////////
283 // ------------------------------------------------------------------------------------------------
284 class CAHSetVirtualDesktop : public IActionHandler
286 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
288 string sVDesk = getParam(Params,"vdesk");
290 if (sVDesk.empty()) return;
291 sint32 nVDesk;
292 fromString(sVDesk, nVDesk);
294 CInterfaceManager *pIM = CInterfaceManager::getInstance();
295 pIM->setMode((uint8)nVDesk);
297 PeopleInterraction.refreshActiveUserChats();
300 REGISTER_ACTION_HANDLER (CAHSetVirtualDesktop, "set_virtual_desktop");
302 // ------------------------------------------------------------------------------------------------
303 class CAHResetVirtualDesktop : public IActionHandler
305 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
307 string sVDesk = getParam(Params,"vdesk");
309 if (sVDesk.empty()) return;
310 sint32 nVDesk;
311 fromString(sVDesk, nVDesk);
313 CInterfaceManager *pIM = CInterfaceManager::getInstance();
314 pIM->resetMode((uint8)nVDesk);
316 PeopleInterraction.refreshActiveUserChats();
319 REGISTER_ACTION_HANDLER (CAHResetVirtualDesktop, "reset_virtual_desktop");
321 // ------------------------------------------------------------------------------------------------
322 class CAHMilkoMenuResetInterface : public IActionHandler
324 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
326 CInterfaceManager *pIM = CInterfaceManager::getInstance();
327 string sParam("mode=");
328 if(R2::getEditor().getMode() == R2::CEditor::TestMode)
329 sParam = "R2TestMode";
331 pIM->validMessageBox(CInterfaceManager::QuestionIconMsg, CI18N::get("uiQResetUI"), "milko_menu_do_reset_interface", sParam);
334 REGISTER_ACTION_HANDLER (CAHMilkoMenuResetInterface, "milko_menu_reset_interface");
336 // ------------------------------------------------------------------------------------------------
337 class CAHMilkoMenuDoResetInterface : public IActionHandler
339 virtual void execute (CCtrlBase * /* pCaller */, const string& Params)
341 // get param
342 string mode = getParam(Params, "mode");
344 // run procedure
345 vector<string> v;
346 if (mode == "R2TestMode")
347 CWidgetManager::getInstance()->runProcedure ("proc_reset_r2ed_interface", NULL, v);
348 else
349 CWidgetManager::getInstance()->runProcedure("proc_reset_interface", NULL, v);
352 REGISTER_ACTION_HANDLER(CAHMilkoMenuDoResetInterface, "milko_menu_do_reset_interface");
354 // ------------------------------------------------------------------------------------------------
355 class CAHResetInterface : public IActionHandler
357 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
359 uint32 i;
360 CInterfaceManager *pIM = CInterfaceManager::getInstance();
361 const vector<CWidgetManager::SMasterGroup> &rVMG = CWidgetManager::getInstance()->getAllMasterGroup();
362 for (uint32 nMasterGroup = 0; nMasterGroup < rVMG.size(); nMasterGroup++)
364 const CWidgetManager::SMasterGroup &rMG = rVMG[nMasterGroup];
365 const vector<CInterfaceGroup*> &rV = rMG.Group->getGroups();
366 // Active all containers (that can be activated)
367 for (i = 0; i < rV.size(); ++i)
369 CGroupContainer *pGC = dynamic_cast<CGroupContainer*>(rV[i]);
370 if (pGC == NULL) continue;
371 if (pGC->isSavable())
373 // Yoyo: DO NOT force activation of containers who don't want to save their Active state.
374 // Usually driven by server.
375 if(pGC->isActiveSavable())
376 pGC->setActive(true);
380 CWidgetManager::getInstance()->checkCoords();
381 CWidgetManager::getInstance()->getMasterGroup((uint8)nMasterGroup).centerAllContainers();
383 // Pop in and close all containers
384 for (i = 0; i < rV.size(); ++i)
386 CGroupContainer *pGC = dynamic_cast<CGroupContainer*>(rV[i]);
387 if (pGC == NULL) continue;
388 if (pGC->isSavable())
390 if (pGC->isPopable()&&pGC->isPopuped())
391 pGC->popin();
393 // Can close ?
394 if (pGC->isOpenable()&&pGC->isOpen())
395 pGC->close();
399 CWidgetManager::getInstance()->getMasterGroup((uint8)nMasterGroup).deactiveAllContainers();
403 REGISTER_ACTION_HANDLER (CAHResetInterface, "reset_interface");
405 // ------------------------------------------------------------------------------------------------
406 class CAHConvertServerEntities : public IActionHandler
408 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
410 string sDstPath = getParam(Params, "dest");
411 if (sDstPath.empty()) return;
412 string sEntityNb = getParam(Params, "entity");
413 uint32 nEntityNb = 0;
414 if (!sEntityNb.empty())
415 fromString(sEntityNb, nEntityNb);
417 CCharacterSummary cs;
418 SCharacter3DSetup::setupCharacterSummaryFromSERVERDB(cs, (uint8)nEntityNb);
419 SCharacter3DSetup::setupDBFromCharacterSummary(sDstPath, cs);
423 REGISTER_ACTION_HANDLER (CAHConvertServerEntities, "convert_server_entities");
425 /*// ------------------------------------------------------------------------------------------------
426 class CAHPopup : public IActionHandler
428 virtual void execute (CCtrlBase *pCaller, const string &Params)
430 string sCont = getParam(Params,"cont");
431 CInterfaceExprValue eVal;
432 if (!CInterfaceExpr::eval(sCont, eVal, NULL)) return;
433 sCont = eVal.getString();
434 if (sCont.empty()) return;
435 CInterfaceManager *pIM = CInterfaceManager::getInstance();
436 CGroupContainer *pGC = dynamic_cast<CGroupContainer*>(CWidgetManager::getInstance()->getElementFromId(sCont));
437 if (pGC == NULL) return;
438 if (pGC->isPopuped()) return;
439 pGC->setHighLighted(false);
440 // pop the window
441 pGC->popupCurrentPos();
442 if (pGC->getPopupW() != -1)
444 pGC->setX(pGC->getPopupX());
445 pGC->setY(pGC->getPopupY());
446 pGC->setW(pGC->getPopupW());
447 // must resize the children to get correct height
448 pGC->setChildrenH(pGC->getPopupChildrenH());
450 pGC->invalidateCoords(2);
453 REGISTER_ACTION_HANDLER (CAHPopup, "popup");