feat: 重构多人游戏界面和代码,使用文件存储游戏配置,重构底层代码
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using RPPackage;
|
||||
|
||||
@ -5,28 +6,60 @@ public partial class Global : Node
|
||||
{
|
||||
public RPClientEDWS RPClient = new();
|
||||
public string sessionId;
|
||||
public string URL = "wss://game.zzyxyz.com/";
|
||||
public Node CurrentScene { get; set; }
|
||||
public Theme GlobalTheme = null;
|
||||
|
||||
readonly GodotConfigManager GlobalConfig = new("user://config.cfg");
|
||||
public Dictionary<string, Variant> GlobalConfigDict = new() {
|
||||
{"font_size", 20},
|
||||
{"server_url", "wss://game.zzyxyz.com/"},
|
||||
{"user_name", "undefined"}
|
||||
};
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
if (OS.GetName() == "Android") {
|
||||
bool ret = OS.RequestPermissions();
|
||||
GD.Print($"RequestPermissions ret is {ret}");
|
||||
}
|
||||
|
||||
// OS.RequestPermissions();
|
||||
RPClient.OnRPCError += (string errCode, string type, string cmd, string errMsg) => {
|
||||
GD.PrintErr($"errCode {errCode}, type/cmd {type}/{cmd}, errMsg {errMsg}");
|
||||
};
|
||||
RPClient.OnClose += (string eventName, object[] args) => {
|
||||
SetProcess(false);
|
||||
};
|
||||
RPClient.OnOpen += (string eventName, object[] args) => {
|
||||
RPClient.UserInit("undefined", "godot chessboard", () => {
|
||||
return RPClient.RegionAdd("server");
|
||||
});
|
||||
};
|
||||
|
||||
Viewport root = GetTree().Root;
|
||||
CurrentScene = root.GetChild(root.GetChildCount() - 1);
|
||||
|
||||
GlobalConfig.LoadConfig("Global", GlobalConfigDict);
|
||||
SetProcess(false);
|
||||
}
|
||||
|
||||
public void ConfigFlush()
|
||||
{
|
||||
int font_size = (int)GlobalConfigDict["font_size"];
|
||||
GlobalTheme.DefaultFontSize = font_size;
|
||||
// GlobalTheme?.SetFontSize("font_size", "Label", font_size);
|
||||
// GlobalTheme?.SetFontSize("font_size", "Button", font_size);
|
||||
// GlobalTheme?.SetFontSize("font_size", "TextEdit", font_size);
|
||||
// GlobalTheme?.SetFontSize("font_size", "LineEdit", font_size);
|
||||
// CurrentScene.GetWindow().AddThemeFontSizeOverride("Control", (int)GlobalConfigDict["font_size"]);
|
||||
}
|
||||
|
||||
private void OnGotoScene()
|
||||
{
|
||||
ConfigFlush();
|
||||
}
|
||||
|
||||
public void SaveConfig()
|
||||
{
|
||||
GlobalConfig.SaveConfig("Global", GlobalConfigDict);
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
@ -36,6 +69,7 @@ public partial class Global : Node
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
if (what == NotificationWMCloseRequest) {
|
||||
SaveConfig();
|
||||
RPClient.Close();
|
||||
GetTree().Quit(); // default behavior
|
||||
}
|
||||
@ -81,5 +115,7 @@ public partial class Global : Node
|
||||
|
||||
// Optionally, to make it compatible with the SceneTree.change_scene_to_file() API.
|
||||
GetTree().CurrentScene = CurrentScene;
|
||||
|
||||
OnGotoScene();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user