fixat mer med traps och arrows och grejjer
This commit is contained in:
@@ -38,6 +38,11 @@ var equipment_selection_index: int = 0 # Current equipment slot index (0-5: main
|
||||
@onready var sfx_food: AudioStreamPlayer2D = $SfxFood
|
||||
@onready var sfx_armour: AudioStreamPlayer2D = $SfxArmour
|
||||
|
||||
# Weight UI elements (created programmatically)
|
||||
var weight_container: HBoxContainer = null
|
||||
var weight_label: Label = null
|
||||
var weight_progress_bar: ProgressBar = null
|
||||
|
||||
# Store button/item mappings for selection highlighting
|
||||
var inventory_buttons: Dictionary = {} # item -> button
|
||||
var equipment_buttons: Dictionary = {} # slot_name -> button
|
||||
@@ -75,6 +80,9 @@ func _ready():
|
||||
# Create equipment slot buttons (dynamically)
|
||||
_create_equipment_slots()
|
||||
|
||||
# Create weight progress bar
|
||||
_create_weight_ui()
|
||||
|
||||
# Setup selection rectangle (already in scene, just configure it)
|
||||
_setup_selection_rectangle()
|
||||
|
||||
@@ -185,9 +193,26 @@ func _update_stats():
|
||||
str(char_stats.defense) + "\n" + \
|
||||
str(char_stats.move_speed) + "\n" + \
|
||||
str(char_stats.attack_speed) + "\n" + \
|
||||
str(char_stats.sight) + "\n" + \
|
||||
str(char_stats.spell_amp) + "\n" + \
|
||||
str(char_stats.crit_chance) + "%"
|
||||
str(char_stats.sight)
|
||||
|
||||
# Update weight progress bar
|
||||
if weight_progress_bar and weight_label:
|
||||
var current_weight = char_stats.get_total_weight()
|
||||
var max_weight = char_stats.get_carrying_capacity()
|
||||
weight_progress_bar.max_value = max_weight
|
||||
weight_progress_bar.value = current_weight
|
||||
weight_label.text = "Weight: " + str(int(current_weight)) + "/" + str(int(max_weight))
|
||||
|
||||
# Change color based on weight (green -> yellow -> red)
|
||||
var weight_ratio = current_weight / max_weight
|
||||
var fill_style = StyleBoxFlat.new()
|
||||
if weight_ratio < 0.7:
|
||||
fill_style.bg_color = Color(0.6, 0.8, 0.3) # Green
|
||||
elif weight_ratio < 0.9:
|
||||
fill_style.bg_color = Color(0.9, 0.8, 0.2) # Yellow
|
||||
else:
|
||||
fill_style.bg_color = Color(0.9, 0.3, 0.2) # Red
|
||||
weight_progress_bar.add_theme_stylebox_override("fill", fill_style)
|
||||
|
||||
func _create_equipment_slots():
|
||||
# Equipment slot order: mainhand, offhand, headgear, armour, boots, accessory
|
||||
@@ -244,6 +269,46 @@ func _create_equipment_slots():
|
||||
equipment_slots[slot_name] = button
|
||||
equipment_buttons[slot_name] = button
|
||||
|
||||
func _create_weight_ui():
|
||||
# Create weight display (label + progress bar)
|
||||
if not stats_panel:
|
||||
return
|
||||
|
||||
# Create container for weight UI
|
||||
weight_container = HBoxContainer.new()
|
||||
weight_container.name = "WeightContainer"
|
||||
weight_container.add_theme_constant_override("separation", 4)
|
||||
|
||||
# Create label
|
||||
weight_label = Label.new()
|
||||
weight_label.text = "Weight:"
|
||||
weight_label.add_theme_font_size_override("font_size", 10)
|
||||
if ResourceLoader.exists("res://assets/fonts/standard_font.png"):
|
||||
var font_resource = load("res://assets/fonts/standard_font.png")
|
||||
if font_resource:
|
||||
weight_label.add_theme_font_override("font", font_resource)
|
||||
weight_container.add_child(weight_label)
|
||||
|
||||
# Create progress bar
|
||||
weight_progress_bar = ProgressBar.new()
|
||||
weight_progress_bar.custom_minimum_size = Vector2(100, 12)
|
||||
weight_progress_bar.show_percentage = false
|
||||
# Style the progress bar
|
||||
var progress_style = StyleBoxFlat.new()
|
||||
progress_style.bg_color = Color(0.2, 0.2, 0.2, 0.8)
|
||||
progress_style.border_color = Color(0.4, 0.4, 0.4)
|
||||
progress_style.set_border_width_all(1)
|
||||
weight_progress_bar.add_theme_stylebox_override("background", progress_style)
|
||||
|
||||
var fill_style = StyleBoxFlat.new()
|
||||
fill_style.bg_color = Color(0.6, 0.8, 0.3) # Green color
|
||||
weight_progress_bar.add_theme_stylebox_override("fill", fill_style)
|
||||
|
||||
weight_container.add_child(weight_progress_bar)
|
||||
|
||||
# Add to stats panel (after stats labels)
|
||||
stats_panel.add_child(weight_container)
|
||||
|
||||
func _has_equipment_in_slot(slot_name: String) -> bool:
|
||||
# Check if there's an item equipped in this slot
|
||||
if not local_player or not local_player.character_stats:
|
||||
@@ -453,14 +518,20 @@ func _update_ui():
|
||||
if equipped_item.can_have_multiple_of and equipped_item.quantity > 1:
|
||||
var quantity_label = Label.new()
|
||||
quantity_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
quantity_label.size = Vector2(24, 24)
|
||||
quantity_label.custom_minimum_size = Vector2(0, 0)
|
||||
quantity_label.position = Vector2(10, 2)
|
||||
quantity_label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
|
||||
quantity_label.size = Vector2(36, 36)
|
||||
quantity_label.custom_minimum_size = Vector2(36, 36)
|
||||
quantity_label.position = Vector2(0, 0)
|
||||
quantity_label.text = str(equipped_item.quantity)
|
||||
if quantity_font:
|
||||
quantity_label.add_theme_font_override("font", quantity_font)
|
||||
quantity_label.add_theme_font_size_override("font_size", 8)
|
||||
quantity_label.scale = Vector2(0.5, 0.5)
|
||||
# Use dmg_numbers.png font (same as inventory items)
|
||||
var dmg_font_resource = load("res://assets/fonts/dmg_numbers.png")
|
||||
if dmg_font_resource:
|
||||
var font_file = FontFile.new()
|
||||
font_file.font_data = dmg_font_resource
|
||||
quantity_label.add_theme_font_override("font", font_file)
|
||||
quantity_label.add_theme_font_size_override("font_size", 16)
|
||||
quantity_label.z_index = 100 # High z-index to show above item sprite
|
||||
quantity_label.z_as_relative = false # Absolute z-index
|
||||
button.add_child(quantity_label)
|
||||
|
||||
# Update inventory grid - clear existing HBoxContainers
|
||||
@@ -727,6 +798,13 @@ func _format_item_info(item: Item) -> String:
|
||||
text += ", ".join(stat_lines)
|
||||
text += "\n\n"
|
||||
|
||||
# Weight
|
||||
var item_weight = item.weight
|
||||
if item.can_have_multiple_of:
|
||||
item_weight *= item.quantity
|
||||
text += "Weight: %.1f" % item_weight
|
||||
text += "\n\n"
|
||||
|
||||
# Controls
|
||||
if item.item_type == Item.ItemType.Equippable:
|
||||
if selected_type == "equipment":
|
||||
@@ -903,6 +981,7 @@ func _on_inventory_item_pressed(item: Item):
|
||||
|
||||
_update_selection_highlight()
|
||||
_update_selection_rectangle()
|
||||
_update_info_panel() # Show item description on single-click
|
||||
|
||||
func _on_inventory_item_gui_input(event: InputEvent, item: Item):
|
||||
# Handle double-click to equip/consume and right-click to drop
|
||||
|
||||
Reference in New Issue
Block a user