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
+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