1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2017 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 "action_handler_tools.h"
39 #include "nel/gui/ctrl_base_button.h"
44 extern sint CompassMode
;
45 extern class CView View
;
46 extern CUserControls UserControls
;
47 extern bool ShowInterface
;
50 /**********************************************************************************************************
52 * debug handlers actions *
54 ***********************************************************************************************************/
56 // ------------------------------------------------------------------------------------------------
57 class CAHChangeCompassMode
: public IActionHandler
59 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
61 CompassMode
= CompassMode
? 0:1;
64 REGISTER_ACTION_HANDLER (CAHChangeCompassMode
, "change_compass_mode");
66 // ------------------------------------------------------------------------------------------------
67 class CAHSetPos
: public IActionHandler
69 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
71 UserEntity
->pacsPos(View
.viewPos());
72 UserEntity
->front(View
.view());
73 UserEntity
->dir(View
.view());
76 REGISTER_ACTION_HANDLER (CAHSetPos
, "set_pos");
79 // ----------------------------------------------
80 class CAHFrontSelection
: public IActionHandler
83 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
88 // select Enemy or enemy? Never select user
91 // for friend: select both dead and alive (for heal). But Select only Players (not bot)
92 flags
= CEntityFilterFlag::NotUser
| CEntityFilterFlag::Player
| CEntityFilterFlag::Friend
;
94 // for enemy: interesting to select only Alive entities (to chain-nuke)
95 // select both NonPlayer and Player (for PVP)
96 flags
= CEntityFilterFlag::NotUser
| CEntityFilterFlag::Enemy
| CEntityFilterFlag::Alive
;
98 // If there is an entity selected -> Set as the Target. Cycle with last target
99 CEntityCL
*entity
= EntitiesMngr
.getEntityInCamera(flags
, ClientCfg
.SpaceSelectionDist
, UserEntity
->targetSlot());
102 // Select this entity.
103 UserEntity
->selection(entity
->slot());
104 // Yoyo: not interesting: commonly Fight (use shortcut instead)
105 // Launch Context Menu.
106 /*CInterfaceManager *IM = CInterfaceManager::getInstance();
107 IM->launchContextMenuInGame("ui:interface:game_context_menu");*/
111 REGISTER_ACTION_HANDLER (CAHFrontSelection
, "front_selection");
113 // ------------------------------------------------------------------------------------------------
114 class CAHMove
: public IActionHandler
117 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
119 // Moving Break the Follow Mode
120 UserEntity
->disableFollow();
121 UserEntity
->moveTo(CLFECOMMON::INVALID_SLOT
, 0.0, CUserEntity::None
);
125 // ------------------------------------------------------------------------------------------------
126 class CAHTurnLeft
: public CAHMove
129 REGISTER_ACTION_HANDLER (CAHTurnLeft
, "turn_left");
131 // ------------------------------------------------------------------------------------------------
132 class CAHTurnRight
: public CAHMove
135 REGISTER_ACTION_HANDLER (CAHTurnRight
, "turn_right");
137 // ------------------------------------------------------------------------------------------------
138 class CAHStrafeLeft
: public CAHMove
141 REGISTER_ACTION_HANDLER (CAHStrafeLeft
, "strafe_left");
143 // ------------------------------------------------------------------------------------------------
144 class CAHStrafeRight
: public CAHMove
147 REGISTER_ACTION_HANDLER (CAHStrafeRight
, "strafe_right");
149 // ------------------------------------------------------------------------------------------------
150 class CAHForward
: public CAHMove
153 REGISTER_ACTION_HANDLER (CAHForward
, "forward");
155 // ------------------------------------------------------------------------------------------------
156 class CAHBackward
: public CAHMove
159 REGISTER_ACTION_HANDLER (CAHBackward
, "backward");
161 // ------------------------------------------------------------------------------------------------
162 class CAHToggleAutoWalk
: public IActionHandler
165 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
169 REGISTER_ACTION_HANDLER (CAHToggleAutoWalk
, "toggle_auto_walk");
172 // ------------------------------------------------------------------------------------------------
173 class CAHToggleLight
: public IActionHandler
175 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
180 REGISTER_ACTION_HANDLER (CAHToggleLight
, "toggle_light");
182 // ------------------------------------------------------------------------------------------------
183 class CAHFreeMouse
: public IActionHandler
185 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
187 InitMouseWithCursor (!IsMouseCursorHardware ());
188 ClientCfg
.HardwareCursor
= IsMouseCursorHardware();
189 // if the game config window is opened, keep in sync
190 bool written
= false;
191 CInterfaceManager
*im
= CInterfaceManager::getInstance();
194 CInterfaceGroup
*ig
= dynamic_cast<CInterfaceGroup
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:game_config"));
195 if (ig
&& ig
->getActive())
197 CInterfaceGroup
*igHard
= dynamic_cast<CInterfaceGroup
*>(ig
->getGroup("hard"));
200 CCtrlBaseButton
*cbb
= dynamic_cast<CCtrlBaseButton
*>(igHard
->getCtrl("c"));
203 if(cbb
->getPushed() != IsMouseCursorHardware())
205 cbb
->setPushed(IsMouseCursorHardware());
206 cbb
->runLeftClickAction();
215 ClientCfg
.writeBool("HardwareCursor", IsMouseCursorHardware());
219 REGISTER_ACTION_HANDLER (CAHFreeMouse
, "free_mouse");
221 // ------------------------------------------------------------------------------------------------
222 class CAHToggleCamera
: public IActionHandler
224 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
226 // Change the camera view
227 UserEntity
->toggleCamera();
230 REGISTER_ACTION_HANDLER (CAHToggleCamera
, "toggle_camera");
232 // ------------------------------------------------------------------------------------------------
233 class CAHTForceFP
: public IActionHandler
235 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
237 // Change the camera view to first person
238 UserEntity
->forceCameraFirstPerson();
241 REGISTER_ACTION_HANDLER (CAHTForceFP
, "force_camera_fp");
243 // ------------------------------------------------------------------------------------------------
244 class CAHToggleNames
: public IActionHandler
252 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
254 CActionsManager
*pAM
= &Actions
;
256 if(!pAM
->valide(CAction::CName("toggle_names", Params
.c_str())))
258 // Toggles Names back.
260 ClientCfg
.Names
= !ClientCfg
.Names
;
268 ClientCfg
.Names
= !ClientCfg
.Names
;
275 REGISTER_ACTION_HANDLER (CAHToggleNames
, "toggle_names");
277 // ------------------------------------------------------------------------------------------------
278 class CAHRearView
: public IActionHandler
280 virtual void execute (CCtrlBase
* /* pCaller */, const string
&Params
)
282 static bool PreviousShowInterface
= true;
284 CActionsManager
*pAM
= &Actions
;
286 if(pAM
->valide(CAction::CName("rear_view", Params
.c_str())))
288 PreviousShowInterface
= ShowInterface
; // save previous show interface value
289 ShowInterface
= false;
295 ShowInterface
= PreviousShowInterface
; // restore previous show interface value
296 View
.rearView(false);
300 REGISTER_ACTION_HANDLER (CAHRearView
, "rear_view");
302 // ------------------------------------------------------------------------------------------------
303 class CAHCameraUp
: public IActionHandler
306 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
310 REGISTER_ACTION_HANDLER (CAHCameraUp
, "camera_up");
311 class CAHCameraDown
: public IActionHandler
314 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
318 REGISTER_ACTION_HANDLER (CAHCameraDown
, "camera_down");
319 // ------------------------------------------------------------------------------------------------
320 class CAHCameraTurnLeft
: public IActionHandler
323 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
327 REGISTER_ACTION_HANDLER (CAHCameraTurnLeft
, "camera_turn_left");
329 class CAHCameraTurnRight
: public IActionHandler
332 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
336 REGISTER_ACTION_HANDLER (CAHCameraTurnRight
, "camera_turn_right");
338 class CAHCameraTurnCenter
: public IActionHandler
341 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
343 UserControls
.resetSmoothCameraDeltaYaw();
346 REGISTER_ACTION_HANDLER (CAHCameraTurnCenter
, "camera_turn_center");
349 // ------------------------------------------------------------------------------------------------
350 // Toggle Sit / Stand, but don't change speed
351 class CAHToggleSitStand
: public IActionHandler
353 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
355 UserEntity
->sit(!UserEntity
->isSit());
358 REGISTER_ACTION_HANDLER (CAHToggleSitStand
, "toggle_sit_stand");
360 // Force sit, but don't change speed
361 class CAHForceSit
: public IActionHandler
363 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
365 if(!UserEntity
->isSit())
368 UserEntity
->setAFK(false);
370 UserEntity
->sit(true);
374 REGISTER_ACTION_HANDLER (CAHForceSit
, "force_sit");
376 // Force stand, but don't change speed
377 class CAHForceStand
: public IActionHandler
379 void execute (CCtrlBase
* /* pCaller */, const std::string
&/* sParams */)
381 if(UserEntity
->isSit())
382 UserEntity
->sit(false);
385 REGISTER_ACTION_HANDLER (CAHForceStand
, "force_stand");
388 // ------------------------------------------------------------------------------------------------
389 // Toggle run/walk, but don't unsit
390 class CAHToggleRunWalk
: public IActionHandler
392 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
394 UserEntity
->switchVelocity();
397 REGISTER_ACTION_HANDLER (CAHToggleRunWalk
, "toggle_run_walk");
399 // force walk mode, and leave sit() mode if any
400 class CAHForceWalk
: public IActionHandler
402 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
405 if(UserEntity
->running())
406 UserEntity
->switchVelocity();
409 if(UserEntity
->isSit())
410 UserEntity
->sit(false);
413 if(UserEntity
->isAFK())
414 UserEntity
->setAFK(false);
417 REGISTER_ACTION_HANDLER (CAHForceWalk
, "force_walk");
419 // force run mode, and leave sit() mode if any
420 class CAHForceRun
: public IActionHandler
422 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
425 if(!UserEntity
->running())
426 UserEntity
->switchVelocity();
429 if(UserEntity
->isSit())
430 UserEntity
->sit(false);
433 if(UserEntity
->isAFK())
434 UserEntity
->setAFK(false);
437 REGISTER_ACTION_HANDLER (CAHForceRun
, "force_run");
439 // ------------------------------------------------------------------------------------------------
440 class CAHToggleDodgeParry
: public IActionHandler
442 virtual void execute (CCtrlBase
* /* pCaller */, const string
&/* Params */)
444 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
448 if (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEFENSE:DEFENSE_MODE")->getValue32() == 0)
450 sendMsgToServer("COMBAT:PARRY");
451 msg
= CI18N::get("msgUserModeParry");
455 sendMsgToServer("COMBAT:DODGE");
456 msg
= CI18N::get("msgUserModeDodge");
458 // display dodge/parry mode message
459 string cat
= getStringCategory(msg
, msg
);
460 pIM
->displaySystemInfo(msg
, cat
);
463 REGISTER_ACTION_HANDLER (CAHToggleDodgeParry
, "toggle_dodge_parry");