Add report generation functionality to the UI
- Introduced a new script `report.gd` that extends `VBoxContainer` to manage the display of reports. - Implemented dynamic localization support for report headers and body content based on the global locale. - Created a `refresh` method to update the report content and header image when visibility changes or locale updates. - Added a static `build` method to format and compile report data from the world state, including calculations for star totals and effects. - Integrated presentation logic to render report templates based on the current state of the game world.
This commit is contained in:
BIN
Binary file not shown.
@@ -0,0 +1,63 @@
|
||||
extends VBoxContainer
|
||||
const E = preload("res://world/owniverse/math/exact.gd")
|
||||
const Presentation = preload("res://world/owniverse/item_presentation.gd")
|
||||
const STARS = ["RD", "OD", "YD", "WYD", "WS", "BG", "SG", "HG"]
|
||||
const EFFECTS = {"Int.Fed": "Federation", "Int.Enl": "Enlightenment", "Int.Ord": "Order"}
|
||||
|
||||
var report_locale: String = ""
|
||||
|
||||
@onready var report_body: RichTextLabel = $ReportBody
|
||||
@onready var report_header: TextureRect = $Header/Header
|
||||
|
||||
func _ready() -> void:
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if is_visible_in_tree() and report_locale != get_node("/root/Global").Locale:
|
||||
refresh()
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if is_node_ready() and is_visible_in_tree():
|
||||
refresh()
|
||||
report_body.scroll_to_line(0)
|
||||
|
||||
func refresh() -> void:
|
||||
var global: Node = get_node("/root/Global")
|
||||
report_locale = global.Locale
|
||||
report_body.text = build(get_parent().owniverse, global)
|
||||
report_header.texture = load("res://ui/report/" + report_locale + "/report.png")
|
||||
|
||||
## Formats existing committed state only. No historical counters or simulation work.
|
||||
static func build(world, global: Node) -> String:
|
||||
var source: Dictionary = world.state
|
||||
var totals: Dictionary = Presentation.amounts(source, world.catalog, true)
|
||||
var physical: Dictionary = world.ledger.physical_amounts(source)
|
||||
var star_total: Variant = 0
|
||||
for id in STARS: star_total = E.add(star_total, physical.get(id, 0))
|
||||
var blocks: PackedStringArray = []
|
||||
var lines: PackedStringArray = []
|
||||
var header: String = ""
|
||||
# Russian keys provide the common order; get_template resolves both key formats.
|
||||
for key in global.Templates.ru:
|
||||
if not str(key).contains(".Report."): continue
|
||||
var parts: PackedStringArray = str(key).rsplit(".Report.", true, 1)
|
||||
var id: String = parts[0]
|
||||
var kind: String = parts[1]
|
||||
var row: Dictionary = global.get_template(id, "Report", kind)
|
||||
if kind == "Header":
|
||||
if not lines.is_empty(): blocks.append(header + "\n\n" + "\n".join(lines))
|
||||
lines.clear()
|
||||
header = global.render_template(row, {})
|
||||
elif kind == "Fraction":
|
||||
var amount: Variant = physical.get(id, 0)
|
||||
if E.gt(amount, 0) and E.gt(star_total, 0):
|
||||
var percent: String = E.grouped(E.mul_div(amount, 100, star_total), 2, false) + "%"
|
||||
lines.append(global.render_template(row, {"proportion": percent}))
|
||||
elif kind == "Max":
|
||||
var amount: Variant = totals.get(id, 0)
|
||||
if EFFECTS.has(id):
|
||||
amount = E.subtract(source.world_parameters.get(EFFECTS[id], 1), 1)
|
||||
if E.gt(amount, 0):
|
||||
lines.append(global.render_template(row, {"max": E.grouped(amount, 2 if EFFECTS.has(id) else 0, false)}))
|
||||
if not lines.is_empty(): blocks.append(header + "\n\n" + "\n".join(lines))
|
||||
return "\n\n".join(blocks)
|
||||
@@ -0,0 +1 @@
|
||||
uid://v8h4ov33opyf
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user