netfishing/ui/components/inventory_notepad.gd

70 lines
2 KiB
GDScript3
Raw Normal View History

2026-07-31 09:29:27 -04:00
class_name InventoryNotepad
extends PanelContainer
const INK_COLOR := Color(0.16, 0.16, 0.14, 1.0)
const CONTENT_MARGIN_LEFT := 18.0
const CONTENT_MARGIN_TOP := 98.0
const CONTENT_MARGIN_RIGHT := 18.0
const CONTENT_MARGIN_BOTTOM := 16.0
const HANDWRITTEN_FONT: Font = preload("res://ui/fonts/seattle_avenue.otf")
2026-07-31 16:51:18 -04:00
const NOTEPAD_TEXTURE: Texture2D = preload("res://art/ui/ui_notepad.png")
const NOTEPAD_ART_SCALE := 1.1
2026-07-31 09:29:27 -04:00
@export var title_text := "notes"
@export var inset_content := true
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_PASS
apply_handwritten_to(self)
2026-07-31 16:51:18 -04:00
add_theme_stylebox_override("panel", make_layout_style(inset_content))
2026-07-31 09:29:27 -04:00
resized.connect(queue_redraw)
queue_redraw()
static func apply_handwritten_to(root: Control) -> void:
root.add_theme_font_override("font", HANDWRITTEN_FONT)
for descendant: Node in root.find_children("*", "Control", true, false):
var control := descendant as Control
control.add_theme_font_override(
"font", HANDWRITTEN_FONT
)
if control is Label:
control.add_theme_color_override("font_color", INK_COLOR)
2026-07-31 09:29:27 -04:00
func _draw() -> void:
2026-07-31 16:51:18 -04:00
var texture_size := NOTEPAD_TEXTURE.get_size()
var uniform_scale := minf(
size.x / texture_size.x,
size.y / texture_size.y,
) * NOTEPAD_ART_SCALE
var rendered_size := texture_size * uniform_scale
var rendered_rect := Rect2(
(size - rendered_size) * 0.5,
rendered_size,
2026-07-31 09:29:27 -04:00
)
2026-07-31 16:51:18 -04:00
draw_texture_rect(NOTEPAD_TEXTURE, rendered_rect, false)
var font: Font = HANDWRITTEN_FONT
2026-07-31 09:29:27 -04:00
draw_string(
font,
Vector2(20.0, 58.0),
title_text,
HORIZONTAL_ALIGNMENT_CENTER,
size.x - 40.0,
20,
INK_COLOR,
)
2026-07-31 16:51:18 -04:00
static func make_layout_style(with_content_margins: bool = true) -> StyleBoxFlat:
2026-07-31 09:29:27 -04:00
var paper := StyleBoxFlat.new()
2026-07-31 16:51:18 -04:00
paper.bg_color = Color.TRANSPARENT
2026-07-31 09:29:27 -04:00
if with_content_margins:
paper.content_margin_left = CONTENT_MARGIN_LEFT
paper.content_margin_top = CONTENT_MARGIN_TOP
paper.content_margin_right = CONTENT_MARGIN_RIGHT
paper.content_margin_bottom = CONTENT_MARGIN_BOTTOM
return paper