#145, #144, #143: a quest that could not be finished, and two boxes that overhung

#145 - the extractor quest could never be completed. Extractors are placed
onto a planet from space and live in GameState.extractors, with their own
position, stock and id; they are not in `buildings`. So the goal asked
has_building_of_type("extractor"), which is false however many the player
builds. Not the death the reporter guessed at - the quest was simply asking
a question that had no yes.

structure_exists() is the question anything wanting "does the player have
one of these" should ask, and the quest model asks it now. The regression
test builds every structure quest's target THE WAY THE GAME BUILDS IT and
watches the goal flip, rather than knowing which array each one lands in -
the knowing is what got this wrong in the first place.

#144 - the build menu's status line is anchored to the top of the panel and
its grid to the panel's centre, so the gap between the two is half the panel
height. It was a written-down constant, correct only at 1280 tall; at 1080
the grid started four pixels ABOVE the status line and drew through it.

Nothing about that geometry is written against a screen size any more. The
band is measured from the header that is actually there, the pitch closes up
to fit it (never below a row's own height, which is what makes overlap
impossible rather than unlikely), and the column count rises until the rows
fit - so a short window gets a wide grid instead of one running off the
bottom. Ten structures now lay out as 5 columns at 900px tall, 4 at 1080, 3
at 1280 and 2 at 1600, clearing the header at every one, which is what the
test walks.

#143 - a hangar caption is "Gas Bomber\n2 available": two lines before
autowrap and three after it in a narrow column, at a size fixed in the
scene. Labels do not clip by default, so the third line was drawn over the
icon of the row below. The size is fitted to the box the layout works out,
and the box clips - the first keeps it legible, the second keeps it correct
however the vessel names grow.

Its box also overhung by exactly HANGAR_LABEL_GAP: the layout subtracted one
gap where it needed two, above the caption and below it. Two pixels, but two
pixels inside the next row's icon.
This commit is contained in:
Loïc Wisniewski 2026-08-29 12:51:09 +02:00
commit 2206b55873
5 changed files with 267 additions and 55 deletions

View file

