Skip to content

Commit

Permalink
[wip] prepare save ui
Browse files Browse the repository at this point in the history
  • Loading branch information
theludovyc committed Dec 15, 2024
1 parent 01f45bf commit f67bbba
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 26 deletions.
39 changes: 37 additions & 2 deletions Scene/Menu/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://dytw0n3b07ux4"]
[gd_scene load_steps=19 format=3 uid="uid://dytw0n3b07ux4"]

[ext_resource type="Script" path="res://Script/Gui/Menu/MainMenu.gd" id="1"]
[ext_resource type="Theme" uid="uid://lyx8kydf373j" path="res://Art/Theme/MenuTheme.tres" id="1_i4hjr"]
Expand All @@ -14,6 +14,7 @@
[ext_resource type="Texture2D" uid="uid://fnwe2ccpoxu7" path="res://Art/Image/Gui/Icons/MainMenu/multiplayer_bw.png" id="11_ulff8"]
[ext_resource type="Texture2D" uid="uid://dx3wfk7nhepo7" path="res://Art/Image/Gui/Logos/uh_no_text.svg" id="12_q4rhy"]
[ext_resource type="Texture2D" uid="uid://lxvd4qr8d35m" path="res://Art/Image/Gui/Logos/uh_only_text.svg" id="13_yw4on"]
[ext_resource type="PackedScene" uid="uid://choevp6ilq78t" path="res://Scene/RGT/loadSaveMenu.tscn" id="15_fufc5"]

[sub_resource type="Animation" id="Animation_ft716"]
length = 0.001
Expand Down Expand Up @@ -202,7 +203,6 @@ offset_left = -158.0
offset_top = -160.0
offset_right = -58.0
offset_bottom = -60.0
disabled = true
text = "Load Game"
texture = ExtResource("6_6uh4k")

Expand Down Expand Up @@ -347,6 +347,39 @@ texture = ExtResource("13_yw4on")
expand_mode = 1
stretch_mode = 4

