blob: ac71c27e928da1e429e88748f30f1a9e6f3c8bc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# Hurry Curry! - a game about cooking
# Copyright 2024 nokoe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
class_name ItemBubble
extends MeshInstance3D
@onready var base: Node3D = $SubViewport/ItemMessage/VBoxContainer/SubViewportContainer/SubViewport/ItemBase
@onready var progress: ProgressBar = $SubViewport/ItemMessage/VBoxContainer/ProgressBar
var item: Item
var timeout_remaining := 0.
var timeout_initial := 0.
var progress_style = preload("res://menu/theme/style/item_bubble_progress_style.tres")
func _init():
progress_style = progress_style.duplicate()
func set_item(t: String, timeout_initial_: float, timeout_remaining_: float):
if timeout_remaining_ == 0.:
remove_item()
return
visible = true
item = ItemFactory.produce(t, base)
base.add_child(item)
timeout_remaining = timeout_remaining_
timeout_initial = timeout_initial_
progress.max_value = timeout_initial
progress.value = timeout_remaining
func remove_item():
visible = false
if item != null:
item.queue_free()
func _process(delta):
if visible:
item.rotation.y += delta * TAU * .05
timeout_remaining -= delta
progress.value = timeout_remaining
var x: float = timeout_remaining / timeout_initial
progress_style.bg_color = Color(min((1-x) * 2, 1), min(x * 2, 1), 0.)
progress_style.corner_radius_bottom_right = max(32.-(1.-x)*320, 0)
progress.add_theme_stylebox_override("fill", progress_style)
|