-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddMapDialog.cs
More file actions
136 lines (118 loc) · 4.58 KB
/
AddMapDialog.cs
File metadata and controls
136 lines (118 loc) · 4.58 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MapsDatEditor
{
public class AddMapDialog : Form
{
public Structs.MapEntry NewMap { get; private set; } = new();
private NumericUpDown _nudId, _nudSizeX, _nudSizeY, _nudFlags, _nudMusic;
private TextBox _txtName;
public AddMapDialog()
{
Text = "Add New Map";
Size = new Size(380, 280);
FormBorderStyle = FormBorderStyle.FixedDialog;
StartPosition = FormStartPosition.CenterParent;
MaximizeBox = false;
MinimizeBox = false;
BackColor = Color.FromArgb(30, 30, 36);
ForeColor = Color.FromArgb(210, 214, 224);
Font = new Font("Segoe UI", 9f);
var table = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 2,
Padding = new Padding(16)
};
table.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
int row = 0;
table.Controls.Add(MakeLabel("Map ID:"), 0, row);
_nudId = MakeNud(-32768, 32767, 0);
table.Controls.Add(_nudId, 1, row++);
table.Controls.Add(MakeLabel("Name:"), 0, row);
_txtName = new TextBox
{
Width = 200,
BackColor = Color.FromArgb(18, 20, 26),
ForeColor = Color.FromArgb(210, 214, 224),
BorderStyle = BorderStyle.FixedSingle
};
table.Controls.Add(_txtName, 1, row++);
table.Controls.Add(MakeLabel("Size X:"), 0, row);
_nudSizeX = MakeNud(0, 255, 10);
table.Controls.Add(_nudSizeX, 1, row++);
table.Controls.Add(MakeLabel("Size Y:"), 0, row);
_nudSizeY = MakeNud(0, 255, 10);
table.Controls.Add(_nudSizeY, 1, row++);
table.Controls.Add(MakeLabel("Flags:"), 0, row);
_nudFlags = MakeNud(0, 255, 0);
table.Controls.Add(_nudFlags, 1, row++);
table.Controls.Add(MakeLabel("Music:"), 0, row);
_nudMusic = MakeNud(-128, 127, -1);
table.Controls.Add(_nudMusic, 1, row++);
var btnPanel = new FlowLayoutPanel
{
FlowDirection = FlowDirection.RightToLeft,
Dock = DockStyle.Bottom,
Height = 44,
Padding = new Padding(8)
};
var btnCancel = new Button
{
Text = "Cancel",
DialogResult = DialogResult.Cancel,
FlatStyle = FlatStyle.Flat,
BackColor = Color.FromArgb(60, 63, 75),
ForeColor = Color.White,
Height = 28
};
btnCancel.FlatAppearance.BorderSize = 0;
var btnOk = new Button
{
Text = "Add Map",
FlatStyle = FlatStyle.Flat,
BackColor = Color.FromArgb(34, 197, 94),
ForeColor = Color.White,
Height = 28
};
btnOk.FlatAppearance.BorderSize = 0;
btnOk.Click += (_, _) =>
{
NewMap = new Structs.MapEntry
{
Id = (short)_nudId.Value,
Name = _txtName.Text,
SizeX = (byte)_nudSizeX.Value,
SizeY = (byte)_nudSizeY.Value,
Flags = (byte)_nudFlags.Value,
Music = (sbyte)_nudMusic.Value
};
DialogResult = DialogResult.OK;
Close();
};
btnPanel.Controls.Add(btnCancel);
btnPanel.Controls.Add(btnOk);
Controls.Add(table);
Controls.Add(btnPanel);
AcceptButton = btnOk;
CancelButton = btnCancel;
}
private static Label MakeLabel(string text) =>
new() { Text = text, AutoSize = true, ForeColor = Color.FromArgb(140, 146, 168), Margin = new Padding(4, 8, 8, 0) };
private static NumericUpDown MakeNud(int min, int max, int val) =>
new()
{
Minimum = min,
Maximum = max,
Value = Math.Clamp(val, min, max),
Width = 100,
BackColor = Color.FromArgb(18, 20, 26),
ForeColor = Color.FromArgb(210, 214, 224),
BorderStyle = BorderStyle.FixedSingle
};
}
}