This commit is contained in:
Forrest 2026-10-01 23:01:56 -04:00
parent 0cba7f5ee0
commit 32ed347b58
172 changed files with 5464 additions and 582 deletions

115
ui/bandwidth_bar.gd Normal file
View file

@ -0,0 +1,115 @@
class_name BandwidthBar
extends Control
## A player's Bandwidth as a neon loading bar (ui-plan.md §A5). Bandwidth has no maximum, so the
## scale is fixed at 0–20 Gb with ticks at the Firewall costs, and the bar glows past 20 instead of
## clipping. Behind the fill, a dimmer ghost runs to what you could reach by salvaging your hand
## (Query.reachable_bandwidth): the number that answers "can I afford this?".
const MAX_GB := 20
const CELLS := 20
var color := Style.ACCENT:
set(value):
color = value
queue_redraw()
## Tick marks, in Gb: the Firewall costs.
var ticks: Array = [2, 4, 8]:
set(value):
ticks = value
queue_redraw()
## Show the numbers under the ticks.
var show_scale := false:
set(value):
show_scale = value
custom_minimum_size.y = 22.0 if value else 10.0
queue_redraw()
## The shown fill, eased toward the real value.
var shown := 0.0:
set(value):
shown = value
queue_redraw()
var gb := 0
var reachable := 0
var _tween: Tween
var _pulse := 0.0
func _init() -> void:
custom_minimum_size = Vector2(120, 10)
mouse_filter = Control.MOUSE_FILTER_IGNORE
## Shows `value` Gb with the ghost at `reach`. Animates the change on the motion curve.
func set_bandwidth(value: int, reach: int, animate := true) -> void:
reachable = maxi(reach, value)
if value == gb and is_equal_approx(shown, value):
queue_redraw()
return
gb = value
if _tween != null:
_tween.kill()
if not animate or Motion.instant() or not is_inside_tree():
shown = value
return
_tween = create_tween()
Motion.rush_in(_tween, self, "shown", float(value), 0.55)
func _process(delta: float) -> void:
if gb > MAX_GB:
_pulse = fmod(_pulse + delta, 2.0)
queue_redraw()
func _draw() -> void:
var bar_h := minf(size.y, 10.0)
var w := size.x
var cell := w / CELLS
var gap := maxf(1.0, cell * 0.14)
var dark := Color(color, 0.1)
var ghost := Color(color, 0.28)
for i in CELLS:
var x := i * cell
var r := Rect2(x + gap / 2.0, 0, cell - gap, bar_h)
var c := dark
if i + 1 <= roundi(shown):
# Brighter toward the head of the fill.
c = color.lerp(Color.WHITE, 0.25 * float(i) / CELLS)
elif i + 1 <= reachable:
c = ghost
draw_rect(r, c)
# A partial cell while the fill moves.
var frac := shown - floorf(shown)
if frac > 0.02 and shown < CELLS:
var i := int(floorf(shown))
draw_rect(Rect2(i * cell + gap / 2.0, 0, (cell - gap) * frac, bar_h), color)
# The frame and the Firewall-cost ticks.
draw_rect(Rect2(0, -2, w, bar_h + 4), Color(color, 0.45), false, 1.0)
for t in ticks:
if t > 0 and t < MAX_GB:
var x: float = t * cell
draw_line(Vector2(x, -4), Vector2(x, bar_h + 4), Color(Style.SCREEN, 0.7), 1.0)
if show_scale:
_text(str(t), Vector2(x, bar_h + 14))
if show_scale:
_text("0", Vector2(0, bar_h + 14), HORIZONTAL_ALIGNMENT_LEFT)
_text("20", Vector2(w, bar_h + 14), HORIZONTAL_ALIGNMENT_RIGHT)
# Past the scale: the bar glows instead of clipping.
if gb > MAX_GB:
var k := 0.5 + 0.5 * sin(_pulse * PI)
for g in 3:
var grow := 2.0 + g * 2.0
draw_rect(Rect2(-grow, -2 - grow, w + grow * 2, bar_h + 4 + grow * 2), Color(color, (0.25 - g * 0.07) * (0.6 + 0.4 * k)), false, 2.0)
func _text(t: String, at: Vector2, align := HORIZONTAL_ALIGNMENT_CENTER) -> void:
var f := Style.body_font()
var fs := 10
var tw := f.get_string_size(t, HORIZONTAL_ALIGNMENT_LEFT, -1, fs).x
var x := at.x - tw / 2.0
if align == HORIZONTAL_ALIGNMENT_LEFT:
x = at.x
elif align == HORIZONTAL_ALIGNMENT_RIGHT:
x = at.x - tw
draw_string(f, Vector2(x, at.y), t, HORIZONTAL_ALIGNMENT_LEFT, -1, fs, Style.MUTED)

