Skip to content

Commit

Permalink
Created notification system
Browse files Browse the repository at this point in the history
Implemented notification system for save/load and settings updates.
  • Loading branch information
Vandreic committed Apr 5, 2024
1 parent 4cc3faa commit 705e481
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 87 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ***PushupProgression***
![Made with Godot](https://img.shields.io/badge/Made%20with-Godot-3776AB.svg?style=plastic&logo=godot-engine&logoColor=white)
![Version](https://img.shields.io/badge/version-1.2.0-00BB1A.svg?style=plastic)
![Version](https://img.shields.io/badge/version-1.3.0-00BB1A.svg?style=plastic)

An app for tracking pushup progress and reaching daily goals. Designed for smartphones.

Expand All @@ -14,10 +14,10 @@ Created with [Godot Game Engine [4.3.dev5]](https://godotengine.org/).
* ~~Implement pop-up confirmation for resetting saved progression~~
* ~~Provide reset options for saved progression~~
* ~~Custom daily goals & pushups per session option~~
* Visual theme update
* ~~Integrate logging system for saving and loading processes~~
* Add notification for saved progression status
* ~~Add notification for saved progression status~~
* Show previous progression
* Visual theme update

## Usage

Expand Down
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.
57 changes: 52 additions & 5 deletions global/global_variables.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const MAIN_SCENE_PATH: String = "res://src/main/main.tscn"
## Logging menu scene file path.
const LOGGING_MENU_SCENE_PATH: String = "res://src/ui/options_menu/logging_menu/logging_menu.tscn"

## App running flag [bool].
## App running flag.
var app_running: bool = false


Expand All @@ -86,13 +86,13 @@ var daily_pushups_goal: int = 100
## Number of pushups in each session.
var pushups_per_session: int = 10

## Total pushups.
## Total pushups today.
var total_pushups_today: int = 0

## Total pushups sessions.
## Total pushups sessions today.
var total_pushups_sessions: int = 0

## Remaining pushup to reach daily goal.
## Remaining pushups to reach daily goal.
var remaining_pushups: int = 0

## Save data [Dictionary] to store settings and progression data.
Expand All @@ -106,5 +106,52 @@ var save_data_dict: Dictionary = {
"calendar": {}
}

## Logs [Array].
## Stores log messages.
var logs_array: Array = []


## Create log message. [br]
##
## [br]
##
## See [method SaveSystem.create_log] for more details.
func create_log(log_message: String) -> void:
# Create log
get_tree().call_group("save_system", "create_log", log_message)


## Create notification. [br]
##
## [br]
##
## See [method NotificationSystem.create_notification] for more details.
func create_notification(notification_text: String, extended_duration: bool = false) -> void:
# Create notification
get_tree().call_group("notification_system", "create_notification", notification_text, extended_duration)


## Update UI. [br]
##
## [br]
##
## See [method UIManager.update_ui] for more details.
func update_ui() -> void:
get_tree().call_group("ui_manager", "update_ui")


## Save data. [br]
##
## [br]
##
## See [method SaveSystem.save_data] for more details.
func save_data() -> void:
get_tree().call_group("save_system", "save_data")


## Load data. [br]
##
## [br]
##
## See [method SaveSystem.load_data] for more details.
func load_data() -> void:
get_tree().call_group("save_system", "load_data")
41 changes: 26 additions & 15 deletions src/main/main.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Main Scene Script.
## Main Scene.
##
## Path: [code]res://src/main/main.gd[/code]

Expand All @@ -14,24 +14,35 @@ func _ready():

# Load save file if game is not running
if GlobalVariables.app_running == false:
get_tree().call_group("save_system", "load_data")
GlobalVariables.load_data()

# Update UI
get_tree().call_group("ui_manager", "update_ui")
GlobalVariables.update_ui()


## Change window size to 480x800 if screen height is less than 1280 pixels
## (Used for 1920x1080 monitors) [br]
## Position window in middle of screen after resizing. [br][br]
## (Used for 1920x1080 monitors). [br]
## Position window in center of screen after resizing. [br]
##
## [br]
##
## [b]Note:[/b] Used for PC.
func change_window_size():
var current_screen_size: Vector2i = DisplayServer.screen_get_size(0)
var window_size_hdpi = Vector2i(480, 800)
# Get primary screen id/index
var primary_monitor_id: int = DisplayServer.get_primary_screen()
# Get primary screen size
var screen_size: Vector2i = DisplayServer.screen_get_size(primary_monitor_id)
# Define desired window size
var window_size: Vector2i = Vector2i(480, 800)

# Change resolution if necessary
if current_screen_size.y < 1280:
DisplayServer.window_set_size(window_size_hdpi)
# Position window in center of screen
var new_x_pos = (current_screen_size.x * 1.5) - (DisplayServer.window_get_size().x / 2)
var new_y_pos = (current_screen_size.y / 2) - (DisplayServer.window_get_size().y / 2)
DisplayServer.window_set_position(Vector2i(new_x_pos, new_y_pos))
# Change resolution if primary screen height is less than 1280 pixels
if screen_size.y < 1280:
# Set desired window size
DisplayServer.window_set_size(window_size)
# Calculate window center position
#var center_x: int = int((screen_size.x - window_size.x) / 2.0)
var center_x: int = int((screen_size.x - window_size.x) * 1.833)
var center_y: int = int((screen_size.y - window_size.y) / 2.0)

# Position window in center
DisplayServer.window_set_position(Vector2i(center_x, center_y))
23 changes: 20 additions & 3 deletions src/main/main.tscn
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
[gd_scene load_steps=4 format=3 uid="uid://b8m5sfw05s6ty"]
[gd_scene load_steps=7 format=3 uid="uid://b8m5sfw05s6ty"]

[ext_resource type="Script" path="res://src/main/main.gd" id="1_ui10i"]
[ext_resource type="PackedScene" uid="uid://bv2v88irqyogj" path="res://src/ui/ui.tscn" id="2_06dc6"]
[ext_resource type="Script" path="res://src/utilities/save_system.gd" id="3_vaodl"]
[ext_resource type="Script" path="res://src/utilities/notification_system.gd" id="4_caoxb"]

[sub_resource type="Animation" id="Animation_pjprj"]
resource_name = "show_notification"
length = 0.2

[sub_resource type="AnimationLibrary" id="AnimationLibrary_ac6sq"]
_data = {
"show_notification": SubResource("Animation_pjprj")
}

[node name="Main" type="Node"]
script = ExtResource("1_ui10i")

[node name="UI" parent="." instance=ExtResource("2_06dc6")]

[node name="ProgressionController" type="Node" parent="."]

[node name="Utilities" type="Node" parent="."]

[node name="SaveSystem" type="Node" parent="Utilities" groups=["save_system"]]
script = ExtResource("3_vaodl")

[node name="NotificationSystem" type="Node" parent="Utilities" groups=["notification_system"]]
script = ExtResource("4_caoxb")

[node name="NotificationAnimationPlayer" type="AnimationPlayer" parent="Utilities/NotificationSystem"]
unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_ac6sq")
}
74 changes: 74 additions & 0 deletions src/ui/notification/notification.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[gd_scene load_steps=4 format=3 uid="uid://fjatxhusdrmj"]

[ext_resource type="Script" path="res://src/ui/notification/notification_manager.gd" id="1_bopgf"]

[sub_resource type="Animation" id="Animation_7vkrs"]
resource_name = "show_notification"
length = 1.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/1/type = "method"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0.9, 1.1),
"transitions": PackedFloat32Array(1, 1),
"values": [{
"args": [],
"method": &"hide_ui"
}, {
"args": [],
"method": &"remove_ui"
}]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_0m8h3"]
_data = {
"show_notification": SubResource("Animation_7vkrs")
}

[node name="Notification" type="CanvasLayer"]
script = ExtResource("1_bopgf")

[node name="PanelContainer" type="PanelContainer" parent="."]
anchors_preset = -1
anchor_left = 0.4
anchor_top = 0.94
anchor_right = 0.6
anchor_bottom = 0.975
grow_horizontal = 2
grow_vertical = 2

[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 7
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 7
theme_override_constants/margin_bottom = 5

[node name="NotificationLabel" type="Label" parent="PanelContainer/MarginContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_font_sizes/font_size = 30
text = "Notification Text..."
horizontal_alignment = 1
vertical_alignment = 1

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_0m8h3")
}
52 changes: 52 additions & 0 deletions src/ui/notification/notification_manager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Notification Manager.
##
## Controls the behavior of notification. [br]
##
## [br]
##
## Path: [code]res://src/ui/notification/notification_manager.gd[/code]


class_name NotificationManager
extends CanvasLayer


## Notification animation player.
@onready var animation_player: AnimationPlayer = %AnimationPlayer

## Signal for removing notification.
signal notification_removed

## Extend notificatio duration.
var extend_duration: bool = false


## Show notification.
func show_ui() -> void:
# Play notification animation
animation_player.play("show_notification")


## Hide notification.
func hide_ui() -> void:
# Change visibility
visible = false


## Remove notification. (Removes scene from tree).
func remove_ui() -> void:
# Emit notification removed signal
notification_removed.emit()
# Delete scene from tree
get_parent().remove_child(self)
queue_free()


# Called when the node enters the scene tree for the first time.
func _ready():
# Hide notification UI as default
hide_ui()
# Check if extend duration is true
if extend_duration == true:
# Extend animation play speed
animation_player.speed_scale = 0.5
5 changes: 1 addition & 4 deletions src/ui/options_menu/logging_menu/logging_menu_controller.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Logging Menu Controller.
##
## Creates logs and controls the behavior of logging menu. [br]
## Creates log messages and controls the behavior of logging menu. [br]
##
## [br]
##
Expand Down Expand Up @@ -49,9 +49,6 @@ func create_logs_ui() -> void:
logs_container.remove_child(base_log_label)
base_log_label.queue_free()

print("Ready")
print(GlobalVariables.logs_array)


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Expand Down
Loading

0 comments on commit 705e481

Please sign in to comment.