Adds history paging

This adds tab+enter based history paging to go with tab+enter -based navigation.

Code needs cleanup before any kind of merging, but functions.
This commit is contained in:
MacDugRPG 2022-01-23 15:18:08 -05:00
parent be8d1addee
commit 571ebf705c
12 changed files with 214 additions and 66 deletions

View File

@ -0,0 +1,34 @@
tool
extends Button
onready var game_history_array = get_node("../../../../../").history_array
var is_history = false
func _on_But_History_button_up():
var history_pager_button = get_node("../../ItemList/But_History_Page")
var history_rows_node = get_node("../../GameInfo/HistoryRows")
var current_text_node = get_node("../../GameInfo/CurrentText")
var option_one = get_node("../../InputArea/VBoxContainer/option1")
var option_two = get_node("../../InputArea/VBoxContainer/option2")
var option_three = get_node("../../InputArea/VBoxContainer/option3")
if(!is_history):
history_rows_node.add_child(game_history_array[0])
history_pager_button.show()
history_rows_node.show()
current_text_node.hide()
option_one.hide()
option_two.hide()
option_three.hide()
is_history = true
else:
history_pager_button.hide()
history_rows_node.hide()
current_text_node.show()
option_one.show()
option_two.show()
option_three.show()
is_history = false

View File

@ -0,0 +1,12 @@
extends Button
onready var game_history_array = get_node("../../../../../").history_array
var current_page = 0
func _on_But_History_Page_button_up():
var history_rows_node = get_node("../../GameInfo/HistoryRows")
current_page += 1
history_rows_node.remove_child(history_rows_node.get_child(0))
history_rows_node.add_child(game_history_array[current_page])

View File

@ -11,6 +11,8 @@ func initialize(starting_locale) -> String:
current_opt1 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option1") current_opt1 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option1")
current_opt2 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option2") current_opt2 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option2")
current_opt3 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option3") current_opt3 = get_node("../Background/MarginContainer/Rows/InputArea/VBoxContainer/option3")
current_opt1.grab_focus()
return change_room(starting_locale) return change_room(starting_locale)
#Function that loads response from the option string chosen #Function that loads response from the option string chosen

View File

