Keep utility pages within menu bounds

This commit is contained in:
Alexander Sellite 2026-08-22 22:56:55 -04:00
parent 3dbfd74b6c
commit 1f3308d83b
3 changed files with 200 additions and 85 deletions

View file

@ -311,15 +311,17 @@ func _build_job_rows(jobs: Array[Dictionary], empty_text: String) -> void:
return
for job: Dictionary in jobs:
var row := PanelContainer.new()
row.clip_contents = true
row.add_theme_stylebox_override(
"panel", UtilityPageStyle.row_style(false)
)
var content := HBoxContainer.new()
content.add_theme_constant_override("separation", 14)
content.clip_contents = true
content.add_theme_constant_override("separation", 10)
row.add_child(content)
var text_column := VBoxContainer.new()
text_column.custom_minimum_size.x = 245.0
text_column.custom_minimum_size.x = 220.0
text_column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
content.add_child(text_column)
var title := Label.new()
@ -334,6 +336,8 @@ func _build_job_rows(jobs: Array[Dictionary], empty_text: String) -> void:
var description := Label.new()
description.text = str(job.get("description", ""))
description.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
description.max_lines_visible = 2
description.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
description.add_theme_font_size_override("font_size", 16)
description.add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
@ -343,7 +347,8 @@ func _build_job_rows(jobs: Array[Dictionary], empty_text: String) -> void:
var target: int = int(job.get("target", 1))
var progress: int = int(job.get("progress", 0))
var progress_bar := ProgressBar.new()
progress_bar.custom_minimum_size = Vector2(100.0, 24.0)
progress_bar.custom_minimum_size = Vector2(104.0, 24.0)
progress_bar.size_flags_vertical = Control.SIZE_SHRINK_CENTER
progress_bar.max_value = float(target)
progress_bar.value = float(progress)
progress_bar.show_percentage = false
@ -360,24 +365,30 @@ func _build_job_rows(jobs: Array[Dictionary], empty_text: String) -> void:
content.add_child(progress_bar)
var count := Label.new()
count.custom_minimum_size.x = 54.0
count.text = "%d / %d" % [progress, target]
count.custom_minimum_size.x = 82.0
count.clip_text = true
count.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
count.text = "%s / %s" % [
_compact_integer(progress),
_compact_integer(target),
]
count.tooltip_text = "%d / %d" % [progress, target]
count.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
count.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
count.add_theme_font_size_override("font_size", 14)
count.add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_PRIMARY
)
content.add_child(count)
var reward := _make_reward_display(
var reward := _make_job_reward_display(
int(job.get("fish_coin", 0)),
int(job.get("experience", 0)),
)
reward.custom_minimum_size.x = 128.0
content.add_child(reward)
var claim := Button.new()
claim.custom_minimum_size = Vector2(76.0, 36.0)
claim.custom_minimum_size = Vector2(72.0, 36.0)
var claimable: bool = bool(job.get("claimable", false))
claim.text = "claim" if claimable else (
"done" if int(job.get("completed_count", 0)) > 0 else "working"
@ -457,17 +468,21 @@ func _claim(claim_id: String) -> void:
func _make_reward_display(fish_coin: int, experience: int) -> HBoxContainer:
var reward := HBoxContainer.new()
reward.mouse_filter = Control.MOUSE_FILTER_IGNORE
reward.tooltip_text = "%d fish coins · %d xp" % [fish_coin, experience]
reward.add_theme_constant_override("separation", 7)
var currency: CurrencyAmount = (
CurrencyPresentationType.instantiate_amount(fish_coin, 18.0)
)
currency.set_amount_text(_compact_integer(fish_coin))
currency.tooltip_text = "%d fish coins" % fish_coin
currency.get_amount_label().add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
)
reward.add_child(currency)
var experience_label := Label.new()
experience_label.text = "%d xp" % experience
experience_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
experience_label.text = "%s xp" % _compact_integer(experience)
experience_label.tooltip_text = "%d xp" % experience
experience_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
experience_label.add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
@ -476,6 +491,67 @@ func _make_reward_display(fish_coin: int, experience: int) -> HBoxContainer:
return reward
func _make_job_reward_display(
fish_coin: int,
experience: int,
) -> VBoxContainer:
var reward := VBoxContainer.new()
reward.custom_minimum_size.x = 104.0
reward.tooltip_text = "%d fish coins · %d xp" % [fish_coin, experience]
reward.add_theme_constant_override("separation", 1)
var currency: CurrencyAmount = (
CurrencyPresentationType.instantiate_amount(fish_coin, 16.0)
)
currency.set_amount_text(_compact_integer(fish_coin))
currency.tooltip_text = "%d fish coins" % fish_coin
currency.size_flags_horizontal = Control.SIZE_EXPAND_FILL
currency.alignment = BoxContainer.ALIGNMENT_CENTER
currency.get_amount_label().add_theme_font_size_override("font_size", 14)
currency.get_amount_label().add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
)
reward.add_child(currency)
var experience_label := Label.new()
experience_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
experience_label.text = "%s xp" % _compact_integer(experience)
experience_label.tooltip_text = "%d xp" % experience
experience_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
experience_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
experience_label.add_theme_font_size_override("font_size", 14)
experience_label.add_theme_color_override(
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
)
reward.add_child(experience_label)
return reward
func _compact_integer(value: int) -> String:
var magnitude: int = absi(value)
var divisor: float = 1.0
var suffix: String = ""
if magnitude >= 1_000_000_000_000:
divisor = 1_000_000_000_000.0
suffix = "t"
elif magnitude >= 1_000_000_000:
divisor = 1_000_000_000.0
suffix = "b"
elif magnitude >= 1_000_000:
divisor = 1_000_000.0
suffix = "m"
elif magnitude >= 1_000:
divisor = 1_000.0
suffix = "k"
else:
return str(value)
var scaled: float = float(value) / divisor
var number: String = (
str(roundi(scaled))
if absf(scaled) >= 100.0
else ("%.1f" % scaled).trim_suffix(".0")
)
return number + suffix
func _add_empty(message: String) -> void:
var empty := Label.new()
empty.text = message