class_name UiTheme extends RefCounted ## The game's UI theme (the project's default theme, gui/theme/custom = ## res://game/resources/ui_theme.tres, written by game/tools/build_ui_theme.gd from build()): ## dark straw-trimmed panels, buttons that light up gold on hover and show a thick gold ring ## when focused (keyboard and gamepad players always see where they are), sliders, check ## boxes, and tabs to match. Labels keep the default look; the HUD sets its own sizes. const TEXT := Color(0.95, 0.93, 0.85) const GOLD := Color(0.95, 0.82, 0.45) const DIM := Color(0.5, 0.5, 0.45) static func build() -> Theme: var t := Theme.new() t.default_font_size = 22 t.set_stylebox("panel", "PanelContainer", ReviewPanel.backing()) t.set_stylebox("panel", "Panel", ReviewPanel.backing()) for type in ["Button", "OptionButton"]: t.set_stylebox("normal", type, _box(Color(0.2, 0.24, 0.18), Color(0.45, 0.42, 0.3), 2)) t.set_stylebox("hover", type, _box(Color(0.3, 0.35, 0.24), GOLD, 2)) t.set_stylebox("pressed", type, _box(Color(0.15, 0.19, 0.13), GOLD, 2)) t.set_stylebox("disabled", type, _box(Color(0.14, 0.15, 0.13), Color(0.28, 0.28, 0.25), 2)) var focus := _box(Color(0, 0, 0, 0), GOLD, 4) focus.draw_center = false focus.set_expand_margin_all(3.0) t.set_stylebox("focus", type, focus) t.set_color("font_color", type, TEXT) t.set_color("font_hover_color", type, Color(1.0, 0.95, 0.7)) t.set_color("font_focus_color", type, Color(1.0, 0.95, 0.7)) t.set_color("font_pressed_color", type, GOLD) t.set_color("font_disabled_color", type, DIM) for type in ["CheckBox", "CheckButton"]: var none := StyleBoxEmpty.new() t.set_stylebox("normal", type, none) t.set_stylebox("pressed", type, none) t.set_stylebox("hover", type, _box(Color(1, 1, 1, 0.05), Color(0, 0, 0, 0), 0)) t.set_stylebox("hover_pressed", type, _box(Color(1, 1, 1, 0.05), Color(0, 0, 0, 0), 0)) var focus := _box(Color(0, 0, 0, 0), GOLD, 3) focus.draw_center = false t.set_stylebox("focus", type, focus) t.set_color("font_color", type, TEXT) t.set_color("font_hover_color", type, Color(1.0, 0.95, 0.7)) t.set_color("font_focus_color", type, Color(1.0, 0.95, 0.7)) t.set_color("font_pressed_color", type, TEXT) t.set_icon("checked", type, check_icon(true, false)) t.set_icon("unchecked", type, check_icon(false, false)) t.set_icon("checked_disabled", type, check_icon(true, true)) t.set_icon("unchecked_disabled", type, check_icon(false, true)) t.set_constant("h_separation", type, 12) var track := _box(Color(0.22, 0.24, 0.2), Color(0, 0, 0, 0), 0) track.content_margin_top = 4.0 track.content_margin_bottom = 4.0 t.set_stylebox("slider", "HSlider", track) var filled := _box(Color(0.55, 0.78, 0.4), Color(0, 0, 0, 0), 0) t.set_stylebox("grabber_area", "HSlider", filled) t.set_stylebox("grabber_area_highlight", "HSlider", _box(Color(0.7, 0.9, 0.5), Color(0, 0, 0, 0), 0)) var slider_focus := _box(Color(0, 0, 0, 0), GOLD, 3) slider_focus.draw_center = false slider_focus.set_expand_margin_all(4.0) t.set_stylebox("focus", "HSlider", slider_focus) t.set_stylebox("tab_selected", "TabContainer", _box(Color(0.3, 0.35, 0.24), GOLD, 2)) t.set_stylebox("tab_unselected", "TabContainer", _box(Color(0.16, 0.19, 0.14), Color(0.35, 0.33, 0.25), 2)) t.set_stylebox("tab_hovered", "TabContainer", _box(Color(0.24, 0.28, 0.2), GOLD, 2)) var tab_focus := _box(Color(0, 0, 0, 0), GOLD, 3) tab_focus.draw_center = false t.set_stylebox("tab_focus", "TabContainer", tab_focus) t.set_stylebox("panel", "TabContainer", _box(Color(0.12, 0.14, 0.11), Color(0.35, 0.33, 0.25), 2)) t.set_color("font_selected_color", "TabContainer", GOLD) t.set_color("font_unselected_color", "TabContainer", TEXT) t.set_color("font_hovered_color", "TabContainer", Color(1.0, 0.95, 0.7)) return t ## A 30 px check box: a dark rounded square with a light border, filled gold with a dark tick ## when checked. static func check_icon(checked: bool, disabled: bool) -> ImageTexture: const N := 30 var img := Image.create(N, N, false, Image.FORMAT_RGBA8) var border := Color(0.78, 0.74, 0.6) if not disabled else Color(0.4, 0.4, 0.36) var fill := (GOLD if not disabled else Color(0.45, 0.42, 0.32)) if checked else Color(0.14, 0.16, 0.12) var tick := Color(0.12, 0.1, 0.05) for y in N: for x in N: var p := Vector2(x + 0.5, y + 0.5) var q := (p - Vector2(N, N) * 0.5).abs() - Vector2(N * 0.5 - 5.0, N * 0.5 - 5.0) var d := Vector2(maxf(q.x, 0.0), maxf(q.y, 0.0)).length() + minf(maxf(q.x, q.y), 0.0) - 4.0 # rounded square var c := Color(0, 0, 0, 0) if d <= 0.0: c = fill if d < -2.0 else border if checked and d < -2.0 and minf(_segment(p, Vector2(8, 15.5), Vector2(13, 21)), _segment(p, Vector2(13, 21), Vector2(22.5, 9))) < 2.0: c = tick img.set_pixel(x, y, c) return ImageTexture.create_from_image(img) static func _segment(p: Vector2, a: Vector2, b: Vector2) -> float: var ab := b - a var t := clampf((p - a).dot(ab) / ab.length_squared(), 0.0, 1.0) return p.distance_to(a + ab * t) static func _box(bg: Color, border: Color, width: int) -> StyleBoxFlat: var s := StyleBoxFlat.new() s.bg_color = bg s.border_color = border s.set_border_width_all(width) s.set_corner_radius_all(6) s.content_margin_left = 16.0 s.content_margin_right = 16.0 s.content_margin_top = 8.0 s.content_margin_bottom = 8.0 return s