Compare commits

...

3 Commits

Author SHA1 Message Date
bb7f8ead08 add chat 2025-02-13 23:35:52 +10:00
bb3b75929a return jumping to _physics_process 2025-02-13 23:35:49 +10:00
c57c724f0a change _input to _unhandled_input in most classes 2025-02-13 23:15:47 +10:00
11 changed files with 182 additions and 16 deletions

View File

@ -160,6 +160,11 @@ look_slow={
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":8,"pressure":0.0,"pressed":true,"script":null)
]
}
chat={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"location":0,"echo":false,"script":null)
]
}
[layer_names]

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://b7fc42grqckl0"]
[gd_scene load_steps=5 format=3 uid="uid://b7fc42grqckl0"]
[ext_resource type="Script" path="res://scripts/main.gd" id="1_80y7k"]
[ext_resource type="PackedScene" uid="uid://b3t5vrqb1eym2" path="res://scenes/ui/chat.tscn" id="3_8t1rc"]
[ext_resource type="Material" uid="uid://00ldcihmubqo" path="res://resources/materials/test_triplanar.tres" id="3_vk6ds"]
[sub_resource type="Environment" id="Environment_wyusq"]
@ -27,6 +28,10 @@ transform = Transform3D(0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, -0.75
shadow_enabled = true
shadow_blur = 2.0
[node name="UI" type="Node" parent="."]
[node name="Chat" parent="UI" instance=ExtResource("3_8t1rc")]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_wyusq")

51
scenes/ui/chat.tscn Normal file
View File

@ -0,0 +1,51 @@
[gd_scene load_steps=2 format=3 uid="uid://b3t5vrqb1eym2"]
[ext_resource type="Script" path="res://scripts/ui/chat.gd" id="1_ulx3h"]
[node name="Chat" type="CanvasLayer"]
script = ExtResource("1_ulx3h")
[node name="Root" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 20
[node name="VBox" type="VBoxContainer" parent="Root"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/separation = 0
[node name="MsgScroll" type="ScrollContainer" parent="Root/VBox"]
layout_mode = 2
size_flags_vertical = 3
mouse_filter = 2
horizontal_scroll_mode = 0
[node name="MsgMargin" type="MarginContainer" parent="Root/VBox/MsgScroll"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 30
[node name="MsgContainer" type="VBoxContainer" parent="Root/VBox/MsgScroll/MsgMargin"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
alignment = 2
[node name="MessageEdit" type="LineEdit" parent="Root/VBox"]
layout_mode = 2
theme_override_font_sizes/font_size = 26

View File

@ -0,0 +1,20 @@
[gd_scene format=3 uid="uid://bjrbngxkvhn7f"]
[node name="RichTextLabel" type="RichTextLabel"]
clip_contents = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_colors/font_outline_color = Color(0, 0, 0, 0.501961)
theme_override_constants/outline_size = 20
theme_override_font_sizes/bold_italics_font_size = 26
theme_override_font_sizes/italics_font_size = 26
theme_override_font_sizes/mono_font_size = 26
theme_override_font_sizes/normal_font_size = 26
theme_override_font_sizes/bold_font_size = 26
bbcode_enabled = true
text = "[b]name:[/b] lorem ipsum"
fit_content = true

View File

@ -50,7 +50,7 @@ func _process(_delta: float) -> void:
_control.queue_redraw()
func _input(event: InputEvent) -> void:
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_debug"):
mode = wrapi(mode + 1, 0, Mode.size()) as Mode
_update_visibility()

View File

@ -5,7 +5,7 @@ func _ready() -> void:
Referencer.main_loaded.connect(_on_referencer_main_loaded)
func _input(event: InputEvent) -> void:
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("toggle_cursor_capture"):
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

View File

@ -43,7 +43,6 @@ func _input(event: InputEvent) -> void:
var event_mode := _get_event_mode(event)
if mode == Mode.KB_MOUSE and event_mode == Mode.CONTROLLER:
mode = Mode.CONTROLLER
mode_changed.emit(mode)
if mode == Mode.CONTROLLER and event_mode == Mode.KB_MOUSE:

View File

@ -9,3 +9,4 @@ var main: Main:
if value:
main_loaded.emit()
main = value
var chat: Chat

View File

@ -16,7 +16,7 @@ func _exit_tree() -> void:
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
if event.is_action_pressed("menu") and not Referencer.chat.open:
get_tree().quit()

View File

@ -22,6 +22,9 @@ var _peer_id: int = 1
var _respawn_point: Vector3
var _default_camera_height: float
var _crouch: bool = false
var _run: bool = false
@onready var _camera: Camera3D = $Camera3D
@onready var _name_label: Label3D = $NameLabel
@ -76,7 +79,7 @@ func _physics_process(delta: float) -> void:
_lateral_movement(delta)
_vertical_movement(delta)
_jumping(delta)
_jumping()
move_and_slide()
@ -85,9 +88,21 @@ func _unhandled_input(event: InputEvent) -> void:
if not is_multiplayer_authority():
return
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
_handle_mouse_rotating(event as InputEventMouseMotion)
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
return
if event is InputEventMouseMotion:
_handle_mouse_rotating(event as InputEventMouseMotion)
if event.is_action_pressed("crouch"):
_crouch = true
if event.is_action_released("crouch"):
_crouch = false
if event.is_action_pressed("run"):
_run = true
if event.is_action_released("run"):
_run = false
func set_info(player_info: Dictionary) -> void:
@ -136,14 +151,14 @@ func _process_controller_rotating(delta: float) -> void:
func _process_camera(delta: float) -> void:
var camera_height := _default_camera_height
if Input.is_action_pressed("crouch"):
if _crouch:
camera_height = CAMERA_CROUCH_HEIGHT
_camera.position.y = move_toward(
_camera.position.y, camera_height, CAMERA_HEIGHT_SPEED * delta
)
var camera_fov := Settings.camera_fov
if Input.is_action_pressed("run"):
if _run:
camera_fov += CAMERA_RUN_EXTRA_FOV
_camera.fov = move_toward(_camera.fov, camera_fov, CAMERA_FOV_SPEED * delta)
@ -152,7 +167,9 @@ func _lateral_movement(delta: float) -> void:
var input_dir := Input.get_vector(
"move_left", "move_right", "move_forward", "move_back"
)
var has_input := input_dir.length() > 0
var has_input := (
input_dir.length() > 0 and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
)
if has_input:
var direction := (
@ -160,10 +177,10 @@ func _lateral_movement(delta: float) -> void:
)
var speed := MOVE_SPEED
Debugger.text("move_mode", "move", 2)
if Input.is_action_pressed("crouch"):
if _crouch:
speed = CROUCH_SPEED
Debugger.text("move_mode", "crouch", 2)
if Input.is_action_pressed("run"):
if _run:
speed = RUN_SPEED
Debugger.text("move_mode", "run", 2)
var new_velocity := direction * speed
@ -184,8 +201,12 @@ func _vertical_movement(delta: float) -> void:
velocity.y = 0
func _jumping(_delta: float) -> void:
if Input.is_action_just_pressed("jump") and is_on_floor():
func _jumping() -> void:
if (
Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED
and Input.is_action_just_pressed("jump")
and is_on_floor()
):
velocity.y = JUMP_FORCE

64
scripts/ui/chat.gd Normal file
View File

@ -0,0 +1,64 @@
class_name Chat
extends CanvasLayer
var open: bool = false
var _chat_message_scene := preload("res://scenes/ui/chat_message.tscn")
@onready var _messages_container: Container = $Root/VBox/MsgScroll/MsgMargin/MsgContainer
@onready var _message_edit: LineEdit = $Root/VBox/MessageEdit
func _ready() -> void:
_message_edit.text_submitted.connect(_on_message_edit_text_submitted)
_message_edit.visible = false
Referencer.chat = self
func _exit_tree() -> void:
Referencer.chat = null
func _input(event: InputEvent) -> void:
if event.is_action_pressed("menu"):
call_deferred("_close")
func _unhandled_input(event: InputEvent) -> void:
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
return
if event.is_action_pressed("chat") and not open:
open = true
_message_edit.visible = true
_message_edit.grab_focus()
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func _close() -> void:
open = false
_message_edit.release_focus()
_message_edit.visible = false
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@rpc("any_peer", "call_local", "reliable", 1)
func _send_message(message: String) -> void:
var player_name := (
Networker.players[multiplayer.get_remote_sender_id()]["name"] as String
)
var message_node := _make_message_node(player_name, message)
_messages_container.add_child(message_node)
print(player_name + ": " + message)
func _make_message_node(player_name: String, message: String) -> RichTextLabel:
var node := _chat_message_scene.instantiate() as RichTextLabel
node.text = "[b]" + player_name + ":[/b]\t" + message
return node
func _on_message_edit_text_submitted(message: String) -> void:
_message_edit.text = ""
_send_message.rpc(message)