UI and other changes
This commit is contained in:
parent
87b5c11fcf
commit
215e24e246
79 changed files with 70023 additions and 2201 deletions
|
|
@ -1,79 +1,111 @@
|
|||
class_name ResourceHud
|
||||
extends Control
|
||||
## Top-right materials readout: what the supply shed holds, and what this machine's scarecrow
|
||||
## carries in its own pouch (with its capacity). A line flashes when its numbers change.
|
||||
## Bottom-left backpack, hand-drawn (Sketch): this machine's scarecrow's pouch, "used/capacity"
|
||||
## beside it, and a red dot once something new has gone into it since it was last opened (gone
|
||||
## again when the pouch is emptied). The pouch action (I / R3) opens the pouch panel over it, and
|
||||
## closes it again: each material carried, and how much of each the supply shed holds.
|
||||
|
||||
## The backpack icon, from the screen's bottom-left corner.
|
||||
const ICON := Rect2(26.0, -136.0, 108.0, 108.0)
|
||||
const PANEL_WIDTH := 410.0
|
||||
const ROW := 46.0
|
||||
const DOT := Color(0.92, 0.12, 0.1)
|
||||
const SHED := Color(1.0, 0.9, 0.62)
|
||||
|
||||
var campaign: CampaignController
|
||||
## The avatar slot whose pouch is shown (FarmSim.set_local: the partner's machine shows P2's).
|
||||
var slot: int = 0
|
||||
## The pouch panel is open.
|
||||
var open := false
|
||||
## Something went into the pouch since it was last opened.
|
||||
var new_items := false
|
||||
|
||||
## 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
|
||||
var _last := {}
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
_last = campaign.state.resources.pouch_of(slot).duplicate()
|
||||
|
||||
|
||||
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:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if campaign != null and is_visible_in_tree() and event.is_action_pressed("pouch", false):
|
||||
toggle()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func toggle() -> void:
|
||||
open = not open
|
||||
if open:
|
||||
new_items = false
|
||||
|
||||
|
||||
## "6/15": what the pouch holds, of what it can.
|
||||
func count_text() -> String:
|
||||
var r := campaign.state.resources
|
||||
return "%d/%d" % [r.pouch_total(slot), r.pouch_capacity]
|
||||
|
||||
|
||||
## The pouch panel's rows: {material, pouch, shed}, one per material (ResourceStore.MATERIALS).
|
||||
func rows() -> Array[Dictionary]:
|
||||
var out: Array[Dictionary] = []
|
||||
var r := campaign.state.resources
|
||||
var p := r.pouch_of(slot)
|
||||
for m in ResourceStore.MATERIALS:
|
||||
out.append({"material": m, "pouch": int(p.get(m, 0)), "shed": int(r.shed.get(m, 0))})
|
||||
return out
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var r := campaign.state.resources
|
||||
var shed := "Shed %s" % _amounts(r.shed)
|
||||
var total := r.pouch_total(slot)
|
||||
var pouch := "Pouch %d/%d %s" % [total, r.pouch_capacity, _amounts(r.pouch_of(slot)) if 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] = []
|
||||
var p := r.pouch_of(slot)
|
||||
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)
|
||||
if int(p.get(m, 0)) > int(_last.get(m, 0)) and not open:
|
||||
new_items = true
|
||||
_last = p.duplicate()
|
||||
if r.pouch_total(slot) == 0:
|
||||
new_items = false
|
||||
queue_redraw()
|
||||
|
||||
|
||||
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
|
||||
func _draw() -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var icon := Rect2(Vector2(ICON.position.x, size.y + ICON.position.y), ICON.size)
|
||||
Sketch.icon(self, "backpack", icon)
|
||||
if new_items:
|
||||
var at := icon.position + Vector2(icon.size.x - 16.0, 16.0)
|
||||
draw_colored_polygon(Sketch.blob(at, 11.0, 11.0, 401.0, 0.04, 20), DOT)
|
||||
Sketch.circle(self, at, 11.5, Sketch.INK, 2.0, 402.0)
|
||||
Sketch.text(self, Vector2(icon.end.x + 4.0, icon.get_center().y - 18.0), count_text(), 42)
|
||||
if open:
|
||||
_draw_panel(icon)
|
||||
|
||||
|
||||
func _draw_panel(icon: Rect2) -> void:
|
||||
var list := rows()
|
||||
var height := 52.0 + list.size() * ROW + 12.0
|
||||
var r := Rect2(Vector2(icon.position.x - 4.0, icon.position.y - 14.0 - height), Vector2(PANEL_WIDTH, height))
|
||||
Sketch.panel(self, r, 411.0)
|
||||
var pouch_x := r.position.x + 290.0
|
||||
var shed_x := r.end.x - 26.0
|
||||
Sketch.text(self, r.position + Vector2(18.0, 8.0), "Pouch", 32)
|
||||
Sketch.text(self, Vector2(pouch_x, r.position.y + 14.0), "Carried", 24, Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.text(self, Vector2(shed_x, r.position.y + 14.0), "Shed", 24, Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.rule(self, r.position.x + 14.0, r.end.x - 14.0, r.position.y + 50.0, 412.0)
|
||||
for i in list.size():
|
||||
var row: Dictionary = list[i]
|
||||
var m: String = row["material"]
|
||||
var y := r.position.y + 56.0 + i * ROW
|
||||
Sketch.icon(self, m, Rect2(Vector2(r.position.x + 14.0, y), Vector2(40.0, 40.0)))
|
||||
Sketch.text(self, Vector2(r.position.x + 62.0, y + 2.0), m.capitalize(), 30, GatherNode.COLORS[m])
|
||||
var carried: int = row["pouch"]
|
||||
Sketch.text(self, Vector2(pouch_x, y + 2.0), str(carried), 30, Sketch.TEXT if carried > 0 else Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
Sketch.text(self, Vector2(shed_x, y + 2.0), str(row["shed"]), 30, SHED, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue