Skip to content

Commit 41a7070

Browse files
committed
Added interface fonts options
1 parent b4fcad0 commit 41a7070

32 files changed

Lines changed: 520 additions & 168 deletions

material_maker/globals.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ const DEFAULT_CONFIG : Dictionary = {
6060
dialog_dim_background = true,
6161
node_minimize_button = false,
6262
node_close_button = false,
63+
ui_use_system_font = false,
64+
ui_font_size = 16,
65+
ui_code_font_size = 12,
6366
}
6467

6568

@@ -228,3 +231,6 @@ func get_node_title_from_gen(generator : MMGenBase) -> String:
228231
var gnode : GraphNode = graph.get_node(node_path)
229232
return gnode.title.to_snake_case()
230233
return "unnamed"
234+
235+
func is_classic_theme() -> bool:
236+
return "classic" in mm_globals.main_window.theme.resource_path

material_maker/main_window.gd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func _ready() -> void:
161161
if mm_globals.config.has_section_key("window", "size"):
162162
get_window().size = mm_globals.config.get_value("window", "size")
163163

164+
# Update fonts
165+
FontManager.rebuild_fonts()
166+
theme.default_font = FontManager.main_font
167+
theme.default_font_size = FontManager.ui_font_size
168+
164169
# Restore the theme
165170
var theme_name: String = "default dark"
166171
if mm_globals.config.has_section_key("window", "theme"):
@@ -620,14 +625,21 @@ func create_menu_set_theme(menu : MMMenuManager.MenuBase) -> void:
620625
func change_theme(theme_name) -> void:
621626
if not ResourceLoader.exists("res://material_maker/theme/"+theme_name+".tres"):
622627
theme_name = "default dark"
623-
var _theme = load("res://material_maker/theme/"+theme_name+".tres")
628+
var _theme : Theme = load("res://material_maker/theme/"+theme_name+".tres")
624629
if _theme == theme:
625630
return
626631
if _theme is EnhancedTheme:
627632
_theme.update()
628-
await get_tree().process_frame
629633
theme = _theme
634+
theme.default_font = FontManager.main_font
635+
theme.set_font("title_font", "TooltipPanel", FontManager.main_font)
636+
theme.set_font("font", "TooltipLabel", FontManager.main_font)
637+
630638
if "classic" in theme_name:
639+
if not FontManager.has_font_config("main_font"):
640+
theme.default_font = FontManager.classic_font
641+
theme.set_font("title_font", "TooltipPanel", FontManager.classic_font)
642+
theme.set_font("font", "TooltipLabel", FontManager.classic_font)
631643
RenderingServer.set_default_clear_color(Color(0.14, 0.17,0.23))
632644
else:
633645
RenderingServer.set_default_clear_color(

material_maker/nodes/base.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func _draw() -> void:
229229
draw_style_box(get_theme_stylebox("node_highlight"), Rect2(Vector2.ZERO, size))
230230
if generator.rendering_time > 0:
231231
var time_color : Color = get_rendering_time_color(generator.rendering_time)
232-
var buffer_timing_font : Font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
232+
var buffer_timing_font : FontVariation = FontManager.medium_font
233233
@warning_ignore_start("narrowing_conversion")
234234
draw_string_outline(buffer_timing_font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, 4, Color.BLACK)
235235
draw_string(buffer_timing_font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, time_color)

material_maker/nodes/generic/generic.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func do_update_preview() -> void:
417417
func update_title() -> void:
418418
title = TranslationServer.translate(generator.get_type_name())
419419
if generator == null or generator.minimized:
420-
var font : Font = get_theme_font("default_font")
420+
var font : Font = FontManager.medium_font
421421
var max_title_width = 28
422422
if font.get_string_size(title).x > max_title_width:
423423
for i in range(1, title.length()-1):
@@ -438,6 +438,8 @@ func update_node() -> void:
438438
if mm_globals.get_config(SETTINGS_NODE_CLOSE_BUTTON) else false)
439439
# Rebuild node
440440
update_title()
441+
var title_label : Label = get_titlebar_hbox().get_child(0)
442+
title_label.add_theme_font_override("font", FontManager.medium_font)
441443
# Resize to minimum
442444
size = Vector2(0, 0)
443445
# Regex for labels

material_maker/nodes/portal/portal.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extends MMGraphNodeMinimal
22
class_name MMGraphPortal
33

4-
const LABEL_FONT = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
4+
var label_font : FontVariation = FontManager.medium_font
55

66
## Whether portal's link is being edited
77
## (i.e. its associated LineEdit is visible)
@@ -32,11 +32,11 @@ func _draw() -> void:
3232
var label_pos := size * 0.5
3333
var label_color : Color = generator.color
3434

