updates
This commit is contained in:
parent
215e24e246
commit
bbd8012fff
16 changed files with 510 additions and 213 deletions
|
|
@ -297,10 +297,8 @@ func _ready() -> void:
|
|||
if phase_hud != null:
|
||||
phase_hud.setup(campaign, waves, enemies)
|
||||
if review_panel != null:
|
||||
review_panel.setup(campaign, structures)
|
||||
review_panel.animals = animals
|
||||
review_panel.waves = waves
|
||||
review_panel.refresh()
|
||||
review_panel.setup(campaign)
|
||||
if hud != null:
|
||||
hud.setup(scarecrow, campaign, combat)
|
||||
hud.build = build
|
||||
|
|
@ -771,7 +769,7 @@ func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignContr
|
|||
if shed_panel != null:
|
||||
shed_panel.close()
|
||||
if review_panel != null:
|
||||
review_panel.refresh() # after the farm is back in sync (the pen's gate)
|
||||
review_panel.refresh()
|
||||
|
||||
|
||||
## End of the dawn grace: whoever is still on the farm leaves (carrying their loot off), and
|
||||
|
|
|
|||
|
|
@ -1,93 +1,144 @@
|
|||
class_name ReviewPanel
|
||||
extends CenterContainer
|
||||
## The morning screen (the untimed MORNING phase), between one night and the next day:
|
||||
## * Last night's results (from the night's log entry): per category what was taken,
|
||||
## recovered, and lost; enemies defeated by type and how many got away with loot; damage
|
||||
## (the scarecrow's, structures hit, broken, and repaired); materials gathered and spent
|
||||
## over the day and night.
|
||||
## * This morning: what's left (crops, animals, supplies, the scarecrow's health), what needs
|
||||
## repair (damaged structures keep their health bars on the farm), the pen's gate, the
|
||||
## materials on hand, and tonight's plan.
|
||||
## "Start the day" (focused, so Enter / A work) ends it. The first morning explains the vacation
|
||||
## instead of results.
|
||||
## The morning screen (the untimed MORNING phase), between one night and the next day: a wooden
|
||||
## sign, hand-drawn (Sketch) over the dimmed farm, the day on its top beam and a sheet of paper
|
||||
## nailed under it with last night's results (from the night's log entry):
|
||||
## * per category (crops, animals, supplies): what was taken, recovered, and lost;
|
||||
## * the enemies defeated, by type;
|
||||
## * the materials gathered over the day and night.
|
||||
## Each row has its icon; a type or material with none isn't listed. "Start the day" (focused,
|
||||
## so Enter / A work) ends it. The first morning explains the vacation instead of results.
|
||||
|
||||
const CATEGORIES := ["Crops", "Animals", "Supplies"]
|
||||
const GOLD := Color(0.95, 0.82, 0.45)
|
||||
const GREY := Color(0.7, 0.72, 0.68)
|
||||
const RED := Color(1.0, 0.5, 0.42)
|
||||
const ENEMY_TYPES := [EnemySystem.TYPE_CROW, EnemySystem.TYPE_THIEF, EnemySystem.TYPE_BREAKER, EnemySystem.TYPE_UFO]
|
||||
## The sign's layout around its paper: the posts and beam ends either side of it, the top beam
|
||||
## (the title is written on it), and the bottom beam.
|
||||
const SIDE := 64.0
|
||||
const BEAM := 92.0
|
||||
const BOTTOM := 70.0
|
||||
const WIDTH := 880.0
|
||||
|
||||
var campaign: CampaignController
|
||||
var structures: StructureSystem
|
||||
## Set by FarmSim: whether the pen is open, and tonight's plan.
|
||||
var animals: AnimalSystem
|
||||
## Set by FarmSim: the night plans (last night's title).
|
||||
var waves: WaveDirector
|
||||
|
||||
var _board: PanelContainer
|
||||
var _title: Label
|
||||
var _last_head: Label
|
||||
var _rule: HSeparator
|
||||
var _grid: GridContainer
|
||||
var _cells := {} # "Crops/taken" -> Label
|
||||
var _results: Label
|
||||
var _rule: HSeparator
|
||||
var _morning_head: Label
|
||||
var _body: Label
|
||||
var _lists: HBoxContainer
|
||||
var _enemies := {} # type -> [icon, name, count]
|
||||
var _no_enemies: Label
|
||||
var _materials := {} # material -> [icon, name, count]
|
||||
var _no_materials: Label
|
||||
var _intro: Label
|
||||
var _start: Button
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController, p_structures: StructureSystem) -> void:
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
structures = p_structures
|
||||
campaign.phase_changed.connect(func(_p: CampaignController.Phase, _prev: CampaignController.Phase) -> void: refresh())
|
||||
refresh()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", backing())
|
||||
add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 30)
|
||||
panel.add_child(margin)
|
||||
theme = UiTheme.sketch()
|
||||
_board = PanelContainer.new()
|
||||
var margins := StyleBoxEmpty.new()
|
||||
margins.content_margin_left = SIDE
|
||||
margins.content_margin_right = SIDE
|
||||
margins.content_margin_bottom = BOTTOM
|
||||
_board.add_theme_stylebox_override("panel", margins)
|
||||
_board.draw.connect(_draw_board)
|
||||
add_child(_board)
|
||||
var column := VBoxContainer.new()
|
||||
column.add_theme_constant_override("separation", 0)
|
||||
_board.add_child(column)
|
||||
_title = Label.new()
|
||||
Sketch.style(_title, 48)
|
||||
_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
_title.custom_minimum_size = Vector2(0.0, BEAM)
|
||||
column.add_child(_title)
|
||||
var sheet := MarginContainer.new()
|
||||
for side: String in ["left", "right"]:
|
||||
sheet.add_theme_constant_override("margin_" + side, 48)
|
||||
sheet.add_theme_constant_override("margin_top", 26)
|
||||
sheet.add_theme_constant_override("margin_bottom", 32)
|
||||
column.add_child(sheet)
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 12)
|
||||
margin.add_child(box)
|
||||
_title = _label(box, 38)
|
||||
_last_head = _label(box, 26, GOLD)
|
||||
_grid = GridContainer.new()
|
||||
_grid.columns = 4
|
||||
_grid.add_theme_constant_override("h_separation", 48)
|
||||
_grid.add_theme_constant_override("v_separation", 2)
|
||||
box.add_child(_grid)
|
||||
for head in ["", "Taken", "Recovered", "Lost"]:
|
||||
_label(_grid, 20, GREY).text = head
|
||||
for cat: String in CATEGORIES:
|
||||
_label(_grid, 22).text = cat
|
||||
for col in ["taken", "recovered", "lost"]:
|
||||
var l := _label(_grid, 22)
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
_cells["%s/%s" % [cat, col]] = l
|
||||
_results = _label(box, 21)
|
||||
_results.custom_minimum_size = Vector2(760.0, 0.0)
|
||||
_results.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
box.custom_minimum_size = Vector2(WIDTH, 0.0)
|
||||
box.add_theme_constant_override("separation", 10)
|
||||
sheet.add_child(box)
|
||||
_last_head = _ink(box, 38)
|
||||
_last_head.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_rule = HSeparator.new()
|
||||
_rule.add_theme_stylebox_override("separator", SketchBox.new(Color(0, 0, 0, 0), Color(Sketch.PAPER_INK, 0.5), 2.0, true))
|
||||
box.add_child(_rule)
|
||||
_morning_head = _label(box, 26, GOLD)
|
||||
_morning_head.text = "This morning"
|
||||
_body = _label(box, 21)
|
||||
_body.custom_minimum_size = Vector2(760.0, 0.0)
|
||||
_body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_grid = GridContainer.new()
|
||||
_grid.columns = 5
|
||||
_grid.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
_grid.add_theme_constant_override("h_separation", 18)
|
||||
_grid.add_theme_constant_override("v_separation", 4)
|
||||
box.add_child(_grid)
|
||||
_grid.add_child(Control.new())
|
||||
_grid.add_child(Control.new())
|
||||
for head: String in ["Taken", "Recovered", "Lost"]:
|
||||
var l := _ink(_grid, 28, Sketch.PAPER_DIM)
|
||||
l.text = head
|
||||
l.custom_minimum_size = Vector2(150.0, 0.0)
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
for i in CATEGORIES.size():
|
||||
var cat: String = CATEGORIES[i]
|
||||
_grid.add_child(SketchIcon.new(LootSystem.CATEGORY_KEYS[i], 52.0))
|
||||
var label := _ink(_grid, 32)
|
||||
label.text = cat
|
||||
label.custom_minimum_size = Vector2(150.0, 0.0)
|
||||
for col: String in ["taken", "recovered", "lost"]:
|
||||
var l := _ink(_grid, 34)
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_cells["%s/%s" % [cat, col]] = l
|
||||
box.add_child(_spacer(8.0))
|
||||
_lists = HBoxContainer.new()
|
||||
_lists.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
_lists.add_theme_constant_override("separation", 90)
|
||||
box.add_child(_lists)
|
||||
var enemies := _list(_lists, "Enemies defeated")
|
||||
for t: int in ENEMY_TYPES:
|
||||
var plural := EnemySystem.PLURALS[t]
|
||||
_enemies[t] = _list_row(enemies, EnemySystem.TYPE_NAMES[t], plural[0].to_upper() + plural.substr(1))
|
||||
_no_enemies = _ink(enemies, 30, Sketch.PAPER_DIM)
|
||||
_no_enemies.text = "None"
|
||||
var materials := _list(_lists, "Materials gathered")
|
||||
for m in ResourceStore.MATERIALS:
|
||||
_materials[m] = _list_row(materials, m, m.capitalize())
|
||||
_no_materials = _ink(materials, 30, Sketch.PAPER_DIM)
|
||||
_no_materials.text = "Nothing"
|
||||
_intro = _ink(box, 28)
|
||||
_intro.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_intro.add_theme_constant_override("paragraph_spacing", 14)
|
||||
_start = Button.new()
|
||||
_start.text = "Start the day"
|
||||
_start.custom_minimum_size = Vector2(260.0, 56.0)
|
||||
_start.add_theme_font_size_override("font_size", 24)
|
||||
_start.custom_minimum_size = Vector2(300.0, 62.0)
|
||||
_start.add_theme_font_size_override("font_size", 32)
|
||||
_start.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
var wood := {
|
||||
"normal": SketchBox.new(Sketch.WOOD, Sketch.INK, 2.5),
|
||||
"hover": SketchBox.new(Sketch.WOOD.lightened(0.15), Sketch.INK, 2.5),
|
||||
"pressed": SketchBox.new(Sketch.WOOD.darkened(0.2), Sketch.GOLD, 2.5),
|
||||
}
|
||||
for key: String in wood:
|
||||
_start.add_theme_stylebox_override(key, wood[key])
|
||||
_start.pressed.connect(func() -> void: campaign.begin_day())
|
||||
box.add_child(_spacer(6.0))
|
||||
box.add_child(_start)
|
||||
visible = false
|
||||
|
||||
|
||||
## The dark, nearly opaque panel behind the morning screen, the menus, and the end screens.
|
||||
## The dark, nearly opaque panel behind the menus and the end screens.
|
||||
static func backing() -> StyleBoxFlat:
|
||||
var bg := StyleBoxFlat.new()
|
||||
bg.bg_color = Color(0.1, 0.12, 0.1)
|
||||
|
|
@ -107,40 +158,25 @@ func refresh() -> void:
|
|||
var s := campaign.state
|
||||
var nights := campaign.config.campaign_nights
|
||||
var first := s.night_log.is_empty()
|
||||
for n: Control in [_last_head, _grid, _results, _rule, _morning_head]:
|
||||
for n: Control in [_last_head, _rule, _grid, _lists]:
|
||||
n.visible = not first
|
||||
var lines: Array[String] = []
|
||||
_intro.visible = first
|
||||
if first:
|
||||
_title.text = "The farmers are away"
|
||||
lines.append("Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights)
|
||||
lines.append("By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.")
|
||||
lines.append("At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or the number keys), and more weapons arrive there over the days.")
|
||||
_intro.text = "\n".join([
|
||||
"Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights,
|
||||
"By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.",
|
||||
"At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or the number keys), and more weapons arrive there over the days.",
|
||||
])
|
||||
else:
|
||||
var e: Dictionary = s.night_log[s.night_log.size() - 1]
|
||||
_title.text = "Morning of day %d of %d" % [s.night, nights]
|
||||
var plan := waves.plan_for(int(e["night"])) if waves != null else null
|
||||
_last_head.text = "Night %d: %s" % [e["night"], plan.title] if plan != null and plan.title != "" else "Night %d" % e["night"]
|
||||
_fill_grid(e)
|
||||
_results.text = "\n".join(result_lines(e, s))
|
||||
lines.append("Left: %d of %d crops, %d of %d animals, %d supplies. Scarecrow: %d of %d HP." % [s.crops, s.crops_total,
|
||||
s.animals, s.animals_total, s.supplies, s.scarecrow_hp, s.scarecrow_max_hp])
|
||||
lines.append(_damage_line())
|
||||
if animals != null and animals.pen_open and s.animals > 0:
|
||||
lines.append("The pen is open: put a gate in its opening (B) before nightfall, or the animals in it will get out and roam loose.")
|
||||
var r := s.resources
|
||||
if s.coop: # each scarecrow carries its own
|
||||
lines.append("In the shed: %s. %s's pouch: %s. %s's pouch: %s." % [_or_none(ResourceStore.describe(r.shed)),
|
||||
Avatar.NAMES[0], _or_none(ResourceStore.describe(r.pouch_of(0))), Avatar.NAMES[1], _or_none(ResourceStore.describe(r.pouch_of(1)))])
|
||||
else:
|
||||
lines.append("In the shed: %s. In the pouch: %s." % [_or_none(ResourceStore.describe(r.shed)), _or_none(ResourceStore.describe(r.pouch))])
|
||||
var plan := waves.tonight() if waves != null else null
|
||||
if plan != null and plan.title != "":
|
||||
if structures != null and structures.has_workbench():
|
||||
lines.append("Tonight: %s. Upgrades: %d of %d levels." % [plan.title, Upgrades.levels_bought(campaign.config, s),
|
||||
Upgrades.levels_total(campaign.config)])
|
||||
else: # #9: the Workbench hasn't been granted yet -- it arrives once Night 1 is survived
|
||||
lines.append("Tonight: %s. The work area will be set up once you survive tonight." % plan.title)
|
||||
_body.text = "\n".join(lines)
|
||||
_fill_list(_enemies, _no_enemies, func(t: int) -> int: return int(e.get("killed_" + EnemySystem.TYPE_NAMES[t], 0)))
|
||||
_fill_list(_materials, _no_materials, func(m: String) -> int: return int(e.get("gathered_" + m, 0)))
|
||||
_board.queue_redraw()
|
||||
_start.grab_focus.call_deferred()
|
||||
|
||||
|
||||
|
|
@ -152,6 +188,16 @@ func grid_text() -> String:
|
|||
return "\n".join(rows)
|
||||
|
||||
|
||||
## The enemies listed, "Crows 12, Aliens 3" (or "None"), for tests.
|
||||
func enemies_text() -> String:
|
||||
return _list_text(_enemies, _no_enemies)
|
||||
|
||||
|
||||
## The materials listed, "Wood 8, Straw 4" (or "Nothing"), for tests.
|
||||
func materials_text() -> String:
|
||||
return _list_text(_materials, _no_materials)
|
||||
|
||||
|
||||
## Per category: (taken, recovered, lost) in a night's log entry. Animals taken include those
|
||||
## that got out of an open pen (loose, not lost).
|
||||
static func category_counts(e: Dictionary) -> Dictionary:
|
||||
|
|
@ -162,30 +208,6 @@ static func category_counts(e: Dictionary) -> Dictionary:
|
|||
}
|
||||
|
||||
|
||||
## Enemies, damage, and materials of a night's log entry.
|
||||
static func result_lines(e: Dictionary, s: FarmState) -> Array[String]:
|
||||
var out: Array[String] = []
|
||||
var enemies := "Enemies defeated: %s." % Assessment.enemies_line(e)
|
||||
if int(e["escaped"]) > 0:
|
||||
enemies = enemies.trim_suffix(".") + "; %d got away with loot." % int(e["escaped"])
|
||||
out.append(enemies)
|
||||
var damage := PackedStringArray()
|
||||
damage.append("the scarecrow took %d" % int(e["scarecrow_damage"]) if int(e["scarecrow_damage"]) > 0 else "the scarecrow wasn't hurt")
|
||||
if int(e["patches"]) > 0:
|
||||
damage.append("patched up %d %s" % [int(e["patches"]), "time" if int(e["patches"]) == 1 else "times"])
|
||||
if int(e["structures_damaged"]) > 0:
|
||||
damage.append("structures took %d damage" % int(e["structures_damaged"]))
|
||||
if int(e["structures_destroyed"]) > 0:
|
||||
damage.append("%d broken" % int(e["structures_destroyed"]))
|
||||
if int(e["repairs"]) > 0:
|
||||
damage.append("%d repaired" % int(e["repairs"]))
|
||||
out.append("Damage: %s." % ", ".join(damage))
|
||||
out.append("Materials: gathered %s; spent %s." % [Assessment.materials_line(e, "gathered_"), Assessment.materials_line(e, "spent_")])
|
||||
if s != null and int(e["structures_built"]) + int(e["upgrades_bought"]) > 0:
|
||||
out.append("Built %d, upgrades bought %d." % [int(e["structures_built"]), int(e["upgrades_bought"])])
|
||||
return out
|
||||
|
||||
|
||||
func _fill_grid(e: Dictionary) -> void:
|
||||
var counts := category_counts(e)
|
||||
for cat: String in CATEGORIES:
|
||||
|
|
@ -193,31 +215,113 @@ func _fill_grid(e: Dictionary) -> void:
|
|||
for k in 3:
|
||||
var l: Label = _cells["%s/%s" % [cat, ["taken", "recovered", "lost"][k]]]
|
||||
l.text = str(c[k])
|
||||
l.add_theme_color_override("font_color", RED if k == 2 and int(c[k]) > 0 else Color(0.92, 0.92, 0.88))
|
||||
var color := Sketch.PAPER_INK if int(c[k]) > 0 else Sketch.PAPER_DIM
|
||||
l.add_theme_color_override("font_color", Sketch.PAPER_RED if k == 2 and int(c[k]) > 0 else color)
|
||||
|
||||
|
||||
func _damage_line() -> String:
|
||||
if structures == null or structures.count() == 0:
|
||||
return "Nothing built yet."
|
||||
var damaged := {}
|
||||
for e in campaign.state.structures:
|
||||
if int(e["hp"]) < structures.max_hp(e["type"]):
|
||||
damaged[e["type"]] = int(damaged.get(e["type"], 0)) + 1
|
||||
if damaged.is_empty():
|
||||
return "No repairs needed."
|
||||
var parts: Array[String] = []
|
||||
for t in damaged:
|
||||
parts.append("%d %s%s" % [damaged[t], StructureSystem.NAMES[t].to_lower(), "s" if int(damaged[t]) > 1 else ""])
|
||||
return "Needs repair (marked with health bars): %s." % ", ".join(parts)
|
||||
## Shows the rows of rows (key -> [icon, name, count]) with a count above 0 (count_of(key)), or
|
||||
## none when there aren't any.
|
||||
func _fill_list(rows: Dictionary, none: Label, count_of: Callable) -> void:
|
||||
var any := false
|
||||
for key: Variant in rows:
|
||||
var n: int = count_of.call(key)
|
||||
for c: Control in rows[key]:
|
||||
c.visible = n > 0
|
||||
(rows[key][2] as Label).text = str(n)
|
||||
any = any or n > 0
|
||||
none.visible = not any
|
||||
|
||||
|
||||
func _label(parent: Node, font_size: int, color: Color = Color(0.92, 0.92, 0.88)) -> Label:
|
||||
func _list_text(rows: Dictionary, none: Label) -> String:
|
||||
var parts := PackedStringArray()
|
||||
for key: Variant in rows:
|
||||
var cells: Array = rows[key]
|
||||
if (cells[2] as Control).visible:
|
||||
parts.append("%s %s" % [(cells[1] as Label).text, (cells[2] as Label).text])
|
||||
return ", ".join(parts) if not parts.is_empty() else none.text
|
||||
|
||||
|
||||
## A headed table of icon, name, and count; returns the grid the rows go in.
|
||||
func _list(parent: Control, heading: String) -> GridContainer:
|
||||
var column := VBoxContainer.new()
|
||||
column.add_theme_constant_override("separation", 4)
|
||||
parent.add_child(column)
|
||||
var head := _ink(column, 30, Sketch.PAPER_DIM)
|
||||
head.text = heading
|
||||
var grid := GridContainer.new()
|
||||
grid.columns = 3
|
||||
grid.add_theme_constant_override("h_separation", 14)
|
||||
grid.add_theme_constant_override("v_separation", 0)
|
||||
column.add_child(grid)
|
||||
return grid
|
||||
|
||||
|
||||
func _list_row(grid: GridContainer, icon: String, text: String) -> Array:
|
||||
var i := SketchIcon.new(icon, 46.0)
|
||||
grid.add_child(i)
|
||||
var l := _ink(grid, 30)
|
||||
l.text = text
|
||||
l.custom_minimum_size = Vector2(150.0, 0.0)
|
||||
var n := _ink(grid, 32)
|
||||
n.custom_minimum_size = Vector2(44.0, 0.0)
|
||||
n.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
return [i, l, n]
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(Vector2.ZERO, size), Color(0.0, 0.0, 0.0, 0.35)) # dims the farm behind
|
||||
|
||||
|
||||
## The sign behind the board's contents: two posts, the paper between them, a beam across its top
|
||||
## (under the title) and one across its bottom, nails, and leaves.
|
||||
func _draw_board() -> void:
|
||||
var b := _board
|
||||
var w := b.size.x
|
||||
var h := b.size.y
|
||||
var paper := Rect2(SIDE - 14.0, BEAM - 26.0, w - 2.0 * SIDE + 28.0, h - BEAM - BOTTOM + 52.0)
|
||||
var posts: Array[float] = [SIDE + 34.0, w - SIDE - 34.0]
|
||||
for k in 2:
|
||||
b.draw_set_transform(Vector2(posts[k], h * 0.5 + 8.0), PI * 0.5)
|
||||
Sketch.plank(b, Rect2(-h * 0.5 - 44.0, -27.0, h + 88.0, 54.0), Sketch.WOOD.darkened(0.08), 601.0 + k)
|
||||
b.draw_set_transform_matrix(Transform2D.IDENTITY)
|
||||
Sketch.paper(b, paper, 611.0)
|
||||
Sketch.plank(b, Rect2(0.0, h - BOTTOM - 4.0, w, 62.0), Sketch.WOOD.darkened(0.04), 621.0)
|
||||
Sketch.plank(b, Rect2(-24.0, 0.0, w + 48.0, BEAM), Sketch.WOOD, 631.0)
|
||||
for x: float in [paper.position.x + 26.0, paper.end.x - 26.0]:
|
||||
Sketch.nail(b, Vector2(x, paper.position.y + 46.0))
|
||||
for k in 2:
|
||||
Sketch.nail(b, Vector2(posts[k], BEAM * 0.5), 6.0)
|
||||
Sketch.nail(b, Vector2(posts[k], h - BOTTOM + 27.0), 6.0)
|
||||
Sketch.leaf(b, Vector2(28.0, 18.0), 46.0, -2.5, 641.0)
|
||||
Sketch.leaf(b, Vector2(34.0, 22.0), 40.0, -1.4, 642.0)
|
||||
Sketch.leaf(b, Vector2(w - 26.0, 16.0), 50.0, -0.5, 643.0)
|
||||
Sketch.leaf(b, Vector2(w - 30.0, 24.0), 38.0, 0.4, 644.0, Sketch.LEAF.lightened(0.12))
|
||||
Sketch.leaf(b, Vector2(posts[0] - 20.0, h - BOTTOM + 40.0), 42.0, 2.6, 645.0, Sketch.LEAF.darkened(0.1))
|
||||
|
||||
|
||||
static func _spacer(height: float) -> Control:
|
||||
var c := Control.new()
|
||||
c.custom_minimum_size = Vector2(0.0, height)
|
||||
return c
|
||||
|
||||
|
||||
## A Label in ink on the paper (no outline).
|
||||
func _ink(parent: Node, font_size: int, color: Color = Sketch.PAPER_INK) -> Label:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_color", color)
|
||||
Sketch.style(l, font_size, color, 0)
|
||||
parent.add_child(l)
|
||||
return l
|
||||
|
||||
|
||||
static func _or_none(text: String) -> String:
|
||||
return text if text != "" else "nothing"
|
||||
## An icon (Sketch.ICONS) drawn in a square, side long, centered in the control.
|
||||
class SketchIcon extends Control:
|
||||
var id := ""
|
||||
|
||||
func _init(p_id: String, side: float) -> void:
|
||||
id = p_id
|
||||
custom_minimum_size = Vector2(side, side)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
func _draw() -> void:
|
||||
var side := minf(size.x, size.y)
|
||||
Sketch.icon(self, id, Rect2((size - Vector2(side, side)) * 0.5, Vector2(side, side)))
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ extends RefCounted
|
|||
## (Gochi Hand, assets/fonts, SIL OFL) with a dark outline so text reads over the farm, wobbly
|
||||
## sketched outlines (each edge drawn twice, slightly off, overshooting its corners), painted
|
||||
## fills (a flat color, a lighter dab, a darker rim), and painted icons for the weapons, the
|
||||
## materials, the backpack, the sun and moon, and the scarecrow's portrait. Every wobble comes
|
||||
## from a hash of a seed, so a shape is drawn the same way each frame (no flicker).
|
||||
## materials, the backpack, the sun and moon, the scarecrow's portrait, what thieves take (crops,
|
||||
## animals, supplies), and the enemies; and the morning screen's wooden sign (planks, a nailed
|
||||
## sheet of paper, leaves). Every wobble comes from a hash of a seed, so a shape is drawn the
|
||||
## same way each frame (no flicker).
|
||||
## Icons are designed in a 100 x 100 box and scaled to the rect they're drawn in.
|
||||
|
||||
const FONT_PATH := "res://assets/fonts/GochiHand-Regular.ttf"
|
||||
|
|
@ -25,9 +27,19 @@ const RULE := Color(0.98, 0.97, 0.92, 0.35)
|
|||
const SLOT := Color(0.1, 0.24, 0.1, 0.62)
|
||||
const GOLD := Color(1.0, 0.86, 0.35)
|
||||
const TEXT_OUTLINE := 8
|
||||
## Icon ids (icon()): ScarecrowCombat.WEAPON_IDS, ResourceStore.MATERIALS, and these.
|
||||
## Text written on paper (the morning sign): ink without an outline, a faded ink for headings and
|
||||
## nothing-to-report, and a red for losses.
|
||||
const PAPER := Color(0.96, 0.87, 0.64)
|
||||
const PAPER_INK := Color(0.24, 0.15, 0.07)
|
||||
const PAPER_DIM := Color(0.5, 0.38, 0.24)
|
||||
const PAPER_RED := Color(0.74, 0.14, 0.08)
|
||||
const WOOD := Color(0.6, 0.38, 0.2)
|
||||
const LEAF := Color(0.42, 0.64, 0.22)
|
||||
## Icon ids (icon()): ScarecrowCombat.WEAPON_IDS, ResourceStore.MATERIALS, LootSystem.CATEGORY_KEYS,
|
||||
## EnemySystem.TYPE_NAMES, and these.
|
||||
const ICONS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb", "potato_cannon", "shurikens",
|
||||
"propane_torch", "alien_ray", "wood", "scrap", "straw", "alien_goop", "backpack", "sun", "moon", "portrait"]
|
||||
"propane_torch", "alien_ray", "wood", "scrap", "straw", "alien_goop", "backpack", "sun", "moon", "portrait",
|
||||
"crops", "animals", "supplies", "crow", "thief", "breaker", "ufo"]
|
||||
|
||||
static var _font: Font
|
||||
|
||||
|
|
@ -207,6 +219,91 @@ static func stroke(ci: CanvasItem, a: Vector2, b: Vector2, color: Color, width:
|
|||
line(ci, a, b, color, width, seed, 0.8)
|
||||
|
||||
|
||||
## A painted wooden beam lying along r's width: bark-edged, grain lines along it, a knot, and the
|
||||
## sawn end grain (a pale ring) at each end.
|
||||
static func plank(ci: CanvasItem, r: Rect2, color: Color, seed: float) -> void:
|
||||
var t := r.size.y
|
||||
var pts := PackedVector2Array()
|
||||
var n := clampi(int(r.size.x / 60.0), 2, 24)
|
||||
for i in n + 1:
|
||||
pts.append(Vector2(lerpf(r.position.x, r.end.x, float(i) / n), r.position.y) + Vector2(0.0, noise(seed + i) * t * 0.06))
|
||||
for i in n + 1:
|
||||
pts.append(Vector2(lerpf(r.end.x, r.position.x, float(i) / n), r.end.y) + Vector2(0.0, noise(seed + 40.0 + i) * t * 0.06))
|
||||
ci.draw_colored_polygon(pts, color)
|
||||
ci.draw_colored_polygon(_band(r, 0.1, 0.36, seed + 20.0), Color(color.lightened(0.2), 0.7))
|
||||
ci.draw_colored_polygon(_band(r, 0.74, 0.94, seed + 30.0), Color(color.darkened(0.22), 0.7))
|
||||
var grain := Color(color.darkened(0.4), 0.85)
|
||||
for k in 4:
|
||||
var y := r.position.y + t * (0.24 + 0.17 * k + noise(seed + 70.0 + k) * 0.04)
|
||||
var x0 := r.position.x + t * 0.4 + r.size.x * (0.05 + 0.15 * absf(noise(seed + 80.0 + k)))
|
||||
var x1 := r.end.x - t * 0.4 - r.size.x * (0.05 + 0.15 * absf(noise(seed + 90.0 + k)))
|
||||
line(ci, Vector2(x0, y), Vector2(x1, y), grain, 2.0, seed + 100.0 + k, 1.6)
|
||||
var knot := Vector2(lerpf(r.position.x, r.end.x, 0.3 + 0.4 * absf(noise(seed + 110.0))), r.get_center().y)
|
||||
paint(ci, blob(knot, t * 0.16, t * 0.1, seed + 111.0), color.darkened(0.25), seed + 112.0, 1.5)
|
||||
outline(ci, pts, Color(color.darkened(0.62), 0.95), 3.0, seed + 0.5, 0.8, 1)
|
||||
for x: float in [r.position.x, r.end.x]:
|
||||
var end := Vector2(x, r.get_center().y)
|
||||
paint(ci, blob(end, t * 0.16, t * 0.5, seed + x * 0.01, 0.06), color.lightened(0.32), seed + 113.0, 2.0)
|
||||
circle(ci, end, t * 0.2, Color(color.darkened(0.2), 0.8), 1.5, seed + 114.0)
|
||||
|
||||
|
||||
## A strip along a plank (r) between fractions a and b of its thickness, short of its ends.
|
||||
static func _band(r: Rect2, a: float, b: float, seed: float) -> PackedVector2Array:
|
||||
var t := r.size.y
|
||||
var x0 := r.position.x + t * 0.3
|
||||
var x1 := r.end.x - t * 0.3
|
||||
var top := line_points(Vector2(x0, r.position.y + t * a), Vector2(x1, r.position.y + t * a), seed, t * 0.04)
|
||||
var bottom := line_points(Vector2(x1, r.position.y + t * b), Vector2(x0, r.position.y + t * b), seed + 1.0, t * 0.04)
|
||||
top.append_array(bottom)
|
||||
return top
|
||||
|
||||
|
||||
## A sheet of paper with soft, torn edges, browned toward them, and a stain or two.
|
||||
static func paper(ci: CanvasItem, r: Rect2, seed: float, color: Color = PAPER) -> void:
|
||||
var edge := _torn(r, seed, 0.0)
|
||||
ci.draw_colored_polygon(edge, color.darkened(0.12))
|
||||
ci.draw_colored_polygon(_torn(r, seed + 50.0, 13.0), color)
|
||||
for k in 2:
|
||||
var at := r.position + r.size * Vector2(0.12 + 0.76 * k, 0.8 - 0.6 * k) + jitter(seed + 5.0 + k, 30.0)
|
||||
ci.draw_colored_polygon(blob(at, 46.0, 34.0, seed + 6.0 + k, 0.12), Color(color.darkened(0.2), 0.18))
|
||||
outline(ci, edge, Color(color.darkened(0.6), 0.9), 2.5, seed + 1.0, 0.8, 1)
|
||||
var crease := Vector2(r.end.x, lerpf(r.position.y, r.end.y, 0.35 + 0.3 * absf(noise(seed + 3.0))))
|
||||
line(ci, crease, crease + Vector2(-r.size.x * 0.12, 8.0), Color(color.darkened(0.35), 0.6), 2.0, seed + 4.0)
|
||||
|
||||
|
||||
## Points around r, every edge ripped a little; inset pulls them toward the middle.
|
||||
static func _torn(r: Rect2, seed: float, inset: float) -> PackedVector2Array:
|
||||
var inner := r.grow(-inset)
|
||||
var c := [inner.position, Vector2(inner.end.x, inner.position.y), inner.end, Vector2(inner.position.x, inner.end.y)]
|
||||
var pts := PackedVector2Array()
|
||||
for side in 4:
|
||||
var a: Vector2 = c[side]
|
||||
var b: Vector2 = c[(side + 1) % 4]
|
||||
var n := maxi(int(a.distance_to(b) / 34.0), 2)
|
||||
for i in n:
|
||||
pts.append(a.lerp(b, float(i) / n) + jitter(seed + side * 31.0 + i, 3.0))
|
||||
return pts
|
||||
|
||||
|
||||
## A leaf from base, length long, pointing along angle.
|
||||
static func leaf(ci: CanvasItem, base: Vector2, length: float, angle: float, seed: float, color: Color = LEAF) -> void:
|
||||
var dir := Vector2.from_angle(angle)
|
||||
var side := dir.orthogonal() * length * 0.38
|
||||
var tip := base + dir * length
|
||||
var mid := base + dir * length * 0.45
|
||||
var pts := _bezier(base, mid + side, tip, 8)
|
||||
pts.append_array(_bezier(tip, mid - side, base, 8).slice(1, -1))
|
||||
paint(ci, pts, color, seed, 2.0)
|
||||
line(ci, base, tip - dir * length * 0.15, Color(color.darkened(0.45), 0.9), 1.6, seed + 1.0, 1.0)
|
||||
|
||||
|
||||
## A nail head.
|
||||
static func nail(ci: CanvasItem, at: Vector2, radius: float = 5.0) -> void:
|
||||
ci.draw_circle(at, radius + 1.5, INK)
|
||||
ci.draw_circle(at, radius, Color(0.5, 0.48, 0.45))
|
||||
ci.draw_circle(at - Vector2(radius, radius) * 0.3, radius * 0.4, Color(0.8, 0.78, 0.74))
|
||||
|
||||
|
||||
static func _bezier(a: Vector2, q: Vector2, b: Vector2, n: int) -> PackedVector2Array:
|
||||
var pts := PackedVector2Array()
|
||||
for i in n + 1:
|
||||
|
|
@ -345,6 +442,85 @@ static func _icon(ci: CanvasItem, id: String) -> void:
|
|||
paint(ci, PackedVector2Array([Vector2(31, 42), Vector2(69, 41), Vector2(65, 11), Vector2(35, 12)]), Color(0.62, 0.42, 0.22), 190.0)
|
||||
paint(ci, PackedVector2Array([Vector2(32, 35), Vector2(68, 34), Vector2(68, 41), Vector2(32, 42)]), Color(0.42, 0.26, 0.14), 191.0, 0.0)
|
||||
paint(ci, blob(Vector2(50, 43), 44.0, 8.0, 192.0, 0.03, 28, -0.06), Color(0.72, 0.52, 0.28), 193.0)
|
||||
"crops": # an ear of corn in its husk
|
||||
paint(ci, blob(Vector2(50, 42), 16.0, 32.0, 201.0, 0.03), Color(0.98, 0.82, 0.24), 202.0)
|
||||
for row in 6:
|
||||
for col in 3:
|
||||
ci.draw_circle(Vector2(43.0 + col * 7.0 + (row % 2) * 2.0, 22.0 + row * 8.0), 2.3, Color(0.86, 0.6, 0.1))
|
||||
paint(ci, PackedVector2Array([Vector2(48, 94), Vector2(26, 78), Vector2(16, 42), Vector2(32, 54), Vector2(46, 72)]), LEAF.lightened(0.1), 203.0, 2.0)
|
||||
paint(ci, PackedVector2Array([Vector2(52, 94), Vector2(54, 72), Vector2(68, 54), Vector2(84, 42), Vector2(74, 78)]), LEAF.darkened(0.08), 204.0, 2.0)
|
||||
"animals": # a pig
|
||||
var pink := Color(0.98, 0.66, 0.72)
|
||||
paint(ci, PackedVector2Array([Vector2(18, 44), Vector2(22, 12), Vector2(46, 30)]), pink.darkened(0.12), 211.0, 2.0)
|
||||
paint(ci, PackedVector2Array([Vector2(82, 44), Vector2(78, 12), Vector2(54, 30)]), pink.darkened(0.12), 212.0, 2.0)
|
||||
paint(ci, blob(Vector2(50, 57), 38.0, 33.0, 213.0, 0.03), pink, 214.0)
|
||||
paint(ci, blob(Vector2(50, 67), 16.0, 11.0, 215.0, 0.03), Color(0.93, 0.5, 0.58), 216.0, 2.0)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
ci.draw_circle(Vector2(50.0 + 6.0 * k, 67.0), 3.2, Color(0.45, 0.16, 0.2))
|
||||
ci.draw_circle(Vector2(50.0 + 15.0 * k, 46.0), 4.2, INK)
|
||||
ci.draw_circle(Vector2(51.4 + 15.0 * k, 44.6), 1.4, Color.WHITE)
|
||||
"supplies": # a sack tied at the neck
|
||||
var burlap := Color(0.8, 0.64, 0.4)
|
||||
paint(ci, PackedVector2Array([Vector2(36, 34), Vector2(64, 34), Vector2(80, 54), Vector2(84, 80), Vector2(70, 93),
|
||||
Vector2(30, 93), Vector2(16, 80), Vector2(20, 54)]), burlap, 221.0)
|
||||
paint(ci, PackedVector2Array([Vector2(38, 36), Vector2(28, 14), Vector2(43, 23), Vector2(50, 11), Vector2(57, 23),
|
||||
Vector2(72, 14), Vector2(62, 36)]), burlap.lightened(0.08), 222.0, 2.0)
|
||||
stroke(ci, Vector2(34.0, 35.0), Vector2(66.0, 35.0), Color(0.55, 0.36, 0.18), 4.0, 223.0)
|
||||
line(ci, Vector2(32, 58), Vector2(40, 84), burlap.darkened(0.3), 2.0, 224.0)
|
||||
line(ci, Vector2(66, 58), Vector2(62, 82), burlap.darkened(0.3), 2.0, 225.0)
|
||||
"crow":
|
||||
var black := Color(0.15, 0.15, 0.19)
|
||||
var beak := Color(0.98, 0.72, 0.18)
|
||||
paint(ci, PackedVector2Array([Vector2(32, 60), Vector2(6, 72), Vector2(10, 84), Vector2(38, 72)]), black, 231.0, 2.0)
|
||||
for x: float in [44.0, 54.0]:
|
||||
line(ci, Vector2(x, 74.0), Vector2(x - 2.0, 92.0), beak.darkened(0.2), 3.0, 232.0 + x, 0.6)
|
||||
paint(ci, blob(Vector2(46, 60), 27.0, 18.0, 233.0, 0.04, 28, -0.25), black, 234.0)
|
||||
paint(ci, blob(Vector2(68, 37), 15.0, 14.0, 235.0), black, 236.0)
|
||||
paint(ci, PackedVector2Array([Vector2(80, 32), Vector2(97, 41), Vector2(80, 46)]), beak, 237.0, 1.5)
|
||||
paint(ci, PackedVector2Array([Vector2(28, 52), Vector2(56, 45), Vector2(62, 58), Vector2(38, 70)]), black.lightened(0.2), 238.0, 2.0)
|
||||
ci.draw_circle(Vector2(71, 34), 4.2, Color(1.0, 0.95, 0.8))
|
||||
ci.draw_circle(Vector2(72, 34), 2.2, INK)
|
||||
"thief": # an alien
|
||||
var skin := Color(0.58, 0.52, 0.72)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
line(ci, Vector2(50.0 + 10.0 * k, 26.0), Vector2(50.0 + 22.0 * k, 9.0), INK, 3.0, 241.0 + k, 0.6)
|
||||
paint(ci, blob(Vector2(50.0 + 23.0 * k, 8.0), 5.5, 5.5, 243.0 + k), Color(0.55, 0.95, 0.35), 245.0 + k, 1.5)
|
||||
var head := PackedVector2Array()
|
||||
for i in 32:
|
||||
var a := TAU * i / 32.0
|
||||
var down := maxf(sin(a), 0.0)
|
||||
head.append(Vector2(50, 52) + Vector2(cos(a) * 33.0 * (1.0 - 0.5 * down), sin(a) * (40.0 if sin(a) > 0.0 else 30.0))
|
||||
+ jitter(247.0 + i, 0.6))
|
||||
paint(ci, head, skin, 248.0)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
paint(ci, blob(Vector2(50.0 + 14.0 * k, 55.0), 12.0, 7.5, 249.0 + k, 0.03, 20, -0.5 * k), INK, 251.0 + k, 0.0)
|
||||
ci.draw_circle(Vector2(47.0 + 14.0 * k, 52.5), 2.2, Color(0.85, 1.0, 0.75))
|
||||
line(ci, Vector2(45, 78), Vector2(55, 78), skin.darkened(0.55), 2.5, 253.0, 0.6)
|
||||
"breaker": # an alien robot
|
||||
var rust := Color(0.8, 0.38, 0.24)
|
||||
var metal := Color(0.58, 0.6, 0.64)
|
||||
line(ci, Vector2(50, 24), Vector2(50, 9), INK, 3.5, 261.0, 0.5)
|
||||
paint(ci, blob(Vector2(50, 9), 6.0, 6.0, 262.0), Color(1.0, 0.85, 0.3), 263.0, 1.5)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
paint(ci, PackedVector2Array([Vector2(50.0 + 30.0 * k, 40), Vector2(50.0 + 41.0 * k, 41), Vector2(50.0 + 41.0 * k, 63),
|
||||
Vector2(50.0 + 30.0 * k, 64)]), metal, 264.0 + k, 2.0)
|
||||
paint(ci, PackedVector2Array([Vector2(18, 24), Vector2(82, 22), Vector2(84, 82), Vector2(16, 84)]), rust, 266.0)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
paint(ci, blob(Vector2(50.0 + 16.0 * k, 46.0), 10.0, 10.0, 267.0 + k), Color(1.0, 0.86, 0.32), 269.0 + k, 2.5)
|
||||
ci.draw_circle(Vector2(50.0 + 16.0 * k, 46.0), 3.5, INK)
|
||||
ci.draw_circle(Vector2(50.0 + 30.0 * k, 30.0), 2.2, rust.darkened(0.5))
|
||||
ci.draw_circle(Vector2(50.0 + 30.0 * k, 76.0), 2.2, rust.darkened(0.5))
|
||||
paint(ci, PackedVector2Array([Vector2(30, 63), Vector2(70, 62), Vector2(70, 74), Vector2(30, 75)]), Color(0.3, 0.14, 0.1), 271.0, 2.0)
|
||||
for i in 4:
|
||||
line(ci, Vector2(38.0 + i * 8.0, 64.0), Vector2(38.0 + i * 8.0, 73.0), metal, 2.0, 272.0 + i, 0.4)
|
||||
"ufo":
|
||||
ci.draw_colored_polygon(PackedVector2Array([Vector2(38, 66), Vector2(62, 66), Vector2(80, 98), Vector2(20, 98)]), Color(0.7, 1.0, 0.5, 0.4))
|
||||
paint(ci, blob(Vector2(50, 46), 21.0, 19.0, 281.0), Color(0.62, 0.9, 0.95), 282.0)
|
||||
paint(ci, blob(Vector2(50, 62), 34.0, 8.0, 283.0, 0.02), Color(0.42, 0.44, 0.5), 284.0, 2.0)
|
||||
paint(ci, blob(Vector2(50, 56), 46.0, 12.0, 285.0, 0.02), Color(0.7, 0.72, 0.78), 286.0)
|
||||
for i in 5:
|
||||
ci.draw_circle(Vector2(18.0 + i * 16.0, 57.0 + absf(i - 2.0) * -1.5), 3.6, Color(1.0, 0.86, 0.35))
|
||||
ci.draw_circle(Vector2(43, 38), 3.5, Color(1.0, 1.0, 1.0, 0.85))
|
||||
|
||||
|
||||
## Points along a circle (center c, radius r) between where it crosses another circle (o, ro),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue