try to fix some stuff

This commit is contained in:
2026-01-26 07:36:23 +01:00
parent 913e5c4418
commit dabec8a119
39 changed files with 3297 additions and 427 deletions

View File

@@ -84,13 +84,13 @@ var level_up_stat_buttons: Array = [] # Buttons for STR, DEX, INT, END, WIS, LCK
var level_up_stat_container: HBoxContainer = null
var selected_level_up_stat_index: int = -1
const STAT_DESCRIPTIONS: Dictionary = {
"str": "STR: Physical damage, carry capacity.",
"dex": "DEX: Dodge, hit chance, move & attack speed.",
"int": "INT: Spell damage, mana, sight.",
"end": "END: Max HP.",
"wis": "WIS: Mana regen, resistances.",
"lck": "LCK: Critical hit chance.",
"per": "PER: Trap detection, perception."
"str": "STR (Strength): Increases melee and bow damage. Raises carry capacity so you can hold more items before becoming encumbered.",
"dex": "DEX (Dexterity): Improves dodge chance and hit chance. Makes you move and attack faster.",
"int": "INT (Intelligence): Boosts spell damage (flames, frost, heal). Increases max mana and vision range.",
"end": "END (Endurance): Increases max HP. Each point raises your maximum health.",
"wis": "WIS (Wisdom): Improves mana regeneration and resistances to certain effects.",
"lck": "LCK (Luck): Increases critical hit chance. Critical hits deal bonus damage and partially ignore defense.",
"per": "PER (Perception): Improves trap detection and perception. Helps you spot hazards and secrets."
}
# Equipment slot buttons
@@ -331,6 +331,9 @@ func _setup_level_up_ui() -> void:
btn.text = stat_name.to_upper()
btn.custom_minimum_size = Vector2(32, 24)
btn.flat = true
btn.add_theme_color_override("font_color", Color(0.85, 0.85, 0.85))
btn.add_theme_color_override("font_hover_color", Color(0.4, 1.0, 0.5))
btn.add_theme_color_override("font_focus_color", Color(0.4, 1.0, 0.5))
if ResourceLoader.exists("res://assets/fonts/standard_font.png"):
var fr = load("res://assets/fonts/standard_font.png")
if fr:
@@ -341,6 +344,7 @@ func _setup_level_up_ui() -> void:
btn.mouse_entered.connect(_on_level_up_stat_hover_entered.bind(stat_name))
btn.mouse_exited.connect(_on_level_up_stat_hover_exited)
btn.gui_input.connect(_on_level_up_stat_gui_input.bind(stat_name, btn))
btn.focus_entered.connect(_on_level_up_stat_focus_entered.bind(stat_name))
level_up_stat_container.add_child(btn)
level_up_stat_buttons.append(btn)
stats_panel.add_child(level_up_stat_container)
@@ -349,6 +353,8 @@ func _setup_level_up_ui() -> void:
func _on_level_up_stat_pressed(stat_name: String) -> void:
if not local_player or not local_player.character_stats:
return
if not _can_use_inventory():
return
if local_player.character_stats.allocate_stat_point(stat_name):
if sfx_armour:
sfx_armour.play()
@@ -375,10 +381,23 @@ func _on_level_up_stat_hover_entered(stat_name: String) -> void:
info_label.text = STAT_DESCRIPTIONS[stat_name]
func _on_level_up_stat_hover_exited() -> void:
if info_label:
_update_info_panel()
if not info_label:
return
var fc = get_viewport().gui_get_focus_owner()
if level_up_stat_container and fc and is_instance_valid(level_up_stat_container) and fc.get_parent() == level_up_stat_container:
var idx = level_up_stat_buttons.find(fc)
if idx >= 0 and idx < CharacterStats.LEVEL_UP_STAT_NAMES.size():
var sn = CharacterStats.LEVEL_UP_STAT_NAMES[idx]
if sn in STAT_DESCRIPTIONS:
info_label.text = STAT_DESCRIPTIONS[sn]
return
_update_info_panel()
func _on_level_up_stat_gui_input(event: InputEvent, stat_name: String, btn: Button) -> void:
func _on_level_up_stat_focus_entered(stat_name: String) -> void:
if info_label and stat_name in STAT_DESCRIPTIONS:
info_label.text = STAT_DESCRIPTIONS[stat_name]
func _on_level_up_stat_gui_input(event: InputEvent, stat_name: String, _btn: Button) -> void:
if event is InputEventKey and event.pressed and not event.echo:
if event.keycode == KEY_ENTER or event.keycode == KEY_KP_ENTER or event.keycode == KEY_SPACE:
_on_level_up_stat_pressed(stat_name)
@@ -573,6 +592,16 @@ func _has_equipment_in_slot(slot_name: String) -> bool:
return false
return local_player.character_stats.equipment[slot_name] != null
func _can_use_inventory() -> bool:
# Block equip/unequip/use/drop/level-up when dead
if not local_player:
return false
if "is_dead" in local_player and local_player.is_dead:
return false
if "is_processing_death" in local_player and local_player.is_processing_death:
return false
return true
func _find_next_filled_equipment_slot(start_index: int, direction: int) -> int:
# Find next filled equipment slot, or -1 if none found
var current_index = start_index
@@ -1110,11 +1139,22 @@ func _navigate_inventory(direction: String):
if inventory_selection_col > 0:
inventory_selection_col -= 1
else:
# Wrap to end of previous row
if inventory_selection_row > 0:
inventory_selection_row -= 1
var row = inventory_rows_list[inventory_selection_row]
inventory_selection_col = row.get_child_count() - 1
elif local_player and local_player.character_stats and local_player.character_stats.pending_level_up and local_player.character_stats.pending_stat_points > 0 and level_up_stat_buttons.size() > 0:
selected_type = "level_up_stat"
selected_level_up_stat_index = 0
selected_slot = ""
selected_item = null
level_up_stat_buttons[0].call_deferred("grab_focus")
if info_label and CharacterStats.LEVEL_UP_STAT_NAMES.size() > 0:
var sn = CharacterStats.LEVEL_UP_STAT_NAMES[0]
if sn in STAT_DESCRIPTIONS:
info_label.text = STAT_DESCRIPTIONS[sn]
_update_selection_rectangle()
return
"right":
if inventory_selection_row < inventory_rows_list.size():
var row = inventory_rows_list[inventory_selection_row]
@@ -1182,7 +1222,7 @@ func _navigate_equipment(direction: String):
if next_index >= 0:
equipment_selection_index = next_index
"up":
# Find next filled slot in row above (same column)
# Find next filled slot in row above (same column), or go to stats
var current_row: int = floor(equipment_selection_index / 3.0)
var current_col = equipment_selection_index % 3
if current_row > 0:
@@ -1191,11 +1231,20 @@ func _navigate_equipment(direction: String):
if _has_equipment_in_slot(target_slot):
equipment_selection_index = target_index
else:
# Skip to next filled slot in that row
var next_index = _find_next_filled_equipment_slot(target_index - 1, 1)
if next_index >= 0 and next_index < 3: # Make sure it's in row 0
if next_index >= 0 and next_index < 3:
equipment_selection_index = next_index
# Can't go up from equipment (already at top)
elif local_player and local_player.character_stats and local_player.character_stats.pending_level_up and local_player.character_stats.pending_stat_points > 0 and level_up_stat_buttons.size() > 0:
selected_type = "level_up_stat"
selected_level_up_stat_index = 0
selected_slot = ""
selected_item = null
level_up_stat_buttons[0].call_deferred("grab_focus")
if info_label and CharacterStats.LEVEL_UP_STAT_NAMES.size() > 0:
var sn = CharacterStats.LEVEL_UP_STAT_NAMES[0]
if sn in STAT_DESCRIPTIONS:
info_label.text = STAT_DESCRIPTIONS[sn]
return
"down":
# Find next filled slot in row below (same column), or move to inventory
var current_row: int = floor(equipment_selection_index / 3.0)
@@ -1274,8 +1323,20 @@ func _navigate_level_up_stats(direction: String) -> void:
var sn = CharacterStats.LEVEL_UP_STAT_NAMES[selected_level_up_stat_index]
if sn in STAT_DESCRIPTIONS:
info_label.text = STAT_DESCRIPTIONS[sn]
"up", "down":
"up":
pass
"down":
selected_type = "equipment"
selected_level_up_stat_index = -1
var next_index = _find_next_filled_equipment_slot(-1, 1)
if next_index >= 0:
equipment_selection_index = next_index
selected_slot = equipment_slots_list[next_index]
selected_item = local_player.character_stats.equipment[selected_slot] if local_player and local_player.character_stats else null
_update_selection_from_navigation()
_update_selection_rectangle()
_update_info_panel()
return
# Don't call _update_info_panel - we've set stat description above
func _on_inventory_item_pressed(item: Item):
@@ -1361,27 +1422,26 @@ func _input(event):
if not is_open:
return
# Arrow key navigation
if event is InputEventKey and event.pressed and not event.echo:
var direction = ""
if event.keycode == KEY_LEFT:
direction = "left"
elif event.keycode == KEY_RIGHT:
direction = "right"
elif event.keycode == KEY_UP:
direction = "up"
elif event.keycode == KEY_DOWN:
direction = "down"
if direction != "":
if selected_type == "level_up_stat":
_navigate_level_up_stats(direction)
elif selected_type == "equipment":
_navigate_equipment(direction)
else:
_navigate_inventory(direction)
get_viewport().set_input_as_handled()
return
# Arrow key navigation (use ui_left/right/up/down so keybindings work)
var direction = ""
var skip_repeat = event is InputEventKey and event.echo
if not skip_repeat and event.is_action_pressed("ui_left"):
direction = "left"
elif not skip_repeat and event.is_action_pressed("ui_right"):
direction = "right"
elif not skip_repeat and event.is_action_pressed("ui_up"):
direction = "up"
elif not skip_repeat and event.is_action_pressed("ui_down"):
direction = "down"
if direction != "":
if selected_type == "level_up_stat":
_navigate_level_up_stats(direction)
elif selected_type == "equipment":
_navigate_equipment(direction)
else:
_navigate_inventory(direction)
get_viewport().set_input_as_handled()
return
# F key: Unequip/equip items
if event is InputEventKey and event.keycode == KEY_F and event.pressed and not event.echo:
@@ -1408,6 +1468,8 @@ func _input(event):
func _handle_f_key():
if not local_player or not local_player.character_stats:
return
if not _can_use_inventory():
return
var char_stats = local_player.character_stats
@@ -1567,6 +1629,8 @@ func _handle_f_key():
func _use_consumable_item(item: Item):
if not local_player or not local_player.character_stats:
return
if not _can_use_inventory():
return
var char_stats = local_player.character_stats
@@ -1641,6 +1705,8 @@ func _use_consumable_item(item: Item):
func _handle_e_key():
if not local_player or not local_player.character_stats:
return
if not _can_use_inventory():
return
if selected_type != "item" or not selected_item:
return