username saving implemented

This commit is contained in:
Jaap Marsman 2022-08-08 14:42:26 +08:00
parent 29e28ac115
commit 67050fc322
8 changed files with 53 additions and 34 deletions

View File

@ -17,4 +17,5 @@ func _ready():
func _on_button_email_feedback_pressed():
# warning-ignore:return_value_discarded
OS.shell_open("mailto:feedback@jaapmarsman.com")

View File

@ -16,4 +16,4 @@ extends Button
func _on_button_open_github_pressed():
OS.shell_open("https://godotengine.org")
OS.shell_open("https://github.com/hobbesjaap/wellbeingapp")

View File

@ -2,8 +2,11 @@ extends Button
var config = ConfigFile.new()
onready var user_name = get_node("textbox_user_name")
onready var user_name = get_node("%textbox_user_name")
onready var user_info = get_node("/root/UserValues")
onready var main_screen = get_node("/root/main_screen")
onready var start_menu = get_node("/root/main_screen/start_menu")
onready var user_menu = get_node("/root/main_screen/user_details")
# Called when the node enters the scene tree for the first time.
func _ready():
@ -17,10 +20,15 @@ func _ready():
func _on_button_user_save_pressed():
# Store some values.
config.set_value("User", "player_name", user_name)
config.set_value("Player1", "best_score", 10)
config.set_value("Player2", "player_name", "V3geta")
config.set_value("Player2", "best_score", 9001)
config.set_value("User", "user_name", user_name.text)
user_info.user_first_name = user_name.text
#config.set_value("Player1", "best_score", 10)
#onfig.set_value("Player2", "player_name", "V3geta")
#config.set_value("Player2", "best_score", 9001)
# Save it to a file (overwrite if already exists).
config.save("user://user.ini")
main_screen.visible = true
start_menu.visible = true
user_menu.visible = false

View File

@ -1,21 +1,42 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var main_screen = get_node("/root/main_screen")
onready var start_menu = get_node("/root/main_screen/start_menu")
onready var user_menu = get_node("/root/main_screen/user_details")
onready var user_name = get_node("%textbox_user_name")
onready var user_info = get_node("/root/UserValues")
onready var program_info = get_node("/root/ProgramValues")
var config = ConfigFile.new()
var err = config.load("user://user.ini")
# Called when the node enters the scene tree for the first time.
func _ready():
# Read config file if it exists
# otherwise set up new user data
if err != OK:
start_menu.visible = false
user_menu.visible = true
else:
# Set starting state visibility
main_screen.visible = true
start_menu.visible = true
user_menu.visible = false
main_screen.visible = true
start_menu.visible = true
user_menu.visible = false
# define variables from ini file
user_info.user_first_name = config.get_value("User", "user_name")
user_name.text = user_info.user_first_name
# Iterate over all sections.
# for player in config.get_sections():
# # Fetch the data for each section.
# var player_name = config.get_value(player, "player_name")
# var player_score = config.get_value(player, "best_score")
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -1,9 +1,6 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var user_info = get_node("/root/UserValues")
onready var program_info = get_node("/root/ProgramValues")
@ -13,5 +10,6 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
func _process(_delta):
$welcome_title.text = "Good morning " + user_info.user_first_name + "!"
# pass

View File

@ -14,7 +14,6 @@ __meta__ = {
}
[node name="start_menu" type="Node2D" parent="."]
visible = false
script = ExtResource( 4 )
[node name="button_daily_action" type="Button" parent="start_menu"]
@ -38,7 +37,7 @@ margin_left = 98.0
margin_top = 195.0
margin_right = 135.0
margin_bottom = 215.0
text = "URL"
text = "GitHub"
script = ExtResource( 2 )
[node name="button_email_feedback" type="Button" parent="start_menu"]
@ -58,23 +57,18 @@ text = "Name"
script = ExtResource( 5 )
[node name="user_details" type="Node2D" parent="."]
[node name="button_user_ok" type="Button" parent="user_details"]
margin_left = 444.0
margin_top = 279.0
margin_right = 500.0
margin_bottom = 316.0
text = "OK"
visible = false
[node name="button_user_save" type="Button" parent="user_details"]
margin_left = 540.0
margin_top = 280.0
margin_right = 615.0
margin_bottom = 317.0
text = "Save"
text = "OK"
script = ExtResource( 6 )
[node name="textbox_user_name" type="LineEdit" parent="user_details"]
unique_name_in_owner = true
margin_left = 244.0
margin_top = 205.0
margin_right = 794.0

View File

@ -1,10 +1,6 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var user_first_name = "No name"
var user_first_name = "Not defined"
# Called when the node enters the scene tree for the first time.
func _ready():

1
release_version.csv Normal file
View File

@ -0,0 +1 @@
2
1 2