1
ui/bandwidth_bar.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://c50u7fnnf6kjs

147
ui/chamfer_box.gd Normal file
View file

@ -0,0 +1,147 @@
@tool
class_name ChamferBox
extends StyleBox
## A panel with the cards' chamfered corners (ui-plan.md §0.3): the `.neon` frame of the print
## templates, an octagon with a fill, an accent border, an optional outer glow and the corner ticks
## on the top chamfers. StyleBoxFlat only rounds corners, so this draws the octagon itself. Being a
## StyleBox, it goes in a Theme like any other and serves panels, buttons and chips at any size.
## Corners to cut, as a bitmask of these. The rest stay square.
const TOP_LEFT := 1
const TOP_RIGHT := 2
const BOTTOM_RIGHT := 4
const BOTTOM_LEFT := 8
const ALL := 15
@export var bg_color := Color(0, 0, 0, 0.8):
set(value):
bg_color = value
emit_changed()
@export var border_color := Color("#22d3ee"):
set(value):
border_color = value
emit_changed()
@export var border_width := 1.5:
set(value):
border_width = value
emit_changed()
## The cut, in pixels. Clamped to half the shorter side.
@export var chamfer := 8.0:
set(value):
chamfer = value
emit_changed()
@export_flags("Top left", "Top right", "Bottom right", "Bottom left") var corners := ALL:
set(value):
corners = value
emit_changed()
## How far the glow reaches past the border, in pixels; 0 for none. It takes the border's color.
@export var glow := 0.0:
set(value):
glow = value
emit_changed()
@export_range(0.0, 1.0) var glow_alpha := 0.35:
set(value):
glow_alpha = value
emit_changed()
## Thick accent bars along the top chamfers, like the cards' corner ticks.
@export var ticks := false:
set(value):
ticks = value
emit_changed()
## A stripe of border color down the left edge, this wide: owner panels and log prompts.
@export var left_bar := 0.0:
set(value):
left_bar = value
emit_changed()
func _init(fill := Color(0, 0, 0, 0.8), border := Color("#22d3ee"), width := 1.5, cut := 8.0) -> void:
bg_color = fill
border_color = border
border_width = width
chamfer = cut
set_content_margin_all(8)
content_margin_top = 6
content_margin_bottom = 6
## The octagon for `r`, clockwise from the top-left corner, cut by `c`.
func _outline(r: Rect2, c: float) -> PackedVector2Array:
c = clampf(c, 0.0, minf(r.size.x, r.size.y) / 2.0)
var x0 := r.position.x
var y0 := r.position.y
var x1 := r.end.x
var y1 := r.end.y
var pts := PackedVector2Array()
if corners & TOP_LEFT and c > 0:
pts.append_array([Vector2(x0, y0 + c), Vector2(x0 + c, y0)])
else:
pts.append(Vector2(x0, y0))
if corners & TOP_RIGHT and c > 0:
pts.append_array([Vector2(x1 - c, y0), Vector2(x1, y0 + c)])
else:
pts.append(Vector2(x1, y0))
if corners & BOTTOM_RIGHT and c > 0:
pts.append_array([Vector2(x1, y1 - c), Vector2(x1 - c, y1)])
else:
pts.append(Vector2(x1, y1))
if corners & BOTTOM_LEFT and c > 0:
pts.append_array([Vector2(x0 + c, y1), Vector2(x0, y1 - c)])
else:
pts.append(Vector2(x0, y1))
return pts
func _closed(pts: PackedVector2Array) -> PackedVector2Array:
var out := pts.duplicate()
out.append(pts[0])
return out
func _draw(to_canvas_item: RID, rect: Rect2) -> void:
var rs := RenderingServer
if rect.size.x <= 1 or rect.size.y <= 1:
return
# The glow: rings outside the border, fading out.
if glow > 0.0 and border_color.a > 0.0:
var rings := 4
var step := glow / rings
for i in rings:
var grow := step * (i + 0.5)
var k := 1.0 - float(i) / rings
var c := Color(border_color, border_color.a * glow_alpha * k * k)
var ring := _outline(rect.grow(grow), chamfer + grow * 0.414)
rs.canvas_item_add_polyline(to_canvas_item, _closed(ring), [c], step + 0.5, true)
var pts := _outline(rect, chamfer)
if bg_color.a > 0.0:
rs.canvas_item_add_polygon(to_canvas_item, pts, [bg_color])
if left_bar > 0.0:
# The panel's own outline cut down to its left edge, so the chamfers cut the bar too.
var strip := PackedVector2Array([rect.position, rect.position + Vector2(left_bar, 0),
rect.position + Vector2(left_bar, rect.size.y), rect.position + Vector2(0, rect.size.y)])
for bar in Geometry2D.intersect_polygons(pts, strip):
rs.canvas_item_add_polygon(to_canvas_item, bar, [border_color])
if border_width > 0.0 and border_color.a > 0.0:
var inset := _outline(rect.grow(-border_width / 2.0), maxf(0.0, chamfer - border_width * 0.2))
rs.canvas_item_add_polyline(to_canvas_item, _closed(inset), [border_color], border_width, true)
if ticks:
var c := clampf(chamfer, 0.0, minf(rect.size.x, rect.size.y) / 2.0)
var w := maxf(2.5, border_width * 2.0)
var tick := Color(border_color, minf(1.0, border_color.a * 1.4))
if corners & TOP_LEFT:
rs.canvas_item_add_line(to_canvas_item, rect.position + Vector2(0, c), rect.position + Vector2(c, 0), tick, w, true)
if corners & TOP_RIGHT:
var tr := Vector2(rect.end.x, rect.position.y)
rs.canvas_item_add_line(to_canvas_item, tr + Vector2(-c, 0), tr + Vector2(0, c), tick, w, true)
func _get_draw_rect(rect: Rect2) -> Rect2:
return rect.grow(glow)
## A copy with other colors, for button states and chips.
func tinted(fill: Color, border: Color) -> ChamferBox:
var b: ChamferBox = duplicate()
b.bg_color = fill
b.border_color = border
return b

