Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom fonts #85

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
752 changes: 376 additions & 376 deletions addons/godot-xr-tools/objects/viewport_2d_in_3d.gd

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions assets/3d_tiles/mesh_library.tres

Large diffs are not rendered by default.

Binary file added assets/textures/down_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/textures/down_arrow.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://capl0owt277ac"
path="res://.godot/imported/down_arrow.png-33c63d10b837e4c73c76fafb9231eaae.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/textures/down_arrow.png"
dest_files=["res://.godot/imported/down_arrow.png-33c63d10b837e4c73c76fafb9231eaae.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added assets/textures/up_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/textures/up_arrow.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cgg87r2cj7eb8"
path="res://.godot/imported/up_arrow.png-7d327b510906fda2075dde1b75ef1dd2.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/textures/up_arrow.png"
dest_files=["res://.godot/imported/up_arrow.png-7d327b510906fda2075dde1b75ef1dd2.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
2 changes: 1 addition & 1 deletion scenes/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func _input(event):

if event.is_action_pressed("pause") and not _xr:
_pause_game()

if event.is_action_pressed("free_pointer") and not _xr:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if event.is_action_pressed("click") and not _xr and not $CanvasLayer.visible:
Expand Down
2 changes: 2 additions & 0 deletions scenes/items/RichTextItem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func init(text):
var t = Util.strip_markup(text)
label.text = t
call_deferred("_center_vertically", label)
#label.add_theme_font_override("font",load_system_font(font_path))


func _center_vertically(label):
# Ensure the SubViewport is sized
Expand Down
1 change: 1 addition & 0 deletions scenes/items/TextItem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func _ready():
func init(text):
var t = Util.strip_markup(text).substr(0, max_chars)
$Label.text = t if len(t) < max_chars else t + "..."


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
Expand Down
74 changes: 74 additions & 0 deletions scenes/menu/FontSettings.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
extends VBoxContainer

signal resume


const FONTS_PANEL = preload("res://scenes/menu/FontsPanel.tscn")
@onready var fonts_container: VBoxContainer = $FontsContainer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:

var system_fonts = OS.get_system_fonts()
for font_str in system_fonts:
var fonts_panel := FONTS_PANEL.instantiate()
fonts_panel.font_str = font_str.replace("_", " ").capitalize()
fonts_panel.name = font_str + " Panel"
fonts_container.add_child(fonts_panel)
fonts_panel.update_font()
for font in fonts_container.get_children():
font.get_child(0).get_child(0).pressed.connect(_on_picked.bind(font))


func _on_picked(font):
$Search.text = ""
$Search.text_changed.emit(font.font_str)
var font_path = OS.get_system_font_path(font.font_str)
#.add_theme_font_override("font",load_system_font(font_path))


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass



func _on_search_text_changed(new_text: String) -> void:
for font in fonts_container.get_children():
if new_text.to_lower() in font.current_font_label.text.to_lower():
font.show()
elif new_text == "":
font.show()
else: font.hide()



func _on_visibility_changed() -> void:
pass
#if _loaded_settings and not visible:
#_save_settings()


func _save_settings() -> void:
#SettingsManager.save_settings(_control_ns, _create_settings_obj())
pass
func _on_resume() -> void:
_save_settings()
emit_signal("resume")

func _on_restore_defaults_button_pressed() -> void:
InputMap.load_from_project_settings()
#update_all_maps_label()
$MouseOptions/InvertY.button_pressed = false
$MouseOptions/Sensitivity.value = 1.0
$JoyOptions/Deadzone.value = 0.05

func _on_list_fonts_toggled(toggled_on: bool) -> void:
$Search.text = ""
$Search/ListFonts.text = "Hide" if toggled_on else "Show"
for font in fonts_container.get_children():
font.hide()
if toggled_on:
font.show()



80 changes: 80 additions & 0 deletions scenes/menu/FontSettings.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[gd_scene load_steps=5 format=3 uid="uid://csyhd0yh2exjh"]

[ext_resource type="Script" path="res://scenes/menu/FontSettings.gd" id="1_2bb4n"]
[ext_resource type="Texture2D" uid="uid://cgg87r2cj7eb8" path="res://assets/textures/up_arrow.png" id="2_epigm"]
[ext_resource type="Texture2D" uid="uid://capl0owt277ac" path="res://assets/textures/down_arrow.png" id="3_eb7rb"]

[sub_resource type="LabelSettings" id="LabelSettings_6eray"]
font_size = 64

[node name="FontSettings" type="VBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_2bb4n")

[node name="MainOptions" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="MainOptions"]
layout_mode = 2
text = "Font Settings"
label_settings = SubResource("LabelSettings_6eray")

[node name="Back" type="Button" parent="MainOptions"]
layout_mode = 2
text = "Back
"

[node name="RestoreDefaultsButton" type="Button" parent="MainOptions"]
layout_mode = 2
text = "Restore Default Settings"

[node name="Spacer" type="Label" parent="."]
layout_mode = 2
text = " "

[node name="FontsLabel" type="Label" parent="."]
layout_mode = 2
text = "Set Fonts"

[node name="Search" type="LineEdit" parent="."]
layout_mode = 2
placeholder_text = "Search..."

[node name="ListFonts" type="CheckButton" parent="Search"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -80.0
offset_right = 18.0
offset_bottom = 45.0
grow_horizontal = 0
scale = Vector2(0.8, 0.8)
theme_override_icons/checked = ExtResource("2_epigm")
theme_override_icons/unchecked = ExtResource("3_eb7rb")
button_pressed = true
text = "Hide"
icon_alignment = 1

[node name="FontsContainer" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="JoyOptions" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="Spacer" type="Label" parent="JoyOptions"]
layout_mode = 2
text = " "

[node name="Label" type="Label" parent="JoyOptions"]
layout_mode = 2
text = "Preview
"

[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
[connection signal="text_changed" from="Search" to="." method="_on_search_text_changed"]
[connection signal="toggled" from="Search/ListFonts" to="." method="_on_list_fonts_toggled"]
47 changes: 47 additions & 0 deletions scenes/menu/FontsPanel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
extends PanelContainer


var font_str := ""

@onready var font_label: Button = $VBoxContainer/FontLabel


var current_font_label : Button = null
var picked_font : String = ""

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.

func update_font() -> void:
font_label.text = " " + font_str
var font_path = OS.get_system_font_path(font_str)
font_label.add_theme_font_override("font",load_system_font(font_path))
current_font_label = font_label


func load_system_font(path: String) -> Font:
var path_lower = path.to_lower()
var font_file = FontFile.new()
if ( path_lower.ends_with(".ttf")
or path_lower.ends_with(".otf")
or path_lower.ends_with(".woff")
or path_lower.ends_with(".woff2")
or path_lower.ends_with(".pfb")
or path_lower.ends_with(".pfm")):
font_file.load_dynamic_font(path)
elif path_lower.ends_with(".fnt") or path_lower.ends_with(".font"):
font_file.load_bitmap_font(path)
else:
push_error("Invalid font file format.")

return font_file

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass


#func _on_font_label_pressed() -> void:

# picked_font = current_font_label.text
37 changes: 37 additions & 0 deletions scenes/menu/FontsPanel.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[gd_scene load_steps=2 format=3 uid="uid://bmu7urym63muk"]

[ext_resource type="Script" path="res://scenes/menu/FontsPanel.gd" id="1_dbces"]

[node name="FontsPanel" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 4
script = ExtResource("1_dbces")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
size_flags_vertical = 4

[node name="FontLabel" type="Button" parent="VBoxContainer"]
layout_mode = 2
text = "Default"
alignment = 0

[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
size_flags_horizontal = 8

[node name="FontSize" type="SpinBox" parent="HBoxContainer"]
layout_mode = 2
min_value = 1.0
max_value = 400.0
value = 1.0
alignment = 1

[node name="OptionButton" type="OptionButton" parent="HBoxContainer"]
layout_mode = 2
item_count = 1
1 change: 1 addition & 0 deletions scenes/menu/GraphicsSettings.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ text = "1.0
horizontal_alignment = 1

[node name="Fullscreen" type="CheckBox" parent="DisplayOptions"]
unique_name_in_owner = true
layout_mode = 2
text = "Fullscreen"

Expand Down
3 changes: 2 additions & 1 deletion scenes/menu/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ signal resume
_vbox.get_node("AudioSettings"),
_vbox.get_node("XrControlsMenu") if _xr else null,
_vbox.get_node("ControlSettings") if not _xr else null,
_vbox.get_node("FontSettings"),
_vbox.get_node("DataSettings"),
]

Expand Down Expand Up @@ -41,7 +42,7 @@ func _on_tab_left():
func _on_tab_right():
if visible:
_tab_bar.select_previous_available()

func _on_resume():
if visible:
emit_signal("resume")
Loading