Initial
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var username_input = $Control/CenterContainer/VBoxContainer/TabContainer/Login/UsernameInput
|
||||
@onready var password_input = $Control/CenterContainer/VBoxContainer/TabContainer/Login/PasswordInput
|
||||
@onready var login_button = $Control/CenterContainer/VBoxContainer/TabContainer/Login/LoginButton
|
||||
|
||||
@onready var reg_username = $Control/CenterContainer/VBoxContainer/TabContainer/Register/RegUsernameInput
|
||||
@onready var reg_email = $Control/CenterContainer/VBoxContainer/TabContainer/Register/RegEmailInput
|
||||
@onready var reg_password = $Control/CenterContainer/VBoxContainer/TabContainer/Register/RegPasswordInput
|
||||
@onready var reg_passwordConfirm = $Control/CenterContainer/VBoxContainer/TabContainer/Register/RegConfirmPasswordInput
|
||||
@onready var char_name = $Control/CenterContainer/VBoxContainer/TabContainer/Register/CharNameInput
|
||||
@onready var register_button = $Control/CenterContainer/VBoxContainer/TabContainer/Register/RegisterButton
|
||||
|
||||
@onready var status_label = $Control/CenterContainer/VBoxContainer/StatusLabel
|
||||
|
||||
func _ready():
|
||||
login_button.pressed.connect(_on_login_pressed)
|
||||
register_button.pressed.connect(_on_register_pressed)
|
||||
|
||||
# Defer network signal connections
|
||||
call_deferred("_connect_network_signals")
|
||||
|
||||
func _connect_network_signals():
|
||||
if Network:
|
||||
Network.connected.connect(_on_connected)
|
||||
Network.disconnected.connect(_on_disconnected)
|
||||
Network.message_received.connect(_on_message)
|
||||
|
||||
func _on_login_pressed():
|
||||
var user = username_input.text.strip_edges()
|
||||
var pass_text = password_input.text
|
||||
|
||||
if user.length() < 3:
|
||||
_set_status("Username must be at least 3 characters", Color.RED)
|
||||
return
|
||||
if pass_text.length() < 8:
|
||||
_set_status("Password must be at least 8 characters", Color.RED)
|
||||
return
|
||||
|
||||
_set_status("Connecting...")
|
||||
|
||||
if not Network.is_socket_connected():
|
||||
Network.connect_to_server()
|
||||
await Network.connected
|
||||
|
||||
Network.send_message(OpCodes.AUTH_LOGIN, {
|
||||
"UsernameOrEmail": user,
|
||||
"Password": pass_text
|
||||
})
|
||||
|
||||
func _on_register_pressed():
|
||||
var user = reg_username.text.strip_edges()
|
||||
var email = reg_email.text.strip_edges()
|
||||
var pass_text = reg_password.text
|
||||
var conf_pass_text = reg_passwordConfirm.text
|
||||
var char_name_text = char_name.text.strip_edges()
|
||||
|
||||
if user.length() < 3:
|
||||
_set_status("Username must be at least 3 characters", Color.RED)
|
||||
return
|
||||
if not "@" in email:
|
||||
_set_status("Please enter a valid email", Color.RED)
|
||||
return
|
||||
if pass_text.length() < 8:
|
||||
_set_status("Password must be at least 8 characters", Color.RED)
|
||||
return
|
||||
if pass_text != conf_pass_text:
|
||||
_set_status("Password does not match.", Color.RED)
|
||||
return
|
||||
if char_name_text.length() < 2:
|
||||
_set_status("Character name is required", Color.RED)
|
||||
return
|
||||
|
||||
|
||||
_set_status("Connecting...")
|
||||
|
||||
if not Network.is_socket_connected():
|
||||
Network.connect_to_server()
|
||||
await Network.connected
|
||||
|
||||
Network.send_message(OpCodes.AUTH_REGISTER, {
|
||||
"Username": user,
|
||||
"Password": pass_text,
|
||||
"Email": email,
|
||||
#"characterName": char_name_text
|
||||
})
|
||||
|
||||
func _on_connected():
|
||||
_set_status("Connected!", Color.GREEN)
|
||||
|
||||
func _on_disconnected():
|
||||
_set_status("Disconnected from server", Color.RED)
|
||||
|
||||
func _on_message(opcode: int, data: Dictionary):
|
||||
if opcode == OpCodes.AUTH_LOGIN_RESULT or opcode == OpCodes.AUTH_REGISTER_RESULT:
|
||||
var ok = data.get("Ok", data.get("ok", false))
|
||||
if ok:
|
||||
_set_status("Logged in!", Color.GREEN)
|
||||
else:
|
||||
var error = data.get("Error", data.get("error", "Unknown error"))
|
||||
_set_status("Failed: " + error, Color.RED)
|
||||
|
||||
func _set_status(text: String, color: Color = Color.WHITE):
|
||||
status_label.text = text
|
||||
status_label.modulate = color
|
||||
@@ -0,0 +1 @@
|
||||
uid://bq76ikog47k8
|
||||
@@ -0,0 +1,74 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var chat_log = $Control/ChatLog
|
||||
@onready var chat_messages_container = $Control/ChatLog/ChatMessages
|
||||
@onready var chat_input = $Control/InputContainer/ChatInput
|
||||
|
||||
const MAX_MESSAGES = 50
|
||||
const TYPE_COLORS = {
|
||||
"normal": Color.WHITE,
|
||||
"system": Color(1, 0.8, 0),
|
||||
"party": Color(0, 0.8, 1),
|
||||
"whisper": Color(0.8, 0.4, 1)
|
||||
}
|
||||
|
||||
func _ready():
|
||||
chat_input.text_submitted.connect(_on_message_submitted)
|
||||
|
||||
visible = false
|
||||
|
||||
# Defer GameState connection
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
if GameState:
|
||||
GameState.chat_message_received.connect(_on_chat_message)
|
||||
|
||||
func _on_chat_message(sender: String, message: String, type: String):
|
||||
_add_message(sender, message, type)
|
||||
|
||||
func _add_message(sender: String, message: String, type: String = "normal"):
|
||||
var label = RichTextLabel.new()
|
||||
label.bbcode_enabled = true
|
||||
label.fit_content = true
|
||||
label.scroll_active = false
|
||||
|
||||
var color = TYPE_COLORS.get(type, Color.WHITE)
|
||||
var color_hex = color.to_html(false)
|
||||
|
||||
if type == "system":
|
||||
label.text = "[color=#%s][System] %s[/color]" % [color_hex, message]
|
||||
else:
|
||||
label.text = "[color=#ffd700]%s:[/color] [color=#%s]%s[/color]" % [sender, color_hex, message]
|
||||
|
||||
chat_messages_container.add_child(label)
|
||||
|
||||
# Limit messages
|
||||
while chat_messages_container.get_child_count() > MAX_MESSAGES:
|
||||
chat_messages_container.get_child(0).queue_free()
|
||||
|
||||
# Scroll to bottom
|
||||
await get_tree().process_frame
|
||||
chat_log.scroll_vertical = chat_log.get_v_scroll_bar().max_value
|
||||
|
||||
func focus_input():
|
||||
chat_input.grab_focus()
|
||||
|
||||
func _on_message_submitted(text: String):
|
||||
if text.strip_edges().is_empty():
|
||||
_close()
|
||||
return
|
||||
|
||||
GameState.send_chat(text)
|
||||
chat_input.text = ""
|
||||
_close()
|
||||
|
||||
func _close():
|
||||
visible = false
|
||||
chat_input.release_focus()
|
||||
|
||||
func _input(event):
|
||||
if visible:
|
||||
if event.is_action_pressed("escape_menu"):
|
||||
_close()
|
||||
get_viewport().set_input_as_handled()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bknoefdelbqoo
|
||||
@@ -0,0 +1,30 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var return_button = $Panel/VBoxContainer/ReturnButton
|
||||
|
||||
func _ready():
|
||||
visible = false
|
||||
|
||||
if return_button:
|
||||
return_button.pressed.connect(_on_return_pressed)
|
||||
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
if GameState:
|
||||
GameState.state_changed.connect(_on_state_changed)
|
||||
GameState.player_died.connect(_on_player_died)
|
||||
|
||||
func _on_state_changed(state: String):
|
||||
visible = (state == "DEAD")
|
||||
if visible:
|
||||
print("[DeathScreen] Now visible")
|
||||
|
||||
func _on_player_died():
|
||||
visible = true
|
||||
print("[DeathScreen] Player died, showing death screen")
|
||||
|
||||
func _on_return_pressed():
|
||||
if GameState:
|
||||
GameState.return_to_hub()
|
||||
visible = false
|
||||
@@ -0,0 +1 @@
|
||||
uid://cmsghh3o0ta18
|
||||
@@ -0,0 +1,79 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var name_label = $Control/HBoxContainer/LeftPanel/CharacterInfo/NameLabel
|
||||
@onready var level_label = $Control/HBoxContainer/LeftPanel/CharacterInfo/LevelLabel
|
||||
@onready var xp_bar = $Control/HBoxContainer/LeftPanel/CharacterInfo/XPBar
|
||||
|
||||
@onready var str_value = $Control/HBoxContainer/LeftPanel/StatsPanel/StrValue
|
||||
@onready var int_value = $Control/HBoxContainer/LeftPanel/StatsPanel/IntValue
|
||||
@onready var wis_value = $Control/HBoxContainer/LeftPanel/StatsPanel/WisValue
|
||||
@onready var end_value = $Control/HBoxContainer/LeftPanel/StatsPanel/EndValue
|
||||
@onready var dex_value = $Control/HBoxContainer/LeftPanel/StatsPanel/DexValue
|
||||
@onready var points_label = $Control/HBoxContainer/LeftPanel/StatsPanel/PointsRemaining
|
||||
|
||||
@onready var enter_btn = $Control/HBoxContainer/RightPanel/EnterDungeonBtn
|
||||
|
||||
var selected_tier: int = 1
|
||||
|
||||
func _ready():
|
||||
enter_btn.pressed.connect(_on_enter_dungeon)
|
||||
|
||||
# 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))
|
||||
|
||||
# Setup stat buttons
|
||||
for stat in ["Str", "Int", "Wis", "End", "Dex"]:
|
||||
var btn_path = "Control/HBoxContainer/LeftPanel/StatsPanel/%sButton" % stat
|
||||
if has_node(btn_path):
|
||||
var btn = get_node(btn_path)
|
||||
btn.pressed.connect(_on_stat_allocate.bind(stat.to_lower()))
|
||||
|
||||
# Defer GameState connection
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
if GameState:
|
||||
GameState.character_updated.connect(_update_ui)
|
||||
|
||||
func _update_ui():
|
||||
var c = GameState.character
|
||||
name_label.text = c.name
|
||||
level_label.text = "Level %d" % c.level
|
||||
xp_bar.max_value = c.xp_next
|
||||
xp_bar.value = c.xp
|
||||
|
||||
str_value.text = str(c.strength)
|
||||
int_value.text = str(c.intelligence)
|
||||
wis_value.text = str(c.wisdom)
|
||||
end_value.text = str(c.endurance)
|
||||
dex_value.text = str(c.dexterity)
|
||||
|
||||
points_label.text = "Points: %d" % c.unspent_points
|
||||
|
||||
# Enable/disable stat buttons based on available points
|
||||
var has_points = c.unspent_points > 0
|
||||
for stat in ["Str", "Int", "Wis", "End", "Dex"]:
|
||||
var btn_path = "Control/HBoxContainer/LeftPanel/StatsPanel/%sButton" % stat
|
||||
if has_node(btn_path):
|
||||
var btn = get_node(btn_path)
|
||||
btn.disabled = not has_points
|
||||
|
||||
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_stat_allocate(stat: String):
|
||||
if GameState.character.unspent_points > 0:
|
||||
GameState.send_allocate_stat(stat)
|
||||
|
||||
func _on_enter_dungeon():
|
||||
GameState.send_enter_dungeon(selected_tier)
|
||||
@@ -0,0 +1 @@
|
||||
uid://c4v4vw32gyxbl
|
||||
@@ -0,0 +1,214 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var hp_bar = $TopLeft/HPBar
|
||||
@onready var hp_text = $TopLeft/HPBar/Label
|
||||
@onready var mp_bar = $TopLeft/MPBar
|
||||
@onready var mp_text = $TopLeft/MPBar/Label
|
||||
@onready var sta_bar = $TopLeft/STABar
|
||||
@onready var sta_text = $TopLeft/STABar/Label
|
||||
|
||||
@onready var tier_label = $TopCenter/DungeonInfo/TierLabel
|
||||
@onready var mobs_label = $TopCenter/DungeonInfo/MobsLabel
|
||||
|
||||
@onready var minimap_container = $TopRight/Minimap
|
||||
@onready var minimap_texture = $TopRight/Minimap/MinimapTexture
|
||||
|
||||
@onready var hotbar_container = $BottomCenter/Hotbar
|
||||
|
||||
@onready var escape_indicator = $EscapeIndicator
|
||||
@onready var escape_countdown = $EscapeIndicator/Countdown
|
||||
|
||||
var hotbar_slots: Array = []
|
||||
var minimap_image: Image = null
|
||||
var minimap_tex: ImageTexture = null
|
||||
|
||||
const MINIMAP_SIZE := 120
|
||||
const MINIMAP_SCALE := 3 # How many world pixels per minimap pixel
|
||||
|
||||
func _ready():
|
||||
_setup_hotbar()
|
||||
_setup_minimap()
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
if GameState:
|
||||
GameState.dungeon_state_updated.connect(_update_resources)
|
||||
GameState.inventory_updated.connect(_update_hotbar)
|
||||
GameState.dungeon_entered.connect(_on_dungeon_entered)
|
||||
|
||||
func _on_dungeon_entered():
|
||||
_generate_minimap()
|
||||
_update_resources()
|
||||
|
||||
func _setup_hotbar():
|
||||
if not hotbar_container:
|
||||
return
|
||||
for i in range(8):
|
||||
var slot = Button.new()
|
||||
slot.custom_minimum_size = Vector2(48, 48)
|
||||
slot.text = str(i + 1)
|
||||
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.15, 0.15, 0.2, 0.9)
|
||||
style.border_color = Color(0.3, 0.3, 0.4)
|
||||
style.set_border_width_all(2)
|
||||
style.set_corner_radius_all(4)
|
||||
slot.add_theme_stylebox_override("normal", style)
|
||||
|
||||
slot.pressed.connect(_on_hotbar_pressed.bind(i))
|
||||
hotbar_container.add_child(slot)
|
||||
hotbar_slots.append(slot)
|
||||
|
||||
func _setup_minimap():
|
||||
minimap_image = Image.create(MINIMAP_SIZE, MINIMAP_SIZE, false, Image.FORMAT_RGBA8)
|
||||
minimap_tex = ImageTexture.create_from_image(minimap_image)
|
||||
if minimap_texture:
|
||||
minimap_texture.texture = minimap_tex
|
||||
|
||||
func _generate_minimap():
|
||||
if not GameState or GameState.dungeon.tiles.is_empty():
|
||||
return
|
||||
|
||||
minimap_image.fill(Color(0.1, 0.1, 0.15, 0.8))
|
||||
|
||||
var tiles = GameState.dungeon.tiles
|
||||
var width = GameState.dungeon.width
|
||||
var height = GameState.dungeon.height
|
||||
|
||||
# Scale factor to fit dungeon in minimap
|
||||
var scale_x = float(MINIMAP_SIZE) / float(width)
|
||||
var scale_y = float(MINIMAP_SIZE) / float(height)
|
||||
var scale = min(scale_x, scale_y)
|
||||
|
||||
# Offset to center the minimap
|
||||
var offset_x = int((MINIMAP_SIZE - width * scale) / 2)
|
||||
var offset_y = int((MINIMAP_SIZE - height * scale) / 2)
|
||||
|
||||
for x in range(width):
|
||||
if x >= tiles.size():
|
||||
continue
|
||||
for y in range(height):
|
||||
if y >= tiles[x].size():
|
||||
continue
|
||||
|
||||
var mx = int(x * scale) + offset_x
|
||||
var my = int(y * scale) + offset_y
|
||||
|
||||
if mx >= 0 and mx < MINIMAP_SIZE and my >= 0 and my < MINIMAP_SIZE:
|
||||
var color = Color(0.3, 0.3, 0.35) if tiles[x][y] == 1 else Color(0.5, 0.45, 0.4)
|
||||
minimap_image.set_pixel(mx, my, color)
|
||||
|
||||
minimap_tex.update(minimap_image)
|
||||
|
||||
func _process(_delta):
|
||||
_update_escape_indicator()
|
||||
_update_minimap_entities()
|
||||
|
||||
func _update_minimap_entities():
|
||||
if not GameState or not minimap_tex or GameState.dungeon.tiles.is_empty():
|
||||
return
|
||||
|
||||
# Start fresh each frame (regenerate base map periodically would be better for perf)
|
||||
var width = GameState.dungeon.width
|
||||
var height = GameState.dungeon.height
|
||||
var scale = min(float(MINIMAP_SIZE) / float(width), float(MINIMAP_SIZE) / float(height))
|
||||
var offset_x = int((MINIMAP_SIZE - width * scale) / 2)
|
||||
var offset_y = int((MINIMAP_SIZE - height * scale) / 2)
|
||||
|
||||
# Draw player position
|
||||
var px = GameState.self_player.get("x", 0) / 32.0 # Convert from pixels to tiles
|
||||
var py = GameState.self_player.get("y", 0) / 32.0
|
||||
var player_mx = int(px * scale) + offset_x
|
||||
var player_my = int(py * scale) + offset_y
|
||||
|
||||
# Draw a small dot for player (green)
|
||||
for dx in range(-1, 2):
|
||||
for dy in range(-1, 2):
|
||||
var draw_x = player_mx + dx
|
||||
var draw_y = player_my + dy
|
||||
if draw_x >= 0 and draw_x < MINIMAP_SIZE and draw_y >= 0 and draw_y < MINIMAP_SIZE:
|
||||
minimap_image.set_pixel(draw_x, draw_y, Color.GREEN)
|
||||
|
||||
# Draw mobs (red dots)
|
||||
for mob_id in GameState.mobs:
|
||||
var mob = GameState.mobs[mob_id]
|
||||
var mx = mob.get("x", mob.get("X", 0)) / 32.0
|
||||
var my = mob.get("y", mob.get("Y", 0)) / 32.0
|
||||
var mob_mx = int(mx * scale) + offset_x
|
||||
var mob_my = int(my * scale) + offset_y
|
||||
if mob_mx >= 0 and mob_mx < MINIMAP_SIZE and mob_my >= 0 and mob_my < MINIMAP_SIZE:
|
||||
minimap_image.set_pixel(mob_mx, mob_my, Color.RED)
|
||||
|
||||
minimap_tex.update(minimap_image)
|
||||
|
||||
func _update_resources():
|
||||
if not GameState:
|
||||
return
|
||||
|
||||
var p = GameState.self_player
|
||||
|
||||
if hp_bar:
|
||||
hp_bar.max_value = p.get("max_health", 100)
|
||||
hp_bar.value = p.get("health", 100)
|
||||
if hp_text:
|
||||
hp_text.text = "%d/%d" % [int(p.get("health", 0)), int(p.get("max_health", 100))]
|
||||
|
||||
if mp_bar:
|
||||
mp_bar.max_value = p.get("max_mana", 50)
|
||||
mp_bar.value = p.get("mana", 50)
|
||||
if mp_text:
|
||||
mp_text.text = "%d/%d" % [int(p.get("mana", 0)), int(p.get("max_mana", 50))]
|
||||
|
||||
if sta_bar:
|
||||
sta_bar.max_value = p.get("max_stamina", 55)
|
||||
sta_bar.value = p.get("stamina", 55)
|
||||
if sta_text:
|
||||
sta_text.text = "%d/%d" % [int(p.get("stamina", 0)), int(p.get("max_stamina", 55))]
|
||||
|
||||
if tier_label:
|
||||
tier_label.text = "Tier %d" % GameState.dungeon.tier
|
||||
if mobs_label:
|
||||
mobs_label.text = "Mobs: %d" % GameState.mobs.size()
|
||||
|
||||
func _update_hotbar():
|
||||
if not GameState:
|
||||
return
|
||||
for i in range(8):
|
||||
if i >= hotbar_slots.size():
|
||||
break
|
||||
var slot = hotbar_slots[i]
|
||||
var hotbar_entry = GameState.hotbar[i]
|
||||
|
||||
if hotbar_entry and hotbar_entry is Dictionary and hotbar_entry.has("inventory_slot"):
|
||||
var inv_slot = hotbar_entry.inventory_slot
|
||||
if inv_slot < GameState.inventory.size():
|
||||
var item = GameState.inventory[inv_slot]
|
||||
if item and item.get("type") == "Consumable":
|
||||
slot.text = _get_item_emoji(item)
|
||||
continue
|
||||
|
||||
slot.text = str(i + 1)
|
||||
|
||||
func _get_item_emoji(item: Dictionary) -> String:
|
||||
var item_name = item.get("name", "").to_lower()
|
||||
if "health" in item_name: return "❤️"
|
||||
if "mana" in item_name: return "💙"
|
||||
if "escape" in item_name: return "🏃"
|
||||
return "🧪"
|
||||
|
||||
func _on_hotbar_pressed(index: int):
|
||||
if not GameState:
|
||||
return
|
||||
var hotbar_entry = GameState.hotbar[index]
|
||||
if hotbar_entry and hotbar_entry is Dictionary and hotbar_entry.has("inventory_slot"):
|
||||
GameState.send_use_item(hotbar_entry.inventory_slot)
|
||||
|
||||
func _update_escape_indicator():
|
||||
if not escape_indicator or not GameState:
|
||||
return
|
||||
escape_indicator.visible = GameState.is_escaping
|
||||
if GameState.is_escaping:
|
||||
var elapsed = (Time.get_ticks_msec() - GameState.escape_start_time) / 1000.0
|
||||
var remaining = max(0, 5 - elapsed)
|
||||
if escape_countdown:
|
||||
escape_countdown.text = "%.1f" % remaining
|
||||
@@ -0,0 +1 @@
|
||||
uid://dis78b7f8x3j0
|
||||
@@ -0,0 +1,341 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var close_button = $PanelContainer/VBoxContainer/Header/CloseButton
|
||||
@onready var equipment_grid = $PanelContainer/VBoxContainer/Content/EquipmentSection/EquipmentGrid
|
||||
@onready var inventory_grid = $PanelContainer/VBoxContainer/Content/BagSection/InventoryGrid
|
||||
@onready var gold_label = $PanelContainer/VBoxContainer/Footer/GoldLabel
|
||||
|
||||
const EQUIPMENT_SLOTS = ["weapon", "offhand", "helm", "chest", "gloves", "legs", "boots", "ring1", "ring2"]
|
||||
const EQUIPMENT_ICONS = {
|
||||
"weapon": "⚔️",
|
||||
"offhand": "🛡️",
|
||||
"helm": "🎩",
|
||||
"chest": "👕",
|
||||
"gloves": "🧤",
|
||||
"legs": "👖",
|
||||
"boots": "👢",
|
||||
"ring1": "💍",
|
||||
"ring2": "💍"
|
||||
}
|
||||
|
||||
const RARITY_COLORS = {
|
||||
"Common": Color(0.7, 0.7, 0.7),
|
||||
"Uncommon": Color(0.18, 0.8, 0.44),
|
||||
"Rare": Color(0.2, 0.6, 0.86),
|
||||
"Epic": Color(0.61, 0.35, 0.71),
|
||||
"Legendary": Color(0.95, 0.61, 0.07)
|
||||
}
|
||||
|
||||
var inventory_slots: Array = []
|
||||
var equipment_slots: Dictionary = {}
|
||||
var tooltip: PanelContainer = null
|
||||
var selected_hotbar_slot: int = -1 # For hotbar assignment
|
||||
|
||||
func _ready():
|
||||
visible = false
|
||||
|
||||
if close_button:
|
||||
close_button.pressed.connect(_on_close)
|
||||
|
||||
_setup_equipment_slots()
|
||||
_setup_inventory_slots()
|
||||
_create_tooltip()
|
||||
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
if GameState:
|
||||
GameState.inventory_updated.connect(_refresh_inventory)
|
||||
|
||||
func _setup_equipment_slots():
|
||||
if not equipment_grid:
|
||||
return
|
||||
for slot_name in EQUIPMENT_SLOTS:
|
||||
var slot = _create_slot_button()
|
||||
slot.set_meta("slot_type", "equipment")
|
||||
slot.set_meta("slot_name", slot_name)
|
||||
slot.set_meta("item", null)
|
||||
slot.text = EQUIPMENT_ICONS.get(slot_name, "?")
|
||||
slot.gui_input.connect(_on_equipment_gui_input.bind(slot_name))
|
||||
slot.mouse_entered.connect(_on_slot_hover.bind(slot))
|
||||
slot.mouse_exited.connect(_hide_tooltip)
|
||||
equipment_grid.add_child(slot)
|
||||
equipment_slots[slot_name] = slot
|
||||
|
||||
func _setup_inventory_slots():
|
||||
if not inventory_grid:
|
||||
return
|
||||
for i in range(30):
|
||||
var slot = _create_slot_button()
|
||||
slot.set_meta("slot_type", "inventory")
|
||||
slot.set_meta("slot_index", i)
|
||||
slot.set_meta("item", null)
|
||||
slot.gui_input.connect(_on_inventory_gui_input.bind(i))
|
||||
slot.mouse_entered.connect(_on_slot_hover.bind(slot))
|
||||
slot.mouse_exited.connect(_hide_tooltip)
|
||||
inventory_grid.add_child(slot)
|
||||
inventory_slots.append(slot)
|
||||
|
||||
func _create_slot_button() -> Button:
|
||||
var btn = Button.new()
|
||||
btn.custom_minimum_size = Vector2(48, 48)
|
||||
btn.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2)))
|
||||
btn.add_theme_stylebox_override("hover", _create_slot_style(Color(0.25, 0.25, 0.35)))
|
||||
return btn
|
||||
|
||||
func _create_slot_style(color: Color) -> StyleBoxFlat:
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = color
|
||||
style.border_color = Color(0.3, 0.3, 0.4)
|
||||
style.set_border_width_all(2)
|
||||
style.set_corner_radius_all(4)
|
||||
return style
|
||||
|
||||
func _create_tooltip():
|
||||
tooltip = PanelContainer.new()
|
||||
tooltip.z_index = 100
|
||||
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.1, 0.1, 0.15, 0.95)
|
||||
style.border_color = Color(0.4, 0.4, 0.5)
|
||||
style.set_border_width_all(1)
|
||||
style.set_corner_radius_all(4)
|
||||
style.set_content_margin_all(8)
|
||||
tooltip.add_theme_stylebox_override("panel", style)
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.name = "VBox"
|
||||
|
||||
var name_label = Label.new()
|
||||
name_label.name = "ItemName"
|
||||
name_label.add_theme_font_size_override("font_size", 14)
|
||||
vbox.add_child(name_label)
|
||||
|
||||
var type_label = Label.new()
|
||||
type_label.name = "ItemType"
|
||||
type_label.add_theme_font_size_override("font_size", 11)
|
||||
type_label.modulate = Color(0.7, 0.7, 0.7)
|
||||
vbox.add_child(type_label)
|
||||
|
||||
var sep = HSeparator.new()
|
||||
vbox.add_child(sep)
|
||||
|
||||
var stats_label = Label.new()
|
||||
stats_label.name = "ItemStats"
|
||||
stats_label.add_theme_font_size_override("font_size", 12)
|
||||
vbox.add_child(stats_label)
|
||||
|
||||
var desc_label = Label.new()
|
||||
desc_label.name = "ItemDesc"
|
||||
desc_label.add_theme_font_size_override("font_size", 10)
|
||||
desc_label.modulate = Color(0.6, 0.6, 0.6)
|
||||
desc_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
desc_label.custom_minimum_size.x = 200
|
||||
vbox.add_child(desc_label)
|
||||
|
||||
var hint_label = Label.new()
|
||||
hint_label.name = "Hint"
|
||||
hint_label.add_theme_font_size_override("font_size", 10)
|
||||
hint_label.modulate = Color(0.5, 0.7, 0.5)
|
||||
vbox.add_child(hint_label)
|
||||
|
||||
tooltip.add_child(vbox)
|
||||
tooltip.visible = false
|
||||
add_child(tooltip)
|
||||
|
||||
func _refresh_inventory():
|
||||
for i in range(30):
|
||||
if i >= inventory_slots.size():
|
||||
break
|
||||
var item = GameState.inventory[i] if i < GameState.inventory.size() else null
|
||||
_update_slot(inventory_slots[i], item)
|
||||
|
||||
for slot_name in EQUIPMENT_SLOTS:
|
||||
if equipment_slots.has(slot_name):
|
||||
var item = GameState.equipment.get(slot_name)
|
||||
_update_slot(equipment_slots[slot_name], item, EQUIPMENT_ICONS.get(slot_name, "?"))
|
||||
|
||||
func _update_slot(slot: Button, item, default_text: String = ""):
|
||||
if item == null or (item is Dictionary and item.is_empty()):
|
||||
slot.text = default_text
|
||||
slot.set_meta("item", null)
|
||||
slot.add_theme_stylebox_override("normal", _create_slot_style(Color(0.15, 0.15, 0.2)))
|
||||
else:
|
||||
slot.text = _get_item_emoji(item)
|
||||
slot.set_meta("item", item)
|
||||
|
||||
var rarity = item.get("rarity", item.get("Rarity", "Common"))
|
||||
var style = _create_slot_style(Color(0.15, 0.15, 0.2))
|
||||
style.border_color = RARITY_COLORS.get(rarity, Color.GRAY)
|
||||
style.border_width_bottom = 3
|
||||
slot.add_theme_stylebox_override("normal", style)
|
||||
|
||||
func _get_item_emoji(item: Dictionary) -> String:
|
||||
var item_type = item.get("type", item.get("Type", "")).to_lower()
|
||||
var item_name = item.get("name", item.get("Name", "")).to_lower()
|
||||
|
||||
match item_type:
|
||||
"consumable":
|
||||
if "health" in item_name: return "❤️"
|
||||
if "mana" in item_name: return "💙"
|
||||
if "escape" in item_name: return "🏃"
|
||||
return "🧪"
|
||||
"material":
|
||||
if "bone" in item_name: return "🦴"
|
||||
if "hide" in item_name or "leather" in item_name: return "🥩"
|
||||
if "essence" in item_name or "soul" in item_name: return "👻"
|
||||
if "shard" in item_name or "crystal" in item_name: return "💎"
|
||||
return "📦"
|
||||
"weapon": return "⚔️"
|
||||
"armor":
|
||||
if "helm" in item_name: return "🎩"
|
||||
return "🛡️"
|
||||
"accessory": return "💍"
|
||||
_: return "❓"
|
||||
|
||||
func _on_inventory_gui_input(event: InputEvent, slot_index: int):
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null
|
||||
if item == null:
|
||||
return
|
||||
|
||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||
# Left click: use/equip
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
if item_type == "Consumable":
|
||||
GameState.send_use_item(slot_index)
|
||||
elif item_type in ["Weapon", "Armor", "Accessory"]:
|
||||
GameState.send_equip_item(slot_index)
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
# Right click: assign to hotbar (for consumables)
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
if item_type == "Consumable":
|
||||
_show_hotbar_menu(slot_index)
|
||||
|
||||
func _on_equipment_gui_input(event: InputEvent, slot_name: String):
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
var item = GameState.equipment.get(slot_name)
|
||||
if item != null:
|
||||
GameState.send_unequip_item(slot_name)
|
||||
|
||||
func _show_hotbar_menu(inv_slot: int):
|
||||
# Simple approach: assign to next empty hotbar slot or show popup
|
||||
# For now, find first empty slot or use slot 0
|
||||
var target_slot = 0
|
||||
for i in range(8):
|
||||
if GameState.hotbar[i] == null:
|
||||
target_slot = i
|
||||
break
|
||||
|
||||
GameState.assign_hotbar(target_slot, inv_slot)
|
||||
print("Assigned inventory slot %d to hotbar slot %d" % [inv_slot, target_slot])
|
||||
|
||||
func _on_slot_hover(slot: Button):
|
||||
if not slot.has_meta("item"):
|
||||
_hide_tooltip()
|
||||
return
|
||||
var item = slot.get_meta("item")
|
||||
if item == null:
|
||||
_hide_tooltip()
|
||||
return
|
||||
|
||||
_show_tooltip(item, slot)
|
||||
|
||||
func _show_tooltip(item: Dictionary, slot: Button):
|
||||
if not tooltip:
|
||||
return
|
||||
|
||||
var vbox = tooltip.get_node_or_null("VBox")
|
||||
if not vbox:
|
||||
return
|
||||
|
||||
var name_label = vbox.get_node_or_null("ItemName")
|
||||
var type_label = vbox.get_node_or_null("ItemType")
|
||||
var stats_label = vbox.get_node_or_null("ItemStats")
|
||||
var desc_label = vbox.get_node_or_null("ItemDesc")
|
||||
var hint_label = vbox.get_node_or_null("Hint")
|
||||
|
||||
if not name_label:
|
||||
return
|
||||
|
||||
var rarity = item.get("rarity", item.get("Rarity", "Common"))
|
||||
var item_name = item.get("name", item.get("Name", "Unknown"))
|
||||
var item_type = item.get("type", item.get("Type", ""))
|
||||
|
||||
name_label.text = item_name
|
||||
name_label.modulate = RARITY_COLORS.get(rarity, Color.WHITE)
|
||||
|
||||
if type_label:
|
||||
type_label.text = "%s %s" % [rarity, item_type]
|
||||
|
||||
# Build stats text
|
||||
var stats = []
|
||||
var min_dmg = item.get("minDamage", item.get("MinDamage", 0))
|
||||
var max_dmg = item.get("maxDamage", item.get("MaxDamage", 0))
|
||||
if min_dmg > 0 and max_dmg > 0:
|
||||
stats.append("Damage: %d-%d" % [int(min_dmg), int(max_dmg)])
|
||||
|
||||
var armor = item.get("armor", item.get("Armor", 0))
|
||||
if armor > 0:
|
||||
stats.append("Armor: +%d" % int(armor))
|
||||
|
||||
var bonus_hp = item.get("bonusHealth", item.get("BonusHealth", 0))
|
||||
if bonus_hp > 0:
|
||||
stats.append("Health: +%d" % int(bonus_hp))
|
||||
|
||||
var bonus_mp = item.get("bonusMana", item.get("BonusMana", 0))
|
||||
if bonus_mp > 0:
|
||||
stats.append("Mana: +%d" % int(bonus_mp))
|
||||
|
||||
var heal = item.get("healAmount", item.get("HealAmount", 0))
|
||||
if heal > 0:
|
||||
stats.append("Heals: %d HP" % int(heal))
|
||||
|
||||
var mana_restore = item.get("manaRestore", item.get("ManaRestore", 0))
|
||||
if mana_restore > 0:
|
||||
stats.append("Restores: %d MP" % int(mana_restore))
|
||||
|
||||
if stats_label:
|
||||
stats_label.text = "\n".join(stats) if stats.size() > 0 else ""
|
||||
stats_label.visible = stats.size() > 0
|
||||
|
||||
if desc_label:
|
||||
var desc = item.get("description", item.get("Description", ""))
|
||||
desc_label.text = desc
|
||||
desc_label.visible = desc != ""
|
||||
|
||||
# Hint for actions
|
||||
if hint_label:
|
||||
if item_type == "Consumable":
|
||||
hint_label.text = "Left-click: Use | Right-click: Add to hotbar"
|
||||
elif item_type in ["Weapon", "Armor", "Accessory"]:
|
||||
hint_label.text = "Left-click: Equip"
|
||||
else:
|
||||
hint_label.text = ""
|
||||
hint_label.visible = hint_label.text != ""
|
||||
|
||||
# Position tooltip near slot
|
||||
await get_tree().process_frame
|
||||
var screen_size = get_viewport().get_visible_rect().size
|
||||
var pos = slot.global_position + Vector2(slot.size.x + 10, 0)
|
||||
|
||||
# Keep on screen
|
||||
if pos.x + tooltip.size.x > screen_size.x:
|
||||
pos.x = slot.global_position.x - tooltip.size.x - 10
|
||||
if pos.y + tooltip.size.y > screen_size.y:
|
||||
pos.y = screen_size.y - tooltip.size.y - 10
|
||||
|
||||
tooltip.global_position = pos
|
||||
tooltip.visible = true
|
||||
|
||||
func _hide_tooltip():
|
||||
if tooltip:
|
||||
tooltip.visible = false
|
||||
|
||||
func _on_close():
|
||||
visible = false
|
||||
|
||||
func _input(event):
|
||||
if visible and event.is_action_pressed("escape_menu"):
|
||||
visible = false
|
||||
get_viewport().set_input_as_handled()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dnt1s2c81111q
|
||||
@@ -0,0 +1,54 @@
|
||||
extends Node
|
||||
|
||||
@onready var auth_screen = $AuthScreen
|
||||
@onready var hub_screen = $HubScreen
|
||||
@onready var dungeon_scene = $DungeonScene
|
||||
@onready var death_screen = $DeathScreen
|
||||
|
||||
func _ready():
|
||||
print("[Main] _ready called")
|
||||
_show_screen("AUTH")
|
||||
call_deferred("_setup_signals")
|
||||
|
||||
func _setup_signals():
|
||||
print("[Main] _setup_signals called")
|
||||
if GameState:
|
||||
print("[Main] GameState found, connecting state_changed signal...")
|
||||
GameState.state_changed.connect(_on_state_changed)
|
||||
print("[Main] Signal connected successfully")
|
||||
else:
|
||||
print("[Main] ERROR: GameState autoload not found!")
|
||||
|
||||
func _on_state_changed(new_state: String):
|
||||
print("[Main] _on_state_changed received: ", new_state)
|
||||
_show_screen(new_state)
|
||||
|
||||
func _show_screen(state: String):
|
||||
print("[Main] _show_screen called with: ", state)
|
||||
|
||||
if auth_screen:
|
||||
_set_screen_visible(auth_screen, state == "AUTH")
|
||||
print("[Main] AuthScreen visible: ", state == "AUTH")
|
||||
if hub_screen:
|
||||
_set_screen_visible(hub_screen, state == "HUB")
|
||||
print("[Main] HubScreen visible: ", state == "HUB")
|
||||
if dungeon_scene:
|
||||
_set_screen_visible(dungeon_scene, state == "PLAYING")
|
||||
print("[Main] DungeonScene visible: ", state == "PLAYING")
|
||||
if death_screen:
|
||||
_set_screen_visible(death_screen, state == "DEAD")
|
||||
print("[Main] DeathScreen visible: ", state == "DEAD")
|
||||
|
||||
func _set_screen_visible(node: Node, is_visible: bool):
|
||||
if node == null:
|
||||
return
|
||||
|
||||
if node is CanvasLayer:
|
||||
node.visible = is_visible
|
||||
elif node is CanvasItem:
|
||||
node.visible = is_visible
|
||||
else:
|
||||
node.set_process(is_visible)
|
||||
node.set_physics_process(is_visible)
|
||||
for child in node.get_children():
|
||||
_set_screen_visible(child, is_visible)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dxdsmo8kp5ppi
|
||||
Reference in New Issue
Block a user