1
ui/chamfer_box.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://dqdsxifyvahdc

38
ui/game_settings.gd Normal file
View file

@ -0,0 +1,38 @@
class_name GameSettings
## The player's settings, kept in user://settings.cfg between runs. The game scene only reads them
## when it's entered from the menu (see SceneRouter), so tests that open it directly always start
## from DEFAULTS.
const PATH := "user://settings.cfg"
const DEFAULTS := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45, "anim": "normal"}
## Animation speeds: `scale` multiplies every animation's length; 0 is instant.
const ANIM_SPEEDS := {
"slow": {"label": "Slow", "scale": 1.6},
"normal": {"label": "Normal", "scale": 1.0},
"fast": {"label": "Fast", "scale": 0.5},
"instant": {"label": "Instant", "scale": 0.0},
}
static func load_saved() -> Dictionary:
var out := DEFAULTS.duplicate()
var cfg := ConfigFile.new()
if cfg.load(PATH) == OK:
for k in DEFAULTS:
var v = cfg.get_value("game", k, DEFAULTS[k])
if typeof(v) == typeof(DEFAULTS[k]) or (DEFAULTS[k] is float and v is int):
out[k] = v
if not ANIM_SPEEDS.has(out.anim):
out.anim = DEFAULTS.anim
return out
static func save(settings: Dictionary) -> void:
var cfg := ConfigFile.new()
for k in DEFAULTS:
cfg.set_value("game", k, settings.get(k, DEFAULTS[k]))
cfg.save(PATH)
static func anim_scale(settings: Dictionary) -> float:
return ANIM_SPEEDS.get(settings.get("anim", "normal"), ANIM_SPEEDS.normal).scale

1
ui/game_settings.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://b5g0pdocs00y0

1278
ui/hud.gd

File diff suppressed because it is too large Load diff

16
ui/scanlines.gdshader Normal file
View file

@ -0,0 +1,16 @@
shader_type canvas_item;
// The CRT texture of the print templates' terminals (ui-plan.md §2): dark lines 2 px of every 4,
// laid over a ChamferBox panel. A StyleBox can't carry a shader, so this goes on a ColorRect on top.
uniform float strength : hint_range(0.0, 1.0) = 0.16;
uniform float period = 4.0;
// A faint moving band, as on an old monitor; 0 turns it off.
uniform float roll = 0.04;
void fragment() {
float line = step(mod(FRAGCOORD.y, period), period * 0.5);
float band = roll * smoothstep(0.0, 1.0, sin(FRAGCOORD.y * 0.012 - TIME * 1.7) * 0.5 + 0.5);
COLOR = vec4(0.0, 0.0, 0.0, strength * line - band * 0.5);
COLOR.a = max(COLOR.a, 0.0);
}

