forked from unknown-horizons/godot-port
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
theludovyc
committed
Dec 15, 2024
1 parent
01f45bf
commit f67bbba
Showing
8 changed files
with
256 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|