133 lines
5.1 KiB
GDScript
133 lines
5.1 KiB
GDScript
class_name MenuUI
|
|
extends RefCounted
|
|
## Helper visuali comuni alle schermate P1/P2a/P3a.
|
|
|
|
const DISPLAY_FONT := preload("res://shared/assets/fonts/NotoSerifDisplay-CondensedExtraBold.ttf")
|
|
const MENU_SHADER := preload("res://menus/assets/shaders/ambient_drift.gdshader")
|
|
const TENT_STAR_SHADER := preload("res://menus/assets/shaders/tent_star_glow.gdshader")
|
|
const TENT_LIGHTS_SHADER := preload("res://menus/assets/shaders/tent_lights.gdshader")
|
|
const SIGN_LIGHTS_SHADER := preload("res://menus/assets/shaders/circus_sign_lights.gdshader")
|
|
const SUBMENU_LIGHTS_SHADER := preload("res://menus/assets/shaders/submenu_tent_lights.gdshader")
|
|
|
|
# Posizione e ingombro condivisi della freccia indietro in tutte le schermate.
|
|
const BACK_BUTTON_CENTER := Vector2(0.12, 0.14)
|
|
const BACK_BUTTON_SIZE := Vector2(0.09, 0.14)
|
|
|
|
|
|
static func set_normalized_rect(control: Control, center: Vector2, normalized_size: Vector2) -> void:
|
|
var viewport_size := control.get_viewport().get_visible_rect().size
|
|
var control_size := viewport_size * normalized_size
|
|
control.position = viewport_size * center - control_size * 0.5
|
|
control.size = control_size
|
|
|
|
|
|
static func add_full_texture(parent: Control, texture: Texture2D, material: Material = null) -> TextureRect:
|
|
var image := TextureRect.new()
|
|
image.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
image.texture = texture
|
|
image.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
image.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
|
|
image.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
image.material = material
|
|
parent.add_child(image)
|
|
return image
|
|
|
|
|
|
static func ambient_material(strength: float, speed: float) -> ShaderMaterial:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = MENU_SHADER
|
|
material.set_shader_parameter("drift_strength", strength)
|
|
material.set_shader_parameter("drift_speed", speed)
|
|
return material
|
|
|
|
|
|
static func tent_star_material() -> ShaderMaterial:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = TENT_STAR_SHADER
|
|
return material
|
|
|
|
|
|
static func tent_material(garland_strength := 0.0) -> ShaderMaterial:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = TENT_LIGHTS_SHADER
|
|
material.set_shader_parameter("garland_strength", garland_strength)
|
|
return material
|
|
|
|
|
|
static func sign_lights_material() -> ShaderMaterial:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = SIGN_LIGHTS_SHADER
|
|
material.set_shader_parameter("sign_lights_active", 0.0)
|
|
return material
|
|
|
|
|
|
static func submenu_lights_material() -> ShaderMaterial:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = SUBMENU_LIGHTS_SHADER
|
|
material.set_shader_parameter("lights_strength", 1.0)
|
|
material.set_shader_parameter("star_strength", 1.0)
|
|
return material
|
|
|
|
|
|
static func add_image(parent: Control, texture: Texture2D, center: Vector2, normalized_size: Vector2, material: Material = null) -> TextureRect:
|
|
var image := TextureRect.new()
|
|
image.texture = texture
|
|
image.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
image.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
image.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
image.material = material
|
|
parent.add_child(image)
|
|
set_normalized_rect(image, center, normalized_size)
|
|
return image
|
|
|
|
|
|
static func add_image_button(parent: Control, texture: Texture2D, center: Vector2, normalized_size: Vector2) -> TextureButton:
|
|
var button := TextureButton.new()
|
|
button.ignore_texture_size = true
|
|
button.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
button.texture_normal = texture
|
|
button.texture_hover = texture
|
|
button.texture_pressed = texture
|
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
button.mouse_entered.connect(func(): button.modulate = Color(1.08, 1.08, 1.08, 1.0))
|
|
button.mouse_exited.connect(func(): button.modulate = Color.WHITE)
|
|
parent.add_child(button)
|
|
set_normalized_rect(button, center, normalized_size)
|
|
return button
|
|
|
|
|
|
static func add_hotspot(parent: Control, center: Vector2, normalized_size: Vector2) -> Button:
|
|
var button := Button.new()
|
|
button.flat = true
|
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
parent.add_child(button)
|
|
set_normalized_rect(button, center, normalized_size)
|
|
return button
|
|
|
|
|
|
static func add_label(parent: Control, text: String, center: Vector2, normalized_size: Vector2, font_size: int) -> Label:
|
|
var label := Label.new()
|
|
label.text = text
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
label.add_theme_font_override("font", DISPLAY_FONT)
|
|
label.add_theme_font_size_override("font_size", font_size)
|
|
label.add_theme_color_override("font_color", Color("#171413"))
|
|
label.add_theme_color_override("font_outline_color", Color("#f4ecd9"))
|
|
label.add_theme_constant_override("outline_size", 2)
|
|
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
parent.add_child(label)
|
|
set_normalized_rect(label, center, normalized_size)
|
|
return label
|
|
|
|
|
|
static func note_style() -> StyleBoxFlat:
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("#f2dfb7")
|
|
style.border_color = Color("#9b6738")
|
|
style.set_border_width_all(3)
|
|
style.set_corner_radius_all(12)
|
|
style.shadow_color = Color(0, 0, 0, 0.25)
|
|
style.shadow_size = 5
|
|
return style
|