Merged Demo: adding settings

Settings implementation is in progress. Currently loads and displays from expected user://PlayerPreferences.cfg at application start, but just the inputName and riskFactor.
This commit is contained in:
MacDugRPG 2022-08-21 16:24:19 -04:00
parent c9b4e38def
commit a241a73b2f
9 changed files with 510 additions and 5 deletions

View File

@ -53,6 +53,7 @@ margin_bottom = -606.384
locale_name = "the island woods"
option1 = "Go: south back to the beach"
option2 = "Go: north deeper in"
option3 = "Examine: the woods"
[node name="Loc_WoodsA2" parent="LocaleManager" instance=ExtResource( 5 )]
margin_left = 509.439
@ -63,6 +64,7 @@ locale_name = "deeper into the woods"
locale_description = "The woods are very thick. You feel like someone -- or something, may be watching you."
option1 = "Go: south back in the direction of the beach"
option2 = "Go: east into the thicket"
option3 = "Rest: set a camp here"
[node name="Loc_WoodsA3" parent="LocaleManager" instance=ExtResource( 5 )]
margin_left = 882.439
@ -81,6 +83,8 @@ margin_right = 1128.44
margin_bottom = -1161.38
locale_name = "a cliff top"
option1 = "Go: south back to the clearing "
option2 = "Rest: set a camp here"
option3 = "Examine: the cliff"
[node name="Background" type="PanelContainer" parent="."]
anchor_right = 1.0
@ -113,7 +117,7 @@ margin_bottom = 40.0
rect_min_size = Vector2( 0, 40 )
[node name="But_MoreOptions" type="Button" parent="Background/MarginContainer/Rows/ItemList"]
margin_right = 170.0
margin_right = 197.0
margin_bottom = 36.0
text = "More Options"
script = ExtResource( 9 )
@ -269,8 +273,7 @@ margin_top = 44.0
margin_right = 290.0
margin_bottom = 194.0
size_flags_vertical = 3
text = "Char1: What do you think?
Char2: Huh? About what?
text = "Nothing yet
"
readonly = true
__meta__ = {

View File

@ -0,0 +1,24 @@
extends Node
# Declare new settings template object
var settingsInstance = PlayerSettingsTemplate.new()
var settings_file = "user://PlayerPreferences.cfg"
# Called when the node enters the scene tree for the first time.
func _ready():
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
settingsInstance.inputName = config.get_value("player_preferences", "player_name")
settingsInstance.riskFactor = config.get_value("player_preferences", "risk_threshold")
#DKM TEMP: working
print("Input name loaded as: " + str(settingsInstance.inputName))
print("Risk loaded as: " + str(settingsInstance.riskFactor))

View File

@ -0,0 +1,26 @@
extends Node
class_name PlayerSettingsTemplate
# Declare Setting Options, to be used inside of the settings menu
var inputName = "none"
var riskFactor = 0
var brightness = 3
var fontSize = 11
var volume = 6
var bClosedCaptions = true
var bdevConsole = false
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
func _ready():
pass

View File

@ -19,6 +19,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://userInterface/Locale.gd"
}, {
"base": "Node",
"class": "PlayerSettingsTemplate",
"language": "GDScript",
"path": "res://globalScripts/playerSettingsTemplate.gd"
}, {
"base": "Resource",
"class": "playerCharacterTemplate",
"language": "GDScript",
@ -27,6 +32,7 @@ _global_script_classes=[ {
_global_script_class_icons={
"HistoryScreensTemplateSingleton": "",
"Locale": "",
"PlayerSettingsTemplate": "",
"playerCharacterTemplate": ""
}
@ -41,6 +47,7 @@ config/icon="res://icon.png"
History="*res://globalScripts/history.gd"
PlayerCharacter="*res://globalScripts/PlayerCharacter.gd"
GameCurrent="*res://globalScripts/gameCurrent.gd"
GlobalSaveInstance="*res://globalScripts/globalSaveInstance.gd"
[physics]

View File

@ -44,6 +44,8 @@ margin_bottom = 40.0
rect_min_size = Vector2( 0, 40 )
[node name="But_ChangeScene" parent="Background/MarginContainer/Rows/ItemList" instance=ExtResource( 2 )]
margin_right = 200.0
margin_bottom = 36.0
text = "More Options"
next_scene_path = "res://screens/MoreOptions.tscn"
@ -51,7 +53,7 @@ next_scene_path = "res://screens/MoreOptions.tscn"
anchor_left = 0.5
anchor_right = 0.5
margin_left = -84.0
margin_right = 84.0
margin_right = 115.0
margin_bottom = 36.0
text = "History Pager"
script = ExtResource( 4 )

View File

@ -3,6 +3,7 @@
extends Control
var settings_file = "user://PlayerPreferences.cfg"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:

View File

@ -80,7 +80,7 @@ margin_top = 223.0
margin_right = 238.0
margin_bottom = 264.0
text = "Settings"
next_scene_path = "res://Screens/Settings_temp.tscn"
next_scene_path = "res://Screens/SettingsMenuControl.tscn"
[node name="But_Quit" parent="VBoxContainer" instance=ExtResource( 10 )]
margin_top = 268.0

View File

@ -0,0 +1,125 @@
extends Control
# https://stackoverflow.com/a/65774028
# Be Sure to make these Vars as OnReadys; you can read up on it here.
# Items to Fill the dropdown Lists
onready var keyboardContents = ["Qwerty", "Dvorak", "Alphabetical"]
onready var themeContents = ["White on Black", "Black on White"]
onready var saveObject = get_node('/root/GlobalSaveInstance')
#res://SettingsMenuControl.tscn
# Vars For UI Widgets
onready var NameVar = get_node('Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/DisplayNameLineEdit')
onready var NRiskVar = get_node('Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/VBoxRiskFactor/RiskSlider')
onready var FontVar = get_node("Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox/FontSizeSlider")
onready var BrightnessVar = get_node('Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox/BrightnessSlider')
onready var VolumeVar = get_node("Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/VolumeSlider")
onready var ClosedCaptionsVar = get_node('Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxClosedCaptions/ClosedCaptionsCheckBox')
onready var ConsoleCommandVar = get_node('Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxDevConsole/DevConsoleCheckbox')
onready var saveButton = get_node("Panel/HBoxBottomRow/SaveButton")
onready var bKeyboardEnabled = get_node("Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/HBoxVirtualKeyboardEnabled/VisualKeyboardCheckBox")
onready var keyboardLayoutList = get_node('Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/LayoutItemList')
onready var themeChoiceList = get_node('Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/ThemeItemList')
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
saveObject.settingsInstance.fontSize = FontVar.value
saveObject.settingsInstance.volume = VolumeVar.value
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()
func saveFile():
iniFile.set_value("player_preferences", "player_name", NameVar.text)
iniFile.set_value("player_preferences", "risk_threshold", NRiskVar.value)
iniFile.set_value("visual_controls", "font_size", FontVar.value)
iniFile.set_value("visual_controls", "brightness", BrightnessVar.value)
iniFile.set_value("general_settings", "volume", VolumeVar.value)
iniFile.set_value("general_settings", "closed_captions", ClosedCaptionsVar.is_pressed())
iniFile.set_value("general_settings", "dev_console", ConsoleCommandVar.is_pressed())
print(keyboardLayoutList.get_selected_items())
var savedKeyboardItems = keyboardLayoutList.get_selected_items()
var keyboardSelection = savedKeyboardItems[0]
var savedThemeItems = keyboardLayoutList.get_selected_items()
var themeSelection = savedThemeItems[0]
print(typeof(keyboardSelection))
iniFile.set_value("virtual_keyboard", "keyboard_layout", keyboardSelection)
iniFile.set_value("theme", "theme_selection", themeSelection)
iniFile.save("user://PlayerPreferences.cfg")
#DKM TEMP: can this be done at singleton, initial load level instead of here?
func loadFile():
pass
func _process(delta):
if saveButton.pressed == true:
if NameVar.text == "":
print("Please input a name")
if NameVar.text != "":
# Save to the template instance
saveToInstance()
saveFile()
print('saveFileRan')
func _ready():
#DKM TEMP: we need to set these to values from the file
NameVar.text = saveObject.settingsInstance.inputName
NRiskVar.value = saveObject.settingsInstance.riskFactor
#themeChoiceList
theme=load("res://assets/ui_controlNode_dark_theme.tres")
print(NameVar.get_path())
# Init Keyboard Layout List
for i in range(3):
keyboardLayoutList.add_item(keyboardContents[i],null,true)
keyboardLayoutList.select(0,true)
# Init Theme Choice List
for i in range(2):
themeChoiceList.add_item(themeContents[i],null,true)
keyboardLayoutList.select(0,true)
themeChoiceList.select(0,true)

View File

@ -0,0 +1,317 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://screens/SettingsMenuConfig.gd" type="Script" id=1]
[ext_resource path="res://assets/liberation_serif.tres" type="DynamicFont" id=2]
[ext_resource path="res://userInterface/But_ChangeScene.tscn" type="PackedScene" id=3]
[sub_resource type="Theme" id=1]
default_font = ExtResource( 2 )
[node name="Control" type="Control"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -512.0
margin_top = -300.0
margin_right = 512.0
margin_bottom = 300.0
theme = SubResource( 1 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Panel" type="Panel" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -512.0
margin_top = -302.0
margin_right = 512.0
margin_bottom = 298.0
rect_pivot_offset = Vector2( -276, 469 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="Panel"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -298.5
margin_right = 298.5
margin_bottom = 19.0
custom_constants/separation = 60
alignment = 1
[node name="RootVboxVisualControls" type="VBoxContainer" parent="Panel/HBoxContainer"]
margin_right = 99.0
margin_bottom = 19.0
[node name="VisualControlsLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls"]
margin_right = 99.0
margin_bottom = 19.0
text = "Visual Controls"
[node name="VisualControlsVBox" type="VBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -77.5
margin_top = 30.0
margin_right = 77.5
margin_bottom = 52.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxFontSize" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox"]
margin_right = 155.0
margin_bottom = 19.0
[node name="FontLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox/HBoxFontSize"]
margin_right = 64.0
margin_bottom = 19.0
text = "Font Size:"
[node name="FontSizeSlider" type="HSlider" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox"]
margin_top = 23.0
margin_right = 155.0
margin_bottom = 39.0
min_value = 1.0
max_value = 5.0
value = 5.0
rounded = true
tick_count = 10
ticks_on_borders = true
[node name="BrightnessLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox"]
margin_top = 43.0
margin_right = 155.0
margin_bottom = 62.0
text = "Brightness:"
[node name="BrightnessSlider" type="HSlider" parent="Panel/HBoxContainer/RootVboxVisualControls/VisualControlsLabel/VisualControlsVBox"]
margin_top = 66.0
margin_right = 155.0
margin_bottom = 82.0
min_value = 1.0
max_value = 5.0
value = 5.0
rounded = true
tick_count = 10
ticks_on_borders = true
[node name="RootVboxPlayerPreferences" type="VBoxContainer" parent="Panel/HBoxContainer"]
margin_left = 159.0
margin_right = 276.0
margin_bottom = 19.0
[node name="Label" type="Label" parent="Panel/HBoxContainer/RootVboxPlayerPreferences"]
margin_right = 117.0
margin_bottom = 19.0
text = "Player Preferances"
[node name="VBoxPlayerPreferances" type="VBoxContainer" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label"]
margin_left = -18.5
margin_top = 30.0
margin_right = 126.5
margin_bottom = 125.0
[node name="HBoxDisplayName" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances"]
margin_right = 145.0
margin_bottom = 19.0
[node name="DisplayNameLabel" type="Label" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/HBoxDisplayName"]
margin_right = 95.0
margin_bottom = 19.0
text = "Display Name:"
[node name="DisplayNameLineEdit" type="LineEdit" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances"]
margin_top = 23.0
margin_right = 145.0
margin_bottom = 52.0
[node name="VBoxRiskFactor" type="VBoxContainer" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances"]
margin_top = 56.0
margin_right = 145.0
margin_bottom = 95.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxRiskFactor" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/VBoxRiskFactor"]
margin_right = 145.0
margin_bottom = 19.0
[node name="RiskFactorLabel" type="Label" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/VBoxRiskFactor/HBoxRiskFactor"]
margin_right = 145.0
margin_bottom = 19.0
text = "Risk Factor Threshold:"
[node name="RiskSlider" type="HSlider" parent="Panel/HBoxContainer/RootVboxPlayerPreferences/Label/VBoxPlayerPreferances/VBoxRiskFactor"]
margin_top = 23.0
margin_right = 145.0
margin_bottom = 39.0
min_value = 1.0
max_value = 5.0
value = 5.0
rounded = true
tick_count = 10
ticks_on_borders = true
[node name="RootVboxGeneralSettings" type="VBoxContainer" parent="Panel/HBoxContainer"]
margin_left = 336.0
margin_right = 440.0
margin_bottom = 19.0
[node name="GeneralSettingsLabel" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings"]
margin_right = 104.0
margin_bottom = 19.0
text = "General Settings"
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -77.5
margin_top = 30.0
margin_right = 77.5
margin_bottom = 120.0
[node name="Label" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"]
margin_right = 155.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 62, 14 )
text = "Volume:"
[node name="VolumeSlider" type="HSlider" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"]
margin_top = 23.0
margin_right = 155.0
margin_bottom = 39.0
max_value = 10.0
rounded = true
tick_count = 10
ticks_on_borders = true
[node name="HBoxClosedCaptions" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"]
margin_top = 43.0
margin_right = 155.0
margin_bottom = 70.0
[node name="ClosedCaptionsLabel" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxClosedCaptions"]
margin_top = 4.0
margin_right = 108.0
margin_bottom = 23.0
text = "Closed Captions:"
[node name="ClosedCaptionsCheckBox" type="CheckBox" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxClosedCaptions"]
margin_left = 112.0
margin_right = 136.0
margin_bottom = 27.0
[node name="HBoxDevConsole" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer"]
margin_top = 74.0
margin_right = 155.0
margin_bottom = 101.0
[node name="DevConsoleLabel" type="Label" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxDevConsole"]
margin_top = 4.0
margin_right = 126.0
margin_bottom = 23.0
text = "Developer Console:"
[node name="DevConsoleCheckbox" type="CheckBox" parent="Panel/HBoxContainer/RootVboxGeneralSettings/GeneralSettingsLabel/VBoxContainer/HBoxDevConsole"]
margin_left = 130.0
margin_right = 154.0
margin_bottom = 27.0
[node name="RootVboxVisualControls2" type="VBoxContainer" parent="Panel/HBoxContainer"]
margin_left = 500.0
margin_right = 599.0
margin_bottom = 19.0
[node name="Label2" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls2"]
margin_right = 99.0
margin_bottom = 19.0
text = "Visual Controls"
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -77.5
margin_top = 30.0
margin_right = 77.5
margin_bottom = 52.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxThemes" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer"]
margin_right = 155.0
margin_bottom = 19.0
[node name="ThemesLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/HBoxThemes"]
margin_right = 119.0
margin_bottom = 19.0
text = "Theme Preference:"
[node name="ThemeItemList" type="ItemList" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer"]
margin_top = 23.0
margin_right = 155.0
margin_bottom = 32.0
auto_height = true
[node name="HBoxVirtualKeyboardEnabled" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer"]
margin_top = 36.0
margin_right = 155.0
margin_bottom = 63.0
[node name="VisualKeyBoardLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/HBoxVirtualKeyboardEnabled"]
margin_top = 4.0
margin_right = 111.0
margin_bottom = 23.0
text = "Virtual Keyboard"
[node name="VisualKeyboardCheckBox" type="CheckBox" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/HBoxVirtualKeyboardEnabled"]
margin_left = 115.0
margin_right = 139.0
margin_bottom = 27.0
[node name="HBoxKeyboardLayout" type="HBoxContainer" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer"]
margin_top = 67.0
margin_right = 155.0
margin_bottom = 86.0
[node name="LayoutLabel" type="Label" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer/HBoxKeyboardLayout"]
margin_right = 120.0
margin_bottom = 19.0
text = "Layout Preference:"
[node name="LayoutItemList" type="ItemList" parent="Panel/HBoxContainer/RootVboxVisualControls2/Label2/VBoxContainer"]
margin_top = 90.0
margin_right = 155.0
margin_bottom = 99.0
auto_height = true
[node name="HBoxBottomRow" type="HBoxContainer" parent="Panel"]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -48.5
margin_top = 200.0
margin_right = 48.5
margin_bottom = 225.0
__meta__ = {
"_edit_use_anchors_": true
}
[node name="SaveButton" type="Button" parent="Panel/HBoxBottomRow"]
margin_right = 97.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_bottom = 25.0
text = "Back"
next_scene_path = "res://screens/MenuScreen.tscn"