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"
43 #include <sys/types.h>
49 static GtkWidget
*fraClient
, *fraSingle
, *fraServer
;
50 static GtkWindow
*window
= NULL
, *networking
= NULL
;
51 static int mode
= CM_SOLO
;
52 static GPid game_pid
= 0;
53 static GIOChannel
*channel
= NULL
;
54 static guint source_id
= 0;
57 extern char **glut_argv
;
59 void turn_game_prefs_off () {
60 GAME_SINGLE
= GAME_SERVER
= GAME_CLIENT
= GAME_EXTREME
= FALSE
;
63 void lookup_widgets(GtkToggleButton
* gtb
) {
64 fraClient
= lookup_widget(GTK_WIDGET(gtb
), "fraClient");
65 fraSingle
= lookup_widget(GTK_WIDGET(gtb
), "fraSingle");
66 fraServer
= lookup_widget(GTK_WIDGET(gtb
), "fraServer");
69 void turn_sensitive_off() {
70 gtk_widget_set_sensitive (fraClient
, FALSE
);
71 gtk_widget_set_sensitive (fraSingle
, FALSE
);
72 gtk_widget_set_sensitive (fraServer
, FALSE
);
75 void toggle_sensitive (GtkToggleButton
* gtb
, gint selector
) {
76 gtk_widget_set_sensitive (fraClient
, FALSE
);
77 gtk_widget_set_sensitive (fraSingle
, FALSE
);
78 gtk_widget_set_sensitive (fraServer
, FALSE
);
80 case 1: gtk_widget_set_sensitive (fraClient
, TRUE
);
82 case 2: gtk_widget_set_sensitive (fraServer
, TRUE
);
87 void prepare_for_actions (GtkToggleButton
*gtb
) {
89 turn_game_prefs_off();
94 game_end (GPid pid
, gint status
, gpointer data
) {
96 g_print("game_end called!\n");
100 gtk_widget_destroy(GTK_WIDGET(networking
));
103 gtk_widget_show(GTK_WIDGET(window
));
105 g_spawn_close_pid (pid
);
109 ca_error_dialog (const char *message
)
111 GtkWidget
*dialog
= NULL
;
112 dialog
= gtk_message_dialog_new (window
,
113 GTK_DIALOG_DESTROY_WITH_PARENT
,
117 gtk_dialog_run (GTK_DIALOG (dialog
));
118 gtk_widget_destroy (dialog
);
123 on_btnCancel_clicked (GtkButton
*button
,
126 GtkWidget
*win
= GTK_WIDGET(user_data
);
127 gtk_widget_destroy(win
);
131 on_winNetworking_destroy (GtkObject
*object
,
135 kill(game_pid
, SIGKILL
);
139 g_io_channel_unref(channel
);
144 gboolean
networking_output (
145 GIOChannel
*source
, GIOCondition condition
, gpointer data
)
147 if (condition
& G_IO_IN
) {
148 GtkWidget
*win
= GTK_WIDGET(data
);
149 GtkTextView
*txtOutput
= NULL
;
151 GtkTextBuffer
*buffer
= NULL
;
155 txtOutput
= GTK_TEXT_VIEW(
156 lookup_widget(GTK_WIDGET(win
), "txtOutput"));
157 buffer
= gtk_text_view_get_buffer(txtOutput
);
158 gtk_text_buffer_get_end_iter(buffer
, &iter
);
159 g_io_channel_read_line(source
, &out
, &length
, NULL
, NULL
);
160 if (length
> 0 && out
[0] != '\33') {
162 gtk_text_buffer_insert(buffer
, &iter
, out
, length
);
168 if (condition
& G_IO_HUP
) {
169 g_source_remove(source_id
);
177 spawn_networking_dialog (gint standard_output
)
179 networking
= GTK_WINDOW(create_winNetworking());
180 gtk_widget_show(GTK_WIDGET(networking
));
182 if(channel
!= NULL
) {
183 g_io_channel_unref(channel
);
186 channel
= g_io_channel_unix_new(standard_output
);
187 source_id
= g_io_add_watch(channel
, (GIOCondition
) (G_IO_IN
| G_IO_HUP
),
188 networking_output
, networking
);
193 on_btnStart_clicked (GtkButton
*button
,
197 GTK_WINDOW(lookup_widget(GTK_WIDGET(button
),"winCrackAttackSplash"));
199 // Save the gui data when the game starts.
200 gui_data_save(GTK_WIDGET(button
));
202 // Set the mode based on all the widget values...
203 mode
= generate_mode(GTK_WIDGET(button
));
206 g_print("Looking for location: %s\n", GC_BINARY_LOCATION
);
210 gtk_widget_hide(GTK_WIDGET(window
));
211 GSpawnFlags flags
= (GSpawnFlags
) (G_SPAWN_LEAVE_DESCRIPTORS_OPEN
|
212 G_SPAWN_DO_NOT_REAP_CHILD
);
215 generate_array(mode
, GC_BINARY_LOCATION
, GTK_WIDGET(button
));
217 gint sin
, sout
, serr
;
219 g_spawn_async_with_pipes(
227 g_child_watch_add(pid
, (GChildWatchFunc
) game_end
, NULL
);
231 if (mode
& CM_SERVER
) {
232 spawn_networking_dialog(sout
);
237 if (err
) ca_error_dialog(err
->message
);
244 on_winCrackAttackSplash_delete_event (GtkWindow
*window
,
251 on_cmbQuality_changed (GtkComboBox
*cmb
,
254 gint tmp
= gtk_combo_box_get_active(cmb
);
255 GtkImage
* imgLogo
= GTK_IMAGE(lookup_widget(GTK_WIDGET(cmb
), "imgLogo"));
256 gchar
*filename
= NULL
;
259 filename
= find_pixmap_file("preview_normal.png");
263 filename
= find_pixmap_file("preview_reduced.png");
267 filename
= find_pixmap_file("preview_extremely_reduced.png");
271 filename
= find_pixmap_file("preview_normal.png");
274 gtk_image_set_from_file(imgLogo
, filename
);