UI and other changes
This commit is contained in:
parent
87b5c11fcf
commit
215e24e246
79 changed files with 70023 additions and 2201 deletions
|
|
@ -1,19 +1,22 @@
|
|||
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.
|
||||
## The build bar, shown in build mode in the weapons hotbar's place (ScarecrowHud), hand-drawn
|
||||
## like the HUD's pouch panel (Sketch): "Build" over a pen rule with how many structures stand on
|
||||
## the farm, 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 lifted in a gold frame, and the
|
||||
## controls in dim text under them.
|
||||
|
||||
const SLOT := Vector2(230.0, 76.0)
|
||||
const SLOT := Vector2(250.0, 80.0)
|
||||
const GAP := 12.0
|
||||
const PAD := 18.0
|
||||
const HEAD := 52.0
|
||||
const HELP := 32.0
|
||||
const BOTTOM := 22.0
|
||||
const SHORT := Color(1.0, 0.45, 0.4)
|
||||
|
||||
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
|
||||
|
|
@ -23,55 +26,47 @@ func setup(p_build: BuildMode, p_campaign: CampaignController) -> void:
|
|||
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()
|
||||
if visible:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## The controls line, as shown.
|
||||
func help_text() -> String:
|
||||
return "LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave"
|
||||
|
||||
|
||||
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 r := campaign.state.resources
|
||||
var slot := build.kit.slot if build.kit != null else 0
|
||||
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
|
||||
var width := n * SLOT.x + (n - 1) * GAP + PAD * 2.0
|
||||
var height := HEAD + SLOT.y + HELP + PAD
|
||||
var panel := Rect2(Vector2((size.x - width) * 0.5, size.y - BOTTOM - height), Vector2(width, height))
|
||||
Sketch.panel(self, panel, 801.0)
|
||||
Sketch.text(self, panel.position + Vector2(PAD, 6.0), "Build", 32)
|
||||
Sketch.text(self, Vector2(panel.end.x - PAD - 8.0, panel.position.y + 12.0), "%d built" % build.structures.count(), 24,
|
||||
Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.rule(self, panel.position.x + 14.0, panel.end.x - 14.0, panel.position.y + 48.0, 802.0)
|
||||
for i in n:
|
||||
var t: String = StructureSystem.ORDER[i]
|
||||
var cost: Dictionary = campaign.config.costs.get(t, {})
|
||||
var rect := Rect2(panel.position + Vector2(PAD + i * (SLOT.x + GAP), HEAD + 4.0), SLOT)
|
||||
var picked := i == build.selected
|
||||
if picked:
|
||||
rect = rect.grow(3.0)
|
||||
rect.position.y -= 4.0
|
||||
Sketch.box(self, rect, Sketch.SLOT, Sketch.INK, 2.5, 810.0 + i * 3.0)
|
||||
if picked:
|
||||
Sketch.box(self, rect.grow(2.0), Color(0, 0, 0, 0), Sketch.GOLD, 3.5, 830.0 + i)
|
||||
Sketch.text(self, rect.position + Vector2(12.0, 4.0), "%d %s" % [i + 1, StructureSystem.NAMES[t]], 28, Sketch.TEXT,
|
||||
HORIZONTAL_ALIGNMENT_LEFT, 6)
|
||||
Sketch.text(self, rect.position + Vector2(12.0, 42.0), ResourceStore.describe(cost), 22,
|
||||
Sketch.TEXT if r.can_afford(cost, slot) else SHORT, HORIZONTAL_ALIGNMENT_LEFT, 6)
|
||||
Sketch.text(self, Vector2(panel.get_center().x, panel.end.y - PAD - 22.0), help_text(), 22, Sketch.DIM,
|
||||
HORIZONTAL_ALIGNMENT_CENTER, 6)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue