From 67050fc322a6df75b406899a2d93a651d15e3989 Mon Sep 17 00:00:00 2001 From: Jaap Marsman Date: Mon, 8 Aug 2022 14:42:26 +0800 Subject: [PATCH] username saving implemented --- godot/button_email_feedback.gd | 1 + godot/button_open_github.gd | 2 +- godot/button_user_save.gd | 18 +++++++++++----- godot/main_screen.gd | 39 ++++++++++++++++++++++++++-------- godot/start_menu.gd | 6 ++---- godot/start_screen.tscn | 14 ++++-------- godot/user_values.gd | 6 +----- release_version.csv | 1 + 8 files changed, 53 insertions(+), 34 deletions(-) create mode 100644 release_version.csv diff --git a/godot/button_email_feedback.gd b/godot/button_email_feedback.gd index 7710c8d..e232c8b 100644 --- a/godot/button_email_feedback.gd +++ b/godot/button_email_feedback.gd @@ -17,4 +17,5 @@ func _ready(): func _on_button_email_feedback_pressed(): +# warning-ignore:return_value_discarded OS.shell_open("mailto:feedback@jaapmarsman.com") diff --git a/godot/button_open_github.gd b/godot/button_open_github.gd index f9d7ba8..48acf5e 100644 --- a/godot/button_open_github.gd +++ b/godot/button_open_github.gd @@ -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") diff --git a/godot/button_user_save.gd b/godot/button_user_save.gd index 6967868..f0fb41e 100644 --- a/godot/button_user_save.gd +++ b/godot/button_user_save.gd @@ -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 diff --git a/godot/main_screen.gd b/godot/main_screen.gd index 290d741..32119f8 100644 --- a/godot/main_screen.gd +++ b/godot/main_screen.gd @@ -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 diff --git a/godot/start_menu.gd b/godot/start_menu.gd index eb2cec8..9a05a05 100644 --- a/godot/start_menu.gd +++ b/godot/start_menu.gd @@ -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 diff --git a/godot/start_screen.tscn b/godot/start_screen.tscn index fa804b6..844f70b 100644 --- a/godot/start_screen.tscn +++ b/godot/start_screen.tscn @@ -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 diff --git a/godot/user_values.gd b/godot/user_values.gd index db11be9..83d069f 100644 --- a/godot/user_values.gd +++ b/godot/user_values.gd @@ -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(): diff --git a/release_version.csv b/release_version.csv new file mode 100644 index 0000000..d8263ee --- /dev/null +++ b/release_version.csv @@ -0,0 +1 @@ +2 \ No newline at end of file