@ -680,56 +680,101 @@ func _planet_under_fleet() -> Node2D:
# The build menu's grid.
#
# #136: rows used to be a written-down list of tops, read with
# `tops[mini(row, tops.size() - 1)]`. That clamp is the bug the ticket
# reported: with every structure researched the menu wanted a fourth row and
# the list had three, so the last entry was placed on the third row's centre
# slot - the gas burner drawn exactly on top of the transport hub. A list
# that silently stacks whatever will not fit in it is not a layout.
# `tops[mini(row, tops.size() - 1)]`. That clamp silently stacked whatever
# would not fit - the gas burner drawn exactly on top of the transport hub.
#
# So rows are COMPUTED from a first top and a pitch, and the pitch is
# tightened when the band is not tall enough - never below a row's own
# height, which is the guarantee that two rows can no longer occupy the same
# space whatever the catalog grows to. Columns widen for the same reason:
# a count that would need more rows than the band holds gets another column
# instead of another row.
# #144: and the band the rows live in was written down too, as a pair of
# constants measured against a 1280-tall canvas. The header above it is
# anchored to the TOP of the panel and the grid is anchored to its CENTRE,
# so the gap between them is half the canvas height - which means the
# constants were only ever right at one window shape. At 1080 tall the grid
# started 4px ABOVE the status line and drew straight through it, which is
# what the ticket reported.
#
# So nothing about the geometry is written down against a screen size any
# more. The band is measured from the header that is actually there, the row
# pitch closes up to fit it (never below a row's own height, which is what
# makes overlapping impossible rather than unlikely), and the column count
# rises until the rows fit - a short panel gets a wide grid instead of one
# that runs off the bottom of it.
const MENU_BUTTON_HALF: float = 64.0
const MENU_BUTTON_H: float = 100.0
const MENU_COST_HALF: float = 74.0
const MENU_COST_H: float = 44.0
const MENU_LABEL_OFFSET: float = 106.0
const MENU_LABEL_GAP: float = 4.0
# Per column-count geometry. The two-column figures are the ones the menu has
# always used; the three-column ones came with the wide mode; four columns is
# what ten structures now need to stay inside three rows.
const MENU_COL_X: Dictionary = {2: 140.0, 3: 224.0, 4: 258.0}
const MENU_LABEL_HALF: Dictionary = {2: 150.0, 3: 108.0, 4: 84.0}
const MENU_LABEL_H: Dictionary = {2: 52.0, 3: 68.0, 4: 68.0}
const MENU_COST_OFFSET: Dictionary = {2: 162.0, 3: 178.0, 4: 178.0}
const MENU_ROW_PITCH: Dictionary = {2: 223.0, 3: 245.0, 4: 245.0}
# The widest a column is ever given, however much room there is: past this
# the entries stop reading as a grid and start reading as a scattering.
const MENU_NATURAL_SPACING: float = 280.0
# The narrowest a column may be squeezed to - a button plus a little air.
const MENU_MIN_SPACING: float = MENU_BUTTON_HALF * 2.0 + 12.0
# A caption gets most of its column, not all of it.
const MENU_LABEL_SHARE: float = 0.46
# Below this a caption is assumed to need two lines.
const MENU_ONE_LINE_HALF: float = 120.0
const MENU_LABEL_H_ONE: float = 52.0
const MENU_LABEL_H_TWO: float = 68.0
# The band the grid may occupy, in the menu's own centre-anchored space: from
# under the status line (which sits below the resource bar added in #137) to
# just short of the bottom of a 1280-tall screen.
const MENU_GRID_TOP: float = -252.0
const MENU_GRID_BOTTOM: float = 612.0
const MENU_SIDE_MARGIN: float = 24.0
const MENU_HEADER_GAP: float = 16.0
const MENU_BOTTOM_MARGIN: float = 28.0
const MENU_MAX_COLUMNS: int = 6
# The vertical band the grid may occupy, in the menu's own centre-anchored
# space: (top, bottom).
#
# MEASURED, not written down (#144). The header is anchored to the top of the
# panel and the grid to its centre, so the two only agree at one canvas
# height - and the pair of constants this replaces happened to be the ones
# for 1280. Reading the status line's own bottom edge and the panel's own
# height makes the answer right at every window shape, including the one the
# player is actually running.
func menu_band() -> Vector2:
var half: float = build_menu.size.y * 0.5
if half <= 0.0:
half = 640.0
var header: float = build_status.offset_bottom + MENU_HEADER_GAP
return Vector2(header - half, half - MENU_BOTTOM_MARGIN)
# How wide one column is given. Never wider than looks like a grid, never
# narrower than a button, and otherwise whatever the panel has room for.
func menu_column_spacing(columns: int) -> float:
var room: float = build_menu.size.x - MENU_SIDE_MARGIN * 2.0
if room <= 0.0:
room = 672.0
return maxf(MENU_MIN_SPACING, minf(MENU_NATURAL_SPACING, room / float(columns)))
func menu_label_half(columns: int) -> float:
return menu_column_spacing(columns) * MENU_LABEL_SHARE
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
func menu_cost_offset(columns: int) -> float:
return MENU_LABEL_OFFSET + menu_label_height(columns) + MENU_LABEL_GAP
# 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 float(MENU_COST_OFFSET[columns]) + MENU_COST_H
# The fewest columns that keep the grid inside MENU_MAX_ROWS. Two is the shape
# the menu is meant to have; the wider ones are what a growing catalog forces.
const MENU_MAX_ROWS: int = 4
return menu_cost_offset(columns) + MENU_COST_H
# The fewest columns whose rows fit the band. Two is the shape the menu is
# meant to have; wider is what a full catalog - or a short window - forces.
func menu_columns(count: int) -> int:
for columns in [2, 3, 4]:
var rows: int = int(ceil(float(count) / float(columns)))
if rows <= MENU_MAX_ROWS and _rows_fit(rows, columns):
var widest: int = maxi(mini(MENU_MAX_COLUMNS,
int(floor((build_menu.size.x - MENU_SIDE_MARGIN * 2.0) / MENU_MIN_SPACING))), 2)
for columns in range(2, widest + 1):
if _rows_fit(int(ceil(float(count) / float(columns))), columns):
return columns
return 4
return widest
func menu_rows(count: int) -> int:
@ -738,22 +783,24 @@ func menu_rows(count: int) -> int:
func _rows_fit(rows: int, columns: int) -> bool:
if rows <= 1:
return true
var height: float = menu_row_height(columns)
return (MENU_GRID_BOTTOM - MENU_GRID_TOP - height) / float(rows - 1) >= height
var band: Vector2 = menu_band()
if rows <= 1:
return band.y - band.x >= height
return (band.y - band.x - height) / float(rows - 1) >= height
# Where one row starts. Top-anchored under the header, with the pitch closed
# up when the band is tight - but never below the row height, so two rows
# cannot land on each other however many structures there are (#136).
# Where one row starts. Top of the band, with the pitch closed up when it is
# tight - but never below the row height, so two rows cannot land on each
# other however many structures there are, or however short the window (#136,
# #144).
func menu_row_top(row: int, rows: int, columns: int) -> float:
var height: float = menu_row_height(columns)
var pitch: float = float(MENU_ROW_PITCH[columns])
var band: Vector2 = menu_band()
var pitch: float = MENU_NATURAL_SPACING
if rows > 1:
pitch = minf(pitch,
(MENU_GRID_BOTTOM - MENU_GRID_TOP - height) / float(rows - 1))
return MENU_GRID_TOP + maxf(pitch, height) * float(row)
pitch = minf(pitch, (band.y - band.x - height) / float(rows - 1))
return band.x + maxf(pitch, height) * float(row)
func _place_entry(node: Control, cx: float, top: float, half: float, height: float) -> void:
@ -780,10 +827,10 @@ func _layout_build_menu() -> void:
var columns: int = menu_columns(shown.size())
var rows: int = menu_rows(shown.size())
var col_x: float = float(MENU_COL_X[columns])
var label_half: float = float(MENU_LABEL_HALF[columns])
var label_h: float = float(MENU_LABEL_H[columns])
var cost_offset: float = float(MENU_COST_OFFSET[columns])
var spacing: float = menu_column_spacing(columns)
var label_half: float = menu_label_half(columns)
var label_h: float = menu_label_height(columns)
var cost_offset: float = menu_cost_offset(columns)
for i in range(shown.size()):
var row: int = i / columns
@ -791,8 +838,7 @@ func _layout_build_menu() -> void:
# read as a row with something missing beside it.
var in_row: int = mini(shown.size() - row * columns, columns)
var col: int = i % columns
var cx: float = (float(col) - (float(in_row) - 1.0) * 0.5) * col_x * 2.0 \
/ maxf(float(columns) - 1.0, 1.0)
var cx: float = (float(col) - (float(in_row) - 1.0) * 0.5) * spacing
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)
@ -1633,7 +1679,13 @@ func _layout_hangar() -> void:
# box barely tall enough for one line, so the second line was clipped and
# a "Gas Bomber" read as "Gas".
var slot_size: float = minf(cell_height * 0.46, cell_width * 0.40)
var label_height: float = maxf(cell_height - slot_size - HANGAR_LABEL_GAP, 1.0)
# #143: TWO gaps, not one - above the caption and below it. With a single
# gap the box ended exactly HANGAR_LABEL_GAP past the bottom of its own
# cell, which is inside the next row's icon. Two pixels of overhang is
# not much on its own, but it is the difference between "the caption
# cannot reach the row below" and "the caption starts in it".
var label_height: float = maxf(
cell_height - slot_size - HANGAR_LABEL_GAP * 2.0, 1.0)
_layout_hangar_section(hangar_available_slots, hangar_available_labels,
top, columns, cell_width, cell_height, slot_size, label_height, width)
@ -1673,11 +1725,40 @@ func _layout_hangar_section(slots: Array, labels: Array, top: float, columns: in
slot.position = Vector2(cell_x + (cell_width - slot_size) * 0.5, cell_y)
slot.size = Vector2(slot_size, slot_size)
var label: Label = labels[i]
label.position = Vector2(cell_x, cell_y + slot_size + 4.0)
label.position = Vector2(cell_x, cell_y + slot_size + HANGAR_LABEL_GAP)
label.size = Vector2(cell_width, label_height)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
# #143: a caption is "Gas Bomber\n2 available" - two lines before
# autowrap, three after it in a narrow column - at a font size fixed
# in the scene. A Label does not clip by default, so the third line
# was drawn straight over the icon of the row below it.
#
# Two things, and both are wanted. The size is fitted to the box the
# layout above worked out, so the text has somewhere to go; and the
# box clips, so however the catalog grows - a longer vessel name, a
# fourth line - nothing can ever reach the next row again. The first
# is what keeps it legible, the second is what keeps it correct.
label.add_theme_font_size_override("font_size",
_hangar_caption_size(label_height))
label.clip_text = true
# The largest caption that still fits HANGAR_CAPTION_LINES lines into the
# height the grid could spare, within what is readable at arm's length.
const HANGAR_CAPTION_LINES: float = 3.0
const HANGAR_CAPTION_MIN: int = 13
const HANGAR_CAPTION_MAX: int = 22
# Godot lays a line out taller than its nominal font size; measured against
# the project font rather than guessed, this is the ratio that keeps three
# lines inside the box.
const HANGAR_LINE_RATIO: float = 1.25
func _hangar_caption_size(label_height: float) -> int:
return clampi(int(label_height / (HANGAR_CAPTION_LINES * HANGAR_LINE_RATIO)),
HANGAR_CAPTION_MIN, HANGAR_CAPTION_MAX)
func _refresh_hangar() -> void: