Adds a second UpgradePanel instance (shop "shed") at the Supply Shed's new
ShedCounter node, opened by interact like the Workbench. corn_shooter and
pumpkin_bomb move there ("shop": "shed" in GameConfig.upgrades); the
Workbench's panel (shop "workbench", the default) keeps rapid_fire,
heavy_seeds, and the rest, with "requires" still crossing shops. Co-op buys
go through the same ["buy", id] host gate; a shed_requested signal mirrors
workbench_requested so the partner's own shed panel opens. The shed's
walk-in pouch deposit is unaffected (no interact, not gated by the
counter's reach).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
152 lines
5.1 KiB
GDScript
152 lines
5.1 KiB
GDScript
class_name UpgradePanel
|
|
extends CenterContainer
|
|
## A shop's menu (Upgrades): one row per upgrade or item sold by this instance's shop (shop,
|
|
## Upgrades.shop_of), by track, with what it does and what it costs. A done one says so; one you
|
|
## can't afford says what's missing. The work area's instance (shop "workbench": player/weapon
|
|
## stat and buildable upgrades) opens with interact at the workbench by day; the supply shed's
|
|
## (shop "shed": weapons and other purchasable items) opens with interact at the shed's counter by
|
|
## day (Interactions). Buy with a click, or the arrows / d-pad and Enter / A. Close it with Close,
|
|
## Escape / B, interact again, by walking off, or at nightfall. The scarecrow stands still and
|
|
## can't shoot while either is open.
|
|
|
|
signal message(text: String, color: Color)
|
|
signal bought(id: String)
|
|
|
|
var campaign: CampaignController
|
|
var structures: StructureSystem
|
|
var player: PlayerCharacter
|
|
var is_open := false
|
|
## Which shop this instance lists ("workbench" or "shed"); set by setup().
|
|
var shop := "workbench"
|
|
## Co-op partner: ask the host to buy (upgrade id); the result comes back as a message.
|
|
var buy_request: Callable
|
|
|
|
var _rows := {} # upgrade id -> Button
|
|
var _title: Label
|
|
var _close: Button
|
|
|
|
|
|
func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_player: PlayerCharacter, p_shop: String = "workbench") -> void:
|
|
campaign = p_campaign
|
|
structures = p_structures
|
|
player = p_player
|
|
shop = p_shop
|
|
var box := get_node("Panel/Margin/Box") as VBoxContainer
|
|
var track := ""
|
|
for id in Upgrades.ORDER:
|
|
var u: Dictionary = campaign.config.upgrades.get(id, {})
|
|
if u.is_empty() or Upgrades.shop_of(campaign.config, id) != shop:
|
|
continue
|
|
if String(u.get("track", "")) != track:
|
|
track = String(u.get("track", ""))
|
|
var head := Label.new()
|
|
head.text = track
|
|
head.add_theme_font_size_override("font_size", 20)
|
|
head.add_theme_color_override("font_color", Color(0.75, 0.85, 0.75))
|
|
box.add_child(head)
|
|
var b := Button.new()
|
|
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
b.custom_minimum_size = Vector2(720.0, 44.0)
|
|
b.add_theme_font_size_override("font_size", 20)
|
|
b.pressed.connect(func() -> void: _buy(id))
|
|
box.add_child(b)
|
|
_rows[id] = b
|
|
_close = Button.new()
|
|
_close.text = "Close"
|
|
_close.custom_minimum_size = Vector2(200.0, 48.0)
|
|
_close.add_theme_font_size_override("font_size", 22)
|
|
_close.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
|
_close.pressed.connect(close)
|
|
box.add_child(_close)
|
|
|
|
|
|
func _ready() -> void:
|
|
set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
var panel := PanelContainer.new()
|
|
panel.name = "Panel"
|
|
panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
|
add_child(panel)
|
|
var margin := MarginContainer.new()
|
|
margin.name = "Margin"
|
|
for side in ["left", "right", "top", "bottom"]:
|
|
margin.add_theme_constant_override("margin_" + side, 24)
|
|
panel.add_child(margin)
|
|
var box := VBoxContainer.new()
|
|
box.name = "Box"
|
|
box.add_theme_constant_override("separation", 6)
|
|
margin.add_child(box)
|
|
_title = Label.new()
|
|
_title.add_theme_font_size_override("font_size", 32)
|
|
box.add_child(_title)
|
|
visible = false
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
|
|
|
|
func open() -> void:
|
|
if is_open:
|
|
return
|
|
is_open = true
|
|
visible = true
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
player.start_channel(&"Idle_A")
|
|
refresh()
|
|
var first: Button = _close
|
|
for id in Upgrades.ORDER:
|
|
if _rows.has(id) and not (_rows[id] as Button).disabled:
|
|
first = _rows[id]
|
|
break
|
|
first.grab_focus.call_deferred()
|
|
|
|
|
|
func close() -> void:
|
|
if not is_open:
|
|
return
|
|
is_open = false
|
|
visible = false
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
player.stop_channel()
|
|
|
|
|
|
## Rewrites every row for what's owned and affordable now.
|
|
func refresh() -> void:
|
|
var cfg := campaign.config
|
|
var s := campaign.state
|
|
var done := 0
|
|
for id: String in _rows:
|
|
var u: Dictionary = cfg.upgrades[id]
|
|
var b := _rows[id] as Button
|
|
var why := Upgrades.blocker(campaign, id)
|
|
if Upgrades.owned(s, id):
|
|
done += 1
|
|
if not Upgrades.revealed(s, cfg, id):
|
|
# Hidden: no name, description, or cost until its reveal condition is met.
|
|
b.text = "?"
|
|
b.disabled = true
|
|
continue
|
|
var price := "Done" if Upgrades.owned(s, id) else ResourceStore.describe(Upgrades.cost(cfg, id))
|
|
b.text = "%s — %s (%s)" % [u["name"], u["text"], price]
|
|
if why != "" and why != "Done":
|
|
b.text += " %s" % why
|
|
b.disabled = why != ""
|
|
var place := "Upgrades at the work area" if shop == "workbench" else "Shop at the supply shed"
|
|
_title.text = "%s (%d of %d done)" % [place, done, _rows.size()]
|
|
|
|
|
|
func _buy(id: String) -> void:
|
|
if buy_request.is_valid():
|
|
buy_request.call(id)
|
|
return
|
|
var was := Upgrades.owned(campaign.state, id)
|
|
var text := Upgrades.buy(campaign, id, structures)
|
|
if not was and Upgrades.owned(campaign.state, id):
|
|
bought.emit(id)
|
|
message.emit(text, Color(0.85, 0.75, 1.0) if text.contains("done:") else Color(1.0, 0.8, 0.5))
|
|
refresh()
|
|
if (_rows[id] as Button).has_focus() and (_rows[id] as Button).disabled:
|
|
_close.grab_focus()
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if is_open and event.is_action_pressed("ui_cancel"):
|
|
close()
|
|
get_viewport().set_input_as_handled()
|