From baa4ee34d4b7085d39d5e23125fa9deda9b7f830 Mon Sep 17 00:00:00 2001 From: MacDugRPG <57243055+MacDugRPG@users.noreply.github.com> Date: Sun, 28 Aug 2022 15:30:38 -0400 Subject: [PATCH] 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. --- .../gamePlay/Game.gd | 4 +-- .../globalScripts/globalSaveInstance.gd | 28 ++++++++++++++--- .../globalScripts/playerSettingsTemplate.gd | 4 +-- .../screens/Character_Add.gd | 2 ++ .../screens/Character_Load.gd | 2 ++ .../screens/HistoryViewer.gd | 4 +-- .../screens/ImportCharacter.gd | 8 ++--- .../screens/MenuScreen.gd | 5 ++- .../screens/MoreOptions.gd | 4 +-- .../screens/PlayerSelection.gd | 4 +-- .../screens/SettingsMenuConfig.gd | 31 ++++++++++++------- .../screens/SettingsMenuControl.tscn | 15 ++++++--- 12 files changed, 74 insertions(+), 37 deletions(-) diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/gamePlay/Game.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/gamePlay/Game.gd index 1743714..118e916 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/gamePlay/Game.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/gamePlay/Game.gd @@ -5,6 +5,7 @@ extends Control 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 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" func _ready() -> void: - #DKM TEMP: for testing only -- this will be set in settings save_module() - theme=load("res://assets/ui_controlNode_dark_theme.tres") + theme=load(settings.themeFile) current_text.show() option_one.show() option_two.show() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/globalSaveInstance.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/globalSaveInstance.gd index 6cbbdd3..fce0913 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/globalSaveInstance.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/globalSaveInstance.gd @@ -4,8 +4,7 @@ extends Node var settingsInstance = PlayerSettingsTemplate.new() var settings_file = "user://PlayerPreferences.cfg" -# Called when the node enters the scene tree for the first time. -func _ready(): +func _ready() -> void: load_settings_file() #Config/ini: @@ -16,9 +15,30 @@ func load_settings_file(): # If the file didn't load, ignore it. if err != OK: return + #Preferences: settingsInstance.inputName = config.get_value("player_preferences", "player_name") 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 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" diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/playerSettingsTemplate.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/playerSettingsTemplate.gd index 156c2fd..acd3d60 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/playerSettingsTemplate.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/globalScripts/playerSettingsTemplate.gd @@ -15,9 +15,9 @@ var bVirtualKeyboard = false # Setting of 0 is Qwerty, Setting of 1 is Davorak, Setting of 2 is Alphabetical var visualKeyboardLayout = 0 - # 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(): pass diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Add.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Add.gd index 3458911..fc7960f 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Add.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Add.gd @@ -4,8 +4,10 @@ extends Control +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance func _ready() -> void: + theme=load(settings.themeFile) $Title/But_SaveChar.grab_focus() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Load.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Load.gd index 55297de..ad6681d 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Load.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/Character_Load.gd @@ -3,8 +3,10 @@ extends Control +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance func _ready() -> void: + theme=load(settings.themeFile) $Title/But_loadCharacter.grab_focus() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/HistoryViewer.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/HistoryViewer.gd index 2e72331..843b361 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/HistoryViewer.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/HistoryViewer.gd @@ -6,6 +6,7 @@ extends Control +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance onready var history_source = get_node("/root/History").historyScreensSingleton onready var current_history = $Background/MarginContainer/Rows/GameInfo/CurrentHistory #For zero-indexed array position: @@ -18,8 +19,7 @@ const InputResponse = preload("res://UserInterface/InputResponse.tscn") func _ready() -> void: - #DKM TEMP: for testing only -- this will be set in settings - theme=load("res://assets/ui_controlNode_dark_theme.tres") + theme=load(settings.themeFile) print("Loaded history array size is: " + str(history_source.output_history_array.size())) update_pager() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/ImportCharacter.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/ImportCharacter.gd index 047b68e..bcb752c 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/ImportCharacter.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/ImportCharacter.gd @@ -2,15 +2,15 @@ # Expanded for Import Character option extends Control + +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance + var charFilePath var a func _ready() -> void: - #DKM TEMP TODO: replace with settings Singleton theme value - #theme=load("res://assets/ui_controlNode_dark_theme.tres") - $But_ChangeScene.grab_focus() - + theme=load(settings.themeFile) func _on_Button_pressed(): $VBoxContainer2/VBoxContainer/FileDialog.popup() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MenuScreen.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MenuScreen.gd index 1d38f52..42aa2e9 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MenuScreen.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MenuScreen.gd @@ -3,10 +3,9 @@ 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. func _ready() -> void: - #DKM TEMP: for testing only -- this will be set for all scenes in settings - theme=load("res://assets/ui_controlNode_dark_theme.tres") + theme=load(settings.themeFile) $VBoxContainer/But_NewGame.grab_focus() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MoreOptions.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MoreOptions.gd index aa9b21b..95f1032 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MoreOptions.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/MoreOptions.gd @@ -3,9 +3,9 @@ extends Control +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance # Called when the node enters the scene tree for the first time. func _ready() -> void: - #DKM TEMP: for testing only -- this will be set in settings - theme=load("res://assets/ui_controlNode_dark_theme.tres") + theme=load(settings.themeFile) $VBoxContainer/But_ResumeGame.grab_focus() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/PlayerSelection.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/PlayerSelection.gd index 4a92014..6aa9b23 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/PlayerSelection.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/PlayerSelection.gd @@ -3,9 +3,9 @@ extends Control +onready var settings = get_node("/root/GlobalSaveInstance").settingsInstance # Called when the node enters the scene tree for the first time. func _ready() -> void: - #DKM TEMP: for testing only -- this will be set in settings - theme=load("res://assets/ui_controlNode_dark_theme.tres") + theme=load(settings.themeFile) $VBoxContainer/But_ChoosePlayer.grab_focus() diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuConfig.gd b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuConfig.gd index 9530e98..f9b192e 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuConfig.gd +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuConfig.gd @@ -41,7 +41,6 @@ onready var themeChoiceList = get_node('Panel/HBoxContainer/RootVboxVisualContro var iniFile = ConfigFile.new() func saveToInstance(): - #Save to Singleton, so saveFile does not need to be constantly read saveObject.settingsInstance.inputName = NameVar.text saveObject.settingsInstance.riskFactor = NRiskVar.value @@ -50,9 +49,15 @@ func saveToInstance(): saveObject.settingsInstance.bClosedCaptions = ClosedCaptionsVar.is_pressed() saveObject.settingsInstance.bdevConsole = ConsoleCommandVar.is_pressed() saveObject.settingsInstance.bVirtualKeyboard = bKeyboardEnabled.is_pressed() - saveObject.settingsInstance.visualKeyboardLayout = keyboardLayoutList.get_selected_items() - saveObject.settingsInstance.themeChoice = themeChoiceList.get_selected_items() - + var savedKeyboardItems = keyboardLayoutList.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(): @@ -71,7 +76,7 @@ func saveFile(): var keyboardSelection = savedKeyboardItems[0] - var savedThemeItems = keyboardLayoutList.get_selected_items() + var savedThemeItems = themeChoiceList.get_selected_items() var themeSelection = savedThemeItems[0] @@ -100,12 +105,13 @@ func _process(delta): print('saveFileRan') 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 NRiskVar.value = saveObject.settingsInstance.riskFactor - #themeChoiceList - - theme=load("res://assets/ui_controlNode_dark_theme.tres") + FontVar.value = saveObject.settingsInstance.fontSize + ClosedCaptionsVar.pressed = saveObject.settingsInstance.bClosedCaptions + ConsoleCommandVar.pressed = saveObject.settingsInstance.bdevConsole + bKeyboardEnabled.pressed = saveObject.settingsInstance.bVirtualKeyboard print(NameVar.get_path()) @@ -120,6 +126,9 @@ func _ready(): for i in range(2): 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) diff --git a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuControl.tscn b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuControl.tscn index 91a0422..585a71f 100644 --- a/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuControl.tscn +++ b/Phase2/Godot ===(Game Code)===/MergedDemo/Doug/bcirpg_mergedDemo_20220814A/screens/SettingsMenuControl.tscn @@ -177,6 +177,9 @@ margin_left = -77.5 margin_top = 30.0 margin_right = 77.5 margin_bottom = 120.0 +__meta__ = { +"_edit_use_anchors_": false +} [node name="Label" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"] margin_right = 155.0 @@ -294,24 +297,26 @@ margin_bottom = 99.0 auto_height = true [node name="HBoxBottomRow" type="HBoxContainer" parent="Panel"] -anchor_left = 0.5 -anchor_right = 0.5 +anchor_left = 0.500488 +anchor_right = 0.595215 margin_left = -48.5 margin_top = 200.0 margin_right = 48.5 margin_bottom = 225.0 +alignment = 1 __meta__ = { "_edit_use_anchors_": true } [node name="SaveButton" type="Button" parent="Panel/HBoxBottomRow"] -margin_right = 97.0 +margin_left = 24.0 +margin_right = 121.0 margin_bottom = 25.0 text = "Save Settings" [node name="But_ChangeScene" parent="Panel/HBoxBottomRow" instance=ExtResource( 3 )] -margin_left = 101.0 -margin_right = 146.0 +margin_left = 125.0 +margin_right = 170.0 margin_bottom = 25.0 text = "Back" next_scene_path = "res://screens/MenuScreen.tscn"