Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
LoginDialog.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
4 public class LoginDialog : Dialog {
5 public Action<byte[]> succ;
6 public Action<Exception> fail;
10 public BusyDialog busyDialog = new("提示", "登录中");
11
12 public LabelWidget tip = new() {
14 };
15
16 public Action cancel;
17
18 public LoginDialog() {
19 CanvasWidget canvasWidget = new() {
21 };
22 RectangleWidget rectangleWidget = new() {
23 FillColor = new Color(0, 0, 0, 255), OutlineColor = new Color(128, 128, 128, 128), OutlineThickness = 2
24 };
25 StackPanelWidget stackPanelWidget = new() {
26 Direction = LayoutDirection.Vertical,
29 Margin = new Vector2(10f, 10f)
30 };
31 Children.Add(canvasWidget);
32 canvasWidget.Children.Add(rectangleWidget);
33 canvasWidget.Children.Add(stackPanelWidget);
34 MainView = stackPanelWidget;
35 MainView.Children.Add(tip);
36 MainView.Children.Add(makeTextBox("账号:"));
37 MainView.Children.Add(makeTextBox("密码:", true));
38 MainView.Children.Add(makeButton());
39 }
40
41 public Widget makeTextBox(string title, bool passwordMode = false) {
42 CanvasWidget canvasWidget = new() { Margin = new Vector2(10, 0) };
43 RectangleWidget rectangleWidget = new() {
44 FillColor = Color.Black, OutlineColor = Color.White, Size = new Vector2(float.PositiveInfinity, 80)
45 };
46 StackPanelWidget stack = new() { Direction = LayoutDirection.Horizontal };
47 LabelWidget label = new() {
48 HorizontalAlignment = WidgetAlignment.Near, VerticalAlignment = WidgetAlignment.Near, Text = title, Margin = new Vector2(1f, 1f)
49 };
50 TextBoxWidget textBox = new() {
51 PasswordMode = passwordMode,
54 Color = new Color(255, 255, 255),
55 Margin = new Vector2(4f, 0f),
56 Size = new Vector2(float.PositiveInfinity, 80)
57 };
58 if (title == "账号:") {
59 txa = textBox;
60 }
61 if (title == "密码:") {
62 txb = textBox;
63 }
64 stack.Children.Add(label);
65 stack.Children.Add(textBox);
66 canvasWidget.Children.Add(rectangleWidget);
67 canvasWidget.Children.Add(stack);
68 return canvasWidget;
69 }
70
71 public Widget makeButton() {
72 StackPanelWidget stack = new() { Direction = LayoutDirection.Horizontal };
73 BevelledButtonWidget bevelledButtonWidget1 = new() { Size = new Vector2(160, 60), Margin = new Vector2(4f, 0), Text = "登录" };
74 BevelledButtonWidget bevelledButtonWidget2 = new() { Size = new Vector2(160, 60), Margin = new Vector2(4f, 0), Text = "注册" };
75 BevelledButtonWidget bevelledButtonWidget3 = new() { Size = new Vector2(160, 60), Margin = new Vector2(4f, 0), Text = "取消" };
76 stack.Children.Add(bevelledButtonWidget1);
77 stack.Children.Add(bevelledButtonWidget2);
78 stack.Children.Add(bevelledButtonWidget3);
79 btna = bevelledButtonWidget1;
80 btnb = bevelledButtonWidget2;
81 btnc = bevelledButtonWidget3;
82 return stack;
83 }
84
85 public override void Update() {
86 if (btna.IsClicked) {
87 Dictionary<string, string> par = new() { { "user", txa.Text }, { "pass", txb.Text } };
90 $"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/api/login",
91 par,
92 null,
93 new MemoryStream(),
95 succ,
96 fail
97 );
98 }
99 if (btnb.IsClicked) {
100 WebBrowserManager.LaunchBrowser($"{CommunityServerManager.CurrentChineseInfo.ApiUrl}/com/reg");
101 }
102 if (btnc.IsClicked) {
103 cancel?.Invoke();
104 }
105 }
106 }
107}
Engine.Color Color
readonly WidgetsList Children
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
Action< byte[]> succ
Widget makeTextBox(string title, bool passwordMode=false)
StackPanelWidget MainView
TextBoxWidget txb
TextBoxWidget txa
override void Update()
BevelledButtonWidget btna
BevelledButtonWidget btnc
Action< Exception > fail
BevelledButtonWidget btnb
static void LaunchBrowser(string url)
static void Post(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, Stream data, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
virtual WidgetAlignment VerticalAlignment
virtual Vector2 Margin
virtual WidgetAlignment HorizontalAlignment
void Add(Widget widget)
static Color White
static Color Black
定义 Color.cs:7