From 7641216d0e29646a5990cb7104f4afd537737035 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 27 Dec 2023 15:23:15 +0100 Subject: [PATCH 1/5] add absolute mouse pos lua binding --- Lua/LuaBindingsManagers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Lua/LuaBindingsManagers.cpp b/Lua/LuaBindingsManagers.cpp index 935938025..337c8d61c 100644 --- a/Lua/LuaBindingsManagers.cpp +++ b/Lua/LuaBindingsManagers.cpp @@ -414,6 +414,7 @@ namespace RTE { .def("MouseButtonPressed", &UInputMan::MouseButtonPressed) .def("MouseButtonReleased", &UInputMan::MouseButtonReleased) .def("MouseButtonHeld", &UInputMan::MouseButtonHeld) + .def("GetMousePos", &UInputMan::GetAbsoluteMousePosition) .def("MouseWheelMoved", &UInputMan::MouseWheelMoved) .def("JoyButtonPressed", &UInputMan::JoyButtonPressed) .def("JoyButtonReleased", &UInputMan::JoyButtonReleased) From 0723798f34156f1e1a54b1d8c1a205c3011557d1 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 27 Dec 2023 15:24:58 +0100 Subject: [PATCH 2/5] add LockControlledActor to allow grabbing player input in lua scripts (mainly for GUIs but I'm sure there's other uses) --- Activities/GameActivity.cpp | 20 ++++++++++++++++++-- Activities/GameActivity.h | 12 ++++++++++++ Lua/LuaBindingsActivities.cpp | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Activities/GameActivity.cpp b/Activities/GameActivity.cpp index 7cad71f3b..87945b145 100644 --- a/Activities/GameActivity.cpp +++ b/Activities/GameActivity.cpp @@ -396,6 +396,20 @@ bool GameActivity::IsBuyGUIVisible(int which) const { } +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +bool GameActivity::LockControlledActor(Players player, bool lock, Controller::InputMode lockToMode) { + if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) { + m_LuaLockActor[player] = lock; + m_LuaLockActorMode[player] = lockToMode; + if (m_pBuyGUI[player]->IsVisible() || m_InventoryMenuGUI[player]->IsVisible()) { + m_LuaLockActor[player] = false; + return false; + } + return true; + } +} + ////////////////////////////////////////////////////////////////////////////////////////// // Virtual method: SwitchToActor ////////////////////////////////////////////////////////////////////////////////////////// @@ -1424,7 +1438,7 @@ void GameActivity::Update() m_ViewState[player] = ViewState::Normal; } // Switch to next actor if the player wants to. Don't do it while the buy menu is open - else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible()) + else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && !m_LuaLockActor[player]) { if (m_ControlledActor[player] && m_ControlledActor[player]->GetPieMenu()) { m_ControlledActor[player]->GetPieMenu()->SetEnabled(false); @@ -1444,7 +1458,7 @@ void GameActivity::Update() g_FrameMan.ClearScreenText(ScreenOfPlayer(player)); } // Go into manual actor select mode if either actor switch buttons are held for a duration - else if (m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && (m_PlayerController[player].IsState(ACTOR_NEXT_PREP) || m_PlayerController[player].IsState(ACTOR_PREV_PREP))) + else if (m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && !m_LuaLockActor[player] && (m_PlayerController[player].IsState(ACTOR_NEXT_PREP) || m_PlayerController[player].IsState(ACTOR_PREV_PREP))) { if (m_ActorSelectTimer[player].IsPastRealMS(250)) { @@ -2015,6 +2029,8 @@ void GameActivity::Update() m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_AI); } else if (m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel()) { m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_DISABLED); + } else if (m_LuaLockActor[player]) { + m_ControlledActor[player]->GetController()->SetInputMode(m_LuaLockActorMode[player]); } else { m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_PLAYER); } diff --git a/Activities/GameActivity.h b/Activities/GameActivity.h index 6dcb0a8a4..34c6b548c 100644 --- a/Activities/GameActivity.h +++ b/Activities/GameActivity.h @@ -252,6 +252,16 @@ class GameActivity : public Activity { SceneEditorGUI * GetEditorGUI(unsigned int which = 0) const { return m_pEditorGUI[which]; } + /// + /// Locks a player controlled actor to a specific controller mode. + /// Locking the actor will disable player input, including switching actors. + /// Locking will fail if the actor is already locked for another reason (such as being in a menu). + /// + /// Which player to lock the actor for. + /// Whether to lock or unlock the actor. (Default: true) + /// Which controller mode to lock the actor to. (Default: `CIM_AI`) + /// Whether the (un)lock was performed. + bool LockControlledActor(Players player, bool lock = true, Controller::InputMode lockToMode = Controller::InputMode::CIM_AI); ////////////////////////////////////////////////////////////////////////////////////////// // Virtual method: SwitchToActor @@ -1035,6 +1045,8 @@ class GameActivity : public Activity { BuyMenuGUI *m_pBuyGUI[Players::MaxPlayerCount]; // The in-game scene editor GUI for each player SceneEditorGUI *m_pEditorGUI[Players::MaxPlayerCount]; + bool m_LuaLockActor[Players::MaxPlayerCount]; //!< Whether or not to lock input for each player while lua has control. + Controller::InputMode m_LuaLockActorMode[Players::MaxPlayerCount]; //!< The input mode to lock to while lua has control. // The in-game important message banners for each player GUIBanner *m_pBannerRed[Players::MaxPlayerCount]; GUIBanner *m_pBannerYellow[Players::MaxPlayerCount]; diff --git a/Lua/LuaBindingsActivities.cpp b/Lua/LuaBindingsActivities.cpp index e30883653..aef4b0fd9 100644 --- a/Lua/LuaBindingsActivities.cpp +++ b/Lua/LuaBindingsActivities.cpp @@ -149,6 +149,7 @@ namespace RTE { .def("SetActorSelectCursor", &GameActivity::SetActorSelectCursor) .def("GetBuyGUI", &GameActivity::GetBuyGUI) .def("GetEditorGUI", &GameActivity::GetEditorGUI) + .def("LockControlledActor", &GameActivity::LockControlledActor) .def("OtherTeam", &GameActivity::OtherTeam) .def("OneOrNoneTeamsLeft", &GameActivity::OneOrNoneTeamsLeft) .def("WhichTeamLeft", &GameActivity::WhichTeamLeft) From 23c22833e5de9ee18d96b3e99d5998a5cf1f4744 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 27 Dec 2023 15:31:13 +0100 Subject: [PATCH 3/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 238627c1c..117462bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - `Enum` binding for `SceneObject.BuyableMode`: `NORESTRICTIONS = 0, BUYMENUONLY = 1, OBJECTPICKERONLY = 2, SCRIPTONLY = 3`. +- Exposed `UInputMan::AbsoluteMousePos` to Lua + +- New `GameActivity::LockControlledActor` Lua function to allow grab player input in the way menus (buy menu/full inventorymenu) do. +
Changed From 3b8eb9839b2e86398ff42130b1eb14ada56e28ff Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 27 Dec 2023 15:33:59 +0100 Subject: [PATCH 4/5] remove locking restrictions --- Activities/GameActivity.cpp | 6 ++---- Activities/GameActivity.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Activities/GameActivity.cpp b/Activities/GameActivity.cpp index 87945b145..be92f33d7 100644 --- a/Activities/GameActivity.cpp +++ b/Activities/GameActivity.cpp @@ -400,14 +400,12 @@ bool GameActivity::IsBuyGUIVisible(int which) const { bool GameActivity::LockControlledActor(Players player, bool lock, Controller::InputMode lockToMode) { if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) { + bool prevLock = m_LuaLockActor[player]; m_LuaLockActor[player] = lock; m_LuaLockActorMode[player] = lockToMode; - if (m_pBuyGUI[player]->IsVisible() || m_InventoryMenuGUI[player]->IsVisible()) { - m_LuaLockActor[player] = false; - return false; - } return true; } + return false; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Activities/GameActivity.h b/Activities/GameActivity.h index 34c6b548c..a60b9595c 100644 --- a/Activities/GameActivity.h +++ b/Activities/GameActivity.h @@ -255,7 +255,6 @@ class GameActivity : public Activity { /// /// Locks a player controlled actor to a specific controller mode. /// Locking the actor will disable player input, including switching actors. - /// Locking will fail if the actor is already locked for another reason (such as being in a menu). /// /// Which player to lock the actor for. /// Whether to lock or unlock the actor. (Default: true) From 83ad85057a29ad0deb96e53f2b860c5b60c2ed1d Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Wed, 27 Dec 2023 15:36:27 +0100 Subject: [PATCH 5/5] trap mouse to player while locked --- Activities/GameActivity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Activities/GameActivity.cpp b/Activities/GameActivity.cpp index be92f33d7..2a7386611 100644 --- a/Activities/GameActivity.cpp +++ b/Activities/GameActivity.cpp @@ -1979,7 +1979,7 @@ void GameActivity::Update() } // Trap the mouse if we're in gameplay and not in menus - g_UInputMan.TrapMousePos(!m_pBuyGUI[player]->IsEnabled() && !m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel(), player); + g_UInputMan.TrapMousePos(!m_pBuyGUI[player]->IsEnabled() && !m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel() && !m_LuaLockActor[player], player); // Start LZ picking mode if a purchase was made if (m_pBuyGUI[player]->PurchaseMade())