Improve reward item display
This commit is contained in:
@@ -3198,9 +3198,27 @@ func _clear_result_choices() -> void:
|
||||
func _format_post_battle_choice_text(choice: Dictionary) -> String:
|
||||
var label := str(choice.get("label", choice.get("text", choice.get("id", "Choice"))))
|
||||
var description := str(choice.get("description", ""))
|
||||
var reward_text := _format_post_battle_choice_reward_text(choice)
|
||||
var text := label
|
||||
if description.is_empty():
|
||||
return label
|
||||
return "%s - %s" % [label, description]
|
||||
text = label
|
||||
else:
|
||||
text = "%s - %s" % [label, description]
|
||||
if not reward_text.is_empty():
|
||||
text += "\nRewards: %s" % reward_text
|
||||
return text
|
||||
|
||||
|
||||
func _format_post_battle_choice_reward_text(choice: Dictionary) -> String:
|
||||
var parts := []
|
||||
var gold: int = maxi(0, int(choice.get("gold", 0)))
|
||||
if gold > 0:
|
||||
parts.append("+%dG" % gold)
|
||||
if typeof(choice.get("items", [])) == TYPE_ARRAY:
|
||||
var items: Array = choice.get("items", [])
|
||||
if not items.is_empty():
|
||||
parts.append(_format_reward_items(items))
|
||||
return _join_strings(parts, ", ")
|
||||
|
||||
|
||||
func _on_post_battle_choice_pressed(choice: Dictionary) -> void:
|
||||
@@ -3209,9 +3227,13 @@ func _on_post_battle_choice_pressed(choice: Dictionary) -> void:
|
||||
var scenario_id := str(battle_result_summary.get("scenario_id", state.battle_id))
|
||||
if campaign_state.try_apply_post_battle_choice(choice, scenario_id):
|
||||
_play_ui_confirm()
|
||||
battle_result_summary["pending_choice"] = false
|
||||
battle_result_summary["choice_applied"] = true
|
||||
battle_result_summary["saved"] = true
|
||||
battle_result_summary["choice_label"] = str(choice.get("label", choice.get("id", "")))
|
||||
var choice_gold: int = maxi(0, int(choice.get("gold", 0)))
|
||||
battle_result_summary["gold"] = int(battle_result_summary.get("gold", 0)) + choice_gold
|
||||
_append_result_items(choice.get("items", []))
|
||||
_append_unique_result_values("joined_officers", choice.get("join_officers", []))
|
||||
_append_unique_result_values("left_officers", choice.get("leave_officers", []))
|
||||
_on_log_added("Campaign choice saved: %s." % battle_result_summary["choice_label"])
|
||||
@@ -3222,6 +3244,18 @@ func _on_post_battle_choice_pressed(choice: Dictionary) -> void:
|
||||
_update_hud()
|
||||
|
||||
|
||||
func _append_result_items(values) -> void:
|
||||
if typeof(values) != TYPE_ARRAY:
|
||||
return
|
||||
var current: Array = battle_result_summary.get("items", [])
|
||||
for value in values:
|
||||
var normalized := str(value)
|
||||
if normalized.is_empty():
|
||||
continue
|
||||
current.append(normalized)
|
||||
battle_result_summary["items"] = current
|
||||
|
||||
|
||||
func _append_unique_result_values(key: String, values) -> void:
|
||||
if typeof(values) != TYPE_ARRAY:
|
||||
return
|
||||
@@ -3340,7 +3374,7 @@ func _format_inventory_items(inventory: Dictionary) -> String:
|
||||
var parts := []
|
||||
for item_id in item_ids:
|
||||
var key := str(item_id)
|
||||
parts.append("%s x%d" % [_item_display_name(key), int(inventory.get(key, 0))])
|
||||
parts.append("%s x%d" % [_item_inventory_display_name(key), int(inventory.get(key, 0))])
|
||||
return _join_strings(parts, ", ")
|
||||
|
||||
|
||||
@@ -3381,6 +3415,17 @@ func _item_display_name(item_id: String) -> String:
|
||||
return str(item.get("name", item_id))
|
||||
|
||||
|
||||
func _item_inventory_display_name(item_id: String) -> String:
|
||||
var item := state.get_item_def(item_id)
|
||||
if item.is_empty():
|
||||
return item_id
|
||||
var display_name := str(item.get("name", item_id))
|
||||
var rarity_text := _format_item_rarity_text(item)
|
||||
if rarity_text.is_empty():
|
||||
return display_name
|
||||
return "%s [%s]" % [display_name, rarity_text]
|
||||
|
||||
|
||||
func _join_strings(values: Array, delimiter: String) -> String:
|
||||
var text := ""
|
||||
for value in values:
|
||||
@@ -3882,6 +3927,10 @@ func _format_equipment_bonus_text(item: Dictionary) -> String:
|
||||
|
||||
|
||||
func _format_equipment_rarity_text(item: Dictionary) -> String:
|
||||
return _format_item_rarity_text(item)
|
||||
|
||||
|
||||
func _format_item_rarity_text(item: Dictionary) -> String:
|
||||
var rarity := str(item.get("rarity", ""))
|
||||
if rarity == "named":
|
||||
return "Named"
|
||||
|
||||
Reference in New Issue
Block a user