View file

@ -0,0 +1 @@
uid://tbf16hlo77r6

280
ui/style.gd Normal file
View file

@ -0,0 +1,280 @@
class_name Style
## The design system (ui-plan.md §2–3): the print templates' tokens, the two fonts, the chamfered
## boxes and the one Theme, plus the screen space the 2D panels take. The HUD, the table's own 2D
## readouts and the menu all read their colors and fonts from here, so nothing restyles by eye.
# ---------------------------------------------------------------------------------------------
# Tokens, from decks/files-deck-1/*.css
const BG := Color("#05080a")
## Primary, secondary and label text.
const SCREEN := Color("#e6fbff")
const SECONDARY := Color("#a9d9e0")
const MUTED := Color("#6f8a90")
## System chrome: frames, buttons, the grid, the terminal.
const ACCENT := Color("#22d3ee")
const ACCENT_DK := Color("#0e6b78")
## Panel fills: translucent black over the table, and a lifted shade for buttons.
const PANEL := Color("#05080ae6")
const PANEL_HI := Color("#0a1a20f0")
const DISABLED := Color("#33464b")
## Warnings, damage and attacks.
const WARN := Color("#ffb02e")
const BAD := Color("#ff5c5c")
const ATTACK := Color("#ff4f6d")
## Okabe–Ito sky blue (South) and orange (North): they stay apart for color-blind players. A stripe
## (South) or dot (North) fill is the second cue, since chrome cyan sits beside South's blue.
const OWNER: Array[Color] = [Color("#56b4e9"), Color("#e69f00")]
const TYPE_ACCENT := {
"server": Color("#39d353"), "hardware": Color("#ffd24a"), "execution": Color("#ffb02e"),
"program": Color("#8b949e"), "system": Color("#22d3ee"),
}
## Anomaly classes: Virus, Bug, Glitch, Patch.
const CLASS_ACCENT := {"V": Color("#3fb950"), "B": Color("#ff5c5c"), "G": Color("#d264ff"), "P": Color("#4aa3ff")}
const CLASS_NAMES := {"V": "Virus", "B": "Bug", "G": "Glitch", "P": "Patch"}
## How table objects glow: legal sources, responses, the selection, targets, attacks, the combat.
const MARK := {
"source": ACCENT, "respond": WARN, "selected": Color.WHITE,
"target": ACCENT, "attack": ATTACK, "fight": ATTACK,
}
const MARK_STRENGTH := {"source": 1.0, "respond": 1.2, "selected": 2.0, "target": 1.5, "attack": 1.8, "fight": 1.2}
# ---------------------------------------------------------------------------------------------
# Panel geometry (§0.4): the one source for what the HUD draws, where the camera fits the mat,
# where the hand lays out and which screen points the click test may use. Pixels at the
# 1600 × 900 base size; scale by the viewport.
const BASE := Vector2(1600, 900)
const PANEL_LEFT := 300.0
const PANEL_RIGHT := 360.0
const PANEL_TOP := 44.0
const PANEL_BOTTOM := 176.0
## Gap between a panel and the screen edge.
const MARGIN := 8.0
## The chamfer, ~3 % of a card's shorter edge (22 px at 750 px).
const CHAMFER_RATIO := 22.0 / 750.0
# ---------------------------------------------------------------------------------------------
# Fonts
const DISPLAY_PATH := "res://assets/fonts/Orbitron.ttf"
const BODY_PATH := "res://assets/fonts/JetBrainsMono.ttf"
static var _fonts := {}
static var _theme: Theme
## Orbitron, for the logo, the menu and headings only: it is too wide for dense readouts.
static func display_font(weight := 700) -> Font:
return _font(DISPLAY_PATH, weight)
## JetBrains Mono, for every HUD string: the nearest shippable match to the cards' Consolas.
static func body_font(weight := 400) -> Font:
return _font(BODY_PATH, weight)
static func _font(path: String, weight: int) -> Font:
var key := "%s@%d" % [path, weight]
if not _fonts.has(key):
var base: FontFile = load(path)
var f := FontVariation.new()
f.base_font = base
f.variation_opentype = {"wght": weight}
_fonts[key] = f
return _fonts[key]
# ---------------------------------------------------------------------------------------------
# Boxes and the theme
## A chamfered box: `accent` border, `fill` inside, `width` px border, `glow` px of outer glow.
static func chamfer_box(accent: Color, fill := PANEL, width := 1.5, glow := 0.0, cut := 8.0) -> ChamferBox:
var b := ChamferBox.new(fill, accent, width, cut)
b.glow = glow
return b
## An emphasis chip: filled accent, dark text (set the label's color to BG), a glow.
static func chip_box(accent: Color, cut := 5.0) -> ChamferBox:
var b := ChamferBox.new(accent, accent.lightened(0.25), 1.0, cut)
b.glow = 6.0
b.glow_alpha = 0.3
b.content_margin_left = 7
b.content_margin_right = 7
b.content_margin_top = 2
b.content_margin_bottom = 2
return b
static func type_accent(kind: String) -> Color:
return TYPE_ACCENT.get(kind, ACCENT)
## The V/B/G/P class color of an Anomaly type, or the accent.
static func class_accent(type: String) -> Color:
return CLASS_ACCENT.get(type, ACCENT)
## The accent for a card def: its class for Anomalies, its kind otherwise.
static func card_accent(d: Dictionary) -> Color:
if d.get("kind", "") == "anomaly":
return class_accent(d.get("type", ""))
return type_accent(d.get("kind", ""))
## A Firewall's color at `level` out of `levels` (the rules' firewallCost size): amber to red.
static func firewall_color(level: int, levels: int) -> Color:
var k := 0.0 if levels <= 1 else clampf(float(level - 1) / (levels - 1), 0.0, 1.0)
return WARN.lerp(BAD, k)
## "#22d3ee" for BBCode color tags, which ignore the theme.
static func hex(c: Color) -> String:
return "#" + c.to_html(c.a < 1.0)
## The one Theme for every 2D screen.
static func theme() -> Theme:
if _theme != null:
return _theme
var t := Theme.new()
t.default_font = body_font()
t.default_font_size = 14
t.set_color("font_color", "Label", SCREEN)
t.set_color("default_color", "RichTextLabel", SCREEN)
t.set_font("normal_font", "RichTextLabel", body_font())
t.set_font("bold_font", "RichTextLabel", body_font(700))
t.set_font("mono_font", "RichTextLabel", body_font())
t.set_font("italics_font", "RichTextLabel", body_font(300))
t.set_stylebox("panel", "PanelContainer", chamfer_box(ACCENT_DK))
t.set_stylebox("panel", "Panel", chamfer_box(ACCENT_DK))
# Buttons: dim frame at rest, the accent on hover, filled when pressed.
var normal := chamfer_box(ACCENT_DK, PANEL_HI, 1.0, 0.0, 6.0)
normal.content_margin_left = 10
normal.content_margin_right = 10
t.set_stylebox("normal", "Button", normal)
t.set_stylebox("hover", "Button", normal.tinted(Color("#0c2730f0"), ACCENT))
t.set_stylebox("pressed", "Button", normal.tinted(Color(ACCENT, 0.35), ACCENT))
t.set_stylebox("disabled", "Button", normal.tinted(Color("#05080ac0"), Color("#16262b")))
t.set_stylebox("focus", "Button", StyleBoxEmpty.new())
t.set_color("font_color", "Button", SCREEN)
t.set_color("font_hover_color", "Button", Color.WHITE)
t.set_color("font_pressed_color", "Button", Color.WHITE)
t.set_color("font_disabled_color", "Button", DISABLED)
# A filled accent button for the main action.
t.add_type("PrimaryButton")
t.set_type_variation("PrimaryButton", "Button")
var prim := chamfer_box(ACCENT, Color(ACCENT, 0.16), 1.5, 6.0, 8.0)
prim.ticks = true
t.set_stylebox("normal", "PrimaryButton", prim)
var prim_hover := prim.tinted(Color(ACCENT, 0.3), ACCENT.lightened(0.3))
prim_hover.glow = 9.0
t.set_stylebox("hover", "PrimaryButton", prim_hover)
t.set_stylebox("pressed", "PrimaryButton", prim.tinted(Color(ACCENT, 0.55), Color.WHITE))
t.set_stylebox("disabled", "PrimaryButton", normal.tinted(Color("#05080ac0"), Color("#16262b")))
t.set_color("font_color", "PrimaryButton", ACCENT.lightened(0.35))
t.set_font("font", "PrimaryButton", body_font(700))
# Big menu buttons in the display face (BigButton: MenuButton is a built-in class).
t.add_type("BigButton")
t.set_type_variation("BigButton", "Button")
var menu := chamfer_box(ACCENT_DK, Color("#05080ad0"), 1.5, 0.0, 12.0)
menu.content_margin_left = 24
menu.content_margin_right = 24
menu.content_margin_top = 12
menu.content_margin_bottom = 12
t.set_stylebox("normal", "BigButton", menu)
var menu_hover := menu.tinted(Color(ACCENT, 0.16), ACCENT)
menu_hover.glow = 12.0
menu_hover.ticks = true
t.set_stylebox("hover", "BigButton", menu_hover)
t.set_stylebox("pressed", "BigButton", menu.tinted(Color(ACCENT, 0.4), Color.WHITE))
t.set_stylebox("disabled", "BigButton", menu.tinted(Color("#05080a90"), Color("#132227")))
t.set_font("font", "BigButton", display_font(600))
t.set_font_size("font_size", "BigButton", 20)
# Text styles.
t.add_type("Title")
t.set_type_variation("Title", "Label")
t.set_color("font_color", "Title", ACCENT)
t.set_font("font", "Title", body_font(700))
t.add_type("Heading")
t.set_type_variation("Heading", "Label")
t.set_color("font_color", "Heading", ACCENT)
t.set_font("font", "Heading", display_font(700))
t.set_font_size("font_size", "Heading", 18)
t.add_type("Muted")
t.set_type_variation("Muted", "Label")
t.set_color("font_color", "Muted", MUTED)
t.add_type("Micro")
t.set_type_variation("Micro", "Label")
t.set_color("font_color", "Micro", MUTED)
t.set_font_size("font_size", "Micro", 11)
# Inputs.
var field := chamfer_box(ACCENT_DK, Color("#03090bf0"), 1.0, 0.0, 5.0)
t.set_stylebox("normal", "LineEdit", field)
t.set_stylebox("focus", "LineEdit", field.tinted(Color("#03090bf0"), ACCENT))
t.set_color("font_color", "LineEdit", SCREEN)
t.set_color("caret_color", "LineEdit", ACCENT)
t.set_color("selection_color", "LineEdit", Color(ACCENT, 0.35))
t.set_stylebox("normal", "OptionButton", normal)
t.set_stylebox("hover", "OptionButton", normal.tinted(Color("#0c2730f0"), ACCENT))
t.set_stylebox("pressed", "OptionButton", normal.tinted(Color(ACCENT, 0.35), ACCENT))
t.set_stylebox("focus", "OptionButton", StyleBoxEmpty.new())
var popup := chamfer_box(ACCENT, Color("#05080af8"), 1.0, 0.0, 6.0)
t.set_stylebox("panel", "PopupMenu", popup)
t.set_stylebox("hover", "PopupMenu", chamfer_box(ACCENT, Color(ACCENT, 0.2), 0.0, 0.0, 4.0))
t.set_color("font_color", "PopupMenu", SCREEN)
t.set_color("font_hover_color", "PopupMenu", Color.WHITE)
t.set_font("font", "PopupMenu", body_font())
for state in ["normal", "hover", "pressed", "hover_pressed", "disabled"]:
t.set_stylebox(state, "CheckBox", StyleBoxEmpty.new())
t.set_stylebox("focus", "CheckBox", StyleBoxEmpty.new())
t.set_color("font_color", "CheckBox", SCREEN)
t.set_color("font_hover_color", "CheckBox", Color.WHITE)
t.set_color("font_pressed_color", "CheckBox", SCREEN)
t.set_color("font_hover_pressed_color", "CheckBox", Color.WHITE)
var track := chamfer_box(ACCENT_DK, Color("#03090b"), 1.0, 0.0, 3.0)
track.content_margin_top = 3
track.content_margin_bottom = 3
t.set_stylebox("slider", "HSlider", track)
var fill := chamfer_box(ACCENT, Color(ACCENT, 0.5), 0.0, 0.0, 3.0)
fill.content_margin_top = 3
fill.content_margin_bottom = 3
t.set_stylebox("grabber_area", "HSlider", fill)
t.set_stylebox("grabber_area_highlight", "HSlider", fill.tinted(Color(ACCENT, 0.75), ACCENT))
# Thin scrollbars in the chrome color.
var grab := chamfer_box(ACCENT_DK, Color(ACCENT_DK, 0.8), 0.0, 0.0, 2.0)
grab.set_content_margin_all(3)
for bar in ["VScrollBar", "HScrollBar"]:
var empty := StyleBoxEmpty.new()
empty.set_content_margin_all(3)
t.set_stylebox("scroll", bar, empty)
t.set_stylebox("grabber", bar, grab)
t.set_stylebox("grabber_highlight", bar, grab.tinted(Color(ACCENT, 0.8), ACCENT))
t.set_stylebox("grabber_pressed", bar, grab.tinted(ACCENT, ACCENT))
var tip := chamfer_box(ACCENT, Color("#05080af8"), 1.0, 0.0, 5.0)
t.set_stylebox("panel", "TooltipPanel", tip)
t.set_color("font_color", "TooltipLabel", SCREEN)
_theme = t
return t
# ---------------------------------------------------------------------------------------------
# Screen geometry
## The base-size scale for a viewport of size `vp`.
static func scale_of(vp: Vector2) -> Vector2:
return vp / BASE
## The screen rect the panels leave free for the table, in viewport pixels.
static func table_region(vp: Vector2, bottom := PANEL_BOTTOM) -> Rect2:
var s := scale_of(vp)
return Rect2(PANEL_LEFT * s.x, PANEL_TOP * s.y, vp.x - (PANEL_LEFT + PANEL_RIGHT) * s.x, vp.y - (PANEL_TOP + bottom) * s.y)

