diff options
author | nokoe <nokoe@mailbox.org> | 2024-06-26 01:06:37 +0200 |
---|---|---|
committer | nokoe <nokoe@mailbox.org> | 2024-06-26 01:07:20 +0200 |
commit | c126d3d3e84fe3b24b42afc7f68f05342988c8c9 (patch) | |
tree | 96f50b02f83852fcf3dd53e5f48ff24526d2666f | |
parent | 6b40114823cac61a92756af55e06a645a3847426 (diff) | |
download | hurrycurry-c126d3d3e84fe3b24b42afc7f68f05342988c8c9.tar hurrycurry-c126d3d3e84fe3b24b42afc7f68f05342988c8c9.tar.bz2 hurrycurry-c126d3d3e84fe3b24b42afc7f68f05342988c8c9.tar.zst |
add chat bubble, replace textmesh with label3d
-rw-r--r-- | client/game.gd | 16 | ||||
-rw-r--r-- | client/map/items/generic_item.gd | 18 | ||||
-rw-r--r-- | client/map/tiles/generic_tile.gd | 18 | ||||
-rw-r--r-- | client/player/chat_bubble.gd | 12 | ||||
-rw-r--r-- | client/player/chat_bubble.tscn | 29 | ||||
-rw-r--r-- | client/player/chat_message.tscn | 36 | ||||
-rw-r--r-- | client/player/player.gd | 11 |
7 files changed, 110 insertions, 30 deletions
diff --git a/client/game.gd b/client/game.gd index 7e954857..16522706 100644 --- a/client/game.gd +++ b/client/game.gd @@ -138,6 +138,22 @@ func _ready(): var t: Tile = tile_by_pos[str(tile)][1] t.finish(warn) ) + + mp.text_message.connect(func(player: int, text: String): + var p: Player = players[player] + p.bubble.set_text(text) + ) + + mp.clear_message.connect(func(player: int): + var p: Player = players[player] + p.bubble.remove_text() + ) + + mp.item_message.connect(func(player: int, item: int): + var p: Player = players[player] + p.bubble.set_text(item_names[item]) + ) + mp.send_join(Global.username, Global.character) func _process(delta): diff --git a/client/map/items/generic_item.gd b/client/map/items/generic_item.gd index be9d5a0a..d1cbc41a 100644 --- a/client/map/items/generic_item.gd +++ b/client/map/items/generic_item.gd @@ -19,16 +19,8 @@ extends Item func _init(owned_by_: Node3D, t: String): super(owned_by_) #add_child(load("res://models/prefabs/map/bag.tscn").instantiate()) - var mesh = MeshInstance3D.new() - var text = TextMesh.new() - var mat = StandardMaterial3D.new() - text.text = t - text.font = SystemFont.new() - text.depth = 0 - mesh.mesh = text - mesh.position.y = 0.5 - mesh.scale = Vector3(3, 3, 3) - mat.billboard_mode = mat.BILLBOARD_ENABLED - mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED - text.material = mat - base.add_child(mesh) + var label = Label3D.new() + label.text = t + label.position.y = 0.5 + label.billboard = BaseMaterial3D.BILLBOARD_ENABLED + base.add_child(label) diff --git a/client/map/tiles/generic_tile.gd b/client/map/tiles/generic_tile.gd index f7d1b4a7..48e82dee 100644 --- a/client/map/tiles/generic_tile.gd +++ b/client/map/tiles/generic_tile.gd @@ -18,16 +18,8 @@ extends Floor func _init(rename: String, neighbors: Array, kind: String): super(rename, neighbors) - var mesh = MeshInstance3D.new() - var text = TextMesh.new() - var mat = StandardMaterial3D.new() - text.text = kind - text.font = SystemFont.new() - text.depth = 0 - mesh.mesh = text - mesh.position.y = 1 - mesh.scale = Vector3(3, 3, 3) - mat.billboard_mode = mat.BILLBOARD_ENABLED - mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED - text.material = mat - item_base.add_child(mesh) + var label = Label3D.new() + label.text = kind + label.position.y = 0.5 + label.billboard = BaseMaterial3D.BILLBOARD_ENABLED + item_base.add_child(label) diff --git a/client/player/chat_bubble.gd b/client/player/chat_bubble.gd new file mode 100644 index 00000000..6b09b69b --- /dev/null +++ b/client/player/chat_bubble.gd @@ -0,0 +1,12 @@ +class_name ChatBubble +extends MeshInstance3D + +@onready var label: Label = $SubViewport/ChatMessage/Label + +func set_text(t: String): + visible = true + label.text = t + +func remove_text(): + visible = false + label.text = "" diff --git a/client/player/chat_bubble.tscn b/client/player/chat_bubble.tscn new file mode 100644 index 00000000..1a5f7dfc --- /dev/null +++ b/client/player/chat_bubble.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=6 format=3 uid="uid://cgi6vcfrnqp0i"] + +[ext_resource type="Script" path="res://player/chat_bubble.gd" id="1_4v1cx"] +[ext_resource type="PackedScene" uid="uid://5rcfoyuiwuya" path="res://player/chat_message.tscn" id="2_lyyq0"] + +[sub_resource type="QuadMesh" id="QuadMesh_tlsxo"] +size = Vector2(2, 0.5) + +[sub_resource type="ViewportTexture" id="ViewportTexture_mko8a"] +viewport_path = NodePath("SubViewport") + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5iy0t"] +resource_local_to_scene = true +transparency = 1 +albedo_texture = SubResource("ViewportTexture_mko8a") +billboard_mode = 2 + +[node name="ChatBubble" type="MeshInstance3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) +visible = false +mesh = SubResource("QuadMesh_tlsxo") +surface_material_override/0 = SubResource("StandardMaterial3D_5iy0t") +script = ExtResource("1_4v1cx") + +[node name="SubViewport" type="SubViewport" parent="."] +transparent_bg = true +size = Vector2i(512, 128) + +[node name="ChatMessage" parent="SubViewport" instance=ExtResource("2_lyyq0")] diff --git a/client/player/chat_message.tscn b/client/player/chat_message.tscn new file mode 100644 index 00000000..1ac82368 --- /dev/null +++ b/client/player/chat_message.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=4 format=3 uid="uid://5rcfoyuiwuya"] + +[ext_resource type="FontFile" uid="uid://5ixo6b3bd3km" path="res://menu/font-josefin-sans.woff2" id="1_3ximm"] + +[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 + +[sub_resource type="FontVariation" id="FontVariation_ecurp"] +base_font = ExtResource("1_3ximm") +variation_embolden = 1.0 + +[node name="ChatMessage" type="Panel"] +offset_right = 512.0 +offset_bottom = 128.0 +auto_translate = false +theme_override_styles/panel = SubResource("StyleBoxFlat_dpele") + +[node name="Label" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +auto_translate = false +theme_override_colors/font_color = Color(0, 0, 0, 1) +theme_override_fonts/font = SubResource("FontVariation_ecurp") +theme_override_font_sizes/font_size = 40 +horizontal_alignment = 1 +vertical_alignment = 1 +autowrap_mode = 3 +text_overrun_behavior = 3 diff --git a/client/player/player.gd b/client/player/player.gd index 5873c9ef..4a5cfa6a 100644 --- a/client/player/player.gd +++ b/client/player/player.gd @@ -2,19 +2,19 @@ # Copyright 2024 nokoe # Copyright 2024 metamuffin # 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 Player extends Node3D @@ -28,6 +28,7 @@ var position_ = Vector2(0, 0) var position_anim = Vector2(0, 0) var character: Character = preload("res://player/character/character.tscn").instantiate() +var bubble: ChatBubble = preload("res://player/chat_bubble.tscn").instantiate() var hand: Item = null var hand_base: Node3D = Node3D.new() @@ -45,6 +46,8 @@ func _init(_id: int, new_name: String, pos: Vector2, _character: int, new_game: hand_base.position = HAND_BASE_POSITION add_child(hand_base) + add_child(bubble) + func update_position(new_position: Vector2, new_rotation: float): position_ = new_position rotation_ = new_rotation |