3 * Andrew Sayman - 10/11/04
5 * Copyright (C) 2000 Daniel Nelson
6 * Copyright (C) 2004 Andrew Sayman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Daniel Nelson - aluminumangel.org
34 #include "../Attack.h"
35 #include "callbacks.h"
36 #include "interface.h"
40 #include "modeparser.h"
42 static GtkWidget
*fraClient
, *fraSingle
, *fraServer
;
43 static GtkWindow
*window
= NULL
;
44 static int mode
= CM_SOLO
;
45 static gboolean MS_RUNNING
= FALSE
;
46 static pid_t running_process
= 0;
47 static int height
= 400, width
= 400;
50 extern char **glut_argv
;
52 void turn_game_prefs_off () {
53 GAME_SINGLE
= GAME_SERVER
= GAME_CLIENT
= GAME_EXTREME
= FALSE
;
56 void lookup_widgets(GtkToggleButton
* gtb
) {
57 fraClient
= lookup_widget(GTK_WIDGET(gtb
), "fraClient");
58 fraSingle
= lookup_widget(GTK_WIDGET(gtb
), "fraSingle");
59 fraServer
= lookup_widget(GTK_WIDGET(gtb
), "fraServer");
62 void turn_sensitive_off() {
63 gtk_widget_set_sensitive (fraClient
, FALSE
);
64 gtk_widget_set_sensitive (fraSingle
, FALSE
);
65 gtk_widget_set_sensitive (fraServer
, FALSE
);
68 void toggle_sensitive (GtkToggleButton
* gtb
, gint selector
) {
69 gtk_widget_set_sensitive (fraClient
, FALSE
);
70 gtk_widget_set_sensitive (fraSingle
, FALSE
);
71 gtk_widget_set_sensitive (fraServer
, FALSE
);
73 case 1: gtk_widget_set_sensitive (fraClient
, TRUE
);
75 case 2: gtk_widget_set_sensitive (fraServer
, TRUE
);
80 void prepare_for_actions (GtkToggleButton
*gtb
) {
82 turn_game_prefs_off();
87 on_rbtnSingle_toggled (GtkToggleButton
*togglebutton
,
90 GtkWidget
*x
= lookup_widget(GTK_WIDGET(togglebutton
), "cbtnXtreme2");
91 gtk_toggle_button_set_active((GtkToggleButton
*) x
, FALSE
);
92 if (gtk_toggle_button_get_active(togglebutton
)) {
93 prepare_for_actions(togglebutton
);
94 gtk_widget_set_sensitive (fraSingle
, TRUE
);
104 on_rbtnServer_toggled (GtkToggleButton
*togglebutton
,
107 GtkWidget
*x
= lookup_widget(GTK_WIDGET(togglebutton
), "cbtnXtreme");
108 gtk_toggle_button_set_active((GtkToggleButton
*) x
, FALSE
);
109 if (gtk_toggle_button_get_active(togglebutton
)) {
110 prepare_for_actions(togglebutton
);
111 gtk_widget_set_sensitive (fraServer
, TRUE
);
120 on_rbtnClient_toggled (GtkToggleButton
*togglebutton
,
123 if (gtk_toggle_button_get_active(togglebutton
)) {
124 prepare_for_actions(togglebutton
);
125 gtk_widget_set_sensitive (fraClient
, TRUE
);
135 on_Xtreme_toggled (GtkToggleButton
*togglebutton
,
138 if (gtk_toggle_button_get_active(togglebutton
)) {
142 GAME_EXTREME
= FALSE
;
148 ca_error_dialog (const char *message
)
150 GtkWidget
*dialog
= NULL
;
151 dialog
= gtk_message_dialog_new (window
,
152 GTK_DIALOG_DESTROY_WITH_PARENT
,
156 gtk_dialog_run (GTK_DIALOG (dialog
));
157 gtk_widget_destroy (dialog
);
161 on_btnStart_clicked (GtkButton
*button
,
165 GtkTextBuffer
*buffer
;
167 GtkEntry
*entPlayerName
, *entPort
, *entServerAddress
;
168 GError
**error
= NULL
;
169 gchar
**output
= NULL
, **errorput
= NULL
;
171 gchar
*command
= NULL
;
175 command
= g_strdup("crack-attack ");
176 char player_name
[GC_PLAYER_NAME_LENGTH
];
179 window
= GTK_WINDOW(lookup_widget(GTK_WIDGET(button
),"winCrackAttackSplash"));
181 //Game is running, display an error message to the user
182 ca_error_dialog("Error: crack-attack is already running");
185 if (GAME_SINGLE
== TRUE
) {
187 } else if (GAME_SERVER
== TRUE
) {
189 entPort
= GTK_ENTRY(lookup_widget(GTK_WIDGET(button
), "entPort"));
191 tmp
= (gchar
*)gtk_entry_get_text(entPort
);
198 } else if (GAME_CLIENT
== TRUE
) {
199 entPort
= GTK_ENTRY(lookup_widget(GTK_WIDGET(button
), "entPort2"));
201 tmp
= (gchar
*)gtk_entry_get_text(entPort
);
208 entServerAddress
= GTK_ENTRY(lookup_widget(GTK_WIDGET(button
), "entServerAddress"));
209 if (entServerAddress
) {
210 tmp
= (gchar
*)gtk_entry_get_text(entServerAddress
);
211 g_strlcpy (host_name
, tmp
, 256);
214 cout
<< "Host name: " << host_name
<< endl
;
218 /* Make the game xtreme!! */
219 if (GAME_EXTREME
== TRUE
) {
224 entPlayerName
= GTK_ENTRY(lookup_widget(GTK_WIDGET(button
), "entPlayerName"));
226 tmp
= (gchar
*)gtk_entry_get_text(entPlayerName
);
228 if (strlen(tmp
) == 0) {
229 ca_error_dialog("Player's name isn't set.");
230 gtk_entry_set_text(entPlayerName
, g_get_user_name());
233 g_strlcpy(player_name
, tmp
, 256);
235 g_print ("Player name: %s tmp: %s",player_name
,tmp
);
243 // Save the gui data when the game starts.
244 gui_data_save(button
);
246 // Set the height and width to the selected value.
247 height
= width
= gui_get_dimensions(GTK_WIDGET(button
));
249 gtk_widget_hide(GTK_WIDGET(window
));
252 gchar
*c
= generate_arguments(mode
, br_strcat(BINDIR
, GC_DD GC_BINARY
), GTK_WIDGET(button
));
254 g_print("Command line: %s\n", c
);
256 gboolean ret
= g_spawn_command_line_sync(c
, NULL
, NULL
, &exit_status
, &err
);
259 if (err
) ca_error_dialog(err
->message
);
261 gtk_widget_show(GTK_WIDGET(window
));
268 on_btnHelp_clicked (GtkButton
*button
,
276 on_cbtnLowGraphics_toggled (GtkToggleButton
*togglebutton
,
279 GtkWidget
*lowButton
= lookup_widget(GTK_WIDGET(togglebutton
), "cbtnReallyLowGraphics");
280 if (gtk_toggle_button_get_active(togglebutton
)) {
282 mode
|= CM_LOW_GRAPHICS
;
284 GRAPHICS_LOW
= FALSE
;
285 mode
&= ~CM_LOW_GRAPHICS
;
286 mode
&= ~CM_REALLY_LOW_GRAPHICS
;
287 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowButton
), FALSE
);
292 on_cbtnReallyLowGraphics_toggled (GtkToggleButton
*togglebutton
,
295 GtkWidget
*lowButton
= lookup_widget(GTK_WIDGET(togglebutton
), "cbtnLowGraphics");
296 if (gtk_toggle_button_get_active(togglebutton
)) {
297 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lowButton
), TRUE
);
299 mode
|= CM_LOW_GRAPHICS
;
300 mode
|= CM_REALLY_LOW_GRAPHICS
;
302 GRAPHICS_LOW
= FALSE
;
303 mode
&= ~CM_REALLY_LOW_GRAPHICS
;
308 on_winCrackAttackSplash_delete_event (GtkWindow
*window
,
315 on_640by480_activate (GtkMenuItem
*menuitem
,
318 height
= width
= GC_RESOLUTION_0
;
322 on_800by600_activate (GtkMenuItem
*menuitem
,
325 height
= width
= GC_RESOLUTION_1
;
329 on_1024by768_activate (GtkMenuItem
*menuitem
,
332 height
= width
= GC_RESOLUTION_2
;
336 on_1280by1024_activate (GtkMenuItem
*menuitem
,
339 height
= width
= GC_RESOLUTION_3
;
343 on_1600by1200_activate (GtkMenuItem
*menuitem
,
346 height
= width
= GC_RESOLUTION_4
;
349 static void undo_ai_settings()
353 mode
&= ~CM_AI_MEDIUM
;
358 on_ai_none_activate (GtkMenuItem
*menuitem
,
361 GtkWidget
*x
= lookup_widget(GTK_WIDGET(menuitem
), "cbtnXtreme");
362 gtk_widget_set_sensitive(x
, TRUE
);
367 on_ai_easy_activate (GtkMenuItem
*menuitem
,
370 GtkWidget
*x
= lookup_widget(GTK_WIDGET(menuitem
), "cbtnXtreme");
371 gtk_toggle_button_set_active((GtkToggleButton
*) x
, FALSE
);
372 gtk_widget_set_sensitive(x
, FALSE
);
379 on_ai_medium_activate (GtkMenuItem
*menuitem
,
382 GtkWidget
*x
= lookup_widget(GTK_WIDGET(menuitem
), "cbtnXtreme");
383 gtk_toggle_button_set_active((GtkToggleButton
*) x
, FALSE
);
384 gtk_widget_set_sensitive(x
, FALSE
);
387 mode
|= CM_AI_MEDIUM
;
391 on_ai_hard_activate (GtkMenuItem
*menuitem
,
394 GtkWidget
*x
= lookup_widget(GTK_WIDGET(menuitem
), "cbtnXtreme");
395 gtk_toggle_button_set_active((GtkToggleButton
*) x
, FALSE
);
396 gtk_widget_set_sensitive(x
, FALSE
);