Player labels display when far from player

This commit is contained in:
Rob Kelly 2024-11-22 11:13:19 -07:00
parent 486cb17604
commit 162f2237d4
6 changed files with 44 additions and 4 deletions

View File

@ -16,7 +16,7 @@ Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true

View File

@ -16,7 +16,7 @@ Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true

View File

@ -16,7 +16,7 @@ Rendering=null
antialiasing=1
generate_mipmaps=true
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
multichannel_signed_distance_field=true
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true

View File

@ -161,6 +161,7 @@ var _tracking_camera: OrbitalCamera
@onready var ball_return_timer: Timer = %BallReturnTimer
@onready var explosion_animation: AnimationPlayer = %ExplosionAnimation
@onready var player_label: Label3D = %PlayerLabel
@onready var camera_distance := zoom.position.z:
set = _set_camera_distance
@ -180,6 +181,12 @@ func _ready() -> void:
ball_type = initial_ball
club = initial_club
character.set_color(player.color)
# Set up player 3D label
player_label.text = player.name
player_label.modulate = player.color
player_label.outline_modulate = ColorTools.get_bg_color(player.color)
_on_phase_change(phase)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=22 format=3 uid="uid://cy7t2tc4y3b4"]
[gd_scene load_steps=23 format=3 uid="uid://cy7t2tc4y3b4"]
[ext_resource type="Script" path="res://src/player/shot_setup/shot_setup.gd" id="1_r6ei4"]
[ext_resource type="Script" path="res://src/player/shot_setup/ball_point.gd" id="2_e6i3g"]
@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://dbdul15c4oblg" path="res://src/ui/3d/projected_target.tscn" id="6_mynqj"]
[ext_resource type="Script" path="res://src/player/shot_setup/hitbox.gd" id="7_uh8kn"]
[ext_resource type="Texture2D" uid="uid://2yoipvd107t1" path="res://assets/sprites/dope_explosion/dope_explosion.tres" id="8_5ghmo"]
[ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="9_y5iv1"]
[sub_resource type="Animation" id="Animation_ug2a7"]
length = 0.001
@ -422,6 +423,27 @@ libraries = {
"": SubResource("AnimationLibrary_dg262")
}
[node name="PlayerLabel" type="Label3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3, 0)
visibility_range_begin = 50.0
visibility_range_begin_margin = 3.0
visibility_range_fade_mode = 1
pixel_size = 0.001
billboard = 1
no_depth_test = true
fixed_size = true
texture_filter = 5
render_priority = 4
outline_render_priority = 3
text = "Player Name"
font = ExtResource("9_y5iv1")
font_size = 36
outline_size = 10
line_spacing = -16.0
autowrap_mode = 2
width = 120.0
[connection signal="ball_changed" from="BallPoint" to="." method="_on_game_ball_changed"]
[connection signal="timeout" from="DownswingTimer" to="." method="finish_downswing"]
[connection signal="timeout" from="BallReturnTimer" to="." method="_on_ball_return_timer_timeout"]

11
src/util/color_tools.gd Normal file
View File

@ -0,0 +1,11 @@
class_name ColorTools
## Toolkit for working with colors
const DEFAULT_LUM_THRESHOLD := 0.179
## Selects an appropriate background color for the given foreground color.
##
## Options are white or black.
static func get_bg_color(fg_color: Color, threshold: float = DEFAULT_LUM_THRESHOLD) -> Color:
return Color.BLACK if fg_color.srgb_to_linear().get_luminance() > threshold else Color.WHITE