Skip to content

Commit 0723798

Browse files
committed
add LockControlledActor to allow grabbing player input in lua scripts (mainly for GUIs but I'm sure there's other uses)
1 parent 7641216 commit 0723798

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Activities/GameActivity.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,20 @@ bool GameActivity::IsBuyGUIVisible(int which) const {
396396

397397
}
398398

399+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
400+
401+
bool GameActivity::LockControlledActor(Players player, bool lock, Controller::InputMode lockToMode) {
402+
if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
403+
m_LuaLockActor[player] = lock;
404+
m_LuaLockActorMode[player] = lockToMode;
405+
if (m_pBuyGUI[player]->IsVisible() || m_InventoryMenuGUI[player]->IsVisible()) {
406+
m_LuaLockActor[player] = false;
407+
return false;
408+
}
409+
return true;
410+
}
411+
}
412+
399413
//////////////////////////////////////////////////////////////////////////////////////////
400414
// Virtual method: SwitchToActor
401415
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1424,7 +1438,7 @@ void GameActivity::Update()
14241438
m_ViewState[player] = ViewState::Normal;
14251439
}
14261440
// Switch to next actor if the player wants to. Don't do it while the buy menu is open
1427-
else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible())
1441+
else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && !m_LuaLockActor[player])
14281442
{
14291443
if (m_ControlledActor[player] && m_ControlledActor[player]->GetPieMenu()) {
14301444
m_ControlledActor[player]->GetPieMenu()->SetEnabled(false);
@@ -1444,7 +1458,7 @@ void GameActivity::Update()
14441458
g_FrameMan.ClearScreenText(ScreenOfPlayer(player));
14451459
}
14461460
// Go into manual actor select mode if either actor switch buttons are held for a duration
1447-
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)))
1461+
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)))
14481462
{
14491463
if (m_ActorSelectTimer[player].IsPastRealMS(250))
14501464
{
@@ -2015,6 +2029,8 @@ void GameActivity::Update()
20152029
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_AI);
20162030
} else if (m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel()) {
20172031
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_DISABLED);
2032+
} else if (m_LuaLockActor[player]) {
2033+
m_ControlledActor[player]->GetController()->SetInputMode(m_LuaLockActorMode[player]);
20182034
} else {
20192035
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_PLAYER);
20202036
}

Activities/GameActivity.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ class GameActivity : public Activity {
252252

253253
SceneEditorGUI * GetEditorGUI(unsigned int which = 0) const { return m_pEditorGUI[which]; }
254254

255+
/// <summary>
256+
/// Locks a player controlled actor to a specific controller mode.
257+
/// Locking the actor will disable player input, including switching actors.
258+
/// Locking will fail if the actor is already locked for another reason (such as being in a menu).
259+
/// </summary>
260+
/// <param name="player">Which player to lock the actor for.</param>
261+
/// <param name="lock">Whether to lock or unlock the actor. (Default: true)</param>
262+
/// <param name="lockToMode">Which controller mode to lock the actor to. (Default: `CIM_AI`)</param>
263+
/// <returns>Whether the (un)lock was performed.</returns>
264+
bool LockControlledActor(Players player, bool lock = true, Controller::InputMode lockToMode = Controller::InputMode::CIM_AI);
255265

256266
//////////////////////////////////////////////////////////////////////////////////////////
257267
// Virtual method: SwitchToActor
@@ -1035,6 +1045,8 @@ class GameActivity : public Activity {
10351045
BuyMenuGUI *m_pBuyGUI[Players::MaxPlayerCount];
10361046
// The in-game scene editor GUI for each player
10371047
SceneEditorGUI *m_pEditorGUI[Players::MaxPlayerCount];
1048+
bool m_LuaLockActor[Players::MaxPlayerCount]; //!< Whether or not to lock input for each player while lua has control.
1049+
Controller::InputMode m_LuaLockActorMode[Players::MaxPlayerCount]; //!< The input mode to lock to while lua has control.
10381050
// The in-game important message banners for each player
10391051
GUIBanner *m_pBannerRed[Players::MaxPlayerCount];
10401052
GUIBanner *m_pBannerYellow[Players::MaxPlayerCount];

Lua/LuaBindingsActivities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace RTE {
149149
.def("SetActorSelectCursor", &GameActivity::SetActorSelectCursor)
150150
.def("GetBuyGUI", &GameActivity::GetBuyGUI)
151151
.def("GetEditorGUI", &GameActivity::GetEditorGUI)
152+
.def("LockControlledActor", &GameActivity::LockControlledActor)
152153
.def("OtherTeam", &GameActivity::OtherTeam)
153154
.def("OneOrNoneTeamsLeft", &GameActivity::OneOrNoneTeamsLeft)
154155
.def("WhichTeamLeft", &GameActivity::WhichTeamLeft)

0 commit comments

Comments
 (0)