diff --git a/scenes/hub/hub_screen.tscn b/scenes/hub/hub_screen.tscn index 4f2353f..0c8e849 100644 --- a/scenes/hub/hub_screen.tscn +++ b/scenes/hub/hub_screen.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://linskq5jx4uh"] +[gd_scene load_steps=6 format=3 uid="uid://linskq5jx4uh"] [ext_resource type="Script" uid="uid://c4v4vw32gyxbl" path="res://scripts/ui/hub_ui.gd" id="1_u7qci"] [ext_resource type="PackedScene" uid="uid://ctsfevsx6nnv2" path="res://scenes/hub/dungeon_browser.tscn" id="2_browser"] -[ext_resource type="PackedScene" path="res://scenes/ui/inventory.tscn" id="3_inventory"] -[ext_resource type="PackedScene" path="res://scenes/ui/crafting_ui.tscn" id="4_crafting"] +[ext_resource type="PackedScene" uid="uid://bwlmaoeg3gbrn" path="res://scenes/ui/inventory.tscn" id="3_inventory"] +[ext_resource type="PackedScene" uid="uid://hsrxtbww60u" path="res://scenes/ui/crafting_ui.tscn" id="4_crafting"] +[ext_resource type="PackedScene" uid="uid://stash_panel_001" path="res://scenes/ui/stash.tscn" id="5_stash"] [node name="HubScreen" type="CanvasLayer"] script = ExtResource("1_u7qci") @@ -123,6 +124,10 @@ text = "Inventory" layout_mode = 2 text = "Crafting" +[node name="StashBtn" type="Button" parent="Control/HBoxContainer/LeftPanel/MenuButtons"] +layout_mode = 2 +text = "Stash ๐Ÿ”" + [node name="RightPanel" type="VBoxContainer" parent="Control/HBoxContainer"] layout_mode = 2 alignment = 2 @@ -159,7 +164,10 @@ layout_mode = 2 text = "Browse Dungeons" [node name="DungeonBrowser" parent="." instance=ExtResource("2_browser")] +visible = false [node name="InventoryUI" parent="." instance=ExtResource("3_inventory")] [node name="CraftingUI" parent="." instance=ExtResource("4_crafting")] + +[node name="StashUI" parent="." instance=ExtResource("5_stash")] diff --git a/scenes/ui/crafting_ui.tscn b/scenes/ui/crafting_ui.tscn index e2530c9..1d4c975 100644 --- a/scenes/ui/crafting_ui.tscn +++ b/scenes/ui/crafting_ui.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=2 format=3 uid="uid://crafting_ui_scene"] +[gd_scene load_steps=2 format=3 uid="uid://hsrxtbww60u"] -[ext_resource type="Script" path="res://scripts/ui/crafting_ui.gd" id="1_crafting"] +[ext_resource type="Script" uid="uid://dht62hol3uhdp" path="res://scripts/ui/crafting_ui.gd" id="1_crafting"] [node name="CraftingUI" type="CanvasLayer"] layer = 10 +visible = false script = ExtResource("1_crafting") [node name="Panel" type="PanelContainer" parent="."] diff --git a/scenes/ui/inventory.tscn b/scenes/ui/inventory.tscn index 43e0863..997fe3f 100644 --- a/scenes/ui/inventory.tscn +++ b/scenes/ui/inventory.tscn @@ -3,6 +3,7 @@ [ext_resource type="Script" uid="uid://dnt1s2c81111q" path="res://scripts/ui/inventory_ui.gd" id="1_s6ek7"] [node name="Inventory" type="CanvasLayer"] +visible = false script = ExtResource("1_s6ek7") [node name="PanelContainer" type="PanelContainer" parent="."] diff --git a/scenes/ui/stash.tscn b/scenes/ui/stash.tscn new file mode 100644 index 0000000..584446e --- /dev/null +++ b/scenes/ui/stash.tscn @@ -0,0 +1,83 @@ +[gd_scene load_steps=2 format=3 uid="uid://stash_panel_001"] + +[ext_resource type="Script" uid="uid://stash_ui_script_001" path="res://scripts/ui/stash_ui.gd" id="1_stash"] + +[node name="Stash" type="CanvasLayer"] +visible = false +script = ExtResource("1_stash") + +[node name="PanelContainer" type="PanelContainer" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -250.0 +offset_top = -200.0 +offset_right = 250.0 +offset_bottom = 200.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] +layout_mode = 2 + +[node name="Header" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="Title" type="Label" parent="PanelContainer/VBoxContainer/Header"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "๐Ÿ”’ Stash (VIP Feature)" + +[node name="CloseButton" type="Button" parent="PanelContainer/VBoxContainer/Header"] +layout_mode = 2 +text = "X" + +[node name="VIPMessage" type="Label" parent="PanelContainer/VBoxContainer"] +visible = false +layout_mode = 2 +text = "Stash is a VIP-only feature. Upgrade your account to access secure item storage!" +autowrap_mode = 2 +horizontal_alignment = 1 + +[node name="Content" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="InventorySection" type="VBoxContainer" parent="PanelContainer/VBoxContainer/Content"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/Content/InventorySection"] +layout_mode = 2 +text = "๐Ÿ“ฆ Inventory" + +[node name="InventoryGrid" type="GridContainer" parent="PanelContainer/VBoxContainer/Content/InventorySection"] +layout_mode = 2 +size_flags_vertical = 3 +columns = 5 + +[node name="VSeparator" type="VSeparator" parent="PanelContainer/VBoxContainer/Content"] +layout_mode = 2 + +[node name="StashSection" type="VBoxContainer" parent="PanelContainer/VBoxContainer/Content"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/Content/StashSection"] +layout_mode = 2 +text = "๐Ÿ” Stash (50 Slots)" + +[node name="StashGrid" type="GridContainer" parent="PanelContainer/VBoxContainer/Content/StashSection"] +layout_mode = 2 +size_flags_vertical = 3 +columns = 5 + +[node name="Footer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="HelpLabel" type="Label" parent="PanelContainer/VBoxContainer/Footer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Right-click: Deposit/Withdraw" diff --git a/scripts/autoload/game_state.gd b/scripts/autoload/game_state.gd index 1822eaa..57400bf 100644 --- a/scripts/autoload/game_state.gd +++ b/scripts/autoload/game_state.gd @@ -18,6 +18,8 @@ signal crafting_skills_updated(skills: Dictionary) signal crafting_recipes_updated(recipes: Array) signal crafting_result_received(result: Dictionary) signal recipe_discovered(recipe: Dictionary) +signal stash_updated(stash_data: Dictionary) +signal stash_result(result: Dictionary) # Use constants instead of enum to avoid type issues const STATE_AUTH = 0 @@ -73,6 +75,10 @@ var inventory: Array = [] var equipment: Dictionary = {} var hotbar: Array = [null, null, null, null, null, null, null, null] +# Stash (VIP Feature) +var stash: Dictionary = {"slots": 0, "items": []} +var is_vip: bool = false + # Escape var is_escaping: bool = false var escape_start_time: int = 0 @@ -115,8 +121,9 @@ func _on_message_received(opcode: int, data: Dictionary): print("[GameState] >>> LOOT_RECEIVED opcode matched! <<<") _handle_loot_received(data) OpCodes.CHAT_MESSAGE: - print("[GameState] >>> CHAT_MESSAGE opcode matched! <<<") _handle_chat_message(data) + OpCodes.SERVER_BROADCAST: + _handle_server_broadcast(data) OpCodes.ESCAPE_INTERRUPTED: print("[OpCodes]PlayerEscape] Interrupted.") is_escaping = false @@ -152,6 +159,10 @@ func _on_message_received(opcode: int, data: Dictionary): _handle_recipe_discovered(data) OpCodes.CRAFTING_SKILL_LEVELUP: _handle_crafting_skill_levelup(data) + OpCodes.STASH_STATE: + _handle_stash_state(data) + OpCodes.STASH_RESULT: + _handle_stash_result(data) _: print("[GameState] Unhandled opcode: ", opcode) @@ -377,19 +388,28 @@ func _handle_loot_received(data: Dictionary): Network.send_message(OpCodes.INVENTORY_REQUEST, {}) func _handle_chat_message(data: Dictionary): - print("[GameState] _handle_chat_message called with: ", data) var sender = data.get("sender", data.get("Sender", data.get("playerName", data.get("PlayerName", "Unknown")))) var message = data.get("message", data.get("Message", data.get("text", data.get("Text", "")))) var type = data.get("type", data.get("Type", data.get("channel", data.get("Channel", "normal")))) - print("[GameState] Chat parsed - Sender: '%s', Message: '%s', Type: '%s'" % [sender, message, type]) - chat_messages.append({"sender": sender, "message": message, "type": type}) if chat_messages.size() > 100: chat_messages.pop_front() - print("[GameState] Emitting chat_message_received signal") chat_message_received.emit(sender, message, type) +func _handle_server_broadcast(data: Dictionary): + var message = data.get("message", data.get("Message", "")) + var msg_type = data.get("type", data.get("Type", "system")) + + print("[GameState] Server broadcast received: [%s] %s" % [msg_type, message]) + + # Broadcast messages appear in chat with [Server] prefix + var sender = "[Server]" + chat_messages.append({"sender": sender, "message": message, "type": msg_type}) + if chat_messages.size() > 100: + chat_messages.pop_front() + chat_message_received.emit(sender, message, msg_type) + func _handle_damage(_data: Dictionary): pass @@ -609,3 +629,36 @@ func send_discover_recipe_with_skill(ingredients: Array, skill_type: int): "Discover": true, "SkillType": skill_type }) + +# Stash functions +func _handle_stash_state(data: Dictionary): + stash.slots = int(data.get("slots", data.get("Slots", 50))) + stash.items = data.get("items", data.get("Items", [])) + is_vip = true # If we got stash state, we're VIP + stash_updated.emit(stash) + +func _handle_stash_result(data: Dictionary): + var success = data.get("success", data.get("Success", false)) + var error = data.get("error", data.get("Error", "")) + var message = data.get("message", data.get("Message", "")) + + if error == "vip_required": + is_vip = false + + stash_result.emit({"success": success, "error": error, "message": message}) + +func request_stash(): + Network.send_message(OpCodes.STASH_REQUEST, {}) + +func stash_deposit(inventory_slot: int, quantity: int = 1, target_slot: int = -1): + Network.send_message(OpCodes.STASH_DEPOSIT, { + "inventorySlot": inventory_slot, + "quantity": quantity, + "targetSlot": target_slot + }) + +func stash_withdraw(stash_slot: int, quantity: int = 1): + Network.send_message(OpCodes.STASH_WITHDRAW, { + "stashSlot": stash_slot, + "quantity": quantity + }) diff --git a/scripts/autoload/opcodes.gd b/scripts/autoload/opcodes.gd index f3af291..777e535 100644 --- a/scripts/autoload/opcodes.gd +++ b/scripts/autoload/opcodes.gd @@ -82,5 +82,15 @@ const EVENT_DEATH = 501 const EVENT_LEVELUP = 502 const EVENT_LOOT = 503 +# Server Broadcast +const SERVER_BROADCAST = 600 + +# Stash (VIP Feature) +const STASH_REQUEST = 610 +const STASH_STATE = 611 +const STASH_DEPOSIT = 612 +const STASH_WITHDRAW = 613 +const STASH_RESULT = 614 + # Legacy const LOOT_RECEIVED = 160 diff --git a/scripts/dungeon/mob_visual.gd b/scripts/dungeon/mob_visual.gd index 010858a..ff221ea 100644 --- a/scripts/dungeon/mob_visual.gd +++ b/scripts/dungeon/mob_visual.gd @@ -12,14 +12,14 @@ var mob_data: Dictionary = {} var _sprite_config: Dictionary = {} # Animation config from server var _animated_sprite: AnimatedSprite2D = null var _using_fallback: bool = true +var _initialized: bool = false # Track if we've already set up this mob +var _last_animation: String = "" # Track animation to avoid spam # Animation state var _current_state: String = "idle" var _facing_direction: String = "down" # down, up, left, right, front, back func _ready(): - print("[MobVisual] _ready called!") - # Try to find child nodes (they may not exist in all mob scenes) fallback_sprite = get_node_or_null("Sprite2D") name_label = get_node_or_null("NameLabel") @@ -52,9 +52,6 @@ func _ready(): # Connect to UpdateManager for async texture loading if UpdateManager: UpdateManager.file_downloaded.connect(_on_file_downloaded) - print("[MobVisual] Connected to UpdateManager") - else: - print("[MobVisual] WARNING: UpdateManager is null!") func update_data(data: Dictionary): mob_data = data @@ -71,36 +68,31 @@ func update_data(data: Dictionary): health_bar.max_value = max_hp health_bar.value = hp - # Get sprite config (sent from server with mob data) - var sprite_config = data.get("spriteConfig", data.get("SpriteConfig", null)) - - # Debug: print what we received - if sprite_config != null: - print("[MobVisual] %s received spriteConfig: %s" % [mname, sprite_config]) - else: - print("[MobVisual] %s has NO spriteConfig" % mname) - - if sprite_config != null and sprite_config is Dictionary and not sprite_config.is_empty(): - if sprite_config != _sprite_config: - _sprite_config = sprite_config - _build_animated_sprite() - elif _using_fallback: - _setup_fallback(data) + # Only process sprite config on first update or if it changed + if not _initialized: + var sprite_config = data.get("spriteConfig", data.get("SpriteConfig", null)) + + if sprite_config != null and sprite_config is Dictionary and not sprite_config.is_empty(): + if sprite_config != _sprite_config: + _sprite_config = sprite_config + _build_animated_sprite() + else: + _setup_fallback(data) + + _initialized = true # Update visual state var state = data.get("state", data.get("State", "idle")).to_lower() var rotation = data.get("rotation", data.get("Rotation", 0.0)) _update_animation_state(state, rotation) - # Apply tint - var tint = data.get("tintColor", data.get("TintColor", "#ffffff")) - _apply_tint(tint) + # Apply tint (only on first setup) + if not _initialized: + var tint = data.get("tintColor", data.get("TintColor", "#ffffff")) + _apply_tint(tint) # Apply scale var mob_scale = data.get("scale", data.get("Scale", 1.0)) - print("[MobVisual] Raw scale from data: %s (type: %s)" % [mob_scale, typeof(mob_scale)]) - - # Ensure scale is valid (at least 1.0 if 0 or invalid) if mob_scale == null or mob_scale <= 0: mob_scale = 1.0 @@ -111,14 +103,10 @@ func update_data(data: Dictionary): func _build_animated_sprite(): ## Build AnimatedSprite2D from sprite config - - print("[MobVisual] _build_animated_sprite called for %s" % mob_data.get("name", "unknown")) - + var mname = mob_data.get("name", "unknown") var sprites = _sprite_config.get("sprites", {}) - print("[MobVisual] sprites dict type: %s, value: %s" % [typeof(sprites), sprites]) if sprites == null or not sprites is Dictionary or sprites.is_empty(): - print("[MobVisual] No sprites in config, using fallback") _setup_fallback(mob_data) return @@ -127,25 +115,14 @@ func _build_animated_sprite(): var missing_files = [] for anim_name in sprites: var sprite_path = sprites[anim_name] - print("[MobVisual] Checking texture: %s" % sprite_path) - if not UpdateManager: - print("[MobVisual] UpdateManager is null!") + if not UpdateManager or not UpdateManager.has_file(sprite_path): all_cached = false missing_files.append(sprite_path) - elif not UpdateManager.has_file(sprite_path): - print("[MobVisual] File NOT in cache: %s" % sprite_path) - all_cached = false - missing_files.append(sprite_path) - else: - print("[MobVisual] File IS in cache: %s" % sprite_path) if not all_cached: - print("[MobVisual] Missing textures: %s" % missing_files) _setup_fallback(mob_data) return - print("[MobVisual] All textures cached, building AnimatedSprite2D") - # Create or reuse AnimatedSprite2D if not _animated_sprite: _animated_sprite = AnimatedSprite2D.new() @@ -164,21 +141,14 @@ func _build_animated_sprite(): var texture = UpdateManager.load_texture(sprite_path) if not texture: - push_warning("[MobVisual] Failed to load texture: %s" % sprite_path) continue - print("[MobVisual] Loaded texture %s: size=%dx%d" % [anim_name, texture.get_width(), texture.get_height()]) - # Get animation config var anim_config = animations.get(anim_name, {"frames": 1, "loop": true}) var frame_count = anim_config.get("frames", 1) var loop = anim_config.get("loop", true) - - # frame_count might be a float from JSON, convert to int frame_count = int(frame_count) - print("[MobVisual] Animation %s: frame_count=%d, loop=%s" % [anim_name, frame_count, loop]) - # Add animation sprite_frames.add_animation(anim_name) sprite_frames.set_animation_speed(anim_name, fps) @@ -189,8 +159,6 @@ func _build_animated_sprite(): var calculated_frames = int(tex_width / frame_width) if frame_width > 0 else 1 frame_count = min(frame_count, calculated_frames) - print("[MobVisual] Texture width=%d, frame_width=%d, calculated_frames=%d, using frame_count=%d" % [tex_width, frame_width, calculated_frames, frame_count]) - for i in range(frame_count): var atlas = AtlasTexture.new() atlas.atlas = texture @@ -199,26 +167,17 @@ func _build_animated_sprite(): _animated_sprite.sprite_frames = sprite_frames _animated_sprite.visible = true - _animated_sprite.z_index = 10 # Make sure it's on top - _animated_sprite.modulate = Color.WHITE # Ensure full visibility - _animated_sprite.position = Vector2.ZERO # Centered on parent + _animated_sprite.z_index = 10 + _animated_sprite.modulate = Color.WHITE + _animated_sprite.position = Vector2.ZERO _using_fallback = false - print("[MobVisual] AnimatedSprite2D position: %s, scale: %s, modulate: %s" % [_animated_sprite.position, _animated_sprite.scale, _animated_sprite.modulate]) - # Hide fallback if fallback_sprite: fallback_sprite.visible = false # Play default animation _update_animation_state(_current_state, 0.0) - - # Debug: print the animation that should be playing - print("[MobVisual] Built animated sprite with %d animations, current animation: %s, visible: %s" % [ - sprites.size(), - _animated_sprite.animation if _animated_sprite.sprite_frames else "none", - _animated_sprite.visible - ]) func _on_file_downloaded(file_path: String): # Check if this is a texture we need @@ -261,18 +220,16 @@ func _update_animation_state(state: String, rotation: float): func _rotation_to_direction(rotation: float) -> String: # Convert rotation (radians) to cardinal direction - # 0 = right, PI/2 = down, PI = left, -PI/2 = up - var angle = fmod(rotation + TAU, TAU) # Normalize to 0-2PI + var angle = fmod(rotation + TAU, TAU) - # Map to front/back/left/right (common sprite sheet naming) if angle < PI * 0.25 or angle >= PI * 1.75: return "right" elif angle < PI * 0.75: - return "front" # or "down" + return "front" elif angle < PI * 1.25: return "left" else: - return "back" # or "up" + return "back" func _play_animation(state: String, direction: String): if not _animated_sprite or not _animated_sprite.sprite_frames: @@ -282,28 +239,26 @@ func _play_animation(state: String, direction: String): # Try different animation name formats var names_to_try = [ - "%s_%s" % [state, direction], # "idle_front" - "%s_%s" % [state, _alt_direction(direction)], # "idle_down" - state, # "idle" - "idle_%s" % direction, # fallback to idle + "%s_%s" % [state, direction], + "%s_%s" % [state, _alt_direction(direction)], + state, + "idle_%s" % direction, "idle_%s" % _alt_direction(direction), "idle" ] for anim_name in names_to_try: if frames.has_animation(anim_name): - print("[MobVisual] Playing animation: %s (current: %s, playing: %s)" % [anim_name, _animated_sprite.animation, _animated_sprite.is_playing()]) - _animated_sprite.play(anim_name) + # Only log and play if animation changed + if anim_name != _last_animation: + _last_animation = anim_name + _animated_sprite.play(anim_name) # Handle left direction with flip _animated_sprite.flip_h = (direction == "left" and not frames.has_animation("%s_left" % state)) return - - # No matching animation found - push_warning("[MobVisual] No animation found for state=%s direction=%s, available: %s" % [state, direction, frames.get_animation_names()]) func _alt_direction(dir: String) -> String: - # Alternative direction names match dir: "front": return "down" "back": return "up" @@ -315,7 +270,6 @@ func _update_fallback_state(state: String): if not fallback_sprite: return - # Simple color changes for fallback match state: "attacking": fallback_sprite.modulate = fallback_sprite.modulate.lightened(0.3) diff --git a/scripts/ui/hub_ui.gd b/scripts/ui/hub_ui.gd index 66fb2d7..56db0fc 100644 --- a/scripts/ui/hub_ui.gd +++ b/scripts/ui/hub_ui.gd @@ -18,8 +18,10 @@ extends CanvasLayer @onready var inventory_btn = $Control/HBoxContainer/LeftPanel/MenuButtons/InventoryBtn @onready var crafting_btn = $Control/HBoxContainer/LeftPanel/MenuButtons/CraftingBtn +@onready var stash_btn = $Control/HBoxContainer/LeftPanel/MenuButtons/StashBtn @onready var inventory_ui = $InventoryUI @onready var crafting_ui = $CraftingUI +@onready var stash_ui = $StashUI var selected_tier: int = 1 @@ -30,11 +32,13 @@ func _ready(): if browse_btn: browse_btn.pressed.connect(_on_browse_dungeons) - # Setup inventory and crafting buttons + # 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) # Setup tier buttons for i in range(1, 6): @@ -119,3 +123,7 @@ func _on_inventory_pressed(): func _on_crafting_pressed(): if crafting_ui: crafting_ui.show_crafting() + +func _on_stash_pressed(): + if stash_ui: + stash_ui.show_stash() diff --git a/scripts/ui/stash_ui.gd b/scripts/ui/stash_ui.gd new file mode 100644 index 0000000..e2fb66c --- /dev/null +++ b/scripts/ui/stash_ui.gd @@ -0,0 +1,343 @@ +extends CanvasLayer + +## Stash UI +## VIP feature for secure item storage between dungeon runs + +@onready var close_button = $PanelContainer/VBoxContainer/Header/CloseButton +@onready var title_label = $PanelContainer/VBoxContainer/Header/Title +@onready var vip_message = $PanelContainer/VBoxContainer/VIPMessage +@onready var content = $PanelContainer/VBoxContainer/Content +@onready var inventory_grid = $PanelContainer/VBoxContainer/Content/InventorySection/InventoryGrid +@onready var stash_grid = $PanelContainer/VBoxContainer/Content/StashSection/StashGrid + +const INVENTORY_DISPLAY_SLOTS = 30 +const STASH_SLOTS = 50 + +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 stash_slots: Array = [] +var tooltip: PanelContainer = null +var is_vip: bool = false + +func _ready(): + visible = false + + if close_button: + close_button.pressed.connect(_on_close) + + _setup_inventory_slots() + _setup_stash_slots() + _create_tooltip() + + call_deferred("_connect_gamestate") + +func _connect_gamestate(): + if GameState: + GameState.inventory_updated.connect(_refresh_inventory) + GameState.stash_updated.connect(_on_stash_updated) + GameState.stash_result.connect(_on_stash_result) + +func _setup_inventory_slots(): + if not inventory_grid: + return + for i in range(INVENTORY_DISPLAY_SLOTS): + 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_slot_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 _setup_stash_slots(): + if not stash_grid: + return + for i in range(STASH_SLOTS): + var slot = _create_slot_button() + slot.set_meta("slot_type", "stash") + slot.set_meta("slot_index", i) + slot.set_meta("item", null) + slot.gui_input.connect(_on_stash_slot_input.bind(i)) + slot.mouse_entered.connect(_on_slot_hover.bind(slot)) + slot.mouse_exited.connect(_hide_tooltip) + stash_grid.add_child(slot) + stash_slots.append(slot) + +func _create_slot_button() -> Button: + var btn = Button.new() + btn.custom_minimum_size = Vector2(40, 40) + 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 stats_label = Label.new() + stats_label.name = "ItemStats" + stats_label.add_theme_font_size_override("font_size", 12) + vbox.add_child(stats_label) + + tooltip.add_child(vbox) + tooltip.visible = false + add_child(tooltip) + +func show_stash(): + visible = true + # Request stash from server + if GameState: + GameState.request_stash() + +func _on_stash_updated(stash_data: Dictionary): + is_vip = true + _update_vip_state(true) + _refresh_stash(stash_data) + +func _on_stash_result(result: Dictionary): + var success = result.get("success", false) + var error = result.get("error", "") + var message = result.get("message", "") + + if error == "vip_required": + is_vip = false + _update_vip_state(false) + + # Could show a toast/notification here + if not success and message: + print("[Stash] Error: ", message) + +func _update_vip_state(is_vip_status: bool): + if vip_message: + vip_message.visible = not is_vip_status + if content: + content.visible = is_vip_status + if title_label: + title_label.text = "๐Ÿ” Stash (VIP Feature)" if is_vip_status else "๐Ÿ”’ Stash (VIP Required)" + +func _refresh_inventory(): + for i in range(INVENTORY_DISPLAY_SLOTS): + if i >= inventory_slots.size(): + break + var item = GameState.inventory[i] if i < GameState.inventory.size() else null + _update_slot(inventory_slots[i], item) + +func _refresh_stash(stash_data: Dictionary): + var items = stash_data.get("items", []) + + # Clear all stash slots first + for slot in stash_slots: + _update_slot(slot, null) + + # Fill in items at their slots + for item_data in items: + var slot_index = int(item_data.get("slotIndex", item_data.get("SlotIndex", -1))) + if slot_index >= 0 and slot_index < stash_slots.size(): + # Merge definition data into item_data for display + var definition = item_data.get("definition", item_data.get("Definition", {})) + var merged_item = item_data.duplicate() + if definition: + for key in definition: + merged_item[key] = definition[key] + _update_slot(stash_slots[slot_index], merged_item) + +func _update_slot(slot: Button, item): + # Clear any existing children + for child in slot.get_children(): + child.queue_free() + + if item == null or (item is Dictionary and item.is_empty()): + slot.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 = "" + slot.set_meta("item", item) + + # Try to load sprite from CDN + var sprite_path = item.get("spritePath", item.get("SpritePath", "")) + var has_sprite = false + + if sprite_path and not sprite_path.is_empty() and UpdateManager: + var texture = UpdateManager.load_texture(sprite_path) + if texture: + var sprite = TextureRect.new() + sprite.texture = texture + sprite.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL + sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED + sprite.custom_minimum_size = Vector2(28, 28) + sprite.position = Vector2(6, 6) + slot.add_child(sprite) + has_sprite = true + + if not has_sprite: + slot.text = _get_item_emoji(item) + + # Add stack count label if quantity > 1 + var quantity = item.get("quantity", item.get("Quantity", 1)) + if quantity > 1: + var count_label = Label.new() + count_label.text = str(quantity) + count_label.add_theme_font_size_override("font_size", 9) + count_label.add_theme_color_override("font_color", Color.WHITE) + count_label.add_theme_color_override("font_shadow_color", Color.BLACK) + count_label.position = Vector2(slot.custom_minimum_size.x - 16, slot.custom_minimum_size.y - 14) + slot.add_child(count_label) + + # Style based on rarity + 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() + match item_type: + "consumable": return "๐Ÿงช" + "material": return "๐Ÿ“ฆ" + "weapon": return "โš”๏ธ" + "armor": return "๐Ÿ›ก๏ธ" + "accessory": return "๐Ÿ’" + _: return "โ“" + +func _on_inventory_slot_input(event: InputEvent, slot_index: int): + if not event is InputEventMouseButton: + return + if not event.pressed: + return + + var item = GameState.inventory[slot_index] if slot_index < GameState.inventory.size() else null + if item == null or (item is Dictionary and item.is_empty()): + return + + if event.button_index == MOUSE_BUTTON_RIGHT: + # Right-click to deposit to stash + var quantity = item.get("quantity", item.get("Quantity", 1)) + GameState.stash_deposit(slot_index, quantity) + +func _on_stash_slot_input(event: InputEvent, slot_index: int): + if not event is InputEventMouseButton: + return + if not event.pressed: + return + + var slot = stash_slots[slot_index] if slot_index < stash_slots.size() else null + if slot == null: + return + + var item = slot.get_meta("item") + if item == null: + return + + if event.button_index == MOUSE_BUTTON_RIGHT: + # Right-click to withdraw from stash + var quantity = item.get("quantity", item.get("Quantity", 1)) + GameState.stash_withdraw(slot_index, quantity) + +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") + + 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", "")) + var quantity = item.get("quantity", item.get("Quantity", 1)) + + if quantity > 1: + name_label.text = "%s (x%d)" % [item_name, quantity] + else: + 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] + + if stats_label: + stats_label.text = "" + + # Position tooltip + 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) + + 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() diff --git a/scripts/ui/stash_ui.gd.uid b/scripts/ui/stash_ui.gd.uid new file mode 100644 index 0000000..29a89ba --- /dev/null +++ b/scripts/ui/stash_ui.gd.uid @@ -0,0 +1 @@ +uid://3dbs5pxnkxkn