1 |
william |
4 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.ComponentModel; |
4 |
|
|
using System.Data; |
5 |
|
|
using System.Drawing; |
6 |
|
|
using System.Linq; |
7 |
|
|
using System.Text; |
8 |
|
|
using System.Windows.Forms; |
9 |
william |
12 |
using EmuXPortal.Api; |
10 |
william |
17 |
using EmuXPortal.Logging; |
11 |
william |
23 |
using System.Diagnostics; |
12 |
william |
4 |
|
13 |
|
|
namespace EmuXPortal |
14 |
|
|
{ |
15 |
|
|
public partial class Form1 : Form |
16 |
|
|
{ |
17 |
william |
17 |
IEmuConfig CurrentSelectedRom = null; |
18 |
william |
31 |
PlatformControl CurrentPlatformControl = null; |
19 |
|
|
GameControl CurrentGameControl = null; |
20 |
william |
4 |
public Form1() |
21 |
|
|
{ |
22 |
|
|
InitializeComponent(); |
23 |
william |
17 |
platform_flow.Dock = DockStyle.Fill; |
24 |
|
|
rom_flow.Dock = DockStyle.Fill; |
25 |
william |
33 |
|
26 |
william |
4 |
} |
27 |
william |
17 |
|
28 |
|
|
private void Form1_Load(object sender, EventArgs e) |
29 |
|
|
{ |
30 |
william |
33 |
Config.LoadConfig(); |
31 |
william |
17 |
Config.InitializePresentationForm(this); |
32 |
|
|
} |
33 |
|
|
private void Form1_Shown(object sender, EventArgs e) { platform_flow.Visible = true; } |
34 |
|
|
void platform_ctrl_LostFocus(object sender, EventArgs e) |
35 |
|
|
{ |
36 |
|
|
PlatformControl c = sender as PlatformControl; |
37 |
|
|
c.BorderStyle = BorderStyle.None; |
38 |
|
|
} |
39 |
william |
13 |
|
40 |
william |
17 |
void platform_ctrl_GotFocus(object sender, EventArgs e) |
41 |
william |
13 |
{ |
42 |
william |
17 |
PlatformControl c = sender as PlatformControl; |
43 |
|
|
c.BorderStyle = BorderStyle.FixedSingle; |
44 |
william |
31 |
CurrentPlatformControl = c; |
45 |
william |
13 |
} |
46 |
william |
17 |
|
47 |
|
|
void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
48 |
|
|
{ |
49 |
|
|
PlatformControl c = sender as PlatformControl; |
50 |
|
|
if (e.KeyCode == Keys.Enter) |
51 |
|
|
{ |
52 |
|
|
// load this platform |
53 |
|
|
platform_flow.Visible = false; |
54 |
|
|
CurrentSelectedRom = c.Tag as IEmuConfig; |
55 |
|
|
rom_flow.Visible = true; |
56 |
|
|
rom_flow.BringToFront(); |
57 |
william |
25 |
} |
58 |
|
|
if (e.KeyCode == Keys.Back) |
59 |
|
|
{ |
60 |
|
|
this.Close(); |
61 |
|
|
} |
62 |
william |
30 |
if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
63 |
|
|
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
64 |
|
|
{ |
65 |
|
|
char t = (char)e.KeyCode; |
66 |
william |
31 |
PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl); |
67 |
|
|
if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); } |
68 |
|
|
bool found = false; |
69 |
|
|
PlatformControl pc = CurrentPlatformControl; |
70 |
|
|
bool wrapped = false; |
71 |
|
|
bool not_found = true; |
72 |
|
|
while (!found) |
73 |
william |
30 |
{ |
74 |
william |
31 |
if (wrapped) |
75 |
william |
30 |
{ |
76 |
william |
31 |
foreach (Control ctl in platform_flow.Controls) |
77 |
|
|
{ |
78 |
|
|
PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
79 |
|
|
} |
80 |
|
|
if (not_found) { found = true; } |
81 |
william |
30 |
} |
82 |
william |
31 |
ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl); |
83 |
|
|
if (ctrl == null) |
84 |
|
|
{ |
85 |
|
|
ctrl = platform_flow.Controls[0] as PlatformControl; |
86 |
|
|
wrapped = true; |
87 |
|
|
} |
88 |
|
|
if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) |
89 |
|
|
{ |
90 |
|
|
platform_flow.ScrollControlIntoView(ctrl); |
91 |
|
|
ctrl.Select(); |
92 |
|
|
found = true; |
93 |
|
|
} |
94 |
|
|
pc = ctrl; |
95 |
william |
30 |
} |
96 |
|
|
} |
97 |
william |
17 |
} |
98 |
|
|
|
99 |
|
|
private void platform_flow_VisibleChanged(object sender, EventArgs e) |
100 |
|
|
{ |
101 |
|
|
if (!platform_flow.Visible) return; |
102 |
|
|
platform_flow.Controls.Clear(); |
103 |
|
|
platform_flow.BringToFront(); |
104 |
|
|
PlatformParser parser = new PlatformParser(Config.RomPath); |
105 |
|
|
foreach (IEmuConfig config in parser.Platforms) |
106 |
|
|
{ |
107 |
|
|
PlatformControl platform_ctrl = new PlatformControl(); |
108 |
william |
19 |
platform_ctrl.Dock = DockStyle.Top; |
109 |
|
|
platform_ctrl.Width = this.Width - 10; |
110 |
william |
17 |
platform_ctrl.Tag = config; |
111 |
|
|
platform_ctrl.PlatformImage = config.PlatformImage; |
112 |
william |
32 |
platform_ctrl.PlatformName = config.ToString(); |
113 |
william |
17 |
platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown); |
114 |
|
|
platform_flow.Controls.Add(platform_ctrl); |
115 |
|
|
platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus); |
116 |
|
|
platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus); |
117 |
|
|
} |
118 |
|
|
platform_flow.Controls[0].Select(); |
119 |
william |
19 |
(platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle; |
120 |
|
|
|
121 |
william |
17 |
} |
122 |
|
|
|
123 |
|
|
private void rom_flow_VisibleChanged(object sender, EventArgs e) |
124 |
|
|
{ |
125 |
|
|
if (!rom_flow.Visible) return; |
126 |
|
|
rom_flow.Controls.Clear(); |
127 |
|
|
rom_flow.BringToFront(); |
128 |
william |
29 |
RomParser parser = new RomParser(CurrentSelectedRom); |
129 |
william |
17 |
foreach (IRomConfig config in parser.Roms) |
130 |
|
|
{ |
131 |
|
|
GameControl game_ctrl = new GameControl(); |
132 |
william |
19 |
game_ctrl.Dock = DockStyle.Top; |
133 |
|
|
game_ctrl.Width = this.Width - 10; |
134 |
william |
17 |
game_ctrl.Tag = config; |
135 |
|
|
game_ctrl.GameImage = config.RomImage; |
136 |
|
|
game_ctrl.GameName = config.RomTitle; |
137 |
|
|
game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown); |
138 |
|
|
rom_flow.Controls.Add(game_ctrl); |
139 |
|
|
game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus); |
140 |
|
|
game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus); |
141 |
|
|
} |
142 |
|
|
rom_flow.Controls[0].Select(); |
143 |
|
|
(rom_flow.Controls[0] as GameControl).BorderStyle = BorderStyle.FixedSingle; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
void game_ctrl_LostFocus(object sender, EventArgs e) |
147 |
|
|
{ |
148 |
|
|
GameControl c = sender as GameControl; |
149 |
|
|
c.BorderStyle = BorderStyle.None; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
void game_ctrl_GotFocus(object sender, EventArgs e) |
153 |
|
|
{ |
154 |
|
|
GameControl c = sender as GameControl; |
155 |
|
|
c.BorderStyle = BorderStyle.FixedSingle; |
156 |
william |
31 |
CurrentGameControl = c; |
157 |
william |
17 |
} |
158 |
|
|
|
159 |
|
|
void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) |
160 |
|
|
{ |
161 |
|
|
GameControl c = sender as GameControl; |
162 |
|
|
if (e.KeyCode == Keys.Enter) |
163 |
|
|
{ |
164 |
william |
23 |
IRomConfig config = c.Tag as IRomConfig; |
165 |
|
|
|
166 |
|
|
Process p = new Process(); |
167 |
|
|
p.StartInfo.FileName = config.Config.EmuPath; |
168 |
|
|
p.StartInfo.Arguments = EmuConfigLoader.GetEMUOptions(config); |
169 |
|
|
p.Start(); |
170 |
william |
17 |
} |
171 |
|
|
if (e.KeyCode == Keys.Back) |
172 |
|
|
{ |
173 |
|
|
rom_flow.Visible = false; |
174 |
|
|
platform_flow.Visible = true; |
175 |
|
|
} |
176 |
william |
30 |
|
177 |
|
|
if ( (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || |
178 |
|
|
(e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) |
179 |
|
|
{ |
180 |
|
|
char t = (char)e.KeyCode; |
181 |
william |
31 |
GameControl ctrl = (rom_flow.GetNextControl(CurrentPlatformControl, true) as GameControl); |
182 |
|
|
if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); } |
183 |
|
|
bool found = false; |
184 |
|
|
GameControl pc = CurrentGameControl; |
185 |
|
|
bool wrapped = false; |
186 |
|
|
bool not_found = true; |
187 |
|
|
while (!found) |
188 |
william |
30 |
{ |
189 |
william |
31 |
if (wrapped) |
190 |
william |
30 |
{ |
191 |
william |
31 |
foreach (Control ctl in rom_flow.Controls) |
192 |
|
|
{ |
193 |
|
|
GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } |
194 |
|
|
} |
195 |
|
|
if (not_found) { found = true; } |
196 |
william |
30 |
} |
197 |
william |
31 |
ctrl = (rom_flow.GetNextControl(pc, true) as GameControl); |
198 |
|
|
if (ctrl == null) |
199 |
|
|
{ |
200 |
|
|
ctrl = rom_flow.Controls[0] as GameControl; |
201 |
|
|
wrapped = true; |
202 |
|
|
} |
203 |
|
|
if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower())) |
204 |
|
|
{ |
205 |
|
|
rom_flow.ScrollControlIntoView(ctrl); |
206 |
|
|
ctrl.Select(); |
207 |
|
|
found = true; |
208 |
|
|
} |
209 |
|
|
pc = ctrl; |
210 |
|
|
} |
211 |
william |
30 |
} |
212 |
william |
25 |
} |
213 |
william |
4 |
} |
214 |
|
|
} |