Improve battle presentation previews
This commit is contained in:
@@ -2286,9 +2286,36 @@ func _format_briefing_objectives() -> String:
|
||||
if not text.is_empty():
|
||||
text += "\n"
|
||||
text += "Defeat: %s" % defeat
|
||||
var rewards_text := _format_briefing_rewards()
|
||||
if not rewards_text.is_empty():
|
||||
if not text.is_empty():
|
||||
text += "\n"
|
||||
text += "Rewards: %s" % rewards_text
|
||||
return text
|
||||
|
||||
|
||||
func _format_briefing_rewards() -> String:
|
||||
if campaign_state.is_scenario_completed(active_scenario_id):
|
||||
return "already claimed"
|
||||
var rewards := state.get_rewards()
|
||||
var parts := []
|
||||
var gold: int = maxi(0, int(rewards.get("gold", 0)))
|
||||
if gold > 0:
|
||||
parts.append("%dG" % gold)
|
||||
var items = rewards.get("items", [])
|
||||
if typeof(items) == TYPE_ARRAY and not items.is_empty():
|
||||
var item_text := _format_reward_items(items)
|
||||
if item_text != "none":
|
||||
parts.append(item_text)
|
||||
var joined_text := _format_officer_id_list(rewards.get("join_officers", []))
|
||||
if not joined_text.is_empty():
|
||||
parts.append("Join %s" % joined_text)
|
||||
var left_text := _format_officer_id_list(rewards.get("leave_officers", []))
|
||||
if not left_text.is_empty():
|
||||
parts.append("Leave %s" % left_text)
|
||||
return _join_strings(parts, ", ")
|
||||
|
||||
|
||||
func _show_briefing() -> void:
|
||||
_play_bgm("menu")
|
||||
var briefing := state.get_briefing()
|
||||
@@ -2877,11 +2904,12 @@ func _rebuild_armory_menu() -> void:
|
||||
var normalized_id := str(item_id)
|
||||
var item := state.get_item_def(normalized_id)
|
||||
var armory_equip_button := Button.new()
|
||||
armory_equip_button.text = "%s x%d %s" % [
|
||||
_item_display_name(normalized_id),
|
||||
int(inventory.get(normalized_id, 0)),
|
||||
_format_equipment_bonus_text(item)
|
||||
]
|
||||
armory_equip_button.text = _format_equipment_option_text(
|
||||
selected,
|
||||
normalized_id,
|
||||
item,
|
||||
int(inventory.get(normalized_id, 0))
|
||||
)
|
||||
armory_equip_button.pressed.connect(_on_armory_equip_pressed.bind(normalized_id))
|
||||
armory_list.add_child(armory_equip_button)
|
||||
|
||||
@@ -3289,11 +3317,11 @@ func _format_battle_result_summary() -> String:
|
||||
var joined_text := ""
|
||||
var joined_officers: Array = battle_result_summary.get("joined_officers", [])
|
||||
if not joined_officers.is_empty():
|
||||
joined_text = "\nJoined: %s" % _join_strings(joined_officers, ", ")
|
||||
joined_text = "\nJoined: %s" % _format_officer_id_list(joined_officers)
|
||||
var left_text := ""
|
||||
var left_officers: Array = battle_result_summary.get("left_officers", [])
|
||||
if not left_officers.is_empty():
|
||||
left_text = "\nLeft: %s" % _join_strings(left_officers, ", ")
|
||||
left_text = "\nLeft: %s" % _format_officer_id_list(left_officers)
|
||||
var progression_text := _format_progression_events(battle_result_summary.get("progression_events", []))
|
||||
|
||||
var saved_text := "Campaign saved." if battle_result_summary.get("saved", false) else "Campaign save failed."
|
||||
@@ -3408,6 +3436,22 @@ func _format_inventory_by_category(inventory: Dictionary) -> String:
|
||||
return _join_strings(sections, " | ")
|
||||
|
||||
|
||||
func _format_officer_id_list(values) -> String:
|
||||
if typeof(values) != TYPE_ARRAY:
|
||||
return ""
|
||||
var labels := []
|
||||
for value in values:
|
||||
var label := _format_identifier_label(str(value))
|
||||
if label.is_empty():
|
||||
continue
|
||||
labels.append(label)
|
||||
return _join_strings(labels, ", ")
|
||||
|
||||
|
||||
func _format_identifier_label(value: String) -> String:
|
||||
return value.strip_edges().replace("_", " ").capitalize()
|
||||
|
||||
|
||||
func _item_display_name(item_id: String) -> String:
|
||||
var item := state.get_item_def(item_id)
|
||||
if item.is_empty():
|
||||
@@ -3854,11 +3898,12 @@ func _rebuild_equip_menu(selected: Dictionary) -> void:
|
||||
var normalized_id := str(item_id)
|
||||
var item := state.get_item_def(normalized_id)
|
||||
var equip_item_button := Button.new()
|
||||
equip_item_button.text = "%s x%d %s" % [
|
||||
_item_display_name(normalized_id),
|
||||
int(inventory.get(normalized_id, 0)),
|
||||
_format_equipment_bonus_text(item)
|
||||
]
|
||||
equip_item_button.text = _format_equipment_option_text(
|
||||
selected,
|
||||
normalized_id,
|
||||
item,
|
||||
int(inventory.get(normalized_id, 0))
|
||||
)
|
||||
equip_item_button.disabled = _is_input_locked()
|
||||
equip_item_button.pressed.connect(_on_equip_item_pressed.bind(normalized_id))
|
||||
equip_list.add_child(equip_item_button)
|
||||
@@ -3906,6 +3951,103 @@ func _equipment_item_id(equipment: Dictionary, slot: String) -> String:
|
||||
return str(item_id)
|
||||
|
||||
|
||||
func _format_equipment_option_text(unit: Dictionary, item_id: String, item: Dictionary, count: int) -> String:
|
||||
var parts := [
|
||||
_item_display_name(item_id),
|
||||
"x%d" % count,
|
||||
_format_equipment_bonus_text(item)
|
||||
]
|
||||
var change_text := _format_equipment_change_text(unit, item)
|
||||
if not change_text.is_empty():
|
||||
parts.append(change_text)
|
||||
return _join_strings(parts, " ")
|
||||
|
||||
|
||||
func _format_equipment_change_text(unit: Dictionary, item: Dictionary) -> String:
|
||||
if unit.is_empty() or item.is_empty():
|
||||
return ""
|
||||
var slot := _equipment_slot_for_display(item)
|
||||
if slot.is_empty():
|
||||
return ""
|
||||
|
||||
var equipment := state.get_equipment_snapshot(str(unit.get("id", "")))
|
||||
var current_item_id := _equipment_item_id(equipment, slot)
|
||||
var current_item := state.get_item_def(current_item_id)
|
||||
var parts := []
|
||||
var candidate_bonuses := _equipment_bonus_map(item)
|
||||
var current_bonuses := _equipment_bonus_map(current_item)
|
||||
for stat in ["hp", "mp", "atk", "def", "int", "agi"]:
|
||||
var delta := int(candidate_bonuses.get(stat, 0)) - int(current_bonuses.get(stat, 0))
|
||||
if delta == 0:
|
||||
continue
|
||||
var sign := "+" if delta > 0 else ""
|
||||
parts.append("%s %s%d" % [stat.to_upper(), sign, delta])
|
||||
|
||||
var range_text := _format_equipment_range_change_text(current_item, item)
|
||||
if not range_text.is_empty():
|
||||
parts.append(range_text)
|
||||
var effectiveness_text := _format_equipment_effectiveness_change_text(current_item, item)
|
||||
if not effectiveness_text.is_empty():
|
||||
parts.append(effectiveness_text)
|
||||
if parts.is_empty():
|
||||
return "Change none"
|
||||
return "Change %s" % _join_strings(parts, ", ")
|
||||
|
||||
|
||||
func _equipment_slot_for_display(item: Dictionary) -> String:
|
||||
var kind := str(item.get("kind", ""))
|
||||
if kind == "weapon" or kind == "armor" or kind == "accessory":
|
||||
return kind
|
||||
return ""
|
||||
|
||||
|
||||
func _equipment_bonus_map(item: Dictionary) -> Dictionary:
|
||||
if item.is_empty() or typeof(item.get("bonuses", {})) != TYPE_DICTIONARY:
|
||||
return {}
|
||||
return item.get("bonuses", {})
|
||||
|
||||
|
||||
func _format_equipment_range_change_text(current_item: Dictionary, candidate_item: Dictionary) -> String:
|
||||
if str(candidate_item.get("kind", "")) != "weapon":
|
||||
return ""
|
||||
var candidate_range := _format_equipment_item_range_text(candidate_item)
|
||||
var current_range := _format_equipment_item_range_text(current_item)
|
||||
if candidate_range.is_empty() or candidate_range == current_range:
|
||||
return ""
|
||||
if current_range.is_empty():
|
||||
current_range = "-"
|
||||
return "RNG %s->%s" % [current_range, candidate_range]
|
||||
|
||||
|
||||
func _format_equipment_item_range_text(item: Dictionary) -> String:
|
||||
if item.is_empty() or not item.has("range"):
|
||||
return ""
|
||||
var value = item.get("range", 1)
|
||||
if typeof(value) == TYPE_ARRAY:
|
||||
if value.size() >= 2:
|
||||
return "%d-%d" % [int(value[0]), int(value[1])]
|
||||
if value.size() == 1:
|
||||
return "%d" % int(value[0])
|
||||
return ""
|
||||
if typeof(value) == TYPE_INT or typeof(value) == TYPE_FLOAT:
|
||||
return "%d" % int(value)
|
||||
return ""
|
||||
|
||||
|
||||
func _format_equipment_effectiveness_change_text(current_item: Dictionary, candidate_item: Dictionary) -> String:
|
||||
if str(candidate_item.get("kind", "")) != "weapon":
|
||||
return ""
|
||||
var candidate_text := _format_equipment_effectiveness_text(candidate_item)
|
||||
var current_text := _format_equipment_effectiveness_text(current_item)
|
||||
if candidate_text == current_text:
|
||||
return ""
|
||||
if current_text.is_empty():
|
||||
return "Gains %s" % candidate_text
|
||||
if candidate_text.is_empty():
|
||||
return "Loses %s" % current_text
|
||||
return "Effect changes"
|
||||
|
||||
|
||||
func _format_equipment_bonus_text(item: Dictionary) -> String:
|
||||
var parts := []
|
||||
var rarity_text := _format_equipment_rarity_text(item)
|
||||
|
||||
Reference in New Issue
Block a user