From c19f81c7ec51009ec63012da9e4522672cd92e35 Mon Sep 17 00:00:00 2001 From: Jaap Marsman Date: Tue, 16 Aug 2022 17:30:28 +0800 Subject: [PATCH] fixed welcome label to no longer depend on process delta script --- godot/apps/daily_prompts.tscn | 3 ++ godot/button_user_save.gd | 56 +++++++++++++++-------------------- godot/main_screen.gd | 8 ++--- godot/node_variables.gd | 5 ++++ godot/start_menu.gd | 22 ++++++++------ godot/start_menu.tscn | 7 ++--- godot/start_screen.tscn | 5 +++- godot/ui_control.gd | 9 ++++++ godot/user_details.tscn | 9 ++++++ godot/user_values.gd | 19 ++++++++---- 10 files changed, 86 insertions(+), 57 deletions(-) create mode 100644 godot/apps/daily_prompts.tscn diff --git a/godot/apps/daily_prompts.tscn b/godot/apps/daily_prompts.tscn new file mode 100644 index 0000000..fc4acb4 --- /dev/null +++ b/godot/apps/daily_prompts.tscn @@ -0,0 +1,3 @@ +[gd_scene format=2] + +[node name="daily_prompts" type="CanvasLayer"] diff --git a/godot/button_user_save.gd b/godot/button_user_save.gd index 10903ba..55944b0 100644 --- a/godot/button_user_save.gd +++ b/godot/button_user_save.gd @@ -1,42 +1,34 @@ extends Button -var config = ConfigFile.new() - onready var node_variables = get_node("/root/NodeVariables") -onready var user_info = get_node("/root/UserValues") +onready var ui_control = get_node("/root/UiControl") +onready var user_values = get_node("/root/UserValues") onready var user_name = get_node("%textbox_user_name") -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass - - func _on_button_user_save_pressed(): -# Store some values. -# Maybe this one only runs if there is no ini - 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) + if user_name.text == "": + # Prettify this later with a friendly user prompt + print("Won't continue. Put in name.") -# Save it to a file (overwrite if already exists). -# Need to make sure I never lose any values I add. -# This seems to be a manual thing to program. -# So per value, make sure to read it upon load. -# And write it out again as well. + else: + # First time label turns off - this is done every time - no harm in that? + node_variables.first_time_label.visible = false + + # Stores values in ini file + user_values.config.set_value("User", "user_name", user_name.text) + user_values.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) - config.save("user://user.ini") - - node_variables.main_screen.visible = true - node_variables.start_menu.visible = true - node_variables.user_menu.visible = false + # Save it to a file (overwrite if already exists). + # Need to make sure I never lose any values I add. + # This seems to be a manual thing to program. + # So per value, make sure to read it upon load. + # And write it out again as well. -# Need to do a "This thing can't be empty" code -# Most likely here. A if .text = null, then, -# don't proceed. + user_values.config.save("user://user.ini") + + node_variables.welcome_label.text = "Good morning, " + user_values.user_first_name + "!" + ui_control.show_start_menu() diff --git a/godot/main_screen.gd b/godot/main_screen.gd index ff63ddf..aff5a16 100644 --- a/godot/main_screen.gd +++ b/godot/main_screen.gd @@ -5,16 +5,13 @@ onready var node_variables = get_node("/root/NodeVariables") onready var ui_control = get_node("/root/UiControl") onready var user_info = get_node("/root/UserValues") -var config = ConfigFile.new() -var err = config.load("user://user.ini") - - func _ready(): # Read config file if it exists # otherwise set up new user data - if err != OK: + if user_info.err != OK: ui_control.show_user_menu() + node_variables.first_time_label.visible = true else: @@ -22,7 +19,6 @@ func _ready(): ui_control.show_start_menu() # define variables from ini file - user_info.user_first_name = config.get_value("User", "user_name") node_variables.user_name.text = user_info.user_first_name # Iterate over all sections. diff --git a/godot/node_variables.gd b/godot/node_variables.gd index aed6952..b73fdc1 100644 --- a/godot/node_variables.gd +++ b/godot/node_variables.gd @@ -4,7 +4,12 @@ extends Node onready var main_screen = get_node("/root/main_screen") onready var start_menu = get_node("/root/main_screen/UI/top_container/menus_container/start_menu") onready var user_menu = get_node("/root/main_screen/UI/top_container/menus_container/user_details") +onready var daily_prompts = get_node("/root/main_screen/UI/top_container/menus_container/daily_prompts") + + onready var user_name = get_node("/root/main_screen/UI/top_container/menus_container/user_details/textbox_user_name") +onready var first_time_label = get_node("/root/main_screen/UI/top_container/menus_container/user_details/label_first_time") +onready var welcome_label = get_node("/root/main_screen/UI/top_container/menus_container/start_menu/welcome_title") # Called when the node enters the scene tree for the first time. diff --git a/godot/start_menu.gd b/godot/start_menu.gd index 4478283..b3ae151 100644 --- a/godot/start_menu.gd +++ b/godot/start_menu.gd @@ -1,27 +1,31 @@ extends CanvasLayer -onready var user_info = get_node("/root/UserValues") -onready var program_info = get_node("/root/ProgramValues") +onready var user_values = get_node("/root/UserValues") +onready var program_values = get_node("/root/ProgramValues") func _ready(): -# $HTTPRequest.connect("request_completed", self, "_on_request_completed") - $version_label.text = str(program_info.current_version) + $version_label.text = str(program_values.current_version) + $welcome_title.text = "Good morning, " + user_values.user_first_name + "!" -func _process(_delta): - $welcome_title.text = "Good morning " + user_info.user_first_name + "!" +#func _process(_delta): +# Currently the only working way to show the user name. NOT desirable, continuously running the same line of code for no reason than me not figuring it out. +# $welcome_title.text = "Good morning, " + user_info.user_first_name + "!" func _on_button_update_check_pressed(): $HTTPRequest.request("https://raw.githubusercontent.com/hobbesjaap/wellbeingapp/main/version_info.csv") +func update_user_name_label(): + $welcome_title.text = "Good morning, " + user_values.user_first_name + "!" + func _on_HTTPRequest_request_completed(_result, _response_code, _headers, body): var json = JSON.parse(body.get_string_from_utf8()) - program_info.web_release_version = json.result - if program_info.web_release_version > program_info.release_version: + program_values.web_release_version = json.result + if program_values.web_release_version > program_values.release_version: print("There's an update!") - elif program_info.web_release_version == program_info.release_version: + elif program_values.web_release_version == program_values.release_version: print("There is no update!") diff --git a/godot/start_menu.tscn b/godot/start_menu.tscn index de264fe..57c8805 100644 --- a/godot/start_menu.tscn +++ b/godot/start_menu.tscn @@ -73,16 +73,15 @@ size_flags_horizontal = 3 size_flags_vertical = 3 text = "Journal" -[node name="welcome_title" type="RichTextLabel" parent="."] +[node name="welcome_title" type="Label" parent="."] +unique_name_in_owner = true anchor_left = 0.5 anchor_right = 0.5 margin_left = -185.0 margin_top = 11.0 margin_right = 185.0 margin_bottom = 42.0 -text = "Good morning, Jaap! -" -scroll_active = false +text = "Poofaces are cool" [node name="HTTPRequest" type="HTTPRequest" parent="."] diff --git a/godot/start_screen.tscn b/godot/start_screen.tscn index 50b3442..012e8c0 100644 --- a/godot/start_screen.tscn +++ b/godot/start_screen.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://main_screen.gd" type="Script" id=1] [ext_resource path="res://user_details.tscn" type="PackedScene" id=2] [ext_resource path="res://start_menu.tscn" type="PackedScene" id=3] +[ext_resource path="res://apps/daily_prompts.tscn" type="PackedScene" id=4] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.862745, 0.435294, 0.329412, 1 ) @@ -40,6 +41,8 @@ margin_right = 1280.0 [node name="user_details" parent="UI/top_container/menus_container" instance=ExtResource( 2 )] +[node name="daily_prompts" parent="UI/top_container/menus_container" instance=ExtResource( 4 )] + [node name="bottom_bar" type="Panel" parent="UI"] margin_top = 680.0 margin_right = 1280.0 diff --git a/godot/ui_control.gd b/godot/ui_control.gd index 2147242..3cfdfac 100644 --- a/godot/ui_control.gd +++ b/godot/ui_control.gd @@ -2,6 +2,7 @@ extends Node onready var node_variables = get_node("/root/NodeVariables") +onready var user_values = get_node("/root/UserValues") # Called when the node enters the scene tree for the first time. func _ready(): @@ -11,11 +12,19 @@ func show_start_menu(): node_variables.main_screen.visible = true node_variables.start_menu.visible = true node_variables.user_menu.visible = false + node_variables.daily_prompts.visible = false func show_user_menu(): node_variables.main_screen.visible = true node_variables.start_menu.visible = false node_variables.user_menu.visible = true + node_variables.daily_prompts.visible = false + +func show_daily_prompts(): + node_variables.main_screen.visible = true + node_variables.start_menu.visible = false + node_variables.user_menu.visible = false + node_variables.daily_prompts.visible = true # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): diff --git a/godot/user_details.tscn b/godot/user_details.tscn index 6846ef7..e67ffb1 100644 --- a/godot/user_details.tscn +++ b/godot/user_details.tscn @@ -29,4 +29,13 @@ margin_bottom = 404.0 focus_mode = 2 text = "Day" +[node name="label_first_time" type="Label" parent="."] +unique_name_in_owner = true +visible = false +margin_left = 211.0 +margin_top = 168.0 +margin_right = 832.0 +margin_bottom = 193.0 +text = "First time user: Please fill in your FIRST NAME only below." + [connection signal="pressed" from="button_user_save" to="button_user_save" method="_on_button_user_save_pressed"] diff --git a/godot/user_values.gd b/godot/user_values.gd index 439f81c..746c5e5 100644 --- a/godot/user_values.gd +++ b/godot/user_values.gd @@ -1,8 +1,8 @@ extends Node -var user_first_name = "Not defined" -var user_birth_month -var user_birth_date +var user_first_name = " " +var user_birth_month = 0 +var user_birth_day = 0 # For the login-streak thing @@ -11,9 +11,18 @@ var user_birth_date #var user_last_login_month #var user_last_login_day -# Called when the node enters the scene tree for the first time. + +var config = ConfigFile.new() +var err = config.load("user://user.ini") + func _ready(): - pass # Replace with function body. + # Read config file if it exists + # define variables from ini file + if err == OK: + user_first_name = config.get_value("User", "user_name") + + else: + pass # Called every frame. 'delta' is the elapsed time since the previous frame.