35-
var label_size = LABEL_FONT.get_string_size(get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
35+
var label_size = label_font.get_string_size(get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size)
3636
var label_draw_pos := label_pos - Vector2(label_size.x * 0.5, label_y_offset)
3737
if not is_editing:
38-
draw_string_outline(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK)
39-
draw_string(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color)
38+
draw_string_outline(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK)
39+
draw_string(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color)
4040

4141
# label dragger
4242
%Dragger.mouse_filter = MOUSE_FILTER_IGNORE if is_editing else MOUSE_FILTER_PASS
@@ -274,7 +274,7 @@ func setup_portal_edit() -> void:
274274
var old_link := get_link()
275275
var graph : MMGraphEdit = get_parent()
276276
var edit := LineEdit.new()
277-
edit.add_theme_font_override("font", LABEL_FONT)
277+
edit.add_theme_font_override("font", label_font)
278278
edit.alignment = HORIZONTAL_ALIGNMENT_CENTER
279279
edit.max_length = 64
280280
edit.expand_to_text_length = true

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ signal graph_changed
6969
signal view_updated
7070
signal preview_changed
7171

72-
7372
func _ready() -> void:
7473
OS.low_processor_usage_mode = true
7574
center_view()

material_maker/panels/library/library.gd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ var category_buttons = {}
1313
@onready var filter_line_edit : LineEdit = %Filter
1414
@onready var item_menu : PopupMenu = %ItemMenu
1515

16-
var section_font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")
17-
1816
const MINIMUM_ITEM_HEIGHT : int = 30
1917

2018
const MENU_CREATE_LIBRARY : int = 1000
@@ -68,8 +66,9 @@ func _notification(what: int) -> void:
6866
func update_theme() -> void:
6967
libraries_button.icon = get_theme_icon("settings", "MM_Icons")
7068

71-
var is_theme_classic : bool = "classic" in mm_globals.main_window.theme.resource_path
69+
var is_theme_classic : bool = mm_globals.is_classic_theme()
7270
library_manager.update_section_colors(is_theme_classic)
71+
update_tree()
7372

7473
func init_expanded_items() -> void:
7574
var f = FileAccess.open("user://expanded_items.bin", FileAccess.READ)
@@ -160,7 +159,7 @@ func update_tree() -> void:
160159

161160
for section : TreeItem in tree.get_root().get_children():
162161
if section.get_children().size():
163-
section.set_custom_font(0, section_font)
162+
section.set_custom_font(0, FontManager.medium_font)
164163
tree.queue_redraw()
165164

166165
func add_item(item, library_index : int, item_name : String, item_icon = null, item_parent = null, force_expand = false) -> TreeItem:

material_maker/theme/classic.tres

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_resource type="Theme" script_class="EnhancedTheme" load_steps=4 format=3 uid="uid://wuddtc1fglln"]
1+
[gd_resource type="Theme" script_class="EnhancedTheme" format=3 uid="uid://wuddtc1fglln"]
22

33
[ext_resource type="Theme" uid="uid://w487nirev8y5" path="res://material_maker/theme/classic_base.tres" id="1_meah8"]
44
[ext_resource type="Script" uid="uid://3ga2k3abkk0d" path="res://material_maker/theme/enhanced_theme_system/color_swap.gd" id="5_qpu3p"]

material_maker/theme/default dark.tres

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_resource type="Theme" script_class="EnhancedTheme" load_steps=42 format=3 uid="uid://dhuhq2immquoh"]
1+
[gd_resource type="Theme" script_class="EnhancedTheme" format=3 uid="uid://dhuhq2immquoh"]
22

33
[ext_resource type="Theme" uid="uid://b628lwfk6ig2c" path="res://material_maker/theme/default.tres" id="3_xjelh"]
44
[ext_resource type="Script" uid="uid://3ga2k3abkk0d" path="res://material_maker/theme/enhanced_theme_system/color_swap.gd" id="4_0efyb"]

material_maker/theme/default.tres

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,8 @@ GraphNode/styles/titlebar = SubResource("StyleBoxFlat_imqse")
12771277
GraphNode/styles/titlebar_selected = SubResource("StyleBoxFlat_ru0kh")
12781278
GraphNodeTitleLabel/colors/font_outline_color = Color(0.168627, 0.176471, 0.192157, 1)
12791279
GraphNodeTitleLabel/colors/font_shadow_color = Color(0.168627, 0.176471, 0.192157, 1)
1280-
GraphNodeTitleLabel/constants/outline_size = 5
1281-
GraphNodeTitleLabel/constants/shadow_outline_size = 6
1280+
GraphNodeTitleLabel/constants/outline_size = 6
1281+
GraphNodeTitleLabel/constants/shadow_outline_size = 7
12821282
GraphNodeTitleLabel/fonts/font = ExtResource("2_5e0gw")
12831283
HScrollBar/styles/grabber = SubResource("StyleBoxFlat_fs6qc")
12841284
HScrollBar/styles/grabber_highlight = SubResource("StyleBoxFlat_70aex")
@@ -1526,6 +1526,8 @@ TabContainer/styles/tab_selected = SubResource("StyleBoxFlat_ld0tj")
15261526
TabContainer/styles/tab_unselected = SubResource("StyleBoxFlat_e07v0")
15271527
TextEdit/styles/focus = SubResource("StyleBoxEmpty_asgc8")
15281528
TooltipLabel/font_sizes/font_size = 15
1529+
TooltipLabel/fonts/font = ExtResource("1_5tfb1")
1530+
TooltipPanel/fonts/title_font = ExtResource("1_5tfb1")
15291531
TooltipPanel/styles/panel = SubResource("StyleBoxFlat_5rnro")
15301532
Tree/colors/font_color = Color(0.7, 0.7, 0.7, 1)
15311533
Tree/colors/font_disabled_color = Color(0.875, 0.875, 0.875, 0.5)

0 commit comments

Comments
 (0)