class_name ScarecrowHud extends Control ## Bottom-left status for the scarecrow: health as pips, the fear ability as a circle that ## sweeps full while it cools down and flashes when it is ready again, the patch hint with its ## progress, and once the Sprint upgrade is bought a sprint line (ready, seconds left, or ## recharging); plus a red screen tint when the scarecrow is hit. Bottom-right, the weapons: ## the main ones by number, the one in hand marked, and how to switch; under them the off-hand ## (pumpkin bombs, marked when one is ready, else its recharge) and its button. The ones not ## bought yet are greyed out (with where to buy them: Upgrades.shop_of). const PIP := Vector2(22.0, 16.0) const PIP_GAP := 5.0 const FEAR_RADIUS := 26.0 ## Extra height of the panel for the sprint line. const SPRINT_ROW := 30.0 ## The weapon panel, from the bottom-right corner, its rows, and where its off-hand part starts. const WEAPONS := Rect2(-340.0, -220.0, 304.0, 194.0) const WEAPON_ROW := 30.0 const OFFHAND_TOP := 122.0 var kit: Scarecrow ## This machine's scarecrow's weapons. var combat: ScarecrowCombat var campaign: CampaignController ## The health line's name ("Scarecrow"; in co-op "P1 Scarecrow" / "P2 Scarecrow"). var label := "Scarecrow" var _tint: ColorRect var _hp_label: Label var _fear_label: Label var _patch_label: Label var _sprint_label: Label var _weapon_title: Label var _weapon_rows: Array[Label] = [] var _weapon_hint: Label var _offhand_title: Label var _offhand_rows: Array[Label] = [] var _hit: float = 0.0 var _ready_flash: float = 0.0 func setup(p_kit: Scarecrow, p_campaign: CampaignController, p_combat: ScarecrowCombat = null) -> void: campaign = p_campaign retarget(p_kit, p_combat) ## Shows another kit (co-op: the partner's game shows player 2's). func retarget(p_kit: Scarecrow, p_combat: ScarecrowCombat = null) -> void: combat = p_combat if kit != null: kit.damaged.disconnect(_on_damaged) kit.fear_ready.disconnect(_on_fear_ready) kit = p_kit kit.damaged.connect(_on_damaged) kit.fear_ready.connect(_on_fear_ready) func _on_damaged(_hp: int) -> void: _hit = 1.0 func _on_fear_ready() -> void: _ready_flash = 1.0 func _ready() -> void: set_anchors_preset(Control.PRESET_FULL_RECT) mouse_filter = Control.MOUSE_FILTER_IGNORE _tint = ColorRect.new() _tint.set_anchors_preset(Control.PRESET_FULL_RECT) _tint.color = Color(0.85, 0.05, 0.0, 0.0) _tint.mouse_filter = Control.MOUSE_FILTER_IGNORE add_child(_tint) _hp_label = _label(22) _fear_label = _label(20) _patch_label = _label(20) _sprint_label = _label(20) _weapon_title = _label(18) _weapon_title.text = "Main weapon" for i in ScarecrowCombat.MAIN_WEAPONS.size(): _weapon_rows.append(_label(20)) _weapon_hint = _label(16) _weapon_hint.text = "Switch: Tab / 1-2 / d-pad down" _offhand_title = _label(18) _offhand_title.text = "Off-hand right mouse / LT" for i in ScarecrowCombat.OFFHAND_WEAPONS.size(): _offhand_rows.append(_label(20)) func _process(delta: float) -> void: _hit = maxf(_hit - delta * 2.5, 0.0) _ready_flash = maxf(_ready_flash - delta * 2.0, 0.0) _tint.color.a = 0.22 * _hit if kit == null: return var base := _base() var s := campaign.state _hp_label.text = "%s %d/%d" % [label, kit.hp(), kit.max_hp()] _hp_label.position = base + Vector2(0.0, -34.0) if not kit.alive: _fear_label.text = "Fear" elif kit.fear_left == 0.0: _fear_label.text = "Fear Q / LB" else: _fear_label.text = "Fear %.0f s" % ceilf(kit.fear_left) _fear_label.position = base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 34.0) if not kit.alive: _patch_label.text = "Patch" elif kit.patching: _patch_label.text = "Patching up..." elif kit.hp() >= kit.max_hp(): _patch_label.text = "Patch (full health)" else: _patch_label.text = "Patch hold F / Y (%s)" % ResourceStore.describe(kit.config.costs.get("patch", {})) _patch_label.position = base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 62.0) var body := kit.player _sprint_label.visible = _sprint_shown() if _sprint_label.visible: if not kit.alive: _sprint_label.text = "Sprint" elif body.sprinting: _sprint_label.text = "Sprinting %.1f s" % body.sprint_left elif body.sprint_recharge > 0.0: _sprint_label.text = "Sprint %.0f s" % ceilf(body.sprint_recharge) else: _sprint_label.text = "Sprint hold Shift / L3" _sprint_label.position = base + Vector2(0.0, 100.0) _update_weapons() queue_redraw() func _update_weapons() -> void: var shown := combat != null for l: Label in [_weapon_title, _weapon_hint, _offhand_title] + _weapon_rows + _offhand_rows: l.visible = shown if not shown: return var at := _weapons_rect().position _weapon_title.position = at + Vector2(12.0, 6.0) for k in _weapon_rows.size(): var w := ScarecrowCombat.MAIN_WEAPONS[k] _weapon_row(_weapon_rows[k], "%d %s" % [k + 1, ScarecrowCombat.WEAPON_NAMES[w]], w, w == combat.weapon) _weapon_rows[k].position = at + Vector2(30.0, 30.0 + k * WEAPON_ROW) _weapon_hint.position = at + Vector2(12.0, 30.0 + _weapon_rows.size() * WEAPON_ROW + 2.0) _offhand_title.position = at + Vector2(12.0, OFFHAND_TOP + 6.0) for k in _offhand_rows.size(): var w := ScarecrowCombat.OFFHAND_WEAPONS[k] var text := ScarecrowCombat.WEAPON_NAMES[w] if w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.owns(w) and combat.bomb_left > 0.0: text += " %.0f s" % ceilf(combat.bomb_left) _weapon_row(_offhand_rows[k], text, w, _offhand_lit(w)) _offhand_rows[k].position = at + Vector2(30.0, OFFHAND_TOP + 30.0 + k * WEAPON_ROW) ## A weapon's row: greyed out until it's bought, gold when it's in hand (lit). func _weapon_row(l: Label, text: String, w: int, lit: bool) -> void: var color := Color(0.95, 0.95, 0.95) if not combat.owns(w): var shop := Upgrades.shop_of(campaign.config, ScarecrowCombat.WEAPON_IDS[w]) if campaign != null else "workbench" text += " (%s)" % ("supply shed" if shop == "shed" else "workbench") color = Color(0.55, 0.55, 0.55) elif lit: color = Color(1.0, 0.85, 0.3) l.text = text l.add_theme_color_override("font_color", color) ## Whether the off-hand weapon is in the off-hand and ready (a pumpkin bomb not recharging). func _offhand_lit(w: int) -> bool: return w == combat.offhand and not (w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0) func _weapons_rect() -> Rect2: return Rect2(size + WEAPONS.position, WEAPONS.size) func _draw() -> void: if kit == null: return var base := _base() var s := campaign.state var height := 146.0 + (SPRINT_ROW if _sprint_shown() else 0.0) draw_rect(Rect2(base - Vector2(14.0, 46.0), Vector2(340.0, height)), Color(0.0, 0.0, 0.0, 0.42)) var frac := float(kit.hp()) / float(maxi(kit.max_hp(), 1)) var full := Color(0.45, 0.9, 0.35) if frac > 0.5 else (Color(1.0, 0.8, 0.2) if frac > 0.25 else Color(1.0, 0.3, 0.2)) full = full.lerp(Color.WHITE, _hit * 0.6) for i in kit.max_hp(): var r := Rect2(base + Vector2(i * (PIP.x + PIP_GAP), 0.0), PIP) draw_rect(r, full if i < kit.hp() else Color(0.15, 0.15, 0.15, 0.8)) draw_rect(r, Color(0.0, 0.0, 0.0, 0.9), false, 2.0) # Fear: dark disc, a sweep that fills while cooling down, bright when ready. var c := base + Vector2(FEAR_RADIUS, 32.0 + FEAR_RADIUS) var ready := kit.fear_left == 0.0 and kit.alive draw_circle(c, FEAR_RADIUS, Color(0.08, 0.1, 0.14, 0.9)) if ready: draw_circle(c, FEAR_RADIUS - 5.0, Color(0.55, 0.85, 1.0).lerp(Color.WHITE, _ready_flash)) else: draw_arc(c, FEAR_RADIUS - 8.0, -PI * 0.5, -PI * 0.5 + TAU * kit.fear_charge(), 48, Color(0.4, 0.6, 0.75), 9.0) draw_arc(c, FEAR_RADIUS + 3.0 + _ready_flash * 10.0, 0.0, TAU, 48, Color(1.0, 1.0, 1.0, 0.25 + 0.75 * _ready_flash), 2.5) if combat != null: var w := _weapons_rect() draw_rect(w, Color(0.0, 0.0, 0.0, 0.42)) _draw_lit_row(w, 32.0 + ScarecrowCombat.MAIN_WEAPONS.find(combat.weapon) * WEAPON_ROW) var off := ScarecrowCombat.OFFHAND_WEAPONS.find(combat.offhand) if off >= 0 and _offhand_lit(combat.offhand): _draw_lit_row(w, OFFHAND_TOP + 32.0 + off * WEAPON_ROW) if kit.patching: var bar := Rect2(base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 92.0), Vector2(210.0, 8.0)) draw_rect(bar, Color(0.1, 0.1, 0.1, 0.9)) draw_rect(Rect2(bar.position, Vector2(bar.size.x * kit.patch_elapsed / kit.config.patch_time, bar.size.y)), Color(0.45, 1.0, 0.4)) ## The marked row of the weapon panel w, top pixels down. func _draw_lit_row(w: Rect2, top: float) -> void: var row := Rect2(w.position + Vector2(6.0, top), Vector2(w.size.x - 12.0, WEAPON_ROW - 2.0)) draw_rect(row, Color(1.0, 0.85, 0.3, 0.18)) draw_rect(Rect2(row.position, Vector2(4.0, row.size.y)), Color(1.0, 0.85, 0.3)) func _base() -> Vector2: return Vector2(36.0, size.y - 126.0 - (SPRINT_ROW if _sprint_shown() else 0.0)) func _sprint_shown() -> bool: return kit != null and kit.player != null and kit.player.can_sprint() func _label(font_size: int) -> Label: var l := Label.new() l.add_theme_font_size_override("font_size", font_size) l.add_theme_color_override("font_outline_color", Color.BLACK) l.add_theme_constant_override("outline_size", 6) l.mouse_filter = Control.MOUSE_FILTER_IGNORE add_child(l) return l