2 "$Id: config.c 9576 2008-07-19 23:42:35Z kbulgrien $";
41 #include <gdk/gdkwin32.h>
43 #include <gdk/gdkkeysyms.h>
99 #define MAX_BUTTONS 33
105 #define SPIN_SCALE 0x101
106 #define SPIN_MAP 0x102
107 #define SPIN_CWINDOW 0x103
109 #define FLAG_UPDATE 0x1
110 #define FLAG_MAPPANE 0x2
130 "Beep When Food is Low"},
132 "Timestamp Messages"},
136 "Echo Bound Commands"},
138 "Fast TCP Send (May improve performance at expense\n of outgoing bandwidth)"},
140 "Gradually change stat bar color based on value of the stat.\nThis option will result in some extra CPU usage."},
144 "Popup Sign Windows (need Popup Windows checked to be used)"},
148 "Show Inventory Icon"},
154 "Split Information Window (Takes effect next run)"},
158 "Trims text in the information window - "
159 "improves performance but bugs in\n gtk make the client unstable if this is used."
160 "This may work better with gtk 2.0"},
162 "Automatically re-applies a container when you use apply to close it. \nIf off, when you use apply to close the container, it stays unapplied"},
165 "Display resistances in two columns rather than only one."},
176 "Download All Image Information (Takes effect on next server connection)"},
180 "Icon Scale (Takes effect next run)"},
182 "Map Scale (Takes effect next run)"},
184 "Enable smoothing - Use additionnal CPU (Take effect on next connection)."},
186 "SDL Image Support (Take effect next run)"},
188 "Print Grid Overlay (SDL only, Slow, useful for debugging/development"},
191 "Lighting options, per pixel is prettier, per tile is faster.\nIf the darkness code is off, the pixel/tile options will be ignored."},
193 "Best Per Pixel Lighting (slowest)"},
195 "Fast Per Pixel Lighting"},
197 "Per Tile Lighting"},
199 "Enable darkness code - if off, all spaces will not be dimmed."},
202 "Map Size: Larger map lets you see more information, but takes more CPU\npower and bandwidth. Changing these will not take effect until the next time\nyou connect to a server"},
257 #define IS_DIFFERENT(TYPE) (want_config[TYPE] != use_config[TYPE])
266 for (onbutton =0; onbutton <
MAX_BUTTONS; onbutton++) {
267 if (cbuttons[onbutton].type ==
CBUTTON) {
268 set_config_value(onbutton, GTK_TOGGLE_BUTTON (cbuttons[onbutton].widget)->active);
269 }
else if (cbuttons[onbutton].type &
SPIN) {
270 set_config_value(onbutton, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(cbuttons[onbutton].widget)));
277 }
else if (cbuttons[onbutton].type ==
RBUTTON) {
282 if ( GTK_TOGGLE_BUTTON (cbuttons[onbutton].widget)->active) {
283 if ( cbuttons[onbutton].config >= 100 && cbuttons[onbutton].config < 200)
284 lighting = cbuttons[onbutton].
config - 100;
309 else gtk_tooltips_disable(
tooltips);
318 perror(
"TCP_NODELAY");
323 perror(
"TCP_NODELAY");
386 GtkWidget *applybutton;
387 GtkWidget *cancelbutton;
388 GtkWidget *savebutton;
390 GtkWidget *frame_map, *vbox_map;
391 GtkWidget *addwidget;
393 GtkWidget *clabel1, *clabel2, *clabel4, *clabel5, *cb1, *cb2, *cb3;
395 GtkWidget *extras[250];
399 gchar *titles[] ={
"#",
"Key",
"(#)",
"Mods",
"Command"};
403 int x, y, wx, wy, w, h;
415 gtk_widget_set_uposition(
gtkwin_config, (wx + w - 450)/2, (wy + h-500) / 2);
417 gtk_window_set_title (GTK_WINDOW (
gtkwin_config),
"Crossfire Configure");
422 gtk_container_border_width (GTK_CONTAINER (
gtkwin_config), 0);
427 vbox = gtk_vbox_new(
FALSE, 2);
430 notebook = gtk_notebook_new ();
431 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP );
432 gtk_box_pack_start (GTK_BOX(vbox),notebook,
TRUE,
TRUE, 0);
434 tablabel = gtk_label_new (
"General");
435 gtk_widget_show (tablabel);
437 frame1 = gtk_frame_new(
"General options");
438 gtk_frame_set_shadow_type (GTK_FRAME(frame1), GTK_SHADOW_ETCHED_IN);
439 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame1, tablabel);
441 vbox1 = gtk_vbox_new(
FALSE, 0);
442 gtk_container_add (GTK_CONTAINER(frame1), vbox1);
444 tablabel = gtk_label_new (
"Map & Image");
445 gtk_widget_show (tablabel);
447 frame_map = gtk_frame_new(
"Map and Image options");
448 gtk_frame_set_shadow_type (GTK_FRAME(frame_map), GTK_SHADOW_ETCHED_IN);
449 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame_map, tablabel);
451 vbox_map = gtk_vbox_new(
FALSE, 0);
452 gtk_container_add (GTK_CONTAINER(frame_map), vbox_map);
456 addwidget = vbox_map;
460 if (cbuttons[i].type ==
CBUTTON) {
461 cbuttons[i].
widget = gtk_check_button_new_with_label(cbuttons[i].label);
462 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(cbuttons[i].widget),
want_config[cbuttons[i].config]);
464 else if (cbuttons[i].type ==
RBUTTON) {
465 if ((i>0) && (cbuttons[i-1].type ==
RBUTTON)) {
466 cbuttons[i].
widget = gtk_radio_button_new_with_label_from_widget(
467 GTK_RADIO_BUTTON(cbuttons[i-1].widget), cbuttons[i].label);
469 cbuttons[i].
widget = gtk_radio_button_new_with_label(NULL, cbuttons[i].label);
472 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(cbuttons[i].widget), 1);
474 else if (cbuttons[i].type &
SPIN) {
475 GtkAdjustment *adj=NULL;
478 adj = (GtkAdjustment *) gtk_adjustment_new(
want_config[cbuttons[i].config], 25, 200, 1, 5, 5);
479 else if (cbuttons[i].type ==
SPIN_MAP)
482 adj = (GtkAdjustment *) gtk_adjustment_new(
want_config[cbuttons[i].config], 1, 127, 1, 5, 5);
483 cbuttons[i].
widget = gtk_spin_button_new(adj, 1, 0);
484 extras[num_extras] = gtk_hbox_new(
FALSE, 2);
485 gtk_box_pack_start(GTK_BOX(extras[num_extras]), cbuttons[i].widget,
FALSE,
FALSE, 0);
486 extras[++num_extras] = gtk_label_new(cbuttons[i].label);
487 gtk_box_pack_start(GTK_BOX(extras[num_extras-1]), extras[num_extras],
FALSE,
FALSE, 0);
488 gtk_box_pack_start(GTK_BOX(addwidget), extras[num_extras-1],
FALSE,
FALSE, 0);
490 extras[num_extras++] = cbuttons[i].
widget;
493 else if (cbuttons[i].type ==
SEPERATOR) {
494 extras[num_extras] = (GtkWidget*)gtk_hseparator_new ();
495 gtk_box_pack_start (GTK_BOX (addwidget), extras[num_extras],
FALSE,
FALSE, 0);
496 cbuttons[i].
widget = gtk_label_new(cbuttons[i].label);
497 gtk_label_set_justify(GTK_LABEL(cbuttons[i].widget), GTK_JUSTIFY_LEFT);
501 LOG(
LOG_WARNING,
"gtk::configdialog",
"Unknown cbutton type %d", cbuttons[i].type);
503 if (cbuttons[i].widget) {
504 extras[num_extras++] = cbuttons[i].
widget;
505 gtk_box_pack_start(GTK_BOX(addwidget), cbuttons[i].widget,
FALSE,
FALSE, 0);
509 for (i=0; i < num_extras; i++) {
510 gtk_widget_show(extras[i]);
527 flist = g_list_append(flist,
"standard");
528 flist = g_list_append(flist,
"classic");
530 if (flist) gtk_combo_set_popdown_strings(GTK_COMBO(
faceset_combo), flist);
531 addwidget = gtk_hbox_new(
FALSE, 0);
533 tablabel = gtk_label_new(
"Faceset to use. Only takes effect for new\n face information from server. Not supported on\n all servers.");
534 gtk_label_set_justify(GTK_LABEL(tablabel), GTK_JUSTIFY_LEFT);
535 gtk_box_pack_start(GTK_BOX(addwidget), tablabel,
FALSE,
FALSE, 0);
537 gtk_box_pack_start(GTK_BOX(vbox_map), addwidget,
FALSE,
FALSE, 0);
538 gtk_widget_show(tablabel);
540 gtk_widget_show(addwidget);
542 gtk_widget_show (vbox1);
543 gtk_widget_show (frame1);
544 gtk_widget_show(vbox_map);
545 gtk_widget_show(frame_map);
553 tablabel = gtk_label_new (
"Keybindings");
554 gtk_widget_show (tablabel);
555 vbox2 = gtk_vbox_new(
FALSE, 0);
556 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox2, tablabel);
557 frame1 = gtk_frame_new(
"Keybindings");
558 gtk_frame_set_shadow_type (GTK_FRAME(frame1), GTK_SHADOW_ETCHED_IN);
559 gtk_box_pack_start (GTK_BOX (vbox2), frame1,
TRUE,
TRUE, 0);
560 vbox1 = gtk_vbox_new(
FALSE, 0);
561 gtk_container_add (GTK_CONTAINER(frame1), vbox1);
562 cclists = gtk_scrolled_window_new (0,0);
563 cclist = gtk_clist_new_with_titles (5, titles);
565 gtk_clist_set_column_width (GTK_CLIST(
cclist), 0, 20);
566 gtk_clist_set_column_width (GTK_CLIST(
cclist), 1, 50);
567 gtk_clist_set_column_width (GTK_CLIST(
cclist), 2, 20);
568 gtk_clist_set_column_width (GTK_CLIST(
cclist), 3, 40);
569 gtk_clist_set_column_width (GTK_CLIST(
cclist), 4, 245);
570 gtk_clist_set_selection_mode (GTK_CLIST(
cclist) , GTK_SELECTION_SINGLE);
572 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(cclists),
573 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
574 gtk_container_add (GTK_CONTAINER (cclists),
cclist);
575 gtk_box_pack_start (GTK_BOX(vbox1),cclists,
TRUE,
TRUE, 0);
578 gtk_signal_connect_after (GTK_OBJECT(
cclist),
584 gtk_widget_show(cclists);
586 ehbox=gtk_hbox_new(
FALSE, 0);
589 clabel1 = gtk_label_new (
"Binding #:");
590 gtk_box_pack_start (GTK_BOX (ehbox),clabel1,
FALSE,
TRUE, 2);
591 gtk_widget_show (clabel1);
598 clabel2 = gtk_label_new (
"Key:");
599 gtk_box_pack_start (GTK_BOX (ehbox),clabel2,
FALSE,
TRUE, 2);
600 gtk_widget_show (clabel2);
605 gtk_signal_connect(GTK_OBJECT(
ckeyentrytext),
"key_press_event",
609 gtk_entry_set_text (GTK_ENTRY(
ckeyentrytext),
"Press key to bind here");
611 clabel4 = gtk_label_new (
"Mods:");
612 gtk_box_pack_start (GTK_BOX (ehbox),clabel4,
FALSE,
TRUE, 2);
613 gtk_widget_show (clabel4);
620 gtk_box_pack_start (GTK_BOX (vbox1),ehbox,
FALSE,
TRUE, 2);
622 gtk_widget_show (ehbox);
624 ehbox=gtk_hbox_new(
FALSE, 0);
626 clabel5 = gtk_label_new (
"Command:");
627 gtk_box_pack_start (GTK_BOX (ehbox),clabel5,
FALSE,
TRUE, 2);
628 gtk_widget_show (clabel5);
634 gtk_box_pack_start (GTK_BOX (vbox1),ehbox,
FALSE,
TRUE, 2);
636 gtk_widget_show (ehbox);
638 ehbox=gtk_hbox_new(
TRUE, 0);
641 cb1 = gtk_button_new_with_label (
"Unbind");
642 gtk_box_pack_start (GTK_BOX (ehbox),cb1,
FALSE,
TRUE, 4);
644 gtk_signal_connect_object (GTK_OBJECT (cb1),
"clicked",
647 gtk_widget_show (cb1);
649 cb2 = gtk_button_new_with_label (
"Bind");
650 gtk_box_pack_start (GTK_BOX (ehbox),cb2,
FALSE,
TRUE, 4);
651 gtk_signal_connect_object (GTK_OBJECT (cb2),
"clicked",
655 gtk_widget_show (cb2);
657 cb3 = gtk_button_new_with_label (
"Clear");
658 gtk_box_pack_start (GTK_BOX (ehbox),cb3,
FALSE,
TRUE, 4);
660 gtk_signal_connect_object (GTK_OBJECT (cb3),
"clicked",
663 gtk_widget_show (cb3);
664 gtk_box_pack_start (GTK_BOX (vbox1),ehbox,
FALSE,
TRUE, 2);
666 gtk_widget_show (ehbox);
668 gtk_widget_show (vbox1);
669 gtk_widget_show (frame1);
670 gtk_widget_show (vbox2);
672 gtk_widget_show (notebook);
676 hbox1 = gtk_hbox_new(
TRUE, 0);
677 gtk_box_pack_start(GTK_BOX(vbox), hbox1,
FALSE,
FALSE, 6);
678 savebutton = gtk_button_new_with_label(
"Save");
679 gtk_signal_connect_object (GTK_OBJECT (savebutton),
"clicked",
682 gtk_box_pack_start(GTK_BOX(hbox1), savebutton,
FALSE,
TRUE, 4);
684 applybutton = gtk_button_new_with_label(
"Apply");
685 gtk_signal_connect_object (GTK_OBJECT (applybutton),
"clicked",
688 gtk_box_pack_start(GTK_BOX(hbox1), applybutton,
FALSE,
TRUE, 4);
690 cancelbutton = gtk_button_new_with_label(
"Close");
691 gtk_signal_connect_object (GTK_OBJECT (cancelbutton),
"clicked",
692 GTK_SIGNAL_FUNC(gtk_widget_destroy),
695 gtk_box_pack_start(GTK_BOX(hbox1), cancelbutton,
FALSE,
TRUE, 4);
696 gtk_widget_show(savebutton);
697 gtk_widget_show(applybutton);
698 gtk_widget_show(cancelbutton);
700 gtk_widget_show (hbox1);
701 gtk_widget_show (vbox);
721 sprintf(path,
"%s/.crossfire/gdefaults", getenv(
"HOME"));
722 if ((fp=fopen(path,
"r"))==NULL)
return;
723 while (fgets(inbuf,
MAX_BUF-1, fp)) {
725 inbuf[strlen(inbuf)-1]=
'\0';
727 if (inbuf[0]==
'#')
continue;
729 if (!(cp=strchr(inbuf,
':')))
continue;
734 if (isdigit(*cp)) val=atoi(cp);
735 else if (!strcmp(cp,
"True")) val =
TRUE;
736 else if (!strcmp(cp,
"False")) val =
FALSE;
741 LOG(
LOG_WARNING,
"gtk::load_defaults",
"Invalid value/line: %s: %s", inbuf, cp);
749 if (i < CONFIG_NUMS)
continue;
754 if (!strcmp(inbuf,
"mapsize")) {
756 LOG(
LOG_WARNING,
"gtk::load_defaults",
"Malformed mapsize option in gdefaults. Ignoring");
759 else if (!strcmp(inbuf,
"server")) {
763 else if (!strcmp(inbuf,
"sound_server")) {
767 else if (!strcmp(inbuf,
"nopopups")) {
772 else if (!strcmp(inbuf,
"nosplash")) {
776 else if (!strcmp(inbuf,
"splash")) {
780 else if (!strcmp(inbuf,
"faceset")) {
785 else if (!strcmp(inbuf,
"resists")) {
788 else if (!strcmp(inbuf,
"sdl")) {
793 else LOG(
LOG_WARNING,
"gtk::load_defaults",
"Unknown line in gdefaults: %s %s", inbuf, cp);
801 LOG(
LOG_WARNING,
"gtk::load_defaults",
"Ignoring iconscale value read for gdefaults file.\n"
802 "Invalid iconscale range (%d), valid range for -iconscale is 25 through 200",
807 LOG(
LOG_WARNING,
"gtk::load_defaults",
"ignoring mapscale value read for gdefaults file.\n"
808 "Invalid mapscale range (%d), valid range for -iconscale is 25 through 200",
813 LOG(
LOG_WARNING,
"gtk::load_defaults",
"No lighting mechanism selected - will not use darkness code");
820 "Invalid map width (%d) option in gdefaults. Valid range is 9 to %d",
826 "Invalid map height (%d) option in gdefaults. Valid range is 9 to %d",
854 sprintf(path,
"%s/.crossfire/gdefaults", getenv(
"HOME"));
856 LOG(
LOG_ERROR,
"gtk::save_defaults",
"Could not create %s", path);
859 if ((fp=fopen(path,
"w"))==NULL) {
860 LOG(
LOG_ERROR,
"gtk::save_defaults",
"Could not open %s", path);
863 fprintf(fp,
"# This file is generated automatically by crossfire-client-gtk.\n");
864 fprintf(fp,
"# Manual editing is allowed, but the client may be finicky about\n");
865 fprintf(fp,
"# some of the matching it does. All comparisons are case sensitive.\n");
866 fprintf(fp,
"# 'True' and 'False' are the proper cases for those two values\n");
867 fprintf(fp,
"# 'True' and 'False' have been replaced with 1 and 0 respectively\n");
868 fprintf(fp,
"server: %s\n",
server);
881 sprintf(buf,
"Defaults saved to %s",path);
void inventory_splitwin_toggling(void)
static void set_config_value(int cval, int value)
void init_SDL(GtkWidget *sdl_window, int just_lightmap)
#define DEFAULT_IMAGE_SIZE
static void toggle_splitwin(int newval)
void configdialog(GtkWidget *widget)
#define CONFIG_APPLY_CONTAINER
int make_path_to_file(char *filename)
Face_Information face_info
void get_window_coord(GtkWidget *win, int *x, int *y, int *wx, int *wy, int *w, int *h)
sint16 want_config[CONFIG_NUMS]
GtkWidget * ckeyentrytext
void bind_callback(GtkWidget *gtklist, GdkEventButton *event)
void draw_keybindings(GtkWidget *keylist)
#define CFG_LT_PIXEL_BEST
void draw_stats(int redraw)
void LOG(LogLevel level, const char *origin, const char *format,...)
static GtkWidget * gtkwin_config
void display_map_doneupdate(int redraw, int notice)
int cs_print_string(int fd, const char *str,...)
void draw_message_window(int redraw)
sint16 use_config[CONFIG_NUMS]
void create_windows(void)
#define CONFIG_GRAD_COLOR
void ckeyentry_callback(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
GtkWidget * cnumentrytext
static void applyconfig(void)
static void saveconfig(void)
void main_window_destroyed(void)
void ckeyunbind(GtkWidget *gtklist, GdkEventButton *event)
GtkWidget * gtkwin_message
#define IS_DIFFERENT(TYPE)
const char *const rcsid_gtk_config_c
char * strdup_local(const char *str)
static int splitwin_toggling
void cclist_button_event(GtkWidget *gtklist, gint row, gint column, GdkEventButton *event)
void draw_info(const char *str, int color)
static CButtons cbuttons[MAX_BUTTONS]
#define CONFIG_DISPLAYMODE
GtkWidget * cmodentrytext
void reset_stat_bars(void)
static GtkWidget * faceset_combo
const char *const config_names[CONFIG_NUMS]
void itemlist_set_show_icon(itemlist *l, int new_setting)
void resize_resistance_table(int resists_show)
void update_list_labels(itemlist *l)