[Freeciv-Dev] Re: (PR#7123) Metaissue for FS
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7123 >
On Thu, Jan 01, 2004 at 12:26:53PM -0800, Raimar Falke wrote:
> > I think I found a nice model here which I will implement new year.
> >
> > You have a background image. You have a set of elements. Each element
> > has a set of measures (x,y,width,height). Each element has depending
> > on the type other attributes partly optional and partly not. There are
> > general attributes like "tooltip", "halign", "valign".
> >
> > Extra attributes are:
> > - label (static text): "text" and general text attributes
> > - info (dynamic text): "id" and general text attributes
> > - button: "id", "background", "text" and and general text attributes
> > - ...
> >
> > The "id" attribute is used to connect the graphical element to the
> > program code. So an info element for the main screen with the id
> > "population" will show the total population of your empire. And a
> > button in the connect screen with the id "connect" will call the
> > connect function in the freeciv code.
I have completed the theme engine for texts, infos, edits and
buttons. I have changed connnectdlg.c (and made it fully functional
again) and created a "connect.screen" file. The result is visiable at
http://freeciv.org/~rfalke/fs3_pics/screen-0002.png.
This theme engine really reduce seperates the data from the code and
so reduces the amount of code drastically. While gui-fs doesn't
implement the metaserver list and the authentication the numbers are
promising:
200 594 5585 client/gui-fs/connectdlg.c
718 1818 23703 client/gui-gtk-2.0/connectdlg.c
683 1747 22869 client/gui-gtk/connectdlg.c
324 821 10174 client/gui-mui/connectdlg.c
1150 2958 33856 client/gui-sdl/connectdlg.c
159 510 4964 client/gui-stub/connectdlg.c
1231 2074 36212 client/gui-win32/connectdlg.c
583 1487 18508 client/gui-xaw/connectdlg.c
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Like the ad says, at 300 dpi you can tell she's wearing a
swimsuit. At 600 dpi you can tell it's wet. At 1200 dpi you
can tell it's painted on. I suppose at 2400 dpi you can tell
if the paint is giving her a rash."
-- Joshua R. Poulson
/**********************************************************************
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include <stdio.h> /* sscanf */
#include "fcintl.h"
#include "log.h"
#include "support.h"
#include "chatline_common.h" /* for append_output_window */
#include "civclient.h"
#include "clinet.h" /* for get_server_address */
#include "gui_main.h"
#include "connectdlg.h"
#include "widget.h"
#include "theme_engine.h"
static struct te_screen *screen;
static void try_to_autoconnect(void *data);
static void connect_callback(void)
{
char errbuf[512];
sz_strlcpy(user_name, te_edit_get_current_value(screen, "username"));
sz_strlcpy(server_host, te_edit_get_current_value(screen, "server"));
sscanf(te_edit_get_current_value(screen, "port"), "%d", &server_port);
if (connect_to_server(user_name, server_host, server_port,
errbuf, sizeof(errbuf)) != -1) {
te_destroy_screen(screen);
screen = NULL;
} else {
append_output_window(errbuf);
}
}
static void button_callback(const char *id)
{
if (strcmp(id, "connect") == 0) {
connect_callback();
} else {
assert(0);
}
}
static char *edit_get_initial_value(const char *id)
{
if (strcmp(id, "port") == 0) {
static char buf[10];
my_snprintf(buf, sizeof(buf), "%d", server_port);
return buf;
} else if (strcmp(id, "username") == 0) {
return user_name;
} else if (strcmp(id, "password") == 0) {
return "";
} else if (strcmp(id, "server") == 0) {
return server_host;
} else {
assert(0);
return NULL;
}
}
static int edit_get_width(const char *id)
{
if (strcmp(id, "port") == 0) {
return 5;
} else if (strcmp(id, "username") == 0) {
return 10;
} else if (strcmp(id, "password") == 0) {
return 10;
} else if (strcmp(id, "server") == 0) {
return 10;
} else {
assert(0);
return 0;
}
}
static char *info_get_value(const char *id)
{
if (0) {
} else {
assert(0);
return NULL;
}
}
static void popup_connect_window(void)
{
struct te_screen_env env;
env.info_get_value=info_get_value;
env.edit_get_initial_value=edit_get_initial_value;
env.edit_get_width=edit_get_width;
env.button_callback=button_callback;
screen = te_get_screen(root_window, "connect", &env);
}
/**************************************************************************
Provide an interface for connecting to a FreeCiv server.
**************************************************************************/
void gui_server_connect(void)
{
popup_connect_window();
}
/**************************************************************************
Start trying to autoconnect to civserver.
Calls get_server_address(), then arranges for
autoconnect_callback(), which calls try_to_connect(), to be called
roughly every AUTOCONNECT_INTERVAL milliseconds, until success,
fatal error or user intervention.
**************************************************************************/
void server_autoconnect(void)
{
char buf[512];
int outcome;
my_snprintf(buf, sizeof(buf),
_("Auto-connecting to server \"%s\" at port %d as \"%s\""),
server_host, server_port, user_name);
append_output_window(buf);
outcome = get_server_address(server_host, server_port, buf, sizeof(buf));
if (outcome < 0) {
freelog(LOG_FATAL,
_("Error contacting server \"%s\" at port %d "
"as \"%s\":\n %s\n"),
server_host, server_port, user_name, buf);
exit(EXIT_FAILURE);
}
try_to_autoconnect(NULL);
}
/**************************************************************************
Make an attempt to autoconnect to the server. If the server isn't
there yet, arrange for this routine to be called again in about
AUTOCONNECT_INTERVAL milliseconds. If anything else goes wrong, log
a fatal error.
Return FALSE iff autoconnect succeeds.
**************************************************************************/
static void try_to_autoconnect(void *data)
{
char errbuf[512];
static int count = 0;
count++;
/* abort if after 10 seconds the server couldn't be reached */
if (AUTOCONNECT_INTERVAL * count >= 10000) {
freelog(LOG_FATAL,
_("Failed to contact server \"%s\" at port "
"%d as \"%s\" after %d attempts"),
server_host, server_port, user_name, count);
exit(EXIT_FAILURE);
}
switch (try_to_connect(user_name, errbuf, sizeof(errbuf))) {
case 0:
/* Success! */
return;
case ECONNREFUSED:
/* Server not available (yet) - wait & retry */
sw_add_timeout(AUTOCONNECT_INTERVAL, try_to_autoconnect, NULL);
return;
default:
/* All other errors are fatal */
freelog(LOG_FATAL,
_("Error contacting server \"%s\" at port %d "
"as \"%s\":\n %s\n"),
server_host, server_port, user_name, errbuf);
exit(EXIT_FAILURE);
}
}
void close_connection_dialog(void){}
void handle_authentication_req(enum authentication_type type, char *message){}
[screen]
background="telescope.png"
#background="romeinse-eetzaal-b.png"
[label_username]
x = 400
y = 100
width = 65
height = 40
align="ec"
text=_("User Name")
text-color="#ff0000"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[label_password]
x = 400
y = 140
width = 65
height = 40
align="ec"
text=_("Password")
text-color="#ff0000"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[label_server]
x = 400
y = 180
width = 65
height = 40
align="ec"
text=_("Server")
text-color="#ff0000"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[label_port]
x = 400
y = 220
width = 65
height = 40
align="ec"
text=_("Port")
text-color="#ff0000"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[edit_username]
x = 470
y = 100
width = 130
height = 40
align="wc"
text-color="#0000ff"
text-background="#00ff00"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[edit_password]
x = 470
y = 140
width = 130
height = 40
align="wc"
text-color="#0000ff"
text-background="#00ff00"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[edit_server]
x = 470
y = 180
width = 130
height = 40
align="wc"
text-color="#0000ff"
text-background="#00ff00"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[edit_port]
x = 470
y = 220
width = 130
height = 40
align="wc"
text-color="#0000ff"
text-background="#00ff00"
text-size=11
text-font="verdana.ttf"
text-antialias=0
[button_connect]
x = 400
y = 300
width = 200
height = 35
align="center"
background="connect-button.png"
text=_("Connect")
text-color="#0000ff"
text-size=45
text-font="verdana.ttf"
text-antialias=0
tooltip=_("Press to connect")
tooltip-color="#000000"
tooltip-background="#f4ed8b"
tooltip-size=12
tooltip-font="verdana.ttf"
tooltip-antialias=0
tooltip-delay=1100
- [Freeciv-Dev] Re: (PR#7123) Metaissue for FS, Raimar Falke, 2004/01/01
- [Freeciv-Dev] Re: (PR#7123) Metaissue for FS,
Raimar Falke <=
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Raimar Falke, 2004/01/02
- [Freeciv-Dev] Re: (PR#7123) Metaissue for FS, Vasco Alexandre da Silva Costa, 2004/01/02
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Vasco Alexandre da Silva Costa, 2004/01/02
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Raimar Falke, 2004/01/02
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Raimar Falke, 2004/01/02
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Raimar Falke, 2004/01/02
- [Freeciv-Dev] Re: Betr: Re: (PR#7123) Metaissue for FS, Vasco Alexandre da Silva Costa, 2004/01/02
|
|