Skip to content

Commit

Permalink
Global scene loader (map scene loader excluded) (Saplings-Projects#86)
Browse files Browse the repository at this point in the history
* Add a scene manager singleton

* Add new scenes to be accessed from main menu and make main menu the first launched scene

* Add option menu, quit button

* Add a script to the testing scene to properly init game state

* Remove the init game call in the ready of phase manager

* Add a draft of a BG for the main menu as placeholder
  • Loading branch information
Turtyo authored Mar 30, 2024
1 parent 355d7fe commit a531d03
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 4 deletions.
61 changes: 61 additions & 0 deletions #Scenes/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[gd_scene load_steps=3 format=3 uid="uid://chw8kc2q4o3pi"]

[ext_resource type="Script" path="res://#Scenes/SceneScripts/MainMenu.gd" id="1_mwp8y"]
[ext_resource type="Texture2D" uid="uid://u5naod8gur3m" path="res://Art/Menus/main_menu_bg-1.png" id="2_v07no"]

[node name="Main menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_mwp8y")

[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 2
offset_right = 1280.0
offset_bottom = 720.0
texture = ExtResource("2_v07no")
expand_mode = 1

[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
theme_override_font_sizes/font_size = 34
text = "This is the main menu"

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -180.0
offset_top = -230.0
offset_right = -21.0
offset_bottom = -27.0
grow_horizontal = 0
grow_vertical = 0
theme_override_constants/separation = 7

[node name="Start" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 40
text = "Start"

[node name="Options" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 40
text = "Options"

[node name="Quit" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 40
text = "Quit"

[connection signal="pressed" from="VBoxContainer/Start" to="." method="_on_start_pressed"]
[connection signal="pressed" from="VBoxContainer/Options" to="." method="_on_options_pressed"]
[connection signal="pressed" from="VBoxContainer/Quit" to="." method="_on_quit_pressed"]
37 changes: 37 additions & 0 deletions #Scenes/OptionsMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[gd_scene load_steps=3 format=3 uid="uid://m1u72kig8f0q"]

[ext_resource type="Texture2D" uid="uid://dyquabho0a3me" path="res://Art/Menus/options_menu_back-1.png" id="1_a6abe"]
[ext_resource type="Script" path="res://#Scenes/SceneScripts/OptionsMenu.gd" id="1_rms2r"]

[node name="Options Menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_rms2r")

[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
theme_override_font_sizes/font_size = 70
text = "Woohoo so many options"

[node name="Back" type="Button" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -159.0
offset_top = -159.0
offset_right = 159.0
offset_bottom = 159.0
grow_horizontal = 2
grow_vertical = 2
icon = ExtResource("1_a6abe")

[connection signal="pressed" from="Back" to="." method="_on_back_pressed"]
14 changes: 14 additions & 0 deletions #Scenes/SceneScripts/MainMenu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Control



func _on_start_pressed() -> void:
SceneManager.goto_scene("res://#Scenes/TestingScene.tscn")


func _on_options_pressed() -> void:
SceneManager.goto_scene("res://#Scenes/OptionsMenu.tscn")


func _on_quit_pressed() -> void:
get_tree().quit()
7 changes: 7 additions & 0 deletions #Scenes/SceneScripts/OptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Control




func _on_back_pressed() -> void:
SceneManager.goto_scene("res://#Scenes/MainMenu.tscn")
7 changes: 7 additions & 0 deletions #Scenes/SceneScripts/TestingScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node2D

## * We do this to properly init the battle state
## Before, the testing scene was the main scene so it was properly started by the phase manager
## Now that the main scene is the main menu and we load the testing scene from there, we init to properly init the game state
func _ready() -> void:
PhaseManager.initialize_game()
5 changes: 5 additions & 0 deletions #Scenes/SceneScripts/TestingScene_UIcontrol.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends Control


func _on_back_to_main_menu_pressed() -> void:
SceneManager.goto_scene("res://#Scenes/MainMenu.tscn")
17 changes: 16 additions & 1 deletion #Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_scene load_steps=16 format=3 uid="uid://b60uabg68ra1l"]
[gd_scene load_steps=18 format=3 uid="uid://b60uabg68ra1l"]

[ext_resource type="Script" path="res://#Scenes/SceneScripts/TestingScene.gd" id="1_ji0t8"]
[ext_resource type="Script" path="res://Map/MapManager.gd" id="2_50npk"]
[ext_resource type="PackedScene" uid="uid://clmg3l3n28x38" path="res://Entity/Player/Player.tscn" id="3_4psp7"]
[ext_resource type="PackedScene" uid="uid://dpjfy4pv0vxst" path="res://Cards/CardContainer.tscn" id="3_e7sws"]
[ext_resource type="Script" path="res://#Scenes/SceneScripts/TestingScene_UIcontrol.gd" id="4_h8431"]
[ext_resource type="PackedScene" uid="uid://bcpmrmofcilbn" path="res://Core/Battler.tscn" id="8_qtw1k"]
[ext_resource type="Script" path="res://UI/DrawPileUISetter.gd" id="8_voref"]
[ext_resource type="Script" path="res://UI/DiscardPileUISetter.gd" id="10_pqly7"]
Expand All @@ -17,6 +19,7 @@
[ext_resource type="Script" path="res://UI/MapButton.gd" id="22_druf4"]

[node name="TestingScene" type="Node2D"]
script = ExtResource("1_ji0t8")
metadata/_edit_vertical_guides_ = [1216.0]

[node name="Battler" parent="." instance=ExtResource("8_qtw1k")]
Expand All @@ -37,6 +40,7 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("4_h8431")

[node name="CardContainer" parent="CanvasLayer/UIControl" node_paths=PackedStringArray("draw_pile_ui", "discard_pile_ui") instance=ExtResource("3_e7sws")]
layout_mode = 1
Expand Down Expand Up @@ -193,4 +197,15 @@ ignore_texture_size = true
stretch_mode = 0
script = ExtResource("22_druf4")

[node name="back_to_main_menu" type="Button" parent="CanvasLayer/UIControl"]
layout_mode = 0
offset_left = 29.0
offset_top = 22.0
offset_right = 148.0
offset_bottom = 86.0
theme_override_font_sizes/font_size = 20
text = "Go back to
main menu"

[connection signal="pressed" from="CanvasLayer/UIControl/EndTurnButton" to="CanvasLayer/UIControl/EndTurnButton" method="_on_pressed"]
[connection signal="pressed" from="CanvasLayer/UIControl/back_to_main_menu" to="CanvasLayer/UIControl" method="_on_back_to_main_menu_pressed"]
Binary file added Art/Menus/main_menu_bg-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Art/Menus/main_menu_bg-1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://u5naod8gur3m"
path="res://.godot/imported/main_menu_bg-1.png-a5473e7c70856731414b60eba624e138.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Art/Menus/main_menu_bg-1.png"
dest_files=["res://.godot/imported/main_menu_bg-1.png-a5473e7c70856731414b60eba624e138.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added Art/Menus/options_menu_back-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Art/Menus/options_menu_back-1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dyquabho0a3me"
path="res://.godot/imported/options_menu_back-1.png-cdb439064b4a6a52f0485f9a1e8ac346.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Art/Menus/options_menu_back-1.png"
dest_files=["res://.godot/imported/options_menu_back-1.png-cdb439064b4a6a52f0485f9a1e8ac346.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
3 changes: 2 additions & 1 deletion Managers/PhaseManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var current_phase: GlobalEnums.Phase = GlobalEnums.Phase.NONE


func _ready() -> void:
initialize_game()
# initialize_game()
return


func initialize_game() -> void:
Expand Down
36 changes: 36 additions & 0 deletions Managers/SceneManager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
extends Node

var current_scene: Node = null

func _ready() -> void:
var root: Node = get_tree().root
current_scene = root.get_child(root.get_child_count() - 1)

func goto_scene(path: String) -> void:
# This function will usually be called from a signal callback,
# or some other function in the current scene.
# Deleting the current scene at this point is
# a bad idea, because it may still be executing code.
# This will result in a crash or unexpected behavior.

# The solution is to defer the load to a later time, when
# we can be sure that no code from the current scene is running:

call_deferred("_deferred_goto_scene", path)


func _deferred_goto_scene(path: String) -> void:
# It is now safe to remove the current scene.
current_scene.free()

# Load the new scene.
var s: Resource = ResourceLoader.load(path)

# Instance the new scene.
current_scene = s.instantiate()

# Add it to the active scene, as child of root.
get_tree().root.add_child(current_scene)

# Optionally, to make it compatible with the SceneTree.change_scene_to_file() API.
get_tree().current_scene = current_scene
2 changes: 1 addition & 1 deletion export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export_filter="exclude"
export_files=PackedStringArray("res://addons/gut/fonts/AnonymousPro-Bold.ttf", "res://addons/gut/fonts/AnonymousPro-BoldItalic.ttf", "res://addons/gut/fonts/AnonymousPro-Italic.ttf", "res://addons/gut/fonts/AnonymousPro-Regular.ttf", "res://addons/gut/fonts/CourierPrime-Bold.ttf", "res://addons/gut/fonts/CourierPrime-BoldItalic.ttf", "res://addons/gut/fonts/CourierPrime-Italic.ttf", "res://addons/gut/fonts/CourierPrime-Regular.ttf", "res://addons/gut/fonts/LobsterTwo-Bold.ttf", "res://addons/gut/fonts/LobsterTwo-BoldItalic.ttf", "res://addons/gut/fonts/LobsterTwo-Italic.ttf", "res://addons/gut/fonts/LobsterTwo-Regular.ttf", "res://addons/gut/gui/arrow.png", "res://addons/gut/gui/BottomPanelShortcuts.gd", "res://addons/gut/gui/BottomPanelShortcuts.tscn", "res://addons/gut/gui/GutBottomPanel.gd", "res://addons/gut/gui/GutBottomPanel.tscn", "res://addons/gut/gui/GutControl.gd", "res://addons/gut/gui/GutControl.tscn", "res://addons/gut/gui/GutRunner.gd", "res://addons/gut/gui/GutRunner.tscn", "res://addons/gut/gui/GutSceneTheme.tres", "res://addons/gut/gui/gut_config_gui.gd", "res://addons/gut/gui/gut_gui.gd", "res://addons/gut/gui/MinGui.tscn", "res://addons/gut/gui/NormalGui.tscn", "res://addons/gut/gui/OutputText.gd", "res://addons/gut/gui/OutputText.tscn", "res://addons/gut/gui/play.png", "res://addons/gut/gui/ResizeHandle.gd", "res://addons/gut/gui/ResizeHandle.tscn", "res://addons/gut/gui/ResultsTree.gd", "res://addons/gut/gui/ResultsTree.tscn", "res://addons/gut/gui/RunAtCursor.gd", "res://addons/gut/gui/RunAtCursor.tscn", "res://addons/gut/gui/RunResults.gd", "res://addons/gut/gui/RunResults.tscn", "res://addons/gut/gui/script_text_editor_controls.gd", "res://addons/gut/gui/Settings.tscn", "res://addons/gut/gui/ShortcutButton.gd", "res://addons/gut/gui/ShortcutButton.tscn", "res://addons/gut/images/Folder.svg", "res://addons/gut/images/green.png", "res://addons/gut/images/red.png", "res://addons/gut/images/Script.svg", "res://addons/gut/images/yellow.png", "res://addons/gut/autofree.gd", "res://addons/gut/awaiter.gd", "res://addons/gut/collected_script.gd", "res://addons/gut/collected_test.gd", "res://addons/gut/comparator.gd", "res://addons/gut/compare_result.gd", "res://addons/gut/diff_formatter.gd", "res://addons/gut/diff_tool.gd", "res://addons/gut/doubler.gd", "res://addons/gut/double_tools.gd", "res://addons/gut/gut.gd", "res://addons/gut/GutScene.gd", "res://addons/gut/GutScene.tscn", "res://addons/gut/gut_cmdln.gd", "res://addons/gut/gut_config.gd", "res://addons/gut/gut_plugin.gd", "res://addons/gut/gut_to_move.gd", "res://addons/gut/hook_script.gd", "res://addons/gut/icon.png", "res://addons/gut/inner_class_registry.gd", "res://addons/gut/input_factory.gd", "res://addons/gut/input_sender.gd", "res://addons/gut/junit_xml_export.gd", "res://addons/gut/logger.gd", "res://addons/gut/method_maker.gd", "res://addons/gut/one_to_many.gd", "res://addons/gut/optparse.gd", "res://addons/gut/orphan_counter.gd", "res://addons/gut/parameter_factory.gd", "res://addons/gut/parameter_handler.gd", "res://addons/gut/printers.gd", "res://addons/gut/result_exporter.gd", "res://addons/gut/script_parser.gd", "res://addons/gut/signal_watcher.gd", "res://addons/gut/source_code_pro.fnt", "res://addons/gut/spy.gd", "res://addons/gut/strutils.gd", "res://addons/gut/stubber.gd", "res://addons/gut/stub_params.gd", "res://addons/gut/summary.gd", "res://addons/gut/test.gd", "res://addons/gut/test_collector.gd", "res://addons/gut/thing_counter.gd", "res://addons/gut/UserFileViewer.gd", "res://addons/gut/UserFileViewer.tscn", "res://addons/gut/utils.gd", "res://Tests/TestBase.gd", "res://Tests/TestCardBase.gd", "res://Tests/TestMapBase.gd", "res://Tests/test_assert_true.gd", "res://Tests/test_cards.gd", "res://Tests/test_death_handling.gd", "res://Tests/test_energy.gd", "res://Tests/test_eventbase.gd", "res://Tests/test_health.gd", "res://Tests/test_light_data.gd", "res://Tests/test_map.gd", "res://Tests/test_map_movement.gd", "res://Tests/test_map_ui.gd", "res://Tests/test_persistence.gd", "res://Tests/test_pile_ui.gd", "res://Tests/test_stats.gd")
include_filter=""
exclude_filter=""
export_path="../export/linux/Fauna-RPG.x86_64"
export_path="../export/release/linux/Fauna-RPG.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
Expand Down
3 changes: 2 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ config_version=5
[application]

config/name="Fauna-RPG"
run/main_scene="res://#Scenes/TestingScene.tscn"
run/main_scene="res://#Scenes/MainMenu.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
boot_splash/image="res://Art/Menus/loading_splash_art-1.png"
config/icon="res://Art/Menus/fauna_icon-1.png"

[autoload]

SceneManager="*res://Managers/SceneManager.gd"
SignalBus="*res://Global/SignalBus.gd"
DebugVar="*res://Global/DEBUG_VAR.gd"
PlayerManager="*res://Managers/PlayerManager.gd"
Expand Down

0 comments on commit a531d03

Please sign in to comment.