211 lines
6.8 KiB
GDScript
211 lines
6.8 KiB
GDScript
extends SceneTree
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
var page := ProfilePage.new()
|
|
page.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
root.add_child(page)
|
|
await process_frame
|
|
await process_frame
|
|
page.set(
|
|
"_draft_appearance",
|
|
CharacterCustomizationCatalog.default_snapshot(),
|
|
)
|
|
var preview := page.get("_preview") as ProfilePreview
|
|
var default_appearance := (
|
|
CharacterCustomizationCatalog.default_snapshot()
|
|
)
|
|
preview.apply_appearance_profile(default_appearance)
|
|
var visible_bounds_result: Dictionary = preview.call(
|
|
"_visible_mesh_bounds"
|
|
)
|
|
assert(bool(visible_bounds_result.get("has_bounds", false)))
|
|
var visible_bounds: AABB = visible_bounds_result.get("bounds", AABB())
|
|
assert(
|
|
(preview.get("_camera_target") as Vector3).is_equal_approx(
|
|
visible_bounds.get_center()
|
|
)
|
|
)
|
|
var stable_fit := float(preview.get("_camera_fit_distance"))
|
|
preview.apply_appearance_profile(default_appearance)
|
|
assert(is_equal_approx(
|
|
float(preview.get("_camera_fit_distance")), stable_fit
|
|
))
|
|
var shell := page.find_child("UtilityMainBox", true, false) as Control
|
|
assert(shell != null)
|
|
var shell_position := shell.position
|
|
var shell_size := shell.size
|
|
for category_id: String in ["species", "arms", "ears", "tail"]:
|
|
page.call("_select_category", category_id)
|
|
await process_frame
|
|
await process_frame
|
|
var scroll := page.find_child(
|
|
"ModelOptionScroll", true, false
|
|
) as ScrollContainer
|
|
var grid := page.find_child(
|
|
"ModelOptionGrid", true, false
|
|
) as GridContainer
|
|
assert(scroll != null)
|
|
assert(grid != null)
|
|
assert(grid.columns == ProfilePage.MODEL_OPTION_GRID_COLUMNS)
|
|
assert(
|
|
grid.get_child_count()
|
|
== CharacterCustomizationCatalog.options_for(category_id).size()
|
|
)
|
|
assert(
|
|
scroll.horizontal_scroll_mode
|
|
== ScrollContainer.SCROLL_MODE_DISABLED
|
|
)
|
|
assert(
|
|
scroll.vertical_scroll_mode
|
|
== ScrollContainer.SCROLL_MODE_AUTO
|
|
)
|
|
assert(shell.position.is_equal_approx(shell_position))
|
|
assert(shell.size.is_equal_approx(shell_size))
|
|
|
|
page.call("_select_category", "species")
|
|
await process_frame
|
|
await process_frame
|
|
var species_scroll := page.find_child(
|
|
"ModelOptionScroll", true, false
|
|
) as ScrollContainer
|
|
assert(species_scroll != null)
|
|
var species_scroll_max := int(
|
|
maxf(
|
|
species_scroll.get_v_scroll_bar().max_value
|
|
- species_scroll.get_v_scroll_bar().page,
|
|
0.0,
|
|
)
|
|
)
|
|
assert(species_scroll_max > 0)
|
|
var saved_position := mini(species_scroll_max, 36)
|
|
species_scroll.scroll_vertical = saved_position
|
|
page.call("_select_category", "arms")
|
|
await process_frame
|
|
page.call("_select_category", "species")
|
|
await process_frame
|
|
await process_frame
|
|
species_scroll = page.find_child(
|
|
"ModelOptionScroll", true, false
|
|
) as ScrollContainer
|
|
assert(species_scroll != null)
|
|
assert(species_scroll.scroll_vertical == saved_position)
|
|
page.call("activate")
|
|
page.call("set_interactive", true)
|
|
var category_scroll := page.find_child(
|
|
"CategoryScroll", true, false
|
|
) as ScrollContainer
|
|
assert(category_scroll != null and category_scroll.follow_focus)
|
|
page.set("_controller_zone", ProfilePage.ControllerZone.CATEGORIES)
|
|
page.call("_apply_controller_zone_focus")
|
|
var category_list := page.get("_category_list") as VBoxContainer
|
|
var last_category_button := category_list.get_child(
|
|
category_list.get_child_count() - 1
|
|
) as Button
|
|
assert(last_category_button != null)
|
|
last_category_button.grab_focus()
|
|
await process_frame
|
|
assert(category_scroll.scroll_vertical > 0)
|
|
|
|
page.set("_controller_zone", ProfilePage.ControllerZone.OPTIONS)
|
|
page.call("_apply_controller_zone_focus")
|
|
var species_grid := page.find_child(
|
|
"ModelOptionGrid", true, false
|
|
) as GridContainer
|
|
var last_species_button := species_grid.get_child(
|
|
species_grid.get_child_count() - 1
|
|
) as Button
|
|
assert(last_species_button != null)
|
|
last_species_button.grab_focus()
|
|
await process_frame
|
|
assert(species_scroll.scroll_vertical > saved_position)
|
|
|
|
page.call("_select_category", "special")
|
|
await process_frame
|
|
await process_frame
|
|
var special_scroll := page.find_child(
|
|
"SpecialOptionScroll", true, false
|
|
) as ScrollContainer
|
|
assert(special_scroll != null)
|
|
for field_id: String in CharacterCustomizationCatalog.SPECIAL_SLOT_IDS:
|
|
var slot_name := "SpecialSlot_%s" % field_id.trim_prefix("special_")
|
|
var slot := page.find_child(slot_name, true, false) as HBoxContainer
|
|
assert(slot != null)
|
|
assert(slot.get_child_count() == 2)
|
|
var slot_label := slot.get_child(0) as Label
|
|
var choices := slot.get_child(1) as HBoxContainer
|
|
assert(slot_label != null and choices != null)
|
|
assert(
|
|
slot_label.text
|
|
== CharacterCustomizationCatalog.special_slot_label(field_id)
|
|
)
|
|
assert(
|
|
choices.get_child_count()
|
|
== CharacterCustomizationCatalog.options_for(field_id).size()
|
|
)
|
|
assert(shell.position.is_equal_approx(shell_position))
|
|
assert(shell.size.is_equal_approx(shell_size))
|
|
|
|
var back_slot := page.find_child(
|
|
"SpecialSlot_back", true, false
|
|
) as HBoxContainer
|
|
var back_choices := back_slot.get_child(1) as HBoxContainer
|
|
var shell_button := back_choices.get_child(1) as Button
|
|
assert(shell_button != null)
|
|
shell_button.pressed.emit()
|
|
await process_frame
|
|
await process_frame
|
|
var draft: Dictionary = page.get("_draft_appearance")
|
|
assert(str(draft.get("special_back", "")) == "shell")
|
|
for other_id: String in CharacterCustomizationCatalog.SPECIAL_SLOT_IDS:
|
|
if other_id != "special_back":
|
|
assert(str(draft.get(other_id, "")) == "none")
|
|
var wings_slot := page.find_child(
|
|
"SpecialSlot_wings", true, false
|
|
) as HBoxContainer
|
|
var wings_choices := wings_slot.get_child(1) as HBoxContainer
|
|
var moth_button := wings_choices.get_child(
|
|
wings_choices.get_child_count() - 1
|
|
) as Button
|
|
assert(moth_button != null)
|
|
moth_button.grab_focus()
|
|
await process_frame
|
|
moth_button.pressed.emit()
|
|
await process_frame
|
|
await process_frame
|
|
draft = page.get("_draft_appearance")
|
|
assert(str(draft.get("special_back", "")) == "shell")
|
|
assert(str(draft.get("special_wings", "")) == "moth")
|
|
var restored_focus := page.get_viewport().gui_get_focus_owner() as Button
|
|
assert(restored_focus != null)
|
|
assert(
|
|
str(restored_focus.get_meta(&"appearance_focus_key", ""))
|
|
== "special_wings:moth"
|
|
)
|
|
|
|
var ordinary_bounds := AABB(Vector3.ZERO, Vector3(1.0, 2.0, 1.0))
|
|
var wide_bounds := AABB(Vector3.ZERO, Vector3(4.0, 2.0, 1.0))
|
|
var tall_bounds := AABB(Vector3.ZERO, Vector3(1.0, 4.0, 1.0))
|
|
var viewport_size := Vector2(320.0, 330.0)
|
|
var ordinary_fit := ProfilePreview.calculate_camera_fit_distance(
|
|
ordinary_bounds, viewport_size, 75.0
|
|
)
|
|
assert(
|
|
ProfilePreview.calculate_camera_fit_distance(
|
|
wide_bounds, viewport_size, 75.0
|
|
) > ordinary_fit
|
|
)
|
|
assert(
|
|
ProfilePreview.calculate_camera_fit_distance(
|
|
tall_bounds, viewport_size, 75.0
|
|
) > ordinary_fit
|
|
)
|
|
|
|
print("Character customizer UI validation: PASS")
|
|
page.queue_free()
|
|
await process_frame
|
|
quit()
|