1
ui/style.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://drakm4raevia

201
ui/widgets.gd Normal file
View file

@ -0,0 +1,201 @@
class_name Widgets
## Small builders shared by the HUD and the menu, so both make buttons, labels and forms the same
## way from Style's theme.
const SCANLINES := preload("res://ui/scanlines.gdshader")
static func button(text: String, fn: Callable, variation := "") -> Button:
var b := Button.new()
b.text = text
b.pressed.connect(fn)
b.focus_mode = Control.FOCUS_NONE
if variation != "":
b.theme_type_variation = variation
return b
static func label(text: String, variation := "") -> Label:
var l := Label.new()
l.text = text
if variation != "":
l.theme_type_variation = variation
return l
static func title(text: String) -> Label:
return label(text, "Title")
static func heading(text: String) -> Label:
return label(text, "Heading")
static func muted(text: String) -> Label:
var l := label(text, "Muted")
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
return l
static func rich() -> RichTextLabel:
var rt := RichTextLabel.new()
rt.bbcode_enabled = true
rt.fit_content = true
rt.scroll_active = false
rt.selection_enabled = false
return rt
## A filled accent chip with dark text, e.g. "SALVAGE +4 Gb".
static func chip(text: String, accent := Style.ACCENT) -> PanelContainer:
var pc := PanelContainer.new()
pc.add_theme_stylebox_override("panel", Style.chip_box(accent))
var l := Label.new()
l.text = text
l.add_theme_color_override("font_color", Style.BG)
l.add_theme_font_override("font", Style.body_font(800))
l.add_theme_font_size_override("font_size", 12)
pc.add_child(l)
return pc
## A clickable chip: an accent-filled button.
static func chip_button(text: String, fn: Callable, accent := Style.ACCENT) -> Button:
var b := button(text, fn)
var box := Style.chip_box(accent)
b.add_theme_stylebox_override("normal", box)
var hover := box.tinted(accent.lightened(0.25), Color.WHITE)
hover.glow = 10.0
b.add_theme_stylebox_override("hover", hover)
b.add_theme_stylebox_override("pressed", box.tinted(Color.WHITE, Color.WHITE))
for c in ["font_color", "font_hover_color", "font_pressed_color"]:
b.add_theme_color_override(c, Style.BG)
b.add_theme_font_override("font", Style.body_font(800))
b.add_theme_font_size_override("font_size", 12)
return b
## The CRT lines over a panel: add as the panel's last child.
static func scanlines(strength := 0.16) -> ColorRect:
var r := ColorRect.new()
r.mouse_filter = Control.MOUSE_FILTER_IGNORE
r.set_anchors_preset(Control.PRESET_FULL_RECT)
var m := ShaderMaterial.new()
m.shader = SCANLINES
m.set_shader_parameter("strength", strength)
r.material = m
return r
## A small swatch in player `p`'s color and pattern: stripes for South, dots for North (the second
## cue beside the color, as on the tiles).
static func owner_badge(p: int, size := 14.0) -> Control:
var c := Control.new()
c.custom_minimum_size = Vector2(size, size)
c.mouse_filter = Control.MOUSE_FILTER_IGNORE
c.draw.connect(func():
var col: Color = Style.OWNER[p]
var r := Rect2(Vector2.ZERO, c.size)
c.draw_rect(r, Color(col, 0.18))
if p == 0:
var n := 4
for i in range(-n, n + 1):
var x := i * r.size.x / n * 0.75
c.draw_line(Vector2(x, r.size.y), Vector2(x + r.size.y, 0), col, 1.5, true)
else:
for yy in 3:
for xx in 3:
c.draw_circle(Vector2((xx + 0.5) * r.size.x / 3, (yy + 0.5) * r.size.y / 3), r.size.x / 10, col)
c.draw_rect(r, col, false, 1.0))
c.clip_contents = true
return c
# ---------------------------------------------------------------------------------------------
# Forms
## The new-game form into `box`: seed, side and bot style. `on_start` gets {seed, human, style}.
## With `on_cancel`, there's a Cancel button too.
static func start_form(box: Container, defaults: Dictionary, on_start: Callable, on_cancel := Callable()) -> void:
var grid := GridContainer.new()
grid.columns = 2
grid.add_theme_constant_override("h_separation", 14)
grid.add_theme_constant_override("v_separation", 8)
box.add_child(grid)
var seed_edit := LineEdit.new()
seed_edit.text = str(defaults.get("seed", randi_range(1, 999999)))
seed_edit.custom_minimum_size = Vector2(220, 0)
grid.add_child(label("SEED", "Muted"))
grid.add_child(seed_edit)
var side := OptionButton.new()
side.add_item("South (S1)")
side.add_item("North (S2)")
side.selected = defaults.get("human", 0)
side.focus_mode = Control.FOCUS_NONE
grid.add_child(label("YOU PLAY", "Muted"))
grid.add_child(side)
var style := OptionButton.new()
style.focus_mode = Control.FOCUS_NONE
var styles: Dictionary = GreedyBot.STYLES
var keys := styles.keys()
for k in keys:
style.add_item(styles[k].label)
style.selected = maxi(0, keys.find(defaults.get("style", "greedy")))
grid.add_child(label("OPPONENT", "Muted"))
grid.add_child(style)
var about := muted(styles[keys[style.selected]].about)
box.add_child(about)
style.item_selected.connect(func(i): about.text = styles[keys[i]].about)
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 10)
row.add_child(button("DEAL ▸", func():
on_start.call({"seed": int(seed_edit.text) if seed_edit.text.is_valid_int() else randi_range(1, 999999),
"human": side.selected, "style": keys[style.selected]}), "PrimaryButton"))
if on_cancel.is_valid():
row.add_child(button("Cancel", on_cancel))
box.add_child(row)
## The settings form into `box`. `on_done` gets the new settings.
static func settings_form(box: Container, settings: Dictionary, on_done: Callable) -> void:
box.add_child(label("WHEN THE GAME STOPS FOR YOU TO RESPOND", "Muted"))
var stops := OptionButton.new()
stops.focus_mode = Control.FOCUS_NONE
var stop_ids := ["combat", "all", "never"]
for text in ["In combat only", "Every opponent move", "Never"]:
stops.add_item(text)
stops.selected = maxi(0, stop_ids.find(settings.stops))
box.add_child(stops)
box.add_child(muted("Hold Shift to stop at the next window anyway."))
var skip := CheckBox.new()
skip.text = "Skip steps where End and Salvage are the only moves"
skip.button_pressed = settings.autoSkip
skip.focus_mode = Control.FOCUS_NONE
box.add_child(skip)
var check := CheckBox.new()
check.text = "Check the rule invariants after every move"
check.button_pressed = settings.checkInvariants
check.focus_mode = Control.FOCUS_NONE
box.add_child(check)
box.add_child(label("ANIMATION", "Muted"))
var anim := OptionButton.new()
anim.focus_mode = Control.FOCUS_NONE
var anim_ids: Array = GameSettings.ANIM_SPEEDS.keys()
for k in anim_ids:
anim.add_item(GameSettings.ANIM_SPEEDS[k].label)
anim.selected = maxi(0, anim_ids.find(settings.get("anim", "normal")))
box.add_child(anim)
var speed_label := label("")
box.add_child(speed_label)
var speed := HSlider.new()
speed.min_value = 0.0
speed.max_value = 1.5
speed.step = 0.05
speed.value = settings.botDelay
var show_speed := func(x): speed_label.text = "Bot pause between moves: %.2fs" % x
show_speed.call(speed.value)
speed.value_changed.connect(show_speed)
box.add_child(speed)
box.add_child(button("Done", func():
on_done.call({"stops": stop_ids[stops.selected], "autoSkip": skip.button_pressed,
"checkInvariants": check.button_pressed, "botDelay": speed.value, "anim": anim_ids[anim.selected]}), "PrimaryButton"))

1
ui/widgets.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://ctlo6e1kgdksi