diff options
author | tpart <tpart120@proton.me> | 2024-09-25 15:30:01 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2024-09-25 15:45:32 +0200 |
commit | 2323f3d4ba638491110be16734be9c24485caefa (patch) | |
tree | 2810e1759488b3e12976e7ef7ca508e68ded8975 /client/menu/communicate/item | |
parent | 8603ed6c5cd6ba8abc8516a25d45fdd0792bc0f8 (diff) | |
download | hurrycurry-2323f3d4ba638491110be16734be9c24485caefa.tar hurrycurry-2323f3d4ba638491110be16734be9c24485caefa.tar.bz2 hurrycurry-2323f3d4ba638491110be16734be9c24485caefa.tar.zst |
Support pinned messages
Diffstat (limited to 'client/menu/communicate/item')
-rw-r--r-- | client/menu/communicate/item/item_message.gd | 65 | ||||
-rw-r--r-- | client/menu/communicate/item/item_message.tscn | 47 | ||||
-rw-r--r-- | client/menu/communicate/item/item_render.gd | 35 | ||||
-rw-r--r-- | client/menu/communicate/item/item_render.tscn | 25 |
4 files changed, 172 insertions, 0 deletions
diff --git a/client/menu/communicate/item/item_message.gd b/client/menu/communicate/item/item_message.gd new file mode 100644 index 00000000..53e6ff22 --- /dev/null +++ b/client/menu/communicate/item/item_message.gd @@ -0,0 +1,65 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 nokoe +# Copyright 2024 tpart +# +# 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 + +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 v_box_container: VBoxContainer = $VBoxContainer + +#func _init(): +# progress_style = progress_style.duplicate() + +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) + + 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: + 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.) + if progress_style.corner_radius_bottom_right != 0: + progress_style.corner_radius_bottom_right = max(32.-(1.-x)*320, 0) + progress.add_theme_stylebox_override("fill", progress_style) diff --git a/client/menu/communicate/item/item_message.tscn b/client/menu/communicate/item/item_message.tscn new file mode 100644 index 00000000..c0b0ea95 --- /dev/null +++ b/client/menu/communicate/item/item_message.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=6 format=3 uid="uid://fkqh36s4vl3p"] + +[ext_resource type="Script" path="res://menu/communicate/item/item_message.gd" id="1_76lg0"] +[ext_resource type="PackedScene" uid="uid://cem5xcld6vn51" path="res://menu/communicate/item/item_render.tscn" id="1_sju7l"] +[ext_resource type="StyleBox" uid="uid://brw8uogdgx2gf" path="res://menu/theme/style/item_bubble_progress_style.tres" id="3_ipe76"] +[ext_resource type="StyleBox" uid="uid://cu0his4018e7h" path="res://menu/theme/style/item_bubble_progress_style_background.tres" id="3_t61n3"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dpele"] +bg_color = Color(1, 1, 1, 1) +corner_radius_top_left = 30 +corner_radius_top_right = 30 +corner_radius_bottom_right = 30 +corner_radius_bottom_left = 30 + +[node name="ItemMessage" type="PanelContainer"] +auto_translate_mode = 2 +offset_right = 256.0 +offset_bottom = 256.0 +size_flags_vertical = 0 +theme_override_styles/panel = SubResource("StyleBoxFlat_dpele") +script = ExtResource("1_76lg0") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_constants/separation = 0 + +[node name="SubViewportContainer" type="SubViewportContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="SubViewport" type="SubViewport" parent="VBoxContainer/SubViewportContainer"] +own_world_3d = true +transparent_bg = true +handle_input_locally = false +size = Vector2i(256, 224) +render_target_update_mode = 4 + +[node name="ItemRender" parent="VBoxContainer/SubViewportContainer/SubViewport" instance=ExtResource("1_sju7l")] + +[node name="ProgressBar" type="ProgressBar" parent="VBoxContainer"] +custom_minimum_size = Vector2(0, 32) +layout_mode = 2 +theme_override_styles/background = ExtResource("3_t61n3") +theme_override_styles/fill = ExtResource("3_ipe76") +step = 0.0 +value = 100.0 +show_percentage = false diff --git a/client/menu/communicate/item/item_render.gd b/client/menu/communicate/item/item_render.gd new file mode 100644 index 00000000..cd7d726a --- /dev/null +++ b/client/menu/communicate/item/item_render.gd @@ -0,0 +1,35 @@ +# Hurry Curry! - a game about cooking +# Copyright 2024 tpart +# +# 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/>. +# +extends Node3D +class_name ItemRender + +var item: Item + +@onready var base = $ItemBase + +func set_item(item_name: String): + if item != null: + remove_item() + + item = ItemFactory.produce(item_name, base) + base.add_child(item) + +func remove_item(): + if item != null: + item.queue_free() + +func _process(delta: float): + base.rotation.y += delta * TAU * .025 diff --git a/client/menu/communicate/item/item_render.tscn b/client/menu/communicate/item/item_render.tscn new file mode 100644 index 00000000..1309509e --- /dev/null +++ b/client/menu/communicate/item/item_render.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=3 format=3 uid="uid://cem5xcld6vn51"] + +[ext_resource type="Script" path="res://menu/communicate/item/item_render.gd" id="1_jfi7o"] + +[sub_resource type="Environment" id="Environment_iyxrx"] +ambient_light_source = 2 +ambient_light_color = Color(1, 1, 1, 1) +ambient_light_energy = 0.5 + +[node name="ItemRender" type="Node3D"] +script = ExtResource("1_jfi7o") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.939693, 0.34202, 0, -0.34202, 0.939693, 0, 0.5, 1) +projection = 1 +size = 0.6 + +[node name="ItemBase" type="Node3D" parent="."] + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.173648, 0.984808, 0, -0.984808, 0.173648, 0, 0, 0) +light_energy = 0.5 + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_iyxrx") |