1 |
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 |
using EmuXPortal.Api; |
10 |
using EmuXPortal.Logging; |
11 |
using System.Diagnostics; |
12 |
|
13 |
namespace EmuXPortal |
14 |
{ |
15 |
public partial class Form1 : Form |
16 |
{ |
17 |
IEmuConfig CurrentSelectedRom = null; |
18 |
PlatformControl CurrentPlatformControl = null; |
19 |
GameControl CurrentGameControl = null; |
20 |
public Form1() |
21 |
{ |
22 |
InitializeComponent(); |
23 |
platform_flow.Dock = DockStyle.Fill; |
24 |
rom_flow.Dock = DockStyle.Fill; |
25 |
|
26 |
Config.LoadConfig(); |
27 |
} |
28 |
|
29 |
private void Form1_Load(object sender, EventArgs e) |
30 |
{ |
31 |
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 |
|
40 |
void platform_ctrl_GotFocus(object sender, EventArgs e) |
41 |
{ |
42 |
PlatformControl c = sender as PlatformControl; |
43 |
c.BorderStyle = BorderStyle.FixedSingle; |
44 |
CurrentPlatformControl = c; |
45 |
} |
46 |
|
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 |
} |
58 |
if (e.KeyCode == Keys.Back) |
59 |
{ |
60 |
this.Close(); |
61 |
} |
62 |
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 |
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 |
{ |
74 |
if (wrapped) |
75 |
{ |
76 |
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 |
} |
82 |
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 |
} |
96 |
} |
97 |
} |
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 |
platform_ctrl.Dock = DockStyle.Top; |
109 |
platform_ctrl.Width = this.Width - 10; |
110 |
platform_ctrl.Tag = config; |
111 |
platform_ctrl.PlatformImage = config.PlatformImage; |
112 |
platform_ctrl.PlatformName = config.PlatformNameLong; |
113 |
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 |
(platform_flow.Controls[0] as PlatformControl).BorderStyle = BorderStyle.FixedSingle; |
120 |
|
121 |
} |
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 |
RomParser parser = new RomParser(CurrentSelectedRom); |
129 |
foreach (IRomConfig config in parser.Roms) |
130 |
{ |
131 |
GameControl game_ctrl = new GameControl(); |
132 |
game_ctrl.Dock = DockStyle.Top; |
133 |
game_ctrl.Width = this.Width - 10; |
134 |
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 |
CurrentGameControl = c; |
157 |
} |
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 |
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 |
} |
171 |
if (e.KeyCode == Keys.Back) |
172 |
{ |
173 |
rom_flow.Visible = false; |
174 |
platform_flow.Visible = true; |
175 |
} |
176 |
|
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 |
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 |
{ |
189 |
if (wrapped) |
190 |
{ |
191 |
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 |
} |
197 |
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 |
} |
212 |
} |
213 |
} |
214 |
} |