class_name ResourceHud extends Control ## Top-right materials readout: what the supply shed holds, and what the scarecrow carries in ## its pouch (with its capacity). A line flashes when its numbers change. var campaign: CampaignController ## Set by FarmSim: shows how many structures stand. var structures: StructureSystem var _shed: RichTextLabel var _pouch: RichTextLabel var _built: RichTextLabel var _last_shed := "" var _last_pouch := "" var _flash_shed: float = 0.0 var _flash_pouch: float = 0.0 func setup(p_campaign: CampaignController) -> void: campaign = p_campaign func _ready() -> void: set_anchors_preset(Control.PRESET_FULL_RECT) mouse_filter = Control.MOUSE_FILTER_IGNORE _shed = _line(20.0) _pouch = _line(52.0) _built = _line(84.0) func _process(delta: float) -> void: if campaign == null: return var r := campaign.state.resources var shed := "Shed %s" % _amounts(r.shed) var pouch := "Pouch %d/%d %s" % [r.pouch_total(), r.pouch_capacity, _amounts(r.pouch) if r.pouch_total() > 0 else "empty"] if shed != _last_shed: _last_shed = shed _shed.text = shed _flash_shed = 1.0 if pouch != _last_pouch: _last_pouch = pouch _pouch.text = pouch _flash_pouch = 1.0 _flash_shed = maxf(_flash_shed - delta * 2.0, 0.0) _flash_pouch = maxf(_flash_pouch - delta * 2.0, 0.0) if structures != null: _built.text = "Built %d structures [B] build" % structures.count() _shed.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_shed) _pouch.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_pouch) func _amounts(d: Dictionary) -> String: var parts: Array[String] = [] for m in ResourceStore.MATERIALS: parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d.get(m, 0))]) return " ".join(parts) func _line(y: float) -> RichTextLabel: var l := RichTextLabel.new() l.bbcode_enabled = true l.fit_content = true l.scroll_active = false l.autowrap_mode = TextServer.AUTOWRAP_OFF l.mouse_filter = Control.MOUSE_FILTER_IGNORE l.add_theme_font_size_override("normal_font_size", 22) l.add_theme_color_override("font_outline_color", Color.BLACK) l.add_theme_constant_override("outline_size", 6) l.set_anchors_preset(Control.PRESET_TOP_RIGHT) l.offset_left = -520.0 l.offset_right = -24.0 l.offset_top = y add_child(l) return l