1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 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>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 using namespace NLMISC
;
29 #include "nel/gui/action_handler.h"
30 #include "../motion/user_controls.h"
34 #include "../client_cfg.h"
35 #include "../actions_client.h"
36 #include "../entities.h"
37 #include "interface_manager.h"
38 #include "ingame_database_manager.h"
39 #include "action_handler_tools.h"
40 #include "nel/gui/ctrl_base_button.h"
45 extern sint CompassMode
;
46 extern class CView View
;
47 extern CUserControls UserControls
;
48 extern bool ShowInterface
;
51 /**********************************************************************************************************
53 * debug handlers actions *
55 ***********************************************************************************************************/
57 // ------------------------------------------------------------------------------------------------
58 class CAHChangeCompassMode
: public IActionHandler
60 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
62 CompassMode
= CompassMode
? 0:1;
65 REGISTER_ACTION_HANDLER (CAHChangeCompassMode
, "change_compass_mode");
67 // ------------------------------------------------------------------------------------------------
68 class CAHSetPos
: public IActionHandler
70 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
72 UserEntity
->pacsPos(View
.viewPos());
73 UserEntity
->front(View
.view());
74 UserEntity
->dir(View
.view());
77 REGISTER_ACTION_HANDLER (CAHSetPos
, "set_pos");
80 // ----------------------------------------------
81 class CAHFrontSelection
: public IActionHandler
84 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
89 // select Enemy or enemy? Never select user
92 // for friend: select both dead and alive (for heal). But Select only Players (not bot)
93 flags
= CEntityFilterFlag::NotUser
| CEntityFilterFlag::Player
| CEntityFilterFlag::Friend
;
95 // for enemy: interesting to select only Alive entities (to chain-nuke)
96 // select both NonPlayer and Player (for PVP)
97 flags
= CEntityFilterFlag::NotUser
| CEntityFilterFlag::Enemy
| CEntityFilterFlag::Alive
;
99 // If there is an entity selected -> Set as the Target. Cycle with last target
100 CEntityCL
*entity
= EntitiesMngr
.getEntityInCamera(flags
, ClientCfg
.SpaceSelectionDist
, UserEntity
->targetSlot());
103 // Select this entity.
104 UserEntity
->selection(entity
->slot());
105 // Yoyo: not interesting: commonly Fight (use shortcut instead)
106 // Launch Context Menu.
107 /*CInterfaceManager *IM = CInterfaceManager::getInstance();
108 IM->launchContextMenuInGame("ui:interface:game_context_menu");*/
112 REGISTER_ACTION_HANDLER (CAHFrontSelection
, "front_selection");
114 // ------------------------------------------------------------------------------------------------
115 class CAHMove
: public IActionHandler
118 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
120 // Moving Break the Follow Mode
121 UserEntity
->disableFollow();
123 // check if speed factor is zero, and if yes, notify the player
124 if (!Actions
.valide("turn_left") && !Actions
.valide("turn_right") && !IngameDbMngr
.initInProgress() && !UserEntity
->isSit())
126 CCDBNodeLeaf
*pNodeLeaf
= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false);
127 if (pNodeLeaf
&& pNodeLeaf
->getValue64() == 0)
128 CInterfaceManager::getInstance()->displaySystemInfo(CI18N::get("uiSpeedFactorZero"), "CHK");
131 UserEntity
->moveTo(CLFECOMMON::INVALID_SLOT
, 0.0, CUserEntity::None
);
135 // ------------------------------------------------------------------------------------------------
136 class CAHTurnLeft
: public CAHMove
139 REGISTER_ACTION_HANDLER (CAHTurnLeft
, "turn_left");
141 // ------------------------------------------------------------------------------------------------
142 class CAHTurnRight
: public CAHMove
145 REGISTER_ACTION_HANDLER (CAHTurnRight
, "turn_right");
147 // ------------------------------------------------------------------------------------------------
148 class CAHStrafeLeft
: public CAHMove
151 REGISTER_ACTION_HANDLER (CAHStrafeLeft
, "strafe_left");
153 // ------------------------------------------------------------------------------------------------
154 class CAHStrafeRight
: public CAHMove
157 REGISTER_ACTION_HANDLER (CAHStrafeRight
, "strafe_right");
159 // ------------------------------------------------------------------------------------------------
160 class CAHForward
: public CAHMove
163 REGISTER_ACTION_HANDLER (CAHForward
, "forward");
165 // ------------------------------------------------------------------------------------------------
166 class CAHBackward
: public CAHMove
169 REGISTER_ACTION_HANDLER (CAHBackward
, "backward");
171 // ------------------------------------------------------------------------------------------------
172 class CAHToggleAutoWalk
: public IActionHandler
175 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
179 REGISTER_ACTION_HANDLER (CAHToggleAutoWalk
, "toggle_auto_walk");
182 // ------------------------------------------------------------------------------------------------
183 class CAHToggleLight
: public IActionHandler
185 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
190 REGISTER_ACTION_HANDLER (CAHToggleLight
, "toggle_light");
192 // ------------------------------------------------------------------------------------------------
193 class CAHToggleLightOn
: public IActionHandler
195 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
197 UserEntity
->lightOn();
200 REGISTER_ACTION_HANDLER (CAHToggleLightOn
, "light_on");
203 // ------------------------------------------------------------------------------------------------
204 class CAHFreeMouse
: public IActionHandler
206 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
208 InitMouseWithCursor (!IsMouseCursorHardware ());
209 ClientCfg
.HardwareCursor
= IsMouseCursorHardware();
210 // if the game config window is opened, keep in sync
211 bool written
= false;
212 CInterfaceManager
*im
= CInterfaceManager::getInstance();
215 CInterfaceGroup
*ig
= dynamic_cast<CInterfaceGroup
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:game_config"));
216 if (ig
&& ig
->getActive())
218 CInterfaceGroup
*igHard
= dynamic_cast<CInterfaceGroup
*>(ig
->getGroup("hard"));
221 CCtrlBaseButton
*cbb
= dynamic_cast<CCtrlBaseButton
*>(igHard
->getCtrl("c"));
224 if(cbb
->getPushed() != IsMouseCursorHardware())
226 cbb
->setPushed(IsMouseCursorHardware());
227 cbb
->runLeftClickAction();
236 ClientCfg
.writeBool("HardwareCursor", IsMouseCursorHardware());
240 REGISTER_ACTION_HANDLER (CAHFreeMouse
, "free_mouse");
242 // ------------------------------------------------------------------------------------------------
243 class CAHToggleCamera
: public IActionHandler
245 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
247 // Change the camera view
248 UserEntity
->toggleCamera();
251 REGISTER_ACTION_HANDLER (CAHToggleCamera
, "toggle_camera");
253 // ------------------------------------------------------------------------------------------------
254 class CAHTForceFP
: public IActionHandler
256 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
258 // Change the camera view to first person
259 UserEntity
->forceCameraFirstPerson();
262 REGISTER_ACTION_HANDLER (CAHTForceFP
, "force_camera_fp");
264 // ------------------------------------------------------------------------------------------------
265 class CAHToggleNames
: public IActionHandler
273 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
275 CActionsManager
*pAM
= &Actions
;
277 if(!pAM
->valide(CAction::CName("toggle_names", Params
.c_str())))
279 // Toggles Names back.
281 ClientCfg
.Names
= !ClientCfg
.Names
;
289 ClientCfg
.Names
= !ClientCfg
.Names
;
296 REGISTER_ACTION_HANDLER (CAHToggleNames
, "toggle_names");
298 // ------------------------------------------------------------------------------------------------
299 class CAHRearView
: public IActionHandler
301 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
303 static bool PreviousShowInterface
= true;
305 CActionsManager
*pAM
= &Actions
;
307 if(pAM
->valide(CAction::CName("rear_view", Params
.c_str())))
309 PreviousShowInterface
= ShowInterface
; // save previous show interface value
310 ShowInterface
= false;
316 ShowInterface
= PreviousShowInterface
; // restore previous show interface value
317 View
.rearView(false);
321 REGISTER_ACTION_HANDLER (CAHRearView
, "rear_view");
324 // ------------------------------------------------------------------------------------------------
325 class CAHRunAction
: public IActionHandler
327 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
330 CActionsManager
*pAM
= &Actions
;
331 pAM
->validate(CAction::CName(Params
.c_str(), ""));
334 REGISTER_ACTION_HANDLER (CAHRunAction
, "run_action");
336 // ------------------------------------------------------------------------------------------------
337 class CAHStopAction
: public IActionHandler
339 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
342 CActionsManager
*pAM
= &Actions
;
343 pAM
->unvalidate(CAction::CName(Params
.c_str(), ""));
346 REGISTER_ACTION_HANDLER (CAHStopAction
, "stop_action");
348 // ------------------------------------------------------------------------------------------------
349 class CAHCameraUp
: public IActionHandler
352 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
356 REGISTER_ACTION_HANDLER (CAHCameraUp
, "camera_up");
357 class CAHCameraDown
: public IActionHandler
360 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
364 REGISTER_ACTION_HANDLER (CAHCameraDown
, "camera_down");
365 // ------------------------------------------------------------------------------------------------
366 class CAHCameraTurnLeft
: public IActionHandler
369 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
373 REGISTER_ACTION_HANDLER (CAHCameraTurnLeft
, "camera_turn_left");
375 class CAHCameraTurnRight
: public IActionHandler
378 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
382 REGISTER_ACTION_HANDLER (CAHCameraTurnRight
, "camera_turn_right");
384 class CAHCameraTurnCenter
: public IActionHandler
387 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
389 UserControls
.resetSmoothCameraDeltaYaw();
392 REGISTER_ACTION_HANDLER (CAHCameraTurnCenter
, "camera_turn_center");
395 // ------------------------------------------------------------------------------------------------
396 // Toggle Sit / Stand, but don't change speed
397 class CAHToggleSitStand
: public IActionHandler
399 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
401 UserEntity
->sit(!UserEntity
->isSit());
404 REGISTER_ACTION_HANDLER (CAHToggleSitStand
, "toggle_sit_stand");
406 // Force sit, but don't change speed
407 class CAHForceSit
: public IActionHandler
409 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
411 if(!UserEntity
->isSit())
414 UserEntity
->setAFK(false);
416 UserEntity
->sit(true);
420 REGISTER_ACTION_HANDLER (CAHForceSit
, "force_sit");
422 // Force stand, but don't change speed
423 class CAHForceStand
: public IActionHandler
425 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
427 if(UserEntity
->isSit())
428 UserEntity
->sit(false);
431 REGISTER_ACTION_HANDLER (CAHForceStand
, "force_stand");
434 // ------------------------------------------------------------------------------------------------
435 // Toggle run/walk, but don't unsit
436 class CAHToggleRunWalk
: public IActionHandler
438 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
440 UserEntity
->switchVelocity();
443 REGISTER_ACTION_HANDLER (CAHToggleRunWalk
, "toggle_run_walk");
445 // force walk mode, and leave sit() mode if any
446 class CAHForceWalk
: public IActionHandler
448 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
451 if(UserEntity
->running())
452 UserEntity
->switchVelocity();
455 if(UserEntity
->isSit())
456 UserEntity
->sit(false);
459 if(UserEntity
->isAFK())
460 UserEntity
->setAFK(false);
463 REGISTER_ACTION_HANDLER (CAHForceWalk
, "force_walk");
465 // force run mode, and leave sit() mode if any
466 class CAHForceRun
: public IActionHandler
468 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
471 if(!UserEntity
->running())
472 UserEntity
->switchVelocity();
475 if(UserEntity
->isSit())
476 UserEntity
->sit(false);
479 if(UserEntity
->isAFK())
480 UserEntity
->setAFK(false);
483 REGISTER_ACTION_HANDLER (CAHForceRun
, "force_run");
485 // ------------------------------------------------------------------------------------------------
486 class CAHToggleDodgeParry
: public IActionHandler
488 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
490 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
494 if (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEFENSE:DEFENSE_MODE")->getValue32() == 0)
496 sendMsgToServer("COMBAT:PARRY");
497 msg
= CI18N::get("msgUserModeParry");
501 sendMsgToServer("COMBAT:DODGE");
502 msg
= CI18N::get("msgUserModeDodge");
504 // display dodge/parry mode message
505 string cat
= getStringCategory(msg
, msg
);
506 pIM
->displaySystemInfo(msg
, cat
);
509 REGISTER_ACTION_HANDLER (CAHToggleDodgeParry
, "toggle_dodge_parry");