Menu fixes - CJK fallback font for difficulties, chart difficulty fallback

This commit is contained in:
Luke Hubmayer-Werner 2020-12-30 00:00:31 +10:30
parent b59abba1b6
commit eaa1d09506
4 changed files with 81 additions and 8 deletions

View File

@ -1,9 +1,11 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[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]
[resource]
size = 36
outline_size = 1
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 1 )
fallback/0 = ExtResource( 2 )

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=2]
[gd_scene load_steps=24 format=2]
[ext_resource path="res://scripts/main.gd" type="Script" id=1]
[ext_resource path="res://scripts/video.gd" type="Script" id=2]
@ -17,6 +17,7 @@
[ext_resource path="res://scripts/Bezel.gd" type="Script" id=15]
[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=16]
[ext_resource path="res://scripts/InputHandler.gd" type="Script" id=17]
[ext_resource path="res://shaders/menu.tres" type="Material" id=18]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 4 )
@ -134,6 +135,7 @@ material = SubResource( 5 )
script = ExtResource( 11 )
[node name="Menu" type="Control" parent="."]
material = ExtResource( 18 )
margin_left = -540.0
margin_top = -540.0
margin_right = 540.0

View File

@ -103,18 +103,21 @@ func draw_songtile(song_key, position, size, title_text:=false, difficulty=selec
# Draw difficulty-colored outline
if typeof(difficulty) == TYPE_STRING:
difficulty = Library.Song.difficulty_key_ids.get(difficulty, 0)
var song_diffs = Library.all_songs[song_key]['chart_difficulties']
if not (Library.Song.default_difficulty_keys[difficulty] in song_diffs):
difficulty = Library.Song.difficulty_key_ids.get(song_diffs.keys()[-1], 0)
var diff_color := GameTheme.COLOR_DIFFICULTY[difficulty*2]
var rect := Rect2(position.x, position.y, size, size)
draw_rect(Rect2(position.x - outline_px, position.y - outline_px, size + outline_px*2, size + outline_px*2), diff_color)
draw_texture_rect(Library.get_song_tile_texture(song_key), rect, false)
# Draw track difficulty rating
draw_string_centered(DiffNumFont, Vector2(position.x+size-17, position.y+size-40), Library.all_songs[song_key]['chart_difficulties'].get(Library.Song.default_difficulty_keys[difficulty], '0'), diff_color)
draw_string_centered(DiffNumFont, Vector2(position.x+size-17, position.y+size-40), song_diffs.get(Library.Song.default_difficulty_keys[difficulty], '0'), diff_color)
if title_text:
draw_string_centered(TitleFont, Vector2(position.x+size/2.0, position.y+size), Library.all_songs[song_key].title.n, diff_color.lightened(0.33))
return rect
func diffstr(difficulty: float):
# Convert .5 to +
func diff_f2str(difficulty: float): # Convert .5 to +
return str(int(floor(difficulty))) + ('+' if fmod(difficulty, 1.0)>0.4 else '')
@ -147,13 +150,13 @@ func _draw_song_select(center: Vector2) -> Array:
var subsize = size * scales[0]
var gx = center.x - (subsize + spacer_x) * selected_song_delta
var songslist = Library.genre_songs[g].keys()
var genre_str = genres.keys()[g] + ' (%d)'%len(songslist)
var genre_str = '%s (%d)'%[genres.keys()[g], len(songslist)]
draw_string_centered(GenreFont, Vector2(center.x, gy), genre_str, Color.aqua)
var s = len(songslist)
var key = songslist[selected_song_vis % s]
var y = gy + spacer_y
var x = -subsize/2.0
var r = draw_songtile(key, Vector2(gx+x, y), subsize, selected, selected_difficulty)
var r = draw_songtile(key, Vector2(gx+x, y), subsize, selected)
touchrects.append({rect=r, song_idx=selected_song_vis, genre_idx=g})
for i in range(1, len(base_scales)):
@ -178,7 +181,7 @@ func _draw_chart_select(center: Vector2) -> Array:
var diffs = song_data.chart_difficulties
var n = len(diffs)
var spacer_x = max(14, 70/n)
var size = min(192, 960/n)
var size = min(192, (1000-spacer_x*(n-1))/n)
var touchrects = [{rect=Rect2(center.x-450.0, center.y+310.0, 900.0, 300.0), chart_idx=-1}] # invisible back button
var x = center.x - (size*n + spacer_x*(n-1))/2

66
shaders/menu.tres Normal file
View File

@ -0,0 +1,66 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
//render_mode unshaded;
const float PI = 3.141592654;
uniform float bps;
// All components are in the range [0…1], including hue.
vec3 hsl2rgb(vec3 c)
{
// vec3 rgb = clamp( abs(mod(c.x*6.0 + vec3(0.0,4.0,2.0), 6.0) - 3.0)-1.0, 0.0, 1.0 );
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
vec3 rgb = clamp(p-K.xxx, 0.0, 1.0);
return clamp(c.z + c.y*(rgb-0.5)*(1.0-abs(2.0*c.z-1.0)), 0.0, 1.0);
}
vec3 lab2xyz(vec3 c){
float fy=(c.x+16.)/116.,
fx=c.y/500.+fy,
fz=fy-c.z/200.;
vec3 scale = vec3(95.047, 100.000, 108.883);
return scale * vec3(
(fx > 0.206897) ? fx*fx*fx : (fx-16./116.)/7.787,
(fy > 0.206897) ? fy*fy*fy : (fy-16./116.)/7.787,
(fz > 0.206897) ? fz*fz*fz : (fz-16./116.)/7.787
);
}
vec3 xyz2rgb(vec3 c){
vec3 v = (c/100.0) * mat3(
vec3( 3.2406,-1.5372,-0.4986),
vec3(-0.9689, 1.8758, 0.0415),
vec3( 0.0557,-0.2040, 1.0570)
);
vec3 r = vec3(
(v.r>.0031308) ? (1.055*pow(v.r, (1./2.4)) - 0.055) : 12.92*v.r,
(v.g>.0031308) ? (1.055*pow(v.g, (1./2.4)) - 0.055) : 12.92*v.g,
(v.b>.0031308) ? (1.055*pow(v.b, (1./2.4)) - 0.055) : 12.92*v.b
);
return r;
}
vec3 lab2rgb(vec3 c){return xyz2rgb(lab2xyz(vec3(100.*c.x,2.*127.*(c.y-.5),2.*127.*(c.z-.5))));}
void fragment() {
float wave_scale = 0.015;
float timescale = 0.75;
float t = TIME * timescale;
vec3 lab;
if (COLOR.rgb == vec3(0.0, 0.0, 1.0)){
//lab.x = mix(texture(TEXTURE, UV).b, 0.5, 0.35+0.25*cos(TIME * PI));
lab.x = 0.7+0.2*cos(TIME * PI/10.0);
lab.y = 0.5 + 0.25*sin(wave_scale*FRAGCOORD.y+t*2.5) + 0.125*sin(0.5*wave_scale*FRAGCOORD.y+cos(t*1.5) + 0.125*cos(t*5.5));
lab.z = 0.5 + 0.25*sin(wave_scale*FRAGCOORD.x+t*2.25) + 0.125*sin(0.5*wave_scale*FRAGCOORD.x+cos(t*3.5) + 0.125*cos(t*6.5));
COLOR.rgb = lab2rgb(lab);
COLOR.a = clamp(texture(TEXTURE, UV).a, 0.0, 1.0);
} else {
COLOR *= texture(TEXTURE, UV);
}
}"
[resource]
shader = SubResource( 1 )
shader_param/bps = null