[WIP] Somewhat nice song menu layout
This commit is contained in:
parent
e85675f780
commit
ad7a49fabf
92
Menu.gd
92
Menu.gd
|
@ -2,6 +2,16 @@ extends Node2D
|
||||||
|
|
||||||
var song_defs = {}
|
var song_defs = {}
|
||||||
var song_images = {}
|
var song_images = {}
|
||||||
|
var genres = {}
|
||||||
|
|
||||||
|
enum ChartDifficulty {EASY, BASIC, ADV, EXPERT, MASTER}
|
||||||
|
|
||||||
|
var selected_genre := 0
|
||||||
|
var selected_song := 0
|
||||||
|
var selected_difficulty = ChartDifficulty.ADV
|
||||||
|
|
||||||
|
var TitleFont := preload("res://assets/MenuTitleFont.tres")
|
||||||
|
var GenreFont := preload("res://assets/MenuGenreFont.tres")
|
||||||
|
|
||||||
func scan_library():
|
func scan_library():
|
||||||
print("Scanning library")
|
print("Scanning library")
|
||||||
|
@ -10,18 +20,22 @@ func scan_library():
|
||||||
var err = dir.open(rootdir)
|
var err = dir.open(rootdir)
|
||||||
if err == OK:
|
if err == OK:
|
||||||
dir.list_dir_begin(true, true)
|
dir.list_dir_begin(true, true)
|
||||||
var file_name = dir.get_next()
|
var key = dir.get_next()
|
||||||
while (file_name != ""):
|
while (key != ""):
|
||||||
if dir.current_is_dir():
|
if dir.current_is_dir():
|
||||||
if dir.file_exists(file_name + "/song.json"):
|
if dir.file_exists(key + "/song.json"):
|
||||||
song_defs[file_name] = FileLoader.load_folder("%s/%s" % [rootdir, file_name])
|
song_defs[key] = FileLoader.load_folder("%s/%s" % [rootdir, key])
|
||||||
print("Loaded song directory: %s" % file_name)
|
print("Loaded song directory: %s" % key)
|
||||||
song_images[file_name] = load("%s/%s/%s" % [rootdir, file_name, song_defs[file_name]["tile_filename"]])
|
song_images[key] = load("%s/%s/%s" % [rootdir, key, song_defs[key]["tile_filename"]])
|
||||||
|
if song_defs[key]["genre"] in genres:
|
||||||
|
genres[song_defs[key]["genre"]].append(key)
|
||||||
else:
|
else:
|
||||||
print("Found directory: " + file_name)
|
genres[song_defs[key]["genre"]] = [key]
|
||||||
else:
|
else:
|
||||||
print("Found file: " + file_name)
|
print("Found non-song directory: " + key)
|
||||||
file_name = dir.get_next()
|
else:
|
||||||
|
print("Found file: " + key)
|
||||||
|
key = dir.get_next()
|
||||||
dir.list_dir_end()
|
dir.list_dir_end()
|
||||||
else:
|
else:
|
||||||
print("An error occurred when trying to access the songs directory: ", err)
|
print("An error occurred when trying to access the songs directory: ", err)
|
||||||
|
@ -30,11 +44,59 @@ func _ready():
|
||||||
scan_library()
|
scan_library()
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
#func _process(delta):
|
func _process(delta):
|
||||||
# pass
|
update()
|
||||||
|
|
||||||
|
func draw_string_centered(font, position, string, color := Color.white):
|
||||||
|
draw_string(font, Vector2(position.x - font.get_string_size(string).x/2.0, position.y + font.get_ascent()), string, color)
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
var i = -512
|
var songs = len(song_defs)
|
||||||
for key in song_images:
|
var size = 216
|
||||||
draw_texture(song_images[key], Vector2(i, -256))
|
var spacer_x = 12
|
||||||
i += 512
|
var spacer_y = 64
|
||||||
|
var outline_px = 3
|
||||||
|
var x = -(size + spacer_x)*2
|
||||||
|
var y = -(size + spacer_y)
|
||||||
|
var sel_scales := [1.0, 0.8, 0.64, 0.512]
|
||||||
|
var sel_cumscales := [1.0, 1.8, 2.44, 2.952]
|
||||||
|
var bg_scales := [0.64, 0.64, 0.64, 0.512]
|
||||||
|
var bg_cumscales := [0.64, 1.28, 1.92, 2.432]
|
||||||
|
|
||||||
|
var gy := -160
|
||||||
|
for g in len(genres):
|
||||||
|
var selected: bool = (g == selected_genre)
|
||||||
|
var scales = sel_scales if selected else bg_scales
|
||||||
|
var cumscales = sel_cumscales if selected else bg_cumscales
|
||||||
|
var genre = genres.keys()[g]
|
||||||
|
draw_string_centered(GenreFont, Vector2(0, gy), genre)
|
||||||
|
var songslist = genres[genre]
|
||||||
|
var s = len(songslist)
|
||||||
|
var key = songslist[selected_song%s]
|
||||||
|
var subsize = size * scales[0]
|
||||||
|
y = gy + spacer_y
|
||||||
|
draw_rect(Rect2(-subsize/2.0 - outline_px, y - outline_px, subsize + outline_px*2, subsize + outline_px*2), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
draw_texture_rect(song_images[key], Rect2(-subsize/2.0, y, subsize, subsize), false)
|
||||||
|
if selected:
|
||||||
|
draw_string_centered(TitleFont, Vector2(0, y+subsize), song_defs[key]["title"], Color(0.95, 0.95, 1.0))
|
||||||
|
draw_string_centered(GenreFont, Vector2(subsize/2.0 - 24, gy+subsize+8), str(song_defs[key]["chart_difficulties"][selected_difficulty]), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
for i in [1, 2, 3]:
|
||||||
|
key = songslist[(selected_song+i)%s]
|
||||||
|
subsize = size * scales[i]
|
||||||
|
var gx = size * (cumscales[i] - scales[0]*0.5 - scales[i]*0.5) + spacer_x * i
|
||||||
|
draw_rect(Rect2(gx - subsize/2.0 - outline_px, y - outline_px, subsize + outline_px*2, subsize + outline_px*2), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
draw_texture_rect(song_images[key], Rect2(gx - subsize/2.0, y, subsize, subsize), false)
|
||||||
|
draw_string_centered(GenreFont, Vector2(gx + subsize/2.0 - 24, gy+subsize+8), str(song_defs[key]["chart_difficulties"][selected_difficulty]), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
key = songslist[(selected_song-i)%s]
|
||||||
|
draw_rect(Rect2(-gx - subsize/2.0 - outline_px, y - outline_px, subsize + outline_px*2, subsize + outline_px*2), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
draw_texture_rect(song_images[key], Rect2(-gx - subsize/2.0, y, subsize, subsize), false)
|
||||||
|
draw_string_centered(GenreFont, Vector2(-gx + subsize/2.0 - 24, gy+subsize+8), str(song_defs[key]["chart_difficulties"][selected_difficulty]), GameTheme.COLOR_DIFFICULTY[selected_difficulty])
|
||||||
|
gy += size + (spacer_y * 2)
|
||||||
|
|
||||||
|
# for key in song_images:
|
||||||
|
# draw_texture_rect(song_images[key], Rect2(x, y, size, size), false)
|
||||||
|
# draw_string_centered(TitleFont, Vector2(x+size/2.0, y+size), song_defs[key]["title"], Color(0.95, 0.95, 1.0))
|
||||||
|
# x += size + spacer_x
|
||||||
|
# if x >= (size + spacer_x)*2:
|
||||||
|
# x = -(size + spacer_x)*2
|
||||||
|
# y += size + spacer_y
|
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_resource type="DynamicFont" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://assets/Sniglet-Regular.ttf" type="DynamicFontData" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
size = 48
|
||||||
|
outline_size = 2
|
||||||
|
outline_color = Color( 0, 0, 0, 1 )
|
||||||
|
font_data = ExtResource( 1 )
|
|
@ -0,0 +1,12 @@
|
||||||
|
[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]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
size = 32
|
||||||
|
outline_size = 2
|
||||||
|
outline_color = Color( 0, 0, 0, 1 )
|
||||||
|
use_filter = true
|
||||||
|
font_data = ExtResource( 2 )
|
||||||
|
fallback/0 = ExtResource( 1 )
|
Binary file not shown.
Binary file not shown.
|
@ -46,6 +46,7 @@ gdscript/warnings/integer_division=false
|
||||||
|
|
||||||
window/size/width=1920
|
window/size/width=1920
|
||||||
window/size/height=1080
|
window/size/height=1080
|
||||||
|
window/size/fullscreen=true
|
||||||
window/handheld/orientation="sensor"
|
window/handheld/orientation="sensor"
|
||||||
window/stretch/mode="2d"
|
window/stretch/mode="2d"
|
||||||
window/stretch/aspect="keep_height"
|
window/stretch/aspect="keep_height"
|
||||||
|
|
Loading…
Reference in New Issue