2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <gdk/gdkkeysyms.h>
25 #include "surfdlg_plugin.h"
27 #include "surfaceflagsdialog_ufoai.h"
32 #define MAX_BUTTONS 32
34 GtkWidget *surface_buttons[MAX_BUTTONS];
35 GtkWidget *content_buttons[MAX_BUTTONS];
37 GtkWidget *value_entry;
38 gboolean setup_buttons = TRUE;
40 int working_surface_flags;
42 int working_content_flags;
46 inline void set_inconsistent(GtkWidget *toggle_button)
48 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON (toggle_button), TRUE);
51 inline void clear_inconsistent(GtkWidget *toggle_button)
53 if ( gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (toggle_button)) )
55 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON (toggle_button), FALSE);
59 void clear_all_inconsistent(void)
63 for (i = 0; i < MAX_BUTTONS; i++) {
64 clear_inconsistent( surface_buttons[i] );
65 clear_inconsistent( content_buttons[i] );
69 void clear_all_buttons_and_values()
73 for (i = 0; i < MAX_BUTTONS; i++) {
74 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON ( surface_buttons[i] ), FALSE);
75 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON ( content_buttons[i] ), FALSE);
78 gtk_entry_set_text( (GtkEntry *)value_entry, "");
81 void SetFlagButtons_UFOAI(texdef_to_face_t *texdef_face_list, bool b_isListEmpty)
86 int diff_contents = 0;
88 gboolean diff_value = FALSE;
91 texdef_to_face_t* temp_texdef_face_list;
95 working_surface_flags = 0;
97 working_content_flags = 0;
101 if (!b_isListEmpty) {
102 tmp_texdef = &texdef_face_list->texdef;
103 contents = tmp_texdef->contents;
104 flags = tmp_texdef->flags;
105 value = tmp_texdef->value;
107 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\ttmp_texdef\n",tmp_texdef->flags,tmp_texdef->contents,tmp_texdef->value);
108 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\n",flags,contents,value);
110 for (temp_texdef_face_list = texdef_face_list->next; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
112 tmp_texdef = &temp_texdef_face_list->texdef;
113 diff_contents |= contents ^ tmp_texdef->contents; // Figure out which buttons are inconsistent
114 diff_flags |= flags ^ tmp_texdef->flags;
115 if (tmp_texdef->value != value)
118 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\ttmp_texdef\n",tmp_texdef->flags,tmp_texdef->contents,tmp_texdef->value);
119 Sys_Printf("Surface: %d\tContents: %d\tValue: %d\n",flags,contents,value);
123 clear_all_inconsistent();
125 // If no faces/brushes are selected, clear everything and bail
127 clear_all_buttons_and_values();
128 setup_buttons = FALSE;
132 for (i = 0; i < MAX_BUTTONS; i++) {
133 // Set surface buttons to reflect brush/face flags, contents, and values
134 if(diff_flags & (1 << i))
135 set_inconsistent(surface_buttons[i]);
136 else if(flags & (1 << i))
137 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (surface_buttons[i]), TRUE);
139 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (surface_buttons[i]), FALSE);
141 if(diff_contents & (1 << i))
142 set_inconsistent(content_buttons[i]);
143 else if(contents & (1 << i))
144 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (content_buttons[i]), TRUE);
146 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (content_buttons[i]), FALSE);
151 gtk_entry_set_text( (GtkEntry *)value_entry, "");
153 working_value = value;
154 sprintf( tex_buff, "%d", value);
155 gtk_entry_set_text( (GtkEntry *)value_entry, tex_buff);
158 setup_buttons = FALSE;
161 void SetChangeInFlags_Face_UFOAI (texdef_to_face_t *texdef_face_list)
163 texdef_to_face_t *temp_texdef_face_list;
164 texdef_t *tmp_texdef;
166 for (temp_texdef_face_list = texdef_face_list; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
168 tmp_texdef = &temp_texdef_face_list->texdef;
169 tmp_texdef->flags = (tmp_texdef->flags & ~surface_mask) | working_surface_flags;
170 tmp_texdef->contents = (tmp_texdef->contents & ~content_mask) | working_content_flags;
171 tmp_texdef->value = working_value;
172 Sys_Printf("content_flag: %d content_mask: %d\n",working_content_flags,content_mask);
173 Sys_Printf("content: %d\n",tmp_texdef->contents);
177 inline void change_surfaceflag (GtkWidget *togglebutton, int sur_flag, gboolean change_flag_to)
179 if (!setup_buttons) // If we're setting up the buttons, we really don't need to
180 { // set flags that are already set
181 if (gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (togglebutton))) // Clear out inconsistent, if set
182 clear_inconsistent(GTK_WIDGET (togglebutton));
184 surface_mask |= sur_flag;
187 working_surface_flags |= sur_flag;
189 working_surface_flags &= ~sur_flag;
193 inline void change_contentflag (GtkWidget *togglebutton, int content_flag, gboolean change_flag_to)
195 if ( (!setup_buttons) ) // If we're setting up the buttons, we really don't need to
196 { // set flags that are already set
197 if (gtk_toggle_button_get_inconsistent(GTK_TOGGLE_BUTTON (togglebutton)))
198 clear_inconsistent(togglebutton);
199 //if (g_ptrSelectedFaces.GetSize() == 0) // Only changing content flags on whole brushes, not faces.
201 content_mask |= content_flag;
204 working_content_flags |= content_flag;
206 working_content_flags &= ~content_flag;
208 Sys_Printf("content_flag: %d content_mask: %d\n",content_flag,content_mask);
212 // Surface Flags Callbacks
213 void on_surface_button_toggled (GtkToggleButton *togglebutton, gpointer user_data)
215 int flag = *(int*)user_data;
216 change_surfaceflag(GTK_WIDGET (togglebutton), flag, (GTK_TOGGLE_BUTTON (togglebutton)->active));
219 // Content Flags Callbacks
220 void on_content_button_toggled (GtkToggleButton *togglebutton, gpointer user_data)
222 int flag = *(int*)user_data;
223 change_contentflag(GTK_WIDGET (togglebutton), flag, (GTK_TOGGLE_BUTTON (togglebutton)->active));
226 // Value Entry Callback
227 void on_value_entry_changed (GtkEditable *editable, gpointer user_data)
229 if ( (!setup_buttons) ) // If we're setting up the buttons, don't change value
230 working_value = atoi( gtk_entry_get_text( (GtkEntry*)editable) );
233 void on_value_entry_insert_text (GtkEditable *editable, gchar *new_text, gint new_text_length, gint *position, gpointer user_data)
238 // Limit input to digits, throwing out anything else
239 // Modified from Gtk FAQ for text filtering of GtkEntry
240 result = g_new (gchar, new_text_length);
242 for (i=0; i < new_text_length; i++) {
243 if (!isdigit(new_text[i]))
245 result[count++] = new_text[i];
249 gtk_signal_handler_block_by_func (GTK_OBJECT (editable),
250 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
252 gtk_editable_insert_text (editable, result, count, position);
253 gtk_signal_handler_unblock_by_func (GTK_OBJECT (editable),
254 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
257 gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "insert_text");
262 void on_surfacebutton_clicked (GtkButton *button, gpointer user_data)
264 gtk_notebook_set_page (GTK_NOTEBOOK(notebook1), 0);
267 void on_contentbutton_clicked (GtkButton *button, gpointer user_data)
269 gtk_notebook_set_page (GTK_NOTEBOOK(notebook1), 1);
272 // FIXME: This should be in the ufoai.game
273 static const char *surfaceFlags[] = {
308 static const char *contentFlags[] = {
343 static const int flagBitMasks[] = {
378 #define UFOAI_FLAG_BUTTON_BORDER 3
380 GtkWidget* Create_UFOAIFlagsDialog (GtkWidget* surfacedialog_widget)
390 GtkWidget *hseparator1;
391 GtkWidget *value_label;
397 frame1 = gtk_frame_new ("Flags");
398 gtk_widget_show (frame1);
399 gtk_container_add (GTK_CONTAINER (surfacedialog_widget), frame1);
401 vbox1 = gtk_vbox_new (FALSE, 0);
402 gtk_widget_show (vbox1);
403 gtk_container_add (GTK_CONTAINER (frame1), vbox1);
405 notebook1 = gtk_notebook_new ();
406 gtk_widget_show (notebook1);
407 gtk_box_pack_start (GTK_BOX (vbox1), notebook1, TRUE, TRUE, 0);
408 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook1), TRUE);
409 gtk_container_set_border_width (GTK_CONTAINER (notebook1), 5);
411 vbox2 = gtk_vbox_new (FALSE, 0);
412 gtk_widget_show (vbox2);
413 gtk_container_add (GTK_CONTAINER (notebook1), vbox2);
415 table4 = gtk_table_new (8, 4, FALSE);
416 gtk_widget_show (table4);
417 gtk_box_pack_start (GTK_BOX (vbox2), table4, TRUE, TRUE, 0);
420 for (i = 0; i < MAX_BUTTONS; i++) {
424 surface_buttons[i] = gtk_toggle_button_new_with_label (surfaceFlags[i]);
425 gtk_signal_connect(GTK_OBJECT (surface_buttons[i]), "toggled", GTK_SIGNAL_FUNC(on_surface_button_toggled), &flagBitMasks[i]);
426 gtk_widget_show(surface_buttons[i]);
427 gtk_table_attach(GTK_TABLE (table4), surface_buttons[i], 0 + x, 1 + x, (0 + y), (1 + y),
428 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
429 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
430 gtk_container_set_border_width (GTK_CONTAINER (surface_buttons[i]), UFOAI_FLAG_BUTTON_BORDER);
433 hseparator1 = gtk_hseparator_new ();
434 gtk_widget_show (hseparator1);
435 gtk_box_pack_start (GTK_BOX (vbox2), hseparator1, FALSE, FALSE, 0);
436 gtk_widget_set_usize (hseparator1, -2, 5);
438 hbox2 = gtk_hbox_new (FALSE, 0);
439 gtk_widget_show (hbox2);
440 gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
442 hbox3 = gtk_hbox_new (FALSE, 0);
443 gtk_widget_show (hbox3);
444 gtk_box_pack_start (GTK_BOX (hbox2), hbox3, TRUE, TRUE, 0);
446 vbox4 = gtk_vbox_new (FALSE, 0);
447 gtk_widget_show (vbox4);
448 gtk_box_pack_start (GTK_BOX (hbox3), vbox4, TRUE, TRUE, 0);
450 value_label = gtk_label_new (" Value: ");
451 gtk_widget_show (value_label);
452 gtk_box_pack_start (GTK_BOX (hbox3), value_label, FALSE, FALSE, 0);
454 value_entry = gtk_entry_new ();
455 gtk_signal_connect (GTK_OBJECT (value_entry), "changed",
456 GTK_SIGNAL_FUNC (on_value_entry_changed),
458 gtk_signal_connect (GTK_OBJECT (value_entry), "insert_text",
459 GTK_SIGNAL_FUNC (on_value_entry_insert_text),
461 gtk_entry_set_max_length( (GtkEntry *)value_entry, 11);
462 gtk_widget_show (value_entry);
463 gtk_box_pack_start (GTK_BOX (hbox3), value_entry, TRUE, TRUE, 0);
465 vbox3 = gtk_vbox_new (FALSE, 0);
466 gtk_widget_show (vbox3);
467 gtk_box_pack_start (GTK_BOX (hbox3), vbox3, TRUE, TRUE, 0);
469 label5 = gtk_label_new ("Surface Flags");
470 gtk_widget_show (label5);
471 gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 0), label5);
473 table3 = gtk_table_new (8, 4, FALSE);
474 gtk_widget_show (table3);
475 gtk_container_add (GTK_CONTAINER (notebook1), table3);
478 for (i = 0; i < MAX_BUTTONS; i++) {
482 content_buttons[i] = gtk_toggle_button_new_with_label(contentFlags[i]);
483 gtk_signal_connect(GTK_OBJECT (content_buttons[i]), "toggled", GTK_SIGNAL_FUNC (on_content_button_toggled), &flagBitMasks[i]);
484 gtk_widget_show(content_buttons[i]);
485 gtk_table_attach(GTK_TABLE (table3), content_buttons[i], 0 + x, 1 + x, (0 + y), (1 + y),
486 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
487 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
488 gtk_container_set_border_width (GTK_CONTAINER (content_buttons[i]), UFOAI_FLAG_BUTTON_BORDER);
491 label6 = gtk_label_new ("Content Flags");
492 gtk_widget_show (label6);
493 gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook1), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook1), 1), label6);