Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / action_handler_move.cpp
blob71f7b55eebcaaac1d000b293ec25f7d41139bfc1
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 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
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/>.
24 #include "stdpch.h"
26 using namespace std;
27 using namespace NLMISC;
29 #include "nel/gui/action_handler.h"
30 #include "../motion/user_controls.h"
31 #include "../view.h"
32 #include "../misc.h"
33 #include "../input.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"
41 ////////////
42 // GLOBAL //
43 ////////////
44 extern sint CompassMode;
45 extern class CView View;
46 extern CUserControls UserControls;
47 extern bool ShowInterface;
50 /**********************************************************************************************************
51 * *
52 * debug handlers actions *
53 * *
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
82 public:
83 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
85 if(!UserEntity)
86 return;
88 // select Enemy or enemy? Never select user
89 uint flags;
90 if(Params=="friend")
91 // for friend: select both dead and alive (for heal). But Select only Players (not bot)
92 flags= CEntityFilterFlag::NotUser | CEntityFilterFlag::Player | CEntityFilterFlag::Friend;
93 else
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());
100 if(entity)
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
116 public:
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
164 public:
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 */)
177 UserEntity->light();
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();
192 if (im)
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"));
198 if (igHard)
200 CCtrlBaseButton *cbb = dynamic_cast<CCtrlBaseButton *>(igHard->getCtrl("c"));
201 if (cbb)
203 if(cbb->getPushed() != IsMouseCursorHardware())
205 cbb->setPushed(IsMouseCursorHardware());
206 cbb->runLeftClickAction();
207 written = true;
213 if (!written)
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
246 public:
247 CAHToggleNames()
249 _Count = 0;
252 virtual void execute (CCtrlBase * /* pCaller */, const string &Params)
254 CActionsManager *pAM = &Actions;
255 // Key Up
256 if(!pAM->valide(CAction::CName("toggle_names", Params.c_str())))
258 // Toggles Names back.
259 if(_Count > 1)
260 ClientCfg.Names = !ClientCfg.Names;
261 _Count = 0;
263 // Key Down
264 else
266 // First Time
267 if(_Count == 0)
268 ClientCfg.Names = !ClientCfg.Names;
269 _Count++;
272 private:
273 uint32 _Count;
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;
285 // Key Down
286 if(pAM->valide(CAction::CName("rear_view", Params.c_str())))
288 PreviousShowInterface = ShowInterface; // save previous show interface value
289 ShowInterface = false;
290 View.rearView(true);
292 // Key Up
293 else
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
305 public:
306 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
310 REGISTER_ACTION_HANDLER (CAHCameraUp, "camera_up");
311 class CAHCameraDown : public IActionHandler
313 public:
314 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
318 REGISTER_ACTION_HANDLER (CAHCameraDown, "camera_down");
319 // ------------------------------------------------------------------------------------------------
320 class CAHCameraTurnLeft : public IActionHandler
322 public:
323 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
327 REGISTER_ACTION_HANDLER (CAHCameraTurnLeft, "camera_turn_left");
329 class CAHCameraTurnRight : public IActionHandler
331 public:
332 virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
336 REGISTER_ACTION_HANDLER (CAHCameraTurnRight, "camera_turn_right");
338 class CAHCameraTurnCenter : public IActionHandler
340 public:
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())
367 // disable afk mode
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 */)
404 // swith velocity?
405 if(UserEntity->running())
406 UserEntity->switchVelocity();
408 // unsit?
409 if(UserEntity->isSit())
410 UserEntity->sit(false);
412 // leave afk mode?
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 */)
424 // swith velocity?
425 if(!UserEntity->running())
426 UserEntity->switchVelocity();
428 // unsit?
429 if(UserEntity->isSit())
430 UserEntity->sit(false);
432 // leave afk mode?
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();
445 string msg;
446 // 0 - dodge mode
447 // 1 - parry mode
448 if (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:DEFENSE:DEFENSE_MODE")->getValue32() == 0)
450 sendMsgToServer("COMBAT:PARRY");
451 msg = CI18N::get("msgUserModeParry");
453 else
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");