Persistent Game Scene

Keeps the game scene persistent while using the 'More Options' menu path. Resume game will now return to the existing scene (game at current place it was left behind). Also removes the old history process which is defunct -- history will now be saved to global/singleton history array, and when history loaded, instantiate a new history scene which reads/pages this array (and saves out later).
This commit is contained in:
MacDugRPG 2022-05-08 15:13:24 -04:00
parent 38c9a422b6
commit e1fc845256
7 changed files with 85 additions and 66 deletions

View File

@ -0,0 +1,25 @@
#But_MoreOptions:
# For these options, we leave the game object active and manually add and remove
# the scenes as needed.
tool
extends Button
#Creates param usable in the UI; and the params next to export make it string and file browser
export(String, FILE) var next_scene_path: = ""
func _on_But_MoreOptions_button_up():
var root = get_node("/root")
var gameCurrent = get_node("/root/Game")
var gameSingleton = get_node("/root/GameCurrent")
var nextScene = load(next_scene_path)
gameSingleton.gameCurrent_scene = gameCurrent
root.remove_child(gameCurrent)
nextScene = nextScene.instance()
root.add_child(nextScene)
func _get_configuration_warning() -> String:
return "next_scene_path must be set for this button to work" if next_scene_path == "" else ""

View File

@ -12,8 +12,6 @@ const InputResponse = preload("res://UserInterface/InputResponse.tscn")
onready var command_processor = $CommandProcessor onready var command_processor = $CommandProcessor
onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
onready var history_rows = $Background/MarginContainer/Rows/GameInfo/HistoryRows
onready var history_on= $Background/MarginContainer/Rows/ItemList/But_History
onready var history_pager = $Background/MarginContainer/Rows/ItemList/But_History_Page onready var history_pager = $Background/MarginContainer/Rows/ItemList/But_History_Page
onready var locale_manager = $LocaleManager onready var locale_manager = $LocaleManager
onready var option_one = $Background/MarginContainer/Rows/InputArea/VBoxContainer/option1 onready var option_one = $Background/MarginContainer/Rows/InputArea/VBoxContainer/option1
@ -31,9 +29,6 @@ func _ready() -> void:
#DKM TEMP: for testing only -- this will be set in settings #DKM TEMP: for testing only -- this will be set in settings
save_module() save_module()
theme=load("res://assets/ui_controlNode_dark_theme.tres") theme=load("res://assets/ui_controlNode_dark_theme.tres")
history_pager.hide()
history_rows.hide()
history_on.hide()
current_text.show() current_text.show()
option_one.show() option_one.show()
option_two.show() option_two.show()
@ -66,17 +61,19 @@ func create_response(response_text: String):
#Copies the response output to add to both current game output, and the #Copies the response output to add to both current game output, and the
# history array. # history array.
func add_response_to_game(response: Control): func add_response_to_game(response: Control):
var response_history = response.duplicate() add_response_to_history(response)
#DKM TEMP: stopped here, trying to add page number to history text
#var history_page_number = HISTORY_SOURCE.output_history_array.size() + 1
#var history_string = "Page " + str(history_page_number) + "; "
if(history_source.output_history_array != null):
history_source.output_history_array.append(response_history)
if(current_text.get_child_count() > 0): if(current_text.get_child_count() > 0):
current_text.remove_child(current_text.get_child(0)) current_text.remove_child(current_text.get_child(0))
current_text.add_child(response) current_text.add_child(response)
func add_response_to_history(response: Control) -> void:
#DKM TEMP: so here we
#1. var response_history = response.duplicate()
#2. get the history array from the singleton,
#3. Add this to the history array
#
pass
func _on_option1_button_down() -> void: func _on_option1_button_down() -> void:
var option1 = get_node("Background/MarginContainer/Rows/InputArea/VBoxContainer/option1") var option1 = get_node("Background/MarginContainer/Rows/InputArea/VBoxContainer/option1")

View File

