Establishes the ImplantApp faux-mobile-OS architecture (D-191):
Foundation:
- ImplantAppManifest (Resource): @export vars for app_path, scene_path, default_key, default_mode, preserves_state
- ImplantNavStack (Node): push/pop/replace/reset_to_default, synchronous screen_changed signal
- ImplantApp (Control base class): absorbs HudGroups boilerplate; on_install/on_open/on_close/on_insert_deactivated lifecycle hooks
- ImplantRegistry (autoload): lazy-scans res://ui/implant/apps/*/app.tres; avoids autoload parse-order trap
Atlas app (replaces atlas_panel + atlas_reach_map + atlas_system_map + atlas_planet_map + root viewer files):
- apps/atlas/app.tres — manifest (implant/map, FULLSCREEN, key=M)
- apps/atlas/atlas_app.gd — coordinator; 4-screen nav via ImplantNavStack
- apps/atlas/screens/{reach,system,planet,regional}_screen.gd — enter/leave interface
- apps/atlas/{atlas_viewer,atlas_marker_overlay,atlas_overlay_bar}.gd — moved from root
Economics app (replaces economics_panel):
- apps/economics/app.tres — manifest (implant/economics, INSERT, key=N)
- apps/economics/economics_app.gd — thin shell delegating to OverviewScreen
- apps/economics/screens/overview_screen.gd — full panel logic, enter/leave interface
Wiring:
- project.godot: add ImplantRegistry autoload after HudGroups
- main.gd: registry-driven key toggle loop; rename atlas_panel→atlas_app, economics_panel→economics_app
- hud.tscn: swap to new scene paths; remove legacy StarMap node
- snapshot_consumers.gd: on_insert_deactivated() uniformly; rename vars
- hud_groups.gd: remove stale starchart compat comment
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
510 lines
15 KiB
GDScript
510 lines
15 KiB
GDScript
class_name SystemScreen
|
|
extends Control
|
|
## System picker and orbital diagram screen for AtlasApp (#844, D-191).
|
|
## Manages alphabetic system picker and orbital diagram for the current system.
|
|
## Emits body_selected when the player clicks a body in orbital view.
|
|
|
|
signal body_selected(body: Dictionary)
|
|
|
|
const ORBITAL_CENTER_FRACTION := Vector2(0.5, 0.55)
|
|
const STAR_RADIUS: float = 12.0
|
|
const ORBITAL_RING_BASE: float = 65.0
|
|
const ORBITAL_RING_STEP: float = 58.0
|
|
const MOON_ORBIT_RADIUS: float = 24.0
|
|
const STATION_SIZE: float = 6.0
|
|
const BODY_HIT_RADIUS: float = 16.0
|
|
const LABEL_OFFSET: float = 11.0
|
|
const PANEL_WIDTH: float = 320.0
|
|
const PANEL_MARGIN: float = 16.0
|
|
|
|
const COLOR_BG: Color = Color("#0d1117")
|
|
const COLOR_STAR: Color = Color("#f0d060")
|
|
const COLOR_PLANET_INHABITED: Color = Color("#44aa66")
|
|
const COLOR_PLANET_HABITABLE: Color = Color("#4488aa")
|
|
const COLOR_PLANET_BARE: Color = Color("#556677")
|
|
const COLOR_MOON: Color = Color("#3a4a55")
|
|
const COLOR_OORT: Color = Color("#253040")
|
|
const COLOR_STATION: Color = Color("#f0d060")
|
|
const COLOR_RING: Color = Color(1.0, 1.0, 1.0, 0.06)
|
|
const COLOR_TEXT: Color = Color("#c8d0e0")
|
|
const COLOR_TEXT_DIM: Color = Color("#667788")
|
|
|
|
var _systems: Array = []
|
|
var _selected_idx: int = 0
|
|
var _orbital_bodies: Array = []
|
|
var _orbital_stations: Array = []
|
|
var _body_positions: Dictionary = {}
|
|
var _station_positions: Dictionary = {}
|
|
var _hovered_body: String = ""
|
|
var _hovered_station: String = ""
|
|
var _selected_station: Dictionary = {}
|
|
var _dirty: bool = true
|
|
var _in_orbital: bool = false
|
|
|
|
var _picker_panel = null # ImplantPanel
|
|
var _picker_nav_row = null # ImplantDataRow
|
|
var _station_panel = null # ImplantPanel
|
|
|
|
|
|
func _ready() -> void:
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if not visible:
|
|
return
|
|
if _dirty:
|
|
queue_redraw()
|
|
_dirty = false
|
|
|
|
|
|
func setup(implant_theme) -> void:
|
|
_build_picker_panel(implant_theme)
|
|
_build_station_panel(implant_theme)
|
|
|
|
|
|
func set_systems(systems: Array) -> void:
|
|
_systems = systems
|
|
|
|
|
|
func set_selected_idx(idx: int) -> void:
|
|
_selected_idx = idx
|
|
|
|
|
|
func get_selected_idx() -> int:
|
|
return _selected_idx
|
|
|
|
|
|
func current_system() -> Dictionary:
|
|
if _systems.is_empty():
|
|
return {}
|
|
_selected_idx = clampi(_selected_idx, 0, _systems.size() - 1)
|
|
return _systems[_selected_idx]
|
|
|
|
|
|
func is_in_orbital() -> bool:
|
|
return _in_orbital
|
|
|
|
|
|
func get_orbital_body_count() -> int:
|
|
var count: int = 0
|
|
for b: Dictionary in _orbital_bodies:
|
|
if b.get("parent_body_id") == null:
|
|
count += 1
|
|
return count
|
|
|
|
|
|
func get_station_count() -> int:
|
|
return _orbital_stations.size()
|
|
|
|
|
|
func show_picker_mode() -> void:
|
|
_in_orbital = false
|
|
if _picker_panel:
|
|
_picker_panel.visible = true
|
|
_rebuild_picker_panel()
|
|
if _station_panel:
|
|
_station_panel.visible = false
|
|
_dirty = true
|
|
|
|
|
|
func load_and_show_orbital() -> void:
|
|
var sys: Dictionary = current_system()
|
|
_orbital_bodies = sys.get("orbit_bodies", [])
|
|
_orbital_stations = sys.get("stations", [])
|
|
_hovered_body = ""
|
|
_hovered_station = ""
|
|
_selected_station = {}
|
|
_compute_body_positions()
|
|
if _picker_panel:
|
|
_picker_panel.visible = false
|
|
if _station_panel:
|
|
_station_panel.visible = false
|
|
_in_orbital = true
|
|
_dirty = true
|
|
|
|
|
|
func navigate_system(delta: int) -> void:
|
|
if _systems.is_empty():
|
|
return
|
|
_selected_idx = wrapi(_selected_idx + delta, 0, _systems.size())
|
|
_rebuild_picker_panel()
|
|
|
|
|
|
func enter(payload: Dictionary) -> void:
|
|
if payload.get("mode") == "orbital":
|
|
load_and_show_orbital()
|
|
else:
|
|
show_picker_mode()
|
|
|
|
|
|
func leave() -> void:
|
|
pass
|
|
|
|
|
|
# =============================================================================
|
|
# Drawing
|
|
# =============================================================================
|
|
|
|
|
|
func _draw() -> void:
|
|
if _in_orbital:
|
|
_draw_orbital()
|
|
else:
|
|
draw_rect(Rect2(Vector2.ZERO, get_rect().size), COLOR_BG)
|
|
|
|
|
|
func _draw_orbital() -> void:
|
|
var sz: Vector2 = get_rect().size
|
|
var center: Vector2 = sz * ORBITAL_CENTER_FRACTION
|
|
|
|
draw_rect(Rect2(Vector2.ZERO, sz), COLOR_BG)
|
|
_draw_orbit_rings(center)
|
|
draw_circle(center, STAR_RADIUS + 4.0, Color(COLOR_STAR.r, COLOR_STAR.g, COLOR_STAR.b, 0.18))
|
|
draw_circle(center, STAR_RADIUS, COLOR_STAR)
|
|
_draw_stations()
|
|
_draw_bodies()
|
|
|
|
|
|
func _draw_orbit_rings(center: Vector2) -> void:
|
|
var seen_orbits: Dictionary = {}
|
|
for b: Dictionary in _orbital_bodies:
|
|
if b.get("parent_body_id") != null:
|
|
continue
|
|
var idx: int = int(b.get("orbit_index", 0))
|
|
if seen_orbits.has(idx):
|
|
continue
|
|
seen_orbits[idx] = true
|
|
var r: float = ORBITAL_RING_BASE + (idx - 1) * ORBITAL_RING_STEP
|
|
draw_arc(center, r, 0.0, TAU, 64, COLOR_RING, 0.5, true)
|
|
|
|
|
|
func _draw_bodies() -> void:
|
|
var font := get_theme_default_font()
|
|
for b: Dictionary in _orbital_bodies:
|
|
var bid: String = str(b.get("body_id", ""))
|
|
if bid.is_empty() or not _body_positions.has(bid):
|
|
continue
|
|
var pos: Vector2 = _body_positions[bid]
|
|
var body_type: String = b.get("body_type", "")
|
|
var atmo: String = b.get("atmosphere", "none")
|
|
var inhabited: bool = bool(b.get("inhabited", false))
|
|
|
|
var color: Color
|
|
var radius: float
|
|
match body_type:
|
|
"moon":
|
|
color = COLOR_MOON
|
|
radius = 3.5
|
|
"oort_cloud":
|
|
color = COLOR_OORT
|
|
radius = 2.0
|
|
_:
|
|
if inhabited:
|
|
color = COLOR_PLANET_INHABITED
|
|
radius = 6.0
|
|
elif atmo in ["breathable", "standard"]:
|
|
color = COLOR_PLANET_HABITABLE
|
|
radius = 5.5
|
|
else:
|
|
color = COLOR_PLANET_BARE
|
|
radius = 4.5
|
|
|
|
if bid == _hovered_body:
|
|
draw_arc(pos, radius + 5.0, 0.0, TAU, 20, Color(1.0, 1.0, 1.0, 0.25), 1.0, true)
|
|
|
|
draw_circle(pos, radius, color)
|
|
|
|
var label: String = b.get("proper_name", bid) if b.get("proper_name") else bid
|
|
var show_label: bool = inhabited or bid == _hovered_body
|
|
if show_label:
|
|
var lcolor: Color = COLOR_TEXT if bid == _hovered_body else COLOR_TEXT_DIM
|
|
var lsz: Vector2 = font.get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, 9)
|
|
var lpos: Vector2 = pos + Vector2(-lsz.x / 2.0, radius + LABEL_OFFSET)
|
|
draw_string(font, lpos, label, HORIZONTAL_ALIGNMENT_LEFT, -1, 9, lcolor)
|
|
|
|
|
|
func _draw_stations() -> void:
|
|
var font := get_theme_default_font()
|
|
for s: Dictionary in _orbital_stations:
|
|
var sid: String = str(s.get("station_id", ""))
|
|
if sid.is_empty() or not _station_positions.has(sid):
|
|
continue
|
|
var pos: Vector2 = _station_positions[sid]
|
|
var half: float = STATION_SIZE / 2.0
|
|
var rect: Rect2 = Rect2(pos - Vector2(half, half), Vector2(STATION_SIZE, STATION_SIZE))
|
|
|
|
if sid == _hovered_station:
|
|
draw_rect(
|
|
Rect2(rect.position - Vector2(3, 3), rect.size + Vector2(6, 6)),
|
|
Color(1.0, 1.0, 1.0, 0.18)
|
|
)
|
|
|
|
draw_rect(rect, COLOR_STATION)
|
|
|
|
if sid == _hovered_station:
|
|
var label: String = s.get("proper_name", sid) if s.get("proper_name") else sid
|
|
var lsz: Vector2 = font.get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, 9)
|
|
draw_string(
|
|
font,
|
|
pos + Vector2(-lsz.x / 2.0, half + 8.0),
|
|
label,
|
|
HORIZONTAL_ALIGNMENT_LEFT,
|
|
-1,
|
|
9,
|
|
COLOR_TEXT_DIM
|
|
)
|
|
|
|
|
|
# =============================================================================
|
|
# Orbital geometry
|
|
# =============================================================================
|
|
|
|
|
|
func _compute_body_positions() -> void:
|
|
_body_positions.clear()
|
|
_station_positions.clear()
|
|
|
|
var sz: Vector2 = get_rect().size
|
|
if sz == Vector2.ZERO:
|
|
sz = Vector2(1280.0, 720.0)
|
|
var center: Vector2 = sz * ORBITAL_CENTER_FRACTION
|
|
|
|
var top_bodies: Array = []
|
|
for b: Dictionary in _orbital_bodies:
|
|
if b.get("parent_body_id") == null:
|
|
top_bodies.append(b)
|
|
top_bodies.sort_custom(
|
|
func(a: Dictionary, b: Dictionary) -> bool:
|
|
return int(a.get("orbit_index", 0)) < int(b.get("orbit_index", 0))
|
|
)
|
|
|
|
var by_orbit: Dictionary = {}
|
|
for b: Dictionary in top_bodies:
|
|
var idx: int = int(b.get("orbit_index", 0))
|
|
if not by_orbit.has(idx):
|
|
by_orbit[idx] = []
|
|
by_orbit[idx].append(b)
|
|
|
|
for orbit_idx: int in by_orbit:
|
|
var ring_bodies: Array = by_orbit[orbit_idx]
|
|
var ring_r: float = ORBITAL_RING_BASE + (orbit_idx - 1) * ORBITAL_RING_STEP
|
|
var count: int = ring_bodies.size()
|
|
for i: int in range(count):
|
|
var b: Dictionary = ring_bodies[i]
|
|
var bid: String = str(b.get("body_id", ""))
|
|
if bid.is_empty():
|
|
continue
|
|
var angle: float
|
|
if count == 1:
|
|
angle = -PI / 2.0
|
|
else:
|
|
angle = -PI / 2.0 + TAU * float(i) / float(count)
|
|
_body_positions[bid] = center + Vector2(cos(angle), sin(angle)) * ring_r
|
|
|
|
# Moons per parent count drives spacing — hard-coded divisor caused overlap on gas giants
|
|
var moons_by_parent: Dictionary = {}
|
|
for b: Dictionary in _orbital_bodies:
|
|
var parent_id: Variant = b.get("parent_body_id")
|
|
if parent_id == null:
|
|
continue
|
|
var key: String = str(parent_id)
|
|
if not moons_by_parent.has(key):
|
|
moons_by_parent[key] = []
|
|
moons_by_parent[key].append(b)
|
|
for parent_key: String in moons_by_parent:
|
|
if not _body_positions.has(parent_key):
|
|
continue
|
|
var siblings: Array = moons_by_parent[parent_key]
|
|
siblings.sort_custom(
|
|
func(a: Dictionary, b: Dictionary) -> bool:
|
|
return int(a.get("orbit_index", 0)) < int(b.get("orbit_index", 0))
|
|
)
|
|
var parent_pos: Vector2 = _body_positions[parent_key]
|
|
var count: int = siblings.size()
|
|
for i: int in range(count):
|
|
var moon: Dictionary = siblings[i]
|
|
var moon_id: String = str(moon.get("body_id", ""))
|
|
if moon_id.is_empty():
|
|
continue
|
|
var angle: float = -PI / 2.0 + TAU * float(i) / float(count)
|
|
_body_positions[moon_id] = (
|
|
parent_pos + Vector2(cos(angle), sin(angle)) * MOON_ORBIT_RADIUS
|
|
)
|
|
|
|
for s: Dictionary in _orbital_stations:
|
|
var station_id: String = str(s.get("station_id", ""))
|
|
if station_id.is_empty():
|
|
continue
|
|
var parent_id: Variant = s.get("orbits_body_id")
|
|
var station_parent_pos: Vector2
|
|
if parent_id != null and _body_positions.has(str(parent_id)):
|
|
station_parent_pos = _body_positions[str(parent_id)]
|
|
else:
|
|
station_parent_pos = center
|
|
_station_positions[station_id] = station_parent_pos + Vector2(20.0, -10.0)
|
|
|
|
|
|
# =============================================================================
|
|
# Input
|
|
# =============================================================================
|
|
|
|
|
|
func _gui_input(event: InputEvent) -> void:
|
|
if not _in_orbital:
|
|
return
|
|
if event is InputEventMouseButton and (event as InputEventMouseButton).pressed:
|
|
_handle_orbital_click((event as InputEventMouseButton).position)
|
|
elif event is InputEventMouseMotion:
|
|
_handle_orbital_hover((event as InputEventMouseMotion).position)
|
|
|
|
|
|
func _handle_orbital_click(pos: Vector2) -> void:
|
|
var bid: String = _find_nearest_body(pos)
|
|
if not bid.is_empty():
|
|
for b: Dictionary in _orbital_bodies:
|
|
if str(b.get("body_id", "")) == bid:
|
|
body_selected.emit(b)
|
|
return
|
|
|
|
var sid: String = _find_nearest_station(pos)
|
|
if not sid.is_empty():
|
|
for s: Dictionary in _orbital_stations:
|
|
if str(s.get("station_id", "")) == sid:
|
|
_selected_station = s
|
|
_rebuild_station_panel()
|
|
if _station_panel:
|
|
_station_panel.visible = true
|
|
return
|
|
|
|
_selected_station = {}
|
|
if _station_panel:
|
|
_station_panel.visible = false
|
|
_dirty = true
|
|
|
|
|
|
func _handle_orbital_hover(pos: Vector2) -> void:
|
|
var new_body: String = _find_nearest_body(pos)
|
|
var new_station: String = "" if not new_body.is_empty() else _find_nearest_station(pos)
|
|
if new_body != _hovered_body or new_station != _hovered_station:
|
|
_hovered_body = new_body
|
|
_hovered_station = new_station
|
|
_dirty = true
|
|
|
|
|
|
func _find_nearest_body(pos: Vector2) -> String:
|
|
var best_dist: float = BODY_HIT_RADIUS
|
|
var best_id: String = ""
|
|
for bid: String in _body_positions:
|
|
var d: float = pos.distance_to(_body_positions[bid])
|
|
if d < best_dist:
|
|
best_dist = d
|
|
best_id = bid
|
|
return best_id
|
|
|
|
|
|
func _find_nearest_station(pos: Vector2) -> String:
|
|
var best_dist: float = BODY_HIT_RADIUS
|
|
var best_id: String = ""
|
|
for sid: String in _station_positions:
|
|
var d: float = pos.distance_to(_station_positions[sid])
|
|
if d < best_dist:
|
|
best_dist = d
|
|
best_id = sid
|
|
return best_id
|
|
|
|
|
|
# =============================================================================
|
|
# Panels
|
|
# =============================================================================
|
|
|
|
|
|
func _build_picker_panel(implant_theme) -> void:
|
|
_picker_panel = ImplantPanel.new()
|
|
_picker_panel.name = "PickerPanel"
|
|
_picker_panel.theme_resource = implant_theme
|
|
_picker_panel.custom_minimum_size.x = PANEL_WIDTH
|
|
_picker_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_picker_panel.position = Vector2(PANEL_MARGIN, 60.0)
|
|
add_child(_picker_panel)
|
|
_rebuild_picker_panel()
|
|
|
|
|
|
func _rebuild_picker_panel() -> void:
|
|
if not _picker_panel:
|
|
return
|
|
_picker_panel.clear()
|
|
|
|
var sys: Dictionary = current_system()
|
|
var sys_name: String = sys.get("proper_name", sys.get("system_id", "—"))
|
|
var sys_id: String = sys.get("system_id", "")
|
|
var sector: String = sys.get("geographic_sector", "").replace("_", " ").to_upper()
|
|
var czone: String = sys.get("currency_zone", "").replace("_", " ")
|
|
var total: int = _systems.size()
|
|
|
|
_picker_panel.add_component(ImplantHeader.new("ATLAS", sys_name))
|
|
_picker_panel.add_component(ImplantSeparator.new())
|
|
|
|
_picker_nav_row = ImplantDataRow.new("◄ ► [%d / %d]" % [_selected_idx + 1, total])
|
|
_picker_panel.add_component(_picker_nav_row)
|
|
|
|
_picker_panel.add_component(ImplantSeparator.new())
|
|
_picker_panel.add_component(ImplantDataRow.new(sys_id))
|
|
if not sector.is_empty():
|
|
_picker_panel.add_component(ImplantDataRow.new(sector + " CORRIDOR"))
|
|
if not czone.is_empty():
|
|
_picker_panel.add_component(ImplantDataRow.new("currency " + czone))
|
|
_picker_panel.add_component(ImplantDataRow.new(sys.get("bodies", "—")))
|
|
_picker_panel.add_component(ImplantDataRow.new("pop " + sys.get("population", "—")))
|
|
|
|
_picker_panel.add_component(ImplantSeparator.new())
|
|
_picker_panel.add_component(ImplantTextBlock.new("enter open orbital map"))
|
|
_picker_panel.add_component(ImplantTextBlock.new("esc close atlas"))
|
|
|
|
_dirty = true
|
|
|
|
|
|
func _build_station_panel(implant_theme) -> void:
|
|
_station_panel = ImplantPanel.new()
|
|
_station_panel.name = "StationPanel"
|
|
_station_panel.theme_resource = implant_theme
|
|
_station_panel.custom_minimum_size.x = PANEL_WIDTH
|
|
_station_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_station_panel.position = Vector2(PANEL_MARGIN, 60.0)
|
|
_station_panel.visible = false
|
|
add_child(_station_panel)
|
|
|
|
|
|
func _rebuild_station_panel() -> void:
|
|
if not _station_panel:
|
|
return
|
|
_station_panel.clear()
|
|
|
|
if _selected_station.is_empty():
|
|
return
|
|
|
|
var s: Dictionary = _selected_station
|
|
var s_name: String = (
|
|
s.get("proper_name", "") if s.get("proper_name") else s.get("station_id", "—")
|
|
)
|
|
var s_type: String = s.get("station_type", "").replace("_", " ").to_upper()
|
|
var gov: String = s.get("governance_type", "") if s.get("governance_type") else ""
|
|
var role: String = s.get("economic_role", "") if s.get("economic_role") else ""
|
|
var sys: Dictionary = current_system()
|
|
var czone: String = sys.get("currency_zone", "") if sys.get("currency_zone") else "—"
|
|
czone = czone.replace("_", " ")
|
|
|
|
_station_panel.add_component(ImplantHeader.new(s_name, s_type + " STATION"))
|
|
_station_panel.add_component(ImplantSeparator.new())
|
|
if not gov.is_empty():
|
|
_station_panel.add_component(
|
|
ImplantDataRow.new("operator " + gov.replace("_", " ").to_upper())
|
|
)
|
|
if not role.is_empty():
|
|
_station_panel.add_component(ImplantDataRow.new("function " + role.replace("_", " ")))
|
|
_station_panel.add_component(ImplantDataRow.new("currency " + czone))
|
|
_station_panel.add_component(ImplantSeparator.new())
|
|
_station_panel.add_component(ImplantTextBlock.new("station atlas deferred"))
|
|
_station_panel.add_component(ImplantTextBlock.new("esc back"))
|