2020-04-08 19:33:07 +04:00
|
|
|
#include "actionmanager.hpp"
|
|
|
|
|
|
|
|
#include <MyGUI_InputManager.h>
|
|
|
|
|
|
|
|
#include <SDL_keyboard.h>
|
|
|
|
|
2023-10-27 12:24:42 +02:00
|
|
|
#include <components/settings/values.hpp>
|
2020-04-08 19:33:07 +04:00
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/inputmanager.hpp"
|
2021-06-26 23:10:24 +02:00
|
|
|
#include "../mwbase/luamanager.hpp"
|
2020-04-08 19:33:07 +04:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
#include "../mwbase/statemanager.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
2023-02-07 00:37:55 +01:00
|
|
|
#include "../mwworld/globals.hpp"
|
2020-04-08 19:33:07 +04:00
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
|
|
|
#include "actions.hpp"
|
2020-04-17 15:21:23 +04:00
|
|
|
#include "bindingsmanager.hpp"
|
2020-04-08 19:33:07 +04:00
|
|
|
|
|
|
|
namespace MWInput
|
|
|
|
{
|
|
|
|
|
2024-06-06 11:23:05 +03:00
|
|
|
ActionManager::ActionManager(BindingsManager* bindingsManager, osg::ref_ptr<osgViewer::Viewer> viewer,
|
|
|
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler)
|
2020-04-17 15:21:23 +04:00
|
|
|
: mBindingsManager(bindingsManager)
|
2023-07-29 12:58:27 +04:00
|
|
|
, mViewer(std::move(viewer))
|
|
|
|
, mScreenCaptureHandler(std::move(screenCaptureHandler))
|
2020-04-16 16:36:32 +04:00
|
|
|
, mTimeIdle(0.f)
|
2020-04-08 19:33:07 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-05 23:31:23 +01:00
|
|
|
void ActionManager::update(float dt)
|
2020-04-16 16:36:32 +04:00
|
|
|
{
|
2020-04-17 15:21:23 +04:00
|
|
|
if (mBindingsManager->actionIsActive(A_MoveForward) || mBindingsManager->actionIsActive(A_MoveBackward)
|
|
|
|
|| mBindingsManager->actionIsActive(A_MoveLeft) || mBindingsManager->actionIsActive(A_MoveRight)
|
|
|
|
|| mBindingsManager->actionIsActive(A_Jump) || mBindingsManager->actionIsActive(A_Sneak)
|
|
|
|
|| mBindingsManager->actionIsActive(A_TogglePOV) || mBindingsManager->actionIsActive(A_ZoomIn)
|
|
|
|
|| mBindingsManager->actionIsActive(A_ZoomOut))
|
2020-04-16 16:36:32 +04:00
|
|
|
{
|
|
|
|
resetIdleTime();
|
|
|
|
}
|
|
|
|
else
|
2021-06-14 19:58:04 +02:00
|
|
|
mTimeIdle += dt;
|
2020-04-16 16:36:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::resetIdleTime()
|
|
|
|
{
|
|
|
|
mTimeIdle = 0.f;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:33:07 +04:00
|
|
|
void ActionManager::executeAction(int action)
|
|
|
|
{
|
2021-06-26 23:10:24 +02:00
|
|
|
MWBase::Environment::get().getLuaManager()->inputEvent({ MWBase::LuaManager::InputEvent::Action, action });
|
2022-05-06 17:46:50 +02:00
|
|
|
const auto inputManager = MWBase::Environment::get().getInputManager();
|
|
|
|
const auto windowManager = MWBase::Environment::get().getWindowManager();
|
2020-04-08 19:33:07 +04:00
|
|
|
// trigger action activated
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case A_GameMenu:
|
|
|
|
toggleMainMenu();
|
|
|
|
break;
|
|
|
|
case A_Screenshot:
|
|
|
|
screenshot();
|
|
|
|
break;
|
|
|
|
case A_Console:
|
|
|
|
toggleConsole();
|
|
|
|
break;
|
|
|
|
case A_Activate:
|
2020-07-25 22:42:58 +02:00
|
|
|
inputManager->resetIdleTime();
|
2020-04-08 19:33:07 +04:00
|
|
|
activate();
|
|
|
|
break;
|
|
|
|
case A_MoveLeft:
|
|
|
|
case A_MoveRight:
|
|
|
|
case A_MoveForward:
|
|
|
|
case A_MoveBackward:
|
|
|
|
handleGuiArrowKey(action);
|
|
|
|
break;
|
|
|
|
case A_Rest:
|
|
|
|
rest();
|
|
|
|
break;
|
|
|
|
case A_QuickKey1:
|
|
|
|
quickKey(1);
|
|
|
|
break;
|
|
|
|
case A_QuickKey2:
|
|
|
|
quickKey(2);
|
|
|
|
break;
|
|
|
|
case A_QuickKey3:
|
|
|
|
quickKey(3);
|
|
|
|
break;
|
|
|
|
case A_QuickKey4:
|
|
|
|
quickKey(4);
|
|
|
|
break;
|
|
|
|
case A_QuickKey5:
|
|
|
|
quickKey(5);
|
|
|
|
break;
|
|
|
|
case A_QuickKey6:
|
|
|
|
quickKey(6);
|
|
|
|
break;
|
|
|
|
case A_QuickKey7:
|
|
|
|
quickKey(7);
|
|
|
|
break;
|
|
|
|
case A_QuickKey8:
|
|
|
|
quickKey(8);
|
|
|
|
break;
|
|
|
|
case A_QuickKey9:
|
|
|
|
quickKey(9);
|
|
|
|
break;
|
|
|
|
case A_QuickKey10:
|
|
|
|
quickKey(10);
|
|
|
|
break;
|
|
|
|
case A_ToggleHUD:
|
2023-10-25 12:34:56 +00:00
|
|
|
windowManager->setHudVisibility(!windowManager->isHudVisible());
|
2020-04-08 19:33:07 +04:00
|
|
|
break;
|
|
|
|
case A_ToggleDebug:
|
2020-07-25 22:42:58 +02:00
|
|
|
windowManager->toggleDebugWindow();
|
2020-04-08 19:33:07 +04:00
|
|
|
break;
|
2022-05-13 18:58:00 -07:00
|
|
|
case A_TogglePostProcessorHUD:
|
|
|
|
windowManager->togglePostProcessorHud();
|
|
|
|
break;
|
2020-04-08 19:33:07 +04:00
|
|
|
case A_QuickSave:
|
|
|
|
quickSave();
|
|
|
|
break;
|
|
|
|
case A_QuickLoad:
|
|
|
|
quickLoad();
|
|
|
|
break;
|
|
|
|
case A_CycleSpellLeft:
|
2020-07-25 22:42:58 +02:00
|
|
|
if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Magic))
|
2020-04-08 19:33:07 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->cycleSpell(false);
|
|
|
|
break;
|
|
|
|
case A_CycleSpellRight:
|
2020-07-25 22:42:58 +02:00
|
|
|
if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Magic))
|
2020-04-08 19:33:07 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->cycleSpell(true);
|
|
|
|
break;
|
|
|
|
case A_CycleWeaponLeft:
|
2020-07-25 22:42:58 +02:00
|
|
|
if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Inventory))
|
2020-04-08 19:33:07 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->cycleWeapon(false);
|
|
|
|
break;
|
|
|
|
case A_CycleWeaponRight:
|
2020-07-25 22:42:58 +02:00
|
|
|
if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Inventory))
|
2020-04-08 19:33:07 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->cycleWeapon(true);
|
|
|
|
break;
|
2023-07-16 19:10:49 +02:00
|
|
|
case A_Inventory:
|
|
|
|
case A_Journal:
|
|
|
|
case A_QuickKeysMenu:
|
|
|
|
// Handled in Lua
|
|
|
|
break;
|
2020-04-08 19:33:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ActionManager::checkAllowedToUseItems() const
|
|
|
|
{
|
|
|
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
|
|
|
if (player.getClass().getNpcStats(player).isWerewolf())
|
|
|
|
{
|
|
|
|
// Cannot use items or spells while in werewolf form
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sWerewolfRefusal}");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::screenshot()
|
|
|
|
{
|
2024-06-06 11:23:05 +03:00
|
|
|
mScreenCaptureHandler->setFramesToCapture(1);
|
|
|
|
mScreenCaptureHandler->captureNextFrame(*mViewer);
|
2020-04-08 19:33:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::toggleMainMenu()
|
|
|
|
{
|
|
|
|
if (MyGUI::InputManager::getInstance().isModalAny())
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->exitCurrentModal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isConsoleMode())
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-19 21:43:46 +02:00
|
|
|
if (MWBase::Environment::get().getWindowManager()->isPostProcessorHudVisible())
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->togglePostProcessorHud();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:33:07 +04:00
|
|
|
if (!MWBase::Environment::get().getWindowManager()->isGuiMode()) // No open GUIs, open up the MainMenu
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_MainMenu);
|
|
|
|
}
|
|
|
|
else // Close current GUI
|
|
|
|
{
|
|
|
|
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::quickLoad()
|
|
|
|
{
|
|
|
|
if (!MyGUI::InputManager::getInstance().isModalAny())
|
|
|
|
MWBase::Environment::get().getStateManager()->quickLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::quickSave()
|
|
|
|
{
|
|
|
|
if (!MyGUI::InputManager::getInstance().isModalAny())
|
|
|
|
MWBase::Environment::get().getStateManager()->quickSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::rest()
|
|
|
|
{
|
|
|
|
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"))
|
|
|
|
return;
|
|
|
|
|
2020-04-17 16:51:47 +04:00
|
|
|
if (!MWBase::Environment::get().getWindowManager()->getRestEnabled()
|
|
|
|
|| MWBase::Environment::get().getWindowManager()->isGuiMode())
|
2020-04-08 19:33:07 +04:00
|
|
|
return;
|
|
|
|
|
2020-04-17 16:51:47 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Rest); // Open rest GUI
|
2020-04-08 19:33:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::toggleConsole()
|
|
|
|
{
|
2020-04-17 16:51:47 +04:00
|
|
|
if (MyGUI::InputManager::getInstance().isModalAny())
|
2020-04-08 19:33:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->toggleConsole();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::quickKey(int index)
|
|
|
|
{
|
|
|
|
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols")
|
|
|
|
|| !MWBase::Environment::get().getInputManager()->getControlSwitch("playerfighting")
|
|
|
|
|| !MWBase::Environment::get().getInputManager()->getControlSwitch("playermagic"))
|
|
|
|
return;
|
|
|
|
if (!checkAllowedToUseItems())
|
|
|
|
return;
|
|
|
|
|
2023-02-07 00:37:55 +01:00
|
|
|
if (MWBase::Environment::get().getWorld()->getGlobalFloat(MWWorld::Globals::sCharGenState) != -1)
|
2020-04-08 19:33:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
MWBase::Environment::get().getWindowManager()->activateQuickKey(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::activate()
|
|
|
|
{
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
|
|
|
{
|
|
|
|
bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed();
|
2020-04-17 15:21:23 +04:00
|
|
|
if (!SDL_IsTextInputActive() && !mBindingsManager->isLeftOrRightButton(A_Activate, joystickUsed))
|
2020-04-08 19:33:07 +04:00
|
|
|
MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Return, 0, false);
|
|
|
|
}
|
|
|
|
else if (MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"))
|
|
|
|
{
|
|
|
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
|
|
|
player.activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 16:29:24 +02:00
|
|
|
bool ActionManager::isSneaking() const
|
|
|
|
{
|
|
|
|
const MWBase::Environment& env = MWBase::Environment::get();
|
|
|
|
return env.getMechanicsManager()->isSneaking(env.getWorld()->getPlayer().getPlayer());
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:33:07 +04:00
|
|
|
void ActionManager::handleGuiArrowKey(int action)
|
|
|
|
{
|
|
|
|
bool joystickUsed = MWBase::Environment::get().getInputManager()->joystickLastUsed();
|
|
|
|
// This is currently keyboard-specific code
|
|
|
|
// TODO: see if GUI controls can be refactored into a single function
|
|
|
|
if (joystickUsed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_IsTextInputActive())
|
|
|
|
return;
|
|
|
|
|
2020-04-17 15:21:23 +04:00
|
|
|
if (mBindingsManager->isLeftOrRightButton(action, joystickUsed))
|
2020-04-08 19:33:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
MyGUI::KeyCode key;
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case A_MoveLeft:
|
|
|
|
key = MyGUI::KeyCode::ArrowLeft;
|
|
|
|
break;
|
|
|
|
case A_MoveRight:
|
|
|
|
key = MyGUI::KeyCode::ArrowRight;
|
|
|
|
break;
|
|
|
|
case A_MoveForward:
|
|
|
|
key = MyGUI::KeyCode::ArrowUp;
|
|
|
|
break;
|
|
|
|
case A_MoveBackward:
|
|
|
|
default:
|
|
|
|
key = MyGUI::KeyCode::ArrowDown;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->injectKeyPress(key, 0, false);
|
|
|
|
}
|
|
|
|
}
|