#216: transport hubs and spacial workshops no longer conjure their crews. Transporters and repair drones are ordered at a ship crafter, assigned per building through a new Station menu, flown out from the mothership hangar, and spent by the work they do - 20 runs, 12 repairs, counted where the run ENDS so nothing retires with cargo in the air or a building half repaired. A spent vessel is gone, so the structure is short again and the player has to build another. The menu shows what each one has left, worst first. Craftability needed its own flag: "the crafter can make it" and "it can take a berth in the fleet" stopped being the same question. #217: transporters crawl at 120 rather than 150, and a Burn Drive lets them carry energy and spend it to travel far faster. Fetching it is a leg of its own, to the nearest store that has any - so a refuelling transporter cannot be dispatched mid-errand - and the leg flown to COLLECT fuel is not charged for it. Unresearched, nothing detours and nothing changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
149 lines
5 KiB
GDScript
149 lines
5 KiB
GDScript
extends "res://ui/menus/ModalMenu.gd"
|
|
|
|
signal craft_requested(vessel_type: String)
|
|
signal queue_cancel_requested(index: int)
|
|
|
|
const VESSEL_DEFINITIONS = preload("res://vessels/VesselDefinitions.gd")
|
|
const MENU_LAYOUT = preload("res://ui/menus/MenuLayout.gd")
|
|
const PRICE_TAG = preload("res://ui/PriceTag.gd")
|
|
const COLUMNS := 3
|
|
const ROW_PITCH := 260.0
|
|
const COLUMN_X := 190.0
|
|
const BUTTON_HALF := 56.0
|
|
const BUTTON_HEIGHT := 100.0
|
|
const LABEL_HALF := 92.0
|
|
const LABEL_HEIGHT := 44.0
|
|
const LABEL_OFFSET := 106.0
|
|
const PRICE_HALF := 92.0
|
|
const PRICE_HEIGHT := 86.0
|
|
const PRICE_OFFSET := 154.0
|
|
|
|
@onready var status: Label = $StatusLabel
|
|
@onready var queue_detail: Label = $QueueDetail
|
|
@onready var resource_bar: Control = $Bar
|
|
# #216 added the two support craft at the end, in the order
|
|
# VESSEL_DEFINITIONS.craftable() returns them - fleet hulls first, so none of
|
|
# the rows above moved.
|
|
@onready var vessel_buttons: Array = [$InterceptorButton, $ShieldButton,
|
|
$GasBomberButton, $CarrierButton, $LaserButton, $DistorderButton,
|
|
$TransporterButton, $RepairDroneButton]
|
|
@onready var vessel_labels: Array = [$InterceptorLabel, $ShieldLabel,
|
|
$GasBomberLabel, $CarrierLabel, $LaserLabel, $DistorderLabel,
|
|
$TransporterLabel, $RepairDroneLabel]
|
|
@onready var queue_slots: Array = [$QueueSlot0, $QueueSlot1, $QueueSlot2, $QueueSlot3]
|
|
|
|
var building_id: int = 0
|
|
var message: String = ""
|
|
var message_until: int = 0
|
|
var price_tags: Array = []
|
|
|
|
|
|
func _ready() -> void:
|
|
super._ready()
|
|
_build_price_tags()
|
|
for i in range(mini(vessel_buttons.size(), VESSEL_DEFINITIONS.craftable().size())):
|
|
var definition: Resource = VESSEL_DEFINITIONS.craftable()[i]
|
|
vessel_buttons[i].pressed.connect(
|
|
func(): craft_requested.emit(String(definition.definition_id)))
|
|
for i in range(queue_slots.size()):
|
|
queue_slots[i].pressed.connect(func(): queue_cancel_requested.emit(i))
|
|
_layout_entries()
|
|
|
|
|
|
func open_for(next_building_id: int) -> void:
|
|
building_id = next_building_id
|
|
resource_bar.building_id = building_id
|
|
open_menu()
|
|
refresh()
|
|
|
|
|
|
func close_menu() -> void:
|
|
super.close_menu()
|
|
building_id = 0
|
|
|
|
|
|
func say(next_message: String) -> void:
|
|
message = next_message
|
|
message_until = Time.get_ticks_msec() + 3000
|
|
refresh()
|
|
|
|
|
|
func refresh() -> void:
|
|
status.text = ""
|
|
var definitions: Array = VESSEL_DEFINITIONS.craftable()
|
|
for i in range(mini(definitions.size(), vessel_buttons.size())):
|
|
var definition: Resource = definitions[i]
|
|
var button: Control = vessel_buttons[i]
|
|
vessel_labels[i].text = String(definition.display_name)
|
|
if i < price_tags.size():
|
|
price_tags[i].set_costs(GameState.product_costs(definition.definition_id))
|
|
button.icon = definition.icon
|
|
button.glow_color = definition.glow_color
|
|
button.enabled = GameState.vessel_is_unlocked(definition.definition_id)
|
|
button.queue_redraw()
|
|
refresh_queue()
|
|
if message != "":
|
|
if Time.get_ticks_msec() < message_until:
|
|
status.text = "%s\n%s" % [message, status.text]
|
|
else:
|
|
message = ""
|
|
|
|
|
|
func refresh_queue() -> void:
|
|
var orders: Array = GameState.order_list(building_id)
|
|
for i in range(queue_slots.size()):
|
|
var slot: Control = queue_slots[i]
|
|
slot.visible = i < orders.size()
|
|
if not slot.visible:
|
|
continue
|
|
var order: Dictionary = orders[i]
|
|
var definition: Resource = VESSEL_DEFINITIONS.get_definition(String(order.product))
|
|
slot.icon = definition.icon
|
|
slot.glow_color = vessel_colour(String(order.product))
|
|
slot.enabled = bool(order.started)
|
|
slot.queue_redraw()
|
|
if orders.is_empty():
|
|
queue_detail.text = "Nothing queued"
|
|
return
|
|
var head: Dictionary = orders[0]
|
|
if bool(head.started):
|
|
queue_detail.text = "Building %s %d%%\nTap to cancel" % [
|
|
GameState.vessel_name(String(head.product)),
|
|
int(round(float(head.progress) * 100.0))]
|
|
else:
|
|
queue_detail.text = "%s waiting for resources\nTap to cancel" \
|
|
% GameState.vessel_name(String(head.product))
|
|
|
|
|
|
func vessel_colour(vessel_type: String) -> Color:
|
|
var definition: Resource = VESSEL_DEFINITIONS.get_definition(vessel_type)
|
|
return definition.glow_color if definition != null else Color(0.25, 0.85, 1.0)
|
|
|
|
|
|
func _build_price_tags() -> void:
|
|
for i in range(vessel_buttons.size()):
|
|
var tag: Control = PRICE_TAG.new()
|
|
tag.name = "CraftPrice%d" % i
|
|
tag.set_anchors_preset(Control.PRESET_CENTER)
|
|
add_child(tag)
|
|
price_tags.append(tag)
|
|
|
|
|
|
func row_height() -> float:
|
|
return PRICE_OFFSET + PRICE_HEIGHT
|
|
|
|
|
|
func _layout_entries() -> void:
|
|
var rows: int = maxi(int(ceil(float(vessel_buttons.size()) / float(COLUMNS))), 1)
|
|
var band: Vector2 = MENU_LAYOUT.grid_band(status.offset_bottom, size.y)
|
|
for i in range(vessel_buttons.size()):
|
|
var row: int = i / COLUMNS
|
|
var column: int = i % COLUMNS
|
|
var cx: float = (float(column) - 1.0) * COLUMN_X
|
|
var top: float = MENU_LAYOUT.grid_row_top(row, rows, row_height(), band, ROW_PITCH)
|
|
MENU_LAYOUT.place_entry(vessel_buttons[i], cx, top, BUTTON_HALF, BUTTON_HEIGHT)
|
|
MENU_LAYOUT.place_entry(vessel_labels[i], cx, top + LABEL_OFFSET,
|
|
LABEL_HALF, LABEL_HEIGHT)
|
|
if i < price_tags.size():
|
|
MENU_LAYOUT.place_entry(price_tags[i], cx, top + PRICE_OFFSET,
|
|
PRICE_HALF, PRICE_HEIGHT)
|