Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' into walkpath-auto-crouch
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Dec 28, 2023
2 parents b3d1f2b + 631c038 commit 7478bb7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
20 changes: 17 additions & 3 deletions Activities/GameActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,18 @@ 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;
return true;
}
return false;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Virtual method: SwitchToActor
//////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1424,7 +1436,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);
Expand All @@ -1444,7 +1456,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))
{
Expand Down Expand Up @@ -1967,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())
Expand Down Expand Up @@ -2015,6 +2027,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);
}
Expand Down
11 changes: 11 additions & 0 deletions Activities/GameActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ class GameActivity : public Activity {

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

/// <summary>
/// Locks a player controlled actor to a specific controller mode.
/// Locking the actor will disable player input, including switching actors.
/// </summary>
/// <param name="player">Which player to lock the actor for.</param>
/// <param name="lock">Whether to lock or unlock the actor. (Default: true)</param>
/// <param name="lockToMode">Which controller mode to lock the actor to. (Default: `CIM_AI`)</param>
/// <returns>Whether the (un)lock was performed.</returns>
bool LockControlledActor(Players player, bool lock = true, Controller::InputMode lockToMode = Controller::InputMode::CIM_AI);

//////////////////////////////////////////////////////////////////////////////////////////
// Virtual method: SwitchToActor
Expand Down Expand Up @@ -1035,6 +1044,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];
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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.

</details>

<details><summary><b>Changed</b></summary>
Expand Down
8 changes: 7 additions & 1 deletion Entities/HDFirearm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ThrownDevice.h"
#include "MOPixel.h"
#include "Actor.h"
#include "Scene.h"

namespace RTE {

Expand Down Expand Up @@ -1062,7 +1063,12 @@ void HDFirearm::Update()
if (m_FireSound && !(m_FireSound->GetLoopSetting() == -1 && m_FireSound->IsBeingPlayed())) {
m_FireSound->Play(m_Pos);
}
if (m_FireEchoSound) { m_FireEchoSound->Play(m_Pos); }
if (m_FireEchoSound) {
Scene::Area* noEchoArea = g_SceneMan.GetScene()->GetOptionalArea("IndoorArea");
if (noEchoArea == nullptr || !noEchoArea->IsInside(m_Pos)) {
m_FireEchoSound->Play(m_Pos);
}
}
}

if (m_Loudness > 0) { g_MovableMan.RegisterAlarmEvent(AlarmEvent(m_Pos, m_Team, m_Loudness)); }
Expand Down
1 change: 1 addition & 0 deletions Lua/LuaBindingsActivities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Lua/LuaBindingsManagers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7478bb7

Please sign in to comment.