329 lines
12 KiB
GDScript
329 lines
12 KiB
GDScript
extends CanvasLayer
|
|
|
|
#@onready var name_label = $Control/Panel/Name#$Control/HBoxContainer/LeftPanel/CharacterInfo/NameLabel
|
|
#@onready var level_label = $Control/Panel/Level#$Control/HBoxContainer/LeftPanel/CharacterInfo/LevelLabel
|
|
#@onready var xp_bar = $Control/Panel/ProgressBar#$Control/HBoxContainer/LeftPanel/CharacterInfo/XPBar
|
|
#@onready var gold_label = $Control/Panel/Label#$Control/HBoxContainer/LeftPanel/CharacterInfo/GoldLabel
|
|
#
|
|
#@onready var str_value = $Control/Panel/HBoxContainer/StrFrame/DisplayCurrentStr/currentStrLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/StrValue
|
|
#@onready var int_value = $Control/Panel/HBoxContainer/IntFrame/DisplayCurrentInt/currentIntLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/IntValue
|
|
#@onready var wis_value = $Control/Panel/HBoxContainer/WisFrame/DisplayCurrentWis/currentWisLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/WisValue
|
|
#@onready var end_value = $Control/Panel/HBoxContainer/EndFrame/DisplayCurrentEnd/currentStrLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/EndValue
|
|
#@onready var dex_value = $Control/Panel/HBoxContainer/DexFrame/DisplayCurrentDex/currentDexLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/DexValue
|
|
#@onready var points_label = $Control/Panel/HBoxContainer/RemainingPoints/DisplayCurrentRP/currentRPLabel#$Control/HBoxContainer/LeftPanel/StatsPanel/PointsRemaining
|
|
|
|
@onready var enter_btn = $Control/HBoxContainer/RightPanel/EnterDungeonBtn
|
|
@onready var browse_btn = $Control/HBoxContainer/RightPanel/BrowseDungeonsBtn
|
|
@onready var dungeon_browser = $DungeonBrowser
|
|
|
|
@onready var inventory_btn = $Control/InventoryBtn#$Control/HBoxContainer/LeftPanel/MenuButtons/InventoryBtn
|
|
@onready var crafting_btn = $Control/CraftingBtn#$Control/HBoxContainer/LeftPanel/MenuButtons/CraftingBtn
|
|
@onready var stash_btn = $Control/StashBtn#$Control/HBoxContainer/LeftPanel/MenuButtons/StashBtn
|
|
@onready var inventory_ui = $InventoryUI
|
|
@onready var crafting_ui = $CraftingUI
|
|
@onready var stash_ui = $StashUI
|
|
@onready var char_sheet_ui = $CharSheetUI
|
|
@onready var char_sheet_btn = $Control/CharSheetBtn
|
|
|
|
# Settings panel
|
|
var settings_panel: Panel = null
|
|
var settings_btn: TextureButton = null
|
|
var mobile_controls_toggle: CheckBox = null
|
|
var logout_btn: Button = null
|
|
|
|
var selected_tier: int = 1
|
|
|
|
func _ready():
|
|
_create_settings_panel()
|
|
enter_btn.pressed.connect(_on_enter_dungeon)
|
|
|
|
# Connect to UpdateManager to refresh settings icon when downloaded
|
|
if UpdateManager:
|
|
UpdateManager.file_downloaded.connect(_on_settings_file_downloaded)
|
|
UpdateManager.update_completed.connect(_on_update_completed)
|
|
|
|
# Setup browse button if it exists
|
|
if browse_btn:
|
|
browse_btn.pressed.connect(_on_browse_dungeons)
|
|
|
|
# Setup inventory, crafting, and stash buttons
|
|
if inventory_btn:
|
|
inventory_btn.pressed.connect(_on_inventory_pressed)
|
|
if crafting_btn:
|
|
crafting_btn.pressed.connect(_on_crafting_pressed)
|
|
if stash_btn:
|
|
stash_btn.pressed.connect(_on_stash_pressed)
|
|
if char_sheet_btn:
|
|
char_sheet_btn.pressed.connect(_toggle_char_sheet)
|
|
|
|
|
|
# Setup tier buttons
|
|
for i in range(1, 6):
|
|
var btn_path = "Control/HBoxContainer/RightPanel/TierSelection/Tier%dBtn" % i
|
|
if has_node(btn_path):
|
|
var btn = get_node(btn_path)
|
|
btn.pressed.connect(_on_tier_selected.bind(i))
|
|
|
|
|
|
# Defer GameState connection
|
|
call_deferred("_connect_gamestate")
|
|
|
|
func _process(delta: float) -> void:
|
|
_handle_input()
|
|
|
|
func _handle_input():
|
|
if Input.is_action_just_pressed("charSheet") and GameState.current_state != GameState.STATE_AUTH:
|
|
_toggle_char_sheet()
|
|
#if Input.is_action_just_pressed("inventory"):
|
|
#_toggle_inventory()
|
|
|
|
func _connect_gamestate():
|
|
#if GameState:
|
|
#GameState.character_updated.connect(_update_ui)
|
|
if GameState:
|
|
GameState.state_changed.connect(_on_state_changed)
|
|
if Network:
|
|
Network.connected.connect(_request_inventory_if_ready)
|
|
_request_inventory_if_ready()
|
|
|
|
func _on_state_changed(_state: String):
|
|
_request_inventory_if_ready()
|
|
|
|
func _request_inventory_if_ready():
|
|
if not GameState or not Network:
|
|
return
|
|
if GameState.current_state != GameState.STATE_HUB:
|
|
return
|
|
if not Network.is_socket_connected():
|
|
return
|
|
GameState.request_inventory()
|
|
|
|
|
|
func _on_tier_selected(tier: int):
|
|
selected_tier = tier
|
|
# Update button visuals
|
|
for i in range(1, 6):
|
|
var btn_path = "Control/HBoxContainer/RightPanel/TierSelection/Tier%dBtn" % i
|
|
if has_node(btn_path):
|
|
var btn = get_node(btn_path)
|
|
btn.button_pressed = (i == tier)
|
|
|
|
func _on_enter_dungeon():
|
|
# Quick join - uses old system for backwards compatibility
|
|
GameState.send_enter_dungeon(selected_tier)
|
|
|
|
func _on_browse_dungeons():
|
|
if dungeon_browser:
|
|
dungeon_browser.show_browser()
|
|
|
|
func _on_inventory_pressed():
|
|
if inventory_ui:
|
|
inventory_ui.visible = true
|
|
# Request fresh inventory data
|
|
if GameState:
|
|
GameState.request_inventory()
|
|
|
|
func _on_crafting_pressed():
|
|
if crafting_ui:
|
|
crafting_ui.show_crafting()
|
|
|
|
func _on_stash_pressed():
|
|
if stash_ui:
|
|
stash_ui.show_stash()
|
|
|
|
func _toggle_char_sheet():
|
|
if char_sheet_ui:
|
|
char_sheet_ui.visible = not char_sheet_ui.visible
|
|
|
|
func _create_settings_panel():
|
|
# Create settings button (top right corner, small size)
|
|
settings_btn = TextureButton.new()
|
|
settings_btn.custom_minimum_size = Vector2(64, 64)
|
|
settings_btn.ignore_texture_size = true
|
|
settings_btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
|
|
# Load settings icon from CDN
|
|
var texture_loaded = false
|
|
if UpdateManager:
|
|
var settings_texture = UpdateManager.load_texture("textures/ui/buttons/settings.png")
|
|
if settings_texture:
|
|
settings_btn.texture_normal = settings_texture
|
|
texture_loaded = true
|
|
|
|
# Fallback: add a visible background if texture doesn't load
|
|
if not texture_loaded:
|
|
var fallback_style = StyleBoxFlat.new()
|
|
fallback_style.bg_color = Color(0.3, 0.3, 0.35, 0.9)
|
|
fallback_style.border_color = Color(0.5, 0.5, 0.6)
|
|
fallback_style.set_border_width_all(2)
|
|
fallback_style.set_corner_radius_all(8)
|
|
settings_btn.add_theme_stylebox_override("normal", fallback_style)
|
|
|
|
# Add a label to show "⚙" gear icon
|
|
var label = Label.new()
|
|
label.text = "⚙"
|
|
label.add_theme_font_size_override("font_size", 20)
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
settings_btn.add_child(label)
|
|
|
|
settings_btn.pressed.connect(_toggle_settings_panel)
|
|
add_child(settings_btn)
|
|
|
|
# Position top right corner
|
|
settings_btn.set_anchors_and_offsets_preset(Control.PRESET_TOP_RIGHT)
|
|
settings_btn.offset_left = -42 # 32 + 10 margin
|
|
settings_btn.offset_top = 10
|
|
settings_btn.offset_right = -10
|
|
settings_btn.offset_bottom = 42
|
|
|
|
# Create settings panel (initially hidden)
|
|
settings_panel = Panel.new()
|
|
settings_panel.custom_minimum_size = Vector2(300, 250)
|
|
settings_panel.visible = false
|
|
add_child(settings_panel)
|
|
|
|
# Position center of screen
|
|
settings_panel.set_anchors_and_offsets_preset(Control.PRESET_CENTER)
|
|
settings_panel.offset_left = -150
|
|
settings_panel.offset_top = -125
|
|
settings_panel.offset_right = 150
|
|
settings_panel.offset_bottom = 125
|
|
|
|
# Panel styling
|
|
var panel_style = StyleBoxFlat.new()
|
|
panel_style.bg_color = Color(0.15, 0.15, 0.2, 0.95)
|
|
panel_style.border_color = Color(0.4, 0.4, 0.5)
|
|
panel_style.set_border_width_all(2)
|
|
panel_style.set_corner_radius_all(8)
|
|
settings_panel.add_theme_stylebox_override("panel", panel_style)
|
|
|
|
# Settings panel content
|
|
var vbox = VBoxContainer.new()
|
|
vbox.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
vbox.offset_left = 10
|
|
vbox.offset_top = 10
|
|
vbox.offset_right = -10
|
|
vbox.offset_bottom = -10
|
|
settings_panel.add_child(vbox)
|
|
|
|
# Title
|
|
var title = Label.new()
|
|
title.text = "Settings"
|
|
title.add_theme_font_size_override("font_size", 24)
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
vbox.add_child(title)
|
|
|
|
# Spacer
|
|
var spacer1 = Control.new()
|
|
spacer1.custom_minimum_size = Vector2(0, 20)
|
|
vbox.add_child(spacer1)
|
|
|
|
# Mobile controls toggle
|
|
mobile_controls_toggle = CheckBox.new()
|
|
mobile_controls_toggle.text = "Enable Mobile Controls"
|
|
mobile_controls_toggle.button_pressed = _get_mobile_controls_enabled()
|
|
mobile_controls_toggle.toggled.connect(_on_mobile_controls_toggled)
|
|
vbox.add_child(mobile_controls_toggle)
|
|
|
|
# Spacer
|
|
var spacer2 = Control.new()
|
|
spacer2.custom_minimum_size = Vector2(0, 20)
|
|
vbox.add_child(spacer2)
|
|
|
|
# Logout button
|
|
logout_btn = Button.new()
|
|
logout_btn.text = "Logout"
|
|
logout_btn.custom_minimum_size = Vector2(0, 40)
|
|
|
|
var logout_style = StyleBoxFlat.new()
|
|
logout_style.bg_color = Color(0.8, 0.2, 0.2, 0.9)
|
|
logout_style.border_color = Color(1.0, 0.4, 0.4)
|
|
logout_style.set_border_width_all(2)
|
|
logout_style.set_corner_radius_all(4)
|
|
logout_btn.add_theme_stylebox_override("normal", logout_style)
|
|
|
|
logout_btn.pressed.connect(_on_logout_pressed)
|
|
vbox.add_child(logout_btn)
|
|
|
|
# Spacer (push close button to bottom)
|
|
var spacer3 = Control.new()
|
|
spacer3.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
vbox.add_child(spacer3)
|
|
|
|
# Close button
|
|
var close_btn = Button.new()
|
|
close_btn.text = "Close"
|
|
close_btn.custom_minimum_size = Vector2(0, 40)
|
|
close_btn.pressed.connect(_toggle_settings_panel)
|
|
vbox.add_child(close_btn)
|
|
|
|
func _toggle_settings_panel():
|
|
if settings_panel:
|
|
settings_panel.visible = not settings_panel.visible
|
|
|
|
func _get_mobile_controls_enabled() -> bool:
|
|
# Check if mobile controls are enabled (stored in config or default to true on mobile)
|
|
# Detect touch-capable devices (mobile native or web on tablets/phones)
|
|
var is_touch_device = OS.has_feature("mobile") or DisplayServer.is_touchscreen_available()
|
|
|
|
if is_touch_device:
|
|
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", true)
|
|
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", false)
|
|
|
|
func _on_mobile_controls_toggled(enabled: bool):
|
|
# Save setting
|
|
ProjectSettings.set_setting("application/config/mobile_controls_enabled", enabled)
|
|
|
|
# Apply to current HUD if in dungeon
|
|
var hud = get_tree().get_first_node_in_group("hud")
|
|
if hud and hud.has_method("set_mobile_controls_visible"):
|
|
hud.set_mobile_controls_visible(enabled)
|
|
|
|
print("[Settings] Mobile controls ", "enabled" if enabled else "disabled")
|
|
|
|
func _on_logout_pressed():
|
|
print("[Settings] Logging out...")
|
|
|
|
# Hide settings panel
|
|
if settings_panel:
|
|
settings_panel.visible = false
|
|
|
|
# Disconnect from server
|
|
if Network:
|
|
Network.disconnect_from_server()
|
|
|
|
# Reset GameState
|
|
if GameState:
|
|
GameState.set_state(0)
|
|
|
|
# Return to login screen
|
|
get_tree().change_scene_to_file("res://scenes/ui/login.tscn")
|
|
|
|
func _on_settings_file_downloaded(file_path: String):
|
|
# Check if the settings icon was downloaded
|
|
if file_path == "textures/ui/buttons/settings.png" and settings_btn:
|
|
var settings_texture = UpdateManager.load_texture("textures/ui/buttons/settings.png")
|
|
if settings_texture:
|
|
settings_btn.texture_normal = settings_texture
|
|
settings_btn.ignore_texture_size = true
|
|
settings_btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
# Remove fallback styling if it was applied
|
|
if settings_btn.get_child_count() > 0:
|
|
for child in settings_btn.get_children():
|
|
child.queue_free()
|
|
|
|
func _on_update_completed(_count: int):
|
|
# Try to load settings icon after all updates complete
|
|
if settings_btn and UpdateManager:
|
|
var settings_texture = UpdateManager.load_texture("textures/ui/buttons/settings.png")
|
|
if settings_texture:
|
|
settings_btn.texture_normal = settings_texture
|
|
settings_btn.ignore_texture_size = true
|
|
settings_btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
# Remove fallback styling if it was applied
|
|
if settings_btn.get_child_count() > 0:
|
|
for child in settings_btn.get_children():
|
|
child.queue_free()
|