# 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 . # 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)