Add StageBackgroundView and related tests for plain background functionality

- Implemented StageBackgroundView class for managing sky and plain backgrounds in the stage.
- Added functionality to set background type and color, bind camera, and apply themes.
- Created test_phase19_plain_background.gd to validate plain background behavior and migration.
- Developed test_phase19_starter_chooser_layout.gd to ensure proper layout and functionality of the starter chooser.
- Included visual capture tests for UI elements and interactions.
This commit is contained in:
2026-10-22 16:18:25 -04:00
parent db677dc194
commit 59f1817063
43 changed files with 2403 additions and 160 deletions
+53 -3
View File
@@ -15,6 +15,26 @@ var _label: Label = null
var _description: Label = null
var _status_label: Label = null
static var _rounded_preview_shader: Shader
const ROUNDED_PREVIEW_SHADER_CODE := """
shader_type canvas_item;
uniform float corner_radius_px = 12.0;
void fragment() {
vec4 preview_color = texture(TEXTURE, UV);
vec2 preview_size = vec2(1.0) / TEXTURE_PIXEL_SIZE;
vec2 half_size = preview_size * 0.5;
vec2 local_position = UV * preview_size;
vec2 rounded_box = abs(local_position - half_size) - (half_size - vec2(corner_radius_px));
float edge_distance = length(max(rounded_box, vec2(0.0))) + min(max(rounded_box.x, rounded_box.y), 0.0) - corner_radius_px;
float antialias_width = max(fwidth(edge_distance), 1.0);
preview_color.a *= 1.0 - smoothstep(0.0, antialias_width, edge_distance);
COLOR = preview_color;
}
"""
func configure(payload: Dictionary, icon_texture: Texture2D = null, theme: Variant = null) -> void:
_payload = payload.duplicate(true)
_drag_threshold = theme.number("palette.drag_threshold", 8.0, 1.0, 128.0) if theme != null else 8.0
@@ -32,7 +52,9 @@ func configure(payload: Dictionary, icon_texture: Texture2D = null, theme: Varia
_box.alignment = BoxContainer.ALIGNMENT_CENTER; _box.add_theme_constant_override("separation", 2); add_child(_box)
_icon = TextureRect.new(); _icon.custom_minimum_size = thumbnail_size; _icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE; _icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED; _icon.texture = icon_texture; _icon.visible = icon_texture != null; _icon.mouse_filter = Control.MOUSE_FILTER_IGNORE; _box.add_child(_icon)
_glyph = Label.new(); _glyph.text = String(_payload.get("icon", "")); _glyph.visible = icon_texture == null; _glyph.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER; _glyph.mouse_filter = Control.MOUSE_FILTER_IGNORE; _glyph.add_theme_font_size_override("font_size", 30); _box.add_child(_glyph)
_label = Label.new(); _label.text = String(_payload.get("label", "")); _label.custom_minimum_size = Vector2(0, 28); _label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER; _label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART; _label.clip_text = true; _label.mouse_filter = Control.MOUSE_FILTER_IGNORE; _box.add_child(_label)
_label = Label.new(); _label.text = String(_payload.get("label", "")); _label.custom_minimum_size = Vector2(0, float(_payload.get("label_min_height", 28.0))); _label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER; _label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART; _label.clip_text = true; _label.mouse_filter = Control.MOUSE_FILTER_IGNORE; _box.add_child(_label)
if _payload.has("label_font_size"):
_label.add_theme_font_size_override("font_size", int(_payload["label_font_size"]))
var description: String = String(_payload.get("description", ""))
var status: String = String(_payload.get("status", ""))
if not status.is_empty():
@@ -56,6 +78,8 @@ func configure(payload: Dictionary, icon_texture: Texture2D = null, theme: Varia
_description.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
_description.max_lines_visible = 2
_description.add_theme_font_size_override("font_size", 14)
if _payload.has("description_font_size"):
_description.add_theme_font_size_override("font_size", int(_payload["description_font_size"]))
_description.mouse_filter = Control.MOUSE_FILTER_IGNORE
_box.add_child(_description)
@@ -75,8 +99,34 @@ func set_preview_control(preview: Control) -> void:
preview.custom_minimum_size = preview_size
preview.size_flags_horizontal = Control.SIZE_EXPAND_FILL
preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
_box.add_child(preview)
_box.move_child(preview, 0)
var preview_corner_radius: float = float(_payload.get("preview_corner_radius", 0.0))
if preview_corner_radius > 0.0:
var rounded_material := ShaderMaterial.new()
rounded_material.shader = _get_rounded_preview_shader()
rounded_material.set_shader_parameter("corner_radius_px", preview_corner_radius)
preview.material = rounded_material
var horizontal_inset: int = int(_payload.get("preview_horizontal_inset", 0))
var top_inset: int = int(_payload.get("preview_top_inset", 0))
if horizontal_inset > 0 or top_inset > 0:
var preview_frame := MarginContainer.new()
preview_frame.name = "PreviewInsetFrame"
preview_frame.size_flags_horizontal = Control.SIZE_EXPAND_FILL
preview_frame.add_theme_constant_override("margin_left", horizontal_inset)
preview_frame.add_theme_constant_override("margin_right", horizontal_inset)
preview_frame.add_theme_constant_override("margin_top", top_inset)
preview_frame.add_child(preview)
_box.add_child(preview_frame)
_box.move_child(preview_frame, 0)
else:
_box.add_child(preview)
_box.move_child(preview, 0)
func _get_rounded_preview_shader() -> Shader:
if _rounded_preview_shader == null:
_rounded_preview_shader = Shader.new()
_rounded_preview_shader.code = ROUNDED_PREVIEW_SHADER_CODE
return _rounded_preview_shader
func set_thumbnail(texture: Texture2D) -> void:
if _icon != null: _icon.texture = texture; _icon.visible = texture != null