@ -3,31 +3,38 @@ extends Control
#Abstract class we instance when wanted in game as child of HistoryReference #Abstract class we instance when wanted in game as child of HistoryReference
const TextOutput = preload("res://UserInterface/Response.tscn") const TextOutput = preload("res://UserInterface/Response.tscn")
const InputResponse = preload("res://UserInterface/InputResponse.tscn") const InputResponse = preload("res://UserInterface/InputResponse.tscn")
#Limit the length of our history:
var max_scroll_length := 0 #TODO: offload this to file
#For storing history selections
var output_history_singleton = OutputHistory.new()
var history_array = output_history_singleton.output_history_array
#TODO: change 'HistoryRows' to better name for current use
var history_screens_array = Array()
onready var command_processor = $CommandProcessor onready var command_processor = $CommandProcessor
onready var history_rows = $Background/MarginContainer/Rows/GameInfo/ScrollContainer/HistoryRows onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
onready var scroll = $Background/MarginContainer/Rows/GameInfo/ScrollContainer onready var history_rows = $Background/MarginContainer/Rows/GameInfo/HistoryRows
onready var scrollbar = scroll.get_v_scrollbar() 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_two= $Background/MarginContainer/Rows/InputArea/VBoxContainer/option2
onready var option_three = $Background/MarginContainer/Rows/InputArea/VBoxContainer/option3
#Ensure that the latest added input is in focus on scroll
func _ready() -> void: func _ready() -> void:
scrollbar.connect("changed", self, "handle_scrollbar_changed") history_pager.hide()
max_scroll_length = scrollbar.max_value history_rows.hide()
current_text.show()
option_one.show()
option_two.show()
option_three.show()
create_response("The game has begun! You can select from the available options below.") create_response("The game has begun! You can select from the available options below.")
var starting_locale_response = command_processor.initialize(locale_manager.get_child(0)) var starting_locale_response = command_processor.initialize(locale_manager.get_child(0))
create_response(starting_locale_response) create_response(starting_locale_response)
func handle_scrollbar_changed():
if max_scroll_length != scrollbar.max_value:
max_scroll_length = scrollbar.max_value
scroll.scroll_vertical = max_scroll_length
#Below temporarily takes user selection and appends it to responses; adding new isntances #Below temporarily takes user selection and appends it to responses; adding new isntances
# of our input row with an input and response pair for each # of our input row with an input and response pair for each
func handleUserInput(user_choice: String) -> void: func handleUserInput(user_choice: String) -> void:
@ -45,7 +52,10 @@ func create_response(response_text: String):
func add_response_to_game(response: Control): func add_response_to_game(response: Control):
history_rows.add_child(response) var response_history = response.duplicate()
history_array.append(response_history)
current_text.remove_child(current_text.get_child(0))
current_text.add_child(response)
func _on_option1_button_down() -> void: func _on_option1_button_down() -> void:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=12 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://Game.gd" type="Script" id=2] [ext_resource path="res://Game.gd" type="Script" id=2]
@ -6,6 +6,8 @@
[ext_resource path="res://CommandProcessor.gd" type="Script" id=4] [ext_resource path="res://CommandProcessor.gd" type="Script" id=4]
[ext_resource path="res://Locale.tscn" type="PackedScene" id=5] [ext_resource path="res://Locale.tscn" type="PackedScene" id=5]
[ext_resource path="res://LocaleManager.gd" type="Script" id=6] [ext_resource path="res://LocaleManager.gd" type="Script" id=6]
[ext_resource path="res://But_History.gd" type="Script" id=7]
[ext_resource path="res://But_History_Page.gd" type="Script" id=8]
[sub_resource type="StyleBoxFlat" id=1] [sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.117647, 0.117647, 0.117647, 1 ) bg_color = Color( 0.117647, 0.117647, 0.117647, 1 )
@ -86,27 +88,50 @@ margin_bottom = 30.0
text = "Menu" text = "Menu"
next_scene_path = "res://Screens/MenuScreen.tscn" next_scene_path = "res://Screens/MenuScreen.tscn"
[node name="But_History" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
margin_left = 96.0
margin_right = 167.0
margin_bottom = 33.0
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 = 33.0
text = "History 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 = 984.0 margin_right = 984.0
margin_bottom = 436.0 margin_bottom = 418.0
size_flags_vertical = 3 size_flags_vertical = 3
custom_styles/panel = SubResource( 2 ) custom_styles/panel = SubResource( 2 )
[node name="ScrollContainer" type="ScrollContainer" parent="Background/MarginContainer/Rows/GameInfo"] [node name="CurrentText" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo"]
margin_right = 984.0 margin_right = 984.0
margin_bottom = 386.0 margin_bottom = 368.0
scroll_horizontal_enabled = false size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 20
[node name="HistoryRows" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo/ScrollContainer"] [node name="HistoryRows" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo"]
margin_right = 984.0 margin_right = 984.0
margin_bottom = 386.0 margin_bottom = 368.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
custom_constants/separation = 20 custom_constants/separation = 20
[node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Rows"] [node name="InputArea" type="PanelContainer" parent="Background/MarginContainer/Rows"]
margin_top = 446.0 margin_top = 428.0
margin_right = 984.0 margin_right = 984.0
margin_bottom = 570.0 margin_bottom = 570.0
rect_min_size = Vector2( 0, 120 ) rect_min_size = Vector2( 0, 120 )
@ -114,31 +139,34 @@ custom_styles/panel = SubResource( 3 )
[node name="VBoxContainer" type="VBoxContainer" parent="Background/MarginContainer/Rows/InputArea"] [node name="VBoxContainer" type="VBoxContainer" parent="Background/MarginContainer/Rows/InputArea"]
margin_right = 984.0 margin_right = 984.0
margin_bottom = 124.0 margin_bottom = 142.0
custom_constants/separation = 5 custom_constants/separation = 5
[node name="option1" type="LinkButton" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"] [node name="option1" type="Button" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"]
margin_right = 984.0 margin_right = 984.0
margin_bottom = 38.0 margin_bottom = 44.0
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
text = "Option 1" text = "Option 1"
align = 0
[node name="option2" type="LinkButton" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"] [node name="option2" type="Button" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"]
margin_top = 43.0 margin_top = 49.0
margin_right = 984.0 margin_right = 984.0
margin_bottom = 81.0 margin_bottom = 93.0
focus_mode = 2
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
text = "Option 2" text = "Option 2"
align = 0
[node name="option3" type="LinkButton" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"] [node name="option3" type="Button" parent="Background/MarginContainer/Rows/InputArea/VBoxContainer"]
margin_top = 86.0 margin_top = 98.0
margin_right = 984.0 margin_right = 984.0
margin_bottom = 124.0 margin_bottom = 142.0
focus_mode = 2
custom_fonts/font = ExtResource( 3 ) custom_fonts/font = ExtResource( 3 )
text = "Option 3" text = "Option 3"
align = 0
[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_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,6 @@
extends Control
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$VBoxContainer/But_NewGame.grab_focus()

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=7 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://UserInterface/But_ChangeScene.tscn" type="PackedScene" id=1]
[ext_resource path="res://Screens/MenuScreen.gd" type="Script" id=2]
[ext_resource path="res://UserInterface/Title.tscn" type="PackedScene" id=5] [ext_resource path="res://UserInterface/Title.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/background_demo.png" type="Texture" id=7] [ext_resource path="res://assets/background_demo.png" type="Texture" id=7]
[ext_resource path="res://assets/ui_theme.tres" type="Theme" id=8] [ext_resource path="res://assets/ui_theme.tres" type="Theme" id=8]
@ -11,6 +12,7 @@
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
theme = ExtResource( 8 ) theme = ExtResource( 8 )
script = ExtResource( 2 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }

View File

@ -19,26 +19,39 @@ func _get_configuration_warning() -> String:
return "next_scene_path must be set for this button to work" if next_scene_path == "" else "" return "next_scene_path must be set for this button to work" if next_scene_path == "" else ""
#CONFIG/INI SAVE:
func _saveSettings(inputSettings : String, riskFactor : String) -> void: func _saveSettings(inputSettings : String, riskFactor : String) -> void:
var player_settings = get_node("/root/PlayerSettings") var player_settings = get_node("/root/PlayerSettings")
player_settings.playerSettingsSingleton.inputName = inputSettings player_settings.playerSettingsSingleton.inputName = inputSettings
player_settings.playerSettingsSingleton.riskFactor = riskFactor player_settings.playerSettingsSingleton.riskFactor = riskFactor
#Temp: var config = ConfigFile.new()
var temp_manual_JSON = {
"playerSettingsTemplate": {
"inputName": inputSettings,
"riskFactor": riskFactor
}
}
#Save to file (JSON for now) config.set_value("Temp player","InputSettings", inputSettings)
var settings_file = "user://testPlayerSettings.sav" config.set_value("Temp player","RiskFactor", riskFactor)
var file = File.new()
if file.open(settings_file, File.WRITE) != 0: config.save("user://settings.cfg")
print("Cannot write temporary file to: " + settings_file)
else: #JSON SAVE:
file.store_line(to_json(temp_manual_JSON)) #func _saveSettings(inputSettings : String, riskFactor : String) -> void:
file.close() # var player_settings = get_node("/root/PlayerSettings")
# player_settings.playerSettingsSingleton.inputName = inputSettings
# player_settings.playerSettingsSingleton.riskFactor = riskFactor
# #Temp:
# var temp_manual_JSON = {
# "playerSettingsTemplate": {
# "inputName": inputSettings,
# "riskFactor": riskFactor
# }
# }
#
# #Save to file (JSON for now)
# var settings_file = "user://testPlayerSettings.sav"
# var file = File.new()
# if file.open(settings_file, File.WRITE) != 0:
# print("Cannot write temporary file to: " + settings_file)
# else:
# file.store_line(to_json(temp_manual_JSON))
# file.close()
#****This save Settings functions as designed; but modified to work with alternate approach of loading #****This save Settings functions as designed; but modified to work with alternate approach of loading

View File

@ -0,0 +1,9 @@
tool
extends Button
onready var history_rows = $Background/MarginContainer/Rows/GameInfo/ScrollContainer/HistoryRows
onready var current_text = $Background/MarginContainer/Rows/GameInfo/CurrentText
func _on_But_History_button_up():
print("History button pressed - temp")

View File

@ -0,0 +1,4 @@
extends Node
class_name OutputHistory
var output_history_array = Array()

View File

@ -4,27 +4,49 @@
extends Node extends Node
var settings_file = "user://testPlayerSettings.sav" #DKM TEMP: JSON:
#var settings_file = "user://testPlayerSettings.sav"
#DKM TEMP: TO DO: constant:
var settings_file = "user://settings.cfg"
var playerSettingsSingleton = PlayerSettingsTemplate.new() var playerSettingsSingleton = PlayerSettingsTemplate.new()
func _ready() -> void: func _ready() -> void:
load_settings_file() load_settings_file()
#Config/ini:
func load_settings_file():
var config = ConfigFile.new()
# Load data from a file.
var err = config.load(settings_file)
# If the file didn't load, ignore it.
if err != OK:
return
for player in config.get_sections():
var inputName = config.get_value(player, "InputSettings")
var riskFactor = config.get_value(player, "RiskFactor")
print("Input name loaded as: " + inputName)
playerSettingsSingleton.inputName = inputName
playerSettingsSingleton.riskFactor = riskFactor
#Using JSON: #Using JSON:
#DKM TEMP: manual JSON parsing is most certainly not the way to go -- temp testing these #DKM TEMP: manual JSON parsing is most certainly not the way to go -- temp testing these
# are saved and loaded correctly. # are saved and loaded correctly.
func load_settings_file(): #func load_settings_file():
var file = File.new() # var file = File.new()
file.open(settings_file, file.READ) # file.open(settings_file, file.READ)
var text = file.get_as_text() # var text = file.get_as_text()
var parsedText = parse_json(text) # var parsedText = parse_json(text)
if(parsedText != null): # if(parsedText != null):
print("Input name loaded as: " + parsedText.playerSettingsTemplate.inputName) # print("Input name loaded as: " + parsedText.playerSettingsTemplate.inputName)
playerSettingsSingleton.inputName = parsedText.playerSettingsTemplate.inputName # playerSettingsSingleton.inputName = parsedText.playerSettingsTemplate.inputName
playerSettingsSingleton.riskFactor = parsedText.playerSettingsTemplate.riskFactor # playerSettingsSingleton.riskFactor = parsedText.playerSettingsTemplate.riskFactor
else: # else:
print("No previously existing player settings file found") # print("No previously existing player settings file found")
#
#DKM TEMP: #DKM TEMP:
#****THIS LOADS a string successfully, but not objects #****THIS LOADS a string successfully, but not objects
#func _loadSettings() -> void: #func _loadSettings() -> void:

View File

@ -15,12 +15,18 @@ _global_script_classes=[ {
"path": "res://Locale.gd" "path": "res://Locale.gd"
}, { }, {
"base": "Node", "base": "Node",
"class": "OutputHistory",
"language": "GDScript",
"path": "res://globalScripts/outputHistory.gd"
}, {
"base": "Node",
"class": "PlayerSettingsTemplate", "class": "PlayerSettingsTemplate",
"language": "GDScript", "language": "GDScript",
"path": "res://globalScripts/playerSettingsTemplate.gd" "path": "res://globalScripts/playerSettingsTemplate.gd"
} ] } ]
_global_script_class_icons={ _global_script_class_icons={
"Locale": "", "Locale": "",
"OutputHistory": "",
"PlayerSettingsTemplate": "" "PlayerSettingsTemplate": ""
} }