Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5265c89
Adding chosen fonts to project with licenses
programnoir Jul 22, 2023
3365ee8
Adds font changing controls (WIP)
programnoir Jul 23, 2023
f168fba
Language and font loads from save file now
programnoir Jul 25, 2023
78323eb
Cleaner implementation by moving theme operations to the global scope.
programnoir Jul 25, 2023
58779ac
implemented in first time setup
programnoir Jul 25, 2023
506569a
Added font size settings
programnoir Jul 26, 2023
5c3daba
Fixes scroll focus and a signal bug.
programnoir Jul 26, 2023
7432d15
Add basic translation support
programnoir Jul 26, 2023
a363cde
Basic translations
programnoir Jul 26, 2023
0fe06a7
Converted theme changes to threads
programnoir Jul 26, 2023
020a5d3
Preloads fonts
programnoir Jul 26, 2023
9b0cc77
Converting to an array of threads, one for each style type
programnoir Jul 26, 2023
ef38cd1
Asynchronous timer calls
programnoir Jul 27, 2023
6b6d1ee
Only one thread per operation necessary
programnoir Jul 27, 2023
ca19608
Removing unneeded increment counters
programnoir Jul 27, 2023
72b5105
Unifies/caps font sizes
programnoir Jul 27, 2023
2e57526
Uses custom spinbox
programnoir Jul 28, 2023
0db8872
Simpler layout
programnoir Jul 28, 2023
a411a7e
Fixing focus neighbors in settings
programnoir Jul 28, 2023
7b4e1df
Resolves weird text update bug
programnoir Jul 28, 2023
fe42b76
Code style adherence pass
programnoir Jul 28, 2023
5ba4d37
Removes unnecessary woff file
programnoir Jul 28, 2023
b153008
Adds translations for edit/confirm button
programnoir Jul 28, 2023
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
91 changes: 91 additions & 0 deletions addons/gdtemplate/autoload/global-theme.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
extends Node

signal new_fontlist

var theme: Theme
var thread_font: Thread
var thread_font_size: Thread

# Maximum font sizes according to Game Scale
var maximum_font_sizes: Array = [ 26, 55, 82, 100 ]

# Needs to consistently match the language codes in the translation sheet.
var font_list: Dictionary = {
'en': {
'Atkinson Hyperlegible': [
'res://assets/fonts/Atkinson-Hyperlegible-Regular-102.ttf', 1.0 ],
'OpenDyslexic': [ 'res://assets/fonts/OpenDyslexic-Regular.otf', 0.85 ]
},
'JP': {
'Noto Sans JP': [ 'res://assets/fonts/NotoSansJP-Regular.ttf', 0.95 ],
'モリサワのBIZ UDゴシックは': [
'res://assets/fonts/BIZUDGothic-Regular.ttf', 0.9 ]
}
}


func set_theme( new_theme: Theme ) -> void:
theme = new_theme


func get_font( font_name: String ) -> Font:
var fonts: Dictionary = font_list[
GlobalUserSettings.get_current_language() ]
if( fonts.has( font_name ) == false ):
return null
var font: Array = fonts[ font_name ]
# End defensive return: No font found?
return load( font[ 0 ] )


func set_font_threaded( type: String, preloaded_font: Font ) -> void:
theme.call_deferred( "set_font", "font", type, preloaded_font )


func set_font( new_font: String ) -> void:
var preloaded_font: Font = get_font( new_font )
if( preloaded_font == null ):
return
# End defensive return: No filepath found.
for type in theme.get_type_list():
var timer: SceneTreeTimer
if( thread_font != null ):
thread_font.wait_to_finish()
thread_font = Thread.new()
timer = get_tree().create_timer( 0.01 )
# Retrieves the filepath to the new font.
thread_font.start( set_font_threaded.bind(
type, preloaded_font ) )
await timer.timeout


func set_font_size_threaded( type: String, new_size: int ) -> void:
theme.call_deferred( "set_font_size", "font_size", type, new_size )


func get_adjusted_font_size( font_name: String ) -> int:
var fonts: Dictionary = font_list[
GlobalUserSettings.get_current_language() ]
var font: Array = fonts[ font_name ]
var adjusted_font_size: float = font[ 1 ] * (
GlobalUserSettings.get_current_font_size() as float )
return adjusted_font_size as int


func set_font_size( new_size: int ) -> void:
for type in theme.get_type_list():
var timer: SceneTreeTimer
if( thread_font_size != null ):
thread_font_size.wait_to_finish()
thread_font_size = Thread.new()
timer = get_tree().create_timer( 0.01 )
thread_font_size.start( set_font_size_threaded.bind(
type, new_size ) )
await timer.timeout


func _exit_tree() -> void:
if( thread_font != null ):
thread_font.wait_to_finish()
if( thread_font_size != null ):
thread_font_size.wait_to_finish()
23 changes: 21 additions & 2 deletions addons/gdtemplate/autoload/global-user-settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const CONFIG_FILE_NAME: String = "settings"
const CONFIG_EXTENSION: String = ".tres"

# Save file information
var first_time_setup: bool = false
var first_time_setup: bool = true
var accessibility: Dictionary = {
"current_language": "English"
"current_language": "en",
"current_font_index": 0,
"current_font_size": 20
}
var input_profiles: Dictionary = {
"profiles": [],
Expand Down Expand Up @@ -75,6 +77,7 @@ func load_settings() -> bool:
CONFIG_EXTENSION ) == false ):
print( "Settings save file not found." )
return false
print( "Settings file was found." )
# End defensive return: File does not exist
var new_load: Resource = ResourceLoader.load(
dirtext + CONFIG_DIR + CONFIG_FILE_NAME + CONFIG_EXTENSION,
Expand Down Expand Up @@ -118,6 +121,22 @@ func set_new_language( language_code: String ) -> void:
TranslationServer.set_locale( language_code )


func get_current_font_index() -> int:
return accessibility[ "current_font_index" ]


func set_current_font_index( new_index: int ) -> void:
accessibility[ "current_font_index" ] = new_index


func get_current_font_size() -> int:
return accessibility[ "current_font_size" ]


func set_current_font_size( new_size: int ) -> void:
accessibility[ "current_font_size" ] = new_size


"""
Keybind Input Profile
"""
Expand Down
2 changes: 2 additions & 0 deletions addons/gdtemplate/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ extends EditorPlugin
# Array containing steps for loading assets into a game.
const AUTOLOAD_ORDER: Array = [
'GlobalActionIgnoreList',
'GlobalTheme',
'GlobalUserSettings',
'GlobalUIScreenFade'
]

const AUTOLOAD_LIST: Dictionary = {
'GlobalTheme': 'res://addons/gdtemplate/autoload/global-theme.gd',
'GlobalActionIgnoreList': 'res://addons/gdtemplate/autoload/' +
'global-action-ignore-list.gd',
'GlobalUserSettings': 'res://addons/gdtemplate/autoload/' +
Expand Down
47 changes: 47 additions & 0 deletions addons/gdtemplate/ui/ui_button_cycle/ui-button-cycle.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
extends Button
class_name ButtonCycle

signal new_index

var list: Array = []
var current_index: int = 0


func get_list() -> Array:
return list


func set_index( increment: int = 0 ) -> void:
if( current_index + increment > list.size() - 1 ):
current_index = 0
elif( current_index + increment < 0 ):
current_index = max( 0, list.size() - 1 )
else:
current_index += increment
text = list[ current_index ]
emit_signal( "new_index", current_index )


# Internally changes the current index without changing font.
func set_index_manual( new_index: int ) -> void:
current_index = new_index


func _unhandled_key_input( event: InputEvent ) -> void:
if( has_focus() == false ):
return
# End defensive return: Not focused.
var increment: int = 0
if( Input.is_action_just_released( "ui_right" ) ):
increment = 1
if( Input.is_action_just_released( "ui_left" ) ):
increment -= 1
if( increment == 0 ):
return
# End defensive return: Not selecting anything
set_index( increment )


func set_list( new_list: Array ) -> void:
list = new_list
text = list[ 0 ]
14 changes: 14 additions & 0 deletions addons/gdtemplate/ui/ui_button_cycle/ui-button-cycle.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=3 uid="uid://i4awy35ykync"]

[ext_resource type="Script" path="res://addons/gdtemplate/ui/ui_button_cycle/ui-button-cycle.gd" id="1_sm75r"]

[node name="ButtonCycle" type="Button"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
focus_neighbor_left = NodePath(".")
focus_neighbor_right = NodePath(".")
script = ExtResource("1_sm75r")
9 changes: 9 additions & 0 deletions addons/gdtemplate/ui/ui_button_tab/ui-button-tab.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3]

[ext_resource type="Script" path="res://addons/gdtemplate/ui/ui_button_tab/ui-button-tab.gd" id="1_7ur2y"]


[node name="ButtonTab" type="Button"]
script = ExtResource("1_7ur2y")

[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
Binary file not shown.
33 changes: 33 additions & 0 deletions assets/fonts/Atkinson-Hyperlegible-Regular-102.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://dewwc2li5whus"
path="res://.godot/imported/Atkinson-Hyperlegible-Regular-102.ttf-bbc2915eb160cc9c865fae4e027ead3b.fontdata"

[deps]

source_file="res://assets/fonts/Atkinson-Hyperlegible-Regular-102.ttf"
dest_files=["res://.godot/imported/Atkinson-Hyperlegible-Regular-102.ttf-bbc2915eb160cc9c865fae4e027ead3b.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Binary file added assets/fonts/BIZUDGothic-Regular.ttf
Binary file not shown.
33 changes: 33 additions & 0 deletions assets/fonts/BIZUDGothic-Regular.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://djssjmir4g553"
path="res://.godot/imported/BIZUDGothic-Regular.ttf-10dfa3e3409571282bfbe1d87b57652b.fontdata"

[deps]

source_file="res://assets/fonts/BIZUDGothic-Regular.ttf"
dest_files=["res://.godot/imported/BIZUDGothic-Regular.ttf-10dfa3e3409571282bfbe1d87b57652b.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Binary file added assets/fonts/NotoSansJP-Regular.ttf
Binary file not shown.
33 changes: 33 additions & 0 deletions assets/fonts/NotoSansJP-Regular.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://biqgkf4op0m08"
path="res://.godot/imported/NotoSansJP-Regular.ttf-5ab1499f300bf3e5488cf75c47d7d03b.fontdata"

[deps]

source_file="res://assets/fonts/NotoSansJP-Regular.ttf"
dest_files=["res://.godot/imported/NotoSansJP-Regular.ttf-5ab1499f300bf3e5488cf75c47d7d03b.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Binary file added assets/fonts/OpenDyslexic-Regular.otf
Binary file not shown.
33 changes: 33 additions & 0 deletions assets/fonts/OpenDyslexic-Regular.otf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://bmfpn32mn46tl"
path="res://.godot/imported/OpenDyslexic-Regular.otf-c3e988c48cb2b5a8c8a198700757d52e.fontdata"

[deps]

source_file="res://assets/fonts/OpenDyslexic-Regular.otf"
dest_files=["res://.godot/imported/OpenDyslexic-Regular.otf-c3e988c48cb2b5a8c8a198700757d52e.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Loading