This commit is contained in:
dingo
2025-12-23 08:32:22 -05:00
parent 7c29268fa4
commit 6a4a64e39e
6 changed files with 195 additions and 41 deletions
+46 -1
View File
@@ -179,6 +179,11 @@ func _update_hotbar():
if i >= hotbar_slots.size():
break
var slot = hotbar_slots[i]
# Clear existing children (sprites, labels)
for child in slot.get_children():
child.queue_free()
var hotbar_entry = GameState.hotbar[i]
if hotbar_entry and hotbar_entry is Dictionary and hotbar_entry.has("inventory_slot"):
@@ -186,7 +191,47 @@ func _update_hotbar():
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)
slot.text = ""
# 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) # Center in slot
# Apply tint if specified
var tint = item.get("tintColor", item.get("TintColor", ""))
if tint and not tint.is_empty():
sprite.modulate = Color.from_string(tint, Color.WHITE)
slot.add_child(sprite)
has_sprite = true
# Fall back to emoji if no sprite
if not has_sprite:
slot.text = _get_item_emoji(item)
# Add stack count label
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.add_theme_constant_override("shadow_offset_x", 1)
count_label.add_theme_constant_override("shadow_offset_y", 1)
count_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
count_label.position = Vector2(slot.custom_minimum_size.x - 18, slot.custom_minimum_size.y - 14)
slot.add_child(count_label)
continue
slot.text = str(i + 1)