teststrecke-game/scripts/menudisplay.gd

55 lines
2.1 KiB
GDScript

extends Node2D
const ADD_STEP_OUTLINESIZE=30
const MAX_OUTLINESIZE=60
@onready var playerlist_particles_2d: CPUParticles2D = $MarginContainer/PlayerlistParticles2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func updateCountdown(t):
if (t<0):
$countdown.visible=false
else:
$countdown.visible=true
$countdown.text=str(t)
func update_playerlist(players:Array[Gamestate.Player],flashplayer_keycode=-1,effect="blink"):
var Playerlabels=$MarginContainer/VBoxContainer_Playerlist.get_children()
var i=0
for label in Playerlabels:
if i<len(players):
var p=players[i]
label.text=str(OS.get_keycode_string(p.inputkey))
if (p.inputkey==flashplayer_keycode): #this player should show an animation
if effect=="blink":
var outlinesize=min(max(0,label.get_theme_constant("outline_size")+ADD_STEP_OUTLINESIZE),MAX_OUTLINESIZE) #enlarge outline a bit
label.add_theme_constant_override("outline_size",outlinesize)
if effect=="explode":
var outlinesize=MAX_OUTLINESIZE
label.add_theme_constant_override("outline_size",outlinesize) #make outline max size
var font_size=label.get_theme_font_size("font_size")
var new_playerlist_particles_2d=playerlist_particles_2d.duplicate()
$MarginContainer.add_child(new_playerlist_particles_2d)
new_playerlist_particles_2d.position=label.position+Vector2(font_size/3,font_size*0.75) #try to center on text
new_playerlist_particles_2d.emitting=true
new_playerlist_particles_2d.emission_rect_extents=Vector2(font_size/3,font_size*0.75)*2
new_playerlist_particles_2d.color=p.color
label.set("theme_override_colors/font_color",p.color)
else:
label.text=""
i+=1
func _process(delta: float) -> void:
var Playerlabels=$MarginContainer/VBoxContainer_Playerlist.get_children()
for label in Playerlabels:
var outlinesize=max(0,label.get_theme_constant("outline_size")-2*delta)
label.add_theme_constant_override("outline_size",outlinesize)