A13: Gamepad and accessibility
Gamepad: PadInput reads pad events in one fixed layout (sticks move and look, triggers aim and fire, bumpers step slots and build pieces, Start pauses), fed through ClientInput alongside the keys and mouse. Menus take South to choose and East or Start to go back. The tutorial names pad buttons once the pad is used. Aim assist (option, on by default, pad only): friction across an opponent in plain sight near the look, and a pull of at most 9 deg/s while aiming. Client look only; never through cover. Accessibility (new Access tab): colour-vision sets for the signal colours (red-green, blue-yellow), checked by simulated colour vision in test_palette; interface size 90-130%, with the HUD hotbar refitting at the larger sizes; captions for key sounds with direction; reduce motion (calmer aim zoom and hurt flash). Tests for the pad, aim assist, captions, palettes, settings, the menus driven from a pad, and a pad playing through a real offline session. make access-captures renders the new screens and options. Closes #53 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
## Aim assist for the gamepad (A13), an option, on by default, and never applied to the
|
||||
## mouse. Two gentle effects, both only for an opponent in plain sight close to where
|
||||
## the player is already looking:
|
||||
##
|
||||
## - Friction: the right stick turns more slowly across an opponent, so a stick can
|
||||
## settle on them instead of sliding past.
|
||||
## - Pull: while aiming down sights and moving (the stick or the player), the look
|
||||
## eases towards the opponent's chest, by no more than PULL_RADIANS_PER_SECOND.
|
||||
##
|
||||
## It only turns the client's look, the same as a player's own thumb, so it changes
|
||||
## nothing the server judges. It never aims through cover: `clear` decides what is
|
||||
## in sight, and the session passes the world's own line test.
|
||||
class_name AimAssist
|
||||
extends RefCounted
|
||||
|
||||
## How far either side of the look an opponent can be and still count.
|
||||
const CONE_RADIANS: float = deg_to_rad(6.0)
|
||||
## Further than this, nobody counts.
|
||||
const RANGE_METRES: float = 90.0
|
||||
## Look speed at the very centre of an opponent, against 1 away from them.
|
||||
const FRICTION: float = 0.45
|
||||
## The fastest the pull turns the look.
|
||||
const PULL_RADIANS_PER_SECOND: float = deg_to_rad(9.0)
|
||||
|
||||
|
||||
## The opponent nearest the look within the cone: {"point", "angle"}, or {} for none.
|
||||
## `clear` takes (eye, point) and returns true when nothing is between them.
|
||||
static func nearest(eye: Vector3, yaw: float, pitch: float, targets: Array[Vector3], clear: Callable = Callable()) -> Dictionary:
|
||||
var look: Vector3 = CameraRig.look_direction(yaw, pitch)
|
||||
var best: Dictionary = {}
|
||||
var best_angle: float = CONE_RADIANS
|
||||
for point: Vector3 in targets:
|
||||
var to: Vector3 = point - eye
|
||||
var distance: float = to.length()
|
||||
if distance < 0.5 or distance > RANGE_METRES:
|
||||
continue
|
||||
var angle: float = look.angle_to(to / distance)
|
||||
if angle >= best_angle:
|
||||
continue
|
||||
if clear.is_valid() and not bool(clear.call(eye, point)):
|
||||
continue
|
||||
best_angle = angle
|
||||
best = {"point": point, "angle": angle}
|
||||
return best
|
||||
|
||||
|
||||
## How much the stick's turn is slowed: 1 with nobody near the look, down to FRICTION
|
||||
## at an opponent's centre.
|
||||
static func friction(found: Dictionary) -> float:
|
||||
if found.is_empty():
|
||||
return 1.0
|
||||
return lerpf(FRICTION, 1.0, clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0))
|
||||
|
||||
|
||||
## The look after `delta` seconds of pull towards `found`: Vector2(yaw, pitch). Pulls
|
||||
## harder the closer the look already is, and never past the opponent.
|
||||
static func pull(eye: Vector3, yaw: float, pitch: float, found: Dictionary, delta: float) -> Vector2:
|
||||
if found.is_empty():
|
||||
return Vector2(yaw, pitch)
|
||||
var to: Vector3 = Vector3(found["point"]) - eye
|
||||
var want_yaw: float = atan2(to.x, to.z)
|
||||
var want_pitch: float = atan2(to.y, Vector2(to.x, to.z).length())
|
||||
var turn: Vector2 = Vector2(angle_difference(yaw, want_yaw), want_pitch - pitch)
|
||||
var closeness: float = 1.0 - clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0)
|
||||
var step: float = PULL_RADIANS_PER_SECOND * closeness * delta
|
||||
if turn.length() > step:
|
||||
turn = turn.normalized() * step
|
||||
return Vector2(fposmod(yaw + turn.x, TAU), clampf(pitch + turn.y, -InputSettings.PITCH_LIMIT, InputSettings.PITCH_LIMIT))
|
||||
@@ -0,0 +1 @@
|
||||
uid://u6jrr2nuxaod
|
||||
@@ -1,10 +1,12 @@
|
||||
## The placement preview: a translucent copy of the piece where fire would put it, sea
|
||||
## green when the server would accept it and rust red when it wouldn't. It asks the same
|
||||
## The placement preview: a translucent copy of the piece where fire would put it, in the
|
||||
## colour-vision set's allowed colour (sea green as standard) when the server would
|
||||
## accept it and its refused colour (rust red) when it wouldn't. It asks the same
|
||||
## Building.target() and Building.check() the server runs, so the ghost and the server
|
||||
## agree on the client's predicted state.
|
||||
class_name BuildGhost
|
||||
extends Node3D
|
||||
|
||||
## The standard set's colours; Palette.vision can change what is shown.
|
||||
const VALID_COLOUR: Color = Palette.GHOST_OK
|
||||
const INVALID_COLOUR: Color = Palette.GHOST_REFUSED
|
||||
|
||||
@@ -44,7 +46,7 @@ func update(sim: Simulation, player: SimEntity, kind: int, material: int) -> voi
|
||||
if key != _shown_key:
|
||||
_shown_key = key
|
||||
_mesh.mesh = PieceMesher.box_mesh(Building.boxes_for_target(target, sim.ground), Color.WHITE)
|
||||
_surface.albedo_color = VALID_COLOUR if valid else INVALID_COLOUR
|
||||
_surface.albedo_color = Palette.ghost_ok() if valid else Palette.ghost_refused()
|
||||
|
||||
|
||||
func colour() -> Color:
|
||||
|
||||
@@ -21,15 +21,20 @@ const CLEARANCE: float = 0.1
|
||||
const CLEAR_STEPS: int = 16
|
||||
## Seconds to move most of the way between hip and aim.
|
||||
const AIM_BLEND_SECONDS: float = 0.12
|
||||
## With reduce motion on (A13): a smaller zoom, eased in over longer. Tidewall has no
|
||||
## camera shake, so the aim zoom is the largest camera motion the player doesn't make.
|
||||
const CALM_AIM_FOV: float = 62.0
|
||||
const CALM_AIM_BLEND_SECONDS: float = 0.3
|
||||
|
||||
## 0 at the hip, 1 fully aimed. Advanced by `update_aim`.
|
||||
var aim_blend: float = 0.0
|
||||
var reduce_motion: bool = false
|
||||
|
||||
|
||||
## Eases aim_blend towards aiming or not over `delta` seconds.
|
||||
func update_aim(aiming: bool, delta: float) -> void:
|
||||
var target: float = 1.0 if aiming else 0.0
|
||||
var rate: float = 1.0 - exp(-delta * 3.0 / AIM_BLEND_SECONDS)
|
||||
var rate: float = 1.0 - exp(-delta * 3.0 / (CALM_AIM_BLEND_SECONDS if reduce_motion else AIM_BLEND_SECONDS))
|
||||
aim_blend = lerpf(aim_blend, target, rate)
|
||||
if absf(aim_blend - target) < 0.001:
|
||||
aim_blend = target
|
||||
@@ -66,7 +71,7 @@ func solve(feet: Vector3, yaw: float, pitch: float, crouching: bool, ground: Sim
|
||||
|
||||
|
||||
func fov() -> float:
|
||||
return lerpf(FOV, AIM_FOV, aim_blend)
|
||||
return lerpf(FOV, CALM_AIM_FOV if reduce_motion else AIM_FOV, aim_blend)
|
||||
|
||||
|
||||
## Moves from `from` towards `to`, stopping MARGIN short of the first surface.
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
## 1 the boathook, 2 to 6 the five slots · B build mode on and off ·
|
||||
## in build mode 1 to 5 pick wall, floor, ramp, roof or breakwater, Tab the material,
|
||||
## and left mouse places · M the chart.
|
||||
## Gamepads come with A13.
|
||||
## A gamepad works alongside them, in PadInput's fixed layout (A13), with AimAssist
|
||||
## on its right stick when the setting is on.
|
||||
##
|
||||
## With `autoplay` on, a simple script plays instead: it leaps from the barge over
|
||||
## land, glides, and walks about. That is for tests and for checking a connection with
|
||||
@@ -31,6 +32,15 @@ var map_open: bool = false
|
||||
var build_kind: int = StructureSet.WALL
|
||||
var material: int = Materials.DRIFTWOOD
|
||||
var autoplay: bool = false
|
||||
## The gamepad's state, fed by handle().
|
||||
var pad: PadInput = PadInput.new()
|
||||
## For aim assist: where the camera is, and the chests of opponents in the world.
|
||||
## The session fills these each frame; `clear` is its line-of-sight test.
|
||||
var eye: Vector3 = Vector3.ZERO
|
||||
var targets: Array[Vector3] = []
|
||||
var clear: Callable = Callable()
|
||||
## Sprint latched by clicking the left stick, until the stick is let go.
|
||||
var _pad_sprint: bool = false
|
||||
|
||||
## Actions held down, and the command buttons they hold.
|
||||
const HELD: Dictionary = {
|
||||
@@ -45,18 +55,43 @@ func aiming() -> bool:
|
||||
return buttons & PlayerCommand.BUTTON_AIM != 0 and not build_mode
|
||||
|
||||
|
||||
## Reads what is held down from the keyboard and mouse. Call once a frame.
|
||||
func poll() -> void:
|
||||
## Reads what is held down from the keyboard, the mouse and the gamepad, and turns
|
||||
## the look by the right stick over `delta` seconds. Call once a frame.
|
||||
func poll(delta: float = 0.0) -> void:
|
||||
if autoplay:
|
||||
return
|
||||
move = Vector2(
|
||||
_axis("right", "left"),
|
||||
_axis("forward", "back"),
|
||||
)
|
||||
var stick: Vector2 = pad.move()
|
||||
if stick != Vector2.ZERO:
|
||||
move = (move + stick).limit_length(1.0)
|
||||
elif _pad_sprint and move == Vector2.ZERO:
|
||||
_pad_sprint = false
|
||||
buttons = 0
|
||||
for action: String in HELD:
|
||||
if bindings.is_held(action):
|
||||
if bindings.is_held(action) or pad.is_held(action):
|
||||
buttons |= int(HELD[action])
|
||||
if _pad_sprint:
|
||||
buttons |= PlayerCommand.BUTTON_SPRINT
|
||||
_pad_look(delta)
|
||||
|
||||
|
||||
## Turns the look by the right stick, with aim assist when it's on.
|
||||
func _pad_look(delta: float) -> void:
|
||||
var stick: Vector2 = pad.look()
|
||||
var found: Dictionary = {}
|
||||
if settings.aim_assist and pad.active and not targets.is_empty():
|
||||
found = AimAssist.nearest(eye, yaw, pitch, targets, clear)
|
||||
if stick != Vector2.ZERO:
|
||||
var look: Vector2 = settings.apply_stick(stick, yaw, pitch, aiming(), delta, AimAssist.friction(found))
|
||||
yaw = look.x
|
||||
pitch = look.y
|
||||
if not found.is_empty() and aiming() and (stick != Vector2.ZERO or move != Vector2.ZERO):
|
||||
var pulled: Vector2 = AimAssist.pull(eye, yaw, pitch, found, delta)
|
||||
yaw = pulled.x
|
||||
pitch = pulled.y
|
||||
|
||||
|
||||
## Takes one input event: mouse motion turns the look, and keys that act once per
|
||||
@@ -64,6 +99,10 @@ func poll() -> void:
|
||||
func handle(event: InputEvent, captured: bool) -> void:
|
||||
if autoplay:
|
||||
return
|
||||
if pad.feed(event):
|
||||
for action: String in pad.take_presses():
|
||||
act(action)
|
||||
return
|
||||
var motion: InputEventMouseMotion = event as InputEventMouseMotion
|
||||
if motion != null and captured:
|
||||
turn(motion.relative)
|
||||
@@ -95,6 +134,16 @@ func act(action: String) -> void:
|
||||
map_open = not map_open
|
||||
elif action == "material" and build_mode:
|
||||
material = (material + 1) % Materials.NAMES.size()
|
||||
elif action == "material_back" and build_mode:
|
||||
material = posmod(material - 1, Materials.NAMES.size())
|
||||
elif action == "slot_next" or action == "slot_back":
|
||||
var step: int = 1 if action == "slot_next" else -1
|
||||
if build_mode:
|
||||
build_kind = posmod(build_kind + step, StructureSet.KINDS.size())
|
||||
else:
|
||||
slot = posmod(slot + step, Inventory.slot_count() + 1)
|
||||
elif action == "sprint":
|
||||
_pad_sprint = true
|
||||
elif action.begins_with("slot_"):
|
||||
var number: int = action.substr(5).to_int()
|
||||
if build_mode:
|
||||
|
||||
@@ -31,6 +31,8 @@ const WINDOW_MODES: Array[String] = ["Windowed", "Fullscreen", "Exclusive fullsc
|
||||
## Frame caps offered, 0 for none.
|
||||
const FRAME_CAPS: Array[int] = [0, 30, 60, 90, 120, 144, 165, 240]
|
||||
const MAX_NAME_LENGTH: int = 24
|
||||
## Interface scales offered (A13): menus and HUD drawn this much larger.
|
||||
const UI_SCALES: Array[float] = [0.9, 1.0, 1.15, 1.3]
|
||||
|
||||
var bindings: KeyBindings = KeyBindings.new()
|
||||
var mouse: InputSettings = InputSettings.new()
|
||||
@@ -78,6 +80,22 @@ var practice_team_size: int = 1:
|
||||
## The tutorial (A12): offered on the first launch until answered, and finished once.
|
||||
var tutorial_offered: bool = false
|
||||
var tutorial_done: bool = false
|
||||
## Accessibility (A13). Colour vision: an index into Palette.VISION_NAMES.
|
||||
var vision: int = Palette.VISION_STANDARD:
|
||||
set(value):
|
||||
vision = clampi(value, 0, Palette.VISION_NAMES.size() - 1)
|
||||
## How large the menus and HUD are drawn: one of UI_SCALES.
|
||||
var ui_scale: float = 1.0:
|
||||
set(value):
|
||||
ui_scale = 1.0
|
||||
for offered: float in UI_SCALES:
|
||||
if absf(offered - value) < 0.001:
|
||||
ui_scale = offered
|
||||
## Captions for the sounds that matter in play (Captions).
|
||||
var captions: bool = false
|
||||
## Less motion and flashing: a smaller zoom when aiming, eased in more slowly, and a
|
||||
## gentler flash when hurt.
|
||||
var reduce_motion: bool = false
|
||||
|
||||
|
||||
func shadow_distance() -> float:
|
||||
@@ -109,9 +127,7 @@ func apply_to_viewport(viewport: Viewport) -> void:
|
||||
func save(path: String = DEFAULT_PATH) -> Error:
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
# The mouse keeps its own section, as InputSettings has always saved it.
|
||||
config.set_value(InputSettings.SECTION, "mouse_sensitivity", mouse.mouse_sensitivity)
|
||||
config.set_value(InputSettings.SECTION, "aim_sensitivity_scale", mouse.aim_sensitivity_scale)
|
||||
config.set_value(InputSettings.SECTION, "invert_y", mouse.invert_y)
|
||||
mouse.write(config)
|
||||
bindings.write(config)
|
||||
config.set_value("graphics", "quality", quality)
|
||||
config.set_value("graphics", "print_pass", print_pass)
|
||||
@@ -128,6 +144,10 @@ func save(path: String = DEFAULT_PATH) -> Error:
|
||||
config.set_value("practice", "team_size", practice_team_size)
|
||||
config.set_value("tutorial", "offered", tutorial_offered)
|
||||
config.set_value("tutorial", "done", tutorial_done)
|
||||
config.set_value("access", "vision", vision)
|
||||
config.set_value("access", "ui_scale", ui_scale)
|
||||
config.set_value("access", "captions", captions)
|
||||
config.set_value("access", "reduce_motion", reduce_motion)
|
||||
return config.save(path)
|
||||
|
||||
|
||||
@@ -157,6 +177,10 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
|
||||
settings.practice_team_size = _int(config, "practice", "team_size", settings.practice_team_size)
|
||||
settings.tutorial_offered = _bool(config, "tutorial", "offered", settings.tutorial_offered)
|
||||
settings.tutorial_done = _bool(config, "tutorial", "done", settings.tutorial_done)
|
||||
settings.vision = _int(config, "access", "vision", settings.vision)
|
||||
settings.ui_scale = _float(config, "access", "ui_scale", settings.ui_scale)
|
||||
settings.captions = _bool(config, "access", "captions", settings.captions)
|
||||
settings.reduce_motion = _bool(config, "access", "reduce_motion", settings.reduce_motion)
|
||||
return settings
|
||||
|
||||
|
||||
@@ -165,6 +189,9 @@ static func load_from(path: String = DEFAULT_PATH) -> GameSettings:
|
||||
## when there is none.
|
||||
func apply_to_program(tree: SceneTree) -> void:
|
||||
_apply_audio()
|
||||
Palette.vision = vision
|
||||
if tree != null:
|
||||
tree.root.content_scale_factor = ui_scale
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return
|
||||
Engine.max_fps = max_fps
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
## Captions for the sounds that matter in play (A13), for players who can't hear them
|
||||
## or play with the sound down: what was heard and, for placed sounds, which way it
|
||||
## came from against where the camera looks. It reads the cues SoundDirector decided
|
||||
## each frame, so a caption is shown exactly when its sound is played.
|
||||
##
|
||||
## Repeats of a caption refresh it rather than stacking ("Footsteps, behind" stays one
|
||||
## line while they go on), the newest line is last, and lines fade after SECONDS.
|
||||
## Sounds the player makes themselves (their own steps, shots and pieces) aren't
|
||||
## captioned: they know.
|
||||
class_name Captions
|
||||
extends RefCounted
|
||||
|
||||
const SECONDS: float = 3.0
|
||||
const MAX_LINES: int = 4
|
||||
## Placed sounds closer than this to the player are their own.
|
||||
const OWN_METRES: float = 2.5
|
||||
## Footsteps further than this aren't worth a line.
|
||||
const STEP_METRES: float = 20.0
|
||||
|
||||
## Each sound's words. Footsteps, shots and pieces go by prefix (see words_for()).
|
||||
const WORDS: Dictionary = {
|
||||
"foghorn": "Foghorn: the sea is rising",
|
||||
"bell": "Ship's bell",
|
||||
"surge": "A surge breaks",
|
||||
"lighthouse": "Lighthouse tone: high water, last land",
|
||||
"hurt": "You're hit",
|
||||
"eliminated": "Someone is out",
|
||||
"keg_blast": "Powder keg blast",
|
||||
"hit_player": "Shot strikes someone",
|
||||
"splash": "Splash",
|
||||
"swim": "Swimming",
|
||||
"swing_boathook": "Boathook swing",
|
||||
"chest_open": "Chest opened",
|
||||
}
|
||||
|
||||
## Live lines: words -> {"words", "side", "left" (seconds)}, newest last.
|
||||
var _lines: Array[Dictionary] = []
|
||||
|
||||
|
||||
## The words for a sound, or "" for one that isn't captioned.
|
||||
static func words_for(sound: String) -> String:
|
||||
if sound.begins_with("step_"):
|
||||
return "Footsteps"
|
||||
if sound.begins_with("shot_"):
|
||||
return "Gunfire"
|
||||
if sound.begins_with("break_"):
|
||||
return "A piece breaks"
|
||||
if sound.begins_with("build_"):
|
||||
return "Building"
|
||||
return String(WORDS.get(sound, ""))
|
||||
|
||||
|
||||
## Which way `at` is from a listener at `eye` looking along `yaw` (simulation
|
||||
## convention): "ahead", "right", "behind" or "left".
|
||||
static func side_of(eye: Vector3, yaw: float, at: Vector3) -> String:
|
||||
var to: Vector2 = Vector2(at.x - eye.x, at.z - eye.z)
|
||||
if to.length() < 0.01:
|
||||
return ""
|
||||
var turn: float = angle_difference(yaw, atan2(to.x, to.y))
|
||||
# Positive turn is to the left: yaw grows anticlockwise seen from above.
|
||||
if absf(turn) <= PI / 4.0:
|
||||
return "ahead"
|
||||
if absf(turn) >= PI * 3.0 / 4.0:
|
||||
return "behind"
|
||||
return "left" if turn > 0.0 else "right"
|
||||
|
||||
|
||||
## Takes a frame's cues. `eye` and `yaw` are the camera's; `own` is where the player
|
||||
## is, or Vector3.INF with no player.
|
||||
func hear(cues: Array[Dictionary], eye: Vector3, yaw: float, own: Vector3, delta: float) -> void:
|
||||
for line: Dictionary in _lines:
|
||||
line["left"] = float(line["left"]) - delta
|
||||
_lines = _lines.filter(func(line: Dictionary) -> bool: return float(line["left"]) > 0.0)
|
||||
for cue: Dictionary in cues:
|
||||
var words: String = words_for(String(cue["sound"]))
|
||||
if words.is_empty():
|
||||
continue
|
||||
var side: String = ""
|
||||
if bool(cue["spatial"]):
|
||||
var at: Vector3 = cue["at"]
|
||||
if own != Vector3.INF and at.distance_to(own) < OWN_METRES:
|
||||
continue
|
||||
if words == "Footsteps" and own != Vector3.INF and at.distance_to(own) > STEP_METRES:
|
||||
continue
|
||||
side = side_of(eye, yaw, at)
|
||||
_show(words, side)
|
||||
|
||||
|
||||
func _show(words: String, side: String) -> void:
|
||||
var text: String = words if side.is_empty() else "%s, %s" % [words, side]
|
||||
for index: int in _lines.size():
|
||||
if _lines[index]["text"] == text:
|
||||
_lines.remove_at(index)
|
||||
break
|
||||
_lines.append({"text": text, "left": SECONDS})
|
||||
while _lines.size() > MAX_LINES:
|
||||
_lines.remove_at(0)
|
||||
|
||||
|
||||
## The lines to show now, oldest first.
|
||||
func lines() -> Array[String]:
|
||||
var shown: Array[String] = []
|
||||
for line: Dictionary in _lines:
|
||||
shown.append(String(line["text"]))
|
||||
return shown
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
_lines.clear()
|
||||
@@ -0,0 +1 @@
|
||||
uid://cx1cgtph7dshj
|
||||
@@ -174,8 +174,8 @@ func _draw_overlay() -> void:
|
||||
var coming: PackedByteArray = coming_flood(world)
|
||||
var per_cell: int = maxi(roundi(PIXELS / float(flood.side)), 1)
|
||||
var taken: Color = Color(Palette.SEA_INK.lightened(0.3), 0.7)
|
||||
var hatch: Color = Color(Palette.WARNING, 0.95)
|
||||
var wash: Color = Color(Palette.WARNING, 0.16)
|
||||
var hatch: Color = Color(Palette.warning(), 0.95)
|
||||
var wash: Color = Color(Palette.warning(), 0.16)
|
||||
for cz: int in flood.side:
|
||||
for cx: int in flood.side:
|
||||
var index: int = cz * flood.side + cx
|
||||
@@ -241,7 +241,7 @@ func _draw() -> void:
|
||||
var ahead: Vector2 = Vector2(sin(facing), cos(facing))
|
||||
var side: Vector2 = Vector2(ahead.y, -ahead.x)
|
||||
var arrow: PackedVector2Array = PackedVector2Array([at + ahead * 11.0, at - ahead * 7.0 + side * 7.0, at - ahead * 3.0, at - ahead * 7.0 - side * 7.0])
|
||||
draw_colored_polygon(arrow, Palette.OILSKIN)
|
||||
draw_colored_polygon(arrow, Palette.own())
|
||||
arrow.append(arrow[0])
|
||||
draw_polyline(arrow, Palette.INK, 2.0)
|
||||
# North, and the frame's ink edge.
|
||||
|
||||
+72
-13
@@ -30,6 +30,8 @@ var _build: Label
|
||||
var _down: Label
|
||||
var _reticle: Reticle
|
||||
var _hurt: HurtEdge
|
||||
## Captions for key sounds (A13), above the materials, newest at the bottom.
|
||||
var _captions: VBoxContainer
|
||||
## When a feed line was first shown (msec), so lines fade after HudState.FEED_SECONDS.
|
||||
var _feed_seen: Dictionary = {}
|
||||
## Captures turn this off to keep every line of the feed.
|
||||
@@ -81,11 +83,13 @@ func _init() -> void:
|
||||
add_child(_vitals)
|
||||
|
||||
_hotbar = HBoxContainer.new()
|
||||
_hotbar.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
|
||||
# Placed by _fit_bottom(): centred, unless a larger interface size (A13) leaves no
|
||||
# room, when it moves clear of the vitals and its slots narrow.
|
||||
_hotbar.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
|
||||
_hotbar.add_theme_constant_override("separation", 6)
|
||||
_hotbar.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
_hotbar.size = Vector2(6.0 * 86.0 + 5.0 * 6.0, 112.0)
|
||||
_hotbar.position = Vector2(-_hotbar.size.x * 0.5, -112.0 - MARGIN)
|
||||
_hotbar.position = Vector2(640.0 - _hotbar.size.x * 0.5, -112.0 - MARGIN)
|
||||
add_child(_hotbar)
|
||||
|
||||
_build = _label(FONT_BODY, Palette.PAPER)
|
||||
@@ -94,7 +98,7 @@ func _init() -> void:
|
||||
_build.size = Vector2(520.0, 24.0)
|
||||
_build.position = Vector2(-260.0, -112.0 - MARGIN - 30.0)
|
||||
add_child(_build)
|
||||
_down = _label(FONT_BODY, Palette.WARNING)
|
||||
_down = _label(FONT_BODY, Palette.warning())
|
||||
_down.set_anchors_preset(Control.PRESET_CENTER_BOTTOM)
|
||||
_down.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_down.size = Vector2(720.0, 24.0)
|
||||
@@ -109,9 +113,23 @@ func _init() -> void:
|
||||
_materials.position = Vector2(-190.0 - MARGIN, -84.0 - MARGIN)
|
||||
_materials.add_theme_constant_override("separation", 2)
|
||||
add_child(_materials)
|
||||
|
||||
_captions = VBoxContainer.new()
|
||||
_captions.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
|
||||
_captions.size = Vector2(420.0, 4.0 * 24.0)
|
||||
# Above the build line and the hotbar's top, so a long caption never runs into them.
|
||||
_captions.position = Vector2(-420.0 - MARGIN, -112.0 - MARGIN - 52.0 - _captions.size.y)
|
||||
_captions.alignment = BoxContainer.ALIGNMENT_END
|
||||
_captions.add_theme_constant_override("separation", 2)
|
||||
add_child(_captions)
|
||||
show_state(state)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_RESIZED and _hotbar != null:
|
||||
_fit_bottom()
|
||||
|
||||
|
||||
## Shows `shown`, and nothing that isn't in it.
|
||||
func show_state(shown: HudState) -> void:
|
||||
state = shown
|
||||
@@ -134,7 +152,7 @@ func show_state(shown: HudState) -> void:
|
||||
for index: int in lines.size():
|
||||
var label: Label = _feed.get_child(index) as Label
|
||||
label.text = String(lines[index]["text"])
|
||||
label.add_theme_color_override("font_color", Palette.OILSKIN if lines[index]["you"] else Palette.PAPER)
|
||||
label.add_theme_color_override("font_color", Palette.own() if lines[index]["you"] else Palette.PAPER)
|
||||
if shown.feed.is_empty():
|
||||
_feed_seen.clear()
|
||||
|
||||
@@ -155,6 +173,7 @@ func show_state(shown: HudState) -> void:
|
||||
var box: SlotBox = SlotBox.new()
|
||||
box.custom_minimum_size = Vector2(86.0, 112.0)
|
||||
_hotbar.add_child(box)
|
||||
_fit_bottom()
|
||||
for index: int in _hotbar.get_child_count():
|
||||
var box: SlotBox = _hotbar.get_child(index) as SlotBox
|
||||
box.visible = index < shown.slots.size()
|
||||
@@ -169,13 +188,53 @@ func show_state(shown: HudState) -> void:
|
||||
var count: int = shown.materials[code] if code < shown.materials.size() else 0
|
||||
(_materials.get_child(code) as Label).text = "%s %d" % [Materials.NAMES[code].replace("_", " ").capitalize(), count]
|
||||
|
||||
_fit_labels(_captions, shown.captions.size(), HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
for index: int in shown.captions.size():
|
||||
(_captions.get_child(index) as Label).text = "[ %s ]" % shown.captions[index]
|
||||
|
||||
_down.visible = shown.playing and shown.downed
|
||||
_down.add_theme_color_override("font_color", Palette.warning())
|
||||
_build.visible = shown.playing and not shown.build.is_empty()
|
||||
if _build.visible:
|
||||
var build: Dictionary = shown.build
|
||||
_build.text = "BUILDING · %s in %s · costs %d%s" % [String(build["kind"]).capitalize(), String(build["material"]).replace("_", " "),
|
||||
int(build["cost"]), "" if build["affordable"] else " · NOT ENOUGH"]
|
||||
_build.add_theme_color_override("font_color", Palette.PAPER if build["affordable"] else Palette.WARNING)
|
||||
_build.add_theme_color_override("font_color", Palette.PAPER if build["affordable"] else Palette.warning())
|
||||
|
||||
|
||||
## The narrowest a hotbar slot gets when there isn't room for the full width.
|
||||
const SLOT_WIDTH: float = 86.0
|
||||
const SLOT_MIN_WIDTH: float = 66.0
|
||||
|
||||
|
||||
## Places the hotbar between the vitals and the materials: centred when there is room,
|
||||
## as at 1280x720; on a narrower canvas (a larger interface size) beside the vitals,
|
||||
## with its slots narrowed to fit.
|
||||
func _fit_bottom() -> void:
|
||||
var count: int = maxi(_hotbar.get_child_count(), 1)
|
||||
var gap: float = 6.0
|
||||
var left: float = MARGIN + _vitals.size.x + 10.0
|
||||
var right: float = size.x - MARGIN - _materials.size.x - 10.0
|
||||
var slot: float = clampf((right - left - gap * (count - 1)) / count, SLOT_MIN_WIDTH, SLOT_WIDTH)
|
||||
var width: float = slot * count + gap * (count - 1)
|
||||
for child: Node in _hotbar.get_children():
|
||||
(child as Control).custom_minimum_size = Vector2(slot, 112.0)
|
||||
_hotbar.size = Vector2(width, 112.0)
|
||||
var x: float = clampf(size.x * 0.5 - width * 0.5, left, maxf(left, right - width))
|
||||
_hotbar.position = Vector2(x, size.y - 112.0 - MARGIN)
|
||||
|
||||
|
||||
## Where the hotbar is drawn, for tests.
|
||||
func hotbar_rect() -> Rect2:
|
||||
return Rect2(_hotbar.position, _hotbar.size)
|
||||
|
||||
|
||||
func vitals_rect() -> Rect2:
|
||||
return Rect2(_vitals.position, _vitals.size)
|
||||
|
||||
|
||||
func materials_rect() -> Rect2:
|
||||
return Rect2(_materials.position, _materials.size)
|
||||
|
||||
|
||||
## Keeps exactly `count` labels in `box`, adding or removing at the end.
|
||||
@@ -262,12 +321,12 @@ class TidePost:
|
||||
# The next level: a rust notch cut into both sides, with a dashed line across.
|
||||
if next > sea + 0.05:
|
||||
var next_y: float = to_y.call(next)
|
||||
draw_dashed_line(Vector2(post.position.x - 6.0, next_y), Vector2(post.end.x + 6.0, next_y), Palette.WARNING, 2.0, 4.0)
|
||||
draw_colored_polygon(PackedVector2Array([Vector2(post.position.x - 10.0, next_y - 5.0), Vector2(post.position.x - 2.0, next_y), Vector2(post.position.x - 10.0, next_y + 5.0)]), Palette.WARNING)
|
||||
draw_dashed_line(Vector2(post.position.x - 6.0, next_y), Vector2(post.end.x + 6.0, next_y), Palette.warning(), 2.0, 4.0)
|
||||
draw_colored_polygon(PackedVector2Array([Vector2(post.position.x - 10.0, next_y - 5.0), Vector2(post.position.x - 2.0, next_y), Vector2(post.position.x - 10.0, next_y + 5.0)]), Palette.warning())
|
||||
# The player's own height: a yellow pointer on the right of the post.
|
||||
if not is_nan(feet):
|
||||
var feet_y: float = to_y.call(feet)
|
||||
draw_colored_polygon(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0)]), Palette.OILSKIN)
|
||||
draw_colored_polygon(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0)]), Palette.own())
|
||||
draw_polyline(PackedVector2Array([Vector2(post.end.x + 2.0, feet_y), Vector2(post.end.x + 12.0, feet_y - 6.0), Vector2(post.end.x + 12.0, feet_y + 6.0), Vector2(post.end.x + 2.0, feet_y)]), Palette.INK, 1.0)
|
||||
|
||||
var x: float = post.end.x + 26.0
|
||||
@@ -285,12 +344,12 @@ class TidePost:
|
||||
timing = "HIGH WATER · last land"
|
||||
_:
|
||||
timing = "Slack water"
|
||||
Hud.draw_text(self, Vector2(x, 54.0), timing, Hud.FONT_BODY, Palette.WARNING if stage != Tide.HOLD else Palette.INK, width)
|
||||
Hud.draw_text(self, Vector2(x, 54.0), timing, Hud.FONT_BODY, Palette.warning() if stage != Tide.HOLD else Palette.INK, width)
|
||||
Hud.draw_text(self, Vector2(x, 74.0), "Sea %.1f m · next %.1f m" % [sea, next], Hud.FONT_SMALL, Palette.INK, width)
|
||||
if not is_nan(feet):
|
||||
var above: float = feet - next
|
||||
var line: String = "You: %.1f m above the next line" % above if above >= 0.0 else "You: %.1f m BELOW the next line" % -above
|
||||
Hud.draw_text(self, Vector2(x, 92.0), line, Hud.FONT_SMALL, Palette.INK if above >= 0.0 else Palette.WARNING, width)
|
||||
Hud.draw_text(self, Vector2(x, 92.0), line, Hud.FONT_SMALL, Palette.INK if above >= 0.0 else Palette.warning(), width)
|
||||
|
||||
|
||||
## Health and armour bars: each a number, a word, notches every quarter and its own
|
||||
@@ -314,7 +373,7 @@ class Vitals:
|
||||
Hud.draw_text(self, Vector2(10.0, rect.position.y + rect.size.y * 0.5 + 5.0), word, Hud.FONT_SMALL)
|
||||
draw_rect(rect, Color(Palette.INK, 0.15))
|
||||
var filled: Rect2 = Rect2(rect.position, Vector2(rect.size.x * clampf(float(value) / most, 0.0, 1.0), rect.size.y))
|
||||
var fill: Color = Palette.WARNING if low else (Palette.SEA_PAINT if striped else Palette.OCHRE_RED.lerp(Palette.TAR, 0.1))
|
||||
var fill: Color = Palette.warning() if low else (Palette.SEA_PAINT if striped else Palette.OCHRE_RED.lerp(Palette.TAR, 0.1))
|
||||
draw_rect(filled, fill)
|
||||
if striped or low:
|
||||
# Armour is hatched one way; low health the other.
|
||||
@@ -370,7 +429,7 @@ class SlotBox:
|
||||
return
|
||||
Hud.draw_card(self, rect, selected)
|
||||
if selected:
|
||||
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.OILSKIN)
|
||||
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.own())
|
||||
draw_rect(Rect2(rect.position, Vector2(rect.size.x, 6.0)), Palette.INK, false, 1.0)
|
||||
Hud.draw_text(self, rect.position + Vector2(5.0, 15.0), str(number), Hud.FONT_SMALL - 2, Palette.INK)
|
||||
var picture: Texture2D = ItemModels.icon(String(slot.get("id", "")))
|
||||
@@ -450,7 +509,7 @@ class HurtEdge:
|
||||
for step: int in steps:
|
||||
var inset: float = band * step / steps
|
||||
var alpha: float = 0.42 * strength * (1.0 - float(step) / steps)
|
||||
var colour: Color = Color(Palette.WARNING, alpha / steps * 2.0)
|
||||
var colour: Color = Color(Palette.warning(), alpha / steps * 2.0)
|
||||
var width: float = band / steps
|
||||
draw_rect(Rect2(inset, inset, size.x - inset * 2.0, width), colour)
|
||||
draw_rect(Rect2(inset, size.y - inset - width, size.x - inset * 2.0, width), colour)
|
||||
|
||||
@@ -33,6 +33,8 @@ var reticle: bool = false
|
||||
## flash for being hurt, each 1 just after and 0 when gone.
|
||||
var hit: float = 0.0
|
||||
var hurt: float = 0.0
|
||||
## Captions for key sounds (A13, Captions), oldest first; empty when they're off.
|
||||
var captions: Array[String] = []
|
||||
|
||||
|
||||
## The HUD for a client: its own predicted player, the world's tide and the server's feed.
|
||||
|
||||
@@ -10,6 +10,8 @@ const MIN_SENSITIVITY: float = 0.05
|
||||
const MAX_SENSITIVITY: float = 10.0
|
||||
## Looking straight up or down flips the camera basis, so stop just short.
|
||||
const PITCH_LIMIT: float = deg_to_rad(85.0)
|
||||
const MIN_PAD_SENSITIVITY: float = 0.2
|
||||
const MAX_PAD_SENSITIVITY: float = 3.0
|
||||
|
||||
var mouse_sensitivity: float = 1.0:
|
||||
set(value):
|
||||
@@ -19,6 +21,12 @@ var aim_sensitivity_scale: float = 0.6:
|
||||
set(value):
|
||||
aim_sensitivity_scale = clampf(value, 0.1, 2.0)
|
||||
var invert_y: bool = false
|
||||
## The gamepad's right stick, against PadInput.LOOK_RADIANS_PER_SECOND (A13).
|
||||
var pad_sensitivity: float = 1.0:
|
||||
set(value):
|
||||
pad_sensitivity = clampf(value, MIN_PAD_SENSITIVITY, MAX_PAD_SENSITIVITY)
|
||||
## Aim assist for the gamepad (AimAssist). Never applies to the mouse.
|
||||
var aim_assist: bool = true
|
||||
|
||||
|
||||
## Applies a mouse motion to a look direction. Returns Vector2(yaw, pitch) in radians.
|
||||
@@ -33,13 +41,33 @@ func apply_mouse(relative: Vector2, yaw: float, pitch: float, aiming: bool) -> V
|
||||
return Vector2(new_yaw, new_pitch)
|
||||
|
||||
|
||||
## Applies `delta` seconds of the right stick (PadInput.look(): x right, y down) to a
|
||||
## look direction, slowed by `friction` (AimAssist). Returns Vector2(yaw, pitch).
|
||||
## Pushing right turns right and pushing up looks up, unless invert_y is set.
|
||||
func apply_stick(stick: Vector2, yaw: float, pitch: float, aiming: bool, delta: float, friction: float = 1.0) -> Vector2:
|
||||
var scale: float = PadInput.LOOK_RADIANS_PER_SECOND * pad_sensitivity * delta * friction
|
||||
if aiming:
|
||||
scale *= aim_sensitivity_scale
|
||||
var vertical: float = stick.y if invert_y else -stick.y
|
||||
var new_yaw: float = fposmod(yaw - stick.x * scale, TAU)
|
||||
var new_pitch: float = clampf(pitch + vertical * scale, -PITCH_LIMIT, PITCH_LIMIT)
|
||||
return Vector2(new_yaw, new_pitch)
|
||||
|
||||
|
||||
func save(path: String = DEFAULT_PATH) -> Error:
|
||||
var config: ConfigFile = ConfigFile.new()
|
||||
config.load(path) # Keep other sections; a missing file is fine.
|
||||
write(config)
|
||||
return config.save(path)
|
||||
|
||||
|
||||
## Writes these settings into `config`'s input section.
|
||||
func write(config: ConfigFile) -> void:
|
||||
config.set_value(SECTION, "mouse_sensitivity", mouse_sensitivity)
|
||||
config.set_value(SECTION, "aim_sensitivity_scale", aim_sensitivity_scale)
|
||||
config.set_value(SECTION, "invert_y", invert_y)
|
||||
return config.save(path)
|
||||
config.set_value(SECTION, "pad_sensitivity", pad_sensitivity)
|
||||
config.set_value(SECTION, "aim_assist", aim_assist)
|
||||
|
||||
|
||||
## Loads saved settings. Missing or malformed values keep their defaults.
|
||||
@@ -57,4 +85,10 @@ static func load_from(path: String = DEFAULT_PATH) -> InputSettings:
|
||||
var invert: Variant = config.get_value(SECTION, "invert_y", false)
|
||||
if invert is bool:
|
||||
settings.invert_y = invert
|
||||
var pad: Variant = config.get_value(SECTION, "pad_sensitivity", 1.0)
|
||||
if (pad is float and is_finite(pad)) or pad is int:
|
||||
settings.pad_sensitivity = float(pad)
|
||||
var assist: Variant = config.get_value(SECTION, "aim_assist", true)
|
||||
if assist is bool:
|
||||
settings.aim_assist = assist
|
||||
return settings
|
||||
|
||||
@@ -39,6 +39,7 @@ func apply_settings(settings: GameSettings) -> void:
|
||||
print_pass.visible = settings.print_pass
|
||||
if effects != null:
|
||||
effects.budget = settings.particle_budget()
|
||||
rig.reduce_motion = settings.reduce_motion
|
||||
|
||||
|
||||
## Builds the scene for `simulation`. `local_id` is the player this client plays, or 0.
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
## The gamepad (A13): one fixed layout, read from the input events the game is given
|
||||
## rather than from the Input singleton, so tests can drive it with simulated events and
|
||||
## any pad (device) works. Buttons use Godot's JoyButton positions, named here as on the
|
||||
## common layouts (south A, east B, west X, north Y).
|
||||
##
|
||||
## Left stick move · right stick look · click the left stick to sprint (until you stop)
|
||||
## South jump · East crouch · West reload · North pick up or open
|
||||
## Right trigger use, fire or place · left trigger aim
|
||||
## Right bumper next slot or piece · left bumper the one before
|
||||
## Click the right stick: build mode · D-pad up the chart · D-pad down drop the held item
|
||||
## D-pad right / left: next / previous material · Start the pause menu
|
||||
##
|
||||
## In the menus the D-pad and the left stick move the focus (Godot's own ui_ actions),
|
||||
## South chooses and East or Start goes back (install_menu_actions()).
|
||||
class_name PadInput
|
||||
extends RefCounted
|
||||
|
||||
## Sticks inside this radius count as centred.
|
||||
const DEADZONE: float = 0.18
|
||||
## A trigger pulled further than this is held.
|
||||
const TRIGGER_PULL: float = 0.45
|
||||
## Radians a second the look turns with the right stick pushed fully, at look speed 1.
|
||||
const LOOK_RADIANS_PER_SECOND: float = 3.2
|
||||
## The look's response: stick deflection (past the dead zone) raised to this, so small
|
||||
## pushes turn finely and full pushes turn fast.
|
||||
const LOOK_CURVE: float = 1.7
|
||||
|
||||
## Actions held while their button is.
|
||||
const HELD_BUTTONS: Dictionary = {
|
||||
"jump": JOY_BUTTON_A, "crouch": JOY_BUTTON_B, "reload": JOY_BUTTON_X,
|
||||
"interact": JOY_BUTTON_Y,
|
||||
}
|
||||
## Actions held while their trigger is pulled.
|
||||
const HELD_TRIGGERS: Dictionary = {
|
||||
"fire": JOY_AXIS_TRIGGER_RIGHT, "aim": JOY_AXIS_TRIGGER_LEFT,
|
||||
}
|
||||
## Actions that happen once per press. "drop" is also held (the command's drop button),
|
||||
## so it is in both: pressed() reports it and held() holds it.
|
||||
const PRESS_BUTTONS: Dictionary = {
|
||||
JOY_BUTTON_RIGHT_STICK: "build", JOY_BUTTON_DPAD_UP: "map",
|
||||
JOY_BUTTON_DPAD_RIGHT: "material", JOY_BUTTON_DPAD_LEFT: "material_back",
|
||||
JOY_BUTTON_RIGHT_SHOULDER: "slot_next", JOY_BUTTON_LEFT_SHOULDER: "slot_back",
|
||||
JOY_BUTTON_LEFT_STICK: "sprint", JOY_BUTTON_START: "pause",
|
||||
}
|
||||
const DROP_BUTTON: JoyButton = JOY_BUTTON_DPAD_DOWN
|
||||
## Names for the settings menu and the tutorial, by action.
|
||||
const NAMES: Dictionary = {
|
||||
"forward": "Left stick", "back": "Left stick", "left": "Left stick", "right": "Left stick",
|
||||
"look": "Right stick", "jump": "South (A)", "crouch": "East (B)", "reload": "West (X)",
|
||||
"interact": "North (Y)", "fire": "Right trigger", "aim": "Left trigger",
|
||||
"sprint": "Click left stick", "build": "Click right stick", "map": "D-pad up",
|
||||
"drop": "D-pad down", "material": "D-pad right", "material_back": "D-pad left",
|
||||
"slot_next": "Right bumper", "slot_back": "Left bumper", "pause": "Start",
|
||||
}
|
||||
## The layout as the settings menu lists it: [what, which].
|
||||
const LAYOUT: Array[Array] = [
|
||||
["Move", "Left stick"], ["Look", "Right stick"], ["Sprint (until you stop)", "Click left stick"],
|
||||
["Jump", "South (A)"], ["Crouch", "East (B)"], ["Reload", "West (X)"],
|
||||
["Pick up or open", "North (Y)"], ["Use, fire or place", "Right trigger"],
|
||||
["Aim", "Left trigger"], ["Next slot or piece", "Right bumper"],
|
||||
["Slot or piece before", "Left bumper"], ["Build mode", "Click right stick"],
|
||||
["Chart", "D-pad up"], ["Drop held item", "D-pad down"],
|
||||
["Next / previous material", "D-pad right / left"], ["Pause menu", "Start"],
|
||||
]
|
||||
|
||||
var _buttons: Dictionary = {}
|
||||
var _axes: PackedFloat32Array = PackedFloat32Array()
|
||||
## Presses since the last take_presses(), as action ids, in order.
|
||||
var _presses: Array[String] = []
|
||||
## True once the pad has been used since the keyboard or mouse last was, so prompts
|
||||
## can name pad buttons.
|
||||
var active: bool = false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_axes.resize(JOY_AXIS_MAX)
|
||||
|
||||
|
||||
## Takes one input event. Returns true if it was the pad's.
|
||||
func feed(event: InputEvent) -> bool:
|
||||
var button: InputEventJoypadButton = event as InputEventJoypadButton
|
||||
if button != null:
|
||||
var index: int = int(button.button_index)
|
||||
var was: bool = bool(_buttons.get(index, false))
|
||||
_buttons[index] = button.pressed
|
||||
if button.pressed and not was:
|
||||
active = true
|
||||
if PRESS_BUTTONS.has(index):
|
||||
_presses.append(String(PRESS_BUTTONS[index]))
|
||||
return true
|
||||
var motion: InputEventJoypadMotion = event as InputEventJoypadMotion
|
||||
if motion != null:
|
||||
var axis: int = int(motion.axis)
|
||||
if axis >= 0 and axis < _axes.size():
|
||||
_axes[axis] = clampf(motion.axis_value, -1.0, 1.0)
|
||||
if absf(motion.axis_value) > 0.5:
|
||||
active = true
|
||||
return true
|
||||
if event is InputEventKey or event is InputEventMouseButton:
|
||||
active = false
|
||||
return false
|
||||
|
||||
|
||||
## The once-per-press actions since the last call, oldest first.
|
||||
func take_presses() -> Array[String]:
|
||||
var taken: Array[String] = _presses
|
||||
_presses = []
|
||||
return taken
|
||||
|
||||
|
||||
func is_held(action: String) -> bool:
|
||||
if action == "drop":
|
||||
return bool(_buttons.get(int(DROP_BUTTON), false))
|
||||
if HELD_BUTTONS.has(action):
|
||||
return bool(_buttons.get(int(HELD_BUTTONS[action]), false))
|
||||
if HELD_TRIGGERS.has(action):
|
||||
return _axes[int(HELD_TRIGGERS[action])] > TRIGGER_PULL
|
||||
return false
|
||||
|
||||
|
||||
## The left stick as Vector2(strafe right, forward), dead zone removed, length up to 1.
|
||||
func move() -> Vector2:
|
||||
var stick: Vector2 = _stick(JOY_AXIS_LEFT_X, JOY_AXIS_LEFT_Y)
|
||||
return Vector2(stick.x, -stick.y)
|
||||
|
||||
|
||||
## The right stick, dead zone removed and curved: x right, y down, length up to 1.
|
||||
func look() -> Vector2:
|
||||
var stick: Vector2 = _stick(JOY_AXIS_RIGHT_X, JOY_AXIS_RIGHT_Y)
|
||||
var length: float = stick.length()
|
||||
if length <= 0.0:
|
||||
return Vector2.ZERO
|
||||
return stick / length * pow(length, LOOK_CURVE)
|
||||
|
||||
|
||||
## Forgets everything held (the pad was unplugged, or a menu opened).
|
||||
func release() -> void:
|
||||
_buttons.clear()
|
||||
_axes.fill(0.0)
|
||||
_presses.clear()
|
||||
|
||||
|
||||
## A stick with a radial dead zone, rescaled so it starts from 0 at the zone's edge.
|
||||
func _stick(x_axis: JoyAxis, y_axis: JoyAxis) -> Vector2:
|
||||
var raw: Vector2 = Vector2(_axes[int(x_axis)], _axes[int(y_axis)])
|
||||
var length: float = raw.length()
|
||||
if length <= DEADZONE:
|
||||
return Vector2.ZERO
|
||||
return raw / length * minf((length - DEADZONE) / (1.0 - DEADZONE), 1.0)
|
||||
|
||||
|
||||
## The name of the pad input for `action`, for prompts.
|
||||
static func describe(action: String) -> String:
|
||||
if action.begins_with("slot_") and not NAMES.has(action):
|
||||
return "Bumpers"
|
||||
return String(NAMES.get(action, "?"))
|
||||
|
||||
|
||||
## Adds the pad to Godot's menu actions: South chooses, East and Start go back. The
|
||||
## D-pad and the left stick already move the focus. Safe to call more than once.
|
||||
static func install_menu_actions() -> void:
|
||||
_add_button("ui_accept", JOY_BUTTON_A)
|
||||
_add_button("ui_cancel", JOY_BUTTON_B)
|
||||
_add_button("ui_cancel", JOY_BUTTON_START)
|
||||
|
||||
|
||||
static func _add_button(action: String, index: JoyButton) -> void:
|
||||
if not InputMap.has_action(action):
|
||||
return
|
||||
for existing: InputEvent in InputMap.action_get_events(action):
|
||||
var pad: InputEventJoypadButton = existing as InputEventJoypadButton
|
||||
if pad != null and pad.button_index == index:
|
||||
return
|
||||
var event: InputEventJoypadButton = InputEventJoypadButton.new()
|
||||
event.button_index = index
|
||||
event.device = -1
|
||||
InputMap.action_add_event(action, event)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bftj1asrutyll
|
||||
@@ -116,3 +116,49 @@ const GHOST_REFUSED: Color = Color(0.86, 0.32, 0.22, 0.38)
|
||||
const WARNING: Color = Color(0.86, 0.32, 0.22)
|
||||
## The sea on the HUD's tide gauge and map.
|
||||
const SEA_INK: Color = Color(0.20, 0.34, 0.42)
|
||||
|
||||
# --- Colour vision (A13) ------------------------------------------------------------
|
||||
## The signal colours above suit most eyes, but red against green (the build ghost) and
|
||||
## rust against oilskin yellow are hard for many people to tell apart. The settings
|
||||
## offer a set for each common kind of colour blindness; everything that signals asks
|
||||
## for its colour through the functions below, so the set chosen applies everywhere.
|
||||
## test_palette checks each set with a simulation of the colour vision it is for.
|
||||
const VISION_NAMES: Array[String] = ["Standard", "Red-green (protan, deutan)", "Blue-yellow (tritan)"]
|
||||
const VISION_STANDARD: int = 0
|
||||
const VISION_RED_GREEN: int = 1
|
||||
const VISION_BLUE_YELLOW: int = 2
|
||||
## Per set: allowed and refused in the build ghost, danger, and the player's own marks.
|
||||
const VISION_SIGNALS: Array[Dictionary] = [
|
||||
{"ghost_ok": GHOST_OK, "ghost_refused": GHOST_REFUSED, "warning": WARNING, "own": OILSKIN},
|
||||
# Blue for allowed and orange for refused; danger a deep magenta, apart from the
|
||||
# yellow of the player's own marks.
|
||||
{"ghost_ok": Color(0.22, 0.52, 0.95, 0.40), "ghost_refused": Color(0.98, 0.56, 0.08, 0.40),
|
||||
"warning": Color(0.78, 0.16, 0.62), "own": OILSKIN},
|
||||
# Teal for allowed and vermilion for refused; the player's marks turn white-blue,
|
||||
# since yellow and pink run together.
|
||||
{"ghost_ok": Color(0.16, 0.70, 0.74, 0.40), "ghost_refused": Color(0.90, 0.16, 0.20, 0.40),
|
||||
"warning": Color(0.88, 0.14, 0.18), "own": Color(0.62, 0.86, 0.98)},
|
||||
]
|
||||
|
||||
## Which set is in use. GameSettings.apply_to_program sets it.
|
||||
static var vision: int = VISION_STANDARD:
|
||||
set(value):
|
||||
vision = clampi(value, 0, VISION_SIGNALS.size() - 1)
|
||||
|
||||
|
||||
static func ghost_ok() -> Color:
|
||||
return VISION_SIGNALS[vision]["ghost_ok"]
|
||||
|
||||
|
||||
static func ghost_refused() -> Color:
|
||||
return VISION_SIGNALS[vision]["ghost_refused"]
|
||||
|
||||
|
||||
## Danger on the HUD and chart (WARNING in the standard set).
|
||||
static func warning() -> Color:
|
||||
return VISION_SIGNALS[vision]["warning"]
|
||||
|
||||
|
||||
## The player's own marks on the HUD and chart (OILSKIN in the standard set).
|
||||
static func own() -> Color:
|
||||
return VISION_SIGNALS[vision]["own"]
|
||||
|
||||
Reference in New Issue
Block a user