Re-added chat alert on player rename
parent
7be3893dd5
commit
53d50c77ae
39
Game/Main.gd
39
Game/Main.gd
|
@ -1,13 +1,13 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
enum GameFocus {MENU, GAME, CHAT, AWAY, SCORETAB}
|
enum GameFocus {MENU, GAME, CHAT, AWAY}
|
||||||
enum NetworkRole {NONE, CLIENT, SERVER, DEDICATED_SERVER, RELAY_SERVER}
|
enum NetworkRole {NONE, CLIENT, SERVER, DEDICATED_SERVER, RELAY_SERVER}
|
||||||
|
|
||||||
|
|
||||||
const NET_PORT = 12597
|
const NET_PORT = 12597
|
||||||
|
|
||||||
#const NET_SERVER = "liblast.unfa.xyz"
|
const NET_SERVER = "liblast.unfa.xyz"
|
||||||
const NET_SERVER = "localhost"
|
#const NET_SERVER = "localhost"
|
||||||
|
|
||||||
var peer = ENetMultiplayerPeer.new()
|
var peer = ENetMultiplayerPeer.new()
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ var focus = GameFocus.MENU :
|
||||||
3:
|
3:
|
||||||
if local_player:
|
if local_player:
|
||||||
local_player.input_active = true
|
local_player.input_active = true
|
||||||
|
|
||||||
focus = new_focus
|
focus = new_focus
|
||||||
|
|
||||||
#@remote set_info(info) -> void:
|
#@remote set_info(info) -> void:
|
||||||
|
@ -169,18 +169,8 @@ func _input(_event) -> void:
|
||||||
focus = GameFocus.MENU
|
focus = GameFocus.MENU
|
||||||
elif focus == GameFocus.MENU:
|
elif focus == GameFocus.MENU:
|
||||||
focus = GameFocus.GAME
|
focus = GameFocus.GAME
|
||||||
|
|
||||||
if Input.is_action_just_pressed("show_scoretab"):
|
#@remote func st(player_list):
|
||||||
if focus == GameFocus.GAME:
|
|
||||||
focus = GameFocus.SCORETAB
|
|
||||||
hud.score_table(true)
|
|
||||||
|
|
||||||
elif Input.is_action_just_released("show_scoretab"):
|
|
||||||
if focus == GameFocus.SCORETAB:
|
|
||||||
focus = GameFocus.GAME
|
|
||||||
hud.score_table(false)
|
|
||||||
|
|
||||||
#@remote func update_player_list(player_list):
|
|
||||||
# self.player_list = player_list
|
# self.player_list = player_list
|
||||||
|
|
||||||
func game_over():
|
func game_over():
|
||||||
|
@ -221,28 +211,27 @@ func update_hud():
|
||||||
else:
|
else:
|
||||||
hud.get_node("ScoreRank").text += str(rank) + "\nGAP: " + str(-lead)
|
hud.get_node("ScoreRank").text += str(rank) + "\nGAP: " + str(-lead)
|
||||||
|
|
||||||
@rpc(any) func player_list_update(info, pid = get_tree().get_rpc_sender_id()):
|
@rpc(any, reliable) func player_list_update(info, pid = get_tree().get_rpc_sender_id()):
|
||||||
var new_info = PlayerInfo.new()
|
var new_info = PlayerInfo.new()
|
||||||
new_info.deserialize(info)
|
new_info.deserialize(info)
|
||||||
|
|
||||||
|
if player_list.players.has(pid):
|
||||||
|
var old_name = player_list.get(pid).name
|
||||||
|
if old_name != new_info.name:
|
||||||
|
chat.chat_notification("Player [b]" + old_name + "[/b] changed name to [b]" + new_info.name + "[/b]")
|
||||||
|
|
||||||
var player = $Players.get_node(str(pid))
|
var player = $Players.get_node(str(pid))
|
||||||
player.update_player(new_info)
|
player.update_player(new_info)
|
||||||
|
|
||||||
player_list.set(pid, new_info) # server relays other PID's data
|
player_list.set(pid, new_info) # server relays other PID's data
|
||||||
|
|
||||||
# update locla HUD
|
# update local HUD
|
||||||
update_hud()
|
update_hud()
|
||||||
#if pid == get_tree().multiplayer.get_network_unique_id():
|
|
||||||
|
|
||||||
func push_local_player_info():
|
func push_local_player_info():
|
||||||
var id = get_tree().multiplayer.get_network_unique_id()
|
var id = get_tree().multiplayer.get_network_unique_id()
|
||||||
|
|
||||||
#print("PLayer info vsr2str: ", var2str(player_list.get(id)) )
|
rpc(&'player_list_update', player_list.get(id).serialize(), get_tree().multiplayer.get_network_unique_id())
|
||||||
|
|
||||||
if id != 1:
|
|
||||||
rpc_id(1, &'player_list_update', player_list.get(id).serialize(), get_tree().multiplayer.get_network_unique_id())
|
|
||||||
else:
|
|
||||||
rpc(&'player_list_update', player_list.get(id).serialize(), 1)
|
|
||||||
|
|
||||||
@rpc(sync,auth,reliable) func destroy_player(pid: int):
|
@rpc(sync,auth,reliable) func destroy_player(pid: int):
|
||||||
var player_node = $Players.get_node(str(pid))
|
var player_node = $Players.get_node(str(pid))
|
||||||
|
|
Reference in New Issue