UI and other changes
This commit is contained in:
parent
87b5c11fcf
commit
215e24e246
79 changed files with 70023 additions and 2201 deletions
|
|
@ -1,22 +1,27 @@
|
|||
class_name PhaseHud
|
||||
extends Control
|
||||
## Top-left phase indicator: a dial whose ring fills over the current phase with a sun (day), a
|
||||
## setting sun (dusk), a moon (night), or a rising sun (dawn) in it; "Night N of M"; the phase
|
||||
## and its time left; and a hint line (what tonight brings at dusk, thieves on the farm at night, the
|
||||
## early-night key when allowed). Each phase also announces itself with a banner that fades;
|
||||
## from dusk into the night, tonight's dusk hint (NightPlan.dusk_hint) shows under it.
|
||||
## Top-right day and time, hand-drawn (Sketch): a sun by day (a moon at night) on a light wash,
|
||||
## "Day N of M", the time left in the phase ("1:42 until Dusk"), and a thin teal line filling
|
||||
## over the phase; under it, a hint when there is one (what tonight brings at dusk, who's on the
|
||||
## farm at night, the early-night key when allowed). Each phase also announces itself with a
|
||||
## banner that fades; from dusk into the night, tonight's dusk hint (NightPlan.dusk_hint) shows
|
||||
## under it.
|
||||
|
||||
const DIAL_CENTER := Vector2(62.0, 64.0)
|
||||
const DIAL_RADIUS := 34.0
|
||||
const BANNER_TIME := 3.0
|
||||
const WIDGET := Vector2(430.0, 112.0)
|
||||
const MARGIN := Vector2(24.0, 18.0)
|
||||
const PROGRESS := Color(0.3, 0.82, 0.8)
|
||||
const HINT_SIZE := 22
|
||||
const HINT_LINE := 28.0
|
||||
|
||||
var campaign: CampaignController
|
||||
var waves: WaveDirector
|
||||
var enemies: EnemySystem
|
||||
|
||||
var _title: Label
|
||||
var _sub: Label
|
||||
var _hint: Label
|
||||
## What the widget shows: "Day 2 of 30", "1:42 until Dusk", and the hint ("" for none).
|
||||
var title := ""
|
||||
var sub := ""
|
||||
var hint := ""
|
||||
var _banner: Label
|
||||
var _banner_left: float = 0.0
|
||||
var _dusk_hint: Label
|
||||
|
|
@ -33,38 +38,40 @@ func setup(p_campaign: CampaignController, p_waves: WaveDirector, p_enemies: Ene
|
|||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_title = _label(28, Vector2(112.0, 26.0))
|
||||
_sub = _label(22, Vector2(112.0, 62.0))
|
||||
_hint = _label(19, Vector2(112.0, 92.0))
|
||||
_banner = Label.new()
|
||||
_banner.set_anchors_preset(Control.PRESET_TOP_WIDE)
|
||||
_banner.offset_top = 250.0
|
||||
_banner.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_banner.add_theme_font_size_override("font_size", 52)
|
||||
_banner.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
_banner.add_theme_constant_override("outline_size", 12)
|
||||
Sketch.style(_banner, 60, Sketch.TEXT, 14)
|
||||
_banner.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_banner.modulate.a = 0.0
|
||||
add_child(_banner)
|
||||
_dusk_hint = Label.new()
|
||||
_dusk_hint.set_anchors_preset(Control.PRESET_CENTER_TOP)
|
||||
_dusk_hint.offset_top = 330.0
|
||||
_dusk_hint.offset_top = 336.0
|
||||
_dusk_hint.offset_left = -520.0
|
||||
_dusk_hint.offset_right = 520.0
|
||||
_dusk_hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_dusk_hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_dusk_hint.add_theme_font_size_override("font_size", 26)
|
||||
_dusk_hint.add_theme_color_override("font_color", Color(1.0, 0.88, 0.7))
|
||||
_dusk_hint.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
_dusk_hint.add_theme_constant_override("outline_size", 8)
|
||||
Sketch.style(_dusk_hint, 30, Color(1.0, 0.88, 0.7), 10)
|
||||
_dusk_hint.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_dusk_hint.visible = false
|
||||
add_child(_dusk_hint)
|
||||
|
||||
|
||||
## "Night 1 of 5 · Day · 2:34 left", as the HUD shows it (also used by tests).
|
||||
## "Day 1 of 5 · 2:34 until Dusk", as the HUD shows it (also used by tests).
|
||||
func describe() -> String:
|
||||
return "%s · %s" % [_title.text, _sub.text]
|
||||
return "%s · %s" % [title, sub]
|
||||
|
||||
|
||||
## The widget's rect (canvas), and the bottom of it and its hint (RadarHud sits under that).
|
||||
func widget_rect() -> Rect2:
|
||||
return Rect2(Vector2(size.x - MARGIN.x - WIDGET.x, MARGIN.y), WIDGET)
|
||||
|
||||
|
||||
func bottom() -> float:
|
||||
var lines := hint.count("\n") + 1 if hint != "" else 0
|
||||
return widget_rect().end.y + 10.0 + lines * HINT_LINE
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -72,29 +79,28 @@ func _process(delta: float) -> void:
|
|||
return
|
||||
var s := campaign.state
|
||||
var cfg := campaign.config
|
||||
_title.text = "Night %d of %d" % [s.night, cfg.campaign_nights]
|
||||
title = "Day %d of %d" % [s.night, cfg.campaign_nights]
|
||||
var left := _clock(s.phase_time_left)
|
||||
var hint := ""
|
||||
hint = ""
|
||||
match s.phase:
|
||||
CampaignController.Phase.MORNING:
|
||||
_sub.text = "Morning"
|
||||
sub = "Morning"
|
||||
CampaignController.Phase.DAY:
|
||||
_sub.text = "Day · %s left" % left
|
||||
sub = "%s until Dusk" % left
|
||||
if campaign.can_start_night_early():
|
||||
hint = "[N] start the night early"
|
||||
CampaignController.Phase.DUSK:
|
||||
_sub.text = "Dusk · nightfall in %s" % left
|
||||
sub = "%s until Nightfall" % left
|
||||
hint = "\n".join(waves.tonight_warning()) if waves != null else ""
|
||||
CampaignController.Phase.NIGHT:
|
||||
_sub.text = "Night · sunrise in %s" % left
|
||||
sub = "%s until Dawn" % left
|
||||
hint = on_the_farm(enemies)
|
||||
CampaignController.Phase.DAWN:
|
||||
_sub.text = "Dawn · the aliens are fleeing (%s)" % left
|
||||
sub = "%s until Morning" % left
|
||||
CampaignController.Phase.FARMERS_RETURN:
|
||||
_sub.text = "The farmers are back"
|
||||
sub = "The farmers are back"
|
||||
CampaignController.Phase.GAME_OVER:
|
||||
_sub.text = "Game over"
|
||||
_hint.text = hint
|
||||
sub = "Game over"
|
||||
var plan := waves.tonight() if waves != null else null
|
||||
_dusk_hint.visible = plan != null and plan.dusk_hint != "" and waves.warning_active()
|
||||
if _dusk_hint.visible:
|
||||
|
|
@ -109,25 +115,21 @@ func _draw() -> void:
|
|||
return
|
||||
var s := campaign.state
|
||||
var length := campaign.phase_length(s.phase)
|
||||
var frac := 1.0 - s.phase_time_left / length if is_finite(length) and length > 0.0 else 0.0
|
||||
var phase := s.phase
|
||||
var night := phase == CampaignController.Phase.NIGHT
|
||||
var hint_size := _hint.get_minimum_size() if _hint.text != "" else Vector2.ZERO
|
||||
var box := Vector2(maxf(430.0, 112.0 + hint_size.x + 18.0), maxf(104.0, 92.0 + hint_size.y - 14.0 + 22.0))
|
||||
draw_rect(Rect2(Vector2(14.0, 14.0), box), Color(0.0, 0.0, 0.0, 0.42))
|
||||
draw_circle(DIAL_CENTER, DIAL_RADIUS, Color(0.08, 0.1, 0.18, 0.95) if night else Color(0.25, 0.45, 0.7, 0.95))
|
||||
var ring := Color(0.6, 0.7, 1.0) if night else Color(1.0, 0.85, 0.4)
|
||||
draw_arc(DIAL_CENTER, DIAL_RADIUS - 4.0, -PI * 0.5, -PI * 0.5 + TAU * frac, 48, ring, 5.0)
|
||||
match phase:
|
||||
CampaignController.Phase.NIGHT:
|
||||
draw_circle(DIAL_CENTER, 15.0, Color(0.93, 0.95, 1.0))
|
||||
draw_circle(DIAL_CENTER + Vector2(7.0, -5.0), 13.0, Color(0.08, 0.1, 0.18))
|
||||
CampaignController.Phase.DUSK, CampaignController.Phase.DAWN:
|
||||
var c := DIAL_CENTER + Vector2(0.0, 8.0)
|
||||
draw_circle(c, 15.0, Color(1.0, 0.55, 0.3) if phase == CampaignController.Phase.DUSK else Color(1.0, 0.72, 0.6))
|
||||
draw_rect(Rect2(c + Vector2(-20.0, 4.0), Vector2(40.0, 16.0)), Color(0.12, 0.2, 0.12))
|
||||
_:
|
||||
draw_circle(DIAL_CENTER, 15.0, Color(1.0, 0.88, 0.35))
|
||||
var frac := clampf(1.0 - s.phase_time_left / length, 0.0, 1.0) if is_finite(length) and length > 0.0 else 0.0
|
||||
var r := widget_rect()
|
||||
Sketch.box(self, r, Sketch.WASH, Color(0, 0, 0, 0), 0.0, 301.0)
|
||||
Sketch.icon(self, "moon" if s.phase == CampaignController.Phase.NIGHT else "sun", Rect2(r.position + Vector2(4.0, 4.0), Vector2(104.0, 104.0)))
|
||||
var right := r.end.x - 18.0
|
||||
Sketch.text(self, Vector2(right, r.position.y + 6.0), title, 40, Sketch.TEXT, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
Sketch.text(self, Vector2(right, r.position.y + 54.0), sub, 36, Sketch.TEXT, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
var y := r.end.y + 1.0
|
||||
Sketch.line(self, Vector2(r.position.x + 6.0, y), Vector2(r.end.x - 6.0, y), Color(PROGRESS, 0.25), 4.0, 302.0, 0.8)
|
||||
if frac > 0.0:
|
||||
Sketch.line(self, Vector2(r.position.x + 6.0, y), Vector2(r.position.x + 6.0 + (r.size.x - 12.0) * frac, y), PROGRESS, 4.0, 302.0, 0.8)
|
||||
var lines := hint.split("\n", false)
|
||||
for i in lines.size():
|
||||
Sketch.text(self, Vector2(right, r.end.y + 10.0 + i * HINT_LINE), lines[i], HINT_SIZE, Color(1.0, 0.93, 0.75),
|
||||
HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
|
||||
|
||||
func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void:
|
||||
|
|
@ -183,13 +185,3 @@ static func join_words(words: PackedStringArray) -> String:
|
|||
return "".join(words)
|
||||
return ", ".join(words.slice(0, words.size() - 1)) + " and " + words[words.size() - 1]
|
||||
|
||||
|
||||
func _label(font_size: int, at: Vector2) -> Label:
|
||||
var l := Label.new()
|
||||
l.position = at
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue