From 1503d8eb03de54c7138b656d8ab6149abbfc42ea Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sat, 30 Jan 2021 23:20:27 +1030 Subject: [PATCH] Refactor font paths Also include some centerline testing and a common theme --- FontTesting.gd | 45 ++++++++++++++++++++++ FontTesting.tscn | 11 ++++++ OptionPanel.tscn | 15 ++------ assets/MenuDiffNumberFont.tres | 4 +- assets/MenuGenreFont.tres | 2 +- assets/MenuScoreFont.tres | 4 +- assets/MenuTitleFont.tres | 4 +- assets/NotoSans.tres | 2 +- assets/{ => fonts}/NotoSans-Regular.ttf | Bin assets/{ => fonts}/NotoSansJP-Black.otf | Bin assets/{ => fonts}/NotoSansJP-Bold.otf | Bin assets/{ => fonts}/NotoSansJP-Regular.otf | Bin assets/{ => fonts}/Sniglet-ExtraBold.ttf | Bin assets/{ => fonts}/Sniglet-Regular.ttf | Bin default.theme | Bin 0 -> 351 bytes main.tscn | 4 +- 16 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 FontTesting.gd create mode 100644 FontTesting.tscn rename assets/{ => fonts}/NotoSans-Regular.ttf (100%) rename assets/{ => fonts}/NotoSansJP-Black.otf (100%) rename assets/{ => fonts}/NotoSansJP-Bold.otf (100%) rename assets/{ => fonts}/NotoSansJP-Regular.otf (100%) rename assets/{ => fonts}/Sniglet-ExtraBold.ttf (100%) rename assets/{ => fonts}/Sniglet-Regular.ttf (100%) create mode 100644 default.theme diff --git a/FontTesting.gd b/FontTesting.gd new file mode 100644 index 0000000..8090179 --- /dev/null +++ b/FontTesting.gd @@ -0,0 +1,45 @@ +extends Control + +var fonts = [] +const path = 'res://assets/fonts/' +const font_size = 32 +func _ready() -> void: + var dir = Directory.new() + dir.open(path) + dir.list_dir_begin(true, true) + var filename = dir.get_next() + while filename != '': + var file = load(path+filename) + if file is DynamicFontData: + var font := DynamicFont.new() + font.size = font_size + font.font_data = file + fonts.append(font) + filename = dir.get_next() + dir.list_dir_end() + + +func _draw() -> void: + var teststr := 'abcdefghijklmnopqrstuvwxyz' + var string = teststr.to_upper() + teststr + '!?#$^²°' + 'らりるれろ(笑)' + var x = 100 + var y = 20 + for font in fonts: + y += 12 + var a = font.get_ascent() + var d = font.get_descent() + var bb = font.get_string_size(string) + assert(a+d == bb.y) + var pos = Vector2(x, y+a) + y += bb.y + draw_rect(Rect2(pos, Vector2(bb.x, -a)), Color.red) + draw_rect(Rect2(pos, Vector2(bb.x, d)), Color.blue) + draw_rect(Rect2(pos, Vector2(-32, -font_size)), Color.green) + draw_line(Vector2(x, y-bb.y/2), Vector2(x+bb.x, y-bb.y/2), Color.green, 2) +# draw_line(Vector2(x, y-d-a/2), Vector2(x+bb.x, y-d-a/2), Color.darkgray, 2) + draw_line(Vector2(x, y-d-font_size/2), Vector2(x+bb.x, y-d-font_size/2), Color.darkgray, 2) + draw_rect(Rect2(pos+Vector2.UP*a, Vector2(-8, bb.y)), Color.gray) + draw_string(font, pos, string) + +func _process(delta: float) -> void: + update() diff --git a/FontTesting.tscn b/FontTesting.tscn new file mode 100644 index 0000000..36b3de1 --- /dev/null +++ b/FontTesting.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://FontTesting.gd" type="Script" id=1] + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/OptionPanel.tscn b/OptionPanel.tscn index 5e66e1f..6126c26 100644 --- a/OptionPanel.tscn +++ b/OptionPanel.tscn @@ -1,15 +1,8 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] -[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1] [ext_resource path="res://scripts/OptionPanel.gd" type="Script" id=2] - -[sub_resource type="DynamicFont" id=1] -outline_size = 1 -outline_color = Color( 0, 0, 0, 1 ) -font_data = ExtResource( 1 ) - -[sub_resource type="Theme" id=2] -default_font = SubResource( 1 ) +[ext_resource path="res://default.theme" type="Theme" id=3] [sub_resource type="DynamicFont" id=3] size = 24 @@ -52,7 +45,7 @@ margin_right = 269.0 margin_bottom = 234.0 size_flags_horizontal = 3 size_flags_vertical = 3 -theme = SubResource( 2 ) +theme = ExtResource( 3 ) script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false diff --git a/assets/MenuDiffNumberFont.tres b/assets/MenuDiffNumberFont.tres index 4f91071..9e0cb5e 100644 --- a/assets/MenuDiffNumberFont.tres +++ b/assets/MenuDiffNumberFont.tres @@ -1,7 +1,7 @@ [gd_resource type="DynamicFont" load_steps=3 format=2] -[ext_resource path="res://assets/Sniglet-Regular.ttf" type="DynamicFontData" id=1] -[ext_resource path="res://assets/NotoSansJP-Bold.otf" type="DynamicFontData" id=2] +[ext_resource path="res://assets/fonts/Sniglet-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/NotoSansJP-Bold.otf" type="DynamicFontData" id=2] [resource] size = 36 diff --git a/assets/MenuGenreFont.tres b/assets/MenuGenreFont.tres index 2576375..2f5f57e 100644 --- a/assets/MenuGenreFont.tres +++ b/assets/MenuGenreFont.tres @@ -1,6 +1,6 @@ [gd_resource type="DynamicFont" load_steps=2 format=2] -[ext_resource path="res://assets/Sniglet-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/Sniglet-Regular.ttf" type="DynamicFontData" id=1] [resource] size = 48 diff --git a/assets/MenuScoreFont.tres b/assets/MenuScoreFont.tres index 3c27304..c6d8f0b 100644 --- a/assets/MenuScoreFont.tres +++ b/assets/MenuScoreFont.tres @@ -1,7 +1,7 @@ [gd_resource type="DynamicFont" load_steps=3 format=2] -[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] -[ext_resource path="res://assets/NotoSansJP-Regular.otf" type="DynamicFontData" id=2] +[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/NotoSansJP-Regular.otf" type="DynamicFontData" id=2] [resource] size = 96 diff --git a/assets/MenuTitleFont.tres b/assets/MenuTitleFont.tres index 84308fb..ec0eef5 100644 --- a/assets/MenuTitleFont.tres +++ b/assets/MenuTitleFont.tres @@ -1,7 +1,7 @@ [gd_resource type="DynamicFont" load_steps=3 format=2] -[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] -[ext_resource path="res://assets/NotoSansJP-Regular.otf" type="DynamicFontData" id=2] +[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/NotoSansJP-Regular.otf" type="DynamicFontData" id=2] [resource] size = 32 diff --git a/assets/NotoSans.tres b/assets/NotoSans.tres index ea93b27..955dcd7 100644 --- a/assets/NotoSans.tres +++ b/assets/NotoSans.tres @@ -1,6 +1,6 @@ [gd_resource type="DynamicFont" load_steps=2 format=2] -[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1] [resource] size = 32 diff --git a/assets/NotoSans-Regular.ttf b/assets/fonts/NotoSans-Regular.ttf similarity index 100% rename from assets/NotoSans-Regular.ttf rename to assets/fonts/NotoSans-Regular.ttf diff --git a/assets/NotoSansJP-Black.otf b/assets/fonts/NotoSansJP-Black.otf similarity index 100% rename from assets/NotoSansJP-Black.otf rename to assets/fonts/NotoSansJP-Black.otf diff --git a/assets/NotoSansJP-Bold.otf b/assets/fonts/NotoSansJP-Bold.otf similarity index 100% rename from assets/NotoSansJP-Bold.otf rename to assets/fonts/NotoSansJP-Bold.otf diff --git a/assets/NotoSansJP-Regular.otf b/assets/fonts/NotoSansJP-Regular.otf similarity index 100% rename from assets/NotoSansJP-Regular.otf rename to assets/fonts/NotoSansJP-Regular.otf diff --git a/assets/Sniglet-ExtraBold.ttf b/assets/fonts/Sniglet-ExtraBold.ttf similarity index 100% rename from assets/Sniglet-ExtraBold.ttf rename to assets/fonts/Sniglet-ExtraBold.ttf diff --git a/assets/Sniglet-Regular.ttf b/assets/fonts/Sniglet-Regular.ttf similarity index 100% rename from assets/Sniglet-Regular.ttf rename to assets/fonts/Sniglet-Regular.ttf diff --git a/default.theme b/default.theme new file mode 100644 index 0000000000000000000000000000000000000000..ebc7db2ec38bf37613807cf6a43893bef61dacc4 GIT binary patch literal 351 zcmV-l0iga;Q$s@n000005C8yL0ssI<0RR9fwJ-f(S^@0|0Je}eE^uqo82tbL|NsAg z{$LhF-iqwaNU1fFy~}ovZ2ZX1oS~S`>JO<%V{%lYYSyMC04V?|0B^8nK=BV)qjZwh zDU0jvYRO((%HZ^(!k_XVtdVvqeu2ji`MXcEu=I9u9K=$JE8$+~pD@&I&{J@fGLoQZ zX`KGZ@U_PzOC8j9dIu8>iqc_ReuUrg+BW5*o0TBQ26j*uEH$m=lbf5h?ma)jIvHk% zDIC2Lm<;B3NTx(+06>mBAht4bZ2X{<<=L&kY!gQ@4bf%h?W0gp#nl*7DGS48-3ull zKmubJI`RSN0oI$BsTC)3?vd>4t&Y+ToDE;wE8Ne;o|28N`K@uBCDzQ9S*czSWI!vs x#TPyZZ{x=1j4!oy@|F0IiVl``hWt62&3w=aqL3hr{Bxv~>{Hgm#R5`OLqnKns|o-B literal 0 HcmV?d00001 diff --git a/main.tscn b/main.tscn index c7c3d9d..869eb08 100644 --- a/main.tscn +++ b/main.tscn @@ -1,12 +1,14 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://RadialGame.tscn" type="PackedScene" id=1] [ext_resource path="res://scripts/TouchInput.gd" type="Script" id=2] +[ext_resource path="res://default.theme" type="Theme" id=3] [ext_resource path="res://OptionPanel.tscn" type="PackedScene" id=13] [node name="main" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 +theme = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false }