Randoloot/scripts/ui/main_menu_button.gd
2026-10-17 16:20:14 +02:00

56 lines
2.6 KiB
GDScript

extends Button
const DISPLAY_FONT := preload("res://assets/fonts/font2.ttf")
var caption := ""
var detail := ""
var symbol := "01"
var primary := false
var _hover := 0.0
func configure(title: String, subtitle: String, marker: String, main: bool = false) -> void:
caption = title
detail = subtitle
symbol = marker
primary = main
text = ""
custom_minimum_size = Vector2(280, 72 if primary else 60)
mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
for state in ["normal", "hover", "pressed", "focus", "disabled"]:
add_theme_stylebox_override(state, StyleBoxEmpty.new())
tooltip_text = title
queue_redraw()
func _process(delta: float) -> void:
var target := 1.0 if (is_hovered() or has_focus()) and not disabled else 0.0
var next := move_toward(_hover, target, delta * 6.0)
if next != _hover:
_hover = next
queue_redraw()
func _draw() -> void:
var accent := Color("f1bd79") if primary else Color("86d5e8")
if disabled:
accent = Color("607180")
var inset := 2.0 if button_pressed else 0.0
var rect := Rect2(Vector2(inset, inset), size - Vector2.ONE * inset * 2)
var points := PackedVector2Array([rect.position, Vector2(rect.end.x - 14, rect.position.y), Vector2(rect.end.x, rect.position.y + 14), rect.end, Vector2(rect.position.x + 10, rect.end.y), Vector2(rect.position.x, rect.end.y - 10)])
var base := Color(0.028, 0.067, 0.10, 0.88).lerp(Color(0.09, 0.19, 0.25, 0.96), _hover)
if primary:
base = Color(0.17, 0.12, 0.075, 0.92).lerp(Color(0.29, 0.20, 0.105, 0.98), _hover)
draw_colored_polygon(points, base)
var edge := points.duplicate()
edge.append(points[0])
draw_polyline(edge, Color(accent, 0.32 + _hover * 0.6), 1.0, true)
draw_line(Vector2(1, 10), Vector2(1, size.y - 10), Color(accent, 0.85), 3.0, true)
draw_line(Vector2(16, 1), Vector2(68 + _hover * 70, 1), Color(accent, 0.7), 1.0, true)
var body_font := ThemeDB.fallback_font
draw_string(body_font, Vector2(18, size.y * 0.5 + 5), symbol, HORIZONTAL_ALIGNMENT_LEFT, -1, 14, Color(accent, 0.65))
draw_line(Vector2(47, 17), Vector2(47, size.y - 17), Color(accent, 0.22), 1)
var label_color := Color("f4ead9") if primary else Color("e0edf3")
if disabled:
label_color = Color("82909d")
draw_string(DISPLAY_FONT, Vector2(62 + _hover * 3, 29 if primary else 24), caption, HORIZONTAL_ALIGNMENT_LEFT, -1, 17 if primary else 14, label_color)
draw_string(body_font, Vector2(62, 50 if primary else 43), detail, HORIZONTAL_ALIGNMENT_LEFT, size.x - 104, 12, Color("a1acb9") if disabled else Color("a9bcc8"))
var tip := Vector2(size.x - 23 + _hover * 3, size.y * 0.5)
draw_polyline(PackedVector2Array([tip + Vector2(-5, -5), tip, tip + Vector2(-5, 5)]), Color(accent, 0.5 + _hover * 0.5), 1.5, true)