diff options
Diffstat (limited to 'client/menu/chat')
-rw-r--r-- | client/menu/chat/chat_message.gd | 29 | ||||
-rw-r--r-- | client/menu/chat/chat_message.tscn | 35 | ||||
-rw-r--r-- | client/menu/chat/chat_open.gd | 47 | ||||
-rw-r--r-- | client/menu/chat/chat_open.tscn | 50 | ||||
-rw-r--r-- | client/menu/chat/chat_preview.gd | 33 | ||||
-rw-r--r-- | client/menu/chat/chat_preview.tscn | 39 |
6 files changed, 233 insertions, 0 deletions
diff --git a/client/menu/chat/chat_message.gd b/client/menu/chat/chat_message.gd new file mode 100644 index 00000000..99a4a520 --- /dev/null +++ b/client/menu/chat/chat_message.gd @@ -0,0 +1,29 @@ +# 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 PanelContainer +class_name ChatMessage + +@onready var fade_away_timer = $FadeAway + +func set_message(username: String, message: String, fade_away: bool = false, fade_time: float = 5.): + $VBox/Sender.text = username + $VBox/Message.text = message + + if fade_away: + fade_away_timer.start(fade_time) + +func _on_fade_away_timeout() -> void: + queue_free() diff --git a/client/menu/chat/chat_message.tscn b/client/menu/chat/chat_message.tscn new file mode 100644 index 00000000..84ccb402 --- /dev/null +++ b/client/menu/chat/chat_message.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=5 format=3 uid="uid://bpc2qgsvcafhe"] + +[ext_resource type="Script" path="res://menu/chat/chat_message.gd" id="1_ey0qp"] +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_rx6vg"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ocjra"] + +[sub_resource type="FontVariation" id="FontVariation_jfhbh"] +variation_embolden = 1.3 + +[node name="ChatMessage" type="PanelContainer"] +offset_right = 72.0 +offset_bottom = 165.0 +theme_override_styles/panel = SubResource("StyleBoxEmpty_ocjra") +script = ExtResource("1_ey0qp") + +[node name="VBox" type="HBoxContainer" parent="."] +layout_mode = 2 +theme = ExtResource("1_rx6vg") + +[node name="Sender" type="Label" parent="VBox"] +layout_mode = 2 +theme_override_fonts/font = SubResource("FontVariation_jfhbh") +text = "<Name>" + +[node name="Message" type="Label" parent="VBox"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Message" +autowrap_mode = 3 + +[node name="FadeAway" type="Timer" parent="."] +one_shot = true + +[connection signal="timeout" from="FadeAway" to="." method="_on_fade_away_timeout"] diff --git a/client/menu/chat/chat_open.gd b/client/menu/chat/chat_open.gd new file mode 100644 index 00000000..f5b93adf --- /dev/null +++ b/client/menu/chat/chat_open.gd @@ -0,0 +1,47 @@ +# 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 Menu +class_name ChatOpen + +const CHAT_MESSAGE_SCENE = preload("res://menu/chat/chat_message.tscn") + +@onready var messages_container: VBoxContainer = $PanelContainer/MarginContainer/VBoxContainer/ScrollContainerCustom/Messages +@onready var line: LineEdit = $PanelContainer/MarginContainer/VBoxContainer/LineEdit +@onready var game_menu: GameMenu = get_parent() +@onready var game: Game = game_menu.game + +func _ready() -> void: + super() + for i in game.text_message_history: + add_message(i[0], i[1]) + + game.text_message.connect( + func message(player: int, text: String, _timeout_initial: float, _timeout_remaining: float): + add_message(player, text) + ) + +func _input(event: InputEvent) -> void: + if Input.is_action_just_pressed("chat"): + if line.text != "": + game.mp.send_chat(game.player_id, line.text) + exit() + super(event) + +func add_message(player: int, message: String): + var username: String = game.players[player].username + var chat_message: ChatMessage = CHAT_MESSAGE_SCENE.instantiate() + messages_container.add_child(chat_message) + chat_message.set_message("<%s>" % username, message) diff --git a/client/menu/chat/chat_open.tscn b/client/menu/chat/chat_open.tscn new file mode 100644 index 00000000..edd9f679 --- /dev/null +++ b/client/menu/chat/chat_open.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=5 format=3 uid="uid://dbd6k56l4p0ls"] + +[ext_resource type="Script" path="res://menu/chat/chat_open.gd" id="1_dsl4a"] +[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="1_isqmk"] +[ext_resource type="Script" path="res://menu/blur_setup.gd" id="2_urbd2"] +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="3_v7xmg"] + +[node name="ChatOpen" type="Control"] +layout_mode = 3 +anchors_preset = 9 +anchor_bottom = 1.0 +offset_right = 296.0 +grow_vertical = 2 +script = ExtResource("1_dsl4a") +support_anim = false + +[node name="PanelContainer" type="PanelContainer" parent="."] +material = ExtResource("1_isqmk") +layout_mode = 1 +anchors_preset = 9 +anchor_bottom = 1.0 +offset_right = 296.0 +grow_vertical = 2 +theme = ExtResource("3_v7xmg") +script = ExtResource("2_urbd2") + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_constants/separation = 0 + +[node name="ScrollContainerCustom" type="ScrollContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] +material = ExtResource("1_isqmk") +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +script = ExtResource("2_urbd2") + +[node name="Messages" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/ScrollContainerCustom"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="LineEdit" type="LineEdit" parent="PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +placeholder_text = "Write message" diff --git a/client/menu/chat/chat_preview.gd b/client/menu/chat/chat_preview.gd new file mode 100644 index 00000000..189ca89b --- /dev/null +++ b/client/menu/chat/chat_preview.gd @@ -0,0 +1,33 @@ +# 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 Control + +const CHAT_MESSAGE_SCENE = preload("res://menu/chat/chat_message.tscn") + +@onready var game: Game = $"../Game" +@onready var messages_container: VBoxContainer = $MarginContainer/ScrollContainer/PanelContainer/Messages + +func _ready(): + game.text_message.connect( + func message(player: int, text: String, timeout_initial: float, timeout_remaining: float): + add_message(player, text, timeout_remaining) + ) + +func add_message(player: int, message: String, time: float): + var username: String = game.players[player].username + var chat_message: ChatMessage = CHAT_MESSAGE_SCENE.instantiate() + messages_container.add_child(chat_message) + chat_message.set_message("<%s>" % username, message, true, time) diff --git a/client/menu/chat/chat_preview.tscn b/client/menu/chat/chat_preview.tscn new file mode 100644 index 00000000..a50b138a --- /dev/null +++ b/client/menu/chat/chat_preview.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=5 format=3 uid="uid://xcxbmynn8mhi"] + +[ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_x8ock"] +[ext_resource type="Script" path="res://menu/chat/chat_preview.gd" id="2_72x70"] +[ext_resource type="Material" uid="uid://beea1pc5nt67r" path="res://menu/theme/dark_blur_material.tres" id="4_jo1xn"] +[ext_resource type="Script" path="res://menu/blur_setup.gd" id="5_1l77s"] + +[node name="ChatPreview" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +theme = ExtResource("1_x8ock") +script = ExtResource("2_72x70") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 2 +anchor_bottom = 1.0 +offset_right = 296.0 +grow_vertical = 2 + +[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer"] +layout_mode = 2 +horizontal_scroll_mode = 0 + +[node name="PanelContainer" type="PanelContainer" parent="MarginContainer/ScrollContainer"] +material = ExtResource("4_jo1xn") +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 0 +mouse_filter = 2 +script = ExtResource("5_1l77s") + +[node name="Messages" type="VBoxContainer" parent="MarginContainer/ScrollContainer/PanelContainer"] +layout_mode = 2 +mouse_filter = 2 |