2026-06-03 23:26:44 +03:00
|
|
|
extends HBoxContainer
|
|
|
|
|
class_name OwniverseAction
|
|
|
|
|
|
|
|
|
|
signal action_pressed(page_id, amount: float)
|
|
|
|
|
|
|
|
|
|
@onready var action_labels: Array = [
|
|
|
|
|
$ActionControl0/Label,
|
|
|
|
|
$ActionControl1/Label,
|
|
|
|
|
$ActionControl2/Label,
|
|
|
|
|
$ActionControl3/Label,
|
|
|
|
|
$ActionControl4/Label,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
var page_id: int = -1
|
2026-06-21 17:27:31 +03:00
|
|
|
var current_item_id = ""
|
2026-06-03 23:26:44 +03:00
|
|
|
|
|
|
|
|
var action_values: Dictionary = {
|
|
|
|
|
0: 0,
|
|
|
|
|
1: 0,
|
|
|
|
|
2: 0,
|
|
|
|
|
3: 0,
|
|
|
|
|
4: 0,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-09-14 07:47:21 +03:00
|
|
|
func set_actions(item_id: String, value: float, preview: Callable = Callable()) -> void:
|
2026-06-21 17:27:31 +03:00
|
|
|
current_item_id = item_id
|
2026-09-14 07:47:21 +03:00
|
|
|
var requests: Array = _get_distribution(value)
|
|
|
|
|
var displayed: Array = requests.duplicate()
|
|
|
|
|
if preview.is_valid():
|
|
|
|
|
for i in range(displayed.size()):
|
|
|
|
|
displayed[i] = preview.call(requests[i]) if requests[i] > 0.0 else 0.0
|
|
|
|
|
_set_action_values(requests, displayed)
|
2026-06-03 23:26:44 +03:00
|
|
|
|
2026-06-21 17:27:31 +03:00
|
|
|
func _get_distribution(value: float) -> Array:
|
2026-09-13 22:57:25 +03:00
|
|
|
if value <= 0.0 or not is_finite(value):
|
|
|
|
|
return [0.0, 0.0, 0.0, 0.0, 0.0]
|
2026-06-21 17:27:31 +03:00
|
|
|
var distribution: Array = [value, 0, 0, 0, 0]
|
|
|
|
|
|
|
|
|
|
var exp_value = int(floor(log(abs(value)) / log(10.0)))
|
|
|
|
|
var floor_value = max(exp_value - 4, -1)
|
|
|
|
|
for ev in range(exp_value, floor_value, -1):
|
|
|
|
|
distribution.push_front(pow(10.0, ev))
|
|
|
|
|
return distribution
|
|
|
|
|
|
2026-09-14 07:47:21 +03:00
|
|
|
func _set_action_values(values: Array, displayed: Array) -> void:
|
2026-06-03 23:26:44 +03:00
|
|
|
for ind in range(0, 5):
|
|
|
|
|
action_values[ind] = values[ind]
|
2026-09-14 07:47:21 +03:00
|
|
|
# Keep the original request for execution; show the exact planned output.
|
2026-09-20 22:14:47 +03:00
|
|
|
var text: String = Global.format_number(displayed[ind]) if displayed[ind] > 0 else ""
|
|
|
|
|
if action_labels[ind].text != text:
|
|
|
|
|
action_labels[ind].text = text
|
2026-06-03 23:26:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_action_button_pressed(button_id: int) -> void:
|
|
|
|
|
action_pressed.emit(page_id, action_values[button_id])
|