fix: radio wheel input rework, weapon-apply guard, control-lock/close fixes (issue #31 review)
linux / build (push) Successful in 24m49s
linux / build (push) Successful in 24m49s
This commit is contained in:
+147
-37
@@ -8,15 +8,25 @@
|
||||
* Interaction (both wheels share one state machine and one radial primitive):
|
||||
* weapon wheel keyboard+mouse: hold Tab, point with the mouse (or WASD/arrows)
|
||||
* gamepad: hold R2, point with the right stick
|
||||
* radio wheel keyboard+mouse: hold R while in a radio-equipped vehicle
|
||||
* gamepad: hold L2 while in a radio-equipped vehicle
|
||||
* The weapon wheel freezes the player while it is held
|
||||
* (PLAYERCONTROL_CAMERA) because it is used on foot; this is
|
||||
* intended and matches GTA V standing still.
|
||||
* radio wheel keyboard+mouse: hold R while in a radio-equipped vehicle,
|
||||
* cycle with left/right arrows or the mouse wheel
|
||||
* gamepad: hold R3, cycle with D-pad left/right or the
|
||||
* mouse wheel
|
||||
* The radio wheel does NOT set PLAYERCONTROL_CAMERA and does
|
||||
* not use the right stick, so throttle, brake, steering
|
||||
* (left stick), handbrake and drive-by aiming keep working
|
||||
* while the car is being driven.
|
||||
* Releasing applies the highlighted entry. Mouse wheel or D-pad left/right
|
||||
* cycles the entry inside one segment (only the grenade/detonator segment has
|
||||
* more than one entry).
|
||||
*
|
||||
* While a wheel is open PLAYERCONTROL_CAMERA is set so the mouse/right stick
|
||||
* does not rotate the camera or fire; time is NOT slowed by default (see
|
||||
* IMPROVED_WEAPON_WHEEL_SLOWMO).
|
||||
* PLAYERCONTROL_CAMERA is a global input gate in this engine
|
||||
* (CPad::ArePlayerControlsDisabled), not a camera-only switch, so it is applied
|
||||
* only for the on-foot weapon wheel. An optional light 0.35x time-slow is
|
||||
* available behind IMPROVED_WEAPON_WHEEL_SLOWMO but is off by default.
|
||||
*
|
||||
* Optional art: `weapon_wheel/wwN.png` and `weapon_wheel/iconN.png` next to the
|
||||
* executable. They are third-party assets and are never shipped with the
|
||||
@@ -31,6 +41,7 @@
|
||||
#include "weaponwheel.h"
|
||||
|
||||
#include "Camera.h"
|
||||
#include "CutsceneMgr.h"
|
||||
#include "DMAudio.h"
|
||||
#include "Font.h"
|
||||
#include "Frontend.h"
|
||||
@@ -42,6 +53,9 @@
|
||||
#include "PlayerInfo.h"
|
||||
#include "PlayerPed.h"
|
||||
#include "Replay.h"
|
||||
#ifdef GTA_SCENE_EDIT
|
||||
#include "SceneEdit.h"
|
||||
#endif
|
||||
#include "Sprite2d.h"
|
||||
#include "Text.h"
|
||||
#include "Timer.h"
|
||||
@@ -54,7 +68,9 @@ extern wchar WideErrorString[];
|
||||
|
||||
enum
|
||||
{
|
||||
WHEEL_SEGMENTS = 12, // one segment per eWeaponType 0..11 (detonator shares 11)
|
||||
// One segment per eWeaponType 0..11; detonator (12) shares segment 11.
|
||||
// See src/weapons/WeaponType.h for the eWeaponType ordering.
|
||||
WHEEL_SEGMENTS = 12,
|
||||
WHEEL_ARC_STEPS = 4, // quads per segment, only for the procedural ring
|
||||
WHEEL_MAX_RADIO = 12
|
||||
};
|
||||
@@ -104,8 +120,10 @@ static bool ms_bRadio;
|
||||
static int32 ms_nSegments;
|
||||
static int32 ms_nHovered; // -1 means "nothing pointed at"
|
||||
static int32 ms_nCurrentSegment; // segment of the currently equipped entry
|
||||
static bool ms_bSelectionMoved; // radio wheel: player actually cycled
|
||||
static float ms_fCursorX, ms_fCursorY;
|
||||
static bool ms_bCameraWasDisabled;
|
||||
static bool ms_bCameraWasDisabled; // bit was already set when a weapon wheel opened
|
||||
static bool ms_bOwnCameraBit; // this wheel set PLAYERCONTROL_CAMERA
|
||||
#ifdef IMPROVED_WEAPON_WHEEL_SLOWMO
|
||||
static float ms_fSavedTimeScale;
|
||||
#endif
|
||||
@@ -115,7 +133,8 @@ static int8 ms_aLastWeapon[WHEEL_SEGMENTS];
|
||||
|
||||
// Radio wheel contents, rebuilt on open.
|
||||
static uint8 ms_aRadioStation[WHEEL_MAX_RADIO];
|
||||
static const char *ms_aRadioLabel[WHEEL_MAX_RADIO];
|
||||
static const char *ms_aRadioLabel[WHEEL_MAX_RADIO]; // ASCII fallback
|
||||
static wchar *ms_apRadioName[WHEEL_MAX_RADIO]; // resolved GXT name or nil
|
||||
static int32 ms_nRadioCount;
|
||||
|
||||
// Optional art, loaded lazily and never freed (process lifetime, like other
|
||||
@@ -350,6 +369,12 @@ Wheel_ApplyWeapon(void)
|
||||
ms_aLastWeapon[ms_nHovered] = (int8)weapon;
|
||||
player->m_nSelectedWepSlot = (int8)weapon;
|
||||
|
||||
// Mirror ProcessWeaponSwitch's m_nSelectedWepSlot != m_currentWeapon check
|
||||
// (PlayerPed.cpp:667): re-picking the equipped weapon must not call
|
||||
// MakeChangesForNewWeapon, which would refill the clip for free.
|
||||
if (player->m_nSelectedWepSlot == player->m_currentWeapon)
|
||||
return;
|
||||
|
||||
// Same rule as the reversed ProcessWeaponSwitch: don't yank the weapon out
|
||||
// mid-attack/aim; the regular switch logic applies it when the state allows.
|
||||
if (player->m_nPedState != PED_ATTACK && player->m_nPedState != PED_AIM_GUN && player->m_nPedState != PED_FIGHT)
|
||||
@@ -393,20 +418,27 @@ Wheel_BuildRadioList(void)
|
||||
for (int32 i = 0; i < (int32)ARRAY_SIZE(ms_aRadioBase) && ms_nRadioCount < WHEEL_MAX_RADIO; i++) {
|
||||
ms_aRadioStation[ms_nRadioCount] = ms_aRadioBase[i];
|
||||
ms_aRadioLabel[ms_nRadioCount] = ms_aRadioShort[i];
|
||||
ms_apRadioName[ms_nRadioCount] = Wheel_RadioFullName(ms_aRadioBase[i]);
|
||||
ms_nRadioCount++;
|
||||
}
|
||||
|
||||
if (DMAudio.IsMP3RadioChannelAvailable() && ms_nRadioCount < WHEEL_MAX_RADIO) {
|
||||
ms_aRadioStation[ms_nRadioCount] = USERTRACK;
|
||||
ms_aRadioLabel[ms_nRadioCount] = ms_aRadioShort[9];
|
||||
ms_apRadioName[ms_nRadioCount] = Wheel_RadioFullName(USERTRACK);
|
||||
ms_nRadioCount++;
|
||||
}
|
||||
|
||||
#ifdef RADIO_OFF_TEXT
|
||||
// Same guard the vanilla radio-name HUD uses; without the GXT entry the
|
||||
// wheel simply has no "off" slot and picking a station turns the radio on.
|
||||
if (ms_nRadioCount < WHEEL_MAX_RADIO) {
|
||||
ms_aRadioStation[ms_nRadioCount] = RADIO_OFF;
|
||||
ms_aRadioLabel[ms_nRadioCount] = ms_aRadioShort[10];
|
||||
ms_apRadioName[ms_nRadioCount] = Wheel_RadioFullName(RADIO_OFF);
|
||||
ms_nRadioCount++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32
|
||||
@@ -424,6 +456,12 @@ Wheel_ApplyRadio(void)
|
||||
if (ms_nHovered < 0 || ms_nHovered >= ms_nRadioCount)
|
||||
return;
|
||||
|
||||
// Seeded hovered entry: releasing without cycling is a no-op.
|
||||
if (!ms_bSelectionMoved)
|
||||
return;
|
||||
if (ms_aRadioStation[ms_nHovered] == MusicManager.GetRadioInCar())
|
||||
return;
|
||||
|
||||
MusicManager.SetRadioInCar(ms_aRadioStation[ms_nHovered]);
|
||||
DMAudio.PlayFrontEndSound(SOUND_FRONTEND_RADIO_CHANGE, 100);
|
||||
}
|
||||
@@ -455,6 +493,15 @@ Wheel_AllowedToOpen(void)
|
||||
return false;
|
||||
if (CReplay::IsPlayingBack() || TheCamera.m_WideScreenOn || CGame::playingIntro)
|
||||
return false;
|
||||
// Rendering (and therefore CHud::Draw) is skipped during the fully faded
|
||||
// state and during scene edit; close the wheel rather than leaving its
|
||||
// PLAYERCONTROL_CAMERA bit set while it cannot be seen.
|
||||
if (TheCamera.GetScreenFadeStatus() == FADE_2)
|
||||
return false;
|
||||
#ifdef GTA_SCENE_EDIT
|
||||
if (CSceneEdit::m_bEditOn)
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -476,7 +523,9 @@ Wheel_RadioTriggerHeld(void)
|
||||
#ifdef IMPROVED_RADIO_WHEEL
|
||||
if (!Wheel_PlayerInRadioVehicle())
|
||||
return false;
|
||||
return pad->NewState.LeftShoulder2 != 0 || !!pad->GetChar('R');
|
||||
// R3 (RightShock) is only PED_LOOKBEHIND on foot; it has no in-car
|
||||
// binding, unlike L2/R2 (drive-by look), L3 (horn) and R1 (handbrake).
|
||||
return pad->NewState.RightShock != 0 || !!pad->GetChar('R');
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@@ -485,8 +534,9 @@ Wheel_RadioTriggerHeld(void)
|
||||
static void
|
||||
Wheel_ClearCameraDisable(void)
|
||||
{
|
||||
if (!ms_bCameraWasDisabled)
|
||||
if (ms_bOwnCameraBit && !ms_bCameraWasDisabled)
|
||||
CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_CAMERA);
|
||||
ms_bOwnCameraBit = false;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -496,7 +546,7 @@ Wheel_Open(bool radio)
|
||||
|
||||
ms_bOpen = true;
|
||||
ms_bRadio = radio;
|
||||
ms_nHovered = -1;
|
||||
ms_bSelectionMoved = false;
|
||||
ms_fCursorX = 0.0f;
|
||||
ms_fCursorY = 0.0f;
|
||||
|
||||
@@ -510,13 +560,36 @@ Wheel_Open(bool radio)
|
||||
ms_nCurrentSegment = player != nil ? Wheel_SegmentForWeapon(player->m_currentWeapon) : -1;
|
||||
}
|
||||
|
||||
CPad *pad = CPad::GetPad(0);
|
||||
ms_bCameraWasDisabled = (pad->DisablePlayerControls & PLAYERCONTROL_CAMERA) != 0;
|
||||
pad->SetDisablePlayerControls(PLAYERCONTROL_CAMERA);
|
||||
// Seed the selection so mouse wheel / D-pad cycling works immediately and
|
||||
// releasing without moving does not lose the current entry.
|
||||
if (ms_nCurrentSegment >= 0)
|
||||
ms_nHovered = ms_nCurrentSegment;
|
||||
else
|
||||
ms_nHovered = ms_nSegments > 0 ? 0 : -1;
|
||||
|
||||
// Remember the equipped weapon for its own segment so a seeded, untouched
|
||||
// weapon wheel (including grenade vs detonator) is a true no-op on release.
|
||||
if (!radio && player != nil && ms_nCurrentSegment >= 0)
|
||||
ms_aLastWeapon[ms_nCurrentSegment] = (int8)player->m_currentWeapon;
|
||||
|
||||
// PLAYERCONTROL_CAMERA is a global input gate. Only the on-foot weapon wheel
|
||||
// may take it: the radio wheel must leave throttle/brake/steering/handbrake
|
||||
// and drive-by aim alive while the car is moving.
|
||||
if (!radio) {
|
||||
CPad *pad = CPad::GetPad(0);
|
||||
ms_bCameraWasDisabled = (pad->DisablePlayerControls & PLAYERCONTROL_CAMERA) != 0;
|
||||
ms_bOwnCameraBit = true;
|
||||
pad->SetDisablePlayerControls(PLAYERCONTROL_CAMERA);
|
||||
} else {
|
||||
ms_bCameraWasDisabled = false;
|
||||
ms_bOwnCameraBit = false;
|
||||
}
|
||||
|
||||
#ifdef IMPROVED_WEAPON_WHEEL_SLOWMO
|
||||
ms_fSavedTimeScale = CTimer::GetTimeScale();
|
||||
CTimer::SetTimeScale(0.35f);
|
||||
if (!radio) {
|
||||
ms_fSavedTimeScale = CTimer::GetTimeScale();
|
||||
CTimer::SetTimeScale(0.35f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -533,7 +606,8 @@ Wheel_Close(bool apply)
|
||||
Wheel_ClearCameraDisable();
|
||||
|
||||
#ifdef IMPROVED_WEAPON_WHEEL_SLOWMO
|
||||
CTimer::SetTimeScale(ms_fSavedTimeScale);
|
||||
if (!ms_bRadio)
|
||||
CTimer::SetTimeScale(ms_fSavedTimeScale);
|
||||
#endif
|
||||
|
||||
ms_bOpen = false;
|
||||
@@ -581,9 +655,39 @@ Wheel_KeyDirection(float *x, float *y)
|
||||
return *x != 0.0f || *y != 0.0f;
|
||||
}
|
||||
|
||||
// Radio wheel: discrete cycling only. No right stick (it drives drive-by look
|
||||
// in a car) and no mouse-delta integration. Arrow keys are mapped to DPadLeft/
|
||||
// Right by ControllerConfig, so this covers pad D-pad and keyboard arrows.
|
||||
static void
|
||||
Wheel_UpdateRadioInput(void)
|
||||
{
|
||||
CPad *pad = CPad::GetPad(0);
|
||||
bool next = pad->GetMouseWheelDownJustDown()
|
||||
|| (pad->NewState.DPadRight && !pad->OldState.DPadRight);
|
||||
bool prev = pad->GetMouseWheelUpJustDown()
|
||||
|| (pad->NewState.DPadLeft && !pad->OldState.DPadLeft);
|
||||
|
||||
if (ms_nRadioCount <= 0 || ms_nHovered < 0)
|
||||
return;
|
||||
|
||||
if (next)
|
||||
ms_nHovered = (ms_nHovered + 1) % ms_nRadioCount;
|
||||
else if (prev)
|
||||
ms_nHovered = (ms_nHovered + ms_nRadioCount - 1) % ms_nRadioCount;
|
||||
else
|
||||
return;
|
||||
|
||||
ms_bSelectionMoved = true;
|
||||
}
|
||||
|
||||
static void
|
||||
Wheel_UpdateInput(void)
|
||||
{
|
||||
if (ms_bRadio) {
|
||||
Wheel_UpdateRadioInput();
|
||||
return;
|
||||
}
|
||||
|
||||
CPad *pad = CPad::GetPad(0);
|
||||
float bestX = 0.0f, bestY = 0.0f, bestMag = 0.0f;
|
||||
|
||||
@@ -639,16 +743,9 @@ Wheel_UpdateInput(void)
|
||||
bool prev = pad->GetMouseWheelUpJustDown()
|
||||
|| (pad->NewState.DPadLeft && !pad->OldState.DPadLeft);
|
||||
|
||||
if (ms_bRadio) {
|
||||
if (next && ms_nRadioCount > 0)
|
||||
ms_nHovered = (ms_nHovered + 1) % ms_nRadioCount;
|
||||
else if (prev && ms_nRadioCount > 0)
|
||||
ms_nHovered = (ms_nHovered + ms_nRadioCount - 1) % ms_nRadioCount;
|
||||
} else {
|
||||
CPlayerPed *player = FindPlayerPed();
|
||||
if (player != nil && (next || prev))
|
||||
Wheel_CycleSegment(player);
|
||||
}
|
||||
CPlayerPed *player = FindPlayerPed();
|
||||
if (player != nil && (next || prev))
|
||||
Wheel_CycleSegment(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,6 +759,10 @@ Wheel_Process(void)
|
||||
CPad *pad = CPad::GetPad(0);
|
||||
|
||||
if (!ms_bOpen) {
|
||||
// Only gate opening. While open the weapon wheel owns the camera bit,
|
||||
// so testing ArePlayerControlsDisabled() there would close it at once.
|
||||
if (pad->ArePlayerControlsDisabled() || CCutsceneMgr::IsRunning())
|
||||
return;
|
||||
if (!Wheel_AllowedToOpen())
|
||||
return;
|
||||
|
||||
@@ -673,9 +774,10 @@ Wheel_Process(void)
|
||||
return;
|
||||
}
|
||||
|
||||
// While open, keep the camera/fire controls suppressed even if another
|
||||
// system cleared the bit in between frames.
|
||||
if (!ms_bCameraWasDisabled)
|
||||
// Only the on-foot weapon wheel suppresses controls; the radio wheel keeps
|
||||
// driving alive. Re-assert the bit only if a weapon wheel owns it and
|
||||
// another system cleared it in between frames.
|
||||
if (!ms_bRadio && ms_bOwnCameraBit && !ms_bCameraWasDisabled)
|
||||
pad->SetDisablePlayerControls(PLAYERCONTROL_CAMERA);
|
||||
|
||||
if (!Wheel_AllowedToOpen()) {
|
||||
@@ -753,7 +855,7 @@ Wheel_DrawCentredText(float x, float y, wchar *text, float scaleX, float scaleY,
|
||||
}
|
||||
|
||||
static void
|
||||
Wheel_DrawSegmentLabel(int32 segment, const char *ascii, float radiusFactor, const CRGBA &color)
|
||||
Wheel_DrawSegmentText(int32 segment, wchar *text, float radiusFactor, const CRGBA &color)
|
||||
{
|
||||
if (ms_nSegments <= 0)
|
||||
return;
|
||||
@@ -763,12 +865,18 @@ Wheel_DrawSegmentLabel(int32 segment, const char *ascii, float radiusFactor, con
|
||||
float radius = SCREEN_HEIGHT * radiusFactor;
|
||||
float angle = HALFPI - segment * (TWOPI / ms_nSegments);
|
||||
|
||||
wchar text[32];
|
||||
AsciiToUnicode(ascii, text);
|
||||
Wheel_DrawCentredText(cx + radius * Cos(angle), cy - radius * Sin(angle),
|
||||
text, 0.30f, 0.50f, color);
|
||||
}
|
||||
|
||||
static void
|
||||
Wheel_DrawSegmentLabel(int32 segment, const char *ascii, float radiusFactor, const CRGBA &color)
|
||||
{
|
||||
wchar text[32];
|
||||
AsciiToUnicode(ascii, text);
|
||||
Wheel_DrawSegmentText(segment, text, radiusFactor, color);
|
||||
}
|
||||
|
||||
static void
|
||||
Wheel_DrawWeaponIcons(void)
|
||||
{
|
||||
@@ -814,7 +922,10 @@ Wheel_DrawRadio(void)
|
||||
|
||||
for (int32 i = 0; i < ms_nRadioCount; i++) {
|
||||
CRGBA color = i == ms_nHovered ? CRGBA(255, 240, 180, 255) : CRGBA(210, 210, 210, 220);
|
||||
Wheel_DrawSegmentLabel(i, ms_aRadioLabel[i], WHEEL_RADIO_TEXT_R, color);
|
||||
if (ms_apRadioName[i] != nil)
|
||||
Wheel_DrawSegmentText(i, ms_apRadioName[i], WHEEL_RADIO_TEXT_R, color);
|
||||
else
|
||||
Wheel_DrawSegmentLabel(i, ms_aRadioLabel[i], WHEEL_RADIO_TEXT_R, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,9 +969,8 @@ Wheel_Draw(void)
|
||||
if (ms_bRadio) {
|
||||
int32 shown = ms_nHovered >= 0 ? ms_nHovered : ms_nCurrentSegment;
|
||||
if (shown >= 0 && shown < ms_nRadioCount) {
|
||||
wchar *full = Wheel_RadioFullName(ms_aRadioStation[shown]);
|
||||
if (full != nil)
|
||||
Wheel_DrawCentredText(cx, cy - SCREEN_SCALE_Y(4.0f), full, 0.62f, 1.05f, CRGBA(255, 240, 180, 255));
|
||||
if (ms_apRadioName[shown] != nil)
|
||||
Wheel_DrawCentredText(cx, cy - SCREEN_SCALE_Y(4.0f), ms_apRadioName[shown], 0.62f, 1.05f, CRGBA(255, 240, 180, 255));
|
||||
else {
|
||||
AsciiToUnicode(ms_aRadioLabel[shown], text);
|
||||
Wheel_DrawCentredText(cx, cy - SCREEN_SCALE_Y(4.0f), text, 0.62f, 1.05f, CRGBA(255, 240, 180, 255));
|
||||
|
||||
Reference in New Issue
Block a user