[Freeciv-Dev] PATCH: (fixed version) gui-gtk: metaserver dialog
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Please ignore the previous gui-gtk patch. This is the right one. Sorry. Index: connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/connectdlg.c,v
retrieving revision 1.20
diff -u -r1.20 connectdlg.c
--- connectdlg.c 2000/07/22 14:20:07 1.20
+++ connectdlg.c 2000/09/23 20:06:08
@@ -16,9 +16,14 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <gtk/gtk.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#include "fcintl.h"
#include "support.h"
#include "version.h"
@@ -30,12 +35,18 @@
#include "gui_stuff.h"
#include "connectdlg.h"
+#include "helpdlg_g.h"
+#define AUTOSTART_SERVER _("(Autostarted)")
+
/* in civclient.c; FIXME hardcoded sizes */
extern char name[];
extern char server_host[];
extern int server_port;
+static int server_game_running;
+static int server_autostart;
+
static GtkWidget *iname, *ihost, *iport;
static GtkWidget *connw, *quitw;
@@ -51,24 +62,239 @@
static int get_meta_list(GtkWidget *list, char *errbuf, int n_errbuf);
+static int group_vals[20]; /* The values of Options radio buttons */
+
+static int option_suggest_name=TRUE, option_hide_inactive=TRUE;
+
+
/**************************************************************************
...
**************************************************************************/
-static void connect_callback(GtkWidget *w, gpointer data)
+static void start_localgame(void)
{
- char errbuf [512];
+ char buf[200];
+ int aifill[] ={2+1, 4+1, 8+1};
+ int xsize[] ={50, 60, 80};
+ int ysize[] ={40, 50, 50};
+ char *difficulty[]={"easy", "hard"};
+ int gen [] ={1,2};
+
+ sprintf(buf, "/set aifill %d", aifill[group_vals[0]]);
+ server_command(buf);
+ sprintf(buf, "/set xsize %d", xsize[group_vals[1]]);
+ server_command(buf);
+ sprintf(buf, "/set ysize %d", ysize[group_vals[1]]);
+ server_command(buf);
+ sprintf(buf, "/%s", difficulty[group_vals[2]]);
+ server_command(buf);
+ sprintf(buf, "/set generator %d", gen[group_vals[3]]);
+ server_command(buf);
+ server_command("/start");
+}
- mystrlcpy(name, gtk_entry_get_text(GTK_ENTRY(iname)), 512);
- mystrlcpy(server_host, gtk_entry_get_text(GTK_ENTRY(ihost)), 512);
- server_port=atoi(gtk_entry_get_text(GTK_ENTRY(iport)));
-
- if(connect_to_server(name, server_host, server_port,
- errbuf, sizeof(errbuf))!=-1) {
+/**************************************************************************
+...
+**************************************************************************/
+int start_server(int port)
+{
+ char buf[200];
+
+ sprintf(buf,"(civserver -b -p %d &) >/dev/null", port);
+ return system(buf);
+#if 0
+ /* does not work */
+ if ((server_pid=fork())<0) {
+ append_output_window(_("Lost connection to server!"));
+ return 1;
+ } else if (server_pid==0) { /* child */
+ sprintf(buf,"%d",port);
+ freopen("/dev/null", "w", stdout);
+ execlp("civserver", "civserver", "-b", "-p", buf);
+ exit(0);
+ }
+ sleep(2);
+ return 0;
+#endif
+}
+/**************************************************************************
+...
+**************************************************************************/
+static GtkWidget *input_dialog;
+
+static void sel_name_dialog_destroy(GtkWidget *button)
+{
+ GtkWidget *parent;
+
+ parent=gtk_object_get_data(GTK_OBJECT(button->parent->parent->parent),
+ "parent");
+
+ gtk_widget_set_sensitive(parent, TRUE);
+
+ gtk_widget_destroy(button->parent->parent->parent);
+}
+
+
+static gint sel_name_del_callback(GtkWidget *widget, GdkEvent *event,
+ gpointer data)
+{
+ gtk_widget_set_sensitive( (GtkWidget *)data, TRUE );
+ return FALSE;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void connection_attempt(char *tempname, int fromlist);
+static char joinas_name[128];
+
+static void select_name_callback(GtkWidget *w, gpointer data)
+{
+ sel_name_dialog_destroy(w);
+
+ if(data)
+ connection_attempt(joinas_name, TRUE);
+}
+
+void sel_name_radio_callback( GtkWidget *w, gpointer data )
+{
+ sz_strlcpy(joinas_name, data);
+}
+
+static void gui_select_name(char *joinas)
+{
+ GtkWidget *shell, *frame, *ok, *cancel, *parent=dialog, *button, *vbox;
+ GSList *namegroup=0;
+ static char namebuf[1024];
+ char *r, *w, *name;
+
+ gtk_widget_set_sensitive(parent, FALSE);
+
+ shell=gtk_dialog_new();
+ gtk_signal_connect(GTK_OBJECT(shell),"delete_event",
+ GTK_SIGNAL_FUNC(sel_name_del_callback), parent);
+
+ gtk_window_set_title(GTK_WINDOW(shell), _("Select player name"));
+
+ gtk_container_border_width(GTK_CONTAINER(GTK_DIALOG(shell)->vbox), 5);
+
+ frame=gtk_frame_new("Select player name");
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(shell)->vbox), frame, TRUE, TRUE, 0);
+
+ vbox = gtk_vbox_new(0,TRUE);
+ r=joinas;
+ w=namebuf;
+ do {
+ if (*r==';')
+ break;
+
+ name=w;
+ for ( ; *r && *r!=',' && *r!=';'; r++)
+ *w++ = *r;
+ *w++=0;
+ for ( ; *r && strchr(" ,",*r); r++) ;
+
+ if (name==namebuf)
+ sz_strlcpy(joinas_name, name);
+
+ button=gtk_radio_button_new_with_label(namegroup, name);
+ namegroup = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
+ gtk_signal_connect(GTK_OBJECT(button), "toggled",
+ GTK_SIGNAL_FUNC(sel_name_radio_callback), name);
+ gtk_box_pack_start( GTK_BOX( vbox ), button, TRUE, FALSE, 0 );
+ gtk_widget_show (button);
+ } while(*r);
+ gtk_container_add(GTK_CONTAINER(frame), vbox);
+
+
+ ok=gtk_button_new_with_label(_("Ok"));
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(shell)->action_area),
+ ok, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(ok), "clicked",
+ GTK_SIGNAL_FUNC(select_name_callback), (gpointer)1);
+
+ cancel=gtk_button_new_with_label(_("Cancel"));
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(shell)->action_area),
+ cancel, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(cancel), "clicked",
+ GTK_SIGNAL_FUNC(select_name_callback), 0);
+
+ gtk_set_relative_position(parent, shell, 10, 10);
+
+ gtk_object_set_data(GTK_OBJECT(shell), "parent",parent);
+
+ gtk_widget_show_all(GTK_DIALOG(shell)->vbox);
+ gtk_widget_show_all(GTK_DIALOG(shell)->action_area);
+ gtk_widget_show(shell);
+
+ input_dialog=shell;
+}
+
+
+/**************************************************************************
+...
+**************************************************************************/
+static void rules_callback(GtkWidget *w, gpointer data)
+{
+ popup_help_dialog_string(HELP_ESSENTIALS_ITEM);
+}
+
+
+/**************************************************************************
+...
+**************************************************************************/
+static char *joinas_names;
+
+static void connection_attempt(char *tempname, int fromlist)
+{
+ char errbuf [512], ok, attempts=0;
+
+ if (*server_host=='-') /* An error message */
+ return;
+
+ server_autostart= !strcmp(server_host, AUTOSTART_SERVER);
+
+ if (server_autostart) {
+ mystrlcpy(server_host, "localhost", 512);
+ server_port=5555;
+
+ if (start_server(server_port))
+ append_output_window(_("Failed to start server"));
+ }
+
+ if (option_suggest_name && !fromlist && server_game_running
+ && joinas_names && *joinas_names) {
+ gui_select_name(joinas_names);
+ return;
+ }
+
+ do {
+ ok=connect_to_server(tempname, server_host, server_port,
+ errbuf, sizeof(errbuf)) != -1;
+ if (server_autostart && !ok)
+ sleep(1);
+ } while (server_autostart && !ok && ++attempts<=5);
+
+ if (ok) {
gtk_widget_destroy(dialog);
gtk_widget_set_sensitive(toplevel,TRUE);
+
+ if (server_autostart)
+ start_localgame();
}
- else
+ else {
append_output_window(errbuf);
+ if (server_autostart)
+ append_output_window("Make sure the latest civserver is first in
path\n");
+ }
+}
+
+static void connect_callback(GtkWidget *w, gpointer data)
+{
+ mystrlcpy(name, gtk_entry_get_text(GTK_ENTRY(iname)), 512);
+ mystrlcpy(server_host, gtk_entry_get_text(GTK_ENTRY(ihost)), 512);
+ server_port=atoi(gtk_entry_get_text(GTK_ENTRY(iport)));
+
+ connection_attempt(name, FALSE);
}
/**************************************************************************
@@ -97,14 +323,25 @@
/**************************************************************************
...
**************************************************************************/
+#define MAXSERVERS 100
+static char *joinas_list[MAXSERVERS];
+
void meta_list_callback(GtkWidget *w, gint row, gint column)
{
- gchar *name, *port;
+ gchar *name, *port, *status;
gtk_clist_get_text(GTK_CLIST(w), row, 0, &name);
gtk_entry_set_text(GTK_ENTRY(ihost), name);
+ mystrlcpy(server_host, name, 512);
+
gtk_clist_get_text(GTK_CLIST(w), row, 1, &port);
gtk_entry_set_text(GTK_ENTRY(iport), port);
+ server_port=atoi(port);
+
+ gtk_clist_get_text(GTK_CLIST(w), row, 3, &status);
+ server_game_running=!strcmp(status,"Running");
+
+ joinas_names = joinas_list[row];
}
/**************************************************************************
@@ -127,36 +364,52 @@
/**************************************************************************
...
**************************************************************************/
-void gui_server_connect(void)
-{
- GtkWidget *label, *table, *book, *scrolled, *list, *vbox, *update;
- static char *titles_[6]= {N_("Server Name"), N_("Port"), N_("Version"),
- N_("Status"), N_("Players"), N_("Comment")};
- static char **titles;
- char buf [256];
- int i;
-
- if (!titles) titles = intl_slist(6, titles_);
+static int button_group_num, button_num;
- gtk_widget_set_sensitive(turn_done_button, FALSE);
- gtk_widget_set_sensitive(toplevel, FALSE);
-
- dialog=gtk_dialog_new();
- gtk_signal_connect(GTK_OBJECT(dialog),"delete_event",
- GTK_SIGNAL_FUNC(connect_deleted_callback), NULL);
-
- gtk_window_set_title(GTK_WINDOW(dialog), _(" Connect to Freeciv Server"));
+static void buttons_callback( GtkWidget *w, gpointer data )
+{
+ group_vals[(int)data/16]= (int)data%16;
+}
- book = gtk_notebook_new ();
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), book, TRUE, TRUE, 0);
+static void
+button_in_table(int groupnum, char *label, int active,
+ GtkWidget *table, int x, int y)
+{
+ static GSList *group;
+ int xx= x>=0?x+1:-x+2, yy=y>=0?y+1:-y+2;
+ GtkWidget *button;
+
+ x=x>=0?x:-x; y=y>=0?y:-y;
+
+ if (button_group_num != groupnum)
+ group=0, button_num=0, button_group_num=groupnum;
+
+ button = gtk_radio_button_new_with_label (group, label);
+ group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
+ gtk_table_attach (GTK_TABLE(table), button, x, xx, y, yy, GTK_FILL,0,0,0);
+ gtk_signal_connect(GTK_OBJECT(button), "toggled",
+ GTK_SIGNAL_FUNC(buttons_callback), (gpointer)(groupnum*16 +
button_num++));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
+ gtk_widget_show (button);
+}
+/**************************************************************************
+The "Options" tab of the connect dialog
+**************************************************************************/
+static int create_local_entry(GtkWidget *list);
- label=gtk_label_new(_("Freeciv Server Selection"));
+static GtkWidget *gui_name_selection(void)
+{
+ GtkWidget *vbox, *label, *table, *update, *list, *scrolled;
+ int i;
+ static char **titles;
+ static char *titles_[6]= {N_("Server Name"), N_("Port"), N_("Version"),
+ N_("Status"), N_("Players"), N_("Comment")};
vbox=gtk_vbox_new(FALSE, 2);
- gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox, label);
- table = gtk_table_new (4, 2, FALSE);
+ /*--------------Name: field---------------*/
+ table = gtk_table_new (1, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
gtk_container_border_width (GTK_CONTAINER (table), 5);
@@ -168,26 +421,8 @@
iname=gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(iname), name);
- gtk_table_attach_defaults (GTK_TABLE (table), iname, 1, 2, 0, 1);
-
- label=gtk_label_new(_("Host:"));
- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, 0, 0, 0, 0);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-
- ihost=gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(ihost), server_host);
- gtk_table_attach_defaults (GTK_TABLE (table), ihost, 1, 2, 1, 2);
+ gtk_table_attach_defaults (GTK_TABLE (table), iname, 1, 3, 0, 1);
- label=gtk_label_new(_("Port:"));
- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, 0, 0, 0, 0);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-
- my_snprintf(buf, sizeof(buf), "%d", server_port);
-
- iport=gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(iport), buf);
- gtk_table_attach_defaults (GTK_TABLE (table), iport, 1, 2, 2, 3);
-
#if IS_BETA_VERSION
{
GtkWidget *label2;
@@ -201,11 +436,9 @@
gtk_table_attach_defaults (GTK_TABLE (table), label2, 0, 2, 3, 4);
}
#endif
-
- label=gtk_label_new(_("Metaserver"));
- vbox=gtk_vbox_new(FALSE, 2);
- gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox, label);
+ /*--------------Server list---------------*/
+ if (!titles) titles = intl_slist(6, titles_);
list=gtk_clist_new_with_titles(6, titles);
gtk_clist_column_titles_passive(GTK_CLIST(list));
@@ -213,28 +446,242 @@
for(i=0; i<6; i++)
gtk_clist_set_column_auto_resize(GTK_CLIST(list), i, TRUE);
+ create_local_entry(list);
+
scrolled=gtk_scrolled_window_new(NULL,NULL);
gtk_container_add(GTK_CONTAINER(scrolled), list);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0);
- update=gtk_button_new_with_label(_("Update"));
+
+ /*--------------Update button---------------*/
+ update=gtk_button_new_with_label(_("Find online games"));
gtk_box_pack_start(GTK_BOX(vbox), update, FALSE, FALSE, 2);
+
+ /*--------------Signals---------------------*/
gtk_signal_connect(GTK_OBJECT(list), "select_row",
GTK_SIGNAL_FUNC(meta_list_callback), NULL);
gtk_signal_connect(GTK_OBJECT(list), "button_press_event",
GTK_SIGNAL_FUNC(meta_click_callback), NULL);
gtk_signal_connect(GTK_OBJECT(update), "clicked",
GTK_SIGNAL_FUNC(meta_update_callback), (gpointer)list);
+ gtk_clist_select_row(GTK_CLIST(list),0,0);
+
+ gtk_signal_connect(GTK_OBJECT(iname), "activate",
+ GTK_SIGNAL_FUNC(connect_callback), NULL);
+
+ return vbox;
+}
+
+
+/**************************************************************************
+The "Options" tab of the connect dialog
+**************************************************************************/
+
+static GtkWidget *gui_options(void)
+{
+ GtkWidget *vbox, *label, *frame, *table;
+
+ vbox=gtk_vbox_new(FALSE, 2);
+ frame=gtk_frame_new("Autostart server options");
+ gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+
+ /* Create and attach table */
+ table = gtk_table_new (4, 5, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 2);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 5);
+ gtk_container_border_width (GTK_CONTAINER (table), 5);
+ gtk_container_add(GTK_CONTAINER(frame), table);
+
+ /*-------------------number of opponents------------------*/
+ button_group_num=-1;
+ label=gtk_label_new(_("Opponents:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL,0,0,0);
+ button_in_table(0, "2", FALSE, table, 1, 0);
+ button_in_table(0, "4", TRUE, table, 2, 0);
+ button_in_table(0, "8", FALSE, table, 3, 0);
+
+ /*-------------------mapsize------------------------------*/
+ label=gtk_label_new(_("Map size:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL,0,0,0);
+ button_in_table(1, "50x40", FALSE, table, 1, 1);
+ button_in_table(1, "60x50", TRUE, table, 2, 1);
+ button_in_table(1, "80x50", FALSE, table, 3, 1);
+
+ /*-------------------difficulty---------------------------*/
+ label=gtk_label_new(_("Difficulty:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL,0,0,0);
+ button_in_table(2, _("easy"), TRUE, table, 1, 2);
+ button_in_table(2, _("hard"), FALSE, table, 2, 2);
+
+ /*-------------------islands------------------------------*/
+ label=gtk_label_new(_("Islands:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_FILL,0,0,0);
+ button_in_table(3, _("random"), TRUE, table, 1, 3);
+ button_in_table(3, _("one per player"), FALSE, table, -2, 3);
+
+ return vbox;
+}
+
+
+
+
+/**************************************************************************
+The "Advanced" tab of the connect dialog
+**************************************************************************/
+static GtkWidget *options_toggle1, *options_toggle2;
+static void options_toggle_callback( GtkWidget *w, gpointer data )
+{
+ option_suggest_name= GTK_TOGGLE_BUTTON(options_toggle1)->active;
+ option_hide_inactive=GTK_TOGGLE_BUTTON(options_toggle2)->active;
+}
+
+static GtkWidget *gui_advanced(void)
+{
+ GtkWidget *vbox, *vbox2, *label, *frame, *table;
+ char buf[10];
+
+ vbox=gtk_vbox_new(FALSE, 2);
+
+ /*====================server list options=======================*/
+ frame=gtk_frame_new(_("Server list options"));
+ gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+
+ table = gtk_table_new (2, 1, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 2);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 5);
+ gtk_container_border_width (GTK_CONTAINER (table), 5);
+ gtk_container_add(GTK_CONTAINER(frame), table);
+
+ /*-------------------suggest names------------------------------*/
+ options_toggle1= gtk_check_button_new_with_label(
+ _("Suggest names when joining running game"));
+ gtk_table_attach(GTK_TABLE (table), options_toggle1,0,1,0,1, GTK_FILL,0,0,0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(options_toggle1),
+ option_suggest_name);
+ gtk_signal_connect(GTK_OBJECT(options_toggle1), "toggled",
+ GTK_SIGNAL_FUNC(options_toggle_callback), NULL);
+
+ /*-------------------hide servers------------------------------*/
+ options_toggle2= gtk_check_button_new_with_label(
+ _("Hide inactive and full servers"));
+ gtk_table_attach(GTK_TABLE (table), options_toggle2,0,1,1,2, GTK_FILL,0,0,0);
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(options_toggle2),
+ option_hide_inactive);
+ gtk_signal_connect(GTK_OBJECT(options_toggle2), "toggled",
+ GTK_SIGNAL_FUNC(options_toggle_callback), NULL);
+
+
+ /*====================manual server selection=======================*/
+ frame=gtk_frame_new(_("Manual server specification"));
+ gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+
+ vbox2=gtk_vbox_new(FALSE, 2);
+ gtk_container_add(GTK_CONTAINER(frame), vbox2);
+
+ /*--------------------server name----------------------------*/
+ table = gtk_table_new (2, 2, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 2);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 5);
+ gtk_container_border_width (GTK_CONTAINER (table), 5);
+ gtk_box_pack_start(GTK_BOX(vbox2), table, FALSE, TRUE, 0);
+
+
+ /*--------------------server host----------------------------*/
+ label=gtk_label_new(_("Host:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, 0,0,0,0);
+
+ ihost=gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(ihost), server_host);
+ gtk_table_attach_defaults (GTK_TABLE (table), ihost, 1, 2, 0, 1);
+
+ /*--------------------server port----------------------------*/
+ label=gtk_label_new(_("Port:"));
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, 0,0,0,0);
+
+ sprintf(buf, "%d", server_port);
+ iport=gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(iport), buf);
+ gtk_table_attach_defaults (GTK_TABLE (table), iport, 1, 2, 1, 2);
+
+ gtk_signal_connect(GTK_OBJECT(ihost), "activate",
+ GTK_SIGNAL_FUNC(connect_callback), NULL);
+ gtk_signal_connect(GTK_OBJECT(iport), "activate",
+ GTK_SIGNAL_FUNC(connect_callback), NULL);
+
+ return vbox;
+}
+
+
+/**************************************************************************
+...
+**************************************************************************/
+
+void gui_server_connect(void)
+{
+ GtkWidget *label, *book, *vbox, *vbox2, *vbox3, *rulesw;
+ GdkGeometry gdkGeometry;
+
+ mystrlcpy(server_host, "localhost", 512);
+ server_port=5555;
+ server_game_running=0;
+
+ memset(&gdkGeometry,0,sizeof(gdkGeometry));
+ gdkGeometry.min_width=600;
+ gdkGeometry.min_height=300;
+
+ gtk_widget_set_sensitive(turn_done_button, FALSE);
+ gtk_widget_set_sensitive(toplevel, FALSE);
+
+ dialog=gtk_dialog_new();
+ gtk_signal_connect(GTK_OBJECT(dialog),"delete_event",
+ GTK_SIGNAL_FUNC(connect_deleted_callback), NULL);
+
+ gtk_window_set_title(GTK_WINDOW(dialog), _(" Connect to Freeciv Server"));
+
+ gtk_window_set_geometry_hints(GTK_WINDOW(dialog), 0, &gdkGeometry,
GDK_HINT_MIN_SIZE);
+
+ book = gtk_notebook_new ();
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), book, TRUE, TRUE, 0);
+
+
+
/*===========================================================================*/
+ vbox3=gui_advanced(); /* initializes ihost/iport */
+ vbox2=gui_options();
+ vbox=gui_name_selection(); /* uses ihost/iport */
+
+
/*===========================================================================*/
+
+ label=gtk_label_new(_("Game selection"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox, label);
+
+ label=gtk_label_new(_("Options"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox2, label);
+
+ label=gtk_label_new(_("Advanced"));
+ gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox3, label);
+
+ /*======================= Action area
=======================================*/
connw=gtk_button_new_with_label(_("Connect"));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), connw,
TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS(connw, GTK_CAN_DEFAULT);
gtk_widget_grab_default(connw);
+ rulesw=gtk_button_new_with_label(_("Show rules"));
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), rulesw,
+ TRUE, TRUE, 0);
+ GTK_WIDGET_SET_FLAGS(rulesw, GTK_CAN_DEFAULT);
+
quitw=gtk_button_new_with_label(_("Quit"));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), quitw,
TRUE, TRUE, 0);
@@ -242,14 +689,10 @@
gtk_widget_grab_focus (iname);
- gtk_signal_connect(GTK_OBJECT(iname), "activate",
- GTK_SIGNAL_FUNC(connect_callback), NULL);
- gtk_signal_connect(GTK_OBJECT(ihost), "activate",
- GTK_SIGNAL_FUNC(connect_callback), NULL);
- gtk_signal_connect(GTK_OBJECT(iport), "activate",
- GTK_SIGNAL_FUNC(connect_callback), NULL);
gtk_signal_connect(GTK_OBJECT(connw), "clicked",
GTK_SIGNAL_FUNC(connect_callback), NULL);
+ gtk_signal_connect(GTK_OBJECT(rulesw), "clicked",
+ GTK_SIGNAL_FUNC(rules_callback), NULL);
gtk_signal_connect(GTK_OBJECT(quitw), "clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
@@ -264,21 +707,58 @@
/**************************************************************************
Get the list of servers from the metaserver
**************************************************************************/
-static int get_meta_list(GtkWidget *list, char *errbuf, int n_errbuf)
+
+static int create_local_entry(GtkWidget *list)
{
+ char *row[6], buf[6][64];
int i;
- char *row[6];
- char buf[6][64];
+
+ for (i=0; i<6; i++)
+ row[i]=buf[i];
+
+ gtk_clist_freeze(GTK_CLIST(list));
+ sz_strlcpy( buf[0], AUTOSTART_SERVER);
+ sz_strlcpy( buf[1], "5555");
+ sz_strlcpy( buf[2], "");
+ sz_strlcpy( buf[3], "");
+ sz_strlcpy( buf[4], "");
+ sz_strlcpy( buf[5], _("Play against the computer"));
+ gtk_clist_append(GTK_CLIST(list), row);
+ gtk_clist_thaw(GTK_CLIST(list));
+
+ return 1; /* 1 entry created */
+}
+
+
+
+static int get_meta_list(GtkWidget *list, char *errbuf, int n_errbuf)
+{
+ int i, pos, bestpos=0, score, bestscore=0;
+ int numservers=0, numshown=0;
+ char *row[6], buf[6][64], *errmsg[6];
struct server_list *server_list = create_server_list(errbuf, n_errbuf);
if(!server_list) return -1;
gtk_clist_freeze(GTK_CLIST(list));
gtk_clist_clear(GTK_CLIST(list));
+ pos=create_local_entry(list);
+
for (i=0; i<6; i++)
- row[i]=buf[i];
+ row[i]=buf[i], errmsg[i]="";
server_list_iterate(*server_list,pserver) {
+ numservers++;
+ if (option_hide_inactive) {
+ if (!strcmp(pserver->status, "Game over"))
+ continue;
+
+ if (!strcmp(pserver->status, "Running") &&
+ (pserver->lastturn>=10 || !*pserver->joinas))
+ continue;
+ }
+ numshown++;
+
sz_strlcpy(buf[0], pserver->name);
sz_strlcpy(buf[1], pserver->port);
sz_strlcpy(buf[2], pserver->version);
@@ -287,10 +767,37 @@
sz_strlcpy(buf[5], pserver->metastring);
gtk_clist_append(GTK_CLIST(list), row);
+
+ if (pos<MAXSERVERS) {
+ joinas_list[pos]=realloc(joinas_list[pos],strlen(pserver->joinas)+1);
+ strcpy(joinas_list[pos],pserver->joinas);
+ }
+
+ /*------------determine which one to highlight--------*/
+ score=0;
+ if(!strcmp(pserver->status,"Pregame"))
+ score=100*atoi(pserver->players);
+ if(!strcmp(pserver->status,"Running") && pserver->lastturn<10 &&
*pserver->joinas)
+ score=atoi(pserver->players);
+ if (score>bestscore)
+ bestpos=pos, bestscore=score;
+ pos++;
}
server_list_iterate_end;
+ if (numshown==0) {
+ errmsg[0]="--------------";
+ if (numservers==0)
+ errmsg[5]=_("(No servers found, try updating again)");
+ else
+ errmsg[5]=_("(All servers hidden, use advanced options & update)");
+ gtk_clist_append(GTK_CLIST(list), errmsg);
+ }
+
+
+
delete_server_list(server_list);
+ gtk_clist_select_row(GTK_CLIST(list),bestpos,0);
gtk_clist_thaw(GTK_CLIST(list));
return 0;
- [Freeciv-Dev] PATCH: (fixed version) gui-gtk: metaserver dialog,
mueller <=
|
|