fix: transparent wheel, remove backdrop, allow movement while open (issue #31)
linux / build (push) Canceled after 2m14s

This commit is contained in:
2026-12-02 15:26:54 +00:00
parent 3b14e45249
commit f9a0da0d17
2 changed files with 24 additions and 134 deletions
+2 -2
View File
@@ -1034,8 +1034,8 @@ void CGame::Process(void)
#ifdef IMPROVED_WEAPON_WHEEL
// Wheel state must advance even when CHud::Draw is skipped (frontend menu,
// FADE_2, scene edit, death), otherwise an open wheel could leave
// PLAYERCONTROL_CAMERA set. CGame::Process runs every game frame from Idle.
// FADE_2, scene edit, death), otherwise an open wheel could stay open while
// it cannot be seen. CGame::Process runs every game frame from Idle.
Wheel_Process();
#endif
+22 -132
View File
@@ -6,27 +6,24 @@
* sanctioned src/extras/ layer. Guard-off builds do not compile it.
*
* Interaction (both wheels share one state machine and one radial primitive):
* weapon wheel keyboard+mouse: hold Tab, point with the mouse (or WASD/arrows)
* weapon wheel keyboard+mouse: hold Tab, point with the mouse
* gamepad: hold R2, point with the right stick
* 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.
* The player keeps walking (WASD/arrows) while the wheel is
* held; the wheel consumes the mouse delta so the camera and
* the player's facing do not turn. This matches GTA V.
* 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.
* The radio wheel 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).
*
* 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.
* 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
@@ -72,9 +69,8 @@ enum
// See src/weapons/WeaponType.h for the eWeaponType ordering.
WHEEL_SEGMENTS = 12,
WHEEL_ARC_STEPS = 8, // quads per segment; smoother arcs, only for the procedural ring
WHEEL_FEATHER_STEPS = 4, // flat alpha steps for the radial/backdrop feather
WHEEL_FEATHER_STEPS = 4, // flat alpha steps for the radial feather
WHEEL_RING_ANGULAR_STEPS = 4, // flat colour steps across one spoke gap
WHEEL_BACKDROP_SEGMENTS = 48,
WHEEL_MAX_RADIO = 12
};
@@ -96,7 +92,6 @@ enum
#define WHEEL_ART_CENTRE_Y ( 30.67f / 1080.0f)
#define WHEEL_STICK_DEADZONE 0.35f
#define WHEEL_KEY_DEADZONE 0.50f
// Weapon wheel: absolute virtual cursor, 1:1 with the raw mouse delta. The
// engine disables the OS cursor during gameplay (GLFW_CURSOR_DISABLED), so there
// is no usable absolute window position; the cursor starts at screen centre and
@@ -107,8 +102,6 @@ enum
#define WHEEL_CURSOR_THICK 0.0018f // marker thickness, fraction of screen height
#define WHEEL_RING_FEATHER 0.006f // stepped alpha-feather band on the ring edges
#define WHEEL_RING_ANGULAR_FEATHER 0.10f // angular edge fade, fraction of one sector's angle
#define WHEEL_BACKDROP_MARGIN 0.012f // dark annulus spans this far inside the inner radius and past the outer radius
#define WHEEL_BACKDROP_FEATHER 0.016f // soft edges of the dark annulus
#define WHEEL_ART_WW_PATH "weapon_wheel/ww%d.png"
#define WHEEL_ART_ICON_PATH "weapon_wheel/icon%d.png"
@@ -142,8 +135,6 @@ 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; // absolute virtual mouse cursor (screen px)
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
@@ -602,14 +593,6 @@ Wheel_RadioTriggerHeld(void)
#endif
}
static void
Wheel_ClearCameraDisable(void)
{
if (ms_bOwnCameraBit && !ms_bCameraWasDisabled)
CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_CAMERA);
ms_bOwnCameraBit = false;
}
static void
Wheel_Open(bool radio)
{
@@ -645,19 +628,6 @@ Wheel_Open(bool radio)
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
if (!radio) {
ms_fSavedTimeScale = CTimer::GetTimeScale();
@@ -676,8 +646,6 @@ Wheel_Close(bool apply)
Wheel_ApplyWeapon();
}
Wheel_ClearCameraDisable();
#ifdef IMPROVED_WEAPON_WHEEL_SLOWMO
if (!ms_bRadio)
CTimer::SetTimeScale(ms_fSavedTimeScale);
@@ -714,20 +682,6 @@ Wheel_SegmentFromVector(float x, float y)
return segment;
}
static bool
Wheel_KeyDirection(float *x, float *y)
{
CPad *pad = CPad::GetPad(0);
bool left = pad->GetLeft() || !!pad->GetChar('A');
bool right = pad->GetRight() || !!pad->GetChar('D');
bool up = pad->GetUp() || !!pad->GetChar('W');
bool down = pad->GetDown() || !!pad->GetChar('S');
*x = (right ? 1.0f : 0.0f) - (left ? 1.0f : 0.0f);
*y = (down ? 1.0f : 0.0f) - (up ? 1.0f : 0.0f);
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.
@@ -804,26 +758,10 @@ Wheel_UpdateInput(void)
float cursorDY = ms_fCursorY - SCREEN_HEIGHT * 0.5f; // screen y is down; helper flips it
float cursorDist = Sqrt(cursorDX * cursorDX + cursorDY * cursorDY);
// Keyboard direction (arrows or WASD), normalised so it competes with the
// analogue sources fairly.
float keyX, keyY;
if (Wheel_KeyDirection(&keyX, &keyY)) {
mag = Sqrt(keyX * keyX + keyY * keyY);
if (mag > 0.0f) {
keyX /= mag;
keyY /= mag;
}
if (mag >= WHEEL_KEY_DEADZONE || bestMag == 0.0f) {
bestX = keyX;
bestY = keyY;
bestMag = 1.0f;
}
}
// The mouse is authoritative once the crosshair leaves the deadzone: the
// maintainer's round-3 report was exactly "crosshair moves but selection
// never changes", caused by updating the cursor without ever assigning
// ms_nHovered from it. Stick/keyboard still drive selection while the
// ms_nHovered from it. The stick still drives selection while the
// crosshair is parked at the centre.
if (cursorDist > WHEEL_CURSOR_DEADZONE * SCREEN_HEIGHT)
ms_nHovered = Wheel_SegmentFromVector(cursorDX, cursorDY);
@@ -846,11 +784,11 @@ Wheel_UpdateInput(void)
// Process / draw
// ---------------------------------------------------------------------------
// The look/freecam code reads CPad::NewMouseControllerState.x/y directly and is
// NOT gated by PLAYERCONTROL_CAMERA, so the weapon wheel must consume the delta
// after using it. Wheel_Process runs from CGame::Process before CWorld::Process
// and TheCamera.Process, and after CPad::UpdatePads committed the delta; the
// debug menu uses the same zeroing trick. Buttons are untouched.
// The look/freecam code reads CPad::NewMouseControllerState.x/y directly, so
// the weapon wheel must consume the delta after using it. Wheel_Process runs
// from CGame::Process before CWorld::Process and TheCamera.Process, and after
// CPad::UpdatePads committed the delta; the debug menu uses the same zeroing
// trick. Buttons are untouched, so movement keys keep working.
static void
Wheel_ConsumeMouse(void)
{
@@ -865,8 +803,8 @@ 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.
// Only gate opening: while open the wheel deliberately leaves the
// player in control, so the controls-disabled flag is checked here.
if (pad->ArePlayerControlsDisabled() || CCutsceneMgr::IsRunning())
return;
if (!Wheel_AllowedToOpen())
@@ -882,12 +820,6 @@ Wheel_Process(void)
return;
}
// 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()) {
bool consumeMouse = !ms_bRadio;
Wheel_Close(false);
@@ -909,8 +841,8 @@ Wheel_Process(void)
Wheel_UpdateInput();
// The radio wheel is non-freezing and does not own the mouse; only the
// on-foot weapon wheel consumes the delta.
// The radio wheel does not own the mouse; only the on-foot weapon wheel
// consumes the delta.
if (!ms_bRadio)
Wheel_ConsumeMouse();
}
@@ -1016,7 +948,7 @@ Wheel_DrawRing(void)
else if (i == highlight)
color[i] = CRGBA(235, 200, 120, 225);
else
color[i] = CRGBA(18, 18, 18, 150);
color[i] = CRGBA(18, 18, 18, 128);
}
// Pass 2: solid sectors with their stepped radial feather. Sides with a
@@ -1071,47 +1003,6 @@ Wheel_DrawRing(void)
}
}
// A dark annulus behind the ring: it hides the bright game scene under the
// semi-transparent sectors and their feathers while leaving the centre hole
// open so the player remains visible. Both edges are stepped flat-alpha
// strips (plain Draw2DPolygon), matching the ring's AA style.
static void
Wheel_DrawBackdrop(void)
{
float inner = SCREEN_HEIGHT * WHEEL_INNER_RADIUS;
float outer = SCREEN_HEIGHT * WHEEL_OUTER_RADIUS;
float margin = SCREEN_HEIGHT * WHEEL_BACKDROP_MARGIN;
float fade = SCREEN_HEIGHT * WHEEL_BACKDROP_FEATHER;
float annInner = inner - margin;
float annOuter = outer + margin;
CRGBA color(8, 8, 8, 235);
int32 steps = WHEEL_FEATHER_STEPS;
for (int32 i = 0; i < WHEEL_BACKDROP_SEGMENTS; i++) {
float a0 = TWOPI * i / WHEEL_BACKDROP_SEGMENTS;
float a1 = TWOPI * (i + 1) / WHEEL_BACKDROP_SEGMENTS;
Wheel_DrawRingQuad(a0, a1, annInner, annOuter, color);
for (int32 k = 0; k < steps; k++) {
float t0 = (float)k / steps;
float t1 = (float)(k + 1) / steps;
uint8 aIn = Wheel_StepAlpha(color.a, k, steps);
if (aIn != 0)
Wheel_DrawRingQuad(a0, a1, annInner - fade + fade * t0,
annInner - fade + fade * t1,
CRGBA(color.r, color.g, color.b, aIn));
uint8 aOut = Wheel_StepAlpha(color.a, steps - 1 - k, steps);
if (aOut != 0)
Wheel_DrawRingQuad(a0, a1, annOuter + fade * t0,
annOuter + fade * t1,
CRGBA(color.r, color.g, color.b, aOut));
}
}
}
static void
Wheel_DrawCentredText(float x, float y, wchar *text, float scaleX, float scaleY, const CRGBA &color)
{
@@ -1255,9 +1146,8 @@ Wheel_Draw(void)
// top of the HUD instead of under the queued text.
CFont::DrawFonts();
// Dim the game/HUD underneath, then the dark hub and the shared ring.
// Dim the game/HUD underneath, then the shared translucent ring.
CSprite2d::DrawRect(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(0, 0, 0, 140));
Wheel_DrawBackdrop();
Wheel_DrawRing();
// Draw2DPolygon restores depth states to ON; the 2D pass wants them off.