Everything lived in one flat directory, so a diff gave no clue what area it touched and finding the file you wanted meant knowing its exact name. Twelve folders now, grouped by what a thing IS rather than what type it is - a vessel's definition, its component scenes and its upgrade resources sit together, because that is the set you read when you change one of them. buildings core controllers enemies logistics planets resources shaders surface ui vessels vfx world 332 files moved and every res:// reference rewritten - 306 files touched, including the autoload and main-scene paths in project.godot. Nothing renamed: this is purely where files sit, so the diff is a pile of pure moves and no behaviour is buried in it. ui_theme.tres, icon.svg and web_shell.html stay at the root, where Godot and the export preset expect them. Verified three ways, because a suite alone would not have caught all of it: the full 117 pass, the web export builds clean, and the game renders. The export is why that matters. The FIRST export after the move failed with "Attempt to open script 'res://GameState.gd'" - the old path - while project.godot on disk plainly said res://core/GameState.gd. That is this project's documented Android FUSE mtime trap: Godot served a cached copy of a file whose content had changed. A `touch` fixed it. Nothing in the test suite would have found that, because the suite runs from a copy on a native filesystem - the one place the bug cannot happen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
248 lines
9.9 KiB
GDScript
248 lines
9.9 KiB
GDScript
class_name ResourceTransferList
|
|
extends Control
|
|
|
|
# Two-sided cargo control. Resources are rows and locations stay fixed:
|
|
# fleet on the left, the current building on the right. Horizontal arrows
|
|
# make the result of a press visible before the player commits to it.
|
|
|
|
signal transfer_requested(resource_type: String, to_building: bool, amount: int)
|
|
|
|
const HEADER_HEIGHT: float = 66.0
|
|
const FLEET_COLOR: Color = Color(1.0, 0.78, 0.25)
|
|
const LOCAL_COLOR: Color = Color(0.45, 0.9, 0.55)
|
|
const RULE_COLOR: Color = Color(0.18, 0.38, 0.52)
|
|
const ALL_AMOUNT: int = 1 << 30
|
|
const AMOUNT_OPTIONS: Array[int] = [1, 5, 25, ALL_AMOUNT]
|
|
|
|
var building_id: int = 0
|
|
var extractor_index: int = -1
|
|
var _destination_heading: Label
|
|
var _rows: Dictionary = {}
|
|
|
|
|
|
func _ready() -> void:
|
|
var fleet_heading := _make_label("FLEET HOLD", 26, FLEET_COLOR)
|
|
fleet_heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(fleet_heading)
|
|
_destination_heading = _make_label("THIS BUILDING", 26, LOCAL_COLOR)
|
|
_destination_heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(_destination_heading)
|
|
|
|
for resource_type in GameState.resource_types():
|
|
var colour: Color = GameState.resource_color(resource_type)
|
|
var glyph := ResourceGlyph.new()
|
|
glyph.resource_type = resource_type
|
|
add_child(glyph)
|
|
var name_label := _make_label(GameState.resource_name(resource_type).to_upper(), 29, colour)
|
|
name_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(name_label)
|
|
var fleet_amount := _make_label("0", 48, FLEET_COLOR)
|
|
fleet_amount.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(fleet_amount)
|
|
var local_amount := _make_label("0", 48, LOCAL_COLOR)
|
|
local_amount.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(local_amount)
|
|
|
|
var unload := IconButton.new()
|
|
unload.name = "%sToBuildingButton" % GameState.resource_name(resource_type)
|
|
unload.icon = IconButton.Icon.RIGHT_ARROW
|
|
unload.glow_color = colour
|
|
unload.pressed.connect(_request_transfer.bind(resource_type, true))
|
|
add_child(unload)
|
|
var unload_label := _make_label("UNLOAD →", 23, colour)
|
|
unload_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(unload_label)
|
|
|
|
var load := IconButton.new()
|
|
load.name = "%sToFleetButton" % GameState.resource_name(resource_type)
|
|
load.icon = IconButton.Icon.LEFT_ARROW
|
|
load.glow_color = colour
|
|
load.pressed.connect(_request_transfer.bind(resource_type, false))
|
|
add_child(load)
|
|
var load_label := _make_label("← LOAD", 23, colour)
|
|
load_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(load_label)
|
|
|
|
var decrease := IconButton.new()
|
|
decrease.name = "%sDecreaseButton" % GameState.resource_name(resource_type)
|
|
decrease.icon = IconButton.Icon.MINUS
|
|
decrease.glow_color = colour
|
|
decrease.pressed.connect(_change_amount.bind(resource_type, -1))
|
|
add_child(decrease)
|
|
var amount_label := _make_label("ALL", 28, colour)
|
|
amount_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
add_child(amount_label)
|
|
var increase := IconButton.new()
|
|
increase.name = "%sIncreaseButton" % GameState.resource_name(resource_type)
|
|
increase.icon = IconButton.Icon.PLUS
|
|
increase.glow_color = colour
|
|
increase.pressed.connect(_change_amount.bind(resource_type, 1))
|
|
add_child(increase)
|
|
_rows[resource_type] = {
|
|
"glyph": glyph, "name": name_label,
|
|
"fleet_amount": fleet_amount, "local_amount": local_amount,
|
|
"unload": unload, "unload_label": unload_label,
|
|
"load": load, "load_label": load_label,
|
|
"decrease": decrease, "amount_label": amount_label,
|
|
"increase": increase,
|
|
"amount_index": AMOUNT_OPTIONS.size() - 1,
|
|
}
|
|
|
|
resized.connect(_layout)
|
|
_layout()
|
|
refresh()
|
|
|
|
|
|
func _make_label(text_value: String, font_size: int, colour: Color) -> Label:
|
|
var label := Label.new()
|
|
label.text = text_value
|
|
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
label.add_theme_font_size_override("font_size", font_size)
|
|
label.add_theme_color_override("font_color", colour)
|
|
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
return label
|
|
|
|
|
|
func _request_transfer(resource_type: String, to_building: bool) -> void:
|
|
var row: Dictionary = _rows.get(resource_type, {})
|
|
if row.is_empty():
|
|
return
|
|
transfer_requested.emit(resource_type, to_building,
|
|
AMOUNT_OPTIONS[int(row.amount_index)])
|
|
|
|
|
|
func _change_amount(resource_type: String, direction: int) -> void:
|
|
var row: Dictionary = _rows.get(resource_type, {})
|
|
if row.is_empty():
|
|
return
|
|
row.amount_index = clampi(int(row.amount_index) + direction, 0, AMOUNT_OPTIONS.size() - 1)
|
|
_refresh_amount_controls(row)
|
|
|
|
|
|
func _refresh_amount_controls(row: Dictionary) -> void:
|
|
var index: int = int(row.amount_index)
|
|
var amount: int = AMOUNT_OPTIONS[index]
|
|
row.amount_label.text = "ALL" if amount == ALL_AMOUNT else str(amount)
|
|
row.decrease.enabled = index > 0
|
|
row.increase.enabled = index < AMOUNT_OPTIONS.size() - 1
|
|
row.decrease.queue_redraw()
|
|
row.increase.queue_redraw()
|
|
|
|
|
|
func set_destination(id: int, heading: String) -> void:
|
|
building_id = id
|
|
extractor_index = -1
|
|
if _destination_heading != null:
|
|
_destination_heading.text = heading.to_upper()
|
|
refresh()
|
|
|
|
|
|
func set_extractor_destination(index: int, heading: String) -> void:
|
|
building_id = 0
|
|
extractor_index = index
|
|
if _destination_heading != null:
|
|
_destination_heading.text = heading.to_upper()
|
|
refresh()
|
|
|
|
|
|
func refresh() -> void:
|
|
for resource_type in GameState.resource_types():
|
|
var row: Dictionary = _rows.get(resource_type, {})
|
|
if row.is_empty():
|
|
continue
|
|
var fleet_amount: int = GameState.fleet_resource(resource_type)
|
|
var local_amount: int = GameState.extractor_resource(extractor_index, resource_type) \
|
|
if extractor_index >= 0 else GameState.building_resource(building_id, resource_type)
|
|
row.fleet_amount.text = str(fleet_amount)
|
|
row.local_amount.text = str(local_amount)
|
|
row.unload.enabled = fleet_amount > 0
|
|
row.load.enabled = local_amount > 0
|
|
row.unload.queue_redraw()
|
|
row.load.queue_redraw()
|
|
_refresh_amount_controls(row)
|
|
|
|
|
|
func _layout() -> void:
|
|
if _destination_heading == null:
|
|
return
|
|
var side_width: float = size.x * 0.35
|
|
var centre_width: float = size.x - side_width * 2.0
|
|
var right_x: float = side_width + centre_width
|
|
var fleet_heading: Label = get_child(0)
|
|
fleet_heading.position = Vector2(0.0, 0.0)
|
|
fleet_heading.size = Vector2(side_width, HEADER_HEIGHT)
|
|
_destination_heading.position = Vector2(right_x, 0.0)
|
|
_destination_heading.size = Vector2(side_width, HEADER_HEIGHT)
|
|
|
|
var row_height: float = (size.y - HEADER_HEIGHT) / maxf(1.0, float(_rows.size()))
|
|
var row_index: int = 0
|
|
for resource_type in GameState.resource_types():
|
|
var row: Dictionary = _rows[resource_type]
|
|
var y: float = HEADER_HEIGHT + float(row_index) * row_height
|
|
|
|
# EVERY offset below is a fraction of row_height. It used to be a
|
|
# fixed pixel ladder - glyph at +10, buttons at +88, selector at
|
|
# +142, captions under that - which needed about 244px inside a row
|
|
# whose height is divided from the available space. At three
|
|
# resources that fit; the fourth cut the row to 180 and every row
|
|
# spilled 64px into the one below it, and the last one into the hint
|
|
# text under the list. Proportions cannot overflow: the bands always
|
|
# sum to the row.
|
|
var pad: float = row_height * 0.04
|
|
var content: float = row_height - pad * 2.0
|
|
var top: float = y + pad
|
|
# amounts, with the resource's glyph and name between them
|
|
var band_totals: float = content * 0.32
|
|
# the arrows, and the amount selector between them
|
|
var band_controls: float = content * 0.48
|
|
# the arrow captions
|
|
var band_captions: float = content * 0.20
|
|
|
|
row.fleet_amount.position = Vector2(0.0, top)
|
|
row.fleet_amount.size = Vector2(side_width, band_totals)
|
|
row.local_amount.position = Vector2(right_x, top)
|
|
row.local_amount.size = Vector2(side_width, band_totals)
|
|
|
|
# Glyph and name sit at the TOP of their row rather than under its
|
|
# controls, so a row reads as one thing. Previously the name hung
|
|
# low enough to look like a heading for the row beneath it.
|
|
var glyph_size: float = minf(band_totals * 0.52, 44.0)
|
|
row.glyph.position = Vector2(size.x * 0.5 - glyph_size * 0.5, top)
|
|
row.glyph.size = Vector2(glyph_size, glyph_size)
|
|
row.name.position = Vector2(side_width, top + glyph_size)
|
|
row.name.size = Vector2(centre_width, maxf(band_totals - glyph_size, 1.0))
|
|
|
|
var controls_y: float = top + band_totals
|
|
var button_size: float = minf(band_controls, side_width * 0.5)
|
|
var button_y: float = controls_y + (band_controls - button_size) * 0.5
|
|
row.unload.position = Vector2(side_width * 0.5 - button_size * 0.5, button_y)
|
|
row.unload.size = Vector2(button_size, button_size)
|
|
row.load.position = Vector2(right_x + side_width * 0.5 - button_size * 0.5, button_y)
|
|
row.load.size = Vector2(button_size, button_size)
|
|
|
|
var selector_size: float = minf(band_controls * 0.62, centre_width * 0.30)
|
|
var selector_y: float = controls_y + (band_controls - selector_size) * 0.5
|
|
row.decrease.position = Vector2(side_width + 2.0, selector_y)
|
|
row.decrease.size = Vector2(selector_size, selector_size)
|
|
row.increase.position = Vector2(right_x - selector_size - 2.0, selector_y)
|
|
row.increase.size = Vector2(selector_size, selector_size)
|
|
row.amount_label.position = Vector2(side_width + selector_size + 2.0, selector_y)
|
|
row.amount_label.size = Vector2(centre_width - selector_size * 2.0 - 4.0, selector_size)
|
|
|
|
var caption_y: float = controls_y + band_controls
|
|
row.unload_label.position = Vector2(0.0, caption_y)
|
|
row.unload_label.size = Vector2(side_width, band_captions)
|
|
row.load_label.position = Vector2(right_x, caption_y)
|
|
row.load_label.size = Vector2(side_width, band_captions)
|
|
row_index += 1
|
|
queue_redraw()
|
|
|
|
|
|
func _draw() -> void:
|
|
var row_height: float = (size.y - HEADER_HEIGHT) / maxf(1.0, float(_rows.size()))
|
|
NeonDraw.draw_glowing_line(self, Vector2(0.0, HEADER_HEIGHT), Vector2(size.x, HEADER_HEIGHT),
|
|
RULE_COLOR, 0.5, 0.7)
|
|
for i in range(1, _rows.size()):
|
|
var y: float = HEADER_HEIGHT + float(i) * row_height
|
|
NeonDraw.draw_glowing_line(self, Vector2(0.0, y), Vector2(size.x, y),
|
|
RULE_COLOR, 0.4, 0.6)
|