Files
chess_game/Scripts/Controllers/GameLobby.cs

61 lines
1.8 KiB
C#

using Godot;
using Godot.Collections;
public partial class GameLobby : Control {
GlobalManager global = GlobalManager.Instance;
readonly Logging.Logger logger = Logging.GetLogger("GameLobby");
Timer timer = null!;
ItemList lists = null!;
ConfirmationDialog dialog = null!;
string URL = null!;
string userName = null!;
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
lists = GetNode<ItemList>("%ItemList_Users");
// TODO using %
dialog = GetNode<ConfirmationDialog>("Dialogs/ConfirmationDialog");
URL = global.ConfigManager.GetValue<string>("server_addr");
userName = global.ConfigManager.GetValue<string>("user_name");
dialog.MinSize = new Vector2I(400, 200);
dialog.DialogAutowrap = true;
dialog.Canceled += () => {
// TODO Cancel to Accept Session Create
};
dialog.Confirmed += () => {
if (dialog.Title == "Session Created") {
// TODO Create Session
}
};
// TODO using new State Shower And Using Heartbeat to calucate the delay time
ColorRect colorRect = GetNode<ColorRect>("MarginContainer/VBoxContainer/MarginContainer2/MarginContainer2/ColorRect");
Connect();
}
public void Connect() {
logger.Info("Connect To Server");
// TODO connet to server
global.SetProcess(true);
}
private void OnItemSelected(int index) {
Dictionary item = lists.GetItemMetadata(index).AsGodotDictionary();
logger.Debug($"Item {index} selected, {item}");
string[] _ = [item["id"].ToString()];
// TODO new a Session
}
private void FlushUserData() {
// TODO Flush user data or heartbeat flush
}
private void OnBack() {
// TODO ExitServer();
global.GotoScene("res://Main.tscn");
}
}