-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFrame.cs
221 lines (179 loc) · 6.09 KB
/
MainFrame.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Ray2Mod.Game.Functions;
namespace R2ObjView
{
public sealed partial class MainFrame : Form
{
private static MainFrame _instance;
public static MainFrame Instance => _instance ?? (_instance = new MainFrame());
public event Action RefreshData;
public event Action<string> LevelChanged;
private string previousLevelName;
private string levelName;
private string _statusText;
public string StatusText
{
get
{
if (ActiveMdiChild is ChildFrame child && !string.IsNullOrEmpty(child.ChildStatusText))
return child.ChildStatusText;
return _statusText;
}
set
{
_statusText = value;
statusLine.Text = _statusText;
}
}
private MdiClient mdiClient;
private WorldForm worldForm;
private MainFrame()
{
InitializeComponent();
Icon = Resources.glidetect;
StatusText = "Ready.";
foreach (Control ctl in Controls)
{
if (ctl is MdiClient client)
mdiClient = client;
}
// HACK: quick fix for VS designer crash
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) return;
autoRefreshToolStripMenuItem.Checked = true;
refreshTimer.Enabled = true;
}
public void SetStatus(ChildFrame child, string status)
{
if (child == ActiveMdiChild)
{
statusLine.Text = status;
}
}
public void ShowChild(Form form)
{
form.MdiParent = this;
form.Show();
}
public void ShowChildAtCursor(Form form)
{
Point point = mdiClient.PointToClient(Cursor.Position);
point.Offset(-8, -8);
form.StartPosition = FormStartPosition.Manual;
form.Location = point;
ShowChild(form);
}
#region View menu
private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
{
toolStrip.Visible = toolBarToolStripMenuItem.Checked;
}
private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
{
statusStrip.Visible = statusBarToolStripMenuItem.Checked;
}
#endregion
#region Windows menu
private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}
private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren) childForm.Close();
}
#endregion
#region Tooltips
private void ToolMouseEnter(object sender, EventArgs e)
{
// HACK: Using AccessibleDescription as tooltip
switch (sender)
{
case ToolStripItem item:
statusLine.Text = item.AccessibleDescription;
break;
case Control control:
statusLine.Text = control.AccessibleDescription;
break;
}
}
private void ToolMouseLeave(object sender, EventArgs e)
{
statusLine.Text = StatusText;
}
private void toolStrip_ItemAdded(object sender, ToolStripItemEventArgs e)
{
e.Item.MouseEnter += ToolMouseEnter;
e.Item.MouseLeave += ToolMouseLeave;
}
private void toolStrip_ItemRemoved(object sender, ToolStripItemEventArgs e)
{
e.Item.MouseEnter -= ToolMouseEnter;
e.Item.MouseLeave -= ToolMouseLeave;
}
#endregion
private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void WorldItemClick(object sender, EventArgs e)
{
if (worldForm == null)
{
worldForm = new WorldForm();
worldForm.FormClosed += WorldFormClosed;
ShowChild(worldForm);
}
else
{
worldForm.Show();
if (worldForm.WindowState == FormWindowState.Minimized)
{
worldForm.WindowState = FormWindowState.Normal;
}
}
}
private void WorldFormClosed(object sender, FormClosedEventArgs e)
{
worldForm = null;
}
private void MainFrame_MdiChildActivate(object sender, EventArgs e)
{
statusLine.Text = StatusText;
ToolStripManager.RevertMerge(toolStrip);
if (ActiveMdiChild is ChildFrame child && child.ChildToolStrip != null)
{
ToolStripManager.Merge(child.ChildToolStrip, toolStrip);
}
}
private void autoRefreshToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
{
refreshTimer.Enabled = autoRefreshToolStripMenuItem.Checked;
}
private void refreshTimer_Tick(object sender, EventArgs e)
{
levelName = EngineFunctions.GetCurrentLevelName.Call();
if (levelName != previousLevelName)
{
LevelChanged?.Invoke(levelName);
previousLevelName = levelName;
levelNameLabel.Text = levelName;
}
RefreshData?.Invoke();
}
}
}