extends Control signal mode_changed(mode_index: int) signal resolution_changed(resolution: Vector2i) @export var window_option_menu_button_scene: PackedScene var current_mode_index: int = 0 var current_resolution: Vector2i = Vector2i.ZERO var available_resolutions: Array[Vector2i] = [ Vector2i(1280, 720), Vector2i(1366, 768), Vector2i(1600, 900), Vector2i(1920, 1080), Vector2i(2560, 1440), Vector2i(3840, 2160) ] var _valid_resolutions: Array[Vector2i] = [] @onready var left_arrow = $%LeftArrowButton @onready var right_arrow = $%RightArrowButton @onready var buttons = [ $%FullScreenButton, $%BorderlessButton, $%WindowedButton ] @onready var base = $%Base @onready var resolutions_list = $%ResolutionsList func _ready() -> void: left_arrow.pressed.connect(_on_left_arrow_pressed) right_arrow.pressed.connect(_on_right_arrow_pressed) _populate_resolutions() _update_ui() func initialize(mode_index: int, res: Vector2i) -> void: current_mode_index = mode_index current_resolution = res _update_ui() func _populate_resolutions() -> void: var screen_size = DisplayServer.screen_get_size() for child in resolutions_list.get_children(): child.queue_free() _valid_resolutions.clear() for res in available_resolutions: if res.x <= screen_size.x and res.y <= screen_size.y: _valid_resolutions.append(res) var btn = window_option_menu_button_scene.instantiate() btn.set_option_text(str(res.x) + " x " + str(res.y)) btn.alignment = HORIZONTAL_ALIGNMENT_CENTER btn.pressed.connect(func(): _on_resolution_selected(res, btn)) resolutions_list.add_child(btn) func _on_resolution_selected(res: Vector2i, btn) -> void: var res_buttons = resolutions_list.get_children() for button in res_buttons: button.deselect() btn.select() current_resolution = res resolution_changed.emit(res) func _on_left_arrow_pressed() -> void: current_mode_index -= 1 if current_mode_index < 0: current_mode_index = buttons.size() - 1 _update_ui() mode_changed.emit(current_mode_index) func _on_right_arrow_pressed() -> void: current_mode_index += 1 if current_mode_index >= buttons.size(): current_mode_index = 0 _update_ui() mode_changed.emit(current_mode_index) func _update_ui() -> void: for i in range(buttons.size()): buttons[i].visible = (i == current_mode_index) var show_res = current_mode_index == 2 var color = Color(1,1,1,1) if show_res else Color(0.2, 0.2 ,0.2, 1) base.modulate = color var res_buttons = resolutions_list.get_children() for button in res_buttons: button.deselect() if show_res: button.enable() else: button.disable() if res_buttons.size() > 0: var target_index = 0 for idx in range(_valid_resolutions.size()): if _valid_resolutions[idx] == current_resolution: target_index = idx break var btn = res_buttons[target_index] btn.select() current_resolution = _valid_resolutions[target_index] if show_res: resolution_changed.emit(current_resolution)