1 /* $Id: LauncherView.cpp,v 1.12 2003/07/29 17:14:30 nan Exp $ */
2
3 // Copyright (C) 2001, 2002, 2003 ���� �ȹ�(Kanna Yoshihiro)
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #include "ttinc.h"
20 #include "LobbyClient.h"
21 #include "LauncherView.h"
22 #include "Launcher.h"
23 #include "RCFile.h"
24 #include "Network.h"
25
26 #ifdef WIN32
27 extern gchar *_gdk_ucs2_to_utf8 (const wchar_t *src, gint src_len);
28
29 HWND LauncherView::hWnd = NULL;
30 LONG ModeNote::pEditWndProc = 0;
31 LONG ModeNote::pParentWndProc = 0;
32 HWND ModeNote::pChildHWnd = NULL;
33 ModeNote *theInternetPlayView;
34
35 // Copyed from gdkim-win32.c of GTK+-2.2.
36 gint
_gdk_utf8_to_ucs2(wchar_t * dest,const gchar * src,gint src_len,gint dest_max)37 _gdk_utf8_to_ucs2 (wchar_t *dest,
38 const gchar *src,
39 gint src_len,
40 gint dest_max)
41 {
42 wchar_t *wcp;
43 guchar *cp, *end;
44 gint n;
45
46 wcp = dest;
47 cp = (guchar *) src;
48 end = cp + src_len;
49 n = 0;
50 while (cp != end && wcp != dest + dest_max)
51 {
52 gint i, mask = 0, len;
53 guchar c = *cp;
54
55 if (c < 0x80)
56 {
57 len = 1;
58 mask = 0x7f;
59 }
60 else if ((c & 0xe0) == 0xc0)
61 {
62 len = 2;
63 mask = 0x1f;
64 }
65 else if ((c & 0xf0) == 0xe0)
66 {
67 len = 3;
68 mask = 0x0f;
69 }
70 else /* Other lengths are not possible with 16-bit wchar_t! */
71 return -1;
72
73 if (cp + len > end)
74 return -1;
75
76 *wcp = (cp[0] & mask);
77 for (i = 1; i < len; i++)
78 {
79 if ((cp[i] & 0xc0) != 0x80)
80 return -1;
81 *wcp <<= 6;
82 *wcp |= (cp[i] & 0x3f);
83 }
84 if (*wcp == 0xFFFF)
85 return -1;
86
87 cp += len;
88 wcp++;
89 n++;
90 }
91 if (cp != end)
92 return -1;
93
94 return n;
95 }
96
97 LRESULT CALLBACK
EditWindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)98 ModeNote::EditWindowProc( HWND hwnd, UINT msg,
99 WPARAM wparam, LPARAM lparam) {
100 LRESULT ret;
101
102 ret = CallWindowProc((WNDPROC)pEditWndProc,hwnd,msg,wparam,lparam);
103
104 if ( msg == WM_CHAR ) {
105 char buf[512], unibuf[2048];
106 GetWindowText( hwnd, buf, 512 );
107
108 char locale[10];
109 HKL input_locale = GetKeyboardLayout(0);
110 GetLocaleInfo (MAKELCID (LOWORD (input_locale), SORT_DEFAULT),
111 LOCALE_IDEFAULTANSICODEPAGE,
112 locale, sizeof (locale));
113
114 int srclen;
115 srclen = MultiByteToWideChar(atoi(locale), 0, buf, 512,
116 (LPWSTR)unibuf, 2048 );
117
118 gtk_entry_set_text( GTK_ENTRY(theInternetPlayView->m_lobbyEdit[0]),
119 _gdk_ucs2_to_utf8((const wchar_t *)unibuf, srclen) );
120 }
121
122 return ret;
123 }
124
125 LRESULT CALLBACK
ParentWindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)126 ModeNote::ParentWindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) {
127 if ( msg == WM_SIZE ) {
128 MoveWindow( pChildHWnd, 0, 0, lparam&0xFFFF, (lparam>>16)&0xFFFF, TRUE );
129 }
130
131 return CallWindowProc((WNDPROC)ModeNote::pParentWndProc,
132 hwnd,msg,wparam,lparam);
133 }
134 #endif
135
136 extern bool isComm;
137 extern long mode;
138
139 extern RCFile *theRC;
140
141 extern void StartGame();
142
143 extern bool WriteRCFile();
144
LauncherHeader()145 LauncherHeader::LauncherHeader() {
146 }
147
~LauncherHeader()148 LauncherHeader::~LauncherHeader() {
149 }
150
151 void
Init(GtkBox * box)152 LauncherHeader::Init( GtkBox *box ) {
153 GtkWidget *frame;
154
155 frame = FullScreenFrame();
156 gtk_box_pack_start( box, frame, FALSE, FALSE, 10 );
157 frame = GraphicsFrame();
158 gtk_box_pack_start( box, frame, FALSE, FALSE, 10 );
159 frame = SoundFrame();
160 gtk_box_pack_start( box, frame, FALSE, FALSE, 10 );
161 #ifdef ENABLE_IPV6
162 frame = ProtocolFrame();
163 gtk_box_pack_start( box, frame, FALSE, FALSE, 10 );
164 #endif
165 }
166
167 GtkWidget *
FullScreenFrame()168 LauncherHeader::FullScreenFrame() {
169 GtkWidget *frame;
170 GtkWidget *box;
171 GtkWidget *button;
172 GSList *list;
173
174 frame = gtk_frame_new( _("FullScreen") );
175
176 box = gtk_hbox_new( FALSE, 10 );
177 gtk_container_border_width (GTK_CONTAINER (box), 5);
178
179 button = gtk_radio_button_new_with_label ((GSList *)NULL, _("On"));
180 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
181 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
182 if (theRC->fullScreen)
183 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
184
185 gtk_signal_connect (GTK_OBJECT (button), "clicked",
186 GTK_SIGNAL_FUNC (LauncherHeader::ToggleFullScreen),
187 &theRC->fullScreen);
188
189 button = gtk_radio_button_new_with_label (list, _("Off"));
190 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
191 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
192 if (!theRC->fullScreen)
193 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
194
195 gtk_signal_connect (GTK_OBJECT (button), "clicked",
196 GTK_SIGNAL_FUNC (LauncherHeader::ToggleFullScreen),
197 &theRC->fullScreen);
198
199 gtk_container_add (GTK_CONTAINER (frame), box);
200
201 return frame;
202 }
203
204 GtkWidget *
GraphicsFrame()205 LauncherHeader::GraphicsFrame() {
206 GtkWidget *frame;
207 GtkWidget *box;
208 GtkWidget *twoDButton, *simpleButton, *normalButton;
209 GSList *list;
210
211 frame = gtk_frame_new( _("Graphics") );
212
213 box = gtk_hbox_new( FALSE, 10 );
214 gtk_container_border_width (GTK_CONTAINER (box), 5);
215
216 #if 0
217 twoDButton = gtk_radio_button_new_with_label ( (GSList *)NULL, "2D");
218 list = gtk_radio_button_group( GTK_RADIO_BUTTON(twoDButton) );
219 gtk_box_pack_start( GTK_BOX(box), twoDButton, FALSE, FALSE, 10 );
220 gtk_widget_show (twoDButton);
221 if ( theRC->gmode == GMODE_2D ) {
222 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(twoDButton), TRUE );
223 }
224
225 simpleButton = gtk_radio_button_new_with_label ( list, _("Simple"));
226 #else
227 simpleButton = gtk_radio_button_new_with_label ( (GSList *)NULL, _("Simple"));
228 #endif
229
230 list = gtk_radio_button_group( GTK_RADIO_BUTTON(simpleButton) );
231 gtk_box_pack_start( GTK_BOX(box), simpleButton, FALSE, FALSE, 10 );
232 if ( theRC->gmode == GMODE_SIMPLE ) {
233 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(simpleButton), TRUE );
234 }
235
236 normalButton = gtk_radio_button_new_with_label (list, _("Normal"));
237 list = gtk_radio_button_group( GTK_RADIO_BUTTON(normalButton) );
238 gtk_box_pack_start( GTK_BOX(box), normalButton, FALSE, FALSE, 10 );
239 if ( theRC->gmode == GMODE_FULL ) {
240 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(normalButton), TRUE );
241 }
242
243 #if 0
244 gtk_signal_connect (GTK_OBJECT (twoDButton), "clicked",
245 GTK_SIGNAL_FUNC (LauncherHeader::Toggle), &theRC->gmode);
246 #endif
247 gtk_signal_connect (GTK_OBJECT (simpleButton), "clicked",
248 GTK_SIGNAL_FUNC (LauncherHeader::Toggle), &theRC->gmode);
249 gtk_signal_connect (GTK_OBJECT (normalButton), "clicked",
250 GTK_SIGNAL_FUNC (LauncherHeader::Toggle), &theRC->gmode);
251
252 gtk_container_add (GTK_CONTAINER (frame), box);
253
254 return frame;
255 }
256
257 GtkWidget *
SoundFrame()258 LauncherHeader::SoundFrame() {
259 GtkWidget *frame;
260 GtkWidget *box;
261 GtkWidget *button;
262 GSList *list;
263
264 frame = gtk_frame_new( _("Sound") );
265
266 box = gtk_hbox_new( FALSE, 10 );
267 gtk_container_border_width (GTK_CONTAINER (box), 5);
268
269 button = gtk_radio_button_new_with_label ((GSList *)NULL, _("On"));
270 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
271 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
272 if (theRC->sndMode == SOUND_SDL)
273 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
274
275 gtk_signal_connect (GTK_OBJECT (button), "clicked",
276 GTK_SIGNAL_FUNC (LauncherHeader::ToggleSound),
277 &theRC->sndMode);
278
279 button = gtk_radio_button_new_with_label (list, _("Off"));
280 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
281 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
282 if (theRC->sndMode == SOUND_NONE)
283 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
284
285 gtk_signal_connect (GTK_OBJECT (button), "clicked",
286 GTK_SIGNAL_FUNC (LauncherHeader::ToggleSound),
287 &theRC->sndMode);
288
289 gtk_container_add (GTK_CONTAINER (frame), box);
290
291 return frame;
292 }
293
294 #ifdef ENABLE_IPV6
295 GtkWidget *
ProtocolFrame()296 LauncherHeader::ProtocolFrame() {
297 GtkWidget *frame;
298 GtkWidget *box;
299 GtkWidget *button;
300 GSList *list;
301
302 frame = gtk_frame_new( "Protocol" );
303
304 box = gtk_hbox_new( FALSE, 10 );
305 gtk_container_border_width (GTK_CONTAINER (box), 5);
306
307 button = gtk_radio_button_new_with_label ((GSList *)NULL, "IPv4");
308 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
309 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
310 if (theRC->protocol == IPv4)
311 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
312
313 gtk_signal_connect (GTK_OBJECT (button), "clicked",
314 GTK_SIGNAL_FUNC (LauncherHeader::ToggleProtocol),
315 &theRC->protocol);
316
317 button = gtk_radio_button_new_with_label (list, "IPv6");
318 list = gtk_radio_button_group( GTK_RADIO_BUTTON(button) );
319 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
320 if (theRC->protocol == IPv6)
321 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(button), TRUE );
322
323 gtk_signal_connect (GTK_OBJECT (button), "clicked",
324 GTK_SIGNAL_FUNC (LauncherHeader::ToggleProtocol),
325 &theRC->protocol);
326
327 gtk_container_add (GTK_CONTAINER (frame), box);
328
329 return frame;
330 }
331 #endif
332
333 void
ToggleFullScreen(GtkWidget * widget,gpointer data)334 LauncherHeader::ToggleFullScreen( GtkWidget *widget, gpointer data ) {
335 GSList *list = gtk_radio_button_group( (GtkRadioButton *)widget );
336
337 if ( gtk_toggle_button_get_active
338 ( (GtkToggleButton *)g_slist_nth_data( list, 0 ) ) ) {
339 theRC->fullScreen = false;
340 } else {
341 theRC->fullScreen = true;
342 }
343 }
344
345 void
ToggleSound(GtkWidget * widget,gpointer data)346 LauncherHeader::ToggleSound( GtkWidget *widget, gpointer data ) {
347 GSList *list = gtk_radio_button_group( (GtkRadioButton *)widget );
348
349 if ( gtk_toggle_button_get_active
350 ( (GtkToggleButton *)g_slist_nth_data( list, 0 ) ) ) {
351 theRC->sndMode = SOUND_NONE;
352 } else {
353 theRC->sndMode = SOUND_SDL;
354 }
355 }
356
357 #ifdef ENABLE_IPV6
358 void
ToggleProtocol(GtkWidget * widget,gpointer data)359 LauncherHeader::ToggleProtocol( GtkWidget *widget, gpointer data ) {
360 GSList *list = gtk_radio_button_group( (GtkRadioButton *)widget );
361
362 if ( gtk_toggle_button_get_active
363 ( (GtkToggleButton *)g_slist_nth_data( list, 0 ) ) ) {
364 theRC->protocol = IPv6;
365 } else {
366 theRC->protocol = IPv4;
367 }
368 }
369 #endif
370
371
372 void
Toggle(GtkWidget * widget,gpointer data)373 LauncherHeader::Toggle( GtkWidget *widget, gpointer data ) {
374 GSList *list = gtk_radio_button_group( (GtkRadioButton *)widget );
375
376 if ( gtk_toggle_button_get_active
377 ( (GtkToggleButton *)g_slist_nth_data( list, 0 ) ) ) {
378 theRC->gmode = GMODE_FULL;
379 theRC->isTexture = true;
380 } else if ( gtk_toggle_button_get_active
381 ( (GtkToggleButton *)g_slist_nth_data( list, 1 ) ) ) {
382 theRC->gmode = GMODE_SIMPLE;
383 theRC->isTexture = false;
384 } else if ( gtk_toggle_button_get_active
385 ( (GtkToggleButton *)g_slist_nth_data( list, 2 ) ) ) {
386 theRC->gmode = GMODE_2D;
387 theRC->isTexture = false;
388 }
389 }
390
ModeNote()391 ModeNote::ModeNote() {
392 }
393
~ModeNote()394 ModeNote::~ModeNote() {
395 }
396
397 void
Init(GtkBox * box)398 ModeNote::Init( GtkBox *box ) {
399 GtkWidget *notebook;
400 GtkWidget *noteBox;
401 GtkWidget *label;
402
403 notebook = gtk_notebook_new();
404
405 gtk_box_pack_start( box, notebook, FALSE, FALSE, 10 );
406 gtk_widget_show(notebook);
407
408 // Solo Play
409 noteBox = InitSoloPlayPanel();
410 label = gtk_label_new( _("Solo") );
411 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), noteBox, label);
412
413 // LAN Play
414 noteBox = InitLANPlayPanel();
415 label = gtk_label_new( _("LAN") );
416 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), noteBox, label);
417
418 // Internet Play
419 noteBox = InitInternetPlayPanel();
420 label = gtk_label_new( _("Internet(Experimental)") );
421 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), noteBox, label);
422
423 #ifdef WIN32
424 HWND cWnd = NULL;
425 cWnd = FindWindowEx( LauncherView::hWnd, NULL, "gdkWindowChild", NULL );
426 cWnd = FindWindowEx( LauncherView::hWnd, cWnd, "gdkWindowChild", NULL );
427 cWnd = FindWindowEx( cWnd, NULL, "gdkWindowChild", NULL );
428
429 ModeNote::pParentWndProc = GetWindowLong(cWnd, GWL_WNDPROC);
430 SetWindowLong(cWnd, GWL_WNDPROC, (LONG)ModeNote::ParentWindowProc);
431
432 ModeNote::pChildHWnd = CreateWindow( "EDIT", NULL, WS_CHILD|WS_VISIBLE,
433 CW_USEDEFAULT, CW_USEDEFAULT,
434 200, 30,
435 cWnd, NULL, NULL, NULL );
436
437 char buf[512], unibuf[2048];
438 char locale[10];
439 HKL input_locale = GetKeyboardLayout(0);
440 GetLocaleInfo (MAKELCID (LOWORD (input_locale), SORT_DEFAULT),
441 LOCALE_IDEFAULTANSICODEPAGE,
442 locale, sizeof (locale));
443
444 _gdk_utf8_to_ucs2((wchar_t *)unibuf, theRC->nickname, 32, 2048);
445
446 WideCharToMultiByte(atoi(locale), 0, (LPWSTR)unibuf, 2048,
447 (LPSTR)buf, 512, NULL, NULL);
448
449 SetWindowText( ModeNote::pChildHWnd, buf );
450
451 ModeNote::pEditWndProc = GetWindowLong(ModeNote::pChildHWnd, GWL_WNDPROC);
452 SetWindowLong(ModeNote::pChildHWnd, GWL_WNDPROC, (LONG)ModeNote::EditWindowProc);
453
454 theInternetPlayView = this;
455 #endif
456 }
457
458 GtkWidget *
InitSoloPlayPanel()459 ModeNote::InitSoloPlayPanel() {
460 GtkWidget *box;
461 GtkWidget *button;
462
463 box = gtk_vbox_new( FALSE, 10 );
464 gtk_container_border_width (GTK_CONTAINER (box), 5);
465
466 button = gtk_button_new_with_label (_("Game Start!"));
467 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
468 gtk_widget_show (button);
469
470 gtk_signal_connect( GTK_OBJECT (button), "clicked",
471 GTK_SIGNAL_FUNC (ModeNote::StartGame), NULL );
472
473 gtk_widget_show (box);
474
475 return box;
476 }
477
478 GtkWidget *
InitLANPlayPanel()479 ModeNote::InitLANPlayPanel() {
480 GtkWidget *box, *toggleBox, *editBox;
481 GtkWidget *button, *label;
482 GtkWidget *toggleButton[2];
483 GSList *list;
484
485 box = gtk_vbox_new( FALSE, 5 );
486 gtk_container_border_width (GTK_CONTAINER (box), 5);
487
488 // Upper toggle button
489 toggleBox = gtk_hbox_new( FALSE, 10 );
490 gtk_container_border_width (GTK_CONTAINER (toggleBox), 5);
491
492 toggleButton[0] = gtk_radio_button_new_with_label ((GSList *)NULL, _("Server"));
493 list = gtk_radio_button_group( GTK_RADIO_BUTTON(toggleButton[0]) );
494 gtk_box_pack_start( GTK_BOX(toggleBox), toggleButton[0], FALSE, FALSE, 5 );
495 gtk_widget_show (toggleButton[0]);
496 toggleButton[1] = gtk_radio_button_new_with_label (list, _("Client"));
497 list = gtk_radio_button_group( GTK_RADIO_BUTTON(toggleButton[1]) );
498 gtk_box_pack_start( GTK_BOX(toggleBox), toggleButton[1], FALSE, FALSE, 5 );
499 gtk_widget_show (toggleButton[1]);
500
501 gtk_widget_show (toggleBox);
502 gtk_box_pack_start( GTK_BOX(box), toggleBox, FALSE, FALSE, 5 );
503
504 if (theRC->serverName[0])
505 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(toggleButton[1]), TRUE );
506
507 // Lower input area for server name
508 editBox = gtk_table_new( 2, 2, FALSE );
509
510 label = gtk_label_new( _("Server name:") );
511 gtk_table_attach( GTK_TABLE(editBox), label, 0, 1, 1, 2,
512 GTK_FILL, GTK_EXPAND, 0, 0 );
513 gtk_widget_show (label);
514 m_serverName = gtk_entry_new ();
515 gtk_table_attach( GTK_TABLE(editBox), m_serverName, 1, 2, 1, 2,
516 GTK_FILL, GTK_EXPAND, 0, 0 );
517 if ( theRC->serverName[0] > 1 ) {
518 gtk_entry_set_text( GTK_ENTRY(m_serverName), theRC->serverName );
519 gtk_widget_show ( GTK_WIDGET(m_serverName) );
520 }
521
522 gtk_widget_show (editBox);
523 gtk_box_pack_start( GTK_BOX(box), editBox, FALSE, FALSE, 5 );
524
525 gtk_signal_connect (GTK_OBJECT (toggleButton[0]), "pressed",
526 GTK_SIGNAL_FUNC (ModeNote::Toggle), m_serverName);
527 gtk_signal_connect (GTK_OBJECT (toggleButton[1]), "pressed",
528 GTK_SIGNAL_FUNC (ModeNote::Toggle), m_serverName);
529
530 // lowest area(start button)
531 button = gtk_button_new_with_label (_("Game Start!"));
532 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 5 );
533 gtk_widget_show (button);
534
535 gtk_signal_connect (GTK_OBJECT (button), "clicked",
536 GTK_SIGNAL_FUNC (ModeNote::LANStartGame), m_serverName);
537
538 gtk_widget_show (box);
539
540 return box;
541 }
542
543 GtkWidget *
InitInternetPlayPanel()544 ModeNote::InitInternetPlayPanel() {
545 GtkWidget *box, *editBox;
546 GtkWidget *button, *label;
547
548 box = gtk_vbox_new( FALSE, 10 );
549 gtk_container_border_width (GTK_CONTAINER (box), 5);
550
551 gtk_widget_show (box);
552
553 editBox = gtk_table_new( 2, 2, FALSE );
554 gtk_box_pack_start( GTK_BOX(box), editBox, FALSE, FALSE, 5 );
555
556 gtk_widget_show (editBox);
557
558 label = gtk_label_new( _("Nickname:") );
559 gtk_table_attach( GTK_TABLE(editBox), label, 0, 1, 0, 1,
560 GTK_FILL, GTK_EXPAND, 0, 0 );
561 gtk_widget_show (label);
562 m_lobbyEdit[0] = gtk_entry_new();
563 gtk_table_attach( GTK_TABLE(editBox), m_lobbyEdit[0], 1, 2, 0, 1,
564 GTK_FILL, GTK_EXPAND, 0, 0 );
565 gtk_entry_set_text( GTK_ENTRY(m_lobbyEdit[0]), theRC->nickname );
566 gtk_widget_show (m_lobbyEdit[0]);
567
568 #if 0
569 label = gtk_label_new( _("Message:") );
570 gtk_table_attach( GTK_TABLE(editBox), label, 0, 1, 1, 2,
571 GTK_FILL, GTK_EXPAND, 0, 0 );
572 gtk_widget_show (label);
573 m_lobbyEdit[1] = gtk_entry_new();
574 gtk_table_attach( GTK_TABLE(editBox), m_lobbyEdit[1], 1, 2, 1, 2,
575 GTK_FILL, GTK_EXPAND, 0, 0 );
576 gtk_widget_show (m_lobbyEdit[1]);
577 gtk_entry_set_text( GTK_ENTRY(m_lobbyEdit[1]), theRC->message );
578 #endif
579
580 button = gtk_button_new_with_label(_("Connect to Lobby Server"));
581 gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 10 );
582 gtk_widget_show(button);
583
584 gtk_signal_connect( GTK_OBJECT(button), "clicked",
585 GTK_SIGNAL_FUNC(ModeNote::InternetStartGame), m_lobbyEdit);
586
587 return box;
588 }
589
590 void
Toggle(GtkWidget * widget,gpointer data)591 ModeNote::Toggle( GtkWidget *widget, gpointer data ) {
592 GSList *list = gtk_radio_button_group( (GtkRadioButton *)widget );
593
594 if ( g_slist_index( list, widget ) == 0 ) {
595 theRC->serverName[0] = 1; // :-p
596 gtk_widget_show ( GTK_WIDGET(data) );
597 } else {
598 theRC->serverName[0] = '\0';
599 gtk_widget_hide ( GTK_WIDGET(data) );
600 }
601 }
602
603 void
StartGame(GtkWidget * widget,gpointer data)604 ModeNote::StartGame( GtkWidget *widget, gpointer data ) {
605 if ( theRC->gmode == GMODE_2D )
606 mode = MODE_TITLE;
607 ::StartGame();
608 }
609
610 void
LANStartGame(GtkWidget * widget,gpointer data)611 ModeNote::LANStartGame( GtkWidget *widget, gpointer data ) {
612 if ( theRC->serverName[0] == 1 &&
613 strlen(gtk_entry_get_text( GTK_ENTRY(data) )) > 0 )
614 strncpy( theRC->serverName, gtk_entry_get_text( GTK_ENTRY(data) ), 256 );
615 isComm = true;
616 mode = MODE_MULTIPLAYSELECT;
617 try {
618 ::StartGame();
619 } catch ( NetworkError ) {
620 LauncherView::ConnectionFailedDialog();
621 }
622 }
623
624 void
InternetStartGame(GtkWidget * widget,gpointer data)625 ModeNote::InternetStartGame( GtkWidget *widget, gpointer data ) {
626 LobbyClient *lb;
627 lb = LobbyClient::Create();
628 if ( lb->
629 #if 0
630 Init((char *)gtk_entry_get_text(GTK_ENTRY(((GtkWidget **)data)[0])),
631 (char *)gtk_entry_get_text(GTK_ENTRY(((GtkWidget **)data)[1])))
632 #else
633 Init((char *)gtk_entry_get_text(GTK_ENTRY(((GtkWidget **)data)[0])),
634 "")
635 #endif
636 == false ) {
637 LauncherView::ConnectionFailedDialog();
638 }
639 }
640
641
LauncherView()642 LauncherView::LauncherView() {
643 }
644
~LauncherView()645 LauncherView::~LauncherView() {
646 }
647
648 void
Init()649 LauncherView::Init() {
650 GtkStyle *style;
651 GtkWidget *label;
652
653 GtkWidget *allbox, *mainbox, *quitBox;
654
655 /* ����� */
656 gtk_init( (int *)NULL, (char ***)NULL );
657 /*
658 style = gtk_widget_get_default_style();
659 #ifdef WIN32
660 //style->font = gdk_font_load(_("-unknown-MS UI Gothic-normal-r-normal--12-100-*-*-*-*-windows-*") );
661 style->font = gdk_font_load(_("-*-ms gothic-normal-r-normal--14-*-*-*-*-*-jisx0208.1983-0") );
662 #endif
663 gtk_widget_set_default_style(style);
664 */
665
666 /* Window ���� */
667 m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
668 gtk_container_border_width (GTK_CONTAINER (m_window), 5);
669
670 #ifdef WIN32
671 char windowName[32];
672 int i;
673 for ( i = 0 ; i < 31 ; i++ )
674 windowName[i] = 'A'+RAND(26);
675 windowName[31] = 0;
676
677 gtk_window_set_title( GTK_WINDOW(m_window), windowName);
678 #else
679 gtk_window_set_title( GTK_WINDOW(m_window), _("Cannon Smash"));
680 #endif
681
682 gtk_widget_realize(m_window);
683
684 #ifdef WIN32
685 LauncherView::hWnd = FindWindow( "gdkWindowTopLevel", windowName );
686 gtk_window_set_title( GTK_WINDOW(m_window), _("Cannon Smash"));
687 #endif
688
689 allbox = gtk_hbox_new( FALSE, 5 );
690 gtk_container_add (GTK_CONTAINER (m_window), allbox);
691
692 mainbox = gtk_vbox_new( FALSE, 5 );
693 quitBox = gtk_vbox_new( FALSE, 5 );
694
695 m_quit = gtk_button_new_with_label (_("Quit"));
696 gtk_box_pack_start( GTK_BOX(quitBox), m_quit, FALSE, TRUE, 10 );
697
698 gtk_box_pack_start( GTK_BOX(allbox), mainbox, FALSE, FALSE, 10 );
699 gtk_box_pack_start( GTK_BOX(allbox), quitBox, FALSE, TRUE, 10 );
700
701 m_header = new LauncherHeader();
702 m_header->Init( GTK_BOX(mainbox) );
703 gtk_widget_show_all(m_window);
704 m_note = new ModeNote();
705 m_note->Init( GTK_BOX(mainbox) );
706
707 label = gtk_label_new( "http://CannonSmash.SourceForge.net\nmailto: nan@utmc.or.jp" );
708 gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_LEFT );
709 gtk_box_pack_start( GTK_BOX(mainbox), label, FALSE, TRUE, 0 );
710 gtk_widget_show(label);
711
712 gtk_signal_connect( GTK_OBJECT (m_window), "destroy",
713 GTK_SIGNAL_FUNC (LauncherView::Destroy), this );
714 gtk_signal_connect( GTK_OBJECT (m_quit), "clicked",
715 GTK_SIGNAL_FUNC (LauncherView::Destroy),
716 this );
717
718 gtk_main();
719 }
720
721 void
Destroy(GtkWidget * widget,gpointer data)722 LauncherView::Destroy(GtkWidget *widget, gpointer data) {
723 ModeNote *note = ((LauncherView *)data)->m_note;
724
725 strncpy( theRC->serverName,
726 gtk_entry_get_text( GTK_ENTRY(note->m_serverName) ), 256 );
727 strncpy( theRC->nickname,
728 gtk_entry_get_text( GTK_ENTRY(note->m_lobbyEdit[0]) ), 32 );
729 #if 0
730 strncpy( theRC->message,
731 gtk_entry_get_text( GTK_ENTRY(note->m_lobbyEdit[1]) ), 64 );
732 #endif
733
734 theRC->WriteRCFile();
735
736 gtk_main_quit();
737
738 gtk_exit(2);
739 }
740
741 void
ConnectionFailedDialog()742 LauncherView::ConnectionFailedDialog() {
743 GtkWidget *dialog, *label, *button;
744
745 dialog = gtk_dialog_new();
746 gtk_window_set_title( GTK_WINDOW(dialog), _("Connection failed"));
747 gtk_container_border_width( GTK_CONTAINER (dialog), 5 );
748 gtk_window_set_modal( (GtkWindow *)dialog, true );
749
750 label = gtk_label_new( "Connection failed." );
751 gtk_label_set_line_wrap( GTK_LABEL(label), true );
752 gtk_widget_show( label );
753
754 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
755 TRUE, TRUE, 0 );
756
757 button = gtk_button_new_with_label( "OK" );
758 GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT );
759 gtk_signal_connect_object( GTK_OBJECT(button), "clicked",
760 GTK_SIGNAL_FUNC(gtk_widget_destroy),
761 GTK_OBJECT(dialog) );
762 gtk_box_pack_start( GTK_BOX (GTK_DIALOG (dialog)->action_area),
763 button, TRUE, TRUE, 0 );
764
765 gtk_widget_show(button);
766
767 gtk_widget_show(dialog);
768 }
769