49 lines
1.8 KiB
GDScript
49 lines
1.8 KiB
GDScript
class_name ABGM52PortraitModule
|
|
extends Control
|
|
|
|
## Fixed portrait window: frame art and image are separate layers, with the
|
|
## image constrained to the measured inner opening.
|
|
|
|
const PORTRAIT_FRAME = preload("res://assets/ui_m52_components/v2_trimmed/frames/portrait_frame.png")
|
|
|
|
var portrait_texture: Texture2D
|
|
|
|
func configure(texture: Texture2D) -> ABGM52PortraitModule:
|
|
portrait_texture = texture
|
|
return self
|
|
|
|
func _ready() -> void:
|
|
clip_contents = true
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
var frame_art := TextureRect.new()
|
|
frame_art.name = "PortraitFrameArt"
|
|
frame_art.texture = PORTRAIT_FRAME
|
|
frame_art.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
frame_art.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
frame_art.stretch_mode = TextureRect.STRETCH_SCALE
|
|
frame_art.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
frame_art.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(frame_art)
|
|
|
|
var viewport := Control.new()
|
|
viewport.name = "PortraitViewport"
|
|
viewport.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
viewport.anchor_left = 0.20
|
|
viewport.anchor_top = 0.16
|
|
viewport.anchor_right = 0.80
|
|
viewport.anchor_bottom = 0.84
|
|
viewport.clip_contents = true
|
|
viewport.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
add_child(viewport)
|
|
var image := TextureRect.new()
|
|
image.name = "PortraitImage"
|
|
image.texture = portrait_texture
|
|
image.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
image.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
# Keep the complete chibi silhouette inside the authored portrait window;
|
|
# the frame owns the crop, not the runtime image.
|
|
image.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
image.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
|
image.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
viewport.add_child(image)
|