Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / action_handler_move.cpp
blob415dedbbcedf6ad4a1f65fc229fd5e86202801ec
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2017 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/>.
23 #include "stdpch.h"
25 using namespace std;
26 using namespace NLMISC;
28 #include "nel/gui/action_handler.h"
29 #include "../motion/user_controls.h"
30 #include "../view.h"
31 #include "../misc.h"
32 #include "../input.h"
33 #include "../client_cfg.h"
34 #include "../actions_client.h"
35 #include "../entities.h"
36 #include "interface_manager.h"
37 #include "action_handler_tools.h"
38 #include "nel/gui/ctrl_base_button.h"
40 ////////////
41 // GLOBAL //
42 ////////////
43 extern sint CompassMode;
44 extern class CView View;
45 extern CUserControls UserControls;
46 extern bool ShowInterface;
49 /**********************************************************************************************************
50 * *
51 * debug handlers actions *
52 * *
53 ***********************************************************************************************************/
55 // ------------------------------------------------------------------------------------------------
56 class CAHChangeCompassMode : public IActionHandler
58 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
60 CompassMode = CompassMode ? 0:1;
63 REGISTER_ACTION_HANDLER (CAHChangeCompassMode, "change_compass_mode");
65 // ------------------------------------------------------------------------------------------------
66 class CAHSetPos : public IActionHandler
68 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
70 UserEntity->pacsPos(View.viewPos());
71 UserEntity->front(View.view());
72 UserEntity->dir(View.view());
75 REGISTER_ACTION_HANDLER (CAHSetPos, "set_pos");
78 // ----------------------------------------------
79 class CAHFrontSelection : public IActionHandler
81 public:
82 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
84 if(!UserEntity)
85 return;
87 // select Enemy or enemy? Never select user
88 uint flags;
89 if(Params=="friend")
90 // for friend: select both dead and alive (for heal). But Select only Players (not bot)
91 flags= CEntityFilterFlag::NotUser | CEntityFilterFlag::Player | CEntityFilterFlag::Friend;
92 else
93 // for enemy: interesting to select only Alive entities (to chain-nuke)
94 // select both NonPlayer and Player (for PVP)
95 flags= CEntityFilterFlag::NotUser | CEntityFilterFlag::Enemy | CEntityFilterFlag::Alive;
97 // If there is an entity selected -> Set as the Target. Cycle with last target
98 CEntityCL *entity = EntitiesMngr.getEntityInCamera(flags, ClientCfg.SpaceSelectionDist, UserEntity->targetSlot());
99 if(entity)
101 // Select this entity.
102 UserEntity->selection(entity->slot());
103 // Yoyo: not interesting: commonly Fight (use shortcut instead)
104 // Launch Context Menu.
105 /*CInterfaceManager *IM = CInterfaceManager::getInstance();
106 IM->launchContextMenuInGame("ui:interface:game_context_menu");*/
110 REGISTER_ACTION_HANDLER (CAHFrontSelection, "front_selection");
112 // ------------------------------------------------------------------------------------------------
113 class CAHMove : public IActionHandler
115 public:
116 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
118 // Moving Break the Follow Mode
119 UserEntity->disableFollow();
120 UserEntity->moveTo(CLFECOMMON::INVALID_SLOT, 0.0, CUserEntity::None);
124 // ------------------------------------------------------------------------------------------------
125 class CAHTurnLeft : public CAHMove
128 REGISTER_ACTION_HANDLER (CAHTurnLeft, "turn_left");
130 // ------------------------------------------------------------------------------------------------
131 class CAHTurnRight : public CAHMove
134 REGISTER_ACTION_HANDLER (CAHTurnRight, "turn_right");
136 // ------------------------------------------------------------------------------------------------
137 class CAHStrafeLeft : public CAHMove
140 REGISTER_ACTION_HANDLER (CAHStrafeLeft, "strafe_left");
142 // ------------------------------------------------------------------------------------------------
143 class CAHStrafeRight : public CAHMove
146 REGISTER_ACTION_HANDLER (CAHStrafeRight, "strafe_right");
148 // ------------------------------------------------------------------------------------------------
149 class CAHForward : public CAHMove
152 REGISTER_ACTION_HANDLER (CAHForward, "forward");
154 // ------------------------------------------------------------------------------------------------
155 class CAHBackward : public CAHMove
158 REGISTER_ACTION_HANDLER (CAHBackward, "backward");
160 // ------------------------------------------------------------------------------------------------
161 class CAHToggleAutoWalk: public IActionHandler
163 public:
164 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
168 REGISTER_ACTION_HANDLER (CAHToggleAutoWalk, "toggle_auto_walk");
171 // ------------------------------------------------------------------------------------------------
172 class CAHToggleLight: public IActionHandler
174 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
176 UserEntity->light();
179 REGISTER_ACTION_HANDLER (CAHToggleLight, "toggle_light");
181 // ------------------------------------------------------------------------------------------------
182 class CAHFreeMouse : public IActionHandler
184 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
186 InitMouseWithCursor (!IsMouseCursorHardware ());
187 ClientCfg.HardwareCursor = IsMouseCursorHardware();
188 // if the game config window is opened, keep in sync
189 bool written = false;
190 CInterfaceManager *im = CInterfaceManager::getInstance();
191 if (im)
193 CInterfaceGroup *ig = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId("ui:interface:game_config"));
194 if (ig && ig->getActive())
196 CInterfaceGroup *igHard = dynamic_cast<CInterfaceGroup *>(ig->getGroup("hard"));
197 if (igHard)
199 CCtrlBaseButton *cbb = dynamic_cast<CCtrlBaseButton *>(igHard->getCtrl("c"));
200 if (cbb)
202 if(cbb->getPushed() != IsMouseCursorHardware())
204 cbb->setPushed(IsMouseCursorHardware());
205 cbb->runLeftClickAction();
206 written = true;
212 if (!written)
214 ClientCfg.writeBool("HardwareCursor", IsMouseCursorHardware());
218 REGISTER_ACTION_HANDLER (CAHFreeMouse, "free_mouse");
220 // ------------------------------------------------------------------------------------------------
221 class CAHToggleCamera : public IActionHandler
223 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
225 // Change the camera view
226 UserEntity->toggleCamera();
229 REGISTER_ACTION_HANDLER (CAHToggleCamera, "toggle_camera");
231 // ------------------------------------------------------------------------------------------------
232 class CAHTForceFP : public IActionHandler
234 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
236 // Change the camera view to first person
237 UserEntity->forceCameraFirstPerson();
240 REGISTER_ACTION_HANDLER (CAHTForceFP, "force_camera_fp");
242 // ------------------------------------------------------------------------------------------------
243 class CAHToggleNames : public IActionHandler
245 public:
246 CAHToggleNames()
248 _Count = 0;
251 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
253 CActionsManager *pAM = &Actions;
254 // Key Up
255 if(!pAM->valide(CAction::CName("toggle_names", Params.c_str())))
257 // Toggles Names back.
258 if(_Count > 1)
259 ClientCfg.Names = !ClientCfg.Names;
260 _Count = 0;
262 // Key Down
263 else
265 // First Time
266 if(_Count == 0)
267 ClientCfg.Names = !ClientCfg.Names;
268 _Count++;
271 private:
272 uint32 _Count;
274 REGISTER_ACTION_HANDLER (CAHToggleNames, "toggle_names");
276 // ------------------------------------------------------------------------------------------------
277 class CAHRearView : public IActionHandler
279 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
281 static bool PreviousShowInterface = true;
283 CActionsManager *pAM = &Actions;
284 // Key Down
285 if(pAM->valide(CAction::CName("rear_view", Params.c_str())))
287 PreviousShowInterface = ShowInterface; // save previous show interface value
288 ShowInterface = false;
289 View.rearView(true);
291 // Key Up
292 else
294 ShowInterface = PreviousShowInterface; // restore previous show interface value
295 View.rearView(false);
299 REGISTER_ACTION_HANDLER (CAHRearView, "rear_view");
301 // ------------------------------------------------------------------------------------------------
302 class CAHCameraUp : public IActionHandler
304 public:
305 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
309 REGISTER_ACTION_HANDLER (CAHCameraUp, "camera_up");
310 class CAHCameraDown : public IActionHandler
312 public:
313 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
317 REGISTER_ACTION_HANDLER (CAHCameraDown, "camera_down");
318 // ------------------------------------------------------------------------------------------------
319 class CAHCameraTurnLeft : public IActionHandler
321 public:
322 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
326 REGISTER_ACTION_HANDLER (CAHCameraTurnLeft, "camera_turn_left");
328 class CAHCameraTurnRight : public IActionHandler
330 public:
331 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
335 REGISTER_ACTION_HANDLER (CAHCameraTurnRight, "camera_turn_right");
337 class CAHCameraTurnCenter : public IActionHandler
339 public:
340 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
342 UserControls.resetSmoothCameraDeltaYaw();
345 REGISTER_ACTION_HANDLER (CAHCameraTurnCenter, "camera_turn_center");
348 // ------------------------------------------------------------------------------------------------
349 // Toggle Sit / Stand, but don't change speed
350 class CAHToggleSitStand: public IActionHandler
352 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
354 UserEntity->sit(!UserEntity->isSit());
357 REGISTER_ACTION_HANDLER (CAHToggleSitStand, "toggle_sit_stand");
359 // Force sit, but don't change speed
360 class CAHForceSit: public IActionHandler
362 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
364 if(!UserEntity->isSit())
366 // disable afk mode
367 UserEntity->setAFK(false);
369 UserEntity->sit(true);
373 REGISTER_ACTION_HANDLER (CAHForceSit, "force_sit");
375 // Force stand, but don't change speed
376 class CAHForceStand: public IActionHandler
378 void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */)
380 if(UserEntity->isSit())
381 UserEntity->sit(false);
384 REGISTER_ACTION_HANDLER (CAHForceStand, "force_stand");
387 // ------------------------------------------------------------------------------------------------
388 // Toggle run/walk, but don't unsit
389 class CAHToggleRunWalk : public IActionHandler
391 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
393 UserEntity->switchVelocity();
396 REGISTER_ACTION_HANDLER (CAHToggleRunWalk, "toggle_run_walk");
398 // force walk mode, and leave sit() mode if any
399 class CAHForceWalk : public IActionHandler
401 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
403 // swith velocity?
404 if(UserEntity->running())
405 UserEntity->switchVelocity();
407 // unsit?
408 if(UserEntity->isSit())
409 UserEntity->sit(false);
411 // leave afk mode?
412 if(UserEntity->isAFK())
413 UserEntity->setAFK(false);
416 REGISTER_ACTION_HANDLER (CAHForceWalk, "force_walk");
418 // force run mode, and leave sit() mode if any
419 class CAHForceRun : public IActionHandler
421 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
423 // swith velocity?
424 if(!UserEntity->running())
425 UserEntity->switchVelocity();
427 // unsit?
428 if(UserEntity->isSit())
429 UserEntity->sit(false);
431 // leave afk mode?
432 if(UserEntity->isAFK())
433 UserEntity->setAFK(false);
436 REGISTER_ACTION_HANDLER (CAHForceRun, "force_run");
438 // ------------------------------------------------------------------------------------------------
439 class CAHToggleDodgeParry : public IActionHandler
441 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
443 CInterfaceManager *pIM = CInterfaceManager::getInstance();
444 string msg;
445 // 0 - dodge mode
446 // 1 - parry mode
447 if (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEFENSE:DEFENSE_MODE")->getValue32() == 0)
449 sendMsgToServer("COMBAT:PARRY");
450 msg = CI18N::get("msgUserModeParry");
452 else
454 sendMsgToServer("COMBAT:DODGE");
455 msg = CI18N::get("msgUserModeDodge");
457 // display dodge/parry mode message
458 string cat = getStringCategory(msg, msg);
459 pIM->displaySystemInfo(msg, cat);
462 REGISTER_ACTION_HANDLER (CAHToggleDodgeParry, "toggle_dodge_parry");