Add equipment unequip flow
This commit is contained in:
@@ -3139,6 +3139,21 @@ func _rebuild_armory_menu() -> void:
|
||||
equipment_label.text = "Equipped: %s" % _format_unit_equipment(selected)
|
||||
armory_list.add_child(equipment_label)
|
||||
|
||||
var equipped_slots := state.get_equipped_equipment_slots(armory_unit_id)
|
||||
if not equipped_slots.is_empty():
|
||||
var unequip_title := Label.new()
|
||||
unequip_title.text = "Unequip"
|
||||
armory_list.add_child(unequip_title)
|
||||
var equipment := state.get_equipment_snapshot(armory_unit_id)
|
||||
for slot in equipped_slots:
|
||||
var normalized_slot := str(slot)
|
||||
var item_id := _equipment_item_id(equipment, normalized_slot)
|
||||
var item := state.get_item_def(item_id)
|
||||
var unequip_button := Button.new()
|
||||
unequip_button.text = _format_equipment_unequip_text(selected, normalized_slot, item_id, item)
|
||||
unequip_button.pressed.connect(_on_armory_unequip_pressed.bind(normalized_slot))
|
||||
armory_list.add_child(unequip_button)
|
||||
|
||||
var item_ids := state.get_equippable_item_ids(armory_unit_id)
|
||||
if item_ids.is_empty():
|
||||
var empty_equipment_label := Label.new()
|
||||
@@ -3197,19 +3212,38 @@ func _on_armory_equip_pressed(item_id: String) -> void:
|
||||
_rebuild_armory_menu()
|
||||
_update_hud()
|
||||
return
|
||||
if campaign_state.try_save_prebattle_loadout(state.get_player_roster_snapshot(), state.get_inventory_snapshot()):
|
||||
_on_log_added("Saved pre-battle equipment.")
|
||||
else:
|
||||
_play_ui_cancel()
|
||||
_on_log_added("Could not save pre-battle equipment.")
|
||||
_load_scenario(active_scenario_id)
|
||||
_show_briefing()
|
||||
if not _save_prebattle_equipment_change():
|
||||
return
|
||||
_rebuild_armory_menu()
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_armory_unequip_pressed(slot: String) -> void:
|
||||
if battle_started or _is_prebattle_prep_locked() or armory_unit_id.is_empty():
|
||||
return
|
||||
if not state.try_unequip_item(armory_unit_id, slot):
|
||||
_rebuild_armory_menu()
|
||||
_update_hud()
|
||||
return
|
||||
if not _save_prebattle_equipment_change():
|
||||
return
|
||||
_rebuild_armory_menu()
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _save_prebattle_equipment_change() -> bool:
|
||||
if campaign_state.try_save_prebattle_loadout(state.get_player_roster_snapshot(), state.get_inventory_snapshot()):
|
||||
_on_log_added("Saved pre-battle equipment.")
|
||||
return true
|
||||
_play_ui_cancel()
|
||||
_on_log_added("Could not save pre-battle equipment.")
|
||||
_load_scenario(active_scenario_id)
|
||||
_show_briefing()
|
||||
return false
|
||||
|
||||
|
||||
func _rebuild_shop_menu() -> void:
|
||||
if shop_list == null:
|
||||
return
|
||||
@@ -4153,6 +4187,22 @@ func _rebuild_equip_menu(selected: Dictionary) -> void:
|
||||
equipment_label.text = "Equipped: %s" % _format_unit_equipment(selected)
|
||||
equip_list.add_child(equipment_label)
|
||||
|
||||
var equipped_slots := state.get_equipped_equipment_slots(str(selected["id"]))
|
||||
if not equipped_slots.is_empty():
|
||||
var unequip_title := Label.new()
|
||||
unequip_title.text = "Unequip"
|
||||
equip_list.add_child(unequip_title)
|
||||
var equipment := state.get_equipment_snapshot(str(selected["id"]))
|
||||
for slot in equipped_slots:
|
||||
var normalized_slot := str(slot)
|
||||
var item_id := _equipment_item_id(equipment, normalized_slot)
|
||||
var item := state.get_item_def(item_id)
|
||||
var unequip_button := Button.new()
|
||||
unequip_button.text = _format_equipment_unequip_text(selected, normalized_slot, item_id, item)
|
||||
unequip_button.disabled = _is_input_locked()
|
||||
unequip_button.pressed.connect(_on_equip_unequip_pressed.bind(normalized_slot))
|
||||
equip_list.add_child(unequip_button)
|
||||
|
||||
var item_ids := state.get_equippable_item_ids(selected["id"])
|
||||
if item_ids.is_empty():
|
||||
var empty_label := Label.new()
|
||||
@@ -4229,6 +4279,39 @@ func _format_equipment_option_text(unit: Dictionary, item_id: String, item: Dict
|
||||
return _join_strings(parts, " ")
|
||||
|
||||
|
||||
func _format_equipment_unequip_text(unit: Dictionary, slot: String, item_id: String, item: Dictionary) -> String:
|
||||
var parts := [
|
||||
"Unequip %s:" % slot.capitalize(),
|
||||
_item_display_name(item_id)
|
||||
]
|
||||
var change_text := _format_equipment_unequip_change_text(unit, slot, item)
|
||||
if not change_text.is_empty():
|
||||
parts.append(change_text)
|
||||
return _join_strings(parts, " ")
|
||||
|
||||
|
||||
func _format_equipment_unequip_change_text(unit: Dictionary, slot: String, item: Dictionary) -> String:
|
||||
if unit.is_empty() or item.is_empty():
|
||||
return ""
|
||||
var parts := []
|
||||
var current_bonuses := _equipment_bonus_map(item)
|
||||
for stat in ["hp", "mp", "atk", "def", "int", "agi"]:
|
||||
var delta := -int(current_bonuses.get(stat, 0))
|
||||
if delta == 0:
|
||||
continue
|
||||
parts.append("%s %d" % [stat.to_upper(), delta])
|
||||
if slot == "weapon":
|
||||
var current_range := _format_equipment_item_range_text(item)
|
||||
if not current_range.is_empty():
|
||||
parts.append("RNG returns to class")
|
||||
var effectiveness_text := _format_equipment_effectiveness_text(item)
|
||||
if not effectiveness_text.is_empty():
|
||||
parts.append("Loses %s" % effectiveness_text)
|
||||
if parts.is_empty():
|
||||
return "Returns to inventory"
|
||||
return "Change %s" % _join_strings(parts, ", ")
|
||||
|
||||
|
||||
func _format_equipment_change_text(unit: Dictionary, item: Dictionary) -> String:
|
||||
if unit.is_empty() or item.is_empty():
|
||||
return ""
|
||||
@@ -4379,6 +4462,17 @@ func _on_equip_item_pressed(item_id: String) -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_equip_unequip_pressed(slot: String) -> void:
|
||||
var selected := state.get_selected_unit()
|
||||
if selected.is_empty():
|
||||
return
|
||||
if state.try_unequip_item(selected["id"], slot):
|
||||
_rebuild_equip_menu(state.get_selected_unit())
|
||||
_refresh_ranges()
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_equip_cancel_pressed() -> void:
|
||||
_play_ui_cancel()
|
||||
_hide_equip_menu()
|
||||
|
||||
Reference in New Issue
Block a user