item art
This commit is contained in:
@@ -156,14 +156,62 @@ func _refresh_inventory():
|
||||
_update_slot(equipment_slots[slot_name], item, EQUIPMENT_ICONS.get(slot_name, "?"))
|
||||
|
||||
func _update_slot(slot: Button, item, default_text: String = ""):
|
||||
# Clear any existing children (sprites, labels)
|
||||
for child in slot.get_children():
|
||||
child.queue_free()
|
||||
|
||||
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.text = "" # Clear text, we'll use sprite instead
|
||||
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(32, 32)
|
||||
sprite.anchors_preset = Control.PRESET_CENTER
|
||||
sprite.position = Vector2(8, 8) # Center in 48x48 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 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", 10)
|
||||
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.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
|
||||
count_label.anchors_preset = Control.PRESET_BOTTOM_RIGHT
|
||||
count_label.position = Vector2(slot.custom_minimum_size.x - 20, slot.custom_minimum_size.y - 16)
|
||||
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)
|
||||
@@ -261,8 +309,13 @@ func _show_tooltip(item: Dictionary, slot: Button):
|
||||
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))
|
||||
|
||||
name_label.text = item_name
|
||||
# Show quantity in name if > 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:
|
||||
|
||||
Reference in New Issue
Block a user