blob: e643c2919409e5c49705d5cde7056c62b6664235 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# 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 ItemMessage
extends Control
const PRINTED_MAT := preload("res://gui/resources/materials/printed_material.tres")
@export var enable_rotation := true
@export var enable_grayscale := false
var timeout_remaining := 0.
var timeout_initial := 0.
@onready var item_render: ItemRender = $VBoxContainer/SubViewportContainer/SubViewport/ItemRender
@onready var progress: ProgressBar = $VBoxContainer/ProgressBar
@onready var sub_viewport: SubViewport = $VBoxContainer/SubViewportContainer/SubViewport
@onready var sub_viewport_container: SubViewportContainer = $VBoxContainer/SubViewportContainer
@onready var v_box_container: VBoxContainer = $VBoxContainer
func _ready() -> void:
Global.configure_viewport_aa(sub_viewport, Global.get_setting("graphics.aa"))
if enable_grayscale:
sub_viewport_container.material = PRINTED_MAT
func set_subviewport_size(sub_viewport_size: Vector2):
sub_viewport.size = sub_viewport_size
progress.custom_minimum_size.y = sub_viewport_size.x - sub_viewport_size.y
v_box_container.size.y = 0
func set_round_corner_radius_progress(radius: int):
var style_bg: StyleBoxFlat = progress.get_theme_stylebox("background")
var style_fill: StyleBoxFlat = progress.get_theme_stylebox("fill")
style_bg.corner_radius_bottom_left = radius
style_bg.corner_radius_bottom_right = radius
style_fill.corner_radius_bottom_left = radius
style_fill.corner_radius_bottom_right = radius
func set_item(item_name: String, timeout_initial_: float, timeout_remaining_: float):
item_render.set_item(item_name, enable_rotation)
timeout_remaining = timeout_remaining_
timeout_initial = timeout_initial_
progress.max_value = timeout_initial
progress.value = timeout_remaining
func remove_item():
item_render.remove_item()
func _process(delta):
if item_render.item != null and !Global.game_paused:
timeout_remaining -= delta
progress.value = timeout_remaining
var x: float = timeout_remaining / timeout_initial
var progress_style: StyleBoxFlat = progress.get_theme_stylebox("fill")
progress_style.bg_color = Color(min((1-x) * 2, 1), min(x * 2, 1), 0.)
progress.add_theme_stylebox_override("fill", progress_style)
|