Settings implementation updates

Finishes merging of current settings to load all from file, update for display, save to singleton. Also adds currently hard-coded (in the GlobalSaveInstance) file name based on themes choice for use in all control nodes.

Applies that theme load to all current control nodes.
This commit is contained in:
MacDugRPG 2022-08-28 15:30:38 -04:00
parent 2c48b0a433
commit baa4ee34d4
12 changed files with 74 additions and 37 deletions

View File

@ -5,6 +5,7 @@
extends Control extends Control
onready var history_source = get_node("/root/History").historyScreensSingleton onready var history_source = get_node("/root/History").historyScreensSingleton
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
#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")
@ -26,9 +27,8 @@ onready var charSheet = $Con_charSheet/MarginContainer/VBoxContainer/CharacterSh
onready var module_map = "user://temp_map.save" onready var module_map = "user://temp_map.save"
func _ready() -> void: func _ready() -> void:
#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(settings.themeFile)
current_text.show() current_text.show()
option_one.show() option_one.show()
option_two.show() option_two.show()

View File

@ -4,8 +4,7 @@ extends Node
var settingsInstance = PlayerSettingsTemplate.new() var settingsInstance = PlayerSettingsTemplate.new()
var settings_file = "user://PlayerPreferences.cfg" var settings_file = "user://PlayerPreferences.cfg"
# Called when the node enters the scene tree for the first time. func _ready() -> void:
func _ready():
load_settings_file() load_settings_file()
#Config/ini: #Config/ini:
@ -16,9 +15,30 @@ func load_settings_file():
# If the file didn't load, ignore it. # If the file didn't load, ignore it.
if err != OK: if err != OK:
return return
#Preferences:
settingsInstance.inputName = config.get_value("player_preferences", "player_name") settingsInstance.inputName = config.get_value("player_preferences", "player_name")
settingsInstance.riskFactor = config.get_value("player_preferences", "risk_threshold") settingsInstance.riskFactor = config.get_value("player_preferences", "risk_threshold")
#Controls:
settingsInstance.fontSize = config.get_value("visual_controls", "font_size")
settingsInstance.brightness = config.get_value("visual_controls", "brightness")
#General Settings:
settingsInstance.volume = config.get_value("general_settings", "volume")
settingsInstance.bClosedCaptions = config.get_value("general_settings", "closed_captions")
settingsInstance.bdevConsole = config.get_value("general_settings", "dev_console")
#Keyboard:
settingsInstance.visualKeyboardLayout = config.get_value("virtual_keyboard", "keyboard_layout")
#Theme:
settingsInstance.themeChoiceInt = config.get_value("theme", "theme_selection")
load_themeFile()
#DKM TEMP: working #DKM TEMP: working
print("Input name loaded as: " + str(settingsInstance.inputName)) print("Input name loaded as: " + str(settingsInstance.inputName))
print("Risk loaded as: " + str(settingsInstance.riskFactor)) print("Theme loaded as: " + str(settingsInstance.themeFile))
func load_themeFile() -> void:
#DKM TEMP: this shouldn't be hard-coded:
if(settingsInstance.themeChoiceInt == 1):
settingsInstance.themeFile = "res://assets/ui_controlNode_light_theme.tres"
else:
settingsInstance.themeFile = "res://assets/ui_controlNode_dark_theme.tres"

View File

@ -15,9 +15,9 @@ var bVirtualKeyboard = false
# Setting of 0 is Qwerty, Setting of 1 is Davorak, Setting of 2 is Alphabetical # Setting of 0 is Qwerty, Setting of 1 is Davorak, Setting of 2 is Alphabetical
var visualKeyboardLayout = 0 var visualKeyboardLayout = 0
# Setting of 0 is dark, setting of 1 is light, and so on # Setting of 0 is dark, setting of 1 is light, and so on
var themeChoice = 0 var themeChoiceInt = 0
var themeFile = "res://assets/ui_controlNode_dark_theme.tres"
func _ready(): func _ready():
pass pass

View File

@ -4,8 +4,10 @@
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
func _ready() -> void: func _ready() -> void:
theme=load(settings.themeFile)
$Title/But_SaveChar.grab_focus() $Title/But_SaveChar.grab_focus()