[node name="PanelMenu" type="Panel" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 1
anchors_preset = -1
anchor_left = 0.1
anchor_top = 0.1
anchor_right = 0.9
anchor_bottom = 0.9
grow_horizontal = 2
grow_vertical = 2

[node name="LoadSaveMenu" parent="PanelMenu" instance=ExtResource("15_fufc5")]
unique_name_in_owner = true
visible = false
layout_mode = 1
metadata/_edit_use_anchors_ = true

[node name="BackButton" type="Button" parent="PanelMenu"]
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -34.0
offset_top = 16.0
offset_right = 37.0
offset_bottom = 61.0
grow_horizontal = 2
grow_vertical = 0
text = "Back"

[node name="VersionNumber" type="Label" parent="."]
unique_name_in_owner = true
layout_mode = 1
Expand All @@ -371,4 +404,6 @@ unique_name_in_owner = true
dialog_text = "Are you sure you want to quit ?"

[connection signal="pressed" from="Decoration/MenuItems/PlayButton" to="." method="_on_play_button_pressed"]
[connection signal="pressed" from="Decoration/MenuItems/LoadButton" to="." method="_on_load_button_pressed"]
[connection signal="pressed" from="Decoration/MenuItems/ExitButton" to="." method="_on_exit_button_pressed"]
[connection signal="pressed" from="PanelMenu/BackButton" to="." method="_on_back_button_pressed"]
21 changes: 21 additions & 0 deletions Scene/RGT/loadSaveMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[gd_scene load_steps=2 format=3 uid="uid://choevp6ilq78t"]

[ext_resource type="Script" path="res://Script/RGT/LoadSaveMenu/load_save_menu.gd" id="1_nyk5l"]

[node name="LoadSaveMenu" type="ScrollContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
horizontal_scroll_mode = 0
script = ExtResource("1_nyk5l")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2
size_flags_horizontal = 3

[node name="ConfirmationDialog" type="ConfirmationDialog" parent="."]
unique_name_in_owner = true

[connection signal="confirmed" from="ConfirmationDialog" to="." method="_on_confirmation_dialog_confirmed"]
49 changes: 49 additions & 0 deletions Scene/RGT/savePanelContainer.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[gd_scene load_steps=2 format=3 uid="uid://wal8k0gos06y"]

[ext_resource type="Script" path="res://Script/RGT/LoadSaveMenu/save_panel_container.gd" id="1_np60c"]

[node name="SavePanelContainer" type="PanelContainer"]
script = ExtResource("1_np60c")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 12

[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 8

[node name="SaveTextureRect" type="TextureRect" parent="MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 4
expand_mode = 5
stretch_mode = 5

[node name="NameLabel" type="Label" parent="MarginContainer/HBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(8, 8)
layout_mode = 2
size_flags_horizontal = 3
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 1

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_vertical = 4
alignment = 1

[node name="LoadButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Load"

[node name="DeleteButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Delete"
18 changes: 18 additions & 0 deletions Script/Gui/Menu/MainMenu.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends MainMenu

@onready var panel_menu = %PanelMenu

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_anything_pressed():
Expand All @@ -8,3 +10,19 @@ func _process(_delta):
animation_player.seek(animation_player.current_animation_length)

set_process(false)


func _open_sub_menu(menu : Control):
panel_menu.visible = true

sub_menu = menu
sub_menu.show()

func _close_sub_menu():
if sub_menu == null:
return

panel_menu.visible = false

sub_menu.hide()
sub_menu = null
2 changes: 1 addition & 1 deletion Script/RGT/LoadSaveMenu/load_save_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ signal no_save_to_load
const confirm_load = "Are you sure you want to load this save?\n"
const confirm_delete = "Are you sure you want to delete this save ?\n"

var SavePanel = preload("res://scenes/LoadSaveMenu/savePanelContainer.tscn")
var SavePanel = preload("res://Scene/RGT/savePanelContainer.tscn")

@onready var vbox_container = $VBoxContainer

Expand Down
46 changes: 23 additions & 23 deletions Script/RGT/MainMenu.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class_name MainMenu
extends Control

#var sub_menu
var sub_menu

#@onready var continue_button = %ContinueButton
@onready var play_button = %PlayButton
Expand All @@ -18,27 +18,27 @@ extends Control
exit_button
]

#@onready var load_save_menu = %LoadSaveMenu
@onready var load_save_menu = %LoadSaveMenu
#@onready var option_menu = %OptionsMenu
#@onready var credit_menu = %CreditsContainer

@onready var confirm_popup = %ConfirmationDialog

#func _open_sub_menu(menu : Control):
#if sub_menu == menu:
#sub_menu.visible = !sub_menu.visible
#return
#if sub_menu != null:
#sub_menu.hide()
#sub_menu = menu
#sub_menu.show()
func _open_sub_menu(menu : Control):
if sub_menu == menu:
sub_menu.visible = !sub_menu.visible
return
if sub_menu != null:
sub_menu.hide()
sub_menu = menu
sub_menu.show()


#func _close_sub_menu():
#if sub_menu == null:
#return
#sub_menu.hide()
#sub_menu = null
func _close_sub_menu():
if sub_menu == null:
return
sub_menu.hide()
sub_menu = null


#func _event_is_mouse_button_released(event : InputEvent):
Expand Down Expand Up @@ -86,8 +86,8 @@ func _on_play_button_pressed():

SceneLoader.change_scene(RGT_Globals.first_game_scene_setting)

#func _on_load_button_pressed() -> void:
#_open_sub_menu(load_save_menu)
func _on_load_button_pressed() -> void:
_open_sub_menu(load_save_menu)
#
#func _on_options_button_pressed():
#_open_sub_menu(option_menu)
Expand All @@ -101,11 +101,11 @@ func _on_exit_button_pressed():
func _on_exit_confirmed():
get_tree().quit()

#func _on_back_button_pressed():
#_close_sub_menu()
func _on_back_button_pressed():
_close_sub_menu()

#func _on_load_save_menu_no_save_to_load() -> void:
func _on_load_save_menu_no_save_to_load() -> void:
#continue_button.hide()
#load_button.hide()
#
#_close_sub_menu()
load_button.hide()

_close_sub_menu()
85 changes: 85 additions & 0 deletions Script/RGT/load_save_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
extends ScrollContainer

signal no_save_to_load

const confirm_load = "Are you sure you want to load this save?\n"
const confirm_delete = "Are you sure you want to delete this save ?\n"

var SavePanel = preload("res://scenes/LoadSaveMenu/savePanelContainer.tscn")

@onready var vbox_container = $VBoxContainer

@onready var confirm_dialog = %ConfirmationDialog

enum Modes{
Loading,
Deleting
}

var popup_mode = Modes.Loading
var current_save_file_name:String = ""
var current_save_panel:Node = null

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if SaveHelper.save_file_names.is_empty():
SaveHelper.update_save_file_names()

if SaveHelper.save_file_names.is_empty():
push_warning("No save to load")
pass

for save_file_name in SaveHelper.save_file_names:
var save_panel = SavePanel.instantiate()

vbox_container.add_child(save_panel)

save_panel.init(save_file_name)

save_panel.load_button.pressed.connect(_on_load_button_pressed.bind(save_file_name))
save_panel.delete_button.pressed.connect(
_on_delete_button_pressed.bind(save_panel, save_file_name))

func _on_load_button_pressed(save_file_name:String):
popup_mode = Modes.Loading

current_save_file_name = save_file_name

confirm_dialog.dialog_text = confirm_load + save_file_name

confirm_dialog.popup_centered()

func _on_delete_button_pressed(save_panel:Node, save_file_name:String):
popup_mode = Modes.Deleting

current_save_file_name = save_file_name

current_save_panel = save_panel

confirm_dialog.dialog_text = confirm_delete + save_file_name

confirm_dialog.popup_centered()

func _on_confirmation_dialog_confirmed() -> void:
match(popup_mode):
Modes.Loading:
SaveHelper.save_file_name_to_load = current_save_file_name

SceneLoader.change_scene(RGT_Globals.first_game_scene_setting)

Modes.Deleting:
SaveHelper.delete(current_save_file_name)

# move to trash the screenshot
OS.move_to_trash(
ProjectSettings.globalize_path(
SaveHelper.get_save_file_path_without_extension(current_save_file_name) + ".png"
))

SaveHelper.update_save_file_names()

if SaveHelper.save_file_names.is_empty():
no_save_to_load.emit()

current_save_panel.queue_free()

22 changes: 22 additions & 0 deletions Script/RGT/save_panel_container.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends PanelContainer

@onready var name_label = %NameLabel
@onready var save_texture = %SaveTextureRect
@onready var load_button = %LoadButton
@onready var delete_button = %DeleteButton

func init(save_name:String):
name_label.text = save_name

var image_path := SaveHelper.save_dir_path + "/" + save_name + ".png"

if not FileAccess.file_exists(image_path):
return

var image := Image.load_from_file(image_path)

if image == null:
return

save_texture.texture = ImageTexture.create_from_image(image)

0 comments on commit f67bbba

Please sign in to comment.