Skip to content

Commit

Permalink
Finish daily goals & pushup per session settings
Browse files Browse the repository at this point in the history
Completed implementation of custom daily goals and pushups per session option.
  • Loading branch information
Vandreic committed Mar 10, 2024
1 parent 73874a9 commit 1804ad1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Created with [Godot Game Engine [4.3.dev4]](https://godotengine.org/).

<br>

<p align="center"><img src="app_screenshot.png" width="40%" ></p>
<p align="center"><img src="app_screenshot.png" width="40%" alt="app_screenshot.png" ></p>

## Roadmap
* ~~Implement pop-up confirmation for resetting saved progression~~
* ~~Provide reset options for saved progression~~
* Custom daily goals & pushups per session option
* ~~Custom daily goals & pushups per session option~~
* Visual theme update
* Integrate logging system for saving and loading processes
* Add notification for saved progression status
Expand Down Expand Up @@ -45,4 +45,4 @@ PushupProgression hasn't been compiled for macOS, iOS, or Linux, but you can co
</details>

## License
PushupProgression is released under the [MIT License](LICENSE.md).
PushupProgression is released under the [MIT License](LICENSE.md).
Binary file modified app_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/ui/options_menu/settings_menu/settings_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ custom_minimum_size = Vector2(300, 0)
layout_mode = 2
size_flags_horizontal = 4
theme_override_font_sizes/font_size = 30
placeholder_text = "Enter number..."
placeholder_text = "Current: 100"
alignment = 1
clear_button_enabled = true

Expand All @@ -81,7 +81,7 @@ custom_minimum_size = Vector2(300, 0)
layout_mode = 2
size_flags_horizontal = 4
theme_override_font_sizes/font_size = 30
placeholder_text = "Enter number..."
placeholder_text = "Current: 10"
alignment = 1
clear_button_enabled = true

Expand Down
49 changes: 42 additions & 7 deletions src/ui/options_menu/settings_menu/settings_menu_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
##
## Path: [code]res://src/ui/options_menu/settings_menu/settings_menu_manager_script.gd[/code]


#TODO: Restrict input fields to only digits


Expand Down Expand Up @@ -35,37 +36,71 @@ func close_menu() -> void:

## On [member SettingsMenuManager.close_menu_button] pressed.
func _on_close_menu_button_pressed() -> void:

# Search daily goal input text for digits
var daily_goal_input_text = regex.search(daily_goal_input.text)
if daily_goal_input_text:
GlobalVariables.daily_pushups_goal = int(daily_goal_input.text)
print("Good daily goal!")
print("Daily goal updated to: %s" % daily_goal_input.text)
elif daily_goal_input.text.is_empty():
print("No daily goal set.")
print("No changes to daily goal were made.")
else:
print("Bad daily goal...")
print("Invalid value for daily goal: %s. Only digits are allowed."\
% str(daily_goal_input.text))

# Search pushups per session input text for digits
var pushups_per_session_input_text = regex.search(pushups_per_session_input.text)
if pushups_per_session_input_text:
GlobalVariables.pushups_per_session = int(pushups_per_session_input.text)
print("Good pushups per session!")
print("Pushups per session updated to: %s" % pushups_per_session_input.text)
elif pushups_per_session_input.text.is_empty():
print("No pushups per session set.")
print("No changes to pushups per session were made.")
else:
print("Bad pushups per session...")
print("Invalid value for pushups per session: %s. Only digits allowed."\
% str(pushups_per_session_input.text))

# Save progression data
get_tree().call_group("save_system", "save_data")
# Update UI
get_tree().call_group("ui_manager", "update_ui")

# Close settings menu
close_menu()


## On [member SettingsMenuManager.daily_goal_input] text changed.
func _on_daily_goal_input_text_changed(input_text: String) -> void:
# Search daily goal input text for digits
var _input_text = regex.search(input_text)
# Change font color if input is not digits
if not _input_text:
daily_goal_input.add_theme_color_override("font_color", Color.RED)
else:
daily_goal_input.add_theme_color_override("font_color", Color.WHITE)


## On [member SettingsMenuManager.pushups_per_session_input] text changed.
func _on_pushups_per_session_input_text_changed(input_text: String) -> void:
# Search pushups per session input text for digits
var _input_text = regex.search(input_text)
# Change font color if input is not digits
if not _input_text:
pushups_per_session_input.add_theme_color_override("font_color", Color.RED)
else:
pushups_per_session_input.add_theme_color_override("font_color", Color.WHITE)


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Connect pressed button signals
close_menu_button.pressed.connect(_on_close_menu_button_pressed)
# Connect signal for text changes in input fields
daily_goal_input.text_changed.connect(_on_daily_goal_input_text_changed)
pushups_per_session_input.text_changed.connect(_on_pushups_per_session_input_text_changed)
# Compiles and assign search pattern for regex (Only digits)
regex.compile("^[0-9]+$")

# Placeholder text for input fields
var _placeholder_text: String = "Current: %d"
# Set placeholder text for input fields
daily_goal_input.placeholder_text = _placeholder_text % GlobalVariables.daily_pushups_goal
pushups_per_session_input.placeholder_text = _placeholder_text % GlobalVariables.pushups_per_session
4 changes: 2 additions & 2 deletions src/ui/ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ text = "Add 10 pushups"
unique_name_in_owner = true
anchors_preset = -1
anchor_left = 0.9
anchor_top = 0.94
anchor_right = 0.99
anchor_top = 0.95
anchor_right = 0.975
anchor_bottom = 0.99
grow_horizontal = 2
grow_vertical = 2
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ui_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func update_progress_bar() -> void:
# Update progress bar value
progress_bar.value = 100
# Update progress value text
progress_value_label.text = str(new_progress_bar_value) + "%!"
progress_value_label.text = str(round(new_progress_bar_value)) + "%!"
else:
progress_bar.value = new_progress_bar_value
progress_value_label.text = str(round(new_progress_bar_value)) + "%"
Expand Down
22 changes: 19 additions & 3 deletions src/utilities/save_system.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ func create_day_data_dict() -> Dictionary:
var day_dict: Dictionary = {}
# Add daily goal to dictionary
day_dict["daily_pushups_goal"] = GlobalVariables.daily_pushups_goal
# Add remaining pushups to dictionary
# Add pushups per session
day_dict["pushups_per_session"] = GlobalVariables.pushups_per_session
# Add remaining pushups
day_dict["remaining_pushups"] = GlobalVariables.remaining_pushups
# Add total pushups for today to dictionary
# Add total pushups for today
day_dict["total_pushups_today"] = GlobalVariables.total_pushups_today
# Add sessions to dictionary
# Add sessions
day_dict["sessions"] = {}
# Return created dictionary
return day_dict
Expand Down Expand Up @@ -113,6 +115,11 @@ func create_save_data_dict_from_saved_data(saved_data_dict: Dictionary) -> void:
# Save daily goal to new dictionaru
years_dict[year][month][day]["daily_pushups_goal"] = daily_goal

# Get pushups per session
var pushups_per_session: int = saved_data_dict["calendar"][year][month][day]["pushups_per_session"]
# Save pushups per session
years_dict[year][month][day]["pushups_per_session"] = pushups_per_session

# Get remaining pushups
var remaining_pushups: int = saved_data_dict["calendar"][year][month][day]["remaining_pushups"]
# Save remaining pushups
Expand Down Expand Up @@ -174,6 +181,8 @@ func create_save_data_dict_from_saved_data(saved_data_dict: Dictionary) -> void:
else:
# Load daily goal
GlobalVariables.daily_pushups_goal = saved_data_dict["calendar"][current_year][current_month][current_day]["daily_pushups_goal"]
# Load pushups per session
GlobalVariables.pushups_per_session = saved_data_dict["calendar"][current_year][current_month][current_day]["pushups_per_session"]
# Load remaining pushups
GlobalVariables.remaining_pushups = saved_data_dict["calendar"][current_year][current_month][current_day]["remaining_pushups"]
# Load total pushups
Expand Down Expand Up @@ -272,6 +281,8 @@ func save_data() -> void:

# Save daily pushups goal
GlobalVariables.save_data_dict["calendar"][year][month][day]["daily_pushups_goal"] = GlobalVariables.daily_pushups_goal
# Save pushups per session
GlobalVariables.save_data_dict["calendar"][year][month][day]["pushups_per_session"] = GlobalVariables.pushups_per_session
# Save remaining pushups
GlobalVariables.save_data_dict["calendar"][year][month][day]["remaining_pushups"] = GlobalVariables.remaining_pushups
# Save total pushups
Expand Down Expand Up @@ -397,6 +408,11 @@ func load_data() -> void:
# Save daily goal
years_dict[int(year)][int(month)][int(day)]["daily_pushups_goal"] = daily_goal

# Get pushups per session
var pushups_per_session: int = int(save_file_data["calendar"][year][month][day]["pushups_per_session"])
# Save pushups per session
years_dict[int(year)][int(month)][int(day)]["pushups_per_session"] = pushups_per_session

# Get remaining pushups
var remaining_pushups: int = int(save_file_data["calendar"][year][month][day]["remaining_pushups"])
# Save remaining pushups
Expand Down

0 comments on commit 1804ad1

Please sign in to comment.