updates
This commit is contained in:
parent
276d43613d
commit
4298caf5cb
552 changed files with 42990 additions and 776 deletions
89
game/scripts/asset_hud.gd
Normal file
89
game/scripts/asset_hud.gd
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
class_name AssetHud
|
||||
extends Control
|
||||
## Top-center readout of what's left to protect: "Crops 28/30 · Animals 7/8 · Supplies 23" (the
|
||||
## shed's stock plus any sacks still on the farm), each in its category's color. A count flashes
|
||||
## red when it drops and green when it rises. Categories not in play are left out.
|
||||
|
||||
const FLASH_TIME := 1.2
|
||||
const LOSS := Color(1.0, 0.3, 0.25)
|
||||
const GAIN := Color(0.5, 1.0, 0.45)
|
||||
|
||||
var campaign: CampaignController
|
||||
|
||||
var _box: HBoxContainer
|
||||
var _panel: PanelContainer
|
||||
var _labels: Array[Label] = []
|
||||
var _last := PackedInt32Array([-1, -1, -1])
|
||||
var _flash := PackedFloat32Array([0.0, 0.0, 0.0])
|
||||
var _flash_color: Array[Color] = [Color.WHITE, Color.WHITE, Color.WHITE]
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
_last = _counts()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_panel = PanelContainer.new()
|
||||
var bg := StyleBoxFlat.new()
|
||||
bg.bg_color = Color(0.0, 0.0, 0.0, 0.42)
|
||||
bg.content_margin_left = 18.0
|
||||
bg.content_margin_right = 18.0
|
||||
bg.content_margin_top = 4.0
|
||||
bg.content_margin_bottom = 4.0
|
||||
_panel.add_theme_stylebox_override("panel", bg)
|
||||
_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_panel)
|
||||
_box = HBoxContainer.new()
|
||||
_box.add_theme_constant_override("separation", 28)
|
||||
_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_panel.add_child(_box)
|
||||
for c in 3:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", 24)
|
||||
l.add_theme_color_override("font_color", LootSystem.CATEGORY_COLORS[c])
|
||||
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
|
||||
_box.add_child(l)
|
||||
_labels.append(l)
|
||||
|
||||
|
||||
## "Crops 28/30 · Animals 7/8 · Supplies 23", as the HUD shows it (also used by tests).
|
||||
func describe() -> String:
|
||||
var parts: Array[String] = []
|
||||
for l in _labels:
|
||||
if l.visible:
|
||||
parts.append(l.text)
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var s := campaign.state
|
||||
var now := _counts()
|
||||
var texts := ["Crops %d/%d" % [s.crops, s.crops_total], "Animals %d/%d" % [s.animals, s.animals_total],
|
||||
"Supplies %d" % s.supplies]
|
||||
var in_play := [s.crops_total > 0, s.animals_total > 0, s.supplies_total > 0]
|
||||
for c in 3:
|
||||
var l := _labels[c]
|
||||
l.visible = in_play[c]
|
||||
l.text = texts[c]
|
||||
if _last[c] >= 0 and now[c] != _last[c]:
|
||||
_flash[c] = FLASH_TIME
|
||||
_flash_color[c] = LOSS if now[c] < _last[c] else GAIN
|
||||
_last[c] = now[c]
|
||||
_flash[c] = maxf(_flash[c] - delta, 0.0)
|
||||
var k := _flash[c] / FLASH_TIME
|
||||
var pulse := (0.5 + 0.5 * sin(_flash[c] * 18.0)) * k
|
||||
l.modulate = Color.WHITE.lerp(_flash_color[c] * 1.4, pulse)
|
||||
_panel.reset_size()
|
||||
_panel.position = Vector2((size.x - _panel.size.x) * 0.5, 14.0)
|
||||
|
||||
|
||||
func _counts() -> PackedInt32Array:
|
||||
var s := campaign.state
|
||||
return PackedInt32Array([s.crops, s.animals, s.supplies])
|
||||
Loading…
Add table
Add a link
Reference in a new issue