harvest/game/scripts/build_hud.gd
Forrest fa7f67fe04 Task #16: per-player pouch in co-op
Each scarecrow carries its own pouch (ResourceStore.pouches by avatar
slot; slot 0 is the solo player / host, `pouch` stays slot 0's), with one
shared pouch_capacity so a Bigger pouch grows both. The shed stays shared.

- Gathering, the shed drop-off, repair, upgrade-in-place, patching,
  building and buying all act on the acting avatar's slot. The host pays
  the partner's "place" and "buy" requests from P2's pouch and the shed.
- The partner's build mode, build hotbar, shop menus and materials HUD
  check affordability against P2's pouch (FarmSim.set_local).
- Alien Goop goes to the killer's pouch: FarmSim sets
  EnemySystem.attacker around each avatar's combat step and shots carry
  their shooter's slot; bomb/turret kills go to the nearest scarecrow.
  The replica no longer rolls goop locally.
- When the partner leaves, their pouch goes into the shed (and is named
  in the toast); a co-op save continued alone banks P2's pouch at morning.
- FarmState.VERSION 7 (resources.partner_pouch) with a v6 migration;
  CoopSession.PROTOCOL 4.
- Tests: per-slot store rules, v6 save migration, and test_coop cases for
  separate gathering, no cross-banking in the shed, own-pouch paying,
  shared capacity, goop credit and leaving. test_coop's crowd case now
  resets the loopback's drop counter so earlier traffic can't change
  which messages it loses.
- Docs: COOP.md and RULES.md no longer say the pouch is shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 13:06:25 -04:00

77 lines
2.6 KiB
GDScript

class_name BuildHud
extends Control
## The build hotbar, shown in build mode: one slot per buildable with its key, name, and cost
## (red when the builder can't afford it from their own pouch and the shed), the selected one
## highlighted, the controls, and how many structures stand on the farm.
const SLOT := Vector2(230.0, 76.0)
const GAP := 12.0
var build: BuildMode
var campaign: CampaignController
var _names: Array[Label] = []
var _costs: Array[Label] = []
var _help: Label
func setup(p_build: BuildMode, p_campaign: CampaignController) -> void:
build = p_build
campaign = p_campaign
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT)
mouse_filter = Control.MOUSE_FILTER_IGNORE
for i in StructureSystem.ORDER.size():
_names.append(_label(22))
_costs.append(_label(18))
_help = _label(19)
func _process(_delta: float) -> void:
visible = build != null and build.active
if not visible:
return
var r := campaign.state.resources
var slot := build.kit.slot if build.kit != null else 0
var origin := _origin()
for i in StructureSystem.ORDER.size():
var t: String = StructureSystem.ORDER[i]
var cost: Dictionary = campaign.config.costs.get(t, {})
var pos := origin + Vector2(i * (SLOT.x + GAP), 0.0)
_names[i].text = "%d %s" % [i + 1, StructureSystem.NAMES[t]]
_names[i].position = pos + Vector2(12.0, 8.0)
_costs[i].text = ResourceStore.describe(cost)
_costs[i].position = pos + Vector2(12.0, 42.0)
_costs[i].add_theme_color_override("font_color", Color(0.9, 0.95, 0.9) if r.can_afford(cost, slot) else Color(1.0, 0.45, 0.4))
_help.text = "Build mode · LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave · %d built" % \
build.structures.count()
_help.position = origin + Vector2(0.0, -34.0)
queue_redraw()
func _draw() -> void:
if build == null or not build.active:
return
var origin := _origin()
for i in StructureSystem.ORDER.size():
var rect := Rect2(origin + Vector2(i * (SLOT.x + GAP), 0.0), SLOT)
draw_rect(rect, Color(0.0, 0.0, 0.0, 0.55))
draw_rect(rect, Color(1.0, 0.9, 0.4) if i == build.selected else Color(1.0, 1.0, 1.0, 0.25), false, 3.0 if i == build.selected else 1.5)
func _origin() -> Vector2:
var n := StructureSystem.ORDER.size()
var width := n * SLOT.x + (n - 1) * GAP
return Vector2((size.x - width) * 0.5, size.y - SLOT.y - 28.0)
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