View File

@ -3,8 +3,10 @@
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
func _ready() -> void: func _ready() -> void:
theme=load(settings.themeFile)
$Title/But_loadCharacter.grab_focus() $Title/But_loadCharacter.grab_focus()

View File

@ -6,6 +6,7 @@
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
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: #For zero-indexed array position:
@ -18,8 +19,7 @@ const InputResponse = preload("res://UserInterface/InputResponse.tscn")
func _ready() -> void: func _ready() -> void:
#DKM TEMP: for testing only -- this will be set in settings theme=load(settings.themeFile)
theme=load("res://assets/ui_controlNode_dark_theme.tres")
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() update_pager()

View File

@ -2,15 +2,15 @@
# Expanded for Import Character option # Expanded for Import Character option
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
var charFilePath var charFilePath
var a var a
func _ready() -> void: func _ready() -> void:
#DKM TEMP TODO: replace with settings Singleton theme value theme=load(settings.themeFile)
#theme=load("res://assets/ui_controlNode_dark_theme.tres")
$But_ChangeScene.grab_focus()
func _on_Button_pressed(): func _on_Button_pressed():
$VBoxContainer2/VBoxContainer/FileDialog.popup() $VBoxContainer2/VBoxContainer/FileDialog.popup()

View File

@ -3,10 +3,9 @@
extends Control extends Control
var settings_file = "user://PlayerPreferences.cfg" onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
#DKM TEMP: for testing only -- this will be set for all scenes in settings theme=load(settings.themeFile)
theme=load("res://assets/ui_controlNode_dark_theme.tres")
$VBoxContainer/But_NewGame.grab_focus() $VBoxContainer/But_NewGame.grab_focus()

View File

@ -3,9 +3,9 @@
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
#DKM TEMP: for testing only -- this will be set in settings theme=load(settings.themeFile)
theme=load("res://assets/ui_controlNode_dark_theme.tres")
$VBoxContainer/But_ResumeGame.grab_focus() $VBoxContainer/But_ResumeGame.grab_focus()

View File

@ -3,9 +3,9 @@
extends Control extends Control
onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
#DKM TEMP: for testing only -- this will be set in settings theme=load(settings.themeFile)
theme=load("res://assets/ui_controlNode_dark_theme.tres")
$VBoxContainer/But_ChoosePlayer.grab_focus() $VBoxContainer/But_ChoosePlayer.grab_focus()

View File

