file select and file creation, menus glued together

This commit is contained in:
Haze Weathers 2023-07-20 18:19:20 -04:00
parent 13708b4046
commit f7496c5e6f
18 changed files with 754 additions and 47 deletions

58
menus/file_create.gd Normal file
View file

@ -0,0 +1,58 @@
extends Node
var file: Save.SaveFile = null
var difficulty: int = Game.Difficulty.SPICY
onready var face: Sprite = $"%Face"
onready var chosen_name: Label = $"%ChosenName"
func _ready() -> void:
# escape to file select if no file is assigned
if not file:
yield(get_tree(), "idle_frame")
SceneManager.current_scene = load("res://menus/file_select.tscn").instance()
return
# pause so that player can not move around until difficulty chosen
get_tree().paused = true
# initialize name
chosen_name.text = ""
file.name = ""
# fade in
Fade.fade_in(0.4)
# focus the difficulty
$"%Spicy".call_deferred("grab_focus")
func _set_difficulty(value: int) -> void:
difficulty = posmod(value, 4)
file.difficulty = difficulty
face.frame = difficulty
func _difficulty_selected() -> void:
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
$"%DifficultySelect".queue_free()
$"%NameEntry".visible = true
get_tree().paused = false
Game.use_lives = false
Fade.fade_in(0.4)
func _on_letter_chosen(letter: String) -> void:
file.name += letter
chosen_name.text = file.name
if file.name.length() > 0:
$"%ExitDoor".frame = 1
func _on_Exit_area_entered(area: Area2D) -> void:
if file.name.length() > 0:
get_tree().paused = true
file.save_to_file()
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
get_tree().paused = false
SceneManager.current_scene = load("res://menus/file_select.tscn").instance()

331
menus/file_create.tscn Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,16 +1,15 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var next_scene: PackedScene
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _ready() -> void:
Fade.fade_in(0.4)
$SelectFile1.call_deferred("grab_focus")
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_file_loaded() -> void:
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
SceneManager.current_scene = next_scene.instance()

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://menus/file_select_panel.tscn" type="PackedScene" id=1]
[ext_resource path="res://menus/level_select_scholar.tscn" type="PackedScene" id=2]
[ext_resource path="res://graphics/borders/skaborder.png" type="Texture" id=8]
[ext_resource path="res://graphics/hud/file_select_arrow.png" type="Texture" id=9]
[ext_resource path="res://menus/file_select.gd" type="Script" id=10]
@ -28,9 +29,9 @@ shader_param/uv_transform = Transform2D( 1, 1.582, 1, 2, 0, 0 )
[node name="FileSelect" type="Node"]
script = ExtResource( 10 )
next_scene = ExtResource( 2 )
[node name="TextureRect2" type="TextureRect" parent="."]
visible = false
modulate = Color( 0, 0.109804, 1, 1 )
anchor_right = 1.0
anchor_bottom = 1.0
@ -53,48 +54,58 @@ margin_bottom = 192.0
margin_left = 12.0
margin_top = 64.0
margin_right = 84.0
margin_bottom = 128.0
margin_bottom = 136.0
[node name="Panel2" parent="." instance=ExtResource( 1 )]
margin_left = 92.0
margin_top = 64.0
margin_right = 164.0
margin_bottom = 128.0
margin_bottom = 136.0
number = 2
[node name="Panel3" parent="." instance=ExtResource( 1 )]
margin_left = 172.0
margin_top = 64.0
margin_right = 244.0
margin_bottom = 128.0
margin_bottom = 136.0
number = 3
[node name="SelectFile1" type="TextureButton" parent="."]
margin_left = 12.0
margin_top = 130.0
margin_top = 138.0
margin_right = 84.0
margin_bottom = 138.0
texture_normal = ExtResource( 9 )
margin_bottom = 146.0
focus_neighbour_left = NodePath("../SelectFile3")
focus_neighbour_right = NodePath("../SelectFile2")
texture_focused = ExtResource( 9 )
expand = true
stretch_mode = 3
[node name="SelectFile2" type="TextureButton" parent="."]
margin_left = 92.0
margin_top = 130.0
margin_top = 138.0
margin_right = 164.0
margin_bottom = 138.0
texture_normal = ExtResource( 9 )
margin_bottom = 146.0
focus_neighbour_left = NodePath("../SelectFile1")
focus_neighbour_right = NodePath("../SelectFile3")
texture_focused = ExtResource( 9 )
expand = true
stretch_mode = 3
[node name="SelectFile3" type="TextureButton" parent="."]
margin_left = 172.0
margin_top = 130.0
margin_top = 138.0
margin_right = 244.0
margin_bottom = 138.0
texture_normal = ExtResource( 9 )
margin_bottom = 146.0
focus_neighbour_left = NodePath("../SelectFile2")
focus_neighbour_right = NodePath("../SelectFile1")
texture_focused = ExtResource( 9 )
expand = true
stretch_mode = 3
[connection signal="file_loaded" from="Panel" to="." method="_on_file_loaded"]
[connection signal="file_loaded" from="Panel2" to="." method="_on_file_loaded"]
[connection signal="file_loaded" from="Panel3" to="." method="_on_file_loaded"]
[connection signal="pressed" from="SelectFile1" to="Panel" method="select"]
[connection signal="pressed" from="SelectFile2" to="Panel2" method="select"]
[connection signal="pressed" from="SelectFile3" to="Panel3" method="select"]

View file

