History Array Pager Display

This update displays the history from singleton history array.
This commit is contained in:
MacDugRPG 2022-05-22 15:19:44 -04:00
parent 098854ec4a
commit 52b3564519
3 changed files with 55 additions and 32 deletions

View File

@ -1,5 +1,5 @@
#BUT_HISTORYPAGER: #BUT_HISTORYPAGER:
# Simply moves through array page -- should call the HistoryViewer script to display # Iterates the page number and calls HistoryViewer script to display
# stored page and response fro the history array # stored page and response fro the history array
# #
@ -7,11 +7,7 @@ extends Button
onready var historyViewerScript = get_node("/root/HistoryViewer") onready var historyViewerScript = get_node("/root/HistoryViewer")
#DKM TEMP: this needs refactoring -- too much being calculated as needed/repeated
func _on_But_HistoryPager_button_up() -> void: func _on_But_HistoryPager_button_up() -> void:
if(historyViewerScript.current_history_page_no < historyViewerScript.history_source.output_history_array.size()): historyViewerScript.update_pager()
historyViewerScript.current_history_page_no = historyViewerScript.current_history_page_no +1
else:
historyViewerScript.current_history_page_no = 0
print("Current page: " + str(historyViewerScript.current_history_page_no))

View File

@ -8,7 +8,9 @@ extends Control
onready var history_source = get_node("/root/History").historyScreensSingleton onready var history_source = get_node("/root/History").historyScreensSingleton
onready var current_history = $Background/MarginContainer/Rows/GameInfo/CurrentHistory onready var current_history = $Background/MarginContainer/Rows/GameInfo/CurrentHistory
#For zero-indexed array position:
onready var current_history_page_no = 0 onready var current_history_page_no = 0
onready var page_displayer = $Background/MarginContainer/Rows/ItemList/Page_Display
#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")
@ -18,23 +20,30 @@ const InputResponse = preload("res://UserInterface/InputResponse.tscn")
func _ready() -> void: 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
theme=load("res://assets/ui_controlNode_dark_theme.tres") theme=load("res://assets/ui_controlNode_dark_theme.tres")
#DKM_TEMP: display size of current history:
print("Loaded history array size is: " + str(history_source.output_history_array.size())) print("Loaded history array size is: " + str(history_source.output_history_array.size()))
update_pager()
#DKM TEMP:
#Handles input text # page_displayer.text = "1"
func create_response(response_text: String): # if(current_history.get_child_count() > 0):
var response = TextOutput.instance() # current_history.remove_child(current_history.get_child(0))
response.text = response_text # var opening_res = history_source.output_history_array[0]
add_response_to_game(response) # current_history.add_child(opening_res)
#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_display_to_game(response: Control):
if(current_history.get_child_count() > 0): if(current_history.get_child_count() > 0):
current_history.remove_child(current_history.get_child(0)) current_history.remove_child(current_history.get_child(0))
current_history.add_child(response) current_history.add_child(response)
func update_pager():
if(current_history_page_no >= history_source.output_history_array.size()):
current_history_page_no = 0
print("Current page: " + str(current_history_page_no))
add_display_to_game(history_source.output_history_array[current_history_page_no])
current_history_page_no = current_history_page_no +1
page_displayer.text = str(current_history_page_no)

View File

@ -17,7 +17,6 @@ __meta__ = {
[node name="Background" type="PanelContainer" parent="."] [node name="Background" type="PanelContainer" parent="."]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_right = -274.0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -25,7 +24,7 @@ __meta__ = {
[node name="MarginContainer" type="MarginContainer" parent="Background"] [node name="MarginContainer" type="MarginContainer" parent="Background"]
margin_left = 1.0 margin_left = 1.0
margin_top = 1.0 margin_top = 1.0
margin_right = 749.0 margin_right = 1023.0
margin_bottom = 599.0 margin_bottom = 599.0
custom_constants/margin_right = 20 custom_constants/margin_right = 20
custom_constants/margin_top = 10 custom_constants/margin_top = 10
@ -35,12 +34,12 @@ custom_constants/margin_bottom = 20
[node name="Rows" type="VBoxContainer" parent="Background/MarginContainer"] [node name="Rows" type="VBoxContainer" parent="Background/MarginContainer"]
margin_left = 20.0 margin_left = 20.0
margin_top = 10.0 margin_top = 10.0
margin_right = 728.0 margin_right = 1002.0
margin_bottom = 578.0 margin_bottom = 578.0
custom_constants/separation = 10 custom_constants/separation = 10
[node name="ItemList" type="ItemList" parent="Background/MarginContainer/Rows"] [node name="ItemList" type="ItemList" parent="Background/MarginContainer/Rows"]
margin_right = 708.0 margin_right = 982.0
margin_bottom = 40.0 margin_bottom = 40.0
rect_min_size = Vector2( 0, 40 ) rect_min_size = Vector2( 0, 40 )
@ -49,29 +48,48 @@ text = "More Options"
next_scene_path = "res://screens/MoreOptions.tscn" next_scene_path = "res://screens/MoreOptions.tscn"
[node name="But_HistoryPager" type="Button" parent="Background/MarginContainer/Rows/ItemList"] [node name="But_HistoryPager" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
anchor_left = 1.0 anchor_left = 0.5
anchor_top = 0.5 anchor_right = 0.5
anchor_right = 1.0 margin_left = -84.0
anchor_bottom = 0.5 margin_right = 84.0
margin_left = -168.0 margin_bottom = 36.0
margin_top = -18.0
margin_bottom = 18.0
text = "History Pager" text = "History Pager"
script = ExtResource( 4 ) script = ExtResource( 4 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="Label" type="Label" parent="Background/MarginContainer/Rows/ItemList"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -194.94
margin_top = -1.12247
margin_right = -81.9397
margin_bottom = 23.8775
text = "History Page:"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Page_Display" type="Label" parent="Background/MarginContainer/Rows/ItemList"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -40.0
margin_bottom = 25.0
__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 = 982.0
margin_bottom = 568.0 margin_bottom = 568.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="CurrentText" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo"] [node name="CurrentHistory" type="VBoxContainer" parent="Background/MarginContainer/Rows/GameInfo"]
margin_left = 1.0 margin_left = 1.0
margin_top = 1.0 margin_top = 1.0
margin_right = 707.0 margin_right = 981.0
margin_bottom = 517.0 margin_bottom = 517.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3