-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrompt.cs
90 lines (81 loc) · 3.71 KB
/
Prompt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DiceGame {
public static class Login {
public static async Task<LoginData> ShowDialog(string text, string caption) {
Form login = new Form() {
Width = 500,
Height = 170,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Width = 400, Left = 50, Top = 20, Text = text };
TextBox username = new TextBox() { Text=DatabaseConn.getUsername() == "Player" ? "" : DatabaseConn.getUsername(), Left = 50, Top = 50, Width = 400 };
TextBox password = new TextBox() { Left = 50, Top = 70, Width = 400 };
Button confirmation = new Button() { Text = "Login", Left = 350, Width = 100, Top = 90, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { login.Close(); };
login.Controls.Add(username);
login.Controls.Add(password);
login.Controls.Add(confirmation);
login.Controls.Add(textLabel);
login.AcceptButton = confirmation;
LoginData data = new LoginData();
if (login.ShowDialog() == DialogResult.OK) {
var x = new DatabaseConn(username.Text, password.Text);
var y = await x.Download();
return y;
} else {
return data;
}
}
}
public class LoginData {
public string username = "Guest";
public int money = 10000;
public string image;
}
public static class Prompt {
public static string ShowDialog(string text, string caption) {
Form prompt = new Form() {
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Width = 400, Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
}
public static class Alert {
public static string ShowDialog(string text, string caption) {
Form alert = new Form() {
Width = 500,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = caption,
StartPosition = FormStartPosition.CenterScreen
};
Label textLabel = new Label() { Width = 400, Left = 50, Top = 20, Text = text };
TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { alert.Close(); };
alert.Controls.Add(confirmation);
alert.Controls.Add(textLabel);
alert.AcceptButton = confirmation;
return alert.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
}
}