diff --git a/Scenes/Global/game_data.gd b/Scenes/Global/game_data.gd index 93c3326..f585760 100644 --- a/Scenes/Global/game_data.gd +++ b/Scenes/Global/game_data.gd @@ -7,6 +7,7 @@ signal printer_bought(printer: Node) signal filament_bought @warning_ignore("unused_signal") signal refresh_printer_dropdown +signal notification_requested(message: String, color: String) # - Variables - Code managed var job_spawn_timer: Timer @@ -14,6 +15,12 @@ var jobs_array: Array[JobData] var current_job_count: int = 0 var filaments_array: Array[FilamentData] +# - Text colors +var hex_white: String = '#ffffff' +var hex_green: String = '#4ade80' +var hex_blue: String = '#60a5fa' +var hex_red: String = '#f87171' + # - Scenes const JOB_CARD = preload("uid://dvfcie8hqcb0") const PRINTER = preload("uid://33ctlyrpibs3") @@ -35,6 +42,10 @@ func _ready() -> void: job_spawn_timer.timeout.connect(_on_job_spawn_timer_timeout) job_spawn_timer.start() +func display_msg(message: String, color: String) -> void: + notification_requested.emit(message,color) + +#region Shop buy interactions func _on_shop_printer_purchase_req(printer_data: PrinterData) -> void: if PlayerData.try_purchase(printer_data.printer_price): var new_printer = PRINTER.instantiate() @@ -46,7 +57,7 @@ func _on_shop_filament_purchase_req(filament_data: FilamentData) -> void: if PlayerData.try_purchase(filament_data.price): filaments_array.append(filament_data) filament_bought.emit() - +#endregion #region Job generation func _on_job_spawn_timer_timeout() -> void: diff --git a/Scenes/Printer/printer.gd b/Scenes/Printer/printer.gd index e40750e..034a3fd 100644 --- a/Scenes/Printer/printer.gd +++ b/Scenes/Printer/printer.gd @@ -10,12 +10,6 @@ extends PanelContainer @onready var reward_label: RichTextLabel = $MarginContainer/MainArea/PrintInfo/InfoRow2/RewardLabel @onready var quality_label: RichTextLabel = $MarginContainer/MainArea/PrintInfo/InfoRow1/QualityLabel -# RichTextLabel - Colors -var hex_white: String = '#ffffff' -var hex_green: String = '#4ade80' -var hex_blue: String = '#60a5fa' -var hex_red: String = '#f87171' - var printer_data: PrinterData var selected_job: JobData var selected_job_index: int @@ -37,9 +31,10 @@ func initialize_printer(data: PrinterData) -> void: reward_label.visible = false time_left_label.visible = false time_left = 0 - set_status() + status_label.text = 'Status: [color=%s]%s[/color]' % [GameData.hex_white, "Free"] progress_bar.visible = false progress_bar.value = 0 + GameData.display_msg('%s printer bought!' % printer_data.printer_manufacturer, GameData.hex_green) _on_select_job_pressed() func _process(delta) -> void: @@ -51,8 +46,8 @@ func _process(delta) -> void: reward_label.visible = true set_status() - quality_label.text = 'Quality: [color=%s]%.0f%%[/color]' % [hex_green, (print_quality * 100)] - reward_label.text = 'Reward: [color=%s]%.2f €[/color]' % [hex_green, (selected_job.job_reward * print_quality)] + quality_label.text = 'Quality: [color=%s]%.0f%%[/color]' % [GameData.hex_green, (print_quality * 100)] + reward_label.text = 'Reward: [color=%s]%.2f €[/color]' % [GameData.hex_green, (selected_job.job_reward * print_quality)] var total_time = selected_job.job_time / printer_data.printer_speed var progress = (total_time - time_left) / total_time @@ -69,16 +64,10 @@ func _process(delta) -> void: if failure_points.has(roundf(progress_bar.value * 100)): if failure_points[0] == roundf(progress_bar.value * 100): if check_failure(roundf(progress_bar.value * 100)): - print('Print failed') print_failed = true reset_status() - else: - if check_failure(roundf(progress_bar.value * 100)): + elif check_failure(roundf(progress_bar.value * 100)): print_quality -= 0.1 - print('Fail check, new print quality: %.2f' % print_quality) - print('Failure points: ', failure_points) - else: - print('Passed check') func reset_status() -> void: is_printing = false @@ -98,17 +87,19 @@ func reset_status() -> void: _on_select_job_pressed() func set_status() -> void: - var color_hex: String = hex_white # Default color: white + var color_hex: String = GameData.hex_white var status: String if print_failed: status = 'Failed' - color_hex = hex_red # Failed color: red + color_hex = GameData.hex_red + GameData.display_msg('Print failed!',color_hex) elif is_printing: status = 'Printing' - color_hex = hex_blue # Printing color: blue + color_hex = GameData.hex_blue else: status = 'Free' - color_hex = hex_green # Free color: green + color_hex = GameData.hex_green + GameData.display_msg('Print completed!',color_hex) status_label.text = 'Status: [color=%s]%s[/color]' % [color_hex, status] diff --git a/Scenes/UI/ui.tscn b/Scenes/UI/ui.tscn index bfb7722..f6a01ce 100644 --- a/Scenes/UI/ui.tscn +++ b/Scenes/UI/ui.tscn @@ -1,6 +1,7 @@ [gd_scene format=3 uid="uid://d24rvu5c0gd1w"] [ext_resource type="Script" uid="uid://d0sgvbphgssmi" path="res://Scenes/UI/ui.gd" id="1_vqjbf"] +[ext_resource type="PackedScene" uid="uid://c4tdg221rvm53" path="res://Scenes/UI/ui_notification.tscn" id="2_s3gqk"] [ext_resource type="Script" uid="uid://bcowlm04qsgqc" path="res://Scenes/UI/shop_filaments.gd" id="9_mbl0m"] [ext_resource type="Script" uid="uid://q8cf21vq4ka6" path="res://Scenes/tab_switcher.gd" id="13_vqjbf"] [ext_resource type="Script" uid="uid://cg2kskiky8iur" path="res://Scenes/Shop/shop_tab_switcher.gd" id="14_vqjbf"] @@ -172,6 +173,9 @@ size_flags_horizontal = 3 size_flags_vertical = 3 theme_override_constants/separation = 8 +[node name="Printer" parent="VBoxContainer/MainAreaMargin/MainArea/LeftColumn/MainMargin/PrinterScroll/MarginContainer/PrinterContainer" unique_id=1372437203 instance_placeholder="res://Scenes/Printer/printer.tscn"] +layout_mode = 2 + [node name="RightColumn" type="VBoxContainer" parent="VBoxContainer/MainAreaMargin/MainArea" unique_id=653054059] layout_mode = 2 size_flags_horizontal = 3 @@ -321,6 +325,16 @@ unique_name_in_owner = true visible = false layout_mode = 2 +[node name="UiNotification" parent="." unique_id=1468421214 instance=ExtResource("2_s3gqk")] +layout_mode = 0 +anchors_preset = 0 +anchor_right = 0.0 +anchor_bottom = 0.0 +offset_right = 1152.0 +offset_bottom = 649.0 +grow_horizontal = 1 +grow_vertical = 1 + [node name="JobSpawner" type="Timer" parent="." unique_id=1696213535] autostart = true diff --git a/Scenes/UI/ui_notification.gd b/Scenes/UI/ui_notification.gd new file mode 100644 index 0000000..8b7d53a --- /dev/null +++ b/Scenes/UI/ui_notification.gd @@ -0,0 +1,11 @@ +extends Control + +@onready var message_label: RichTextLabel = $Base/Margin/Message +@onready var animation_player: AnimationPlayer = $AnimationPlayer + +func _ready() -> void: + GameData.notification_requested.connect(_on_notification_requested) + +func _on_notification_requested(message: String, color: String) -> void: + message_label.text = '[color=%s]%s[/color]' % [color, message] + animation_player.play("show_notification") diff --git a/Scenes/UI/ui_notification.gd.uid b/Scenes/UI/ui_notification.gd.uid new file mode 100644 index 0000000..3021ae2 --- /dev/null +++ b/Scenes/UI/ui_notification.gd.uid @@ -0,0 +1 @@ +uid://y3jtgv0vknvk diff --git a/Scenes/UI/ui_notification.tscn b/Scenes/UI/ui_notification.tscn new file mode 100644 index 0000000..116825e --- /dev/null +++ b/Scenes/UI/ui_notification.tscn @@ -0,0 +1,104 @@ +[gd_scene format=3 uid="uid://c4tdg221rvm53"] + +[ext_resource type="Script" uid="uid://y3jtgv0vknvk" path="res://Scenes/UI/ui_notification.gd" id="1_7y7gh"] + +[sub_resource type="Animation" id="Animation_8qs5e"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Base:position:y") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [-50.0] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Base:modulate:a") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [1.0] +} + +[sub_resource type="Animation" id="Animation_np30a"] +resource_name = "show_notification" +length = 3.0000000000000004 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Base:position:y") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.29999995), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [-50.0, 10.0] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Base:modulate:a") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 1.5, 3), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [1.0, 1.0, 0.0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_7ag70"] +_data = { +&"RESET": SubResource("Animation_8qs5e"), +&"show_notification": SubResource("Animation_np30a") +} + +[node name="UiNotification" type="Control" unique_id=1468421214] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +script = ExtResource("1_7y7gh") + +[node name="Base" type="PanelContainer" parent="." unique_id=870318481] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -79.0 +offset_top = -50.0 +offset_right = 79.0 +offset_bottom = -7.0 +grow_horizontal = 2 + +[node name="Margin" type="MarginContainer" parent="Base" unique_id=716680500] +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Message" type="RichTextLabel" parent="Base/Margin" unique_id=438265807] +layout_mode = 2 +bbcode_enabled = true +text = "Example message" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=152270752] +libraries/ = SubResource("AnimationLibrary_7ag70")