Mobile Controls

This commit is contained in:
dingo
2026-01-19 08:49:10 -05:00
parent 718a8ecb3b
commit 5e8f9d383e
3 changed files with 376 additions and 42 deletions
+198 -1
View File
@@ -25,11 +25,23 @@ extends CanvasLayer
@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)
@@ -109,3 +121,188 @@ func _on_stash_pressed():
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, smaller)
settings_btn = TextureButton.new()
settings_btn.custom_minimum_size = Vector2(16, 16)
# 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
settings_btn.scale = Vector2(.5,.5)
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", 18)
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 (moved further left)
settings_btn.set_anchors_and_offsets_preset(Control.PRESET_TOP_RIGHT)
settings_btn.offset_left = -100
settings_btn.offset_top = 10
settings_btn.offset_right = -118
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)
if OS.has_feature("mobile"):
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.reset_state()
# 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
# 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
# Remove fallback styling if it was applied
if settings_btn.get_child_count() > 0:
for child in settings_btn.get_children():
child.queue_free()
+84
View File
@@ -23,14 +23,24 @@ var hotbar_slots: Array = []
var minimap_image: Image = null
var minimap_tex: ImageTexture = null
# Mobile UI buttons
var inventory_button: Button = null
var crafting_button: Button = null
const MINIMAP_SIZE := 120
const MINIMAP_SCALE := 3 # How many world pixels per minimap pixel
func _ready():
add_to_group("hud")
_setup_hotbar()
_setup_minimap()
_setup_mobile_buttons()
call_deferred("_connect_gamestate")
# Apply mobile controls visibility based on settings
var mobile_enabled = _get_mobile_controls_enabled()
set_mobile_controls_visible(mobile_enabled)
func _connect_gamestate():
if GameState:
GameState.dungeon_state_updated.connect(_update_resources)
@@ -117,6 +127,63 @@ func _setup_minimap():
if minimap_texture:
minimap_texture.texture = minimap_tex
func _setup_mobile_buttons():
# Create inventory button (bottom right)
inventory_button = Button.new()
inventory_button.text = "Inv"
inventory_button.custom_minimum_size = Vector2(60, 60)
var inv_style = StyleBoxFlat.new()
inv_style.bg_color = Color(0.2, 0.3, 0.5, 0.9)
inv_style.border_color = Color(0.4, 0.5, 0.7)
inv_style.set_border_width_all(2)
inv_style.set_corner_radius_all(8)
inventory_button.add_theme_stylebox_override("normal", inv_style)
inventory_button.pressed.connect(_on_mobile_inventory_pressed)
add_child(inventory_button)
# Position bottom right, above joystick
inventory_button.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_RIGHT)
inventory_button.offset_left = -70
inventory_button.offset_top = -140
inventory_button.offset_right = -10
inventory_button.offset_bottom = -80
# Create crafting button (bottom right, above inventory)
crafting_button = Button.new()
crafting_button.text = "Craft"
crafting_button.custom_minimum_size = Vector2(60, 60)
var craft_style = StyleBoxFlat.new()
craft_style.bg_color = Color(0.5, 0.3, 0.2, 0.9)
craft_style.border_color = Color(0.7, 0.5, 0.4)
craft_style.set_border_width_all(2)
craft_style.set_corner_radius_all(8)
crafting_button.add_theme_stylebox_override("normal", craft_style)
crafting_button.pressed.connect(_on_mobile_crafting_pressed)
add_child(crafting_button)
# Position bottom right, above inventory button
crafting_button.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_RIGHT)
crafting_button.offset_left = -70
crafting_button.offset_top = -210
crafting_button.offset_right = -10
crafting_button.offset_bottom = -150
func _on_mobile_inventory_pressed():
# Toggle inventory visibility
var dungeon_manager = get_tree().get_first_node_in_group("dungeon_manager")
if dungeon_manager and dungeon_manager.has_method("_toggle_inventory"):
dungeon_manager._toggle_inventory()
func _on_mobile_crafting_pressed():
# Toggle crafting UI visibility
var dungeon_manager = get_tree().get_first_node_in_group("dungeon_manager")
if dungeon_manager and dungeon_manager.has_method("_toggle_crafting"):
dungeon_manager._toggle_crafting()
func _generate_minimap():
if not GameState or GameState.dungeon.tiles.is_empty():
return
@@ -356,3 +423,20 @@ func add_log_entry(text: String, color: Color):
var child = event_log.get_child(0)
if is_instance_valid(child):
child.queue_free()
func _get_mobile_controls_enabled() -> bool:
if OS.has_feature("mobile"):
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", true)
return ProjectSettings.get_setting("application/config/mobile_controls_enabled", false)
func set_mobile_controls_visible(visible: bool):
# Show/hide mobile UI buttons
if inventory_button:
inventory_button.visible = visible
if crafting_button:
crafting_button.visible = visible
# Show/hide touch joystick
var joystick = get_node_or_null("TouchJoystick")
if joystick:
joystick.visible = visible