@ -1,14 +1,11 @@
[gd_scene load_steps=11 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://UserInterface/But_ChangeScene.tscn" type="PackedScene" id=1]
[ext_resource path="res://gamePlay/Game.gd" type="Script" id=2] [ext_resource path="res://gamePlay/Game.gd" type="Script" id=2]
[ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=3] [ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=3]
[ext_resource path="res://gamePlay/CommandProcessor.gd" type="Script" id=4] [ext_resource path="res://gamePlay/CommandProcessor.gd" type="Script" id=4]
[ext_resource path="res://userInterface/Locale.tscn" type="PackedScene" id=5] [ext_resource path="res://userInterface/Locale.tscn" type="PackedScene" id=5]
[ext_resource path="res://gamePlay/LocaleManager.gd" type="Script" id=6] [ext_resource path="res://gamePlay/LocaleManager.gd" type="Script" id=6]
[ext_resource path="res://userInterface/But_History.gd" type="Script" id=7] [ext_resource path="res://gamePlay/But_MoreOptions.gd" type="Script" id=9]
[ext_resource path="res://userInterface/But_History_Page.gd" type="Script" id=8]
[ext_resource path="res://_toArchive/ui_gameplay_theme.tres" type="Theme" id=10]
[ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=11] [ext_resource path="res://assets/liberation_serif_30pt.tres" type="DynamicFont" id=11]
[node name="Game" type="Control"] [node name="Game" type="Control"]
@ -115,36 +112,16 @@ margin_right = 708.0
margin_bottom = 40.0 margin_bottom = 40.0
rect_min_size = Vector2( 0, 40 ) rect_min_size = Vector2( 0, 40 )
[node name="But_ChangeScene" parent="Background/MarginContainer/Rows/ItemList" instance=ExtResource( 1 )] [node name="But_MoreOptions" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
margin_right = 135.0 margin_right = 170.0
margin_bottom = 30.0 margin_bottom = 36.0
theme = ExtResource( 10 )
text = "More Options" text = "More Options"
script = ExtResource( 9 )
__meta__ = {
"_edit_use_anchors_": false
}
next_scene_path = "res://Screens/MoreOptions.tscn" next_scene_path = "res://Screens/MoreOptions.tscn"
[node name="But_History" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
margin_left = 148.756
margin_right = 273.756
margin_bottom = 30.0
theme = ExtResource( 10 )
text = "Toggle History"
script = ExtResource( 7 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="But_History_Page" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -103.0
margin_bottom = 30.0
theme = ExtResource( 10 )
text = "Next Page"
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GameInfo" type="PanelContainer" parent="Background/MarginContainer/Rows"] [node name="GameInfo" type="PanelContainer" parent="Background/MarginContainer/Rows"]
margin_top = 50.0 margin_top = 50.0
margin_right = 708.0 margin_right = 708.0
@ -160,15 +137,6 @@ size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
custom_constants/separation = 20 custom_constants/separation = 20
[node name="HistoryRows" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo"]
margin_left = 1.0
margin_top = 1.0
margin_right = 707.0
margin_bottom = 387.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 20
[node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Rows"] [node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Rows"]
margin_top = 448.0 margin_top = 448.0
margin_right = 708.0 margin_right = 708.0
@ -309,8 +277,7 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[connection signal="button_up" from="Background/MarginContainer/Rows/ItemList/But_History" to="Background/MarginContainer/Rows/ItemList/But_History" method="_on_But_History_button_up"] [connection signal="button_up" from="Background/MarginContainer/Rows/ItemList/But_MoreOptions" to="Background/MarginContainer/Rows/ItemList/But_MoreOptions" method="_on_But_MoreOptions_button_up"]
[connection signal="button_up" from="Background/MarginContainer/Rows/ItemList/But_History_Page" to="Background/MarginContainer/Rows/ItemList/But_History_Page" method="_on_But_History_Page_button_up"]
[connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option1" to="." method="_on_option1_button_down"] [connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option1" to="." method="_on_option1_button_down"]
[connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option2" to="." method="_on_option2_button_down"] [connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option2" to="." method="_on_option2_button_down"]
[connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option3" to="." method="_on_option3_button_down"] [connection signal="button_down" from="Background/MarginContainer/Rows/InputArea/VBoxContainer/option3" to="." method="_on_option3_button_down"]

View File

@ -0,0 +1,10 @@
#gameCurrent:
# Simple singleton script for storing persistent game cene paths.
# These must then not be destroyed, but manually removed as a child of the
# node and they can always be re-added as needed.
extends Node
var gameCurrent_scene

View File

@ -40,6 +40,7 @@ config/icon="res://icon.png"
History="*res://globalScripts/history.gd" History="*res://globalScripts/history.gd"
PlayerCharacter="*res://globalScripts/PlayerCharacter.gd" PlayerCharacter="*res://globalScripts/PlayerCharacter.gd"
GameCurrent="*res://globalScripts/gameCurrent.gd"
[physics] [physics]

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://UserInterface/But_ChangeScene.tscn" type="PackedScene" id=1] [ext_resource path="res://UserInterface/But_ChangeScene.tscn" type="PackedScene" id=1]
[ext_resource path="res://screens/MoreOptions.gd" type="Script" id=2] [ext_resource path="res://screens/MoreOptions.gd" type="Script" id=2]
[ext_resource path="res://userInterface/But_ResumeGame.gd" type="Script" id=3]
[ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=6] [ext_resource path="res://assets/ui_controlNode_dark_theme.tres" type="Theme" id=6]
[node name="MoreOptions" type="Control"] [node name="MoreOptions" type="Control"]
@ -34,28 +35,31 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="But_ResumeGame" parent="VBoxContainer" instance=ExtResource( 1 )] [node name="But_ResumeGame" type="Button" parent="VBoxContainer"]
margin_right = 238.0 margin_right = 238.0
margin_bottom = 73.0 margin_bottom = 36.0
text = "Resume Game" text = "Resume Game"
next_scene_path = "res://gamePlay/Game.tscn" script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="But_ShowHistory" parent="VBoxContainer" instance=ExtResource( 1 )] [node name="But_ShowHistory" parent="VBoxContainer" instance=ExtResource( 1 )]
margin_top = 77.0 margin_top = 40.0
margin_right = 238.0 margin_right = 238.0
margin_bottom = 150.0 margin_bottom = 125.0
text = "Show History" text = "Show History"
next_scene_path = "res://gamePlay/Game.tscn" next_scene_path = "res://screens/MenuScreen.tscn"
[node name="But_Chat" parent="VBoxContainer" instance=ExtResource( 1 )] [node name="But_Chat" parent="VBoxContainer" instance=ExtResource( 1 )]
margin_top = 154.0 margin_top = 129.0
margin_right = 238.0 margin_right = 238.0
margin_bottom = 227.0 margin_bottom = 214.0
text = "Chat" text = "Chat"
next_scene_path = "res://Screens/MenuScreen.tscn" next_scene_path = "res://screens/MenuScreen.tscn"
[node name="But_MainMenu" parent="VBoxContainer" instance=ExtResource( 1 )] [node name="But_MainMenu" parent="VBoxContainer" instance=ExtResource( 1 )]
margin_top = 231.0 margin_top = 218.0
margin_right = 238.0 margin_right = 238.0
margin_bottom = 304.0 margin_bottom = 304.0
text = "Main Menu" text = "Main Menu"
@ -74,3 +78,5 @@ text = "Version: 0.0.0"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[connection signal="button_up" from="VBoxContainer/But_ResumeGame" to="VBoxContainer/But_ResumeGame" method="_on_But_ResumeGame_button_up"]

View File

@ -0,0 +1,13 @@
tool
extends Button
func _on_But_ResumeGame_button_up():
var root = get_node("/root")
var thisScene = get_node("/root/MoreOptions")
var gameSingleton = get_node("/root/GameCurrent")
var gameScene = gameSingleton.gameCurrent_scene
root.remove_child(thisScene)
thisScene.queue_free()
root.add_child(gameScene)