75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using Godot;
|
|
using ChineseChess;
|
|
|
|
public partial class ChessGame : Node2D {
|
|
GlobalManager global = GlobalManager.Instance;
|
|
readonly Logging.Logger logger = Logging.GetLogger("ChessGame");
|
|
ChessBoard board = null!;
|
|
ConfirmationDialog dialog = null!;
|
|
ChessCore Game = null!;
|
|
private bool isSession = false;
|
|
ChessCore.TurnsSideType sideSelf;
|
|
ChessCore.TurnsSideType sideOpposite;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready() {
|
|
board = GetNode<ChessBoard>("%Chessboard");
|
|
GetNode<LineEdit>("%LineEdit_YouAre").Text = global.GlobalData["player_color"].AsString();
|
|
LineEdit turnSideEdit = GetNode<LineEdit>("%LineEdit_TurnSide");
|
|
turnSideEdit.Text = "red";
|
|
|
|
dialog = new ConfirmationDialog {
|
|
DialogAutowrap = true,
|
|
MinSize = new Vector2I(400, 200),
|
|
Position = new Vector2I(200, 400),
|
|
};
|
|
AddChild(dialog);
|
|
|
|
if (global.GlobalData["player_color"].AsString() == "red") {
|
|
sideSelf = ChessCore.TurnsSideType.Red;
|
|
sideOpposite = ChessCore.TurnsSideType.Black;
|
|
} else {
|
|
sideSelf = ChessCore.TurnsSideType.Black;
|
|
sideOpposite = ChessCore.TurnsSideType.Red;
|
|
}
|
|
|
|
Game = new(isSession ? ChessCore.Mode.MultiMode : ChessCore.Mode.SingleMode, sideSelf, board);
|
|
|
|
board.OnStepsChanged += (sender, e) => {
|
|
turnSideEdit.Text = Game.GetTurnsType() == ChessCore.TurnsSideType.Red ? "red" : "black";
|
|
};
|
|
|
|
board.OnPosClicked += (sender, pos) => {
|
|
int posX = (int)pos.X;
|
|
int posY = (int)pos.Y;
|
|
Vector.Vector2I vector = new(posX, posY);
|
|
Game.OnPosClicked(vector);
|
|
};
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta) {
|
|
}
|
|
|
|
private void BtnOver() {
|
|
logger.Info($"BtnOver");
|
|
}
|
|
|
|
public void GoHome() {
|
|
// TODO ClearServer();
|
|
global.GotoScene("res://Main.tscn");
|
|
}
|
|
|
|
public void Undo() {
|
|
logger.Info($"Undo");
|
|
if (Game.board.Steps == 0) board.Clear();
|
|
Game.Undo();
|
|
}
|
|
|
|
public void ReInit() {
|
|
// TODO using dialog to confirm
|
|
logger.Info($"ReInit");
|
|
Game.ReInit();
|
|
}
|
|
}
|