#162 - a single tap bought a research node outright. One physical tap arrives TWICE: Godot emulates a mouse button from every touch AND a touch from every mouse button, both project settings are on, and the menu's dispatcher routes InputEventScreenTouch and InputEventMouseButton alike to the tree. The second arrival found the node already selected and took itself for the confirming tap. Measured, not reasoned about - one tap produced two picks and two confirms. What is ignored is specifically the TWIN: same frame, same place, arriving through the other input kind. Deduping on frame and position alone also swallowed two genuine taps in one frame, which the test caught. #164 - the build menu predicted a caption's height from the COLUMN WIDTH: wide column, assume one line. Right for most names and wrong for the long ones, so "Spacial Workshop" wrapped onto the price beneath it. Captions are now measured against the font that draws them, and prices sized from PriceTag.wanted_height(), which existed for exactly this and was not being asked. Prices are set before anything is measured, because the old order laid out first and priced afterwards. The ship lab: its buy button is gone and a second tap on an option buys it, the same rule as the research tree; the explanation drops into the room that freed; research points move up into the resource table, where everything else being spent already is; the second row of options is placed from the first row's measured bottom rather than a constant; and the vessel strip is spaced from the panel's own width, so the eighth vessel is no longer half off the right edge. #160 - the quest panel was drawn BEFORE the sticks and the pivot pair, so they sat on top of it. Moved after them, under the narration banner. Its title rule ran straight through the close button; the header band is now as tall as that button. #161 - the prologue widens the formation into a freight convoy by writing over GameState.formation, and nothing put it back. The player flew the convoy's 600-unit spread for the rest of the game - a shape nobody chose, which reads as the fleet having drifted apart. #163 - a quest to station a vessel at the outpost, after the one that asks for the outpost. Building one and crewing it are different acts, and an empty outpost holds nothing. #165 - the gas bomb's blast and a vessel arriving fast both damage a structure. The blast used to stop politely at anything the player owned, which made a bomb dropped on a besieged mothership a free way to sweep the attackers off it. Collisions are caught on ENTRY, not on the 0.7s strike tick: a vessel is only moving fast for the instant it arrives, and a ship sent in at 900 did no damage at all until this moved. Docking is free - the fleet sits on its own mothership constantly to bank ore - and garrison vessels are exempt outright, because they launch from their outpost and re-dock with it at speed. The suite caught that one: the ram rule was destroying the garrison as it launched. Suite 153/153. Four tests changed because what they pinned moved: the lab's buy button, the intro's formation, the research tree's tap delivery, and the build menu's own preview. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
4c920f10b0
commit
3fcc26c8bc
18 changed files with 645 additions and 173 deletions
|
|
@ -43,7 +43,10 @@ const VESSEL_DEFINITIONS = preload("res://vessels/VesselDefinitions.gd")
|
|||
]
|
||||
@onready var lab_detail: Label = get_node("../UI/LabMenu/DetailLabel")
|
||||
@onready var lab_status: Label = get_node("../UI/LabMenu/StatusLabel")
|
||||
@onready var lab_buy_button: IconButton = get_node("../UI/LabMenu/BuyButton")
|
||||
# What the buy button's `enabled` used to carry. The button is gone (#164) but
|
||||
# the question it answered - is this option actually purchasable right now -
|
||||
# still gates the confirming tap.
|
||||
var lab_can_buy: bool = false
|
||||
@onready var lab_close_button: IconButton = get_node("../UI/LabMenu/CloseButton")
|
||||
@onready var lab_upgrade_buttons: Array = [
|
||||
get_node("../UI/LabMenu/Upgrade0"), get_node("../UI/LabMenu/Upgrade1"),
|
||||
|
|
@ -283,7 +286,6 @@ func _ready() -> void:
|
|||
planning_panel.changed.connect(_refresh_planning)
|
||||
_configure_build_menu_entries()
|
||||
lab_close_button.pressed.connect(func(): lab_menu.visible = false)
|
||||
lab_buy_button.pressed.connect(_on_lab_buy)
|
||||
for i in range(lab_vessel_buttons.size()):
|
||||
lab_vessel_buttons[i].pressed.connect(_on_lab_vessel.bind(i))
|
||||
for i in range(lab_upgrade_buttons.size()):
|
||||
|
|
@ -717,6 +719,10 @@ const MENU_LABEL_SHARE: float = 0.46
|
|||
const MENU_ONE_LINE_HALF: float = 120.0
|
||||
const MENU_LABEL_H_ONE: float = 52.0
|
||||
const MENU_LABEL_H_TWO: float = 68.0
|
||||
# Breathing room around a measured caption and a measured price, so glyphs
|
||||
# never sit flush against the row below them.
|
||||
const MENU_LABEL_PADDING: float = 10.0
|
||||
const MENU_COST_PADDING: float = 12.0
|
||||
|
||||
const MENU_SIDE_MARGIN: float = 24.0
|
||||
const MENU_HEADER_GAP: float = 16.0
|
||||
|
|
@ -773,9 +779,51 @@ func menu_label_half(columns: int) -> float:
|
|||
return menu_column_spacing(columns) * MENU_LABEL_SHARE
|
||||
|
||||
|
||||
# How tall a caption of `text` really is at this column width, measured
|
||||
# against the font that will draw it.
|
||||
#
|
||||
# This used to be a guess from the column width alone: wide column, assume one
|
||||
# line; narrow column, assume two. That is right for most names and wrong for
|
||||
# the long ones - "Spacial Workshop" wrapped to two lines in a column the rule
|
||||
# called wide enough for one, and the second line came down on top of the
|
||||
# price underneath it (#164). A name is as tall as it is; asking the font is
|
||||
# both simpler and correct for names nobody has written yet.
|
||||
func measured_label_height(label: Label, text: String, columns: int) -> float:
|
||||
var font: Font = label.get_theme_font("font")
|
||||
var size: int = label.get_theme_font_size("font_size")
|
||||
if font == null or size <= 0 or text == "":
|
||||
return MENU_LABEL_H_ONE
|
||||
var width: float = menu_label_half(columns) * 2.0
|
||||
var height: float = font.get_multiline_string_size(text,
|
||||
HORIZONTAL_ALIGNMENT_CENTER, width, size).y
|
||||
# A floor of the one-line height keeps single-line captions on the rhythm
|
||||
# the menu already had, rather than tightening around the glyphs.
|
||||
return maxf(MENU_LABEL_H_ONE, height + MENU_LABEL_PADDING)
|
||||
|
||||
|
||||
# The tallest caption among the entries currently shown. The grid is a grid -
|
||||
# every row uses the same offsets - so one long name sets the height for all
|
||||
# of them, which is what keeps the columns lined up.
|
||||
func menu_label_height(columns: int) -> float:
|
||||
return MENU_LABEL_H_ONE if menu_label_half(columns) >= MENU_ONE_LINE_HALF \
|
||||
else MENU_LABEL_H_TWO
|
||||
var tallest: float = MENU_LABEL_H_ONE
|
||||
for entry in build_menu_entries:
|
||||
var label: Label = entry[2]
|
||||
if label.visible:
|
||||
tallest = maxf(tallest, measured_label_height(label, label.text, columns))
|
||||
return tallest
|
||||
|
||||
|
||||
# The tallest price among the entries currently shown, asked of the tags
|
||||
# themselves rather than assumed. A structure costing three resources stacks
|
||||
# three lines (see PriceTag), and the fixed height this replaces was sized for
|
||||
# two - so the third line ran into whatever the grid put underneath (#164).
|
||||
func menu_cost_height() -> float:
|
||||
var tallest: float = MENU_COST_H
|
||||
for entry in build_menu_entries:
|
||||
var tag: Control = entry[3]
|
||||
if tag.visible and tag.has_method("wanted_height"):
|
||||
tallest = maxf(tallest, float(tag.wanted_height()) + MENU_COST_PADDING)
|
||||
return tallest
|
||||
|
||||
|
||||
func menu_cost_offset(columns: int) -> float:
|
||||
|
|
@ -784,7 +832,7 @@ func menu_cost_offset(columns: int) -> float:
|
|||
|
||||
# How tall one row is, end to end - the cost strip is the last thing in it.
|
||||
func menu_row_height(columns: int) -> float:
|
||||
return menu_cost_offset(columns) + MENU_COST_H
|
||||
return menu_cost_offset(columns) + menu_cost_height()
|
||||
|
||||
|
||||
# The fewest columns whose rows fit the band. Two is the shape the menu is
|
||||
|
|
@ -840,6 +888,13 @@ func _layout_build_menu() -> void:
|
|||
entry[2].visible = visible
|
||||
entry[3].visible = visible
|
||||
if visible:
|
||||
# Priced BEFORE anything is measured. The row's height now comes
|
||||
# from the price tag's own wanted_height(), and _refresh_build_
|
||||
# status() sets prices only after calling this - so on the first
|
||||
# layout every tag was still empty and every row was sized for a
|
||||
# price that was not there yet. show_price() early-outs when the
|
||||
# price has not changed, so restating it here costs nothing.
|
||||
entry[3].show_price(GameState.building_costs(String(entry[0])))
|
||||
shown.append(entry)
|
||||
|
||||
var columns: int = menu_columns(shown.size())
|
||||
|
|
@ -848,6 +903,7 @@ func _layout_build_menu() -> void:
|
|||
var label_half: float = menu_label_half(columns)
|
||||
var label_h: float = menu_label_height(columns)
|
||||
var cost_offset: float = menu_cost_offset(columns)
|
||||
var cost_height: float = menu_cost_height()
|
||||
|
||||
for i in range(shown.size()):
|
||||
var row: int = i / columns
|
||||
|
|
@ -859,7 +915,7 @@ func _layout_build_menu() -> void:
|
|||
var top: float = menu_row_top(row, rows, columns)
|
||||
_place_entry(shown[i][1], cx, top, MENU_BUTTON_HALF, MENU_BUTTON_H)
|
||||
_place_entry(shown[i][2], cx, top + MENU_LABEL_OFFSET, label_half, label_h)
|
||||
_place_entry(shown[i][3], cx, top + cost_offset, MENU_COST_HALF, MENU_COST_H)
|
||||
_place_entry(shown[i][3], cx, top + cost_offset, MENU_COST_HALF, cost_height)
|
||||
|
||||
|
||||
func _refresh_build_status() -> void:
|
||||
|
|
@ -1260,6 +1316,78 @@ func _build_craft_price_strips() -> void:
|
|||
# option block is the same height it was and the row below it does not move.
|
||||
const LAB_TAG_H: float = 38.0
|
||||
const LAB_LABEL_H: float = 40.0
|
||||
# Room around a stacked price, so its last line never sits flush against the
|
||||
# option underneath.
|
||||
const LAB_TAG_PADDING: float = 8.0
|
||||
# Between the bottom of one option's price and the top of the option below.
|
||||
const LAB_ROW_GAP: float = 18.0
|
||||
|
||||
|
||||
# How tall the lab's price strips need to be: the tallest any of them wants,
|
||||
# asked of the tags rather than assumed. Every strip gets the same height so
|
||||
# the two columns stay level with each other.
|
||||
# Re-seats the option grid around whatever the prices actually need. The two
|
||||
# rows are authored at fixed offsets in the scene, which is fine while every
|
||||
# price is one line and wrong the moment one stacks - the second row's buttons
|
||||
# sat where the first row's price had grown into (#164). Row one keeps its
|
||||
# authored place; row two is pushed to clear it.
|
||||
# The vessel strip is authored at fixed offsets, which fits exactly as many
|
||||
# vessels as there were when it was written. The catalog has grown since - the
|
||||
# eighth ran off the right edge, its caption clipped in half - so the row is
|
||||
# spaced from the panel's actual width and centred, the way every other grid
|
||||
# in this menu already is.
|
||||
const LAB_VESSEL_HALF: float = 30.0
|
||||
const LAB_VESSEL_NATURAL_SPACING: float = 90.0
|
||||
const LAB_VESSEL_MARGIN: float = 24.0
|
||||
|
||||
|
||||
func _layout_lab_vessels() -> void:
|
||||
var shown: Array = []
|
||||
for i in range(lab_vessel_buttons.size()):
|
||||
if lab_vessel_buttons[i].visible:
|
||||
shown.append(i)
|
||||
if shown.is_empty():
|
||||
return
|
||||
var room: float = lab_menu.size.x - LAB_VESSEL_MARGIN * 2.0
|
||||
if room <= 0.0:
|
||||
room = 672.0
|
||||
var spacing: float = minf(LAB_VESSEL_NATURAL_SPACING, room / float(shown.size()))
|
||||
for slot in range(shown.size()):
|
||||
var i: int = shown[slot]
|
||||
var cx: float = (float(slot) - (float(shown.size()) - 1.0) * 0.5) * spacing
|
||||
lab_vessel_buttons[i].offset_left = cx - LAB_VESSEL_HALF
|
||||
lab_vessel_buttons[i].offset_right = cx + LAB_VESSEL_HALF
|
||||
# The caption is allowed the full column, so two-word names wrap
|
||||
# inside their own slot instead of over the vessel beside them.
|
||||
lab_vessel_labels[i].offset_left = cx - spacing * 0.5
|
||||
lab_vessel_labels[i].offset_right = cx + spacing * 0.5
|
||||
|
||||
|
||||
func _resize_lab_price_tags() -> void:
|
||||
var height: float = lab_tag_height()
|
||||
for tag in lab_price_tags:
|
||||
if tag != null:
|
||||
tag.offset_bottom = tag.offset_top + height
|
||||
if lab_price_tags.size() < 3 or lab_upgrade_buttons.size() < 3:
|
||||
return
|
||||
var first_row_bottom: float = lab_price_tags[0].offset_bottom
|
||||
var shift: float = first_row_bottom + LAB_ROW_GAP - lab_upgrade_buttons[2].offset_top
|
||||
if absf(shift) < 0.5:
|
||||
return
|
||||
for i in range(2, lab_upgrade_buttons.size()):
|
||||
for node in [lab_upgrade_buttons[i], lab_upgrade_labels[i], lab_price_tags[i]]:
|
||||
if node == null:
|
||||
continue
|
||||
node.offset_top += shift
|
||||
node.offset_bottom += shift
|
||||
|
||||
|
||||
func lab_tag_height() -> float:
|
||||
var tallest: float = LAB_TAG_H
|
||||
for tag in lab_price_tags:
|
||||
if tag != null and tag.has_method("wanted_height"):
|
||||
tallest = maxf(tallest, float(tag.wanted_height()) + LAB_TAG_PADDING)
|
||||
return tallest
|
||||
|
||||
|
||||
func _build_lab_price_tags() -> void:
|
||||
|
|
@ -1278,7 +1406,11 @@ func _build_lab_price_tags() -> void:
|
|||
# together occupy what the two-line caption used to.
|
||||
label.offset_bottom = label.offset_top + LAB_LABEL_H
|
||||
tag.offset_top = label.offset_bottom + 2.0
|
||||
tag.offset_bottom = tag.offset_top + LAB_TAG_H
|
||||
# Tall enough for the tallest price any upgrade carries, not for the
|
||||
# one the constant was written against. An upgrade costing ore AND a
|
||||
# research point stacks two lines (see PriceTag), and the second was
|
||||
# landing on the option below it (#164).
|
||||
tag.offset_bottom = tag.offset_top + lab_tag_height()
|
||||
lab_menu.add_child(tag)
|
||||
lab_price_tags.append(tag)
|
||||
|
||||
|
|
@ -1388,11 +1520,20 @@ func _on_lab_vessel(index: int) -> void:
|
|||
_refresh_lab()
|
||||
|
||||
|
||||
# #164: the separate buy button is gone, so the option itself is the control.
|
||||
# Same rule as the research tree (#83): the first tap selects and fills in the
|
||||
# detail below it, a second tap on the SAME option buys - no timed double-tap
|
||||
# to miss, and never a blind commitment, because the first tap always shows
|
||||
# what the second will cost.
|
||||
func _on_lab_upgrade(index: int) -> void:
|
||||
if index < 0 or index >= _lab_options().size():
|
||||
return
|
||||
var confirming: bool = index == lab_choice
|
||||
lab_choice = index
|
||||
lab_status.text = ""
|
||||
if confirming and lab_can_buy:
|
||||
_on_lab_buy()
|
||||
return
|
||||
_refresh_lab()
|
||||
|
||||
|
||||
|
|
@ -1456,10 +1597,16 @@ func _refresh_lab() -> void:
|
|||
lab_upgrade_buttons[i].highlighted = i == lab_choice
|
||||
lab_upgrade_buttons[i].enabled = true
|
||||
lab_upgrade_buttons[i].queue_redraw()
|
||||
_layout_lab_vessels()
|
||||
|
||||
# Re-height the strips now that every price on show is set. They are
|
||||
# created before any price exists, so their built-in size is only a
|
||||
# starting point.
|
||||
_resize_lab_price_tags()
|
||||
|
||||
if options.is_empty():
|
||||
lab_detail.text = ""
|
||||
lab_buy_button.enabled = false
|
||||
lab_buy_button.queue_redraw()
|
||||
lab_can_buy = false
|
||||
return
|
||||
lab_choice = clampi(lab_choice, 0, options.size() - 1)
|
||||
|
||||
|
|
@ -1469,7 +1616,7 @@ func _refresh_lab() -> void:
|
|||
if choice_points > 0:
|
||||
lab_detail.text += "\nResearch points: %d/%d" % [GameState.research_points, choice_points]
|
||||
var queued: Dictionary = GameState.lab_research_order(lab_building_id)
|
||||
lab_buy_button.enabled = queued.is_empty() and (choice.unlock or not GameState.upgrade_maxed(choice.id))
|
||||
lab_can_buy = queued.is_empty() and (choice.unlock or not GameState.upgrade_maxed(choice.id))
|
||||
if not queued.is_empty():
|
||||
var queued_points: int = GameState.research_point_cost(String(queued.id))
|
||||
if not bool(queued.started) and GameState.research_points < queued_points:
|
||||
|
|
@ -1480,7 +1627,6 @@ func _refresh_lab() -> void:
|
|||
% [queued_points, "" if queued_points == 1 else "s", GameState.research_points]
|
||||
else:
|
||||
lab_status.text = "%s %d%%" % ["Researching" if bool(queued.started) else "Waiting for resources", int(100.0 * float(queued.elapsed) / maxf(GameState.lab_research_time(), 0.001))]
|
||||
lab_buy_button.queue_redraw()
|
||||
|
||||
|
||||
func _upgrade_icon(option: Dictionary) -> IconButton.Icon:
|
||||
|
|
|
|||
Loading…
Reference in a new issue