_on_buoy() rebuilt the side rows synchronously inside Button.pressed for the start and partial-tap branches, freeing the emitting row mid-emission and crashing Godot with a SIGSEGV under real InputEventScreenTouch. Defer only those two _refresh_side calls; start/tap/save/claim order and the completed path through _on_lowfreq_result are unchanged. Extend ch_systems_touch_test.gd lifecycle mode to cover buoy start, a partial tap with save/live agreement, and completion via _on_lowfreq_result. Each tap re-discovers the live row rect after the deferred rebuild so no freed coordinate is reused. Full 72-step matrix is unchanged.
3912 lines
144 KiB
GDScript
3912 lines
144 KiB
GDScript
class_name GameRoot
|
|
extends Control
|
|
|
|
## P3a game shell: owns the persistent profile and routes between the skyport,
|
|
## the region map and the battle scene. Each page is a plain Control subtree
|
|
## built from the shared theme, so the whole loop stays data-driven.
|
|
|
|
const GrowthActions = preload("res://scripts/growth_actions.gd")
|
|
const GrowthModifiers = preload("res://scripts/growth_modifiers.gd")
|
|
const HeroSkillLoader = preload("res://scripts/hero_skill_loader.gd")
|
|
const EnemyMechanics = preload("res://scripts/enemy_mechanics.gd")
|
|
const CommissionBoard = preload("res://scripts/commission_board.gd")
|
|
const PartnerPerks = preload("res://scripts/partner_perks.gd")
|
|
const EndlessBattle = preload("res://scripts/endless_battle.gd")
|
|
const EndlessOffline = preload("res://scripts/endless_offline.gd")
|
|
const BigValue = preload("res://scripts/big_value.gd")
|
|
const Prestige = preload("res://scripts/prestige.gd")
|
|
const Transcendence = preload("res://scripts/transcendence.gd")
|
|
const OutsiderBook = preload("res://scripts/outsider_book.gd")
|
|
const WorldContent = preload("res://scripts/world_content.gd")
|
|
const SideSystems = preload("res://scripts/side_systems.gd")
|
|
const LowFreq = preload("res://scripts/low_freq.gd")
|
|
const GearActions = preload("res://scripts/gear_actions.gd")
|
|
const ChRelicGild = preload("res://scripts/ch_relic_gild.gd")
|
|
const ChSystems = preload("res://scripts/ch_systems_adapter.gd")
|
|
|
|
const PAGE_SKYPORT := "skyport"
|
|
const PAGE_MAP := "map"
|
|
const PAGE_BATTLE := "battle"
|
|
const PAGE_SETTINGS := "settings"
|
|
const PAGE_GROWTH := "growth"
|
|
const PAGE_WORLD := "world"
|
|
const PAGE_SIDE := "side"
|
|
const PAGE_LOADOUT := "loadout"
|
|
const PAGE_ENDLESS := "endless"
|
|
|
|
var profile: Dictionary = {}
|
|
var locale := "zh_CN"
|
|
var low_power := false
|
|
var muted := false
|
|
var reduced_motion := false
|
|
var sfx: SfxPlayer
|
|
var current_page := PAGE_SKYPORT
|
|
var active_node := ""
|
|
var active_wave := 0
|
|
var _revive_budget_left := 0 # P04 医师: finite per-node revive budget
|
|
var _endless_state: Dictionary = {} # CH-style endless run (BigValue)
|
|
|
|
var _header_gold: Label
|
|
var _header_crystal: Label
|
|
var _page_host: Control
|
|
var _skyport: Control
|
|
var _map: Control
|
|
var _battle_host: Control
|
|
var _battle: BattleScene
|
|
var _settings: Control
|
|
var _growth: Control
|
|
var _growth_rows: Dictionary = {}
|
|
var _settings_rows: Dictionary = {}
|
|
var _settings_labels: Dictionary = {}
|
|
var _settings_note: Label
|
|
var _settings_title: Label
|
|
var _header_title: Label
|
|
var _header_box: Control
|
|
var _nav_box: Control
|
|
var _safe_top := 0.0
|
|
var _safe_bottom := 0.0
|
|
var _shell_theme: Theme
|
|
var _modal: Control
|
|
var _modal_title: Label
|
|
var _modal_body: Label
|
|
var _modal_actions: VBoxContainer
|
|
var _toast_label: Label
|
|
var _toast_tween: Tween
|
|
var _nav_buttons: Dictionary = {}
|
|
var skyport_report_text: Label
|
|
var _skyport_report_button: Button
|
|
var _auto_run_button: Button
|
|
var _map_rows: Dictionary = {}
|
|
var _map_progress: Label
|
|
var _map_progress_fill: ColorRect
|
|
var _map_connectors: Array = []
|
|
var _skyport_upgrade_rows: Dictionary = {}
|
|
var _auto_advance_pending := false
|
|
var _victory_row: Control
|
|
var _victory_number: Label
|
|
var _victory_tween: Tween
|
|
var _victory_banner: Control
|
|
var _event_banner: Control
|
|
|
|
# Full-game expedition world (L5 runtime): region -> chapter -> node navigator
|
|
# over WorldContent's 600 nodes. Kept separate from the 10-node slice map so the
|
|
# proven slice loop stays untouched.
|
|
var _world: Control
|
|
var _world_region := "R1"
|
|
var _world_chapter := "R1-C01"
|
|
var _world_node := ""
|
|
var _world_region_row: HBoxContainer
|
|
var _world_chapter_col: GridContainer
|
|
var _world_node_col: GridContainer
|
|
var _world_detail: Label
|
|
var _world_progress: Label
|
|
var _world_mode := false
|
|
|
|
# L5 side systems: partners / records / black market.
|
|
var _side: Control
|
|
var _side_tab := "partners"
|
|
var _side_tabs: Dictionary = {}
|
|
var _side_rows: VBoxContainer
|
|
var _side_summary: Label
|
|
var _side_scroll: ScrollContainer
|
|
# S5/S6 CH systems: explicit touch targets so real ScreenTouch probes can find
|
|
# the new rows on every portrait size without calling callbacks directly.
|
|
var _ch_targets: Dictionary = {}
|
|
|
|
# L5 loadout: hero detail + 6 gear slots + relics, driven by real pack data.
|
|
var _loadout: Control
|
|
var _loadout_hero := "H01"
|
|
var _loadout_hero_row: HBoxContainer
|
|
var _loadout_detail: Label
|
|
var _loadout_gear_col: VBoxContainer
|
|
var _endless_page: Control
|
|
var _endless_status: Label
|
|
var _endless_econ: Label
|
|
var _endless_actions: VBoxContainer
|
|
var _endless_log: VBoxContainer
|
|
var _endless_recent: Array = []
|
|
var _endless_offline_msg := ""
|
|
|
|
# U2 visual bridge. U1 leaf pages are views only; profile, routing, locale,
|
|
# safe area and save stay owned by GameRoot. No UiSliceShell is instantiated.
|
|
var _u2_skyport: UiPageSkyport = null
|
|
var _u2_world: UiPageWorld = null
|
|
var _u2_dock: PrimaryCTADock = null
|
|
var _u2_settlement: UiPageSettlement = null
|
|
var _u2_settlement_host: Control = null
|
|
var _u2_connected: Dictionary = {}
|
|
|
|
|
|
func _fb() -> FeedbackService:
|
|
return get_node_or_null("/root/Feedback") as FeedbackService
|
|
|
|
func _ready() -> void:
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_shell_theme = UiTheme.build_theme(str(profile.get("ui_skin", "default")))
|
|
theme = _shell_theme
|
|
profile = ProfileStore.load_profile()
|
|
low_power = bool(profile.get("low_power", false))
|
|
muted = bool(profile.get("muted", false))
|
|
reduced_motion = bool(profile.get("reduced_motion", false))
|
|
ProfileStore.build_offline_report(profile, _roster_bonus() + 33.0 + ProfileStore.ch_auto_dps(profile))
|
|
sfx = SfxPlayer.new()
|
|
sfx.name = "Sfx"
|
|
add_child(sfx)
|
|
sfx.start_bgm()
|
|
if _fb() != null:
|
|
_fb().configure(reduced_motion, low_power)
|
|
_build_background()
|
|
_build_header()
|
|
_build_page_host()
|
|
_build_skyport()
|
|
_build_map()
|
|
_build_world()
|
|
_build_side()
|
|
_build_loadout()
|
|
_build_endless()
|
|
_build_settings()
|
|
_build_growth()
|
|
_build_bottom_nav()
|
|
_build_u2_dock()
|
|
_build_modal()
|
|
_build_toast()
|
|
show_page(PAGE_SKYPORT)
|
|
_apply_safe_area()
|
|
# React to orientation / display changes (safe inset changes on rotation).
|
|
var viewport := get_viewport()
|
|
if viewport != null and not viewport.size_changed.is_connected(_apply_safe_area):
|
|
viewport.size_changed.connect(_apply_safe_area)
|
|
_apply_debug_nav()
|
|
|
|
|
|
## S5/S6 live schedulers. CH quests use wall-clock timestamps (settled on open
|
|
## and on collect); autoclick/achievement/clickable use live clamped deltas.
|
|
## Persist only on a noteworthy change so a frame tick never writes the save.
|
|
func _process(delta: float) -> void:
|
|
if profile.is_empty() or delta <= 0.0:
|
|
return
|
|
var changed := ProfileStore.tick_ch_services(profile, minf(delta, 0.25),
|
|
int(profile.get("rebuild_count", 0)) > 0)
|
|
if bool(changed.get("achievement")) or bool(changed.get("spawned")):
|
|
ProfileStore.save_profile(profile)
|
|
# A service tick fires every 0.1 s. Never rebuild the side page from a tick:
|
|
# that would replace live buttons under the player's finger. Only structural
|
|
# changes (a spawned windfall or a newly earned achievement) refresh it.
|
|
if (bool(changed.get("spawned")) or bool(changed.get("achievement"))) and current_page == PAGE_SIDE:
|
|
_refresh_side()
|
|
|
|
|
|
## Keep all shell UI inside the iOS safe area (Dynamic Island / status bar /
|
|
## home indicator). DisplayServer.get_display_safe_area() returns (0,0,0,0) on
|
|
## macOS/desktop, so this is a no-op there and only insets on notched devices.
|
|
func _apply_safe_area() -> void:
|
|
# Godot 4's get_display_safe_area() is already in WINDOW coordinates: its
|
|
# position/size are the unprotected rectangle inside the window. The inset
|
|
# is simply how far that rect starts from the window's top/bottom edges.
|
|
# (Subtracting window_get_position() double-counted and pushed the header
|
|
# a quarter screen down on iOS.)
|
|
var area := DisplayServer.get_display_safe_area()
|
|
var win_size := DisplayServer.window_get_size()
|
|
_safe_top = maxf(0.0, float(area.position.y))
|
|
_safe_bottom = maxf(0.0, float(win_size.y - (area.position.y + area.size.y)))
|
|
# Clamp to sane bounds: a mis-reported inset must never eat the screen.
|
|
_safe_top = mini(_safe_top, 96.0)
|
|
_safe_bottom = mini(_safe_bottom, 64.0)
|
|
if _header_box != null:
|
|
_header_box.offset_top = _safe_top + 8.0
|
|
if _page_host != null:
|
|
_page_host.offset_top = _safe_top + 60.0
|
|
_page_host.offset_bottom = -(_safe_bottom + 84.0)
|
|
if _nav_box != null:
|
|
# Keep the whole 76px bar above the home indicator, not just its bottom.
|
|
_nav_box.offset_bottom = -(_safe_bottom + 8.0)
|
|
_nav_box.offset_top = -(_safe_bottom + 84.0)
|
|
# The battle HUD computes its own safe-area rect; feed it the same insets.
|
|
if _battle != null and _battle.hud != null:
|
|
_battle.hud.set_safe_area(_safe_top, _safe_bottom)
|
|
_layout_u2_dock()
|
|
|
|
|
|
## Optional debug navigation for real-window visual inspection. Only active
|
|
## when WINDROOST_DEBUG_PAGE is set (e.g. map/battle/settings); the player's
|
|
## normal first-run flow is untouched.
|
|
func _apply_debug_nav() -> void:
|
|
var target := OS.get_environment("WINDROOST_DEBUG_PAGE")
|
|
if target.is_empty():
|
|
return
|
|
match target:
|
|
"map":
|
|
show_page(PAGE_MAP)
|
|
"world":
|
|
show_page(PAGE_WORLD)
|
|
"side":
|
|
show_page(PAGE_SIDE)
|
|
"loadout":
|
|
show_page(PAGE_LOADOUT)
|
|
"settings":
|
|
show_page(PAGE_SETTINGS)
|
|
"growth", "company":
|
|
show_page(PAGE_GROWTH)
|
|
"battle":
|
|
var node_id := OS.get_environment("WINDROOST_DEBUG_NODE")
|
|
if node_id.is_empty():
|
|
node_id = "R1-C01-N10"
|
|
start_node(node_id)
|
|
"event":
|
|
start_node("R1-C01-N04")
|
|
_:
|
|
pass
|
|
|
|
|
|
func _build_background() -> void:
|
|
var background := TextureRect.new()
|
|
background.texture = load("res://assets/windplain_pixel_background_source.png") as Texture2D
|
|
background.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
|
background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
background.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
background.modulate = Color(0.52, 0.60, 0.74, 1.0)
|
|
add_child(background)
|
|
var veil := ColorRect.new()
|
|
veil.color = Color(0.03, 0.08, 0.14, 0.18)
|
|
veil.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
veil.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(veil)
|
|
|
|
|
|
func _build_header() -> void:
|
|
# A quiet translucent strip instead of a bright gold box: the pixel sky
|
|
# behind the header should stay visible and the currencies should read as
|
|
# status, not as another primary action.
|
|
var header := UiTheme.make_status_strip()
|
|
header.set_anchors_and_offsets_preset(Control.PRESET_TOP_WIDE)
|
|
header.offset_left = 8
|
|
header.offset_right = -8
|
|
header.offset_top = 8
|
|
header.custom_minimum_size = Vector2(0, 52)
|
|
add_child(header)
|
|
_header_box = header
|
|
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 14)
|
|
margin.add_theme_constant_override("margin_right", 14)
|
|
margin.add_theme_constant_override("margin_top", 6)
|
|
margin.add_theme_constant_override("margin_bottom", 6)
|
|
header.add_child(margin)
|
|
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 10)
|
|
margin.add_child(row)
|
|
|
|
_header_gold = UiTheme.make_label("0", 14, UiTheme.COLOR_BORDER)
|
|
_header_crystal = UiTheme.make_label("0", 14, UiTheme.COLOR_MINT)
|
|
row.add_child(_icon_rect("res://assets/icons/icon_gold.png"))
|
|
row.add_child(_header_gold)
|
|
row.add_child(_icon_rect("res://assets/icons/icon_crystal.png"))
|
|
row.add_child(_header_crystal)
|
|
var title := UiTheme.make_label(UiText.t("shell.title", locale), 15)
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
|
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
row.add_child(title)
|
|
_header_title = title
|
|
|
|
|
|
func _icon_rect(path: String) -> TextureRect:
|
|
var icon := TextureRect.new()
|
|
icon.texture = load(path) as Texture2D
|
|
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
icon.custom_minimum_size = Vector2(18, 18)
|
|
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
return icon
|
|
|
|
|
|
func _build_page_host() -> void:
|
|
_page_host = Control.new()
|
|
_page_host.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_page_host.offset_top = 68
|
|
_page_host.offset_bottom = -72
|
|
_page_host.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
add_child(_page_host)
|
|
|
|
|
|
func _build_skyport() -> void:
|
|
# U2: the accepted U1 visual layer is a VIEW inside the live shell. No
|
|
# UiSliceShell is created, so routing/locale/save/progress keep one owner.
|
|
_skyport = Control.new()
|
|
_skyport.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_skyport.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_skyport)
|
|
|
|
_u2_skyport = UiPageSkyport.new()
|
|
_u2_skyport.name = "U2SkyportVisual"
|
|
_u2_skyport.build(locale, reduced_motion)
|
|
_skyport.add_child(_u2_skyport)
|
|
|
|
skyport_report_text = _u2_skyport.report_label
|
|
_skyport_report_button = _u2_skyport.tap_targets.get("skyport_claim") as Button
|
|
if _skyport_report_button != null:
|
|
_skyport_report_button.pressed.connect(_on_claim_offline)
|
|
|
|
# U1 building tiles are rebound to real hero upgrades; no invented levels.
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
for i in range(4):
|
|
var tile: Button = _u2_skyport.tap_targets.get("skyport_building_%d" % i) as Button
|
|
if tile != null and i < unlocked.size():
|
|
tile.pressed.connect(_on_upgrade.bind(str(unlocked[i])))
|
|
for hid in ["H01", "H02", "H03"]:
|
|
var upgrade: Button = _u2_skyport.tap_targets.get("skyport_upgrade_%s" % hid) as Button
|
|
if upgrade != null:
|
|
upgrade.pressed.connect(_on_upgrade.bind(hid))
|
|
|
|
# U1 tertiary drawer becomes the real world/side/loadout/growth routes.
|
|
var drawer_routes := {
|
|
0: PAGE_WORLD, 1: PAGE_SIDE, 2: PAGE_LOADOUT, 3: PAGE_GROWTH,
|
|
}
|
|
for i in drawer_routes.keys():
|
|
var entry: Button = _u2_skyport.tap_targets.get("skyport_more_%d" % int(i)) as Button
|
|
if entry != null:
|
|
entry.pressed.connect(show_page.bind(str(drawer_routes[i])))
|
|
|
|
# Shipped secondary entries are appended so U2 never removes an entry point.
|
|
_u2_skyport.add_action_row([
|
|
{"id": "auto", "icon": "res://assets/icons/icon_tempo_bolt.png", "text": UiText.t("shell.auto.note", locale)},
|
|
{"id": "endless", "icon": "res://assets/icons/icon_tempo_bolt.png", "text": UiText.t("shell.endless.button", locale)},
|
|
{"id": "rebuild", "icon": "res://assets/icons/icon_hammer.png", "text": UiText.t("shell.rebuild.button", locale)},
|
|
{"id": "prestige", "icon": "", "text": UiText.t("shell.prestige.title", locale)},
|
|
])
|
|
_auto_run_button = _u2_skyport.tap_targets.get("skyport_action_auto") as Button
|
|
if _auto_run_button != null:
|
|
_auto_run_button.pressed.connect(_on_toggle_auto_run)
|
|
var endless_button: Button = _u2_skyport.tap_targets.get("skyport_action_endless") as Button
|
|
if endless_button != null:
|
|
endless_button.pressed.connect(func() -> void:
|
|
_on_endless()
|
|
show_page(PAGE_ENDLESS))
|
|
var rebuild_button: Button = _u2_skyport.tap_targets.get("skyport_action_rebuild") as Button
|
|
if rebuild_button != null:
|
|
rebuild_button.pressed.connect(_on_rebuild)
|
|
var prestige_button: Button = _u2_skyport.tap_targets.get("skyport_action_prestige") as Button
|
|
if prestige_button != null:
|
|
prestige_button.pressed.connect(_on_prestige_preview)
|
|
|
|
# Keep the legacy row hooks meaningful for _refresh_pages (no new state).
|
|
for hid in ["H01", "H02", "H03"]:
|
|
var meta: Dictionary = _u2_skyport._hero_meta.get(hid, {})
|
|
_skyport_upgrade_rows[hid] = {
|
|
"level": meta.get("level"),
|
|
"dps": meta.get("dps"),
|
|
"button": _u2_skyport.tap_targets.get("skyport_upgrade_%s" % hid),
|
|
}
|
|
|
|
|
|
func _build_map() -> void:
|
|
_map = Control.new()
|
|
_map.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_map.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_map)
|
|
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
# STOP (not PASS): the scroll container must receive touch/drag events to
|
|
# scroll its content. PASS makes events fall through to the parent and the
|
|
# list becomes unscrollable on touch devices.
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_map.add_child(scroll)
|
|
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 12)
|
|
outer.add_theme_constant_override("margin_right", 12)
|
|
outer.add_theme_constant_override("margin_top", 6)
|
|
outer.add_theme_constant_override("margin_bottom", 6)
|
|
scroll.add_child(outer)
|
|
|
|
var column := VBoxContainer.new()
|
|
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
column.add_theme_constant_override("separation", 6)
|
|
outer.add_child(column)
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.map.title", locale), 20))
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.map.note", locale), 12, UiTheme.COLOR_TEXT_DIM))
|
|
|
|
# Chapter progress rail: a labelled bar makes the journey legible at a
|
|
# glance instead of reading ten identical rows.
|
|
var progress_row := HBoxContainer.new()
|
|
progress_row.add_theme_constant_override("separation", 10)
|
|
column.add_child(progress_row)
|
|
_map_progress = UiTheme.make_label("", 11, UiTheme.COLOR_BORDER)
|
|
progress_row.add_child(_map_progress)
|
|
var track := ColorRect.new()
|
|
track.color = Color(0.10, 0.16, 0.24, 1)
|
|
track.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
track.custom_minimum_size = Vector2(0, 8)
|
|
track.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
progress_row.add_child(track)
|
|
_map_progress_fill = ColorRect.new()
|
|
_map_progress_fill.color = UiTheme.COLOR_MINT
|
|
_map_progress_fill.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_map_progress_fill.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
track.add_child(_map_progress_fill)
|
|
|
|
var node_list: Array = LaunchContent.nodes()
|
|
for index in range(node_list.size()):
|
|
var row: Dictionary = node_list[index]
|
|
var node_id := str(row.get("id", ""))
|
|
var node_type := str(row.get("type", "normal"))
|
|
var panel := UiTheme.make_panel()
|
|
column.add_child(panel)
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 14)
|
|
margin.add_theme_constant_override("margin_right", 10)
|
|
margin.add_theme_constant_override("margin_top", 6)
|
|
margin.add_theme_constant_override("margin_bottom", 6)
|
|
panel.add_child(margin)
|
|
var line := HBoxContainer.new()
|
|
line.add_theme_constant_override("separation", 8)
|
|
margin.add_child(line)
|
|
# A route step dot: filled mint when cleared, gold for the current
|
|
# target, dim when locked. Combined with the progress bar it reads as
|
|
# a journey rather than ten identical rows.
|
|
var dot := ColorRect.new()
|
|
dot.color = UiTheme.COLOR_TEXT_DIM
|
|
dot.custom_minimum_size = Vector2(10, 10)
|
|
dot.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
line.add_child(dot)
|
|
_map_connectors.append({"dot": dot, "node_id": node_id})
|
|
# Type icon (sword / shield / question / flag).
|
|
line.add_child(_icon_rect(_node_type_icon(node_type)))
|
|
var labels := VBoxContainer.new()
|
|
labels.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
labels.add_theme_constant_override("separation", 0)
|
|
line.add_child(labels)
|
|
var name_label := UiTheme.make_label(
|
|
UiText.node_name(node_id, locale), 12
|
|
)
|
|
name_label.clip_text = true
|
|
labels.add_child(name_label)
|
|
var type_label := UiTheme.make_label(
|
|
UiText.t("shell.node.type.%s" % node_type) + " · %02d" % int(row.get("index", 0)),
|
|
9, _node_type_color(node_type)
|
|
)
|
|
labels.add_child(type_label)
|
|
var status := UiTheme.make_label("", 11, UiTheme.COLOR_TEXT_DIM)
|
|
line.add_child(status)
|
|
var button := UiTheme.make_button(UiText.t("shell.node.start", locale), 12)
|
|
button.custom_minimum_size = Vector2(70, 40)
|
|
button.pressed.connect(_on_start_node.bind(node_id))
|
|
line.add_child(button)
|
|
_map_rows[node_id] = {"status": status, "button": button, "panel": panel}
|
|
|
|
|
|
func _signature_icon(signature: String) -> String:
|
|
match signature:
|
|
"break":
|
|
return "res://assets/icons/icon_shield_break.png"
|
|
"single":
|
|
return "res://assets/icons/icon_single_arrow.png"
|
|
"aoe":
|
|
return "res://assets/icons/icon_aoe_fireball.png"
|
|
"click":
|
|
return "res://assets/icons/icon_click_gear.png"
|
|
"tempo":
|
|
return "res://assets/ui/ui_icon_bolt.png"
|
|
"sustain":
|
|
return "res://assets/icons/icon_sustain_leaf.png"
|
|
_:
|
|
return "res://assets/icons/icon_sword.png"
|
|
|
|
|
|
func _node_type_color(node_type: String) -> Color:
|
|
match node_type:
|
|
"elite":
|
|
return UiTheme.COLOR_ORANGE
|
|
"event":
|
|
return UiTheme.COLOR_MINT
|
|
"boss":
|
|
return Color("#d35a5a") # danger red
|
|
_:
|
|
return UiTheme.COLOR_BORDER
|
|
|
|
|
|
func _node_type_icon(node_type: String) -> String:
|
|
match node_type:
|
|
"elite":
|
|
return "res://assets/icons/icon_shield_break.png"
|
|
"event":
|
|
return "res://assets/icons/icon_question.png"
|
|
"boss":
|
|
return "res://assets/icons/icon_flag.png"
|
|
_:
|
|
return "res://assets/icons/icon_sword.png"
|
|
|
|
|
|
func _build_world() -> void:
|
|
# U2: U1 route-spine visuals live inside the live world page. Region,
|
|
# chapter, node and launch state remain GameRoot's authority.
|
|
_world = Control.new()
|
|
_world.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_world.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_world)
|
|
|
|
_u2_world = UiPageWorld.new()
|
|
_u2_world.name = "U2WorldVisual"
|
|
_u2_world.build(locale, reduced_motion)
|
|
_world.add_child(_u2_world)
|
|
_world_detail = _u2_world.detail_label_ref
|
|
_world.visible = false
|
|
|
|
|
|
func _clear_children(node: Node) -> void:
|
|
for child in node.get_children():
|
|
node.remove_child(child)
|
|
child.free()
|
|
|
|
|
|
func _refresh_world() -> void:
|
|
if _world == null or _u2_world == null:
|
|
return
|
|
_refresh_world_progress()
|
|
var regions: Array = WorldContent.regions()
|
|
if not regions.is_empty() and not regions.has(_world_region):
|
|
_world_region = str(regions[0])
|
|
var chapters: Array = WorldContent.chapters(_world_region)
|
|
if not chapters.is_empty() and not chapters.has(_world_chapter):
|
|
_world_chapter = str(chapters[0])
|
|
var nodes: Array = WorldContent.nodes(_world_chapter)
|
|
if not nodes.is_empty():
|
|
var first_id := str((nodes[0] as Dictionary).get("id", ""))
|
|
if _world_node.is_empty() or not _has_world_node(_world_node):
|
|
_world_node = first_id
|
|
|
|
var node_rows: Array = []
|
|
for row in nodes:
|
|
var nid := str((row as Dictionary).get("id", ""))
|
|
var available := _is_world_node_available(nid)
|
|
var done := _is_world_node_done(nid)
|
|
node_rows.append({
|
|
"id": nid,
|
|
"type": str((row as Dictionary).get("type", "normal")),
|
|
"state": "done" if done else ("available" if available else "locked"),
|
|
"label": "%02d · %s" % [int((row as Dictionary).get("index", 0)), UiText.node_name(nid, locale)],
|
|
})
|
|
var done_count := (profile.get("completed_nodes", []) as Array).size()
|
|
_u2_world.set_runtime({
|
|
"region": _world_region,
|
|
"regions": regions,
|
|
"chapters": chapters,
|
|
"nodes": node_rows,
|
|
"selected": _world_node,
|
|
"detail_text": UiText.t("shell.world.select", locale),
|
|
"ratio": float(done_count) / float(maxi(1, int(WorldContent.counts().get("nodes", 600)))),
|
|
})
|
|
_refresh_world_detail()
|
|
|
|
# Connect each generated view control once to the existing authority path.
|
|
for rid in regions:
|
|
_connect_u2_target("region_%s" % rid, "world_region_%s" % rid, _select_world_region.bind(str(rid)))
|
|
for ck in chapters:
|
|
_connect_u2_target("chapter_%s" % ck, "world_chapter_%s" % ck, _select_world_chapter.bind(str(ck)))
|
|
for row in nodes:
|
|
var nid := str((row as Dictionary).get("id", ""))
|
|
_connect_u2_target("node_%s" % nid, "world_node_%s" % nid, _select_world_node.bind(nid))
|
|
if current_page == PAGE_WORLD:
|
|
_update_u2_dock()
|
|
|
|
|
|
func _connect_u2_target(key: String, target: String, callback: Callable) -> void:
|
|
if _u2_world == null or _u2_connected.has(key):
|
|
return
|
|
var button: Button = _u2_world.tap_targets.get(target) as Button
|
|
if button == null:
|
|
return
|
|
button.pressed.connect(callback)
|
|
_u2_connected[key] = true
|
|
|
|
|
|
func _refresh_world_progress() -> void:
|
|
if _world_progress == null:
|
|
return
|
|
var highest := int(profile.get("highest_node", 0))
|
|
var done := (profile.get("completed_nodes", []) as Array).size()
|
|
_world_progress.text = UiText.tf("shell.world.progress", {"cur": highest, "done": done}, locale)
|
|
|
|
|
|
func _refresh_world_detail() -> void:
|
|
if _world_detail == null:
|
|
return
|
|
var row := WorldContent.node(_world_node)
|
|
if row.is_empty():
|
|
_world_detail.text = UiText.t("shell.world.select", locale)
|
|
return
|
|
var ntype := str(row.get("type", "normal"))
|
|
var type_text := UiText.t("shell.world.type.%s" % ntype, locale)
|
|
var theme := UiText.t("world.theme.%s" % str(row.get("chapter", "")), locale)
|
|
var waves := (row.get("waves", []) as Array).size()
|
|
_world_detail.text = UiText.tf("shell.world.detail", {
|
|
"id": _world_node, "type": type_text, "theme": theme, "waves": waves,
|
|
"gold": int(row.get("gold", 0)), "crystal": int(row.get("crystal", 0)),
|
|
}, locale)
|
|
if not _is_world_node_available(_world_node):
|
|
_world_detail.text += "\n" + UiText.t("shell.world.locked", locale)
|
|
|
|
|
|
func _has_world_node(node_id: String) -> bool:
|
|
return not WorldContent.node(node_id).is_empty()
|
|
|
|
|
|
func _select_world_region(region_id: String) -> void:
|
|
_world_region = region_id
|
|
var chapters: Array = WorldContent.chapters(region_id)
|
|
if not chapters.is_empty():
|
|
_world_chapter = str(chapters[0])
|
|
_world_node = ""
|
|
_refresh_world()
|
|
|
|
|
|
func _select_world_chapter(chapter_id: String) -> void:
|
|
_world_chapter = chapter_id
|
|
var nodes: Array = WorldContent.nodes(chapter_id)
|
|
_world_node = "" if nodes.is_empty() else str((nodes[0] as Dictionary).get("id", ""))
|
|
_refresh_world()
|
|
|
|
|
|
func _select_world_node(node_id: String) -> void:
|
|
_world_node = node_id
|
|
_refresh_world()
|
|
|
|
|
|
func _world_node_order(node_id: String) -> int:
|
|
var row := WorldContent.node(node_id)
|
|
if row.is_empty():
|
|
return 0
|
|
var parts := node_id.split("-")
|
|
if parts.size() < 3:
|
|
return 0
|
|
var region_idx := int(parts[0].substr(1)) - 1
|
|
var chapter_idx := int(parts[1].substr(1)) - 1
|
|
var node_idx := int(row.get("index", 0))
|
|
return region_idx * 120 + chapter_idx * 10 + node_idx
|
|
|
|
|
|
func _is_world_node_done(node_id: String) -> bool:
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
return completed.has(node_id)
|
|
|
|
|
|
func _is_world_node_available(node_id: String) -> bool:
|
|
if _is_world_node_done(node_id):
|
|
return false
|
|
return _world_node_order(node_id) <= int(profile.get("highest_node", 0)) + 1
|
|
|
|
|
|
## Next available world node after the cleared one, in content order. Selection
|
|
## only: no reward, save, unlock, auto-run or route mutation happens here.
|
|
func _world_next_node_id(node_id: String) -> String:
|
|
var row := WorldContent.node(node_id)
|
|
if row.is_empty():
|
|
return ""
|
|
var current_order := _world_node_order(node_id)
|
|
var found := false
|
|
for next_row in WorldContent.nodes():
|
|
var next_id := str((next_row as Dictionary).get("id", ""))
|
|
if next_id == node_id:
|
|
found = true
|
|
continue
|
|
if found and _world_node_order(next_id) > current_order \
|
|
and _is_world_node_available(next_id):
|
|
return next_id
|
|
return ""
|
|
|
|
|
|
## WR170 settlement-return semantics: a world victory used to leave the cleared
|
|
## node selected, which disabled the launch CTA and pushed the next node below
|
|
## the fold. Re-select the existing next available node on return. Chapter and
|
|
## region state follow the selected node so a boundary node is visible.
|
|
func _select_world_next_after_settlement() -> void:
|
|
var next_id := _world_next_node_id(active_node)
|
|
if not next_id.is_empty():
|
|
var next_row := WorldContent.node(next_id)
|
|
_world_region = str(next_row.get("region", _world_region))
|
|
_world_chapter = str(next_row.get("chapter", _world_chapter))
|
|
_select_world_node(next_id)
|
|
|
|
|
|
func _launch_world_node() -> void:
|
|
if _world_node.is_empty():
|
|
return
|
|
var row := WorldContent.node(_world_node)
|
|
if row.is_empty() or not _is_world_node_available(_world_node):
|
|
return
|
|
var scenario := WorldContent.scenario_for_node(_world_node, 0, profile.get("unlocked_heroes", []))
|
|
if scenario.is_empty():
|
|
return
|
|
_world_mode = true
|
|
active_node = _world_node
|
|
active_wave = 0
|
|
_revive_budget_left = PartnerPerks.effective_revives(profile)
|
|
# Full-game nodes consume the authored per-talent stat values, not the
|
|
# slice's flat fallback. Both engines are parity-gated on this path.
|
|
scenario["growth_modifiers"] = GrowthModifiers.compute_full_game(profile)
|
|
_present_battle(scenario, _world_node, 0)
|
|
|
|
|
|
func _on_world_battle_finished(result: String, _reward_id: String, _sid: String) -> void:
|
|
_world_mode = false
|
|
var row := WorldContent.node(active_node)
|
|
if result == "win":
|
|
var gold := int(row.get("gold", 0))
|
|
var crystal := int(row.get("crystal", 0))
|
|
var claimed := ProfileStore.claim_once(profile, str(row.get("reward_id", "")))
|
|
if claimed:
|
|
sfx.play("reward", "sfx")
|
|
sfx.play("victory", "sfx")
|
|
profile["gold"] = int(profile.get("gold", 0)) + gold
|
|
profile["crystal"] = int(profile.get("crystal", 0)) + crystal
|
|
profile["battle_wins"] = int(profile.get("battle_wins", 0)) + 1
|
|
profile["total_gold_earned"] = int(profile.get("total_gold_earned", 0)) + gold
|
|
profile["total_essence_earned"] = int(profile.get("total_essence_earned", 0)) + int(floor(float(_world_node_order(active_node)) / 10.0))
|
|
# Gear drops this round (design 7.2); equipped gear feeds growth.
|
|
GearActions.grant_drop(profile, active_node, WorldContent.content())
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
if not completed.has(active_node):
|
|
completed.append(active_node)
|
|
profile["completed_nodes"] = completed
|
|
# Derive the L2/L3 progress counters from the authoritative cleared set.
|
|
var chapters_done: Dictionary = {}
|
|
var regions_done: Dictionary = {}
|
|
var boss_clears := 0
|
|
var final_clears := 0
|
|
for nid in completed:
|
|
var nr := WorldContent.node(str(nid))
|
|
if nr.is_empty():
|
|
continue
|
|
chapters_done[str(nr.get("chapter", ""))] = true
|
|
regions_done[str(nr.get("region", ""))] = true
|
|
if str(nr.get("type", "")) == "boss":
|
|
boss_clears += 1
|
|
if str(nr.get("chapter", "")) == "R5-C12":
|
|
final_clears += 1
|
|
profile["completed_chapters"] = chapters_done.size()
|
|
profile["region_boss_first_clears"] = boss_clears
|
|
profile["completed_regions"] = regions_done.size()
|
|
profile["final_boss_first_clears"] = final_clears
|
|
var order := _world_node_order(active_node)
|
|
if int(profile.get("highest_node", 0)) < order:
|
|
profile["highest_node"] = order
|
|
ProfileStore.save_profile(profile)
|
|
_show_modal(UiText.t("shell.prestige.done", locale), UiText.tf("shell.world.result", {
|
|
"id": active_node, "gold": gold, "crystal": crystal,
|
|
}, locale), [{"label": UiText.t("shell.world.back", locale), "action": "world_settlement"}], -1, {
|
|
"state": "victory", "reward_gold": gold, "time": "", "ally_visible": false,
|
|
"cause": UiText.tf("shell.victory.cleared", {
|
|
"region": UiText.t("content.region.%s" % active_node.substr(0, 2), locale),
|
|
"index": int(row.get("index", 0)),
|
|
}, locale),
|
|
"return_label": UiText.t("shell.world.back", locale),
|
|
})
|
|
else:
|
|
sfx.play("defeat", "sfx")
|
|
_show_modal(UiText.t("shell.defeat.title", locale), UiText.t("shell.defeat.body", locale), [
|
|
{"label": UiText.t("shell.world.back", locale), "action": "world"},
|
|
], -1, {
|
|
"state": "defeat", "reason": UiText.t("shell.defeat.body", locale),
|
|
"time": "", "return_label": UiText.t("shell.world.back", locale),
|
|
})
|
|
|
|
|
|
func _build_side() -> void:
|
|
_side = Control.new()
|
|
_side.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_side.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_side)
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_side.add_child(scroll)
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 12)
|
|
outer.add_theme_constant_override("margin_right", 12)
|
|
outer.add_theme_constant_override("margin_top", 8)
|
|
outer.add_theme_constant_override("margin_bottom", 8)
|
|
scroll.add_child(outer)
|
|
var column := VBoxContainer.new()
|
|
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
column.add_theme_constant_override("separation", 7)
|
|
outer.add_child(column)
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.side.title", locale), 20))
|
|
var tab_grid := GridContainer.new()
|
|
tab_grid.columns = 3
|
|
tab_grid.add_theme_constant_override("h_separation", 6)
|
|
tab_grid.add_theme_constant_override("v_separation", 6)
|
|
column.add_child(tab_grid)
|
|
for tab in ["partners", "records", "market", "interactions", "guild", "bounties"]:
|
|
var btn := UiTheme.make_button(UiText.t("shell.side.%s" % tab, locale), 13)
|
|
btn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
btn.pressed.connect(_select_side_tab.bind(tab))
|
|
tab_grid.add_child(btn)
|
|
_side_tabs[tab] = btn
|
|
_ch_targets["side_tab_%s" % tab] = btn
|
|
_side_scroll = scroll
|
|
_side_summary = UiTheme.make_label("", 12, UiTheme.COLOR_BORDER)
|
|
# Long localized summaries (en_US guild/bounties) must wrap, not widen the
|
|
# column past the phone viewport and push row buttons off-screen.
|
|
_side_summary.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
column.add_child(_side_summary)
|
|
_side_rows = VBoxContainer.new()
|
|
_side_rows.add_theme_constant_override("separation", 6)
|
|
column.add_child(_side_rows)
|
|
_side.visible = false
|
|
|
|
|
|
func _refresh_side() -> void:
|
|
if _side == null:
|
|
return
|
|
for tab in _side_tabs.keys():
|
|
var btn: Button = _side_tabs[tab]
|
|
# Tab captions are built once in _build_side; rebind them here so a
|
|
# locale switch while on another page is reflected when returning.
|
|
btn.text = UiText.t("shell.side.%s" % tab, locale)
|
|
btn.add_theme_stylebox_override("normal", UiTheme.tab_style(tab == _side_tab))
|
|
_clear_children(_side_rows)
|
|
var pack := WorldContent.content()
|
|
match _side_tab:
|
|
"partners":
|
|
_side_summary.text = UiText.t("shell.side.partner_note", locale)
|
|
var rows := SideSystems.partner_status(profile, pack.get("partners", []))
|
|
for row in rows:
|
|
var target := int(row.get("step", 1)) * (int(row.get("claimed", 0)) + 1)
|
|
var info := UiText.tf("shell.side.partner_row", {
|
|
"name": row.get("name", ""), "role": row.get("role", ""),
|
|
"level": row.get("level", 0),
|
|
"progress": mini(int(row.get("progress", 0)), target),
|
|
"target": target,
|
|
"gold": row.get("next_reward_gold", 0), "crystal": row.get("next_reward_crystal", 0),
|
|
}, locale)
|
|
var claimable := int(row.get("claimable", 0)) > 0
|
|
_add_side_row(info, UiText.t("shell.side.claim", locale), claimable,
|
|
_on_partner_claim.bind(str(row.get("id", ""))))
|
|
"records":
|
|
var rows2 := SideSystems.record_status(profile, pack.get("records", []))
|
|
var claimed := 0
|
|
var claimable := 0
|
|
var open_rows: Array = []
|
|
for row in rows2:
|
|
if bool(row.get("claimed", false)):
|
|
claimed += 1
|
|
elif bool(row.get("claimable", false)):
|
|
claimable += 1
|
|
open_rows.append(row)
|
|
_side_summary.text = UiText.tf("shell.side.record_summary", {
|
|
"claimed": claimed, "total": rows2.size(), "claimable": claimable,
|
|
}, locale) + " · " + UiText.t("shell.side.record_note", locale)
|
|
if open_rows.is_empty():
|
|
var empty := UiTheme.make_label(UiText.t("shell.side.no_claim", locale), 12, UiTheme.COLOR_TEXT_DIM)
|
|
_side_rows.add_child(empty)
|
|
else:
|
|
for row in open_rows.slice(0, 12):
|
|
var rid := str(row.get("id", ""))
|
|
var info2 := UiText.tf("shell.side.record_row", {
|
|
"id": rid, "category": row.get("category", ""),
|
|
"progress": row.get("progress", 0), "target": row.get("target", 0),
|
|
"gold": row.get("reward_gold", 0), "crystal": row.get("reward_crystal", 0),
|
|
}, locale)
|
|
var title := UiText.t("record.%s.title" % rid, locale)
|
|
var desc := UiText.t("record.%s.desc" % rid, locale)
|
|
info2 = "%s · %s\n%s" % [title, desc, info2]
|
|
_add_side_row(info2, UiText.t("shell.side.claim", locale), true,
|
|
_on_record_claim.bind(rid))
|
|
"market":
|
|
_side_summary.text = UiText.t("shell.side.market_note", locale)
|
|
for row in SideSystems.market_status(profile, pack.get("market", [])):
|
|
var info3 := UiText.tf("shell.side.market_row", {
|
|
"category": row.get("category", ""), "price": row.get("price", 0),
|
|
}, locale)
|
|
_add_side_row(info3, UiText.t("shell.side.buy", locale), bool(row.get("affordable", false)),
|
|
_on_market_buy.bind(str(row.get("id", ""))))
|
|
"interactions":
|
|
_refresh_interactions(pack)
|
|
"guild":
|
|
_refresh_ch_guild()
|
|
"bounties":
|
|
_refresh_ch_bounties()
|
|
|
|
|
|
func _add_ch_row(key: String, text: String, button_text: String, enabled: bool, callback: Callable) -> void:
|
|
_add_side_row(text, button_text, enabled, callback)
|
|
var panel := _side_rows.get_child(_side_rows.get_child_count() - 1)
|
|
if panel is Control:
|
|
var buttons := _find_buttons(panel)
|
|
if not buttons.is_empty():
|
|
_ch_targets[key] = buttons[buttons.size() - 1]
|
|
|
|
|
|
func _find_buttons(node: Node) -> Array:
|
|
var found: Array = []
|
|
if node is Button:
|
|
found.append(node)
|
|
for child in node.get_children():
|
|
for b in _find_buttons(child):
|
|
found.append(b)
|
|
return found
|
|
|
|
|
|
func _refresh_ch_guild() -> void:
|
|
var slots := ProfileStore.ch_slots(profile)
|
|
var auto: Dictionary = profile.get("autoclick", {}) if profile.get("autoclick") is Dictionary else {}
|
|
var ach: Dictionary = profile.get("ch_achievements", {}) if profile.get("ch_achievements") is Dictionary else {}
|
|
var owned := int(auto.get("owned", 0))
|
|
var now_ms := Time.get_unix_time_from_system() * 1000
|
|
_side_summary.text = UiText.tf("shell.side.guild_note", {
|
|
"count": slots.size(), "owned": owned, "rate": ChSystems.autoclicker_rate(owned),
|
|
"clicks": int(auto.get("total_clicks", 0)), "bonus": int(ach.get("click_bonus", 0)),
|
|
}, locale)
|
|
var hire_price := ChSystems.HIRE_COST
|
|
_add_ch_row("ch_hire", UiText.tf("shell.side.guild_hire", {
|
|
"cost": hire_price, "crystal": int(profile.get("crystal", 0)),
|
|
}, locale), UiText.t("shell.side.guild_hire_btn", locale),
|
|
int(profile.get("crystal", 0)) >= hire_price and slots.size() < 5, _on_ch_hire)
|
|
var clicker_price := ChSystems.autoclicker_price(owned)
|
|
_add_ch_row("ch_buy_clicker", UiText.tf("shell.side.guild_clicker", {"price": clicker_price}, locale),
|
|
UiText.t("shell.side.guild_clicker_btn", locale),
|
|
clicker_price >= 0 and int(profile.get("gold", 0)) >= clicker_price, _on_ch_buy_clicker)
|
|
if slots.is_empty():
|
|
var empty_hint := UiTheme.make_label(UiText.t("shell.side.guild_empty", locale), 12, UiTheme.COLOR_TEXT_DIM)
|
|
empty_hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
_side_rows.add_child(empty_hint)
|
|
for item in slots:
|
|
var slot: Dictionary = item
|
|
var uid := int(slot.get("uid", 0))
|
|
var quest: Dictionary = slot.get("quest", {})
|
|
var state := ChSystems.quest_status(quest, now_ms)
|
|
var progress := int(round(ChSystems.quest_progress(quest, now_ms) * 100.0))
|
|
var info := UiText.tf("shell.side.guild_slot", {
|
|
"uid": uid, "level": int(slot.get("level", 1)), "status": state,
|
|
"progress": progress, "gold": int(quest.get("quantity", 0)),
|
|
}, locale)
|
|
match state:
|
|
"idle":
|
|
_add_ch_row("ch_quest_%d_start" % uid, info, UiText.t("shell.side.guild_start", locale),
|
|
true, _on_ch_start_quest.bind(uid))
|
|
_add_ch_row("ch_quest_%d_dismiss" % uid, UiText.t("shell.side.guild_dismiss_note", locale),
|
|
UiText.t("shell.side.guild_dismiss", locale), true, _on_ch_dismiss.bind(uid))
|
|
"ready":
|
|
_add_ch_row("ch_quest_%d_collect" % uid, info, UiText.t("shell.side.guild_collect", locale),
|
|
true, _on_ch_finish_quest.bind(uid))
|
|
"dead":
|
|
_add_ch_row("ch_quest_%d_revive" % uid, info, UiText.tf("shell.side.guild_revive", {
|
|
"cost": ChSystems.revival_cost(int(slot.get("level", 1))),
|
|
}, locale), int(profile.get("revive_charges", 0)) > 0, _on_ch_revive.bind(uid))
|
|
_:
|
|
_add_ch_row("ch_quest_%d_wait" % uid, info, UiText.t("shell.side.guild_wait", locale), false, Callable())
|
|
|
|
|
|
func _refresh_ch_bounties() -> void:
|
|
var ach: Dictionary = profile.get("ch_achievements", {}) if profile.get("ch_achievements") is Dictionary else {}
|
|
var click: Dictionary = profile.get("clickable", {}) if profile.get("clickable") is Dictionary else {}
|
|
var bonus := int(ach.get("click_bonus", 0))
|
|
var unlocked := (ach.get("obtained", []) as Array).has(ChSystems.CLICK_BONUS_ACHIEVEMENT_ID)
|
|
var uid := int(click.get("active_uid", 0))
|
|
_side_summary.text = UiText.tf("shell.side.bounty_note", {
|
|
"bonus": bonus,
|
|
"state": UiText.t("shell.side.bounty_done" if unlocked else "shell.side.bounty_locked", locale),
|
|
"windfall": UiText.t("shell.side.bounty_clickable" if uid > 0 else "shell.side.bounty_wait", locale),
|
|
}, locale)
|
|
_add_ch_row("ch_achievement", UiText.tf("shell.side.bounty_ach", {"bonus": bonus}, locale),
|
|
UiText.t("shell.side.bounty_seen", locale), false, Callable())
|
|
if uid > 0:
|
|
_add_ch_row("ch_clickable", UiText.t("shell.side.bounty_clickable", locale),
|
|
UiText.t("shell.side.bounty_tap", locale), true, _on_ch_claim_clickable.bind(uid))
|
|
|
|
|
|
func _add_side_row(text: String, button_text: String, enabled: bool, callback: Callable) -> void:
|
|
var panel := UiTheme.make_panel()
|
|
_side_rows.add_child(panel)
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 12)
|
|
margin.add_theme_constant_override("margin_right", 12)
|
|
margin.add_theme_constant_override("margin_top", 6)
|
|
margin.add_theme_constant_override("margin_bottom", 6)
|
|
panel.add_child(margin)
|
|
var line := HBoxContainer.new()
|
|
line.add_theme_constant_override("separation", 8)
|
|
margin.add_child(line)
|
|
var label := UiTheme.make_label(text, 12)
|
|
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
line.add_child(label)
|
|
var btn := UiTheme.make_button(button_text, 12)
|
|
btn.disabled = not enabled
|
|
if callback.is_valid():
|
|
btn.pressed.connect(callback)
|
|
line.add_child(btn)
|
|
|
|
|
|
func _select_side_tab(tab: String) -> void:
|
|
_side_tab = tab
|
|
_refresh_side()
|
|
|
|
|
|
func _side_result_modal(title: String, body: String) -> void:
|
|
_show_modal(title, body, [{"label": UiText.t("shell.world.back", locale), "action": "side"}])
|
|
|
|
|
|
func _on_partner_claim(partner_id: String) -> void:
|
|
var r := SideSystems.claim_partner(profile, partner_id)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("reward", "sfx")
|
|
# A real ScreenTouch emits Button.pressed; rebuilding the side rows inside
|
|
# that signal frees the emitting button mid-emission and crashes Godot.
|
|
# Defer the exact refresh/modal pair to the next idle frame; no route,
|
|
# label or reward change.
|
|
call_deferred("_refresh_side")
|
|
call_deferred("_side_result_modal", UiText.t("shell.side.partners", locale),
|
|
UiText.tf("shell.side.done", {"gold": r.get("gold", 0), "crystal": r.get("crystal", 0)}, locale))
|
|
|
|
|
|
func _on_record_claim(record_id: String) -> void:
|
|
var r := SideSystems.claim_record(profile, record_id, WorldContent.content().get("records", []))
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("reward", "sfx")
|
|
# Same freed-pressed-Button boundary as partner/market claims.
|
|
call_deferred("_refresh_side")
|
|
call_deferred("_side_result_modal", UiText.t("shell.side.records", locale),
|
|
UiText.tf("shell.side.done", {"gold": r.get("gold", 0), "crystal": r.get("crystal", 0)}, locale))
|
|
|
|
|
|
func _on_market_buy(offer_id: String) -> void:
|
|
var r := SideSystems.purchase(profile, offer_id, WorldContent.content())
|
|
var body := ""
|
|
if bool(r.get("ok")):
|
|
# S4: the crystal-only WR offer stays the wallet boundary. M01/M02 bind
|
|
# the already-granted WR relic/emblem to the source-bound CH book; no
|
|
# ruby price, second currency or new paid offer is introduced.
|
|
ChRelicGild.on_market_purchase(profile, offer_id, str(r.get("granted", "")))
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
body = UiText.tf("shell.side.bought", {"effect": r.get("effect", "")}, locale)
|
|
else:
|
|
body = UiText.t("shell.side.insufficient", locale)
|
|
# A real ScreenTouch emits Button.pressed; rebuilding the side rows inside
|
|
# that signal frees the emitting button mid-emission and crashes Godot.
|
|
# Defer both updates to the next idle frame. Routes/text are unchanged.
|
|
call_deferred("_refresh_side")
|
|
call_deferred("_side_result_modal", UiText.t("shell.side.market", locale), body)
|
|
|
|
|
|
## S5/S6 handlers. Every payout goes through ProfileStore's save-first claim and
|
|
## the visible result is a plain-language modal; no callback is exposed outside
|
|
## this shell, so the touch probes must click real Buttons.
|
|
func _ch_result(title_key: String, body: String) -> void:
|
|
_refresh_pages()
|
|
_side_result_modal(UiText.t(title_key, locale), body)
|
|
|
|
|
|
func _on_ch_hire() -> void:
|
|
var r := ProfileStore.hire_merc(profile)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("reward", "sfx")
|
|
_ch_result("shell.side.guild", UiText.tf("shell.side.ch_hired", {"uid": int(r.get("uid", 0))}, locale))
|
|
|
|
|
|
func _on_ch_start_quest(uid: int) -> void:
|
|
var r := ProfileStore.start_quest(profile, uid)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_ch_result("shell.side.guild", UiText.t("shell.side.ch_quest_started", locale))
|
|
|
|
|
|
func _on_ch_finish_quest(uid: int) -> void:
|
|
var r := ProfileStore.finish_quest(profile, uid)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
sfx.play("reward", "sfx")
|
|
_ch_result("shell.side.guild", UiText.tf("shell.side.ch_quest_done", {"gold": int(r.get("gold", 0))}, locale))
|
|
|
|
|
|
func _on_ch_revive(uid: int) -> void:
|
|
var r := ProfileStore.revive_merc(profile, uid)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_ch_result("shell.side.guild", UiText.tf("shell.side.ch_revived", {"cost": int(r.get("cost", 0))}, locale))
|
|
|
|
|
|
func _on_ch_dismiss(uid: int) -> void:
|
|
var r := ProfileStore.dismiss_merc(profile, uid)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
_ch_result("shell.side.guild", UiText.t("shell.side.ch_dismissed", locale))
|
|
|
|
|
|
func _on_ch_buy_clicker() -> void:
|
|
var r := ProfileStore.buy_autoclicker(profile)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_ch_result("shell.side.guild", UiText.tf("shell.side.ch_clicker_bought", {
|
|
"owned": int(r.get("owned", 0)), "price": int(r.get("price", 0)),
|
|
}, locale))
|
|
|
|
|
|
func _on_ch_claim_clickable(uid: int) -> void:
|
|
var r := ProfileStore.claim_clickable(profile, uid)
|
|
if not bool(r.get("ok")):
|
|
return
|
|
sfx.play("reward", "sfx")
|
|
_ch_result("shell.side.bounties", UiText.tf("shell.side.bounty_done2", {
|
|
"crystal": int(r.get("crystal", 0)), "tier": int(r.get("tier", 0)),
|
|
}, locale))
|
|
|
|
|
|
func _on_lowfreq_result(result: Dictionary) -> void:
|
|
var gold := int(result.get("gold", 0))
|
|
var crystal := int(result.get("crystal", 0))
|
|
var frag := int(result.get("fragments", 0))
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("reward", "sfx")
|
|
# Same freed-pressed-Button boundary: echo/crate/commission/journal rows are
|
|
# rebuilt while their Button is still emitting pressed.
|
|
call_deferred("_refresh_side")
|
|
call_deferred("_side_result_modal", UiText.t("shell.interact.title", locale),
|
|
UiText.tf("shell.interact.done", {"gold": gold, "crystal": crystal, "frag": frag}, locale))
|
|
|
|
|
|
func _refresh_interactions(pack: Dictionary) -> void:
|
|
var st := LowFreq.status(profile, pack)
|
|
_side_summary.text = UiText.t("shell.interact.note", locale)
|
|
var echo: Dictionary = st["echo"]
|
|
var buoy: Dictionary = st["buoy"]
|
|
var crate: Dictionary = st["crate"]
|
|
var commission: Dictionary = st["commission"]
|
|
var journal: Dictionary = st["journal"]
|
|
var board_available := false
|
|
for brow in CommissionBoard.status(profile):
|
|
if int((brow as Dictionary).get("available", 0)) > 0:
|
|
board_available = true
|
|
break
|
|
var any_available := int(echo.get("available", 0)) > 0 or bool(buoy.get("available", false)) \
|
|
or int(crate.get("available", 0)) > 0 or int(commission.get("available", 0)) > 0 \
|
|
or not (journal.get("unread", []) as Array).is_empty() or bool(buoy.get("active", false)) \
|
|
or board_available
|
|
if not any_available:
|
|
_side_rows.add_child(UiTheme.make_label(UiText.t("shell.interact.none", locale), 12, UiTheme.COLOR_TEXT_DIM))
|
|
|
|
if int(echo.get("available", 0)) > 0:
|
|
_add_side_row(UiText.tf("shell.interact.echo_desc", {
|
|
"n": 6, "avail": echo.get("available", 0),
|
|
}, locale), UiText.t("shell.interact.claim", locale), true,
|
|
_on_echo_claim.bind())
|
|
if bool(buoy.get("active", false)) or bool(buoy.get("available", false)):
|
|
var taps := int(buoy.get("taps", 0))
|
|
var need := int(buoy.get("need", 5))
|
|
var btext := UiText.tf("shell.interact.buoy_tap", {"taps": taps, "need": need}, locale) \
|
|
if bool(buoy.get("active", false)) else UiText.t("shell.interact.buoy_go", locale)
|
|
_add_side_row(UiText.t("shell.interact.buoy_desc", locale), btext, true,
|
|
_on_buoy.bind())
|
|
if int(crate.get("available", 0)) > 0:
|
|
_add_side_row(UiText.tf("shell.interact.crate_desc", {
|
|
"n": 10, "avail": crate.get("available", 0),
|
|
}, locale), UiText.t("shell.interact.open", locale), true,
|
|
_on_crate_claim.bind())
|
|
if int(commission.get("available", 0)) > 0:
|
|
_add_side_row(UiText.tf("shell.interact.commission_desc", {
|
|
"n": 2, "avail": commission.get("available", 0),
|
|
}, locale), UiText.t("shell.interact.claim", locale), true,
|
|
_on_commission_claim.bind())
|
|
# Stage H: 4-type commission board -- each task type is a distinct row with
|
|
# its own progress counter and reward currency, claimable in the live UI.
|
|
for row in CommissionBoard.status(profile):
|
|
var rd: Dictionary = row
|
|
if int(rd.get("available", 0)) <= 0:
|
|
continue
|
|
var key := "shell.interact.board_" + str(rd.get("type", ""))
|
|
var desc := UiText.tf(key, {
|
|
"prog": rd.get("progress", 0), "step": rd.get("step", 1),
|
|
"avail": rd.get("available", 0),
|
|
}, locale)
|
|
_add_side_row(desc, UiText.t("shell.interact.claim", locale), true,
|
|
_on_board_commission_claim.bind(str(rd.get("type", ""))))
|
|
for chapter in (journal.get("unread", []) as Array):
|
|
_add_side_row(UiText.tf("shell.interact.journal_desc", {
|
|
"n": (journal.get("unread", []) as Array).size(),
|
|
}, locale) + " · " + str(chapter), UiText.t("shell.interact.read", locale), true,
|
|
_on_journal_read.bind(str(chapter)))
|
|
|
|
|
|
func _on_echo_claim() -> void:
|
|
var r := LowFreq.claim_echo(profile)
|
|
if bool(r.get("ok")):
|
|
_on_lowfreq_result(r)
|
|
|
|
|
|
func _on_buoy() -> void:
|
|
var buoy: Dictionary = profile.get("buoy", {})
|
|
if not bool(buoy.get("active", false)):
|
|
LowFreq.start_buoy(profile)
|
|
# A real ScreenTouch emits Button.pressed; rebuilding the side rows
|
|
# inside that signal frees the emitting buoy row mid-emission. Defer
|
|
# only the refresh; start/taps/save/claim order is unchanged.
|
|
call_deferred("_refresh_side")
|
|
return
|
|
var r := LowFreq.tap_buoy(profile)
|
|
if bool(r.get("ok")) and bool(r.get("done")):
|
|
_on_lowfreq_result(r)
|
|
else:
|
|
ProfileStore.save_profile(profile)
|
|
# Same freed-pressed-Button boundary on the partial-tap branch.
|
|
call_deferred("_refresh_side")
|
|
|
|
|
|
func _on_crate_claim() -> void:
|
|
var r := LowFreq.claim_crate(profile)
|
|
if bool(r.get("ok")):
|
|
_on_lowfreq_result(r)
|
|
|
|
|
|
func _on_commission_claim() -> void:
|
|
var r := LowFreq.claim_commission(profile)
|
|
if bool(r.get("ok")):
|
|
_on_lowfreq_result(r)
|
|
|
|
|
|
func _on_board_commission_claim(tid: String) -> void:
|
|
var r := CommissionBoard.claim(profile, tid)
|
|
if bool(r.get("ok")):
|
|
_on_lowfreq_result(r)
|
|
|
|
|
|
## CH-style endless expedition: initialize the BigValue run and show status.
|
|
func _on_endless() -> void:
|
|
var offline_report := ""
|
|
if _endless_state.is_empty():
|
|
# Restore from save (BigValue gold encoded as string) or start fresh.
|
|
var saved: Dictionary = profile.get("endless", {})
|
|
_endless_state = EndlessBattle.from_save(saved) if not saved.is_empty() else EndlessBattle.new_state()
|
|
# CH-style offline settlement: advance the endless run by elapsed time
|
|
# since last save (8h cap), banking BigValue gold. Only when a run exists.
|
|
if not saved.is_empty():
|
|
var saved_at := int(profile.get("last_saved_at", 0))
|
|
var now := Time.get_unix_time_from_system()
|
|
if saved_at > 0 and now > saved_at:
|
|
var r := EndlessOffline.settle(_endless_state, float(now - saved_at))
|
|
var zones: int = int(r.get("zones_cleared", 0))
|
|
if zones > 0:
|
|
_endless_state = r["state"]
|
|
offline_report = "offline +%d zones" % zones
|
|
_endless_offline_msg = offline_report
|
|
profile["endless"] = EndlessBattle.snapshot_for_save(_endless_state)
|
|
ProfileStore.save_profile(profile)
|
|
|
|
|
|
func _show_endless_modal(last_event: Dictionary = {}, offline_report: String = "") -> void:
|
|
var s := _endless_state
|
|
var body := UiText.tf("shell.endless.status", {
|
|
"zone": int(s.get("zone", 1)), "level": int(s.get("level", 1)),
|
|
"essence": int(s.get("essence", 0)), "rebuilds": int(s.get("rebuilds", 0)),
|
|
}, locale)
|
|
body += "\n" + "gold=%s dps=%s" % [
|
|
str(EndlessBattle.snapshot_for_save(s).get("gold", "0:0")),
|
|
EndlessBattle.roster_dps(s.get("bases"), int(s.get("level", 1)),
|
|
int(s.get("essence", 0)), float(s.get("gild", 1.0))).encoded()]
|
|
if not offline_report.is_empty():
|
|
body += "\n" + offline_report
|
|
if not last_event.is_empty():
|
|
body += "\n" + "zone %d · %s · %s" % [int(last_event.get("zone", 0)),
|
|
str(last_event.get("hp", "")), str(last_event.get("dps", ""))]
|
|
_show_modal(UiText.t("shell.endless.title", locale), body, [
|
|
{"label": UiText.t("shell.endless.step", locale), "action": "endless_step"},
|
|
{"label": UiText.t("shell.endless.run", locale), "action": "endless_run"},
|
|
{"label": UiText.t("shell.endless.upgrade", locale), "action": "endless_upgrade"},
|
|
{"label": UiText.t("shell.world.back", locale), "action": "map"},
|
|
])
|
|
|
|
|
|
func _endless_advance(count: int) -> void:
|
|
if _endless_state.is_empty():
|
|
var saved: Dictionary = profile.get("endless", {})
|
|
_endless_state = EndlessBattle.from_save(saved) if not saved.is_empty() else EndlessBattle.new_state()
|
|
var last := {}
|
|
for i in range(count):
|
|
last = EndlessBattle.step(_endless_state)
|
|
# Persist the endless run (BigValue gold -> encoded string, JSON-safe).
|
|
profile["endless"] = EndlessBattle.snapshot_for_save(_endless_state)
|
|
ProfileStore.save_profile(profile)
|
|
_show_endless_modal(last)
|
|
|
|
|
|
func _on_journal_read(chapter: String) -> void:
|
|
var r := LowFreq.claim_journal(profile, chapter)
|
|
if bool(r.get("ok")):
|
|
_on_lowfreq_result(r)
|
|
|
|
|
|
## CH-style endless expedition page: persistent status + actions + zone log.
|
|
func _build_endless() -> void:
|
|
_endless_page = Control.new()
|
|
_endless_page.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_endless_page.visible = false
|
|
_endless_page.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_endless_page)
|
|
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_endless_page.add_child(scroll)
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 14)
|
|
outer.add_theme_constant_override("margin_right", 14)
|
|
outer.add_theme_constant_override("margin_top", 8)
|
|
outer.add_theme_constant_override("margin_bottom", 8)
|
|
scroll.add_child(outer)
|
|
var col := VBoxContainer.new()
|
|
col.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
col.add_theme_constant_override("separation", 10)
|
|
outer.add_child(col)
|
|
|
|
col.add_child(UiTheme.make_label(UiText.t("shell.endless.title", locale), 22))
|
|
_endless_status = UiTheme.make_label("", 15, UiTheme.COLOR_MINT)
|
|
_endless_econ = UiTheme.make_label("", 13, UiTheme.COLOR_TEXT_DIM)
|
|
col.add_child(_endless_status)
|
|
col.add_child(_endless_econ)
|
|
|
|
# Primary actions
|
|
var actions := UiTheme.make_panel()
|
|
var av := VBoxContainer.new()
|
|
av.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
av.add_theme_constant_override("separation", 6)
|
|
actions.add_child(av)
|
|
var b1 := UiTheme.make_button(UiText.t("shell.endless.step", locale), 15)
|
|
b1.custom_minimum_size = Vector2(0, 52)
|
|
b1.pressed.connect(func() -> void: _endless_page_advance(1))
|
|
av.add_child(b1)
|
|
var b2 := UiTheme.make_button(UiText.t("shell.endless.run", locale), 15)
|
|
b2.custom_minimum_size = Vector2(0, 52)
|
|
b2.pressed.connect(func() -> void: _endless_page_advance(25))
|
|
av.add_child(b2)
|
|
var b3 := UiTheme.make_button(UiText.t("shell.endless.upgrade", locale), 15)
|
|
b3.custom_minimum_size = Vector2(0, 52)
|
|
b3.pressed.connect(_endless_page_upgrade)
|
|
av.add_child(b3)
|
|
_endless_actions = av
|
|
col.add_child(actions)
|
|
|
|
col.add_child(UiTheme.make_label(UiText.t("shell.endless.log", locale), 15, UiTheme.COLOR_BORDER))
|
|
_endless_log = VBoxContainer.new()
|
|
_endless_log.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
col.add_child(_endless_log)
|
|
|
|
|
|
func _endless_page_advance(count: int) -> void:
|
|
if _endless_state.is_empty():
|
|
_endless_state = EndlessBattle.new_state()
|
|
for i in range(count):
|
|
var ev := EndlessBattle.step(_endless_state)
|
|
_endless_recent.push_front(ev)
|
|
while _endless_recent.size() > 10:
|
|
_endless_recent.pop_back()
|
|
profile["endless"] = EndlessBattle.snapshot_for_save(_endless_state)
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("reward", "ui")
|
|
_refresh_endless()
|
|
|
|
|
|
func _endless_page_upgrade() -> void:
|
|
if _endless_state.is_empty():
|
|
return
|
|
if EndlessBattle.buy_levels(_endless_state, 5):
|
|
profile["endless"] = EndlessBattle.snapshot_for_save(_endless_state)
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_refresh_endless()
|
|
|
|
|
|
func _refresh_endless() -> void:
|
|
if _endless_state.is_empty():
|
|
var saved: Dictionary = profile.get("endless", {})
|
|
_endless_state = EndlessBattle.from_save(saved) if not saved.is_empty() else EndlessBattle.new_state()
|
|
var s := _endless_state
|
|
_endless_status.text = UiText.tf("shell.endless.status", {
|
|
"zone": int(s.get("zone", 1)), "level": int(s.get("level", 1)),
|
|
"essence": int(s.get("essence", 0)), "rebuilds": int(s.get("rebuilds", 0)),
|
|
}, locale)
|
|
var nd = preload("res://scripts/number_display.gd")
|
|
var dps := EndlessBattle.roster_dps(s.get("bases"), int(s.get("level", 1)),
|
|
int(s.get("essence", 0)), float(s.get("gild", 1.0)))
|
|
_endless_econ.text = "gold=%s dps=%s" % [
|
|
nd.format_number(BigValue.from_text(str(EndlessBattle.snapshot_for_save(s).get("gold", "0:0")))),
|
|
nd.format_number(dps)]
|
|
if not _endless_offline_msg.is_empty():
|
|
_endless_econ.text += " · " + _endless_offline_msg
|
|
# zone log rows
|
|
for child in _endless_log.get_children():
|
|
child.queue_free()
|
|
for ev in _endless_recent:
|
|
var row := UiTheme.make_label("#%d %s %s" % [
|
|
int((ev as Dictionary).get("zone", 0)),
|
|
str((ev as Dictionary).get("seconds", 0)),
|
|
"BOSS" if bool((ev as Dictionary).get("boss")) else "",
|
|
], 12, UiTheme.COLOR_TEXT_DIM)
|
|
_endless_log.add_child(row)
|
|
|
|
|
|
func _build_loadout() -> void:
|
|
_loadout = Control.new()
|
|
_loadout.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_loadout.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_loadout)
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_loadout.add_child(scroll)
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 12)
|
|
outer.add_theme_constant_override("margin_right", 12)
|
|
outer.add_theme_constant_override("margin_top", 8)
|
|
outer.add_theme_constant_override("margin_bottom", 8)
|
|
scroll.add_child(outer)
|
|
var column := VBoxContainer.new()
|
|
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
column.add_theme_constant_override("separation", 7)
|
|
outer.add_child(column)
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.loadout.title", locale), 20))
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.loadout.note", locale), 12, UiTheme.COLOR_TEXT_DIM))
|
|
_loadout_hero_row = HBoxContainer.new()
|
|
_loadout_hero_row.add_theme_constant_override("separation", 6)
|
|
column.add_child(_loadout_hero_row)
|
|
var detail_panel := UiTheme.make_panel()
|
|
column.add_child(detail_panel)
|
|
var dm := MarginContainer.new()
|
|
dm.add_theme_constant_override("margin_left", 12)
|
|
dm.add_theme_constant_override("margin_right", 12)
|
|
dm.add_theme_constant_override("margin_top", 8)
|
|
dm.add_theme_constant_override("margin_bottom", 8)
|
|
detail_panel.add_child(dm)
|
|
_loadout_detail = UiTheme.make_label("", 12, UiTheme.COLOR_BORDER)
|
|
_loadout_detail.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
dm.add_child(_loadout_detail)
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.loadout.gear", locale), 13))
|
|
_loadout_gear_col = VBoxContainer.new()
|
|
_loadout_gear_col.add_theme_constant_override("separation", 5)
|
|
column.add_child(_loadout_gear_col)
|
|
_loadout.visible = false
|
|
|
|
|
|
func _refresh_loadout() -> void:
|
|
if _loadout == null:
|
|
return
|
|
var pack := WorldContent.content()
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
if not unlocked.is_empty() and not unlocked.has(_loadout_hero):
|
|
_loadout_hero = str(unlocked[0])
|
|
_clear_children(_loadout_hero_row)
|
|
for hid in unlocked:
|
|
var btn := UiTheme.make_button(UiText.t("content.hero.%s.short" % str(hid), locale), 12)
|
|
btn.add_theme_stylebox_override("normal", UiTheme.tab_style(str(hid) == _loadout_hero))
|
|
btn.pressed.connect(_select_loadout_hero.bind(str(hid)))
|
|
_loadout_hero_row.add_child(btn)
|
|
|
|
# Hero detail from authored content: signature + 4 structured talents.
|
|
var hero: Dictionary = {}
|
|
for h in pack.get("heroes", []):
|
|
if str((h as Dictionary).get("id", "")) == _loadout_hero:
|
|
hero = h
|
|
break
|
|
var detail := ""
|
|
if not hero.is_empty():
|
|
var sig := str(hero.get("signature", ""))
|
|
var ab: Dictionary = hero.get("abilities", {})
|
|
detail = "%s\n%s: %s\n%s" % [
|
|
UiText.t("content.hero.%s" % _loadout_hero, locale),
|
|
UiText.t("shell.loadout.signature", locale), sig,
|
|
"%s / %s / %s / %s" % [ab.get("a1", ""), ab.get("a2", ""), ab.get("passive", ""), ab.get("ultimate", "")],
|
|
]
|
|
var invested: Dictionary = profile.get("talents", {})
|
|
for slot in range(1, 5):
|
|
var tid := "T-%s-%02d" % [_loadout_hero, slot]
|
|
var tal: Dictionary = {}
|
|
for t in pack.get("talents", []):
|
|
if str((t as Dictionary).get("id", "")) == tid:
|
|
tal = t
|
|
break
|
|
if not tal.is_empty():
|
|
var mark := "✓" if bool(invested.get(tid, false)) else "○"
|
|
detail += "\n%s %s · %s" % [mark, str(tal.get("slot_purpose", "")), str(tal.get("behavior", ""))]
|
|
_loadout_detail.text = detail
|
|
|
|
# Gear slots: equipped item + owned alternatives for that slot.
|
|
_clear_children(_loadout_gear_col)
|
|
var equipped: Dictionary = profile.get("equipped", {})
|
|
for slot in GearActions.SLOTS:
|
|
var owned: Array = GearActions.owned_for_slot(profile, slot, pack)
|
|
var cur := str(equipped.get(slot, ""))
|
|
var label := "%s: %s" % [slot, cur if not cur.is_empty() else UiText.t("shell.loadout.empty", locale)]
|
|
var line := HBoxContainer.new()
|
|
line.add_theme_constant_override("separation", 8)
|
|
_loadout_gear_col.add_child(line)
|
|
var lbl := UiTheme.make_label(label, 12)
|
|
lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
line.add_child(lbl)
|
|
if not cur.is_empty():
|
|
var unequip := UiTheme.make_button(UiText.t("shell.loadout.unequip", locale), 11)
|
|
unequip.pressed.connect(_on_unequip.bind(slot))
|
|
line.add_child(unequip)
|
|
var equiv: Array = []
|
|
for gid in owned:
|
|
if str(gid) != cur:
|
|
equiv.append(gid)
|
|
if not equiv.is_empty():
|
|
var eq_btn := UiTheme.make_button(UiText.t("shell.loadout.equip", locale), 11)
|
|
eq_btn.pressed.connect(_on_equip_first.bind(slot, str(equiv[0])))
|
|
line.add_child(eq_btn)
|
|
|
|
|
|
func _select_loadout_hero(hid: String) -> void:
|
|
_loadout_hero = hid
|
|
_refresh_loadout()
|
|
|
|
|
|
func _on_equip_first(slot: String, gear_id: String) -> void:
|
|
var r := GearActions.equip(profile, slot, gear_id, WorldContent.content())
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_refresh_loadout()
|
|
_side_result_modal(UiText.t("shell.loadout.title", locale),
|
|
UiText.tf("shell.loadout.equipped", {"gear": gear_id}, locale) if bool(r.get("ok"))
|
|
else UiText.t("shell.loadout.fail", locale))
|
|
|
|
|
|
func _on_unequip(slot: String) -> void:
|
|
GearActions.unequip(profile, slot)
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_loadout()
|
|
|
|
|
|
func _build_settings() -> void:
|
|
_settings = Control.new()
|
|
_settings.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_settings.visible = false
|
|
_settings.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_settings)
|
|
|
|
# Match the other pages: a STOP scroll container keeps settings reachable
|
|
# on short/landscape viewports instead of clipping behind the nav bar.
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_settings.add_child(scroll)
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 12)
|
|
outer.add_theme_constant_override("margin_right", 12)
|
|
outer.add_theme_constant_override("margin_top", 6)
|
|
outer.add_theme_constant_override("margin_bottom", 70)
|
|
scroll.add_child(outer)
|
|
|
|
var column := VBoxContainer.new()
|
|
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
column.add_theme_constant_override("separation", 8)
|
|
outer.add_child(column)
|
|
_settings_title = UiTheme.make_label(UiText.t("shell.settings.title", locale), 22)
|
|
column.add_child(_settings_title)
|
|
|
|
for setting_id in ["language", "skin", "lowpower", "reducedmotion", "mute"]:
|
|
var panel := UiTheme.make_panel()
|
|
column.add_child(panel)
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 12)
|
|
margin.add_theme_constant_override("margin_right", 12)
|
|
margin.add_theme_constant_override("margin_top", 8)
|
|
margin.add_theme_constant_override("margin_bottom", 8)
|
|
panel.add_child(margin)
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 10)
|
|
margin.add_child(row)
|
|
var label := UiTheme.make_label(UiText.t("shell.settings.%s" % setting_id, locale), 13)
|
|
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
row.add_child(label)
|
|
_settings_labels[setting_id] = label
|
|
var button := UiTheme.make_button("", 12)
|
|
button.custom_minimum_size = Vector2(90, 40)
|
|
button.pressed.connect(_on_setting_toggled.bind(setting_id))
|
|
row.add_child(button)
|
|
_settings_rows[setting_id] = button
|
|
|
|
var note := UiTheme.make_label(UiText.t("shell.settings.note", locale), 11, UiTheme.COLOR_TEXT_DIM)
|
|
note.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
column.add_child(note)
|
|
_settings_note = note
|
|
_refresh_settings()
|
|
|
|
|
|
func _refresh_settings() -> void:
|
|
if _settings_rows.is_empty():
|
|
return
|
|
if _settings_title != null:
|
|
_settings_title.text = UiText.t("shell.settings.title", locale)
|
|
for setting_id in _settings_labels.keys():
|
|
var label: Label = _settings_labels[setting_id]
|
|
label.text = UiText.t("shell.settings.%s" % setting_id, locale)
|
|
if _settings_note != null:
|
|
_settings_note.text = UiText.t("shell.settings.note", locale)
|
|
var language := "zh_CN" if locale == "zh_CN" else "en_US"
|
|
var display := "中文" if locale == "zh_CN" else "English"
|
|
_settings_rows["language"].text = display
|
|
var skin_name := str(profile.get("ui_skin", "default"))
|
|
_settings_rows["skin"].text = UiText.t("shell.settings.skin_name.%s" % skin_name, locale)
|
|
_settings_rows["lowpower"].text = (
|
|
UiText.t("shell.settings.on", locale) if low_power
|
|
else UiText.t("shell.settings.off", locale)
|
|
)
|
|
_settings_rows["reducedmotion"].text = (
|
|
UiText.t("shell.settings.on", locale) if reduced_motion
|
|
else UiText.t("shell.settings.off", locale)
|
|
)
|
|
_settings_rows["mute"].text = (
|
|
UiText.t("shell.settings.on", locale) if muted
|
|
else UiText.t("shell.settings.off", locale)
|
|
)
|
|
|
|
|
|
func _build_growth() -> void:
|
|
_growth = Control.new()
|
|
_growth.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_growth.visible = false
|
|
_growth.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
_page_host.add_child(_growth)
|
|
|
|
var scroll := ScrollContainer.new()
|
|
scroll.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scroll.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_growth.add_child(scroll)
|
|
var outer := MarginContainer.new()
|
|
outer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
outer.add_theme_constant_override("margin_left", 12)
|
|
outer.add_theme_constant_override("margin_right", 12)
|
|
outer.add_theme_constant_override("margin_top", 6)
|
|
outer.add_theme_constant_override("margin_bottom", 6)
|
|
scroll.add_child(outer)
|
|
var column := VBoxContainer.new()
|
|
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
column.add_theme_constant_override("separation", 8)
|
|
outer.add_child(column)
|
|
column.add_child(UiTheme.make_label(UiText.t("shell.growth.title", locale), 22))
|
|
var frag_label := UiTheme.make_label("", 12, UiTheme.COLOR_MINT)
|
|
column.add_child(frag_label)
|
|
_growth_rows["__frag"] = frag_label
|
|
|
|
# One card per unlocked hero: star level + 4 talent slots.
|
|
for hero_row in LaunchContent.heroes():
|
|
var hero_id := str(hero_row.get("id", ""))
|
|
if not _is_unlocked(hero_id):
|
|
continue
|
|
var card := UiTheme.glass_panel(0.82)
|
|
column.add_child(card)
|
|
var m := MarginContainer.new()
|
|
m.add_theme_constant_override("margin_left", 12)
|
|
m.add_theme_constant_override("margin_right", 12)
|
|
m.add_theme_constant_override("margin_top", 8)
|
|
m.add_theme_constant_override("margin_bottom", 8)
|
|
card.add_child(m)
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 6)
|
|
m.add_child(v)
|
|
var head := HBoxContainer.new()
|
|
v.add_child(head)
|
|
var name := UiTheme.make_label(UiText.t("content.hero.%s.short" % hero_id, locale), 13)
|
|
name.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
head.add_child(name)
|
|
var star_btn := UiTheme.make_menu_button("", "", "secondary", 11)
|
|
star_btn.custom_minimum_size = Vector2(150, 38)
|
|
star_btn.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
star_btn.pressed.connect(func() -> void: _on_invest_star(hero_id))
|
|
head.add_child(star_btn)
|
|
# 2x2 grid so each talent button is wide enough for its label+cost; a
|
|
# single HBox squeezed 4 buttons and overflowed the text on device.
|
|
var talents := GridContainer.new()
|
|
talents.columns = 2
|
|
talents.add_theme_constant_override("h_separation", 6)
|
|
talents.add_theme_constant_override("v_separation", 6)
|
|
v.add_child(talents)
|
|
var slot_buttons: Array = []
|
|
for slot in range(1, GrowthActions.MAX_TALENTS_PER_HERO + 1):
|
|
var tb := UiTheme.make_menu_button("", "", "secondary", 11)
|
|
tb.custom_minimum_size = Vector2(0, 38)
|
|
tb.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
tb.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
tb.pressed.connect(func() -> void: _on_invest_talent(hero_id, slot))
|
|
talents.add_child(tb)
|
|
slot_buttons.append(tb)
|
|
_growth_rows[hero_id] = {"star": star_btn, "talents": slot_buttons}
|
|
|
|
var back := UiTheme.make_menu_button("", UiText.t("shell.growth.close", locale), "quiet", 13)
|
|
back.pressed.connect(func() -> void: show_page(PAGE_SKYPORT))
|
|
column.add_child(back)
|
|
|
|
|
|
func _on_invest_talent(hero_id: String, slot: int) -> void:
|
|
var r := invest_talent(hero_id, slot)
|
|
sfx.play("ui" if not bool(r.get("ok")) else "upgrade", "ui")
|
|
_refresh_growth()
|
|
|
|
|
|
func _on_invest_star(hero_id: String) -> void:
|
|
var r := upgrade_star(hero_id)
|
|
sfx.play("ui" if not bool(r.get("ok")) else "upgrade", "ui")
|
|
_refresh_growth()
|
|
|
|
|
|
func _refresh_growth() -> void:
|
|
if _growth_rows.is_empty():
|
|
return
|
|
var frag: int = int(profile.get("star_fragments", 0))
|
|
var frag_label: Label = _growth_rows.get("__frag")
|
|
if frag_label != null:
|
|
frag_label.text = UiText.t("shell.growth.fragments", locale) + ": %d" % frag
|
|
var stars: Dictionary = profile.get("star_levels", {})
|
|
var talents: Dictionary = profile.get("talents", {})
|
|
for hero_id in _growth_rows.keys():
|
|
if hero_id == "__frag":
|
|
continue
|
|
var row: Dictionary = _growth_rows[hero_id]
|
|
var cur_star: int = int(stars.get(hero_id, 1))
|
|
var star_btn: Button = row["star"]
|
|
if cur_star >= GrowthActions.MAX_STAR:
|
|
star_btn.text = UiText.t("shell.growth.star", locale) + " %d · %s" % [cur_star, UiText.t("shell.growth.maxed", locale)]
|
|
star_btn.disabled = true
|
|
else:
|
|
star_btn.text = UiText.t("shell.growth.star", locale) + " %d→%d · %d✦" % [cur_star, cur_star + 1, GrowthActions.star_cost(cur_star + 1)]
|
|
star_btn.disabled = frag < GrowthActions.star_cost(cur_star + 1)
|
|
var slot_buttons: Array = row["talents"]
|
|
for i in range(slot_buttons.size()):
|
|
var slot := i + 1
|
|
var tid := "T-%s-%02d" % [hero_id, slot]
|
|
var tb: Button = slot_buttons[i]
|
|
var cost := GrowthActions.talent_cost(slot)
|
|
if bool(talents.get(tid, false)):
|
|
tb.text = UiText.t("shell.growth.talent", locale) + " %d ✓" % slot
|
|
tb.disabled = true
|
|
else:
|
|
tb.text = UiText.t("shell.growth.talent", locale) + " %d · %d" % [slot, cost]
|
|
tb.disabled = int(profile.get("gold", 0)) < cost
|
|
|
|
|
|
func _on_setting_toggled(setting_id: String) -> void:
|
|
match setting_id:
|
|
"language":
|
|
set_locale("en_US" if locale == "zh_CN" else "zh_CN")
|
|
"skin":
|
|
# Cycle skins, persist, then reload the scene so every control is
|
|
# rebuilt with the new frame overrides (styleboxes bake at creation).
|
|
var order: Array = ["default", "parchment"]
|
|
var cur := str(profile.get("ui_skin", "default"))
|
|
var idx: int = order.find(cur)
|
|
var next_skin: String = str(order[(idx + 1) % order.size()]) if idx >= 0 else "default"
|
|
profile["ui_skin"] = next_skin
|
|
ProfileStore.save_profile(profile)
|
|
get_tree().reload_current_scene()
|
|
return
|
|
"lowpower":
|
|
low_power = not low_power
|
|
profile["low_power"] = low_power
|
|
ProfileStore.save_profile(profile)
|
|
if _fb() != null:
|
|
_fb().configure(reduced_motion, low_power)
|
|
if _battle != null:
|
|
_battle.set_low_power(low_power)
|
|
"reducedmotion":
|
|
reduced_motion = not reduced_motion
|
|
profile["reduced_motion"] = reduced_motion
|
|
ProfileStore.save_profile(profile)
|
|
if _fb() != null:
|
|
_fb().configure(reduced_motion, low_power)
|
|
if _battle != null:
|
|
_battle.set_reduced_motion(reduced_motion)
|
|
"mute":
|
|
muted = not muted
|
|
profile["muted"] = muted
|
|
ProfileStore.save_profile(profile)
|
|
sfx.set_muted(muted)
|
|
if _battle != null:
|
|
_battle.set_muted(muted)
|
|
_refresh_settings()
|
|
_refresh_pages()
|
|
|
|
|
|
func set_locale(value: String) -> void:
|
|
locale = value
|
|
if _battle != null and is_instance_valid(_battle) and _battle.hud != null:
|
|
_battle.hud.set_locale(value)
|
|
_refresh_settings()
|
|
_refresh_pages()
|
|
if current_page == PAGE_WORLD:
|
|
_refresh_world()
|
|
if current_page == PAGE_SIDE:
|
|
_refresh_side()
|
|
|
|
|
|
func _build_bottom_nav() -> void:
|
|
var nav := UiTheme.make_panel()
|
|
nav.name = "ShellBottomNav"
|
|
nav.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_WIDE)
|
|
nav.offset_left = 8
|
|
nav.offset_right = -8
|
|
# PRESET_BOTTOM_WIDE leaves offset_top=0 on a freshly created Control, so
|
|
# minimum-size growth pushed the entire bar BELOW the viewport (y=844 on a
|
|
# 844-tall screen) -- it was on-screen logically but never visible. Pin both
|
|
# edges explicitly so the bar sits inside the viewport.
|
|
nav.offset_top = -76.0
|
|
nav.offset_bottom = 0.0
|
|
nav.custom_minimum_size = Vector2(0, 76)
|
|
add_child(nav)
|
|
_nav_box = nav
|
|
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 8)
|
|
margin.add_theme_constant_override("margin_right", 8)
|
|
margin.add_theme_constant_override("margin_top", 5)
|
|
margin.add_theme_constant_override("margin_bottom", 5)
|
|
nav.add_child(margin)
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 6)
|
|
margin.add_child(row)
|
|
|
|
var nav_icons := {
|
|
"map": "res://assets/icons/icon_flag.png",
|
|
"company": "res://assets/icons/icon_chest.png",
|
|
"skyport": "res://assets/icons/icon_hammer.png",
|
|
"archive": "res://assets/icons/icon_bow.png",
|
|
}
|
|
for page in ["map", "company", "skyport", "archive"]:
|
|
# The shell's map page uses the battle nav's "expedition" label; there
|
|
# is no hud.nav.map key, which previously rendered as "[hud.nav.map]".
|
|
var label_key := "hud.nav.expedition" if page == "map" else "hud.nav.%s" % page
|
|
var button := UiTheme.make_nav_button(
|
|
UiText.t(label_key), str(nav_icons.get(page, "")), page == current_page)
|
|
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
button.pressed.connect(_on_nav.bind(page))
|
|
row.add_child(button)
|
|
_nav_buttons[page] = button
|
|
|
|
|
|
func _build_modal() -> void:
|
|
# The battle HUD lives in a CanvasLayer (layer 0), which draws above plain
|
|
# Control nodes regardless of tree order. Put shell modals in a higher
|
|
# CanvasLayer so victory/defeat/event dialogs actually appear during battle.
|
|
var modal_layer := CanvasLayer.new()
|
|
modal_layer.name = "ModalLayer"
|
|
modal_layer.layer = 10
|
|
add_child(modal_layer)
|
|
_modal = Control.new()
|
|
_modal.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_modal.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_modal.visible = false
|
|
# CanvasLayer breaks theme inheritance from the shell root; assign the CJK
|
|
# theme explicitly or modal labels render as tofu boxes on iOS.
|
|
_modal.theme = _shell_theme
|
|
modal_layer.add_child(_modal)
|
|
var dim := ColorRect.new()
|
|
dim.color = Color(0.02, 0.05, 0.09, 0.74)
|
|
dim.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
dim.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
_modal.add_child(dim)
|
|
var center := MarginContainer.new()
|
|
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
center.add_theme_constant_override("margin_left", 32)
|
|
center.add_theme_constant_override("margin_right", 32)
|
|
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_modal.add_child(center)
|
|
var column := VBoxContainer.new()
|
|
column.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
center.add_child(column)
|
|
var panel := UiTheme.make_panel()
|
|
column.add_child(panel)
|
|
var inner := MarginContainer.new()
|
|
inner.add_theme_constant_override("margin_left", 16)
|
|
inner.add_theme_constant_override("margin_right", 16)
|
|
# The golden panel frame is thick; a 14px top inset let long titles clip
|
|
# into the border (seen on the 9-row edict shop). Give the title headroom.
|
|
inner.add_theme_constant_override("margin_top", 24)
|
|
inner.add_theme_constant_override("margin_bottom", 14)
|
|
panel.add_child(inner)
|
|
var stack := VBoxContainer.new()
|
|
stack.add_theme_constant_override("separation", 10)
|
|
inner.add_child(stack)
|
|
_modal_title = UiTheme.make_label("", 20)
|
|
stack.add_child(_modal_title)
|
|
_modal_body = UiTheme.make_label("", 13)
|
|
stack.add_child(_modal_body)
|
|
_modal_actions = VBoxContainer.new()
|
|
_modal_actions.add_theme_constant_override("separation", 8)
|
|
stack.add_child(_modal_actions)
|
|
|
|
|
|
## Short non-blocking notice above every layer. Used to explain that leaving
|
|
## battle ended the fight and where the player landed.
|
|
func _build_toast() -> void:
|
|
var layer := CanvasLayer.new()
|
|
layer.name = "ToastLayer"
|
|
layer.layer = 11
|
|
add_child(layer)
|
|
_toast_label = UiTheme.make_label("", 14, UiTheme.COLOR_TEXT)
|
|
_toast_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
_toast_label.set_anchors_and_offsets_preset(Control.PRESET_CENTER_TOP)
|
|
_toast_label.offset_top = 96.0
|
|
_toast_label.offset_bottom = 132.0
|
|
_toast_label.offset_left = 16.0
|
|
_toast_label.offset_right = -16.0
|
|
_toast_label.theme = _shell_theme
|
|
_toast_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_toast_label.visible = false
|
|
layer.add_child(_toast_label)
|
|
|
|
|
|
func show_toast(message: String) -> void:
|
|
if _toast_label == null:
|
|
return
|
|
var toast_id := _toast_label.get_instance_id()
|
|
# Drop any previous managed entry before restarting, so clear_all() cannot
|
|
# later reset a stale toast.
|
|
if _fb() != null:
|
|
_fb().kill_tween(toast_id)
|
|
if _toast_tween != null and _toast_tween.is_valid():
|
|
_toast_tween.kill()
|
|
_toast_label.text = message
|
|
_toast_label.modulate = Color(1, 1, 1, 1)
|
|
_toast_label.visible = true
|
|
_toast_tween = create_tween()
|
|
_toast_tween.tween_interval(2.2)
|
|
_toast_tween.tween_property(_toast_label, "modulate:a", 0.0, 0.4)
|
|
_toast_tween.tween_callback(func() -> void:
|
|
var obj := instance_from_id(toast_id)
|
|
if obj is Control:
|
|
(obj as Control).visible = false)
|
|
if _fb() != null:
|
|
_fb().track_tween(toast_id, _toast_tween, func() -> void:
|
|
var obj := instance_from_id(toast_id)
|
|
if obj is Control:
|
|
(obj as Control).visible = false)
|
|
|
|
|
|
## U2 primary CTA: a view owned by GameRoot, never a second state machine.
|
|
func _build_u2_dock() -> void:
|
|
_u2_dock = PrimaryCTADock.new("", "", int(_safe_bottom))
|
|
_u2_dock.name = "U2PrimaryCTA"
|
|
add_child(_u2_dock)
|
|
_u2_dock.cta_pressed.connect(_on_u2_cta)
|
|
_layout_u2_dock()
|
|
|
|
|
|
func _layout_u2_dock() -> void:
|
|
if _u2_dock == null:
|
|
return
|
|
var nav_h := 84.0 if _nav_box != null and _nav_box.visible else 8.0
|
|
var dock_h := float(_u2_dock.min_height())
|
|
_u2_dock.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_WIDE)
|
|
_u2_dock.offset_left = 0
|
|
_u2_dock.offset_right = 0
|
|
_u2_dock.offset_top = -(nav_h + dock_h + _safe_bottom)
|
|
_u2_dock.offset_bottom = -(nav_h + _safe_bottom)
|
|
_u2_dock.set_safe_bottom(int(_safe_bottom))
|
|
# The page host must end above the fixed dock, or its MOUSE_FILTER_STOP
|
|
# scroll container swallows the CTA touch (U1 shell reserved the same gap).
|
|
if _page_host != null:
|
|
var reserve := dock_h + 8.0 if _u2_dock.visible else 0.0
|
|
_page_host.offset_bottom = -(_safe_bottom + 84.0 + reserve)
|
|
|
|
|
|
func _update_u2_dock() -> void:
|
|
if _u2_dock == null:
|
|
return
|
|
var visible_page := current_page == PAGE_SKYPORT or current_page == PAGE_WORLD
|
|
_u2_dock.visible = visible_page
|
|
if not visible_page:
|
|
return
|
|
_u2_dock.set_icon("res://assets/icons/icon_sword.png")
|
|
if current_page == PAGE_WORLD:
|
|
_u2_dock.set_label(UiText.t("shell.world.launch", locale))
|
|
_u2_dock.set_enabled(not _world_node.is_empty() and _is_world_node_available(_world_node))
|
|
else:
|
|
_u2_dock.set_label(UiText.t("shell.expedition.start", locale))
|
|
_u2_dock.set_enabled(true)
|
|
_layout_u2_dock()
|
|
|
|
|
|
func _on_u2_cta() -> void:
|
|
# The dock emits only an intent; routing stays on the existing path.
|
|
if current_page == PAGE_WORLD:
|
|
_launch_world_node()
|
|
elif current_page == PAGE_SKYPORT:
|
|
show_page(PAGE_MAP)
|
|
|
|
|
|
func show_page(page: String) -> void:
|
|
if page == PAGE_BATTLE:
|
|
return
|
|
current_page = page
|
|
# Keep the bottom nav highlight in sync for every route into a page, not
|
|
# just tab clicks (World settlement, battle exit, back buttons, ...).
|
|
_refresh_nav_tabs()
|
|
_skyport.visible = page == PAGE_SKYPORT
|
|
_map.visible = page == PAGE_MAP
|
|
_settings.visible = page == PAGE_SETTINGS
|
|
_growth.visible = page == PAGE_GROWTH
|
|
if _world != null:
|
|
_world.visible = page == PAGE_WORLD
|
|
if page == PAGE_WORLD:
|
|
_refresh_world()
|
|
if _side != null:
|
|
_side.visible = page == PAGE_SIDE
|
|
if page == PAGE_SIDE:
|
|
_refresh_side()
|
|
if _loadout != null:
|
|
_loadout.visible = page == PAGE_LOADOUT
|
|
if page == PAGE_LOADOUT:
|
|
_refresh_loadout()
|
|
if _endless_page != null:
|
|
_endless_page.visible = page == PAGE_ENDLESS
|
|
if page == PAGE_ENDLESS:
|
|
_refresh_endless()
|
|
if _battle_host != null:
|
|
_battle_host.visible = false
|
|
# Battle HUD sits in a CanvasLayer that renders above all normal Controls;
|
|
# hiding the host is not enough. Hide the layer explicitly on every page
|
|
# change so no exit path leaves the fight covering the destination.
|
|
if _battle != null:
|
|
_battle.set_process(false)
|
|
if _battle.hud != null:
|
|
_battle.hud.visible = false
|
|
var hl := _battle.get_node_or_null("HUDLayer")
|
|
if hl != null:
|
|
hl.visible = false
|
|
# Restore shell chrome when leaving battle (hidden in _present_battle).
|
|
if _nav_box != null:
|
|
_nav_box.visible = true
|
|
if _header_box != null:
|
|
_header_box.visible = true
|
|
_refresh_pages()
|
|
_update_u2_dock()
|
|
|
|
|
|
func _refresh_pages() -> void:
|
|
# U2: feed the U1 visual layer authoritative profile values. The block below
|
|
# still owns offline/auto labels and every existing test hook.
|
|
if _u2_skyport != null:
|
|
var heroes: Array = []
|
|
for hid in ["H01", "H02", "H03"]:
|
|
if not _is_unlocked(hid):
|
|
continue
|
|
var hlevel := int((profile.get("hero_levels", {}) as Dictionary).get(hid, 1))
|
|
var cost := ProfileStore.upgrade_cost(hlevel)
|
|
var affordable := int(profile.get("gold", 0)) >= cost
|
|
heroes.append({
|
|
"id": hid, "level": hlevel, "affordable": affordable,
|
|
"cost_text": ("%d ◆" % cost) if affordable else UiText.tf("shell.growth.need_gold", {"cost": cost}, locale),
|
|
})
|
|
var buildings: Array = []
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
for i in range(4):
|
|
var text := "—"
|
|
if i < unlocked.size():
|
|
var blevel := int((profile.get("hero_levels", {}) as Dictionary).get(str(unlocked[i]), 1))
|
|
text = UiText.tf("hud.growth.level", {"level": blevel}, locale) + " · " + \
|
|
UiText.tf("hud.growth.cost", {"gold": ProfileStore.upgrade_cost(blevel)}, locale)
|
|
buildings.append({"text": text})
|
|
_u2_skyport.set_runtime({"heroes": heroes, "buildings": buildings})
|
|
if _header_title != null:
|
|
_header_title.text = UiText.t("shell.title", locale)
|
|
_header_gold.text = str(int(profile.get("gold", 0)))
|
|
_header_crystal.text = str(int(profile.get("crystal", 0)))
|
|
var pending := int(profile.get("pending_offline_gold", 0))
|
|
if pending > 0:
|
|
skyport_report_text.text = UiText.tf("shell.offline.pending", {"gold": pending}, locale)
|
|
_skyport_report_button.visible = true
|
|
elif ProfileStore.is_first_run(profile):
|
|
skyport_report_text.text = UiText.t("shell.intro.banner", locale)
|
|
_skyport_report_button.visible = false
|
|
else:
|
|
skyport_report_text.text = UiText.t("shell.offline.idle", locale)
|
|
_skyport_report_button.visible = false
|
|
var auto_on := bool(profile.get("auto_run", false))
|
|
_auto_run_button.text = UiText.t("shell.auto.on" if auto_on else "shell.auto.off", locale)
|
|
_auto_run_button.add_theme_color_override(
|
|
"font_color", UiTheme.COLOR_MINT if auto_on else UiTheme.COLOR_TEXT_DIM
|
|
)
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
# Chapter progress: how many nodes cleared out of the route length.
|
|
var total_nodes := LaunchContent.node_ids().size()
|
|
var done_count := 0
|
|
for node_id in _map_rows.keys():
|
|
if completed.has(node_id):
|
|
done_count += 1
|
|
if _map_progress != null:
|
|
_map_progress.text = UiText.tf("shell.map.progress", {"done": done_count, "total": total_nodes}, locale)
|
|
if _map_progress_fill != null:
|
|
var ratio := float(done_count) / float(maxi(1, total_nodes))
|
|
_map_progress_fill.anchor_left = 0.0
|
|
_map_progress_fill.anchor_right = ratio
|
|
_map_progress_fill.offset_left = 0
|
|
_map_progress_fill.offset_right = 0
|
|
# The first available node is the current target; highlight its step dot.
|
|
var current_target := ""
|
|
for node_id in _map_rows.keys():
|
|
if _is_node_available(node_id) and not completed.has(node_id):
|
|
current_target = node_id
|
|
break
|
|
for conn in _map_connectors:
|
|
var dot: ColorRect = conn["dot"]
|
|
var cid := str(conn["node_id"])
|
|
if completed.has(cid):
|
|
dot.color = UiTheme.COLOR_MINT
|
|
elif cid == current_target:
|
|
dot.color = UiTheme.COLOR_BORDER
|
|
else:
|
|
dot.color = UiTheme.COLOR_TEXT_DIM
|
|
|
|
for node_id in _map_rows.keys():
|
|
var row: Dictionary = _map_rows[node_id]
|
|
var status: Label = row["status"]
|
|
var button: Button = row["button"]
|
|
var done := completed.has(node_id)
|
|
var available := _is_node_available(node_id)
|
|
status.text = UiText.t("shell.node.done", locale) if done else (UiText.t("shell.node.available", locale) if available else UiText.t("shell.node.locked", locale))
|
|
status.add_theme_color_override(
|
|
"font_color", UiTheme.COLOR_MINT if done else (UiTheme.COLOR_BORDER if available else UiTheme.COLOR_TEXT_DIM)
|
|
)
|
|
button.disabled = not available or done
|
|
# A cleared node reads as complete: dimmed + mint status, no more CTA.
|
|
var panel: Control = row.get("panel")
|
|
if panel != null:
|
|
panel.modulate = Color(0.75, 0.85, 0.78, 1) if done else Color(1, 1, 1, 1)
|
|
button.add_theme_color_override(
|
|
"font_color", UiTheme.COLOR_TEXT if available else UiTheme.COLOR_TEXT_DIM
|
|
)
|
|
# Available nodes get the brass "go" treatment; locked/done stay quiet.
|
|
button.add_theme_stylebox_override("normal", UiTheme.tab_style(available))
|
|
for hero_id in _skyport_upgrade_rows.keys():
|
|
var row: Dictionary = _skyport_upgrade_rows[hero_id]
|
|
var level := int((profile.get("hero_levels", {}) as Dictionary).get(hero_id, 1))
|
|
var hero_row := LaunchContent.hero(hero_id)
|
|
var base_dps := float(hero_row.get("base_dps", 0.0))
|
|
var dps := base_dps * (1.0 + 0.25 * float(maxi(0, level - 1)))
|
|
row["level"].text = "Lv.%d" % level
|
|
row["dps"].text = "DPS %.1f" % dps
|
|
var cost := ProfileStore.upgrade_cost(level)
|
|
var affordable := int(profile.get("gold", 0)) >= cost
|
|
var button: Button = row["button"]
|
|
button.text = ("%d ◆" % cost) if affordable else UiText.tf("shell.growth.need_gold", {"cost": cost}, locale)
|
|
button.disabled = not affordable
|
|
button.add_theme_color_override(
|
|
"font_color", UiTheme.COLOR_TEXT if affordable else UiTheme.COLOR_TEXT_DIM
|
|
)
|
|
# Affordability is shown by text color + dimming, not by swapping in a
|
|
# bright gold frame (which made every row look like the same gold box).
|
|
button.modulate = Color(1, 1, 1, 1) if affordable else Color(0.55, 0.55, 0.6, 1)
|
|
_refresh_growth()
|
|
_refresh_world_progress()
|
|
|
|
|
|
func _is_unlocked(hero_id: String) -> bool:
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
return unlocked.has(hero_id)
|
|
|
|
|
|
func _is_node_available(node_id: String) -> bool:
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
if completed.has(node_id):
|
|
return false
|
|
var row := LaunchContent.node(node_id)
|
|
var index := int(row.get("index", 99))
|
|
if index <= 1:
|
|
return true
|
|
var ids := LaunchContent.node_ids()
|
|
var previous := ids[index - 2] if index - 2 < ids.size() else ""
|
|
return completed.has(previous)
|
|
|
|
|
|
func _on_toggle_auto_run() -> void:
|
|
profile["auto_run"] = not bool(profile.get("auto_run", false))
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("ui", "ui")
|
|
_refresh_pages()
|
|
|
|
|
|
func _on_claim_offline() -> void:
|
|
var gold := ProfileStore.claim_offline(profile)
|
|
if gold > 0:
|
|
sfx.play("reward", "sfx")
|
|
ProfileStore.save_profile(profile)
|
|
_show_modal(UiText.t("shell.offline.report.title", locale), UiText.tf("shell.offline.report.body", {"gold": gold}, locale), [
|
|
{"label": UiText.t("shell.offline.accept", locale), "action": "map"},
|
|
])
|
|
_refresh_pages()
|
|
|
|
|
|
func _format_duration(seconds: int) -> String:
|
|
if seconds < 60:
|
|
return "%ds" % seconds
|
|
var minutes := int(seconds / 60)
|
|
var rem := seconds % 60
|
|
if minutes < 60:
|
|
return "%dm %ds" % [minutes, rem]
|
|
return "%dh %dm" % [int(minutes / 60), minutes % 60]
|
|
|
|
|
|
func _bucket_label(bucket: String) -> String:
|
|
return UiText.t("shell.prestige.bucket.%s" % bucket, locale)
|
|
|
|
|
|
func _chosen_oath_line() -> String:
|
|
# Design 8.3: show what the player's chosen oath changes next cycle.
|
|
var pack := WorldContent.content()
|
|
var oaths: Dictionary = profile.get("oaths", {})
|
|
for o in pack.get("oaths", []):
|
|
var row: Dictionary = o
|
|
var oid := str(row.get("id", ""))
|
|
if bool(oaths.get(oid, false)):
|
|
return UiText.tf("shell.prestige.oath_change", {
|
|
"name": row.get("name", oid),
|
|
"bucket": _bucket_label(str(row.get("bucket", ""))),
|
|
}, locale)
|
|
return UiText.t("shell.prestige.choose_hint", locale)
|
|
|
|
|
|
func _on_prestige_preview() -> void:
|
|
# Design 8.3: the player must SEE gains, unlock gates, ETA and the next
|
|
# cycle's rule change before choosing. No forced/prestige-in-the-dark.
|
|
var pv := prestige_preview_for_test()
|
|
var reb: Dictionary = pv["rebuild"]
|
|
var sky: Dictionary = pv["new_sky"]
|
|
var asc: Dictionary = pv.get("ascension", {})
|
|
# S3: CH transcendence / outsider slice sits on the same preview surface.
|
|
var tr: Dictionary = Transcendence.preview(profile)
|
|
var r_unlock := Prestige.rebuild_unlock(profile)
|
|
var n_unlock := Prestige.new_sky_unlock(profile)
|
|
var eta := Prestige.return_time_estimate(profile)
|
|
var body := ""
|
|
|
|
if not bool(r_unlock.get("unlocked")):
|
|
body = UiText.t("shell.prestige.locked", locale)
|
|
else:
|
|
body = UiText.tf("shell.prestige.rebuild_gain", {"essence": reb.get("essence", 0)}, locale)
|
|
# CH ascension adds a second, source-bound reward line: hero souls from
|
|
# floor(total hero levels / 2000) plus any primal souls. Reset-now vs
|
|
# push-one-more-node changes this number, so the choice is readable.
|
|
body += "\n" + UiText.tf("shell.prestige.soul_gain", {
|
|
"souls": int(asc.get("reward", 0)),
|
|
}, locale)
|
|
body += "\n" + UiText.tf("shell.prestige.ancient_gain", {
|
|
"gain": int(tr.get("gain", 0)),
|
|
"tp": snappedf(float(tr.get("transcendent_power", 0)) * 100.0, 0.1),
|
|
}, locale)
|
|
body += "\n" + UiText.tf("shell.prestige.sky_gain", {"marks": sky.get("sky_marks", 0)}, locale)
|
|
body += "\n" + UiText.tf("shell.prestige.eta", {
|
|
"time": _format_duration(int(eta.get("seconds", 0))),
|
|
}, locale)
|
|
body += "\n" + UiText.tf("shell.prestige.sky_cond", {
|
|
"regions": n_unlock.get("completed_regions", 0),
|
|
"rift": n_unlock.get("rift_layer", 0),
|
|
}, locale)
|
|
body += "\n" + _chosen_oath_line()
|
|
body += "\n" + UiText.t("shell.prestige.rebuild_keep", locale)
|
|
|
|
var actions: Array = [
|
|
{"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"},
|
|
]
|
|
if bool(r_unlock.get("unlocked")):
|
|
actions.append({"label": UiText.t("shell.prestige.do_rebuild", locale), "action": "confirm_full_rebuild"})
|
|
if bool(n_unlock.get("unlocked")):
|
|
actions.append({"label": UiText.t("shell.prestige.do_sky", locale), "action": "confirm_new_sky"})
|
|
# Edict shop is reachable once new-sky is unlocked (marks are its currency).
|
|
actions.append({"label": UiText.tf("shell.prestige.edict_shop", {
|
|
"marks": int(profile.get("sky_marks", 0)),
|
|
}, locale), "action": "open_edict_shop"})
|
|
if bool(tr.get("can_transcend")):
|
|
actions.append({"label": UiText.t("shell.prestige.do_transcend", locale),
|
|
"action": "confirm_transcendence"})
|
|
var outsider_book: OutsiderBook = Transcendence.book_from_profile(profile)
|
|
actions.append({"label": UiText.tf("shell.prestige.ancient_shop", {
|
|
"souls": int(outsider_book.balance),
|
|
"tp": snappedf(outsider_book.transcendent_power() * 100.0, 0.1),
|
|
}, locale), "action": "open_outsider_shop"})
|
|
_show_modal(UiText.t("shell.prestige.title", locale), body, actions)
|
|
_modal_body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
|
|
func _open_edict_shop() -> void:
|
|
# Design 8.2: sky marks buy the 9 wind edicts; each changes a rule/direction.
|
|
var pack := WorldContent.content()
|
|
var owned: Dictionary = profile.get("edicts", {})
|
|
var marks := int(profile.get("sky_marks", 0))
|
|
_edict_shop_actions.clear()
|
|
var body := UiText.tf("shell.prestige.edict_shop", {"marks": marks}, locale)
|
|
for e in pack.get("edicts", []):
|
|
var row: Dictionary = e
|
|
var eid := str(row.get("id", ""))
|
|
var cost := Prestige.edict_cost(eid)
|
|
var desc := str(row.get("description", ""))
|
|
var line := UiText.tf("shell.prestige.edict_row", {
|
|
"name": row.get("name", eid), "cost": cost, "desc": desc,
|
|
}, locale)
|
|
body += "\n" + line
|
|
_edict_shop_actions.append({"label": eid, "edict": eid, "cost": cost,
|
|
"owned": bool(owned.get(eid, false))})
|
|
var actions: Array = []
|
|
for row in _edict_shop_actions:
|
|
var label := ""
|
|
if bool(row["owned"]):
|
|
label = "%s · %s" % [str(row["edict"]), UiText.t("shell.prestige.edict_owned", locale)]
|
|
elif marks < int(row["cost"]):
|
|
label = "%s · %d · %s" % [str(row["edict"]), int(row["cost"]), UiText.t("shell.prestige.edict_nomarks", locale)]
|
|
else:
|
|
label = "%s · %d · %s" % [str(row["edict"]), int(row["cost"]), UiText.t("shell.prestige.edict_buy", locale)]
|
|
actions.append({"label": label, "action": "buy_edict:%s" % str(row["edict"]),
|
|
"disabled": bool(row["owned"]) or marks < int(row["cost"])})
|
|
actions.append({"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"})
|
|
_show_modal(UiText.t("shell.prestige.edict_shop_title", locale), body, actions)
|
|
_modal_body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
|
|
var _edict_shop_actions: Array = []
|
|
|
|
|
|
## S3 outsider shop: source-bound CH outsider levels paid with the Ancient Soul
|
|
## wallet. Kept separate from the WR bool `edicts` rule shop above.
|
|
func _open_outsider_shop() -> void:
|
|
var book: OutsiderBook = Transcendence.book_from_profile(profile)
|
|
var body := UiText.tf("shell.prestige.ancient_shop", {
|
|
"souls": int(book.balance),
|
|
"tp": snappedf(book.transcendent_power() * 100.0, 0.1),
|
|
}, locale)
|
|
var actions: Array = []
|
|
for id: int in book.listed_ids():
|
|
var def: Dictionary = book.definitions.get(id, {"name": str(id)})
|
|
var level := int(book.levels.get(id, 0))
|
|
var bonus_value = book.bonus(id)
|
|
var quote := book.quote(id, 1)
|
|
body += "\n" + UiText.tf("shell.prestige.ancient_row", {
|
|
"name": str(def.get("name", str(id))), "level": level,
|
|
"bonus": snappedf(bonus_value.to_float(), 0.01),
|
|
"cost": int(quote.get("cost", 0)),
|
|
}, locale)
|
|
var label := ""
|
|
var disabled := false
|
|
if bool(quote.get("affordable")):
|
|
label = UiText.tf("shell.prestige.ancient_buy", {
|
|
"id": id, "count": int(quote.get("count", 1)),
|
|
}, locale)
|
|
elif level >= book.level_cap(id):
|
|
label = UiText.tf("shell.prestige.ancient_maxed", {"id": id}, locale)
|
|
disabled = true
|
|
else:
|
|
label = UiText.tf("shell.prestige.ancient_nofunds", {
|
|
"id": id, "cost": int(quote.get("cost", 0)),
|
|
}, locale)
|
|
disabled = true
|
|
actions.append({"label": label, "action": "buy_outsider:%d" % id, "disabled": disabled})
|
|
actions.append({"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"})
|
|
_show_modal(UiText.t("shell.prestige.ancient_shop_title", locale), body, actions)
|
|
_modal_body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
|
|
func completed_has_ch1() -> bool:
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
return completed.has("R1-C01-N10")
|
|
|
|
|
|
func _on_rebuild() -> void:
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
if not completed.has("R1-C01-N10"):
|
|
_show_modal(UiText.t("shell.rebuild.button", locale), UiText.t("shell.rebuild.locked", locale), [
|
|
{"label": UiText.t("shell.rebuild.continue", locale), "action": "map"},
|
|
])
|
|
return
|
|
var levels: Dictionary = profile.get("hero_levels", {})
|
|
var total_levels := 0
|
|
for value in levels.values():
|
|
total_levels += int(value)
|
|
var essence := total_levels / ProfileStore.REBUILD_LEVELS_PER_ESSENCE
|
|
_show_modal(
|
|
UiText.t("shell.rebuild.button", locale),
|
|
UiText.tf("shell.rebuild.body", {"essence": essence}, locale),
|
|
[
|
|
{"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"},
|
|
{"label": UiText.t("shell.rebuild.confirm", locale), "action": "confirm_rebuild"},
|
|
]
|
|
)
|
|
_pending_rebuild_essence = essence
|
|
|
|
|
|
var _pending_rebuild_essence := 0
|
|
|
|
|
|
func _confirm_rebuild() -> void:
|
|
profile["gold"] = 0
|
|
profile["hero_levels"] = {}
|
|
profile["completed_nodes"] = []
|
|
profile["claimed_rewards"] = []
|
|
profile["crystal"] = int(profile.get("crystal", 0)) + _pending_rebuild_essence
|
|
profile["rebuild_count"] = int(profile.get("rebuild_count", 0)) + 1
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
_show_modal(UiText.t("shell.rebuild.done", locale), UiText.tf("shell.rebuild.done_body", {"essence": _pending_rebuild_essence}, locale), [
|
|
{"label": UiText.t("shell.rebuild.go", locale), "action": "map"},
|
|
])
|
|
|
|
|
|
func _on_upgrade(hero_id: String) -> void:
|
|
var levels: Dictionary = profile.get("hero_levels", {})
|
|
var level := int(levels.get(hero_id, 1))
|
|
var cost := ProfileStore.upgrade_cost(level)
|
|
if int(profile.get("gold", 0)) < cost:
|
|
sfx.play("ui", "ui")
|
|
return
|
|
sfx.play("upgrade", "ui")
|
|
profile["gold"] = int(profile.get("gold", 0)) - cost
|
|
levels[hero_id] = level + 1
|
|
profile["hero_levels"] = levels
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
# Pop the specific row that just changed; a purchase is a medium event and
|
|
# deserves a legible confirmation beyond the number update.
|
|
var row: Dictionary = _skyport_upgrade_rows.get(hero_id, {})
|
|
if row.has("button"):
|
|
if _fb() != null:
|
|
_fb().pop(row["button"] as Control, 1.0)
|
|
|
|
|
|
## Test helpers for the headless loop test.
|
|
func get_battle() -> BattleScene:
|
|
return _battle
|
|
|
|
|
|
func get_profile() -> Dictionary:
|
|
return profile
|
|
|
|
|
|
func start_node(node_id: String) -> void:
|
|
_on_start_node(node_id)
|
|
|
|
|
|
func is_modal_visible() -> bool:
|
|
return _modal.visible
|
|
|
|
|
|
func modal_action_count() -> int:
|
|
return _modal_actions.get_child_count()
|
|
|
|
|
|
func get_upgrade_rows_for_test() -> Dictionary:
|
|
return _skyport_upgrade_rows
|
|
|
|
|
|
func set_auto_run_for_test(value: bool) -> void:
|
|
profile["auto_run"] = value
|
|
_refresh_pages()
|
|
|
|
|
|
func find_skyport_scroll_for_test() -> ScrollContainer:
|
|
if _u2_skyport != null:
|
|
return _u2_skyport.scroll
|
|
if _skyport == null:
|
|
return null
|
|
for child in _skyport.get_children():
|
|
if child is ScrollContainer:
|
|
return child
|
|
return null
|
|
|
|
|
|
func show_page_for_test(page: String) -> void:
|
|
show_page(page)
|
|
|
|
|
|
func set_locale_for_test(value: String) -> void:
|
|
set_locale(value)
|
|
|
|
|
|
func set_side_tab_for_test(tab: String) -> void:
|
|
_select_side_tab(tab)
|
|
|
|
|
|
func get_side_state_for_test() -> Dictionary:
|
|
return {
|
|
"tab": _side_tab,
|
|
"summary": _side_summary.text if _side_summary != null else "",
|
|
"rows": _side_rows.get_child_count() if _side_rows != null else 0,
|
|
}
|
|
|
|
|
|
func claim_partner_for_test(partner_id: String) -> Dictionary:
|
|
return SideSystems.claim_partner(profile, partner_id)
|
|
|
|
|
|
## Stage H: 4-type commission board + 5 partner perks, on the live profile.
|
|
func commission_board_status_for_test() -> Array:
|
|
return CommissionBoard.status(profile)
|
|
|
|
|
|
func claim_commission_board_for_test(tid: String) -> Dictionary:
|
|
return CommissionBoard.claim(profile, tid)
|
|
|
|
|
|
func partner_perks_for_test() -> Dictionary:
|
|
return PartnerPerks.compute(profile)
|
|
|
|
|
|
func battle_chrome_state_for_test() -> Dictionary:
|
|
return {"shell_nav_visible": _nav_box != null and _nav_box.visible,
|
|
"shell_header_visible": _header_box != null and _header_box.visible,
|
|
"shell_modal_visible": _modal != null and _modal.visible,
|
|
"current_page": current_page}
|
|
|
|
|
|
func endless_state_for_test() -> Dictionary:
|
|
return _endless_state.duplicate(true)
|
|
|
|
|
|
func endless_advance_for_test(count: int) -> Dictionary:
|
|
if _endless_state.is_empty():
|
|
_endless_state = EndlessBattle.new_state()
|
|
var last := {}
|
|
for i in range(count):
|
|
last = EndlessBattle.step(_endless_state)
|
|
return last
|
|
|
|
|
|
func endless_offline_for_test(elapsed: float) -> Dictionary:
|
|
# Settle offline progression on the current endless state; returns report.
|
|
var r := EndlessOffline.settle(_endless_state, elapsed)
|
|
_endless_state = r["state"]
|
|
return {"zones": int(r.get("zones_cleared", 0)), "zone": int(_endless_state.get("zone", 1))}
|
|
|
|
|
|
func endless_upgrade_for_test() -> bool:
|
|
return EndlessBattle.buy_levels(_endless_state, 5)
|
|
|
|
|
|
func endless_fund_for_test() -> void:
|
|
# Test-only: grant 1e12 gold so upgrade can be verified deterministically.
|
|
var BigValue = preload("res://scripts/big_value.gd")
|
|
_endless_state["gold"] = BigValue.new(1.0, 12.0)
|
|
|
|
|
|
func revive_budget_for_test() -> int:
|
|
return _revive_budget_left
|
|
|
|
|
|
func claim_record_for_test(record_id: String) -> Dictionary:
|
|
return SideSystems.claim_record(profile, record_id, WorldContent.content().get("records", []))
|
|
|
|
|
|
func buy_market_for_test(offer_id: String) -> Dictionary:
|
|
return SideSystems.purchase(profile, offer_id, WorldContent.content())
|
|
|
|
|
|
# S4 source-bound relic/gild probes. Save-first stays in the caller, matching
|
|
# the existing market/partner hooks.
|
|
func relic_gild_state_for_test() -> Dictionary:
|
|
return ChRelicGild.state_for_test(profile)
|
|
|
|
|
|
func gild_levels_for_test() -> Dictionary:
|
|
return ChRelicGild.gild_levels(profile)
|
|
|
|
|
|
func active_relics_for_test() -> Dictionary:
|
|
return ChRelicGild.active_relics(profile)
|
|
|
|
|
|
func relic_action_for_test(action: String, uid: int = 0, target: int = 0) -> Dictionary:
|
|
var r := ChRelicGild.relic_action(profile, action, uid, target)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func gild_action_for_test(hero_id: String, mode: String) -> Dictionary:
|
|
var r := ChRelicGild.gild_action(profile, hero_id, mode)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func claim_gild_for_test(all_available: bool = false) -> Dictionary:
|
|
var r := ChRelicGild.claim_gild(profile, all_available)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func _find_button(node: Node) -> Button:
|
|
if node is Button:
|
|
return node as Button
|
|
for child in node.get_children():
|
|
var found := _find_button(child)
|
|
if found != null:
|
|
return found
|
|
return null
|
|
|
|
|
|
func market_button_rect_for_test(index: int) -> Rect2:
|
|
if _side_rows == null or index < 0 or index >= _side_rows.get_child_count():
|
|
return Rect2()
|
|
var btn := _find_button(_side_rows.get_child(index))
|
|
if btn == null:
|
|
return Rect2()
|
|
return btn.get_global_rect()
|
|
|
|
|
|
func scroll_market_to_for_test(index: int) -> void:
|
|
if _side_rows == null or index < 0 or index >= _side_rows.get_child_count():
|
|
return
|
|
var scroll := _side.get_child(0) as ScrollContainer
|
|
if scroll != null:
|
|
scroll.scroll_vertical = maxi(0, int(_side_rows.get_child(index).position.y) - 12)
|
|
|
|
|
|
func get_lowfreq_status_for_test() -> Dictionary:
|
|
return LowFreq.status(profile, WorldContent.content())
|
|
|
|
|
|
func claim_echo_for_test() -> Dictionary:
|
|
var r := LowFreq.claim_echo(profile)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func start_buoy_for_test() -> Dictionary:
|
|
var r := LowFreq.start_buoy(profile)
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func tap_buoy_for_test() -> Dictionary:
|
|
var r := LowFreq.tap_buoy(profile)
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func claim_crate_for_test() -> Dictionary:
|
|
var r := LowFreq.claim_crate(profile)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func claim_commission_for_test() -> Dictionary:
|
|
var r := LowFreq.claim_commission(profile)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func claim_journal_for_test(chapter: String) -> Dictionary:
|
|
var r := LowFreq.claim_journal(profile, chapter)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func get_loadout_state_for_test() -> Dictionary:
|
|
return {
|
|
"hero": _loadout_hero, "detail": _loadout_detail.text,
|
|
"gear_rows": _loadout_gear_col.get_child_count() if _loadout_gear_col != null else 0,
|
|
"owned_gear": (profile.get("gear", {}) as Dictionary).size(),
|
|
"equipped": (profile.get("equipped", {}) as Dictionary).duplicate(true),
|
|
}
|
|
|
|
|
|
func select_loadout_hero_for_test(hid: String) -> void:
|
|
_select_loadout_hero(hid)
|
|
|
|
|
|
func grant_gear_drop_for_test(node_id: String) -> Dictionary:
|
|
var r := GearActions.grant_drop(profile, node_id, WorldContent.content())
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func equip_gear_for_test(slot: String, gear_id: String) -> Dictionary:
|
|
var r := GearActions.equip(profile, slot, gear_id, WorldContent.content())
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_loadout()
|
|
return r
|
|
|
|
|
|
func get_loadout_growth_for_test() -> Dictionary:
|
|
return GrowthModifiers.compute_full_game(profile)
|
|
|
|
|
|
func get_world_state_for_test() -> Dictionary:
|
|
var regions := 0
|
|
var chapters := 0
|
|
var nodes := 0
|
|
if _u2_world != null:
|
|
for key in _u2_world.tap_targets.keys():
|
|
var k := str(key)
|
|
if k.begins_with("world_region_"):
|
|
regions += 1
|
|
elif k.begins_with("world_chapter_"):
|
|
chapters += 1
|
|
elif k.begins_with("world_node_"):
|
|
nodes += 1
|
|
return {
|
|
"region": _world_region, "chapter": _world_chapter, "node": _world_node,
|
|
"detail": _world_detail.text if _world_detail != null else "",
|
|
"progress": _world_progress.text if _world_progress != null else "",
|
|
"region_count": regions, "chapter_count": chapters, "node_count": nodes,
|
|
}
|
|
|
|
|
|
func get_world_counts_for_test() -> Dictionary:
|
|
return WorldContent.counts()
|
|
|
|
|
|
func select_world_region_for_test(region_id: String) -> void:
|
|
_select_world_region(region_id)
|
|
|
|
|
|
func select_world_chapter_for_test(chapter_id: String) -> void:
|
|
_select_world_chapter(chapter_id)
|
|
|
|
|
|
func select_world_node_for_test(node_id: String) -> void:
|
|
_select_world_node(node_id)
|
|
|
|
|
|
func is_world_node_available_for_test(node_id: String) -> bool:
|
|
return _is_world_node_available(node_id)
|
|
|
|
|
|
func launch_world_node_for_test(node_id: String) -> void:
|
|
_select_world_node(node_id)
|
|
_launch_world_node()
|
|
|
|
|
|
func force_world_battle_result_for_test(result: String) -> void:
|
|
if _battle != null:
|
|
_battle.battle_finished.emit(result, "REWARD-WORLD-TEST", "TEST")
|
|
|
|
|
|
func is_world_mode_for_test() -> bool:
|
|
return _world_mode
|
|
|
|
|
|
func get_world_growth_modifiers_for_test() -> Dictionary:
|
|
return GrowthModifiers.compute_full_game(profile)
|
|
|
|
|
|
func compute_growth_for_profile_for_test(p: Dictionary) -> Dictionary:
|
|
return GrowthModifiers.compute_full_game(p)
|
|
|
|
|
|
func get_prestige_direction_for_test(oaths: Dictionary, edicts: Dictionary) -> Dictionary:
|
|
const PD = preload("res://scripts/prestige_direction.gd")
|
|
return PD.direction_modifier(oaths, edicts)
|
|
|
|
|
|
func core_combo_valid_for_test(oaths: Dictionary) -> bool:
|
|
const PD = preload("res://scripts/prestige_direction.gd")
|
|
return PD.core_combo_valid(oaths)
|
|
|
|
|
|
func new_sky_unlock_for_test() -> Dictionary:
|
|
return Prestige.new_sky_unlock(profile)
|
|
|
|
|
|
func rebuild_unlock_for_test() -> Dictionary:
|
|
return Prestige.rebuild_unlock(profile)
|
|
|
|
|
|
func return_time_estimate_for_test() -> Dictionary:
|
|
return Prestige.return_time_estimate(profile)
|
|
|
|
|
|
func edict_cost_for_test(edict_id: String) -> int:
|
|
return Prestige.edict_cost(edict_id)
|
|
|
|
|
|
func buy_edict_for_test(edict_id: String) -> Dictionary:
|
|
var r := Prestige.buy_edict(profile, edict_id)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
return r
|
|
|
|
|
|
func open_edict_shop_for_test() -> void:
|
|
_open_edict_shop()
|
|
|
|
|
|
## S3 transcendence / outsider probes (source-bound, isolated profile state).
|
|
func transcendence_preview_for_test(respec_: bool = false) -> Dictionary:
|
|
return Transcendence.preview(profile, respec_)
|
|
|
|
|
|
func apply_transcendence_for_test(respec_: bool = false) -> Dictionary:
|
|
var result := Transcendence.apply_transcendence(profile, respec_)
|
|
if bool(result.get("ok")):
|
|
_refresh_pages()
|
|
return result
|
|
|
|
|
|
func transcendent_power_for_test() -> float:
|
|
return Transcendence.book_from_profile(profile).transcendent_power()
|
|
|
|
|
|
func transcendent_primal_reward_for_test(level: int) -> int:
|
|
return Transcendence.transcendent_primal_reward(level, Transcendence.book_from_profile(profile))
|
|
|
|
|
|
func buy_outsider_for_test(id: int, count: int = 1) -> Dictionary:
|
|
# Save-first: the candidate wallet reaches disk before adoption, so a failed
|
|
# write cannot leave an in-memory purchase that disappears on reload.
|
|
var candidate := profile.duplicate(true)
|
|
var book: OutsiderBook = Transcendence.book_from_profile(candidate)
|
|
var quote := book.quote(id, count)
|
|
if not bool(quote.get("affordable")):
|
|
return {"ok": false, "reason": "unaffordable", "quote": quote}
|
|
if not book.buy(id, count):
|
|
return {"ok": false, "reason": "buy_rejected", "quote": quote}
|
|
candidate["ancient_souls"] = book.snapshot()
|
|
if not ProfileStore.save_profile(candidate):
|
|
return {"ok": false, "reason": "save_failed", "quote": quote}
|
|
profile["ancient_souls"] = candidate["ancient_souls"]
|
|
return {"ok": true, "id": id, "count": int(quote.get("count", 0)),
|
|
"cost": int(quote.get("cost", 0)), "balance": book.balance}
|
|
|
|
|
|
func open_outsider_shop_for_test() -> void:
|
|
_open_outsider_shop()
|
|
|
|
|
|
func get_modal_button_disabled_for_test() -> Array:
|
|
var out: Array = []
|
|
for child in _modal_actions.get_children():
|
|
out.append((child as Button).disabled)
|
|
return out
|
|
|
|
|
|
func find_map_scroll_for_test() -> ScrollContainer:
|
|
if _map == null:
|
|
return null
|
|
for child in _map.get_children():
|
|
if child is ScrollContainer:
|
|
return child
|
|
return null
|
|
|
|
|
|
func unlock_all_for_test() -> void:
|
|
var unlocked: Array = []
|
|
for row in LaunchContent.heroes():
|
|
unlocked.append(str(row.get("id", "")))
|
|
profile["unlocked_heroes"] = unlocked
|
|
|
|
|
|
func refresh_pages_for_test() -> void:
|
|
_refresh_pages()
|
|
|
|
|
|
func upgrade_for_test(hero_id: String) -> void:
|
|
_on_upgrade(hero_id)
|
|
|
|
|
|
## Full-game growth investments through the real profile. Returns the action
|
|
## result and saves/persists + refreshes on success, so UI and tests share one
|
|
## authoritative path.
|
|
func invest_talent(hero_id: String, slot: int) -> Dictionary:
|
|
var r := GrowthActions.invest_talent(profile, hero_id, slot)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
return r
|
|
|
|
|
|
## Full-game prestige preview (design section 8). The live slice rebuild keeps
|
|
## its own smaller formula; these expose the full-game engine for the eventual
|
|
## 600-node build and for verification now.
|
|
func prestige_preview_for_test() -> Dictionary:
|
|
return {
|
|
"rebuild": Prestige.rebuild_preview(profile),
|
|
"new_sky": Prestige.new_sky_preview(profile),
|
|
"ascension": Prestige.ascension_preview(profile),
|
|
}
|
|
|
|
|
|
func apply_full_rebuild_for_test() -> Dictionary:
|
|
var result := ProfileStore.normalize_for_test(Prestige.apply_rebuild(profile))
|
|
profile = result
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
return result
|
|
|
|
|
|
func apply_new_sky_for_test() -> Dictionary:
|
|
var result := ProfileStore.normalize_for_test(Prestige.apply_new_sky(profile))
|
|
# Partner P05 (观星师) specialty: sky-mark yield scales with its level.
|
|
var base_marks := int(result.get("sky_marks", 0))
|
|
var boosted := PartnerPerks.apply_sky_marks(profile, base_marks)
|
|
result["sky_marks"] = boosted
|
|
profile["sky_marks"] = boosted
|
|
profile = result
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
return result
|
|
|
|
|
|
func get_growth_rows_for_test() -> Dictionary:
|
|
return _growth_rows.duplicate()
|
|
|
|
|
|
func upgrade_star(hero_id: String) -> Dictionary:
|
|
var r := GrowthActions.upgrade_star(profile, hero_id)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
_refresh_pages()
|
|
return r
|
|
|
|
|
|
func get_map_progress_text_for_test() -> String:
|
|
return _map_progress.text if _map_progress != null else ""
|
|
|
|
|
|
func get_map_progress_ratio_for_test() -> float:
|
|
return _map_progress_fill.anchor_right if _map_progress_fill != null else -1.0
|
|
|
|
|
|
func get_map_step_dots_for_test() -> Array:
|
|
var result: Array = []
|
|
for conn in _map_connectors:
|
|
var dot: ColorRect = conn["dot"]
|
|
result.append({"node_id": str(conn["node_id"]), "color": dot.color})
|
|
return result
|
|
|
|
|
|
func get_event_banner_for_test() -> Control:
|
|
return _event_banner
|
|
|
|
|
|
func get_modal_actions_for_test() -> VBoxContainer:
|
|
return _modal_actions
|
|
|
|
|
|
func get_modal_visible_for_test() -> bool:
|
|
return _modal.visible
|
|
|
|
|
|
func get_modal_title_for_test() -> String:
|
|
return _modal_title.text
|
|
|
|
|
|
func get_modal_body_for_test() -> String:
|
|
return _modal_body.text
|
|
|
|
|
|
func on_modal_action_for_test(action: String) -> void:
|
|
_on_modal_action(action)
|
|
|
|
|
|
## Global-space centre of a modal action button, for real InputEventScreenTouch
|
|
## probes. Returns Vector2.ZERO when the action is not currently on screen.
|
|
func modal_button_center_for_test(action: String) -> Vector2:
|
|
# Match the bound action: queue_free() is deferred, so old buttons may still
|
|
# be in the tree while the replacement modal is being laid out.
|
|
for child in _modal_actions.get_children():
|
|
var button := child as Button
|
|
if button == null or button.disabled or button.is_queued_for_deletion():
|
|
continue
|
|
for conn in button.pressed.get_connections():
|
|
var callable: Callable = conn["callable"]
|
|
var args: Array = callable.get_bound_arguments()
|
|
if args.size() > 0 and str(args[0]) == action:
|
|
return button.get_global_rect().get_center()
|
|
return Vector2.ZERO
|
|
|
|
|
|
func on_prestige_preview_for_test() -> void:
|
|
_on_prestige_preview()
|
|
|
|
|
|
## U2 wiring evidence hook: reports the single authority's live view state.
|
|
func get_u2_state_for_test() -> Dictionary:
|
|
var dock_rect := Rect2()
|
|
var dock_label := ""
|
|
if _u2_dock != null and _u2_dock.button != null:
|
|
dock_rect = _u2_dock.button_global_rect()
|
|
dock_label = _u2_dock.button.text
|
|
var labels: Array = []
|
|
var raw_keys: Array = []
|
|
_collect_u2_labels(self, labels, raw_keys, 60)
|
|
return {
|
|
"page": current_page,
|
|
"active_node": active_node,
|
|
"world_node": _world_node,
|
|
"dock_visible": _u2_dock != null and _u2_dock.visible,
|
|
"dock_enabled": _u2_dock != null and _u2_dock.button != null and not _u2_dock.button.disabled,
|
|
"dock_rect": [dock_rect.position.x, dock_rect.position.y, dock_rect.size.x, dock_rect.size.y],
|
|
"dock_label": dock_label,
|
|
"safe_top": _safe_top,
|
|
"safe_bottom": _safe_bottom,
|
|
"u2_shell_count": _count_u2_shells(self),
|
|
"u2_skyport": _u2_skyport != null,
|
|
"u2_world": _u2_world != null,
|
|
"u2_settlement": _u2_settlement_host != null and is_instance_valid(_u2_settlement_host),
|
|
"u2_settlement_card": _u2_settlement != null and is_instance_valid(_u2_settlement) and _u2_settlement.get_child_count() > 0,
|
|
"labels": labels,
|
|
"raw_keys": raw_keys,
|
|
}
|
|
|
|
|
|
func u2_target_rect_for_test(key: String) -> Rect2:
|
|
if _u2_world != null and _u2_world.tap_targets.has(key):
|
|
var control := _u2_world.tap_targets[key] as Control
|
|
if control != null:
|
|
return control.get_global_rect()
|
|
if _u2_skyport != null and _u2_skyport.tap_targets.has(key):
|
|
var control2 := _u2_skyport.tap_targets[key] as Control
|
|
if control2 != null:
|
|
return control2.get_global_rect()
|
|
return Rect2()
|
|
|
|
|
|
## S5/S6 real-touch probes: return the global rect of a live Button created by
|
|
## the guild/bounties tabs. No callback is invoked directly by the probe.
|
|
func ch_target_rect_for_test(key: String) -> Rect2:
|
|
var control := _ch_targets.get(key, null) as Control
|
|
if control == null or not is_instance_valid(control):
|
|
return Rect2()
|
|
return control.get_global_rect()
|
|
|
|
|
|
## Probe-only: global rect of the first enabled side-row Button whose pressed
|
|
## callback matches `method` (and optional bound id, e.g. "P01"/"A001").
|
|
## Read-only lookup for real-touch tests -- product routes, labels, disabled
|
|
## flags and touch handling are untouched.
|
|
func side_row_rect_for_test(method: String, bound_id: String = "") -> Rect2:
|
|
if _side_rows == null:
|
|
return Rect2()
|
|
for panel in _side_rows.get_children():
|
|
var btn := _find_button(panel)
|
|
if btn == null or not is_instance_valid(btn) or btn.disabled or btn.is_queued_for_deletion():
|
|
continue
|
|
for conn in btn.pressed.get_connections():
|
|
var callable: Callable = conn["callable"]
|
|
if str(callable.get_method()) != method:
|
|
continue
|
|
var args: Array = callable.get_bound_arguments()
|
|
if bound_id.is_empty() or (args.size() > 0 and str(args[0]) == bound_id):
|
|
return btn.get_global_rect()
|
|
return Rect2()
|
|
|
|
|
|
func find_side_scroll_for_test() -> ScrollContainer:
|
|
return _side_scroll
|
|
|
|
|
|
func ch_status_for_test() -> Dictionary:
|
|
return {"page": current_page, "side_tab": _side_tab,
|
|
"targets": _ch_targets.keys(),
|
|
"autoclick": (profile.get("autoclick", {}) as Dictionary).duplicate(true),
|
|
"clickable": (profile.get("clickable", {}) as Dictionary).duplicate(true),
|
|
"achievements": (profile.get("ch_achievements", {}) as Dictionary).duplicate(true),
|
|
"merc_count": (profile.get("merc_quests", []) as Array).size()}
|
|
|
|
|
|
func _collect_u2_labels(node: Node, labels: Array, raw_keys: Array, limit: int) -> void:
|
|
if labels.size() >= limit:
|
|
return
|
|
if node is Label:
|
|
var text := (node as Label).text
|
|
labels.append(text)
|
|
if text.begins_with("[") and text.ends_with("]") and text.length() > 2:
|
|
raw_keys.append(text)
|
|
for child in node.get_children():
|
|
_collect_u2_labels(child, labels, raw_keys, limit)
|
|
|
|
|
|
func _count_u2_shells(node: Node) -> int:
|
|
var count := 0
|
|
if node is UiSliceShell:
|
|
count += 1
|
|
for child in node.get_children():
|
|
count += _count_u2_shells(child)
|
|
return count
|
|
|
|
|
|
func get_victory_row_for_test() -> Control:
|
|
return _victory_row
|
|
|
|
|
|
func get_victory_number_for_test() -> Label:
|
|
return _victory_number
|
|
|
|
|
|
func get_victory_banner_for_test() -> Control:
|
|
return _victory_banner
|
|
|
|
|
|
## Drive the real player victory path to completion for capture evidence.
|
|
## Battle advances synchronously so the celebration modal is live with no
|
|
## dependence on real-time frame pacing.
|
|
## Emit a battle result through the real player routing without depending on
|
|
## sim dynamics (used to test defeat / wave-clear modal states).
|
|
func force_battle_result_for_test(result: String) -> void:
|
|
if _battle != null:
|
|
_battle.battle_finished.emit(result, "REWARD-TEST", "TEST")
|
|
|
|
|
|
func force_victory_for_test(node_id: String) -> void:
|
|
start_node(node_id)
|
|
if _battle == null:
|
|
return
|
|
_battle.set_process(false)
|
|
var guard := 0
|
|
while not _battle.finished and guard < 1200:
|
|
_battle.advance_ticks(1)
|
|
guard += 1
|
|
|
|
|
|
func reset_profile_for_test() -> void:
|
|
var p := ProfileStore.fresh_profile()
|
|
p["reduced_motion"] = reduced_motion
|
|
profile = p
|
|
_refresh_pages()
|
|
|
|
|
|
func set_reduced_motion_for_test(value: bool) -> void:
|
|
reduced_motion = value
|
|
profile["reduced_motion"] = value
|
|
if _battle != null:
|
|
_battle.set_reduced_motion(value)
|
|
ProfileStore.save_profile(profile)
|
|
|
|
|
|
func next_auto_node_for_test() -> String:
|
|
return _next_auto_node()
|
|
|
|
|
|
func active_node_for_test() -> String:
|
|
return active_node
|
|
|
|
|
|
func auto_pending_for_test() -> bool:
|
|
return _auto_advance_pending
|
|
|
|
|
|
func should_auto_advance_for_test(node_id: String) -> bool:
|
|
return _should_auto_advance(LaunchContent.node(node_id))
|
|
|
|
|
|
func choose_event(choice_id: String) -> void:
|
|
_on_event_choice(active_node, choice_id)
|
|
|
|
|
|
func _on_start_node(node_id: String) -> void:
|
|
if ProfileStore.is_first_run(profile):
|
|
ProfileStore.mark_intro_seen(profile)
|
|
ProfileStore.save_profile(profile)
|
|
var node_row := LaunchContent.node(node_id)
|
|
if str(node_row.get("type", "")) == "event":
|
|
active_node = node_id
|
|
_show_event(node_id)
|
|
return
|
|
active_node = node_id
|
|
active_wave = 0
|
|
_revive_budget_left = PartnerPerks.effective_revives(profile)
|
|
_start_active_wave()
|
|
|
|
|
|
func _clear_event_banner() -> void:
|
|
if _event_banner != null and is_instance_valid(_event_banner):
|
|
_event_banner.queue_free()
|
|
_event_banner = null
|
|
|
|
|
|
func _show_event(node_id: String) -> void:
|
|
var event: Dictionary = LaunchContent.content().get("events", {}).get(node_id, {})
|
|
if event.is_empty():
|
|
_finish_node()
|
|
return
|
|
_clear_victory_row()
|
|
_clear_event_banner()
|
|
_modal_title.text = UiText.t(str(event.get("title_key", "")), locale)
|
|
_modal_body.text = UiText.t(str(event.get("body_key", "")), locale)
|
|
_modal_body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
|
|
# A distinct banner makes an event read as a story beat, not a generic
|
|
# dialog: a large question icon + an event tag, tinted mint.
|
|
_event_banner = HBoxContainer.new()
|
|
_event_banner.add_theme_constant_override("separation", 12)
|
|
var banner_icon := _icon_rect("res://assets/icons/icon_question.png")
|
|
banner_icon.custom_minimum_size = Vector2(44, 44)
|
|
_event_banner.add_child(banner_icon)
|
|
var banner_tag := UiTheme.make_label(UiText.t("shell.event.tag", locale), 15, UiTheme.COLOR_MINT)
|
|
_event_banner.add_child(banner_tag)
|
|
var stack := _modal_title.get_parent()
|
|
var idx := _modal_title.get_index()
|
|
stack.add_child(_event_banner)
|
|
stack.move_child(_event_banner, idx)
|
|
|
|
for child in _modal_actions.get_children():
|
|
child.queue_free()
|
|
for choice in event.get("choices", []):
|
|
# Each choice is a card: a short imperative + a visual reward row
|
|
# (coin / crystal icons with amounts). The trade-off is scannable
|
|
# without reading sentences, and stays data-driven from the content.
|
|
var card := UiTheme.glass_panel(0.9)
|
|
var card_margin := MarginContainer.new()
|
|
card_margin.add_theme_constant_override("margin_left", 12)
|
|
card_margin.add_theme_constant_override("margin_right", 12)
|
|
card_margin.add_theme_constant_override("margin_top", 8)
|
|
card_margin.add_theme_constant_override("margin_bottom", 8)
|
|
card.add_child(card_margin)
|
|
var card_stack := VBoxContainer.new()
|
|
card_stack.add_theme_constant_override("separation", 6)
|
|
card_margin.add_child(card_stack)
|
|
var short_key := "event.%s.%s.short" % [_event_key(node_id), str(choice.get("id", ""))]
|
|
var short_text := UiText.t(short_key, locale)
|
|
if short_text == short_key:
|
|
short_text = UiText.t(str(choice.get("label_key", "")), locale)
|
|
var button := UiTheme.make_button(short_text, 14)
|
|
button.custom_minimum_size = Vector2(0, 42)
|
|
button.pressed.connect(_on_event_choice.bind(node_id, str(choice.get("id", ""))))
|
|
card_stack.add_child(button)
|
|
card_stack.add_child(_reward_chip_row(int(choice.get("gold", 0)), int(choice.get("crystal", 0))))
|
|
_modal_actions.add_child(card)
|
|
_modal.visible = true
|
|
|
|
|
|
func _event_key(node_id: String) -> String:
|
|
# Content event keys use the short suffix (R1-C01-N04 -> N04).
|
|
return node_id.substr(node_id.rfind("-") + 1)
|
|
|
|
|
|
func _reward_chip_row(gold: int, crystal: int) -> HBoxContainer:
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 14)
|
|
if gold > 0:
|
|
var chip := HBoxContainer.new()
|
|
chip.add_theme_constant_override("separation", 4)
|
|
chip.add_child(_icon_rect("res://assets/icons/icon_gold.png"))
|
|
chip.add_child(UiTheme.make_label("+%d" % gold, 12, UiTheme.COLOR_BORDER))
|
|
row.add_child(chip)
|
|
if crystal > 0:
|
|
var chip := HBoxContainer.new()
|
|
chip.add_theme_constant_override("separation", 4)
|
|
chip.add_child(_icon_rect("res://assets/icons/icon_crystal.png"))
|
|
chip.add_child(UiTheme.make_label("+%d" % crystal, 12, UiTheme.COLOR_MINT))
|
|
row.add_child(chip)
|
|
return row
|
|
|
|
|
|
func _on_event_choice(node_id: String, choice_id: String) -> void:
|
|
var event: Dictionary = LaunchContent.content().get("events", {}).get(node_id, {})
|
|
var chosen: Dictionary = {}
|
|
for choice in event.get("choices", []):
|
|
if str(choice.get("id", "")) == choice_id:
|
|
chosen = choice
|
|
break
|
|
if chosen.is_empty():
|
|
return
|
|
profile["gold"] = int(profile.get("gold", 0)) + int(chosen.get("gold", 0))
|
|
profile["crystal"] = int(profile.get("crystal", 0)) + int(chosen.get("crystal", 0))
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
if not completed.has(node_id):
|
|
completed.append(node_id)
|
|
profile["completed_nodes"] = completed
|
|
ProfileStore.save_profile(profile)
|
|
_modal.visible = false
|
|
_refresh_pages()
|
|
|
|
|
|
func _start_active_wave() -> void:
|
|
var scenario := LaunchContent.scenario_for_node(active_node, active_wave)
|
|
if scenario.is_empty():
|
|
_finish_node()
|
|
return
|
|
_world_mode = false
|
|
_present_battle(scenario, active_node, active_wave)
|
|
|
|
|
|
func _present_battle(scenario: Dictionary, node_id: String, wave: int) -> void:
|
|
current_page = PAGE_BATTLE
|
|
_skyport.visible = false
|
|
_map.visible = false
|
|
# Hide the shell's bottom nav during battle: the battle HUD has its own nav
|
|
# bar. Two overlapping nav bars made taps ambiguous / appear dead on device.
|
|
if _nav_box != null:
|
|
_nav_box.visible = false
|
|
if _header_box != null:
|
|
_header_box.visible = false
|
|
if _u2_dock != null:
|
|
_u2_dock.visible = false
|
|
_layout_u2_dock()
|
|
# A leftover full-screen modal (STOP filter) would swallow every tap in
|
|
# battle and look like "the tabs do nothing / battle frozen".
|
|
if _modal != null:
|
|
_modal.visible = false
|
|
if _world != null:
|
|
_world.visible = false
|
|
if _settings != null:
|
|
_settings.visible = false
|
|
if _growth != null:
|
|
_growth.visible = false
|
|
if _battle_host == null:
|
|
_battle_host = Control.new()
|
|
_battle_host.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_page_host.add_child(_battle_host)
|
|
_battle_host.visible = true
|
|
for child in _battle_host.get_children():
|
|
child.queue_free()
|
|
_battle = load("res://scenes/battle_scene.tscn").instantiate() as BattleScene
|
|
_battle_host.add_child(_battle)
|
|
_battle.use_external_progress = true
|
|
_battle.battle_finished.connect(_on_battle_finished)
|
|
_battle.exit_requested.connect(_on_battle_exit_requested)
|
|
_battle.set_low_power(low_power)
|
|
_battle.set_muted(muted)
|
|
_battle.set_reduced_motion(reduced_motion)
|
|
if _battle.hud != null:
|
|
_battle.hud.set_locale(locale)
|
|
# The HUD's own rect starts at 0 unless we inject the platform insets.
|
|
_battle.hud.set_safe_area(_safe_top, _safe_bottom)
|
|
# Apply the profile before setup so roster DPS and visible heroes match.
|
|
_apply_profile_to_battle()
|
|
# setup() resets the HUD locale from its first argument, so pass the shell
|
|
# locale here; the earlier set_locale() call alone gets overwritten.
|
|
_battle.setup(locale, node_id, 10001 + wave)
|
|
# setup() builds its own scenario; replace it with the P3a node scenario.
|
|
# Full-game growth layers produce a modifier bundle (empty profile -> identity).
|
|
# Inject it into the scenario so both sims consume the same numbers.
|
|
scenario["growth_modifiers"] = GrowthModifiers.compute(profile)
|
|
# Stage E: fold enemy/boss mechanics into each spec (different enemies need
|
|
# different answers); absent tags leave the scenario unchanged.
|
|
EnemyMechanics.apply_to_scenario(scenario)
|
|
# Stage B: attach each visible hero's 4 skill archetypes so combat triggers
|
|
# DIFFERENT effect primitives per hero (ADR-008 / PRODUCTION/51). Absent when
|
|
# no heroes unlocked -> sim identity. Built from the same unlocked roster that
|
|
# set_p3a_scenario will install as visible_hero_ids.
|
|
if not scenario.has("skills"):
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
if not unlocked.is_empty():
|
|
# Stage C: active behavior talents rewrite the hero's skill effects.
|
|
scenario["skills"] = HeroSkillLoader.build_skills(
|
|
unlocked, HeroSkillLoader.load_skill_data(), HeroSkillLoader.load_hero_stats(),
|
|
profile.get("talents", {}), HeroSkillLoader.load_talent_specs(),
|
|
profile.get("edicts", {}), profile.get("relics", {}),
|
|
profile.get("oaths", {}), profile.get("hero_levels", {}),
|
|
ChRelicGild.gild_levels(profile))
|
|
_battle.set_p3a_scenario(scenario, _roster_bonus(), profile.get("unlocked_heroes", []), 10001 + wave)
|
|
# The previous shell paused the battle here and never resumed it, so real
|
|
# (non-test) play froze on frame 0. Tests pause explicitly after start_node;
|
|
# enabling here makes the live slice AND world nodes actually advance.
|
|
_battle.set_process(true)
|
|
|
|
|
|
func _apply_profile_to_battle() -> void:
|
|
if _battle == null:
|
|
return
|
|
_battle.gold = int(profile.get("gold", 0))
|
|
_battle.crystal = int(profile.get("crystal", 0))
|
|
var levels: Dictionary = profile.get("hero_levels", {})
|
|
for key in levels.keys():
|
|
_battle.hero_levels[str(key)] = int(levels[key])
|
|
|
|
|
|
func _roster_bonus() -> float:
|
|
var bonus := 0.0
|
|
for hero_row in LaunchContent.heroes():
|
|
var hero_id := str(hero_row.get("id", ""))
|
|
if not _is_unlocked(hero_id):
|
|
continue
|
|
var level := int((profile.get("hero_levels", {}) as Dictionary).get(hero_id, 1))
|
|
var base := float(hero_row.get("base_dps", 0.0))
|
|
bonus += base * (1.0 + 0.25 * float(maxi(0, level - 1))) - base
|
|
return bonus
|
|
|
|
|
|
## Leave the current battle via pause-exit / nav buttons. Abandoning a fight
|
|
## grants no reward and keeps progress at the last completed node.
|
|
func _on_battle_exit_requested(page: String) -> void:
|
|
_diag_write("exit_req:%s from=%s" % [page, current_page])
|
|
if _battle != null:
|
|
_battle.set_process(false)
|
|
# Battle HUD lives in a CanvasLayer: it renders above all normal Control
|
|
# nodes and is NOT reliably hidden by the parent host's visible=false.
|
|
# Explicitly hide it or the fight keeps covering the destination page.
|
|
if _battle.hud != null:
|
|
_battle.hud.visible = false
|
|
var hud_layer := _battle.get_node_or_null("HUDLayer")
|
|
if hud_layer != null:
|
|
hud_layer.visible = false
|
|
if _battle_host != null:
|
|
_battle_host.visible = false
|
|
sfx.play("ui", "ui")
|
|
# Map HUD nav ids to shell pages. Each of the four battle tabs now really
|
|
# goes somewhere different instead of all exiting to the same page.
|
|
var dest := PAGE_SKYPORT
|
|
var nav_key := "skyport"
|
|
match page:
|
|
"expedition":
|
|
dest = PAGE_MAP
|
|
nav_key = "expedition"
|
|
"company":
|
|
dest = PAGE_GROWTH
|
|
nav_key = "company"
|
|
"archive":
|
|
dest = PAGE_SIDE
|
|
nav_key = "archive"
|
|
show_page(dest)
|
|
# Leaving battle via a tab used to be silent -- the player could not tell
|
|
# whether the fight ended or the screen simply changed. Say it explicitly.
|
|
show_toast(UiText.t("hud.exit.notice", locale) + " " + UiText.t("hud.nav.%s" % nav_key, locale))
|
|
_diag_write("after_exit:page=%s battle_vis=%s" % [current_page,
|
|
str(_battle_host.visible if _battle_host != null else false)])
|
|
|
|
|
|
func _diag_write(line: String) -> void:
|
|
var f := FileAccess.open("user://nav_taps.log", FileAccess.READ_WRITE)
|
|
if f == null:
|
|
f = FileAccess.open("user://nav_taps.log", FileAccess.WRITE)
|
|
if f != null:
|
|
f.seek_end()
|
|
f.store_string(line + "\n")
|
|
f.close()
|
|
|
|
|
|
func _on_battle_finished(result: String, reward_id: String, _scenario_id: String) -> void:
|
|
if _world_mode:
|
|
_on_world_battle_finished(result, reward_id, _scenario_id)
|
|
return
|
|
var node_row := LaunchContent.node(active_node)
|
|
var waves: Array = node_row.get("waves", [])
|
|
if result == "win" and active_wave + 1 < waves.size():
|
|
active_wave += 1
|
|
_show_modal(
|
|
UiText.t("shell.victory.title", locale), UiText.tf("shell.victory.wave", {"wave": active_wave}, locale),
|
|
[{"label": UiText.t("shell.victory.continue", locale), "action": "next_wave"}]
|
|
)
|
|
return
|
|
if result == "win":
|
|
var gold := int(node_row.get("gold", 0))
|
|
var crystal := int(node_row.get("crystal", 0))
|
|
var claimed := ProfileStore.claim_once(profile, reward_id)
|
|
var new_unlocks: Array = []
|
|
if claimed:
|
|
sfx.play("reward", "sfx")
|
|
sfx.play("victory", "sfx")
|
|
profile["gold"] = int(profile.get("gold", 0)) + gold
|
|
profile["crystal"] = int(profile.get("crystal", 0)) + crystal
|
|
profile["battle_wins"] = int(profile.get("battle_wins", 0)) + 1
|
|
profile["total_gold_earned"] = int(profile.get("total_gold_earned", 0)) + gold
|
|
GearActions.grant_drop(profile, active_node, WorldContent.content())
|
|
var completed: Array = profile.get("completed_nodes", [])
|
|
if not completed.has(active_node):
|
|
completed.append(active_node)
|
|
profile["completed_nodes"] = completed
|
|
for unlock in node_row.get("unlocks", []):
|
|
var unlocked: Array = profile.get("unlocked_heroes", [])
|
|
if not unlocked.has(str(unlock)):
|
|
unlocked.append(str(unlock))
|
|
new_unlocks.append(str(unlock))
|
|
profile["unlocked_heroes"] = unlocked
|
|
ProfileStore.save_profile(profile)
|
|
var auto_advance := _should_auto_advance(node_row)
|
|
var actions: Array = [
|
|
{"label": UiText.t("shell.victory.map", locale), "action": "map"},
|
|
]
|
|
if auto_advance:
|
|
actions.append({"label": UiText.t("shell.auto.advance", locale), "action": "map"})
|
|
_show_victory(gold, crystal, node_row, actions, new_unlocks)
|
|
if auto_advance:
|
|
_auto_advance_pending = true
|
|
get_tree().create_timer(0.9).timeout.connect(_on_auto_advance_timeout)
|
|
else:
|
|
# Partner P04 (医师) specialty: a finite per-node revive budget = owned
|
|
# charges + medic-level free revives. Retry the current wave while the
|
|
# budget lasts; never infinite (prevents trivialising combat).
|
|
if _revive_budget_left > 0:
|
|
_revive_budget_left -= 1
|
|
if int(profile.get("revive_charges", 0)) > 0:
|
|
profile["revive_charges"] = int(profile["revive_charges"]) - 1
|
|
ProfileStore.save_profile(profile)
|
|
_start_active_wave()
|
|
return
|
|
sfx.play("defeat", "sfx")
|
|
_show_modal(
|
|
UiText.t("shell.defeat.title", locale), UiText.t("shell.defeat.body", locale),
|
|
[{"label": UiText.t("shell.victory.map", locale), "action": "map"}], -1,
|
|
{"state": "defeat", "reason": UiText.t("shell.defeat.body", locale),
|
|
"time": "", "return_label": UiText.t("shell.victory.map", locale)}
|
|
)
|
|
|
|
|
|
func _finish_node() -> void:
|
|
show_page(PAGE_MAP)
|
|
|
|
|
|
## Next node for continuous auto-expedition. Returns "" when the run should
|
|
## stop at an event (a real player choice) or after the chapter boss.
|
|
func _next_auto_node() -> String:
|
|
for row in LaunchContent.nodes():
|
|
var node_id := str(row.get("id", ""))
|
|
if not _is_node_available(node_id):
|
|
continue
|
|
# Events are state-dependent choices; never auto-resolve them.
|
|
if str(row.get("type", "")) == "event":
|
|
return ""
|
|
return node_id
|
|
return ""
|
|
|
|
|
|
## True while continuous auto-expedition is engaged and this win should
|
|
## chain straight into another battle instead of waiting at the result modal.
|
|
func _should_auto_advance(won_node: Dictionary) -> bool:
|
|
if not bool(profile.get("auto_run", false)):
|
|
return false
|
|
# A chapter boss clear is a milestone: stop and let the player see it.
|
|
if str(won_node.get("type", "")) == "boss":
|
|
return false
|
|
return not _next_auto_node().is_empty()
|
|
|
|
|
|
## U2 settlement visual: the U1 chapter card is rendered INSIDE the existing
|
|
## modal. Its own buttons are suppressed; _modal_actions -> _on_modal_action
|
|
## remains the only action path, so no settlement logic is bypassed.
|
|
func _clear_u2_settlement() -> void:
|
|
if _u2_settlement_host != null and is_instance_valid(_u2_settlement_host):
|
|
_u2_settlement_host.queue_free()
|
|
_u2_settlement_host = null
|
|
_u2_settlement = null
|
|
if _modal_title != null:
|
|
_modal_title.visible = true
|
|
if _modal_body != null:
|
|
_modal_body.visible = true
|
|
|
|
|
|
func _render_u2_settlement(data: Dictionary) -> void:
|
|
_clear_u2_settlement()
|
|
_u2_settlement = UiPageSettlement.new()
|
|
_u2_settlement.name = "U2SettlementVisual"
|
|
_u2_settlement.build(locale, reduced_motion)
|
|
_u2_settlement.set_state(str(data.get("state", "victory")))
|
|
_u2_settlement.set_runtime(data)
|
|
_u2_settlement.set_actions_visible(false)
|
|
var stack := _modal_title.get_parent()
|
|
if stack == null:
|
|
return
|
|
_u2_settlement_host = Control.new()
|
|
_u2_settlement_host.name = "U2SettlementHost"
|
|
_u2_settlement_host.custom_minimum_size = Vector2(0, 420)
|
|
_u2_settlement_host.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
stack.add_child(_u2_settlement_host)
|
|
stack.move_child(_u2_settlement_host, _modal_title.get_index())
|
|
_u2_settlement_host.add_child(_u2_settlement)
|
|
_u2_settlement.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_modal_title.visible = false
|
|
_modal_body.visible = false
|
|
|
|
|
|
func _show_modal(title: String, body: String, actions: Array, victory_gold: int = -1, settlement: Dictionary = {}) -> void:
|
|
_modal_title.text = title
|
|
_modal_body.text = body
|
|
_clear_u2_settlement()
|
|
_clear_victory_row()
|
|
_clear_event_banner()
|
|
_clear_victory_banner()
|
|
if victory_gold >= 0:
|
|
_build_victory_row(victory_gold)
|
|
for child in _modal_actions.get_children():
|
|
child.queue_free()
|
|
for i in actions.size():
|
|
var action: Dictionary = actions[i] as Dictionary
|
|
var button := UiTheme.make_dialog_action(str(action.get("label", "")), i == 0)
|
|
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
button.disabled = bool(action.get("disabled", false))
|
|
button.pressed.connect(_on_modal_action.bind(str(action.get("action", ""))))
|
|
_modal_actions.add_child(button)
|
|
if not settlement.is_empty():
|
|
_render_u2_settlement(settlement)
|
|
_modal.visible = true
|
|
|
|
|
|
func _show_victory(gold: int, crystal: int, node_row: Dictionary, actions: Array, new_unlocks: Array = []) -> void:
|
|
# A dedicated climax screen, not the generic dialog reused by every modal.
|
|
# Identity: a chest ribbon + "spoils secured" + region/node context, then a
|
|
# spoils card that rolls the gold number (and shows crystal / new ally).
|
|
_clear_u2_settlement()
|
|
_clear_victory_row()
|
|
_clear_event_banner()
|
|
_clear_victory_banner()
|
|
_modal_title.text = UiText.t("shell.victory.title", locale)
|
|
_modal_body.text = UiText.t("shell.victory.celebrate", locale)
|
|
|
|
var stack := _modal_title.get_parent()
|
|
var title_idx := _modal_title.get_index()
|
|
|
|
# Ribbon: chest icon + region/node "cleared" context above the title.
|
|
_victory_banner = HBoxContainer.new()
|
|
_victory_banner.add_theme_constant_override("separation", 10)
|
|
var chest := _icon_rect("res://assets/icons/icon_chest.png")
|
|
chest.custom_minimum_size = Vector2(44, 44)
|
|
_victory_banner.add_child(chest)
|
|
var region_name := UiText.t("content.region.%s" % active_node.substr(0, 2), locale)
|
|
var cleared := UiText.tf("shell.victory.cleared", {
|
|
"region": region_name, "index": int(node_row.get("index", 0)),
|
|
}, locale)
|
|
_victory_banner.add_child(UiTheme.make_label(cleared, 12, UiTheme.COLOR_BORDER))
|
|
stack.add_child(_victory_banner)
|
|
stack.move_child(_victory_banner, title_idx)
|
|
|
|
# The reward row keeps its hooks (get_victory_row_for_test /
|
|
# get_victory_number_for_test) so the celebration test stays authoritative.
|
|
_build_victory_row(gold)
|
|
|
|
# Crystal and newly-unlocked hero chips make the spoils legible.
|
|
if crystal > 0:
|
|
var chip := HBoxContainer.new()
|
|
chip.add_theme_constant_override("separation", 6)
|
|
chip.add_child(_icon_rect("res://assets/icons/icon_crystal.png"))
|
|
chip.add_child(UiTheme.make_label("+%d" % crystal, 13, UiTheme.COLOR_MINT))
|
|
var row_parent := _victory_row.get_parent()
|
|
row_parent.add_child(chip)
|
|
row_parent.move_child(chip, _victory_row.get_index() + 1)
|
|
for unlock in new_unlocks:
|
|
var hero_id := str(unlock)
|
|
var ally := UiTheme.make_label(
|
|
UiText.tf("shell.victory.new_hero", {"name": UiText.t("content.hero.%s.short" % hero_id, locale)}, locale),
|
|
12, UiTheme.COLOR_ORANGE
|
|
)
|
|
var row_parent := _victory_row.get_parent()
|
|
row_parent.add_child(ally)
|
|
row_parent.move_child(ally, _victory_row.get_index() + 1)
|
|
|
|
for child in _modal_actions.get_children():
|
|
child.queue_free()
|
|
for i in actions.size():
|
|
var action: Dictionary = actions[i] as Dictionary
|
|
var button := UiTheme.make_dialog_action(str(action.get("label", "")), i == 0)
|
|
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
button.disabled = bool(action.get("disabled", false))
|
|
button.pressed.connect(_on_modal_action.bind(str(action.get("action", ""))))
|
|
_modal_actions.add_child(button)
|
|
_modal.visible = true
|
|
|
|
|
|
func _clear_victory_banner() -> void:
|
|
if _victory_banner != null and is_instance_valid(_victory_banner):
|
|
_victory_banner.queue_free()
|
|
_victory_banner = null
|
|
|
|
|
|
func _clear_victory_row() -> void:
|
|
# Release the managed entry first; otherwise a session-long registry keeps
|
|
# a dead id after this row is freed.
|
|
if _victory_number != null and is_instance_valid(_victory_number) and _fb() != null:
|
|
_fb().kill_tween(_victory_number.get_instance_id())
|
|
if _victory_tween != null and _victory_tween.is_valid():
|
|
_victory_tween.kill()
|
|
_victory_tween = null
|
|
if _victory_row != null and is_instance_valid(_victory_row):
|
|
_victory_row.queue_free()
|
|
_victory_row = null
|
|
_victory_number = null
|
|
|
|
|
|
func _build_victory_row(gold: int) -> void:
|
|
# A dedicated celebration row: coin icon + a number that rolls up from 0.
|
|
_victory_row = HBoxContainer.new()
|
|
_victory_row.add_theme_constant_override("separation", 10)
|
|
# Insert between body and actions.
|
|
var body_node := _modal_body
|
|
var parent := body_node.get_parent()
|
|
var idx := body_node.get_index()
|
|
parent.add_child(_victory_row)
|
|
parent.move_child(_victory_row, idx + 1)
|
|
|
|
var icon := _icon_rect("res://assets/icons/icon_gold.png")
|
|
icon.custom_minimum_size = Vector2(36, 36)
|
|
_victory_row.add_child(icon)
|
|
_victory_number = UiTheme.make_label("0", 28, UiTheme.COLOR_BORDER)
|
|
_victory_row.add_child(_victory_number)
|
|
|
|
if reduced_motion:
|
|
_victory_number.text = "+%d" % gold
|
|
else:
|
|
# Number rolls from 0 to gold over ~0.6s with ease-out; the icon pops.
|
|
_victory_tween = create_tween()
|
|
_victory_tween.tween_method(_set_victory_number, 0, gold, 0.6) \
|
|
.set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
|
|
if _fb() != null:
|
|
var number_id := _victory_number.get_instance_id()
|
|
# clear_all() snaps the display to the final value instead of
|
|
# leaving a half-rolled number on screen.
|
|
_fb().track_tween(number_id, _victory_tween, func() -> void:
|
|
var obj := instance_from_id(number_id)
|
|
if obj is Label:
|
|
(obj as Label).text = "+%d" % gold)
|
|
_fb_pop(icon)
|
|
|
|
|
|
func _set_victory_number(value: int) -> void:
|
|
if is_instance_valid(_victory_number):
|
|
_victory_number.text = "+%d" % value
|
|
|
|
|
|
func _fb_pop(target: Control) -> void:
|
|
if _fb() != null:
|
|
_fb().pop(target, 1.0)
|
|
|
|
|
|
func _on_auto_advance_timeout() -> void:
|
|
if not _auto_advance_pending:
|
|
return
|
|
_auto_advance_pending = false
|
|
var next := _next_auto_node()
|
|
if next.is_empty():
|
|
show_page(PAGE_MAP)
|
|
return
|
|
_modal.visible = false
|
|
start_node(next)
|
|
|
|
|
|
func _on_modal_action(action: String) -> void:
|
|
_auto_advance_pending = false
|
|
_modal.visible = false
|
|
if action.begins_with("buy_edict:"):
|
|
var eid := action.substr(action.find(":") + 1)
|
|
var r := Prestige.buy_edict(profile, eid)
|
|
if bool(r.get("ok")):
|
|
ProfileStore.save_profile(profile)
|
|
sfx.play("upgrade", "ui")
|
|
_open_edict_shop() # refresh the shop with the new balance / owned state
|
|
return
|
|
if action.begins_with("buy_outsider:"):
|
|
var oid := int(action.substr(action.find(":") + 1))
|
|
var bought := buy_outsider_for_test(oid, 1)
|
|
if bool(bought.get("ok")):
|
|
sfx.play("upgrade", "ui")
|
|
_open_outsider_shop() # refresh levels, balance and TP
|
|
return
|
|
match action:
|
|
"endless_step":
|
|
_endless_advance(1)
|
|
return
|
|
"endless_run":
|
|
_endless_advance(25)
|
|
return
|
|
"endless_upgrade":
|
|
var ok := false
|
|
if not _endless_state.is_empty():
|
|
ok = EndlessBattle.buy_levels(_endless_state, 5)
|
|
if ok:
|
|
profile["endless"] = EndlessBattle.snapshot_for_save(_endless_state)
|
|
ProfileStore.save_profile(profile)
|
|
_show_endless_modal()
|
|
return
|
|
"next_wave":
|
|
_start_active_wave()
|
|
"confirm_rebuild":
|
|
_confirm_rebuild()
|
|
"confirm_full_rebuild":
|
|
var r := apply_full_rebuild_for_test()
|
|
var detail := UiText.tf("shell.prestige.rebuild_gain", {"essence": int(r.get("essence", 0))}, locale)
|
|
detail += "\n" + UiText.tf("shell.prestige.soul_gain", {"souls": int(r.get("soul_reward", 0))}, locale)
|
|
_show_modal(UiText.t("shell.prestige.done", locale), UiText.tf("shell.prestige.done_body", {"detail": detail}, locale), [
|
|
{"label": UiText.t("shell.prestige.do_rebuild", locale), "action": "map"},
|
|
])
|
|
"confirm_new_sky":
|
|
# Design 8.2: guard the gate at the action boundary too, not just UI.
|
|
if not bool(Prestige.new_sky_unlock(profile).get("unlocked")):
|
|
_show_modal(UiText.t("shell.prestige.title", locale),
|
|
UiText.t("shell.prestige.sky_locked", locale), [
|
|
{"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"},
|
|
])
|
|
return
|
|
var r2 := apply_new_sky_for_test()
|
|
var detail2 := UiText.tf("shell.prestige.sky_gain", {"marks": int(r2.get("sky_marks", 0))}, locale)
|
|
_show_modal(UiText.t("shell.prestige.done", locale), UiText.tf("shell.prestige.done_body", {"detail": detail2}, locale), [
|
|
{"label": UiText.t("shell.prestige.do_sky", locale), "action": "map"},
|
|
])
|
|
"open_edict_shop":
|
|
_open_edict_shop()
|
|
"open_outsider_shop":
|
|
_open_outsider_shop()
|
|
"confirm_transcendence":
|
|
# CH transcend() gate at the action boundary, not only in the preview.
|
|
var tr_preview: Dictionary = Transcendence.preview(profile)
|
|
if not bool(tr_preview.get("can_transcend")):
|
|
_show_modal(UiText.t("shell.prestige.title", locale),
|
|
UiText.t("shell.prestige.transcend_locked", locale), [
|
|
{"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"},
|
|
])
|
|
return
|
|
var tr_result := apply_transcendence_for_test()
|
|
if bool(tr_result.get("ok")):
|
|
var detail3 := UiText.tf("shell.prestige.ancient_gain", {
|
|
"gain": int(tr_result.get("gain", 0)),
|
|
"tp": snappedf(float(Transcendence.book_from_profile(profile).transcendent_power()) * 100.0, 0.1),
|
|
}, locale)
|
|
_show_modal(UiText.t("shell.prestige.done", locale),
|
|
UiText.tf("shell.prestige.done_body", {"detail": detail3}, locale), [
|
|
{"label": UiText.t("shell.prestige.do_sky", locale), "action": "map"},
|
|
])
|
|
else:
|
|
_show_modal(UiText.t("shell.prestige.title", locale),
|
|
UiText.t("shell.prestige.transcend_locked", locale), [
|
|
{"label": UiText.t("shell.rebuild.cancel", locale), "action": "map"},
|
|
])
|
|
"world_settlement":
|
|
show_page(PAGE_WORLD)
|
|
_select_world_next_after_settlement()
|
|
"world":
|
|
show_page(PAGE_WORLD)
|
|
"side":
|
|
show_page(PAGE_SIDE)
|
|
"map":
|
|
if _battle_host != null:
|
|
_battle_host.visible = false
|
|
show_page(PAGE_MAP)
|
|
|
|
|
|
func _on_nav(page: String) -> void:
|
|
sfx.play("ui", "ui")
|
|
if page == "map" or page == "skyport" or page == "world" or page == "side" or page == "loadout":
|
|
show_page(page)
|
|
elif page == "company":
|
|
show_page(PAGE_GROWTH)
|
|
else:
|
|
show_page(PAGE_SETTINGS)
|
|
|
|
|
|
## Visual-only: move the active tab underline. Routing is owned by _on_nav;
|
|
## every show_page() call now keeps it in sync.
|
|
func _refresh_nav_tabs() -> void:
|
|
for page in _nav_buttons.keys():
|
|
var button: Button = _nav_buttons[page] as Button
|
|
if button == null:
|
|
continue
|
|
var shown_page := str(page)
|
|
if shown_page == "company":
|
|
shown_page = PAGE_GROWTH
|
|
elif shown_page == "archive":
|
|
shown_page = PAGE_SETTINGS
|
|
var active := shown_page == current_page
|
|
button.add_theme_stylebox_override("normal", UiTheme.tab_style(active))
|
|
button.add_theme_color_override(
|
|
"font_color", UiTheme.COLOR_TEXT if active else UiTheme.COLOR_TEXT_DIM)
|