updates
This commit is contained in:
parent
276d43613d
commit
4298caf5cb
552 changed files with 42990 additions and 776 deletions
251
game/scripts/end_panel.gd
Normal file
251
game/scripts/end_panel.gd
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
class_name EndPanel
|
||||
extends CenterContainer
|
||||
## The two end screens. Works with mouse, keyboard (arrows + Enter), and gamepad (d-pad + A)
|
||||
## through focus.
|
||||
## * Failure, a moment after a Game Over (so the fall can play): the cause (the scarecrow
|
||||
## destroyed, or the farm stripped bare), the night reached and its plan, what's left and
|
||||
## what the night cost so far, the vacation's totals, and Retry the night (D9, focused: back
|
||||
## to that morning) and Main menu (New vacation when there's no menu, e.g. the farm scene on
|
||||
## its own).
|
||||
## * The final assessment, once the farmers' return (FarmersReturn) has played or been
|
||||
## skipped: the rating and score (Assessment), the share kept per category with a bar, and
|
||||
## the vacation's totals, with Main menu (or New vacation).
|
||||
|
||||
signal menu_requested
|
||||
|
||||
const DELAY := 1.4
|
||||
const GOLD := Color(0.95, 0.82, 0.45)
|
||||
const GREY := Color(0.75, 0.77, 0.72)
|
||||
|
||||
var campaign: CampaignController
|
||||
## Set by Main: the Main menu button shows instead of New vacation.
|
||||
var has_menu := false
|
||||
## Set by FarmSim: the final assessment waits for the farmers' return to finish.
|
||||
var ending: FarmersReturn
|
||||
var waves: WaveDirector
|
||||
## Set when the screen is up: "failure" or "assessment".
|
||||
var mode := ""
|
||||
|
||||
var _title: Label
|
||||
var _rating: Label
|
||||
var _detail: Label
|
||||
var _bars: GridContainer
|
||||
var _bar_rows := {} # category -> [ProgressBar, Label]
|
||||
var _stats: Label
|
||||
var _retry: Button
|
||||
var _menu: Button
|
||||
var _new: Button
|
||||
var _wait: float = -1.0
|
||||
var _pending_mode := ""
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
campaign.campaign_ended.connect(_on_ended)
|
||||
campaign.phase_changed.connect(func(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void:
|
||||
if phase == CampaignController.Phase.MORNING:
|
||||
hide_panel())
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
||||
add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 34)
|
||||
panel.add_child(margin)
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 16)
|
||||
margin.add_child(box)
|
||||
_title = _label(box, 46)
|
||||
_rating = _label(box, 30, GOLD)
|
||||
_detail = _label(box, 22)
|
||||
_bars = GridContainer.new()
|
||||
_bars.columns = 3
|
||||
_bars.add_theme_constant_override("h_separation", 18)
|
||||
_bars.add_theme_constant_override("v_separation", 8)
|
||||
_bars.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
box.add_child(_bars)
|
||||
for cat in ["crops", "animals", "supplies"]:
|
||||
var name_label := _label(_bars, 22)
|
||||
name_label.text = cat.capitalize()
|
||||
name_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
var bar := ProgressBar.new()
|
||||
bar.custom_minimum_size = Vector2(320.0, 26.0)
|
||||
bar.show_percentage = false
|
||||
bar.max_value = 1.0
|
||||
var fill := StyleBoxFlat.new()
|
||||
fill.bg_color = Color(0.55, 0.78, 0.4)
|
||||
fill.set_corner_radius_all(4)
|
||||
var back := StyleBoxFlat.new()
|
||||
back.bg_color = Color(0.22, 0.24, 0.2)
|
||||
back.set_corner_radius_all(4)
|
||||
bar.add_theme_stylebox_override("fill", fill)
|
||||
bar.add_theme_stylebox_override("background", back)
|
||||
_bars.add_child(bar)
|
||||
var text := _label(_bars, 20, GREY)
|
||||
text.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
_bar_rows[cat] = [bar, text, name_label]
|
||||
_stats = _label(box, 20, GREY)
|
||||
var buttons := HBoxContainer.new()
|
||||
buttons.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
buttons.add_theme_constant_override("separation", 24)
|
||||
box.add_child(buttons)
|
||||
_retry = _button(buttons, "Retry the night")
|
||||
_retry.pressed.connect(func() -> void: campaign.retry_night())
|
||||
_menu = _button(buttons, "Main menu")
|
||||
_menu.pressed.connect(func() -> void: menu_requested.emit())
|
||||
_new = _button(buttons, "New vacation")
|
||||
_new.pressed.connect(func() -> void: campaign.new_campaign())
|
||||
hide_panel()
|
||||
|
||||
|
||||
func hide_panel() -> void:
|
||||
visible = false
|
||||
mode = ""
|
||||
_wait = -1.0
|
||||
_pending_mode = ""
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
|
||||
func _on_ended(outcome: CampaignController.Outcome) -> void:
|
||||
if outcome == CampaignController.Outcome.VACATION_COMPLETE:
|
||||
if ending != null:
|
||||
if not ending.finished.is_connected(_on_ending_finished):
|
||||
ending.finished.connect(_on_ending_finished)
|
||||
return
|
||||
_pending_mode = "assessment"
|
||||
else:
|
||||
_pending_mode = "failure"
|
||||
_wait = DELAY
|
||||
|
||||
|
||||
func _on_ending_finished() -> void:
|
||||
_pending_mode = "assessment"
|
||||
_wait = 0.01
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _wait < 0.0:
|
||||
return
|
||||
_wait -= delta
|
||||
if _wait <= 0.0:
|
||||
_wait = -1.0
|
||||
if _pending_mode == "assessment":
|
||||
show_assessment()
|
||||
else:
|
||||
show_failure()
|
||||
|
||||
|
||||
func show_failure() -> void:
|
||||
var s := campaign.state
|
||||
var cfg := campaign.config
|
||||
mode = "failure"
|
||||
var plan := waves.plan_for(s.night) if waves != null else null
|
||||
var night := "Night %d of %d%s" % [s.night, cfg.campaign_nights, (": " + plan.title) if plan != null and plan.title != "" else ""]
|
||||
if campaign.outcome == CampaignController.Outcome.GAME_OVER_SCARECROW:
|
||||
_title.text = "The scarecrow has fallen"
|
||||
_rating.text = "%s. Its straw gave out." % night
|
||||
else:
|
||||
_title.text = "The farm was stripped bare"
|
||||
_rating.text = "%s. Every crop, animal, and supply is gone." % night
|
||||
var e := s.night_events
|
||||
var lines: Array[String] = []
|
||||
lines.append("You kept the farm for %d %s." % [s.nights_survived, "night" if s.nights_survived == 1 else "nights"])
|
||||
lines.append("Left: %d of %d crops, %d of %d animals, %d supplies." % [s.crops, s.crops_total, s.animals, s.animals_total, s.supplies])
|
||||
lines.append("Tonight: %s defeated; %d crops, %d animals, and %d supplies snatched." % [Assessment.enemies_line(e),
|
||||
int(e.get("crops_stolen", 0)), int(e.get("animals_stolen", 0)), int(e.get("supplies_stolen", 0))])
|
||||
_detail.text = "\n".join(lines)
|
||||
_bars.visible = false
|
||||
_stats.text = _totals_text(s.totals(), false)
|
||||
_stats.visible = not s.night_log.is_empty()
|
||||
_retry.visible = true
|
||||
_retry.text = "Retry the night (from the morning of day %d)" % s.night
|
||||
_show_buttons()
|
||||
_open(_retry)
|
||||
|
||||
|
||||
func show_assessment() -> void:
|
||||
var s := campaign.state
|
||||
var cfg := campaign.config
|
||||
mode = "assessment"
|
||||
var a := Assessment.of(s, cfg)
|
||||
_title.text = "The farmers are home!"
|
||||
_rating.text = "%s · %d points" % [a["tier"], a["score"]]
|
||||
_detail.text = "%s\nYou kept the farm for all %d nights." % [a["text"], s.nights_survived]
|
||||
_bars.visible = true
|
||||
var parts: Dictionary = a["parts"]
|
||||
for cat: String in _bar_rows:
|
||||
var row: Array = _bar_rows[cat]
|
||||
var shown := parts.has(cat)
|
||||
for c: Control in row:
|
||||
c.visible = shown
|
||||
if not shown:
|
||||
continue
|
||||
(row[0] as ProgressBar).value = float(parts[cat])
|
||||
var pct := roundi(100.0 * float(parts[cat]))
|
||||
match cat:
|
||||
"crops":
|
||||
(row[1] as Label).text = "%d%% (%d of %d)" % [pct, s.crops, s.crops_total]
|
||||
"animals":
|
||||
(row[1] as Label).text = "%d%% (%d of %d)" % [pct, s.animals, s.animals_total]
|
||||
_:
|
||||
(row[1] as Label).text = "%d%% kept from thieves (%d of %d carried off)" % [pct, a["supplies_lost"], a["supplies_handled"]]
|
||||
_stats.text = _totals_text(a["totals"], true)
|
||||
_stats.visible = true
|
||||
_retry.visible = false
|
||||
_show_buttons()
|
||||
_open(_menu if has_menu else _new)
|
||||
|
||||
|
||||
## The vacation's totals, a few lines.
|
||||
func _totals_text(t: Dictionary, finished: bool) -> String:
|
||||
var s := campaign.state
|
||||
var lines: Array[String] = []
|
||||
if not finished:
|
||||
lines.append("Over the vacation so far:")
|
||||
lines.append("Enemies defeated: %s. Got away with loot: %d." % [Assessment.enemies_line(t), int(t["escaped"])])
|
||||
lines.append("Recovered: %s, %s, %d supplies. Carried off: %s, %s, %d supplies." % [
|
||||
_count(t["crops_recovered"], "crop"), _count(t["animals_recovered"], "animal"), int(t["supplies_recovered"]),
|
||||
_count(t["crops_lost"], "crop"), _count(t["animals_lost"], "animal"), int(t["supplies_lost"])])
|
||||
lines.append("Built %d, repaired %d, broken %d. Upgrades: %d of %d. Patched up %s, %d damage taken." % [
|
||||
int(t["structures_built"]), int(t["repairs"]), int(t["structures_destroyed"]), s.upgrades.size(),
|
||||
Upgrades.ORDER.size(), _count(t["patches"], "time"), int(t["scarecrow_damage"])])
|
||||
lines.append("Gathered %s. Spent %s." % [Assessment.materials_line(t, "gathered_"), Assessment.materials_line(t, "spent_")])
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
## "1 crop", "3 crops".
|
||||
static func _count(n: Variant, word: String) -> String:
|
||||
return "%d %s%s" % [int(n), word, "" if int(n) == 1 else "s"]
|
||||
|
||||
|
||||
func _show_buttons() -> void:
|
||||
_menu.visible = has_menu
|
||||
_new.visible = not has_menu
|
||||
|
||||
|
||||
func _open(focus: Button) -> void:
|
||||
visible = true
|
||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
focus.grab_focus()
|
||||
|
||||
|
||||
func _label(parent: Node, font_size: int, color: Color = Color(0.92, 0.92, 0.88)) -> Label:
|
||||
var l := Label.new()
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_color", color)
|
||||
parent.add_child(l)
|
||||
return l
|
||||
|
||||
|
||||
func _button(parent: Control, text: String) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.custom_minimum_size = Vector2(230.0, 56.0)
|
||||
b.add_theme_font_size_override("font_size", 24)
|
||||
parent.add_child(b)
|
||||
return b
|
||||
Loading…
Add table
Add a link
Reference in a new issue