2024-11-03 18:16:30 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
@onready var countdown: Label = $MenuDisplay/countdown
|
2024-12-22 12:32:03 +00:00
|
|
|
@onready var btn_fullscreen = $MenuDisplay/btn_fullscreen
|
2024-12-22 13:27:13 +00:00
|
|
|
@onready var btn_save_whitelist= $MenuDisplay/btn_save_whitelist
|
2024-12-22 12:32:03 +00:00
|
|
|
var keywhitelist
|
2024-11-09 23:23:08 +00:00
|
|
|
|
2024-11-03 18:16:30 +00:00
|
|
|
func _ready():
|
|
|
|
removeAssignedKeys()
|
|
|
|
Gamestate.removeAllPlayers()
|
2024-11-09 23:45:22 +00:00
|
|
|
$Timer.stop()
|
2024-12-22 12:32:03 +00:00
|
|
|
|
|
|
|
btn_fullscreen.button_pressed=DisplayServer.window_get_mode(0)==DisplayServer.WINDOW_MODE_FULLSCREEN #toogle fullscreen switch to correct init state
|
|
|
|
|
|
|
|
btn_fullscreen.button_pressed=ConfigFileHandler.get_video_setting("fullscreen")
|
|
|
|
|
|
|
|
keywhitelist=ConfigFileHandler.get_keywhitelist_setting() #empty list if disabled
|
2024-12-22 13:27:13 +00:00
|
|
|
btn_save_whitelist.disabled=keywhitelist.size()>0 #whitelist enabled, then disable save whitelist button
|
|
|
|
btn_save_whitelist.visible=!keywhitelist.size()>0
|
2024-12-22 12:32:03 +00:00
|
|
|
print("Loaded Keywhitelist="+str(keywhitelist))
|
2024-12-29 18:52:44 +00:00
|
|
|
Gamestate.setColorwheelstepByPlayernum(keywhitelist.size())
|
2024-12-22 12:32:03 +00:00
|
|
|
|
2024-12-22 13:27:13 +00:00
|
|
|
#Preload players to set colors
|
|
|
|
if keywhitelist.size()>0: #add whitelisted players if whitelist enabled and remove them afterwards
|
2024-12-22 12:32:03 +00:00
|
|
|
for k in keywhitelist:
|
|
|
|
Gamestate.addPlayer(k)
|
|
|
|
Gamestate.removeAllPlayers()
|
|
|
|
|
|
|
|
|
2024-11-03 18:16:30 +00:00
|
|
|
|
|
|
|
func assignKeys():
|
|
|
|
var i=0
|
|
|
|
for playerkey in Gamestate.getPlayerkeys():
|
|
|
|
InputMap.add_action(Gamestate.userinput_prefix+str(i))
|
|
|
|
var ev = InputEventKey.new()
|
|
|
|
ev.keycode=playerkey
|
|
|
|
InputMap.action_add_event(Gamestate.userinput_prefix+str(i), ev)
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
func removeAssignedKeys():
|
|
|
|
for action in InputMap.get_actions():
|
|
|
|
if action.get_basename().begins_with(Gamestate.userinput_prefix):
|
|
|
|
print("Removed Action "+str(action.get_basename()))
|
|
|
|
InputMap.erase_action(action)
|
|
|
|
|
|
|
|
func _unhandled_key_input(event: InputEvent) -> void:
|
|
|
|
if event is InputEventKey:
|
|
|
|
if event.pressed:
|
2024-12-22 12:32:03 +00:00
|
|
|
if keywhitelist.has(event.keycode) or keywhitelist.size()<1:
|
|
|
|
print("Key keycode:"+str(event.keycode))
|
|
|
|
var addedID=Gamestate.addPlayer(event.keycode)
|
|
|
|
|
2024-12-22 13:27:13 +00:00
|
|
|
$MenuDisplay.update_playerlist(Gamestate.players,event.keycode)
|
2024-11-03 18:16:30 +00:00
|
|
|
|
2024-12-22 13:27:13 +00:00
|
|
|
if addedID!=-1: #player was added
|
2024-12-22 12:32:03 +00:00
|
|
|
if len(Gamestate.getPlayerkeys())>=1:
|
|
|
|
$Timer.start()
|
|
|
|
else:
|
|
|
|
$Timer.stop()
|
|
|
|
else:
|
|
|
|
print("keycode "+str(event.keycode)+" is not whitelisted")
|
2024-11-03 18:16:30 +00:00
|
|
|
|
|
|
|
|
2024-11-09 23:23:08 +00:00
|
|
|
|
2024-11-09 12:58:22 +00:00
|
|
|
func _on_timer_timeout() -> void: #Start Game
|
2024-11-03 18:16:30 +00:00
|
|
|
print("Game starting")
|
|
|
|
get_tree().change_scene_to_file("res://scenes/game.tscn")
|
|
|
|
$Timer.stop()
|
|
|
|
assignKeys()
|
|
|
|
|
2024-11-09 12:58:22 +00:00
|
|
|
|
2024-11-03 18:16:30 +00:00
|
|
|
func _process(delta: float) -> void:
|
|
|
|
if $Timer.is_stopped() or $Timer.time_left>3.5:
|
|
|
|
$MenuDisplay.updateCountdown(-1) #do not display countdown
|
|
|
|
else:
|
|
|
|
$MenuDisplay.updateCountdown(round($Timer.time_left)) #update countdown time
|
|
|
|
|
|
|
|
|
|
|
|
func _input(ev):
|
|
|
|
#if ev is InputEventKey and
|
|
|
|
if Input.is_action_just_pressed("ui_cancel"):
|
|
|
|
get_tree().quit()
|
2024-11-04 20:56:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_btn_fullscreen_toggled(toggled_on: bool) -> void:
|
|
|
|
if toggled_on:
|
|
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
|
|
|
else:
|
|
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
2024-12-22 13:27:13 +00:00
|
|
|
ConfigFileHandler.save_video_setting("fullscreen", toggled_on)
|
2024-11-09 23:23:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_rounds_selection_item_selected(index: int) -> void:
|
2024-11-09 23:45:22 +00:00
|
|
|
if not $Timer.is_stopped(): #only restart
|
|
|
|
$Timer.start()
|
2024-11-09 23:23:08 +00:00
|
|
|
|
|
|
|
func _on_map_container_map_changed() -> void:
|
2024-11-09 23:45:22 +00:00
|
|
|
if not $Timer.is_stopped(): #only restart
|
|
|
|
$Timer.start()
|
2024-12-22 12:32:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_button_pressed() -> void:
|
|
|
|
if len(Gamestate.getPlayerkeys())>=1:
|
|
|
|
var _playerkeys=Gamestate.getPlayerkeys()
|
|
|
|
print("Keys ="+str(_playerkeys))
|
|
|
|
ConfigFileHandler.save_keywhitelist_setting(_playerkeys)
|