extends Control const SLOT_SCENE := preload("res://scenes/ccs_cases_2/slot_machine.tscn") const DOCTOR_SCENE := preload("res://scenes/ccs_cases_2/doctor_office.tscn") const DESIGN_SIZE := Vector2(1500.0, 800.0) var stage_root: Control var active_scene: Control var current_view := "" func _ready() -> void: set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) clip_contents = true stage_root = Control.new() stage_root.name = "GraphicalCcsStage" stage_root.size = DESIGN_SIZE add_child(stage_root) resized.connect(_fit_stage) _fit_stage() func on_show(_payload: Variant = null) -> void: _show_slot_machine() func on_hide() -> void: _clear_active_scene() func _show_slot_machine() -> void: _set_active_scene(SLOT_SCENE.instantiate(), "slot_machine") if active_scene.has_signal("continue_requested"): active_scene.continue_requested.connect(_show_doctor_office) func _show_doctor_office() -> void: _set_active_scene(DOCTOR_SCENE.instantiate(), "doctor_office") func _set_active_scene(scene: Control, view_name: String) -> void: _clear_active_scene() active_scene = scene current_view = view_name stage_root.add_child(active_scene) active_scene.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) func _clear_active_scene() -> void: if active_scene != null and is_instance_valid(active_scene): if active_scene.get_parent() != null: active_scene.get_parent().remove_child(active_scene) active_scene.queue_free() active_scene = null current_view = "" func _fit_stage() -> void: if stage_root == null: return var available := size if available.x <= 0.0 or available.y <= 0.0: return var fit_scale := minf(available.x / DESIGN_SIZE.x, available.y / DESIGN_SIZE.y) stage_root.scale = Vector2.ONE * fit_scale stage_root.position = (available - DESIGN_SIZE * fit_scale) * 0.5