@ -41,7 +41,6 @@ onready var themeChoiceList = get_node('Panel/HBoxContainer/RootVboxVisualContro
var iniFile = ConfigFile.new() var iniFile = ConfigFile.new()
func saveToInstance(): func saveToInstance():
#Save to Singleton, so saveFile does not need to be constantly read #Save to Singleton, so saveFile does not need to be constantly read
saveObject.settingsInstance.inputName = NameVar.text saveObject.settingsInstance.inputName = NameVar.text
saveObject.settingsInstance.riskFactor = NRiskVar.value saveObject.settingsInstance.riskFactor = NRiskVar.value
@ -50,9 +49,15 @@ func saveToInstance():
saveObject.settingsInstance.bClosedCaptions = ClosedCaptionsVar.is_pressed() saveObject.settingsInstance.bClosedCaptions = ClosedCaptionsVar.is_pressed()
saveObject.settingsInstance.bdevConsole = ConsoleCommandVar.is_pressed() saveObject.settingsInstance.bdevConsole = ConsoleCommandVar.is_pressed()
saveObject.settingsInstance.bVirtualKeyboard = bKeyboardEnabled.is_pressed() saveObject.settingsInstance.bVirtualKeyboard = bKeyboardEnabled.is_pressed()
saveObject.settingsInstance.visualKeyboardLayout = keyboardLayoutList.get_selected_items() var savedKeyboardItems = keyboardLayoutList.get_selected_items()
saveObject.settingsInstance.themeChoice = themeChoiceList.get_selected_items() var keyboardSelection = savedKeyboardItems[0]
saveObject.settingsInstance.visualKeyboardLayout = keyboardSelection
var savedThemeItems = themeChoiceList.get_selected_items()
var themeSelection = savedThemeItems[0]
saveObject.settingsInstance.themeChoiceInt = themeSelection
#Trigger re-load of the file name
saveObject.load_settings_file()
theme=load(saveObject.settingsInstance.themeFile)
func saveFile(): func saveFile():
@ -71,7 +76,7 @@ func saveFile():
var keyboardSelection = savedKeyboardItems[0] var keyboardSelection = savedKeyboardItems[0]
var savedThemeItems = keyboardLayoutList.get_selected_items() var savedThemeItems = themeChoiceList.get_selected_items()
var themeSelection = savedThemeItems[0] var themeSelection = savedThemeItems[0]
@ -100,12 +105,13 @@ func _process(delta):
print('saveFileRan') print('saveFileRan')
func _ready(): func _ready():
#DKM TEMP: we need to set these to values from the file #Get the singleton's values for initial settings:
NameVar.text = saveObject.settingsInstance.inputName NameVar.text = saveObject.settingsInstance.inputName
NRiskVar.value = saveObject.settingsInstance.riskFactor NRiskVar.value = saveObject.settingsInstance.riskFactor
#themeChoiceList FontVar.value = saveObject.settingsInstance.fontSize
ClosedCaptionsVar.pressed = saveObject.settingsInstance.bClosedCaptions
theme=load("res://assets/ui_controlNode_dark_theme.tres") ConsoleCommandVar.pressed = saveObject.settingsInstance.bdevConsole
bKeyboardEnabled.pressed = saveObject.settingsInstance.bVirtualKeyboard
print(NameVar.get_path()) print(NameVar.get_path())
@ -120,6 +126,9 @@ func _ready():
for i in range(2): for i in range(2):
themeChoiceList.add_item(themeContents[i],null,true) themeChoiceList.add_item(themeContents[i],null,true)
keyboardLayoutList.select(0,true) keyboardLayoutList.select(saveObject.settingsInstance.visualKeyboardLayout,true)
themeChoiceList.select(0,true) themeChoiceList.select(saveObject.settingsInstance.themeChoiceInt,true)
#Load selected theme:
theme=load(saveObject.settingsInstance.themeFile)

View File

@ -177,6 +177,9 @@ margin_left = -77.5
margin_top = 30.0 margin_top = 30.0
margin_right = 77.5 margin_right = 77.5
margin_bottom = 120.0 margin_bottom = 120.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"] [node name="Label" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"]
margin_right = 155.0 margin_right = 155.0
@ -294,24 +297,26 @@ margin_bottom = 99.0
auto_height = true auto_height = true
[node name="HBoxBottomRow" type="HBoxContainer" parent="Panel"] [node name="HBoxBottomRow" type="HBoxContainer" parent="Panel"]
anchor_left = 0.5 anchor_left = 0.500488
anchor_right = 0.5 anchor_right = 0.595215
margin_left = -48.5 margin_left = -48.5
margin_top = 200.0 margin_top = 200.0
margin_right = 48.5 margin_right = 48.5
margin_bottom = 225.0 margin_bottom = 225.0
alignment = 1
__meta__ = { __meta__ = {
"_edit_use_anchors_": true "_edit_use_anchors_": true
} }
[node name="SaveButton" type="Button" parent="Panel/HBoxBottomRow"] [node name="SaveButton" type="Button" parent="Panel/HBoxBottomRow"]
margin_right = 97.0 margin_left = 24.0
margin_right = 121.0
margin_bottom = 25.0 margin_bottom = 25.0
text = "Save Settings" text = "Save Settings"
[node name="But_ChangeScene" parent="Panel/HBoxBottomRow" instance=ExtResource( 3 )] [node name="But_ChangeScene" parent="Panel/HBoxBottomRow" instance=ExtResource( 3 )]
margin_left = 101.0 margin_left = 125.0
margin_right = 146.0 margin_right = 170.0
margin_bottom = 25.0 margin_bottom = 25.0
text = "Back" text = "Back"
next_scene_path = "res://screens/MenuScreen.tscn" next_scene_path = "res://screens/MenuScreen.tscn"