diff --git a/material_maker/globals.gd b/material_maker/globals.gd index 79d377a66..c2c3cbcd9 100644 --- a/material_maker/globals.gd +++ b/material_maker/globals.gd @@ -64,7 +64,11 @@ const DEFAULT_CONFIG : Dictionary = { node_minimize_button = true, node_close_button = true, ui_field_sensitivity = 1.0, - color_picker_floating = false + color_picker_floating = false, + ui_use_system_font = false, + ui_font_size = 16, + ui_code_font_size = 12, + ui_font_enable_msdf = true, } @@ -237,3 +241,6 @@ func ui_scale_factor() -> float: if get_tree().root.gui_embed_subwindows: return 1.0 return get_tree().root.content_scale_factor + +func is_classic_theme() -> bool: + return "classic" in mm_globals.main_window.theme.resource_path diff --git a/material_maker/main_window.gd b/material_maker/main_window.gd index 4d7f9b658..6757be13b 100644 --- a/material_maker/main_window.gd +++ b/material_maker/main_window.gd @@ -165,6 +165,11 @@ func _ready() -> void: if mm_globals.config.has_section_key("window", "size"): get_window().size = mm_globals.config.get_value("window", "size") + # Update fonts + FontManager.rebuild_fonts() + theme.default_font = FontManager.main_font + theme.default_font_size = FontManager.ui_font_size + # Restore the theme var theme_name: String = "default dark" if mm_globals.config.has_section_key("window", "theme"): @@ -631,14 +636,21 @@ func create_menu_set_theme(menu : MMMenuManager.MenuBase) -> void: func change_theme(theme_name) -> void: if not ResourceLoader.exists("res://material_maker/theme/"+theme_name+".tres"): theme_name = "default dark" - var _theme = load("res://material_maker/theme/"+theme_name+".tres") + var _theme : Theme = load("res://material_maker/theme/"+theme_name+".tres") if _theme == theme: return if _theme is EnhancedTheme: _theme.update() - await get_tree().process_frame theme = _theme + theme.default_font = FontManager.main_font + theme.set_font("title_font", "TooltipPanel", FontManager.main_font) + theme.set_font("font", "TooltipLabel", FontManager.main_font) + if "classic" in theme_name: + if not FontManager.has_font_config("main_font"): + theme.default_font = FontManager.classic_font + theme.set_font("title_font", "TooltipPanel", FontManager.classic_font) + theme.set_font("font", "TooltipLabel", FontManager.classic_font) RenderingServer.set_default_clear_color(Color(0.14, 0.17,0.23)) else: RenderingServer.set_default_clear_color( diff --git a/material_maker/nodes/base.gd b/material_maker/nodes/base.gd index fb070f3eb..d6c19de3e 100644 --- a/material_maker/nodes/base.gd +++ b/material_maker/nodes/base.gd @@ -231,7 +231,7 @@ func _draw() -> void: draw_style_box(get_theme_stylebox("node_highlight"), Rect2(Vector2.ZERO, size)) if generator.rendering_time > 0: var time_color : Color = get_rendering_time_color(generator.rendering_time) - var buffer_timing_font : Font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf") + var buffer_timing_font : FontVariation = FontManager.medium_font @warning_ignore_start("narrowing_conversion") 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) draw_string(buffer_timing_font, Vector2i(0, size.y+12), str(generator.rendering_time)+"ms", HORIZONTAL_ALIGNMENT_CENTER, size.x, 12, time_color) diff --git a/material_maker/nodes/generic/generic.gd b/material_maker/nodes/generic/generic.gd index fda580f44..fe5532038 100644 --- a/material_maker/nodes/generic/generic.gd +++ b/material_maker/nodes/generic/generic.gd @@ -421,7 +421,7 @@ func do_update_preview() -> void: func update_title() -> void: title = TranslationServer.translate(generator.get_type_name()) if generator == null or generator.minimized: - var font : Font = get_theme_font("default_font") + var font : Font = FontManager.medium_font var max_title_width = 28 if font.get_string_size(title).x > max_title_width: for i in range(1, title.length()-1): @@ -443,6 +443,8 @@ func update_node() -> void: if mm_globals.get_config(SETTINGS_NODE_CLOSE_BUTTON) else false) # Rebuild node update_title() + var title_label : Label = get_titlebar_hbox().get_child(0) + title_label.add_theme_font_override("font", FontManager.medium_font) # Resize to minimum size = Vector2(0, 0) # Regex for labels diff --git a/material_maker/nodes/minimal.gd b/material_maker/nodes/minimal.gd index d26a2eca0..a633e6453 100644 --- a/material_maker/nodes/minimal.gd +++ b/material_maker/nodes/minimal.gd @@ -19,6 +19,8 @@ func _ready() -> void: buttons = HBoxContainer.new() var space : Control = Control.new() buttons.add_theme_constant_override("separation", 1) + var title_label : Label = get_titlebar_hbox().get_child(0) + title_label.add_theme_font_override("font", FontManager.medium_font) space.custom_minimum_size = Vector2(4, 0) buttons.add_child(space) get_titlebar_hbox().add_child(buttons) diff --git a/material_maker/nodes/portal/portal.gd b/material_maker/nodes/portal/portal.gd index cc42fa726..97a7ade34 100644 --- a/material_maker/nodes/portal/portal.gd +++ b/material_maker/nodes/portal/portal.gd @@ -1,7 +1,7 @@ extends MMGraphNodeMinimal class_name MMGraphPortal -const LABEL_FONT = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf") +var label_font : FontVariation = FontManager.medium_font ## Whether portal's link is being edited ## (i.e. its associated LineEdit is visible) @@ -34,7 +34,7 @@ func _draw() -> void: var label_pos : Vector2 = size * 0.5 var label_color : Color = generator.color var label_draw_pos : Vector2 = label_pos - var label_size : Vector2 = LABEL_FONT.get_string_size( + var label_size : Vector2 = label_font.get_string_size( get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size) if not is_editing: @@ -43,8 +43,8 @@ func _draw() -> void: else: label_draw_pos -= Vector2(label_size.x * 0.5, label_y_offset) - draw_string_outline(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK) - draw_string(LABEL_FONT, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color) + draw_string_outline(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, 5, Color.BLACK) + draw_string(label_font, label_draw_pos, get_link(), HORIZONTAL_ALIGNMENT_CENTER, -1, label_font_size, label_color) # label dragger %Dragger.mouse_filter = MOUSE_FILTER_IGNORE if is_editing else MOUSE_FILTER_PASS @@ -338,8 +338,8 @@ func setup_portal_edit() -> void: var old_link : String = get_link() var graph : MMGraphEdit = get_parent() - var edit : LineEdit = LineEdit.new() - edit.add_theme_font_override("font", LABEL_FONT) + var edit := LineEdit.new() + edit.add_theme_font_override("font", label_font) edit.alignment = HORIZONTAL_ALIGNMENT_CENTER edit.max_length = 64 edit.expand_to_text_length = true diff --git a/material_maker/panels/graph_edit/graph_zoom_menu.gd b/material_maker/panels/graph_edit/graph_zoom_menu.gd index 19fe28e59..3bc26ce8d 100644 --- a/material_maker/panels/graph_edit/graph_zoom_menu.gd +++ b/material_maker/panels/graph_edit/graph_zoom_menu.gd @@ -40,3 +40,7 @@ func update_zoom() -> void: if graph_edit: graph_edit.zoom = zoom_level mm_globals.set_config(SETTING_GRAPH_ZOOM_LEVEL, zoom_level) + +func _notification(what : int) -> void: + if what == NOTIFICATION_THEME_CHANGED: + %ZoomLabel.add_theme_font_override("font", FontManager.main_font) diff --git a/material_maker/panels/library/library.gd b/material_maker/panels/library/library.gd index 739fcfd97..9b832077d 100644 --- a/material_maker/panels/library/library.gd +++ b/material_maker/panels/library/library.gd @@ -13,8 +13,6 @@ var category_buttons = {} @onready var filter_line_edit : LineEdit = %Filter @onready var item_menu : PopupMenu = %ItemMenu -var section_font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf") - const MINIMUM_ITEM_HEIGHT : int = 30 const MENU_CREATE_LIBRARY : int = 1000 @@ -63,8 +61,9 @@ func _notification(what: int) -> void: func update_theme() -> void: libraries_button.icon = get_theme_icon("settings", "MM_Icons") - var is_theme_classic : bool = "classic" in mm_globals.main_window.theme.resource_path + var is_theme_classic : bool = mm_globals.is_classic_theme() library_manager.update_section_colors(is_theme_classic) + update_tree() func init_expanded_items() -> void: var f = FileAccess.open("user://expanded_items.bin", FileAccess.READ) @@ -155,7 +154,7 @@ func update_tree() -> void: for section : TreeItem in tree.get_root().get_children(): if section.get_children().size(): - section.set_custom_font(0, section_font) + section.set_custom_font(0, FontManager.medium_font) tree.queue_redraw() func add_item(item, library_index : int, item_name : String, item_icon = null, item_parent = null, force_expand = false) -> TreeItem: diff --git a/material_maker/panels/preview_2d/export_menu.gd b/material_maker/panels/preview_2d/export_menu.gd index 5d4efb1f6..5ccffc2bb 100644 --- a/material_maker/panels/preview_2d/export_menu.gd +++ b/material_maker/panels/preview_2d/export_menu.gd @@ -24,6 +24,8 @@ func _notification(what: int) -> void: %ExportFolderButton.icon = get_theme_icon("folder", "MM_Icons") %ExportFileResultLabel.add_theme_color_override("font_color", get_theme_color("font_color", "Label").lerp(Color.ORANGE, 0.5)) %ExportNotificationLabel.add_theme_color_override("font_color", get_theme_color("font_color", "Label").lerp(get_theme_color("icon_pressed_color", "Button"), 0.5)) + %ExportFileResultLabel.add_theme_font_override("font", + FontManager.create_italic_variation(FontManager.main_font)) func _open() -> void: diff --git a/material_maker/panels/preview_3d/export_menu.gd b/material_maker/panels/preview_3d/export_menu.gd index 21d166116..3f33dfa64 100644 --- a/material_maker/panels/preview_3d/export_menu.gd +++ b/material_maker/panels/preview_3d/export_menu.gd @@ -100,3 +100,10 @@ func interpret_map_file_name(file_name: String, path:="") -> String: func _on_map_file_type_item_selected(_index: int) -> void: update_generate_map_file_label() + +func _notification(what: int) -> void: + if what == NOTIFICATION_THEME_CHANGED: + if not is_node_ready(): + await ready + MapExportFileResultLabel.add_theme_font_override("font", + FontManager.create_italic_variation(FontManager.main_font)) diff --git a/material_maker/theme/classic.tres b/material_maker/theme/classic.tres index ee3307336..c5c391144 100644 --- a/material_maker/theme/classic.tres +++ b/material_maker/theme/classic.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" script_class="EnhancedTheme" load_steps=4 format=3 uid="uid://wuddtc1fglln"] +[gd_resource type="Theme" script_class="EnhancedTheme" format=3 uid="uid://wuddtc1fglln"] [ext_resource type="Theme" uid="uid://w487nirev8y5" path="res://material_maker/theme/classic_base.tres" id="1_meah8"] [ext_resource type="Script" uid="uid://3ga2k3abkk0d" path="res://material_maker/theme/enhanced_theme_system/color_swap.gd" id="5_qpu3p"] diff --git a/material_maker/theme/default.tres b/material_maker/theme/default.tres index dd8b6e67b..391f535c0 100644 --- a/material_maker/theme/default.tres +++ b/material_maker/theme/default.tres @@ -1345,8 +1345,8 @@ GraphNode/styles/titlebar = SubResource("StyleBoxFlat_imqse") GraphNode/styles/titlebar_selected = SubResource("StyleBoxFlat_ru0kh") GraphNodeTitleLabel/colors/font_outline_color = Color(0.168627, 0.176471, 0.192157, 1) GraphNodeTitleLabel/colors/font_shadow_color = Color(0.168627, 0.176471, 0.192157, 1) -GraphNodeTitleLabel/constants/outline_size = 5 -GraphNodeTitleLabel/constants/shadow_outline_size = 6 +GraphNodeTitleLabel/constants/outline_size = 6 +GraphNodeTitleLabel/constants/shadow_outline_size = 7 GraphNodeTitleLabel/fonts/font = ExtResource("2_5e0gw") HScrollBar/styles/grabber = SubResource("StyleBoxFlat_fs6qc") HScrollBar/styles/grabber_highlight = SubResource("StyleBoxFlat_70aex") @@ -1603,6 +1603,8 @@ TabContainer/styles/tab_selected = SubResource("StyleBoxFlat_ld0tj") TabContainer/styles/tab_unselected = SubResource("StyleBoxFlat_e07v0") TextEdit/styles/focus = SubResource("StyleBoxEmpty_asgc8") TooltipLabel/font_sizes/font_size = 15 +TooltipLabel/fonts/font = ExtResource("1_5tfb1") +TooltipPanel/fonts/title_font = ExtResource("1_5tfb1") TooltipPanel/styles/panel = SubResource("StyleBoxFlat_5rnro") Tree/colors/font_color = Color(0.7, 0.7, 0.7, 1) Tree/colors/font_disabled_color = Color(0.875, 0.875, 0.875, 0.5) diff --git a/material_maker/theme/font_manager.gd b/material_maker/theme/font_manager.gd new file mode 100644 index 000000000..799e5e08f --- /dev/null +++ b/material_maker/theme/font_manager.gd @@ -0,0 +1,81 @@ +class_name FontManager +extends RefCounted + +static var main_font : FontVariation = preload("res://material_maker/theme/fonts/ui/main_font.tres") +static var medium_font : FontVariation = preload("res://material_maker/theme/fonts/ui/medium_font.tres") +static var bold_font : FontVariation = preload("res://material_maker/theme/fonts/ui/bold_font.tres") +static var code_font : FontVariation = preload("res://material_maker/theme/fonts/ui/code_font.tres") + +static var classic_font : FontVariation = preload("res://material_maker/theme/fonts/ui/classic_font.tres") + +static var ui_font_size : int +static var ui_code_font_size : int + +const SETTINGS_UI_FONT_SIZE : String = "ui_font_size" +const SETTINGS_UI_CODE_FONT_SIZE : String = "ui_code_font_size" +const SETTINGS_UI_USE_SYSTEM_FONT : String = "ui_use_system_font" + +static func create_italic_variation(font : FontVariation) -> FontVariation: + var f : FontVariation = font.duplicate() + f.variation_transform = Transform2D( + Vector2(1.0, 0.22), Vector2(0.0, 1.0), Vector2.ZERO) + return f + +static func has_font_config(config : String) -> bool: + return (mm_globals.has_config(config) + and not mm_globals.get_config(config).is_empty()) + +static func setup_rendering(font : FontVariation) -> void: + if mm_globals.get_config("ui_font_enable_msdf"): + font.base_font.msdf_pixel_range = 32 + font.base_font.msdf_size = 48 + font.base_font.multichannel_signed_distance_field = true + else: + font.base_font.multichannel_signed_distance_field = false + +static func rebuild_fonts() -> void: + if mm_globals.has_config(SETTINGS_UI_FONT_SIZE): + ui_font_size = mm_globals.get_config(SETTINGS_UI_FONT_SIZE) + + if mm_globals.has_config(SETTINGS_UI_CODE_FONT_SIZE): + ui_code_font_size = mm_globals.get_config(SETTINGS_UI_CODE_FONT_SIZE) + + if mm_globals.get_config(SETTINGS_UI_USE_SYSTEM_FONT): + main_font = preload("res://material_maker/theme/fonts/system/system_main_font.tres") + medium_font = preload("res://material_maker/theme/fonts/system/system_medium_font.tres") + bold_font = preload("res://material_maker/theme/fonts/system/system_bold_font.tres") + code_font = preload("res://material_maker/theme/fonts/system/system_code_font.tres") + + var config : Dictionary[FontVariation, Dictionary] = { + main_font : { "weight": 400, "name": "Segoe UI" }, + medium_font : { "weight": 600, "name": "Segoe UI" }, + bold_font : { "weight": 800, "name": "Segoe UI" }, + code_font : { "weight": 400, "name": "Consolas" } + } + + for font_var : FontVariation in config: + var cfg : Dictionary = config[font_var] + if OS.get_name() == "Windows": + font_var.base_font = SystemFont.new() + font_var.base_font.font_names.append(cfg.name) + font_var.base_font.font_weight = cfg.weight + setup_rendering(font_var) + return + + var fonts : Dictionary[String, FontVariation] = { + "main_font": main_font, + "medium_font": medium_font, + "bold_font": bold_font, + "code_font": code_font + } + + for font : String in fonts: + var font_variation : FontVariation = fonts[font] + var custom_font_path : String = mm_globals.get_config(font) + if has_font_config(font) and FileAccess.file_exists(custom_font_path): + font_variation.base_font = FontFile.new() + font_variation.base_font.load_dynamic_font(custom_font_path) + else: + mm_globals.set_config(font, "") + font_variation.base_font = load(font_variation.fallbacks[0].resource_path) + setup_rendering(font_variation) diff --git a/material_maker/theme/font_manager.gd.uid b/material_maker/theme/font_manager.gd.uid new file mode 100644 index 000000000..bbfe459b2 --- /dev/null +++ b/material_maker/theme/font_manager.gd.uid @@ -0,0 +1 @@ +uid://c50net8nr1iig diff --git a/material_maker/theme/fonts/system/system_bold_font.tres b/material_maker/theme/fonts/system/system_bold_font.tres new file mode 100644 index 000000000..0ee605336 --- /dev/null +++ b/material_maker/theme/fonts/system/system_bold_font.tres @@ -0,0 +1,14 @@ +[gd_resource type="FontVariation" format=3 uid="uid://ch4d2bwcn5a"] + +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="1_ub2cf"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="2_ml3ku"] + +[sub_resource type="SystemFont" id="SystemFont_ouejq"] +font_names = PackedStringArray("Sans-Serif") +font_weight = 800 +multichannel_signed_distance_field = true +msdf_pixel_range = 32 + +[resource] +fallbacks = Array[Font]([ExtResource("1_ub2cf"), ExtResource("2_ml3ku")]) +base_font = SubResource("SystemFont_ouejq") diff --git a/material_maker/theme/fonts/system/system_code_font.tres b/material_maker/theme/fonts/system/system_code_font.tres new file mode 100644 index 000000000..9f7795d14 --- /dev/null +++ b/material_maker/theme/fonts/system/system_code_font.tres @@ -0,0 +1,13 @@ +[gd_resource type="FontVariation" format=3 uid="uid://dhfia0y843i1y"] + +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="1_tb5d5"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="2_qhq60"] + +[sub_resource type="SystemFont" id="SystemFont_ouejq"] +font_names = PackedStringArray("Monospace") +multichannel_signed_distance_field = true +msdf_pixel_range = 32 + +[resource] +fallbacks = Array[Font]([ExtResource("1_tb5d5"), ExtResource("2_qhq60")]) +base_font = SubResource("SystemFont_ouejq") diff --git a/material_maker/theme/fonts/system/system_main_font.tres b/material_maker/theme/fonts/system/system_main_font.tres new file mode 100644 index 000000000..693bcc095 --- /dev/null +++ b/material_maker/theme/fonts/system/system_main_font.tres @@ -0,0 +1,13 @@ +[gd_resource type="FontVariation" format=3 uid="uid://bke5ujsr368cv"] + +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="1_dcm08"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="2_dulnh"] + +[sub_resource type="SystemFont" id="SystemFont_ouejq"] +font_names = PackedStringArray("Sans-Serif") +multichannel_signed_distance_field = true +msdf_pixel_range = 32 + +[resource] +fallbacks = Array[Font]([ExtResource("1_dcm08"), ExtResource("2_dulnh")]) +base_font = SubResource("SystemFont_ouejq") diff --git a/material_maker/theme/fonts/system/system_medium_font.tres b/material_maker/theme/fonts/system/system_medium_font.tres new file mode 100644 index 000000000..28ce67581 --- /dev/null +++ b/material_maker/theme/fonts/system/system_medium_font.tres @@ -0,0 +1,14 @@ +[gd_resource type="FontVariation" format=3 uid="uid://6k785eldqigf"] + +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="1_qyurx"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="2_wh3pl"] + +[sub_resource type="SystemFont" id="SystemFont_ouejq"] +font_names = PackedStringArray("Sans-Serif") +font_weight = 600 +multichannel_signed_distance_field = true +msdf_pixel_range = 32 + +[resource] +fallbacks = Array[Font]([ExtResource("1_qyurx"), ExtResource("2_wh3pl")]) +base_font = SubResource("SystemFont_ouejq") diff --git a/material_maker/theme/fonts/ui/bold_font.tres b/material_maker/theme/fonts/ui/bold_font.tres new file mode 100644 index 000000000..f5c15a74d --- /dev/null +++ b/material_maker/theme/fonts/ui/bold_font.tres @@ -0,0 +1,8 @@ +[gd_resource type="FontVariation" format=3 uid="uid://cfoeywyltjuo2"] + +[ext_resource type="FontFile" uid="uid://dq4ssdyyfotag" path="res://material_maker/theme/font_rubik/Rubik-Bold.ttf" id="1_v3ac0"] +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="2_bhm15"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="3_bhm15"] + +[resource] +fallbacks = Array[Font]([ExtResource("1_v3ac0"), ExtResource("2_bhm15"), ExtResource("3_bhm15")]) diff --git a/material_maker/theme/fonts/ui/classic_font.tres b/material_maker/theme/fonts/ui/classic_font.tres new file mode 100644 index 000000000..333c5f18a --- /dev/null +++ b/material_maker/theme/fonts/ui/classic_font.tres @@ -0,0 +1,7 @@ +[gd_resource type="FontVariation" format=3 uid="uid://cukrxt4w03iac"] + +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="2_em5my"] + +[resource] +fallbacks = Array[Font]([ExtResource("2_em5my")]) +base_font = ExtResource("2_em5my") diff --git a/material_maker/theme/fonts/ui/code_font.tres b/material_maker/theme/fonts/ui/code_font.tres new file mode 100644 index 000000000..98eee92b0 --- /dev/null +++ b/material_maker/theme/fonts/ui/code_font.tres @@ -0,0 +1,8 @@ +[gd_resource type="FontVariation" format=3 uid="uid://cjc2c8qp5r5x0"] + +[ext_resource type="FontFile" uid="uid://c4vhxy5kgdp8s" path="res://material_maker/fonts/hack.ttf" id="1_w2v43"] +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="2_nv7dv"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="3_nv7dv"] + +[resource] +fallbacks = Array[Font]([ExtResource("1_w2v43"), ExtResource("2_nv7dv"), ExtResource("3_nv7dv")]) diff --git a/material_maker/theme/fonts/ui/main_font.tres b/material_maker/theme/fonts/ui/main_font.tres new file mode 100644 index 000000000..6a0014355 --- /dev/null +++ b/material_maker/theme/fonts/ui/main_font.tres @@ -0,0 +1,8 @@ +[gd_resource type="FontVariation" format=3 uid="uid://b3d8p401jppew"] + +[ext_resource type="FontFile" uid="uid://lro0qdrhfytt" path="res://material_maker/theme/font_rubik/Rubik-Light.ttf" id="1_c62ru"] +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="2_waneu"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="3_waneu"] + +[resource] +fallbacks = Array[Font]([ExtResource("1_c62ru"), ExtResource("2_waneu"), ExtResource("3_waneu")]) diff --git a/material_maker/theme/fonts/ui/medium_font.tres b/material_maker/theme/fonts/ui/medium_font.tres new file mode 100644 index 000000000..9e8327b28 --- /dev/null +++ b/material_maker/theme/fonts/ui/medium_font.tres @@ -0,0 +1,8 @@ +[gd_resource type="FontVariation" format=3 uid="uid://clmqa2fxntpp4"] + +[ext_resource type="FontFile" uid="uid://bn648prik7soq" path="res://material_maker/theme/font_rubik/Rubik-416.ttf" id="1_22i4t"] +[ext_resource type="FontFile" uid="uid://btybkvkb8rtol" path="res://material_maker/fonts/DroidSansFallback.ttf" id="2_k8ftl"] +[ext_resource type="FontFile" uid="uid://buwvapsuukd0n" path="res://material_maker/fonts/DroidSansJapanese.ttf" id="3_k8ftl"] + +[resource] +fallbacks = Array[Font]([ExtResource("1_22i4t"), ExtResource("2_k8ftl"), ExtResource("3_k8ftl")]) diff --git a/material_maker/widgets/float_edit/float_edit.gd b/material_maker/widgets/float_edit/float_edit.gd index 4c55cfba1..62e0e784c 100644 --- a/material_maker/widgets/float_edit/float_edit.gd +++ b/material_maker/widgets/float_edit/float_edit.gd @@ -306,6 +306,8 @@ func update() -> void: $Edit.add_theme_color_override("font_uneditable_color", get_theme_color("font_color")) else: $Edit.remove_theme_color_override("font_uneditable_color") + $Edit.add_theme_font_size_override("font_size", FontManager.ui_font_size) + $Edit.add_theme_font_override("font", FontManager.main_font) $Edit.queue_redraw() diff --git a/material_maker/widgets/splines_edit/splines_editor.gd b/material_maker/widgets/splines_edit/splines_editor.gd index 15fed136e..de1d045b1 100644 --- a/material_maker/widgets/splines_edit/splines_editor.gd +++ b/material_maker/widgets/splines_edit/splines_editor.gd @@ -17,7 +17,7 @@ var mode : Modes = Modes.DRAW var progressive : bool = false -var spline_font = preload("res://material_maker/theme/font_rubik/Rubik-Bold.ttf") +var spline_font : FontVariation = FontManager.bold_font var font_size = 16 var text_bg_width = 12 diff --git a/material_maker/windows/material_editor/export_editor.gd b/material_maker/windows/material_editor/export_editor.gd index b13351652..b3735244b 100644 --- a/material_maker/windows/material_editor/export_editor.gd +++ b/material_maker/windows/material_editor/export_editor.gd @@ -358,6 +358,8 @@ func _on_Cancel_pressed() -> void: func _notification(what: int) -> void: match what: NOTIFICATION_THEME_CHANGED: + %"Custom Script".add_theme_font_override("font", FontManager.code_font) + %"Custom Script".add_theme_font_size_override("font_size", FontManager.ui_code_font_size) var theme_path : String = mm_globals.main_window.theme.resource_path if "dark" in theme_path: $BG.color = Color("0b0b0c") diff --git a/material_maker/windows/material_editor/export_editor.tscn b/material_maker/windows/material_editor/export_editor.tscn index 5bd2df39a..275277456 100644 --- a/material_maker/windows/material_editor/export_editor.tscn +++ b/material_maker/windows/material_editor/export_editor.tscn @@ -203,6 +203,7 @@ size_flags_vertical = 3 mouse_default_cursor_shape = 0 [node name="Custom Script" type="TextEdit" parent="MarginContainer/VBoxContainer/TabBar"] +unique_name_in_owner = true visible = false custom_minimum_size = Vector2(100, 200) layout_mode = 2 diff --git a/material_maker/windows/node_editor/node_editor.gd b/material_maker/windows/node_editor/node_editor.gd index 79e4bf4de..325823b15 100644 --- a/material_maker/windows/node_editor/node_editor.gd +++ b/material_maker/windows/node_editor/node_editor.gd @@ -168,3 +168,12 @@ func _notification(what: int) -> void: $BG.color = Color("1e2330") else: $BG.color = Color("eaeaea") + + if not is_node_ready(): + await ready + + # Setup code editor fonts + for editor : CodeEdit in [main_code_editor, + global_functions_editor, instance_functions_editor]: + editor.add_theme_font_override("font", FontManager.code_font) + editor.add_theme_font_size_override("font_size", FontManager.ui_code_font_size) diff --git a/material_maker/windows/preferences/file_option.gd b/material_maker/windows/preferences/file_option.gd new file mode 100644 index 000000000..376df8d43 --- /dev/null +++ b/material_maker/windows/preferences/file_option.gd @@ -0,0 +1,30 @@ +class_name FileOption +extends HBoxContainer + +@export var config_variable : String +@export var file_picker_filters : PackedStringArray + +func _ready() -> void: + for f in file_picker_filters: + $FilePickerButton.add_filter(f) + $FilePickerButton.tooltip_text = tooltip_text + +func init_from_config(config : ConfigFile) -> void: + if config.has_section_key("config", config_variable): + $FilePickerButton.path = config.get_value("config", config_variable) + set_reset_button() + +func update_config(config : ConfigFile) -> void: + config.set_value("config", config_variable, $FilePickerButton.path) + +func _on_reset_pressed() -> void: + $FilePickerButton.path = "" + set_reset_button() + +func set_reset_button() -> void: + $Reset.disabled = $FilePickerButton.path == "" + if $FilePickerButton.path == "": + $FilePickerButton.text = "Default" + +func _on_file_picker_button_file_selected(_f : Variant) -> void: + set_reset_button() diff --git a/material_maker/windows/preferences/file_option.gd.uid b/material_maker/windows/preferences/file_option.gd.uid new file mode 100644 index 000000000..ae398e14f --- /dev/null +++ b/material_maker/windows/preferences/file_option.gd.uid @@ -0,0 +1 @@ +uid://bv04peqautr3c diff --git a/material_maker/windows/preferences/file_option.tscn b/material_maker/windows/preferences/file_option.tscn new file mode 100644 index 000000000..dbeb5f2bc --- /dev/null +++ b/material_maker/windows/preferences/file_option.tscn @@ -0,0 +1,31 @@ +[gd_scene format=3 uid="uid://b7ko0gpbs5mqa"] + +[ext_resource type="Script" uid="uid://bv04peqautr3c" path="res://material_maker/windows/preferences/file_option.gd" id="1_3nbpc"] +[ext_resource type="PackedScene" uid="uid://cfyio0a1b27t0" path="res://material_maker/widgets/file_picker_button/file_picker_button.tscn" id="2_8arj1"] +[ext_resource type="Texture2D" uid="uid://1s0c37uoj4rf" path="res://material_maker/theme/default_theme_icons.svg" id="2_wpo6d"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_0r3o7"] +atlas = ExtResource("2_wpo6d") +region = Rect2(96, 192, 16, 16) + +[node name="FileOption" type="HBoxContainer" unique_id=1399365702] +offset_right = 94.0 +offset_bottom = 31.0 +size_flags_horizontal = 3 +script = ExtResource("1_3nbpc") +config_variable = "code_font" + +[node name="Reset" type="Button" parent="." unique_id=1833752383] +unique_name_in_owner = true +custom_minimum_size = Vector2(25, 0) +layout_mode = 2 +icon = SubResource("AtlasTexture_0r3o7") + +[node name="FilePickerButton" parent="." unique_id=275857412 instance=ExtResource("2_8arj1")] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 + +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="pressed" from="Reset" to="." method="_on_reset_pressed"] +[connection signal="file_selected" from="FilePickerButton" to="." method="_on_file_picker_button_file_selected"] diff --git a/material_maker/windows/preferences/preferences.tscn b/material_maker/windows/preferences/preferences.tscn index 34a245592..bdcf2a3a5 100644 --- a/material_maker/windows/preferences/preferences.tscn +++ b/material_maker/windows/preferences/preferences.tscn @@ -7,6 +7,11 @@ [ext_resource type="Script" uid="uid://b6irr1ykhui6l" path="res://material_maker/windows/preferences/preferences_tree.gd" id="3_mlqij"] [ext_resource type="Script" uid="uid://gmystrme5ayw" path="res://material_maker/windows/preferences/lang_option.gd" id="4"] [ext_resource type="Script" uid="uid://d3h4xmek7b2vq" path="res://material_maker/windows/preferences/enum_option.gd" id="5_vp06c"] +[ext_resource type="PackedScene" uid="uid://b7ko0gpbs5mqa" path="res://material_maker/windows/preferences/file_option.tscn" id="7_btfio"] + +[sub_resource type="LabelSettings" id="LabelSettings_btfio"] +outline_size = 2 +shadow_size = 0 [node name="Preferences" type="Window" unique_id=906006602] oversampling_override = 1.0 @@ -373,12 +378,160 @@ float_only = true custom_minimum_size = Vector2(0, 10) layout_mode = 2 -[node name="Bake" type="ScrollContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer" unique_id=660237356] +[node name="Theme" type="ScrollContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer" unique_id=1111133403] visible = false layout_mode = 2 theme_type_variation = &"MM_PreferenceTab" metadata/_tab_index = 1 +[node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme" unique_id=1231307394] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="SectionFont" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=486879697] +layout_mode = 2 +text = "Fonts (requires restart)" +label_settings = SubResource("LabelSettings_btfio") + +[node name="GuiInterfaceMainFont" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=758900584] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceMainFont" unique_id=1822476730] +layout_mode = 2 +text = "Main font" + +[node name="FileOption" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceMainFont" unique_id=1399365702 instance=ExtResource("7_btfio")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +config_variable = "main_font" +file_picker_filters = PackedStringArray("*.ttf; TrueType Font file", "*.otf; OpenType Font file") + +[node name="GuiInterfaceMediumFont" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=34572927] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceMediumFont" unique_id=914702841] +layout_mode = 2 +text = "Medium font" + +[node name="FileOption" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceMediumFont" unique_id=1544432129 instance=ExtResource("7_btfio")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +config_variable = "medium_font" +file_picker_filters = PackedStringArray("*.ttf; TrueType Font file", "*.otf; OpenType Font file") + +[node name="GuiInterfaceBoldFont" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1462088612] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceBoldFont" unique_id=1490863117] +layout_mode = 2 +text = "Bold font" + +[node name="FileOption" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceBoldFont" unique_id=945782835 instance=ExtResource("7_btfio")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +config_variable = "bold_font" +file_picker_filters = PackedStringArray("*.ttf; TrueType Font file", "*.otf; OpenType Font file") + +[node name="GuiInterfaceCodeFont" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1481852751] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceCodeFont" unique_id=1662114990] +layout_mode = 2 +text = "Code font" + +[node name="FileOption" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceCodeFont" unique_id=1735527225 instance=ExtResource("7_btfio")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +file_picker_filters = PackedStringArray("*.ttf; TrueType Font file", "*.otf; OpenType Font file") + +[node name="GuiInterfaceUseSystemFonts" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1096584127] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceUseSystemFonts" unique_id=817621155] +layout_mode = 2 +text = "Use system fonts" + +[node name="UiUseSystemFonts" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceUseSystemFonts" unique_id=270406247 instance=ExtResource("1")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +tooltip_text = "When enabled, system fonts will be used instead of Material Maker's built-in fonts or custom fonts set in preferences." +text = "On" +flat = false +config_variable = "ui_use_system_font" + +[node name="Spacer1" type="Control" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1988482743] +custom_minimum_size = Vector2(0, 10) +layout_mode = 2 + +[node name="GuiInterfaceFontMSDF" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=2144824696] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceFontMSDF" unique_id=177195979] +layout_mode = 2 +text = "MSDF Rendering" + +[node name="UiFontUseMSDF" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceFontMSDF" unique_id=609117319 instance=ExtResource("1")] +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 +size_flags_horizontal = 10 +tooltip_text = "Enables MSDF(Multichannel Signed Distance Field) for font rendering. +This makes text look crisp at any scale but is prone to artifacts if font glyphs have overlapping shapes." +text = "On" +flat = false +config_variable = "ui_font_enable_msdf" + +[node name="Spacer2" type="Control" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1657519221] +custom_minimum_size = Vector2(0, 10) +layout_mode = 2 + +[node name="GuiInterfaceFontSize" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=197296407] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceFontSize" unique_id=83511662] +layout_mode = 2 +text = "UI font size" + +[node name="UiFontSize" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceFontSize" unique_id=2037581063 instance=ExtResource("3")] +custom_minimum_size = Vector2(200, 24) +layout_mode = 2 +size_flags_horizontal = 10 +config_variable = "ui_font_size" +value = 16.0 +min_value = 16.0 +max_value = 48.0 +step = 1.0 +float_only = true + +[node name="GuiInterfaceCodeFontSize" type="HBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer" unique_id=1343680422] +layout_mode = 2 + +[node name="Label" type="Label" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceCodeFontSize" unique_id=1460436146] +layout_mode = 2 +text = "Code font size" + +[node name="UiCodeFontSize" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Theme/VBoxContainer/GuiInterfaceCodeFontSize" unique_id=336987241 instance=ExtResource("3")] +custom_minimum_size = Vector2(200, 24) +layout_mode = 2 +size_flags_horizontal = 10 +config_variable = "ui_code_font_size" +value = 16.0 +min_value = 16.0 +max_value = 48.0 +step = 1.0 +float_only = true + +[node name="Bake" type="ScrollContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer" unique_id=660237356] +visible = false +layout_mode = 2 +theme_type_variation = &"MM_PreferenceTab" +metadata/_tab_index = 2 + [node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Bake" unique_id=1589724560] layout_mode = 2 size_flags_horizontal = 3 @@ -458,7 +611,7 @@ float_only = true visible = false layout_mode = 2 theme_type_variation = &"MM_PreferenceTab" -metadata/_tab_index = 2 +metadata/_tab_index = 3 [node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Graph" unique_id=798147459] layout_mode = 2 @@ -590,7 +743,7 @@ config_variable = "color_picker_floating" visible = false layout_mode = 2 theme_type_variation = &"MM_PreferenceTab" -metadata/_tab_index = 3 +metadata/_tab_index = 4 [node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/PreferencesPanel/VBoxContainer/TabContainer/Export" unique_id=969038621] layout_mode = 2 diff --git a/material_maker/windows/preferences/preferences_tree.gd b/material_maker/windows/preferences/preferences_tree.gd index e819d1a4f..3d7aa4f6f 100644 --- a/material_maker/windows/preferences/preferences_tree.gd +++ b/material_maker/windows/preferences/preferences_tree.gd @@ -18,6 +18,7 @@ func update_tree() -> void: var item: TreeItem = create_item() item.set_text(0, " %s " % tr(child.name)) item.set_metadata(0, child.get_index()) + item.set_custom_font(0, FontManager.medium_font) sections.append(item) set_selected(sections[selected_section_id], 0)