@ -1,16 +1,48 @@
extends Panel
signal file_loaded()
const FileCreate = preload("res://menus/file_create.tscn")
export var number = 1
var file: Save.SaveFile
var file: Save.SaveFile = null
func _ready():
$FileNumber.text = "FILE%d" % number
# check if the file exists
if File.new().file_exists("user://file%d.pr" % number):
# load file and fill in information
file = Save.load_file("user://file%d.pr" % number)
$"%Name".text = file.name
$"%ShardCounter".text = "%02d" % file.get_total_shards()
$"%KeyCounter".text = "%03d" % file.get_total_keys()
$"%DeathCounter".text = "%04d" % file.get_total_deaths()
$"%TimeCounter".text = "%02d:%02d" % [file.play_time / 3600.0, fmod(file.play_time / 60.0, 60.0)]
else:
$FileExists.visible = false
$FileDoesNotExist.visible = true
func select() -> void:
# if a file exists, load and play it!
if file:
# set current file and difficulty
Save.current_file = file
Game.difficulty = file.difficulty
# update last-played file for continue button
Options.last_file = number
Options.save_options()
# let file select scene know a file has been loaded
emit_signal("file_loaded")
# empty file, so go to file creation screen
else:
# wait for fade
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
# create new file and give it to the file create screen
var file_create = FileCreate.instance()
file_create.file = Save.SaveFile.new("user://file%d.pr" % number)
SceneManager.current_scene = file_create

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://shaders/recolor_border.shader" type="Shader" id=1]
[ext_resource path="res://ui/2ndpuberty_outline.tres" type="Material" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://ui/theme.tres" type="Theme" id=4]
[ext_resource path="res://objects/collectibles/shard.tscn" type="PackedScene" id=5]
[ext_resource path="res://menus/file_select_panel.gd" type="Script" id=6]
[ext_resource path="res://graphics/hud/deaths_head.png" type="Texture" id=7]
[ext_resource path="res://graphics/player/sg_idle.png" type="Texture" id=8]
[ext_resource path="res://graphics/player/palettes/default.png" type="Texture" id=9]
@ -17,12 +18,9 @@ shader_param/palette = ExtResource( 9 )
[node name="Panel" type="Panel"]
margin_right = 72.0
margin_bottom = 64.0
margin_bottom = 72.0
theme = ExtResource( 4 )
script = ExtResource( 6 )
__meta__ = {
"_edit_group_": true
}
[node name="FileNumber" type="Label" parent="."]
material = ExtResource( 2 )
@ -32,7 +30,9 @@ theme = ExtResource( 4 )
text = "file1"
align = 1
[node name="FileExists" type="Node2D" parent="."]
[node name="FileExists" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="Name" type="Label" parent="FileExists"]
unique_name_in_owner = true
@ -46,12 +46,20 @@ align = 1
[node name="TimeCounter" type="Label" parent="FileExists"]
unique_name_in_owner = true
margin_left = 3.0
margin_top = 50.0
margin_top = 58.0
margin_right = 69.0
margin_bottom = 60.0
margin_bottom = 68.0
text = "00:00"
align = 1
[node name="DeathCounter" type="Label" parent="FileExists"]
unique_name_in_owner = true
margin_left = 25.0
margin_top = 47.0
margin_right = 56.0
margin_bottom = 57.0
text = "0000"
[node name="Palette" type="TextureRect" parent="FileExists"]
material = SubResource( 1 )
margin_left = 8.0
@ -83,7 +91,11 @@ position = Vector2( 32, 23 )
[node name="Key" parent="FileExists" instance=ExtResource( 3 )]
position = Vector2( 32, 34 )
[node name="FileDoesNotExist" type="Node2D" parent="."]
[node name="DeathsHead" type="Sprite" parent="FileExists"]
position = Vector2( 21, 52 )
texture = ExtResource( 7 )
[node name="FileDoesNotExist" type="Control" parent="."]
visible = false
[node name="Label" type="Label" parent="FileDoesNotExist"]

View file

@ -3,10 +3,11 @@ extends Node
onready var continue_button = $Panel/Continue
func _ready():
Fade.fade_in(0.4)
#Grey out continue if no save files
yield(get_tree(),"idle_frame")
var file = File.new()
if file.file_exists("user://file1.pr") or file.file_exists("user://file2.pr") or file.file_exists("user://file3.pr"):
print(Save.current_file)
if Save.current_file:
$Panel/Continue.grab_focus()
else:
$Panel/Body/GreyedContinue.visible = true
@ -17,12 +18,18 @@ func _ready():
func _on_Continue_button_down():
pass # Replace with function body.
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
SceneManager.current_scene = load("res://menus/level_select_scholar.tscn").instance()
func _on_FileSelect_button_down():
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
SceneManager.current_scene = load("res://menus/file_select.tscn").instance()
func _on_Exit_button_down():
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
get_tree().quit()

View file

@ -135,7 +135,7 @@ margin_left = 8.0
margin_top = 9.0
margin_right = 16.0
margin_bottom = 17.0
focus_neighbour_top = NodePath("../Options")
focus_neighbour_top = NodePath("../Exit")
focus_neighbour_bottom = NodePath("../FileSelect")
texture_focused = ExtResource( 4 )

View file

@ -4,4 +4,6 @@ export var next_menu: PackedScene
func _input(event):
if Input.is_action_just_pressed("start"):
Fade.fade_out(0.4)
yield(Fade, "fade_finished")
SceneManager.current_scene = next_menu.instance()