Add gdlint and gdformat scripts
This commit is contained in:
@@ -2,6 +2,7 @@ extends Control
|
||||
|
||||
@onready var button: Button = $Button
|
||||
|
||||
|
||||
func _ready():
|
||||
button.pressed.connect(_on_button_pressed)
|
||||
DebugManager.debug_ui_toggled.connect(_on_debug_ui_toggled)
|
||||
@@ -10,8 +11,10 @@ func _ready():
|
||||
var current_state = DebugManager.is_debug_ui_visible()
|
||||
button.text = "Debug UI: " + ("ON" if current_state else "OFF")
|
||||
|
||||
|
||||
func _on_button_pressed():
|
||||
DebugManager.toggle_debug_ui()
|
||||
|
||||
|
||||
func _on_debug_ui_toggled(visible: bool):
|
||||
button.text = "Debug UI: " + ("ON" if visible else "OFF")
|
||||
button.text = "Debug UI: " + ("ON" if visible else "OFF")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends DebugMenuBase
|
||||
|
||||
|
||||
func _find_target_scene():
|
||||
# Fixed: Search more thoroughly for match3 scene
|
||||
if match3_scene:
|
||||
|
||||
@@ -4,10 +4,14 @@ extends Control
|
||||
@onready var regenerate_button: Button = $VBoxContainer/RegenerateButton
|
||||
@onready var gem_types_spinbox: SpinBox = $VBoxContainer/GemTypesContainer/GemTypesSpinBox
|
||||
@onready var gem_types_label: Label = $VBoxContainer/GemTypesContainer/GemTypesLabel
|
||||
@onready var grid_width_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthSpinBox
|
||||
@onready var grid_height_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightSpinBox
|
||||
@onready var grid_width_label: Label = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthLabel
|
||||
@onready var grid_height_label: Label = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightLabel
|
||||
@onready
|
||||
var grid_width_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthSpinBox
|
||||
@onready
|
||||
var grid_height_spinbox: SpinBox = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightSpinBox
|
||||
@onready
|
||||
var grid_width_label: Label = $VBoxContainer/GridSizeContainer/GridWidthContainer/GridWidthLabel
|
||||
@onready
|
||||
var grid_height_label: Label = $VBoxContainer/GridSizeContainer/GridHeightContainer/GridHeightLabel
|
||||
|
||||
@export var target_script_path: String = "res://scenes/game/gameplays/match3_gameplay.gd"
|
||||
@export var log_category: String = "DebugMenu"
|
||||
@@ -23,16 +27,18 @@ var search_timer: Timer
|
||||
var last_scene_search_time: float = 0.0
|
||||
const SCENE_SEARCH_COOLDOWN := 0.5 # Prevent excessive scene searching
|
||||
|
||||
func _exit_tree():
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if search_timer:
|
||||
search_timer.queue_free()
|
||||
|
||||
func _ready():
|
||||
|
||||
func _ready() -> void:
|
||||
DebugManager.log_debug("DebugMenuBase _ready() called", log_category)
|
||||
DebugManager.debug_toggled.connect(_on_debug_toggled)
|
||||
|
||||
# Initialize with current debug state
|
||||
var current_debug_state = DebugManager.is_debug_enabled()
|
||||
var current_debug_state: bool = DebugManager.is_debug_enabled()
|
||||
visible = current_debug_state
|
||||
|
||||
# Connect signals
|
||||
@@ -50,7 +56,8 @@ func _ready():
|
||||
# Start searching for target scene
|
||||
_find_target_scene()
|
||||
|
||||
func _initialize_spinboxes():
|
||||
|
||||
func _initialize_spinboxes() -> void:
|
||||
# Initialize gem types spinbox with safety limits
|
||||
gem_types_spinbox.min_value = MIN_TILE_TYPES
|
||||
gem_types_spinbox.max_value = MAX_TILE_TYPES
|
||||
@@ -68,40 +75,47 @@ func _initialize_spinboxes():
|
||||
grid_height_spinbox.step = 1
|
||||
grid_height_spinbox.value = 8 # Default value
|
||||
|
||||
func _setup_scene_finding():
|
||||
|
||||
func _setup_scene_finding() -> void:
|
||||
# Create timer for periodic scene search with longer intervals to reduce CPU usage
|
||||
search_timer = Timer.new()
|
||||
search_timer.wait_time = 0.5 # Reduced frequency from 0.1 to 0.5 seconds
|
||||
search_timer.timeout.connect(_find_target_scene)
|
||||
add_child(search_timer)
|
||||
|
||||
|
||||
# Virtual method - override in derived classes for specific finding logic
|
||||
func _find_target_scene():
|
||||
func _find_target_scene() -> void:
|
||||
DebugManager.log_error("_find_target_scene() not implemented in derived class", log_category)
|
||||
|
||||
|
||||
func _find_node_by_script(node: Node, script_path: String) -> Node:
|
||||
# Helper function to find node by its script path
|
||||
if not node:
|
||||
return null
|
||||
|
||||
if node.get_script():
|
||||
var node_script = node.get_script()
|
||||
var node_script: Script = node.get_script()
|
||||
if node_script.resource_path == script_path:
|
||||
return node
|
||||
|
||||
for child in node.get_children():
|
||||
var result = _find_node_by_script(child, script_path)
|
||||
var result: Node = _find_node_by_script(child, script_path)
|
||||
if result:
|
||||
return result
|
||||
|
||||
return null
|
||||
|
||||
func _update_ui_from_scene():
|
||||
|
||||
func _update_ui_from_scene() -> void:
|
||||
if not match3_scene:
|
||||
return
|
||||
|
||||
# Connect to grid state loaded signal if not already connected
|
||||
if match3_scene.has_signal("grid_state_loaded") and not match3_scene.grid_state_loaded.is_connected(_on_grid_state_loaded):
|
||||
if (
|
||||
match3_scene.has_signal("grid_state_loaded")
|
||||
and not match3_scene.grid_state_loaded.is_connected(_on_grid_state_loaded)
|
||||
):
|
||||
match3_scene.grid_state_loaded.connect(_on_grid_state_loaded)
|
||||
DebugManager.log_debug("Connected to grid_state_loaded signal", log_category)
|
||||
|
||||
@@ -112,14 +126,18 @@ func _update_ui_from_scene():
|
||||
|
||||
# Update grid size display
|
||||
if "GRID_SIZE" in match3_scene:
|
||||
var grid_size = match3_scene.GRID_SIZE
|
||||
var grid_size: Vector2i = match3_scene.GRID_SIZE
|
||||
grid_width_spinbox.value = grid_size.x
|
||||
grid_height_spinbox.value = grid_size.y
|
||||
grid_width_label.text = "Width: " + str(grid_size.x)
|
||||
grid_height_label.text = "Height: " + str(grid_size.y)
|
||||
|
||||
func _on_grid_state_loaded(grid_size: Vector2i, tile_types: int):
|
||||
DebugManager.log_debug("Grid state loaded signal received: size=%s, types=%d" % [grid_size, tile_types], log_category)
|
||||
|
||||
func _on_grid_state_loaded(grid_size: Vector2i, tile_types: int) -> void:
|
||||
DebugManager.log_debug(
|
||||
"Grid state loaded signal received: size=%s, types=%d" % [grid_size, tile_types],
|
||||
log_category
|
||||
)
|
||||
|
||||
# Update the UI with the actual loaded values
|
||||
gem_types_spinbox.value = tile_types
|
||||
@@ -130,16 +148,19 @@ func _on_grid_state_loaded(grid_size: Vector2i, tile_types: int):
|
||||
grid_width_label.text = "Width: " + str(grid_size.x)
|
||||
grid_height_label.text = "Height: " + str(grid_size.y)
|
||||
|
||||
func _stop_search_timer():
|
||||
|
||||
func _stop_search_timer() -> void:
|
||||
if search_timer and search_timer.timeout.is_connected(_find_target_scene):
|
||||
search_timer.stop()
|
||||
|
||||
func _start_search_timer():
|
||||
|
||||
func _start_search_timer() -> void:
|
||||
if search_timer and not search_timer.timeout.is_connected(_find_target_scene):
|
||||
search_timer.timeout.connect(_find_target_scene)
|
||||
search_timer.start()
|
||||
|
||||
func _on_debug_toggled(enabled: bool):
|
||||
|
||||
func _on_debug_toggled(enabled: bool) -> void:
|
||||
DebugManager.log_debug("Debug toggled to " + str(enabled), log_category)
|
||||
visible = enabled
|
||||
if enabled:
|
||||
@@ -150,13 +171,17 @@ func _on_debug_toggled(enabled: bool):
|
||||
# Force refresh the values in case they changed while debug was hidden
|
||||
_refresh_current_values()
|
||||
|
||||
func _refresh_current_values():
|
||||
|
||||
func _refresh_current_values() -> void:
|
||||
# Refresh UI with current values from the scene
|
||||
if match3_scene:
|
||||
DebugManager.log_debug("Refreshing debug menu values from current scene state", log_category)
|
||||
DebugManager.log_debug(
|
||||
"Refreshing debug menu values from current scene state", log_category
|
||||
)
|
||||
_update_ui_from_scene()
|
||||
|
||||
func _on_regenerate_pressed():
|
||||
|
||||
func _on_regenerate_pressed() -> void:
|
||||
if not match3_scene:
|
||||
_find_target_scene()
|
||||
|
||||
@@ -170,9 +195,10 @@ func _on_regenerate_pressed():
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have regenerate_grid method", log_category)
|
||||
|
||||
func _on_gem_types_changed(value: float):
|
||||
|
||||
func _on_gem_types_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -184,10 +210,16 @@ func _on_gem_types_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for gem types change", log_category)
|
||||
return
|
||||
|
||||
var new_value = int(value)
|
||||
var new_value: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_value < MIN_TILE_TYPES or new_value > MAX_TILE_TYPES:
|
||||
DebugManager.log_error("Invalid gem types value: %d (range: %d-%d)" % [new_value, MIN_TILE_TYPES, MAX_TILE_TYPES], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid gem types value: %d (range: %d-%d)"
|
||||
% [new_value, MIN_TILE_TYPES, MAX_TILE_TYPES]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
gem_types_spinbox.value = clamp(new_value, MIN_TILE_TYPES, MAX_TILE_TYPES)
|
||||
return
|
||||
@@ -203,9 +235,10 @@ func _on_gem_types_changed(value: float):
|
||||
match3_scene.TILE_TYPES = new_value
|
||||
gem_types_label.text = "Gem Types: " + str(new_value)
|
||||
|
||||
func _on_grid_width_changed(value: float):
|
||||
|
||||
func _on_grid_width_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -217,10 +250,16 @@ func _on_grid_width_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for grid width change", log_category)
|
||||
return
|
||||
|
||||
var new_width = int(value)
|
||||
var new_width: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_width < MIN_GRID_SIZE or new_width > MAX_GRID_SIZE:
|
||||
DebugManager.log_error("Invalid grid width value: %d (range: %d-%d)" % [new_width, MIN_GRID_SIZE, MAX_GRID_SIZE], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid grid width value: %d (range: %d-%d)"
|
||||
% [new_width, MIN_GRID_SIZE, MAX_GRID_SIZE]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_width_spinbox.value = clamp(new_width, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
return
|
||||
@@ -228,17 +267,20 @@ func _on_grid_width_changed(value: float):
|
||||
grid_width_label.text = "Width: " + str(new_width)
|
||||
|
||||
# Get current height
|
||||
var current_height = int(grid_height_spinbox.value)
|
||||
var current_height: int = int(grid_height_spinbox.value)
|
||||
|
||||
if match3_scene.has_method("set_grid_size"):
|
||||
DebugManager.log_debug("Setting grid size to " + str(new_width) + "x" + str(current_height), log_category)
|
||||
DebugManager.log_debug(
|
||||
"Setting grid size to " + str(new_width) + "x" + str(current_height), log_category
|
||||
)
|
||||
await match3_scene.set_grid_size(Vector2i(new_width, current_height))
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have set_grid_size method", log_category)
|
||||
|
||||
func _on_grid_height_changed(value: float):
|
||||
|
||||
func _on_grid_height_changed(value: float) -> void:
|
||||
# Rate limiting for scene searches
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var current_time: float = Time.get_ticks_msec() / 1000.0
|
||||
if current_time - last_scene_search_time < SCENE_SEARCH_COOLDOWN:
|
||||
return
|
||||
|
||||
@@ -250,10 +292,16 @@ func _on_grid_height_changed(value: float):
|
||||
DebugManager.log_error("Could not find target scene for grid height change", log_category)
|
||||
return
|
||||
|
||||
var new_height = int(value)
|
||||
var new_height: int = int(value)
|
||||
# Enhanced input validation with safety constants
|
||||
if new_height < MIN_GRID_SIZE or new_height > MAX_GRID_SIZE:
|
||||
DebugManager.log_error("Invalid grid height value: %d (range: %d-%d)" % [new_height, MIN_GRID_SIZE, MAX_GRID_SIZE], log_category)
|
||||
DebugManager.log_error(
|
||||
(
|
||||
"Invalid grid height value: %d (range: %d-%d)"
|
||||
% [new_height, MIN_GRID_SIZE, MAX_GRID_SIZE]
|
||||
),
|
||||
log_category
|
||||
)
|
||||
# Reset to valid value
|
||||
grid_height_spinbox.value = clamp(new_height, MIN_GRID_SIZE, MAX_GRID_SIZE)
|
||||
return
|
||||
@@ -261,10 +309,12 @@ func _on_grid_height_changed(value: float):
|
||||
grid_height_label.text = "Height: " + str(new_height)
|
||||
|
||||
# Get current width
|
||||
var current_width = int(grid_width_spinbox.value)
|
||||
var current_width: int = int(grid_width_spinbox.value)
|
||||
|
||||
if match3_scene.has_method("set_grid_size"):
|
||||
DebugManager.log_debug("Setting grid size to " + str(current_width) + "x" + str(new_height), log_category)
|
||||
DebugManager.log_debug(
|
||||
"Setting grid size to " + str(current_width) + "x" + str(new_height), log_category
|
||||
)
|
||||
await match3_scene.set_grid_size(Vector2i(current_width, new_height))
|
||||
else:
|
||||
DebugManager.log_error("Target scene does not have set_grid_size method", log_category)
|
||||
DebugManager.log_error("Target scene does not have set_grid_size method", log_category)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Button
|
||||
|
||||
|
||||
func _ready():
|
||||
pressed.connect(_on_pressed)
|
||||
DebugManager.debug_toggled.connect(_on_debug_toggled)
|
||||
@@ -8,8 +9,10 @@ func _ready():
|
||||
var current_state = DebugManager.is_debug_enabled()
|
||||
text = "Debug: " + ("ON" if current_state else "OFF")
|
||||
|
||||
|
||||
func _on_pressed():
|
||||
DebugManager.toggle_debug()
|
||||
|
||||
|
||||
func _on_debug_toggled(enabled: bool):
|
||||
text = "Debug: " + ("ON" if enabled else "OFF")
|
||||
|
||||
@@ -6,14 +6,16 @@ signal open_settings
|
||||
var current_menu_index: int = 0
|
||||
var original_button_scales: Array[Vector2] = []
|
||||
|
||||
func _ready():
|
||||
|
||||
func _ready() -> void:
|
||||
DebugManager.log_info("MainMenu ready", "MainMenu")
|
||||
_setup_menu_navigation()
|
||||
_update_new_game_button()
|
||||
|
||||
func _on_new_game_button_pressed():
|
||||
|
||||
func _on_new_game_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
var button_text = $MenuContainer/NewGameButton.text
|
||||
var button_text: String = $MenuContainer/NewGameButton.text
|
||||
if button_text == "Continue":
|
||||
DebugManager.log_info("Continue pressed", "MainMenu")
|
||||
GameManager.continue_game()
|
||||
@@ -21,17 +23,20 @@ func _on_new_game_button_pressed():
|
||||
DebugManager.log_info("New Game pressed", "MainMenu")
|
||||
GameManager.start_new_game()
|
||||
|
||||
func _on_settings_button_pressed():
|
||||
|
||||
func _on_settings_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Settings pressed", "MainMenu")
|
||||
open_settings.emit()
|
||||
|
||||
func _on_exit_button_pressed():
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Exit pressed", "MainMenu")
|
||||
get_tree().quit()
|
||||
|
||||
func _setup_menu_navigation():
|
||||
|
||||
func _setup_menu_navigation() -> void:
|
||||
menu_buttons.clear()
|
||||
original_button_scales.clear()
|
||||
|
||||
@@ -44,6 +49,7 @@ func _setup_menu_navigation():
|
||||
|
||||
_update_visual_selection()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("move_up"):
|
||||
_navigate_menu(-1)
|
||||
@@ -60,7 +66,8 @@ func _input(event: InputEvent) -> void:
|
||||
DebugManager.log_info("Quit game shortcut pressed", "MainMenu")
|
||||
get_tree().quit()
|
||||
|
||||
func _navigate_menu(direction: int):
|
||||
|
||||
func _navigate_menu(direction: int) -> void:
|
||||
AudioManager.play_ui_click()
|
||||
current_menu_index = (current_menu_index + direction) % menu_buttons.size()
|
||||
if current_menu_index < 0:
|
||||
@@ -68,15 +75,17 @@ func _navigate_menu(direction: int):
|
||||
_update_visual_selection()
|
||||
DebugManager.log_info("Menu navigation: index " + str(current_menu_index), "MainMenu")
|
||||
|
||||
func _activate_current_button():
|
||||
|
||||
func _activate_current_button() -> void:
|
||||
if current_menu_index >= 0 and current_menu_index < menu_buttons.size():
|
||||
var button = menu_buttons[current_menu_index]
|
||||
var button: Button = menu_buttons[current_menu_index]
|
||||
DebugManager.log_info("Activating button via keyboard/gamepad: " + button.text, "MainMenu")
|
||||
button.pressed.emit()
|
||||
|
||||
func _update_visual_selection():
|
||||
|
||||
func _update_visual_selection() -> void:
|
||||
for i in range(menu_buttons.size()):
|
||||
var button = menu_buttons[i]
|
||||
var button: Button = menu_buttons[i]
|
||||
if i == current_menu_index:
|
||||
button.scale = original_button_scales[i] * 1.1
|
||||
button.modulate = Color(1.2, 1.2, 1.0)
|
||||
@@ -84,16 +93,23 @@ func _update_visual_selection():
|
||||
button.scale = original_button_scales[i]
|
||||
button.modulate = Color.WHITE
|
||||
|
||||
func _update_new_game_button():
|
||||
# Check if there's an existing save with progress
|
||||
var current_score = SaveManager.get_current_score()
|
||||
var games_played = SaveManager.get_games_played()
|
||||
var has_saved_grid = SaveManager.has_saved_grid()
|
||||
|
||||
var new_game_button = $MenuContainer/NewGameButton
|
||||
func _update_new_game_button() -> void:
|
||||
# Check if there's an existing save with progress
|
||||
var current_score: int = SaveManager.get_current_score()
|
||||
var games_played: int = SaveManager.get_games_played()
|
||||
var has_saved_grid: bool = SaveManager.has_saved_grid()
|
||||
|
||||
var new_game_button: Button = $MenuContainer/NewGameButton
|
||||
if current_score > 0 or games_played > 0 or has_saved_grid:
|
||||
new_game_button.text = "Continue"
|
||||
DebugManager.log_info("Updated button to Continue (score: %d, games: %d, grid: %s)" % [current_score, games_played, has_saved_grid], "MainMenu")
|
||||
DebugManager.log_info(
|
||||
(
|
||||
"Updated button to Continue (score: %d, games: %d, grid: %s)"
|
||||
% [current_score, games_played, has_saved_grid]
|
||||
),
|
||||
"MainMenu"
|
||||
)
|
||||
else:
|
||||
new_game_button.text = "New Game"
|
||||
DebugManager.log_info("Updated button to New Game", "MainMenu")
|
||||
|
||||
@@ -14,27 +14,27 @@ signal back_to_main_menu
|
||||
# Progress reset confirmation dialog
|
||||
var confirmation_dialog: AcceptDialog
|
||||
|
||||
|
||||
# Navigation system variables
|
||||
var navigable_controls: Array[Control] = []
|
||||
var current_control_index: int = 0
|
||||
var original_control_scales: Array[Vector2] = []
|
||||
var original_control_modulates: Array[Color] = []
|
||||
|
||||
func _ready():
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("localizable")
|
||||
DebugManager.log_info("SettingsMenu ready", "Settings")
|
||||
# Language selector is initialized automatically
|
||||
|
||||
var master_callback = _on_volume_slider_changed.bind("master_volume")
|
||||
var master_callback: Callable = _on_volume_slider_changed.bind("master_volume")
|
||||
if not master_slider.value_changed.is_connected(master_callback):
|
||||
master_slider.value_changed.connect(master_callback)
|
||||
|
||||
var music_callback = _on_volume_slider_changed.bind("music_volume")
|
||||
var music_callback: Callable = _on_volume_slider_changed.bind("music_volume")
|
||||
if not music_slider.value_changed.is_connected(music_callback):
|
||||
music_slider.value_changed.connect(music_callback)
|
||||
|
||||
var sfx_callback = _on_volume_slider_changed.bind("sfx_volume")
|
||||
var sfx_callback: Callable = _on_volume_slider_changed.bind("sfx_volume")
|
||||
if not sfx_slider.value_changed.is_connected(sfx_callback):
|
||||
sfx_slider.value_changed.connect(sfx_callback)
|
||||
|
||||
@@ -45,37 +45,41 @@ func _ready():
|
||||
_setup_navigation_system()
|
||||
_setup_confirmation_dialog()
|
||||
|
||||
func _update_controls_from_settings():
|
||||
|
||||
func _update_controls_from_settings() -> void:
|
||||
master_slider.value = settings_manager.get_setting("master_volume")
|
||||
music_slider.value = settings_manager.get_setting("music_volume")
|
||||
sfx_slider.value = settings_manager.get_setting("sfx_volume")
|
||||
|
||||
# Language display is handled by the ValueStepper component
|
||||
|
||||
func _on_volume_slider_changed(value, setting_key):
|
||||
|
||||
func _on_volume_slider_changed(value: float, setting_key: String) -> void:
|
||||
# Input validation for volume settings
|
||||
if not setting_key in ["master_volume", "music_volume", "sfx_volume"]:
|
||||
DebugManager.log_error("Invalid volume setting key: " + str(setting_key), "Settings")
|
||||
return
|
||||
|
||||
if not (value is float or value is int):
|
||||
if typeof(value) != TYPE_FLOAT and typeof(value) != TYPE_INT:
|
||||
DebugManager.log_error("Invalid volume value type: " + str(typeof(value)), "Settings")
|
||||
return
|
||||
|
||||
# Clamp value to valid range
|
||||
var clamped_value = clamp(float(value), 0.0, 1.0)
|
||||
var clamped_value: float = clamp(float(value), 0.0, 1.0)
|
||||
if clamped_value != value:
|
||||
DebugManager.log_warn("Volume value %f clamped to %f" % [value, clamped_value], "Settings")
|
||||
|
||||
if not settings_manager.set_setting(setting_key, clamped_value):
|
||||
DebugManager.log_error("Failed to set volume setting: " + setting_key, "Settings")
|
||||
|
||||
func _exit_settings():
|
||||
|
||||
func _exit_settings() -> void:
|
||||
DebugManager.log_info("Exiting settings", "Settings")
|
||||
settings_manager.save_settings()
|
||||
back_to_main_menu.emit()
|
||||
|
||||
func _input(event):
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("action_east") or event.is_action_pressed("pause_menu"):
|
||||
DebugManager.log_debug("Cancel/back action pressed in settings", "Settings")
|
||||
_exit_settings()
|
||||
@@ -103,14 +107,14 @@ func _input(event):
|
||||
_activate_current_control()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _on_back_button_pressed():
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Back button pressed", "Settings")
|
||||
_exit_settings()
|
||||
|
||||
|
||||
|
||||
func update_text():
|
||||
func update_text() -> void:
|
||||
$SettingsContainer/SettingsTitle.text = tr("settings_title")
|
||||
$SettingsContainer/MasterVolumeContainer/MasterVolume.text = tr("master_volume")
|
||||
$SettingsContainer/MusicVolumeContainer/MusicVolume.text = tr("music_volume")
|
||||
@@ -127,7 +131,8 @@ func _on_reset_setting_button_pressed() -> void:
|
||||
_update_controls_from_settings()
|
||||
localization_manager.change_language(settings_manager.get_setting("language"))
|
||||
|
||||
func _setup_navigation_system():
|
||||
|
||||
func _setup_navigation_system() -> void:
|
||||
navigable_controls.clear()
|
||||
original_control_scales.clear()
|
||||
original_control_modulates.clear()
|
||||
@@ -148,7 +153,8 @@ func _setup_navigation_system():
|
||||
|
||||
_update_visual_selection()
|
||||
|
||||
func _navigate_controls(direction: int):
|
||||
|
||||
func _navigate_controls(direction: int) -> void:
|
||||
AudioManager.play_ui_click()
|
||||
current_control_index = (current_control_index + direction) % navigable_controls.size()
|
||||
if current_control_index < 0:
|
||||
@@ -156,32 +162,36 @@ func _navigate_controls(direction: int):
|
||||
_update_visual_selection()
|
||||
DebugManager.log_info("Settings navigation: index " + str(current_control_index), "Settings")
|
||||
|
||||
func _adjust_current_control(direction: int):
|
||||
|
||||
func _adjust_current_control(direction: int) -> void:
|
||||
if current_control_index < 0 or current_control_index >= navigable_controls.size():
|
||||
return
|
||||
|
||||
var control = navigable_controls[current_control_index]
|
||||
var control: Control = navigable_controls[current_control_index]
|
||||
|
||||
# Handle sliders
|
||||
if control is HSlider:
|
||||
var slider = control as HSlider
|
||||
var step = slider.step if slider.step > 0 else 0.1
|
||||
var new_value = slider.value + (direction * step)
|
||||
var slider: HSlider = control as HSlider
|
||||
var step: float = slider.step if slider.step > 0 else 0.1
|
||||
var new_value: float = slider.value + (direction * step)
|
||||
new_value = clamp(new_value, slider.min_value, slider.max_value)
|
||||
slider.value = new_value
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Slider adjusted: %s = %f" % [_get_control_name(control), new_value], "Settings")
|
||||
DebugManager.log_info(
|
||||
"Slider adjusted: %s = %f" % [_get_control_name(control), new_value], "Settings"
|
||||
)
|
||||
|
||||
# Handle language stepper with left/right
|
||||
elif control == language_stepper:
|
||||
if language_stepper.handle_input_action("move_left" if direction == -1 else "move_right"):
|
||||
AudioManager.play_ui_click()
|
||||
|
||||
func _activate_current_control():
|
||||
|
||||
func _activate_current_control() -> void:
|
||||
if current_control_index < 0 or current_control_index >= navigable_controls.size():
|
||||
return
|
||||
|
||||
var control = navigable_controls[current_control_index]
|
||||
var control: Control = navigable_controls[current_control_index]
|
||||
|
||||
# Handle buttons
|
||||
if control is Button:
|
||||
@@ -193,7 +203,8 @@ func _activate_current_control():
|
||||
elif control == language_stepper:
|
||||
DebugManager.log_info("Language stepper selected - use left/right to change", "Settings")
|
||||
|
||||
func _update_visual_selection():
|
||||
|
||||
func _update_visual_selection() -> void:
|
||||
for i in range(navigable_controls.size()):
|
||||
var control = navigable_controls[i]
|
||||
if i == current_control_index:
|
||||
@@ -211,6 +222,7 @@ func _update_visual_selection():
|
||||
control.scale = original_control_scales[i]
|
||||
control.modulate = original_control_modulates[i]
|
||||
|
||||
|
||||
func _get_control_name(control: Control) -> String:
|
||||
if control == master_slider:
|
||||
return "master_volume"
|
||||
@@ -223,10 +235,15 @@ func _get_control_name(control: Control) -> String:
|
||||
else:
|
||||
return "button"
|
||||
|
||||
func _on_language_stepper_value_changed(new_value: String, new_index: int):
|
||||
DebugManager.log_info("Language changed via ValueStepper: " + new_value + " (index: " + str(new_index) + ")", "Settings")
|
||||
|
||||
func _setup_confirmation_dialog():
|
||||
func _on_language_stepper_value_changed(new_value: String, new_index: float) -> void:
|
||||
DebugManager.log_info(
|
||||
"Language changed via ValueStepper: " + new_value + " (index: " + str(int(new_index)) + ")",
|
||||
"Settings"
|
||||
)
|
||||
|
||||
|
||||
func _setup_confirmation_dialog() -> void:
|
||||
"""Create confirmation dialog for progress reset"""
|
||||
confirmation_dialog = AcceptDialog.new()
|
||||
confirmation_dialog.title = tr("confirm_reset_title")
|
||||
@@ -244,7 +261,8 @@ func _setup_confirmation_dialog():
|
||||
|
||||
add_child(confirmation_dialog)
|
||||
|
||||
func _on_reset_progress_button_pressed():
|
||||
|
||||
func _on_reset_progress_button_pressed() -> void:
|
||||
"""Handle reset progress button press with confirmation"""
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Reset progress button pressed", "Settings")
|
||||
@@ -257,7 +275,8 @@ func _on_reset_progress_button_pressed():
|
||||
# Show confirmation dialog
|
||||
confirmation_dialog.popup_centered()
|
||||
|
||||
func _on_reset_progress_confirmed():
|
||||
|
||||
func _on_reset_progress_confirmed() -> void:
|
||||
"""Actually reset the progress after confirmation"""
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Progress reset confirmed by user", "Settings")
|
||||
@@ -267,7 +286,7 @@ func _on_reset_progress_confirmed():
|
||||
DebugManager.log_info("All progress successfully reset", "Settings")
|
||||
|
||||
# Show success message
|
||||
var success_dialog = AcceptDialog.new()
|
||||
var success_dialog: AcceptDialog = AcceptDialog.new()
|
||||
success_dialog.title = tr("reset_success_title")
|
||||
success_dialog.dialog_text = tr("reset_success_message")
|
||||
success_dialog.ok_button_text = tr("ok")
|
||||
@@ -283,7 +302,7 @@ func _on_reset_progress_confirmed():
|
||||
DebugManager.log_error("Failed to reset progress", "Settings")
|
||||
|
||||
# Show error message
|
||||
var error_dialog = AcceptDialog.new()
|
||||
var error_dialog: AcceptDialog = AcceptDialog.new()
|
||||
error_dialog.title = tr("reset_error_title")
|
||||
error_dialog.dialog_text = tr("reset_error_message")
|
||||
error_dialog.ok_button_text = tr("ok")
|
||||
@@ -291,7 +310,8 @@ func _on_reset_progress_confirmed():
|
||||
error_dialog.popup_centered()
|
||||
error_dialog.confirmed.connect(func(): error_dialog.queue_free())
|
||||
|
||||
func _on_reset_progress_canceled():
|
||||
|
||||
func _on_reset_progress_canceled() -> void:
|
||||
"""Handle reset progress cancellation"""
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Progress reset canceled by user", "Settings")
|
||||
|
||||
@@ -29,7 +29,8 @@ var original_scale: Vector2
|
||||
var original_modulate: Color
|
||||
var is_highlighted: bool = false
|
||||
|
||||
func _ready():
|
||||
|
||||
func _ready() -> void:
|
||||
DebugManager.log_info("ValueStepper ready for: " + data_source, "ValueStepper")
|
||||
|
||||
# Store original visual properties
|
||||
@@ -47,8 +48,9 @@ func _ready():
|
||||
_load_data()
|
||||
_update_display()
|
||||
|
||||
|
||||
## Loads data based on the data_source type
|
||||
func _load_data():
|
||||
func _load_data() -> void:
|
||||
match data_source:
|
||||
"language":
|
||||
_load_language_data()
|
||||
@@ -59,8 +61,9 @@ func _load_data():
|
||||
_:
|
||||
DebugManager.log_warn("Unknown data_source: " + data_source, "ValueStepper")
|
||||
|
||||
func _load_language_data():
|
||||
var languages_data = SettingsManager.get_languages_data()
|
||||
|
||||
func _load_language_data() -> void:
|
||||
var languages_data: Dictionary = SettingsManager.get_languages_data()
|
||||
if languages_data.has("languages"):
|
||||
values.clear()
|
||||
display_names.clear()
|
||||
@@ -69,28 +72,31 @@ func _load_language_data():
|
||||
display_names.append(languages_data.languages[lang_code]["display_name"])
|
||||
|
||||
# Set current index based on current language
|
||||
var current_lang = SettingsManager.get_setting("language")
|
||||
var index = values.find(current_lang)
|
||||
var current_lang: String = SettingsManager.get_setting("language")
|
||||
var index: int = values.find(current_lang)
|
||||
current_index = max(0, index)
|
||||
|
||||
DebugManager.log_info("Loaded %d languages" % values.size(), "ValueStepper")
|
||||
|
||||
func _load_resolution_data():
|
||||
|
||||
func _load_resolution_data() -> void:
|
||||
# Example resolution data - customize as needed
|
||||
values = ["1920x1080", "1366x768", "1280x720", "1024x768"]
|
||||
display_names = ["1920×1080 (Full HD)", "1366×768", "1280×720 (HD)", "1024×768"]
|
||||
current_index = 0
|
||||
DebugManager.log_info("Loaded %d resolutions" % values.size(), "ValueStepper")
|
||||
|
||||
func _load_difficulty_data():
|
||||
|
||||
func _load_difficulty_data() -> void:
|
||||
# Example difficulty data - customize as needed
|
||||
values = ["easy", "normal", "hard", "nightmare"]
|
||||
display_names = ["Easy", "Normal", "Hard", "Nightmare"]
|
||||
current_index = 1 # Default to "normal"
|
||||
DebugManager.log_info("Loaded %d difficulty levels" % values.size(), "ValueStepper")
|
||||
|
||||
|
||||
## Updates the display text based on current selection
|
||||
func _update_display():
|
||||
func _update_display() -> void:
|
||||
if values.size() == 0 or current_index < 0 or current_index >= values.size():
|
||||
value_display.text = "N/A"
|
||||
return
|
||||
@@ -100,26 +106,30 @@ func _update_display():
|
||||
else:
|
||||
value_display.text = values[current_index]
|
||||
|
||||
|
||||
## Changes the current value by the specified direction (-1 for previous, +1 for next)
|
||||
func change_value(direction: int):
|
||||
func change_value(direction: int) -> void:
|
||||
if values.size() == 0:
|
||||
DebugManager.log_warn("No values available for: " + data_source, "ValueStepper")
|
||||
return
|
||||
|
||||
var new_index = (current_index + direction) % values.size()
|
||||
var new_index: int = (current_index + direction) % values.size()
|
||||
if new_index < 0:
|
||||
new_index = values.size() - 1
|
||||
|
||||
current_index = new_index
|
||||
var new_value = values[current_index]
|
||||
var new_value: String = values[current_index]
|
||||
|
||||
_update_display()
|
||||
_apply_value_change(new_value, current_index)
|
||||
value_changed.emit(new_value, current_index)
|
||||
DebugManager.log_info("Value changed to: " + new_value + " (index: " + str(current_index) + ")", "ValueStepper")
|
||||
DebugManager.log_info(
|
||||
"Value changed to: " + new_value + " (index: " + str(current_index) + ")", "ValueStepper"
|
||||
)
|
||||
|
||||
|
||||
## Override this method for custom value application logic
|
||||
func _apply_value_change(new_value: String, _index: int):
|
||||
func _apply_value_change(new_value: String, _index: int) -> void:
|
||||
match data_source:
|
||||
"language":
|
||||
SettingsManager.set_setting("language", new_value)
|
||||
@@ -132,29 +142,37 @@ func _apply_value_change(new_value: String, _index: int):
|
||||
# Apply difficulty change logic here
|
||||
DebugManager.log_info("Difficulty would change to: " + new_value, "ValueStepper")
|
||||
|
||||
|
||||
## Sets up custom values for the stepper
|
||||
func setup_custom_values(custom_values: Array[String], custom_display_names: Array[String] = []):
|
||||
func setup_custom_values(
|
||||
custom_values: Array[String], custom_display_names: Array[String] = []
|
||||
) -> void:
|
||||
values = custom_values.duplicate()
|
||||
display_names = custom_display_names.duplicate() if custom_display_names.size() > 0 else values.duplicate()
|
||||
display_names = (
|
||||
custom_display_names.duplicate() if custom_display_names.size() > 0 else values.duplicate()
|
||||
)
|
||||
current_index = 0
|
||||
_update_display()
|
||||
DebugManager.log_info("Setup custom values: " + str(values.size()) + " items", "ValueStepper")
|
||||
|
||||
|
||||
## Gets the current value
|
||||
func get_current_value() -> String:
|
||||
if values.size() > 0 and current_index >= 0 and current_index < values.size():
|
||||
return values[current_index]
|
||||
return ""
|
||||
|
||||
|
||||
## Sets the current value by string
|
||||
func set_current_value(value: String):
|
||||
var index = values.find(value)
|
||||
func set_current_value(value: String) -> void:
|
||||
var index: int = values.find(value)
|
||||
if index >= 0:
|
||||
current_index = index
|
||||
_update_display()
|
||||
|
||||
|
||||
## Visual highlighting for navigation systems
|
||||
func set_highlighted(highlighted: bool):
|
||||
func set_highlighted(highlighted: bool) -> void:
|
||||
is_highlighted = highlighted
|
||||
if highlighted:
|
||||
scale = original_scale * 1.05
|
||||
@@ -163,6 +181,7 @@ func set_highlighted(highlighted: bool):
|
||||
scale = original_scale
|
||||
modulate = original_modulate
|
||||
|
||||
|
||||
## Handle input actions for navigation integration
|
||||
func handle_input_action(action: String) -> bool:
|
||||
match action:
|
||||
@@ -175,16 +194,19 @@ func handle_input_action(action: String) -> bool:
|
||||
_:
|
||||
return false
|
||||
|
||||
func _on_left_button_pressed():
|
||||
|
||||
func _on_left_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Left button clicked", "ValueStepper")
|
||||
change_value(-1)
|
||||
|
||||
func _on_right_button_pressed():
|
||||
|
||||
func _on_right_button_pressed() -> void:
|
||||
AudioManager.play_ui_click()
|
||||
DebugManager.log_info("Right button clicked", "ValueStepper")
|
||||
change_value(1)
|
||||
|
||||
|
||||
## For navigation system integration
|
||||
func get_control_name() -> String:
|
||||
return data_source + "_stepper"
|
||||
|
||||
Reference in New Issue
Block a user