[Freeciv-Dev] Re: (PR#8908) endgame numbers
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8908 >
Here's an update of the changes to the endgame rep.
It's split in two patches: apply patch 1 to fix the population bug, and
then apply patch 2 to get flags in the dialog.
Andreas Røsdal
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk/repodlgs.c
freeciv-cvs-Jul-03-endgame-2/client/gui-gtk/repodlgs.c
--- freeciv-cvs-Jul-03-endgame-1/client/gui-gtk/repodlgs.c 2004-07-05
16:58:22.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-2/client/gui-gtk/repodlgs.c 2004-07-05
17:26:25.415075568 +0200
@@ -96,10 +96,13 @@
static GtkWidget *activeunits_list;
static GtkWidget *upgrade_command;
+static SPRITE *flags[MAX_NUM_PLAYERS];
+
static int activeunits_dialog_shell_is_modal;
/******************************************************************/
static void create_endgame_report(struct packet_endgame_report *packet);
+static void build_flag(int playerindex);
static void endgame_destroy_callback(GtkObject *object, gpointer data);
static GtkWidget *endgame_report_shell;
@@ -107,7 +110,9 @@
static GtkWidget *close_endgame_command;
static GtkWidget *sw;
-#define NUM_SCORE_COLS 14
+#define NUM_SCORE_COLS 15
+#define MIN_DIMENSION 5
+
/******************************************************************/
/******************************************************************
@@ -1129,6 +1134,7 @@
static const char *titles_[NUM_SCORE_COLS] = {
N_("Player\n"),
+ N_("Flag\n"),
N_("Score\n"),
N_("Population\n"),
N_("Trade\n(M goods)"),
@@ -1186,40 +1192,86 @@
gtk_widget_show_all(GTK_DIALOG(endgame_report_shell)->vbox);
gtk_widget_show_all(GTK_DIALOG(endgame_report_shell)->action_area);
+ gtk_set_relative_position(toplevel, endgame_report_shell, 10, 10);
+ gtk_widget_show(endgame_report_shell);
+
/* Insert score statistics into table. */
gtk_clist_freeze(GTK_CLIST(scores_list));
gtk_clist_clear(GTK_CLIST(scores_list));
for (i = 0; i < packet->nscores; i++) {
my_snprintf(stat[0], sizeof(stat[0]), "%s",
get_player(packet->id[i])->name);
- my_snprintf(stat[1], sizeof(stat[1]), "%d", packet->score[i]);
- my_snprintf(stat[2], sizeof(stat[2]), "%s",
+ my_snprintf(stat[2], sizeof(stat[2]), "%d", packet->score[i]);
+ my_snprintf(stat[3], sizeof(stat[3]), "%s",
population_to_text(packet->pop[i]));
- my_snprintf(stat[3], sizeof(stat[3]), "%d", packet->bnp[i]);
- my_snprintf(stat[4], sizeof(stat[4]), "%d", packet->mfg[i]);
- my_snprintf(stat[5], sizeof(stat[5]), "%d", packet->cities[i]);
- my_snprintf(stat[6], sizeof(stat[6]), "%d", packet->techs[i]);
- my_snprintf(stat[7], sizeof(stat[7]), "%d", packet->mil_service[i]);
- my_snprintf(stat[8], sizeof(stat[8]), "%d", packet->wonders[i]);
- my_snprintf(stat[9], sizeof(stat[9]), "%d", packet->research[i]);
- my_snprintf(stat[10], sizeof(stat[10]), "%d", packet->landarea[i]);
- my_snprintf(stat[11], sizeof(stat[11]), "%d", packet->settledarea[i]);
- my_snprintf(stat[12], sizeof(stat[12]), "%d", packet->literacy[i]);
- my_snprintf(stat[13], sizeof(stat[13]), "%d", packet->spaceship[i]);
+ my_snprintf(stat[4], sizeof(stat[4]), "%d", packet->bnp[i]);
+ my_snprintf(stat[5], sizeof(stat[5]), "%d", packet->mfg[i]);
+ my_snprintf(stat[6], sizeof(stat[6]), "%d", packet->cities[i]);
+ my_snprintf(stat[7], sizeof(stat[7]), "%d", packet->techs[i]);
+ my_snprintf(stat[8], sizeof(stat[8]), "%d", packet->mil_service[i]);
+ my_snprintf(stat[9], sizeof(stat[9]), "%d", packet->wonders[i]);
+ my_snprintf(stat[10], sizeof(stat[10]), "%d", packet->research[i]);
+ my_snprintf(stat[11], sizeof(stat[11]), "%d", packet->landarea[i]);
+ my_snprintf(stat[12], sizeof(stat[12]), "%d", packet->settledarea[i]);
+ my_snprintf(stat[13], sizeof(stat[13]), "%d", packet->literacy[i]);
+ my_snprintf(stat[14], sizeof(stat[14]), "%d", packet->spaceship[i]);
gtk_clist_append(GTK_CLIST(scores_list), row);
+
+ build_flag(packet->id[i]);
+ if (flags[packet->id[i]]) {
+ gtk_clist_set_pixmap(GTK_CLIST(scores_list), i, 1,
+ flags[packet->id[i]]->pixmap,
+ flags[packet->id[i]]->mask);
+ }
+ if (packet->id[i] == game.player_idx) {
+ gtk_clist_select_row(GTK_CLIST(scores_list), i, 0);
+ }
}
gtk_clist_thaw(GTK_CLIST(scores_list));
}
/**************************************************************************
+ Builds the flag pixmap.
+**************************************************************************/
+static void build_flag(int playerindex)
+{
+ int start_x, start_y, end_x, end_y, flag_h, flag_w, newflag_h, newflag_w;
+ SPRITE *flag, *croped, *scaled;
+
+ flag = get_nation_by_plr(&game.players[playerindex])->flag_sprite;
+ if (!flag) {
+ flags[playerindex] = NULL;
+ return;
+ }
+ /* calculate the bounding box ... */
+ sprite_get_bounding_box(flag, &start_x, &start_y, &end_x, &end_y);
+ assert(start_x != -1);
+ assert(start_y != -1);
+ assert(end_x != -1);
+ assert(end_y != -1);
+ flag_w = (end_x - start_x) + 1;
+ flag_h = (end_y - start_y) + 1;
+ /* if the flag is smaller then 5 x 5, something is wrong */
+ assert(flag_w >= MIN_DIMENSION && flag_h >= MIN_DIMENSION);
+ /* croping */
+ croped = crop_sprite(flag, start_x, start_y, flag_w, flag_h, NULL, -1, -1);
+ /* scaling */
+ newflag_h = GTK_CLIST(scores_list)->row_height;
+ newflag_w = ((double) newflag_h / flag_h) * flag_w;
+ scaled = sprite_scale(croped, newflag_w, newflag_h);
+ free_sprite(croped);
+ sprite_draw_black_border(scaled);
+ /* and finaly store the scaled flagsprite in the static flags array */
+ flags[playerindex] = scaled;
+}
+
+/**************************************************************************
Show a dialog with player statistics at endgame.
**************************************************************************/
void popup_endgame_report_dialog(struct packet_endgame_report *packet)
{
if (!endgame_report_shell) {
create_endgame_report(packet);
- gtk_set_relative_position(toplevel, endgame_report_shell, 10, 10);
- gtk_widget_show(endgame_report_shell);
}
}
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/plrdlg.c
freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/plrdlg.c
--- freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/plrdlg.c 2004-05-02
07:12:07.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/plrdlg.c 2004-07-05
17:08:20.990933096 +0200
@@ -433,7 +433,7 @@
/**************************************************************************
Builds the flag pixmap.
**************************************************************************/
-static GdkPixbuf *get_flag(struct nation_type *nation)
+GdkPixbuf *get_flag(struct nation_type *nation)
{
int x0, y0, x1, y1, w, h;
GdkPixbuf *im;
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/plrdlg.h
freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/plrdlg.h
--- freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/plrdlg.h 2002-12-15
01:38:23.000000000 +0100
+++ freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/plrdlg.h 2004-07-05
17:08:21.034926408 +0200
@@ -16,5 +16,6 @@
#include "plrdlg_g.h"
void popdown_players_dialog(void);
+GdkPixbuf *get_flag(struct nation_type *nation);
#endif /* FC__PLRDLG_H */
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/repodlgs.c
freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/repodlgs.c
--- freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/repodlgs.c 2004-07-05
16:57:46.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-2/client/gui-gtk-2.0/repodlgs.c 2004-07-05
17:14:30.235799344 +0200
@@ -44,6 +44,7 @@
#include "mapview_common.h"
#include "options.h"
#include "packhand_gen.h"
+#include "plrdlg.h"
#include "control.h"
#include "text.h"
@@ -114,7 +115,7 @@
static GtkWidget *scores_list;
static GtkWidget *sw;
-#define NUM_SCORE_COLS 14
+#define NUM_SCORE_COLS 15
/******************************************************************/
/******************************************************************
@@ -1307,9 +1308,12 @@
int i;
static bool titles_done;
GtkTreeIter it;
+ GtkTreeSelection *selection;
+ GdkPixbuf *flag;
static const char *titles[NUM_SCORE_COLS] = {
N_("Player\n"),
+ N_("Flag\n"),
N_("Score\n"),
N_("Population\n"),
N_("Trade\n(M goods)"),
@@ -1325,8 +1329,9 @@
N_("Spaceship\n")
};
- static GType model_types[NUM_SCORE_COLS] = {
+ GType model_types[NUM_SCORE_COLS] = {
G_TYPE_STRING,
+ GDK_TYPE_PIXBUF,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_INT,
@@ -1358,18 +1363,28 @@
setup_dialog(endgame_report_shell, toplevel);
scores_store = gtk_list_store_newv(ARRAY_SIZE(model_types), model_types);
scores_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(scores_store));
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(scores_list));
g_object_unref(scores_store);
for (i = 0; i < NUM_SCORE_COLS; i++) {
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *col;
+ if (model_types[i] == GDK_TYPE_PIXBUF) {
+ GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new();
+ GtkTreeViewColumn *col =
+ gtk_tree_view_column_new_with_attributes(titles[i],
+ renderer, "pixbuf",
+ i, NULL);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(scores_list), col);
+ } else {
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *col;
- renderer = gtk_cell_renderer_text_new();
- g_object_set(renderer, "weight", "bold", NULL);
- col = gtk_tree_view_column_new_with_attributes(titles[i], renderer,
+ renderer = gtk_cell_renderer_text_new();
+ g_object_set(renderer, "weight", "bold", NULL);
+ col = gtk_tree_view_column_new_with_attributes(titles[i], renderer,
"text", i, NULL);
- gtk_tree_view_column_set_sort_column_id(col, i);
- gtk_tree_view_append_column(GTK_TREE_VIEW(scores_list), col);
+ gtk_tree_view_column_set_sort_column_id(col, i);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(scores_list), col);
+ }
}
/* Setup the layout. */
@@ -1388,23 +1403,29 @@
/* Insert score statistics into table. */
gtk_list_store_clear(scores_store);
for (i = 0; i < packet->nscores; i++) {
+ flag = get_flag(get_nation_by_plr(get_player(packet->id[i])));
gtk_list_store_append(scores_store, &it);
gtk_list_store_set(scores_store, &it,
0, (gchar *)get_player(packet->id[i])->name,
- 1, packet->score[i],
- 2, population_to_text(packet->pop[i]),
- 3, packet->bnp[i],
- 4, packet->mfg[i],
- 5, packet->cities[i],
- 6, packet->techs[i],
- 7, packet->mil_service[i],
- 8, packet->wonders[i],
- 9, packet->research[i],
- 10, packet->landarea[i],
- 11, packet->settledarea[i],
- 12, packet->literacy[i],
- 13, packet->spaceship[i],
+ 1, flag,
+ 2, packet->score[i],
+ 3, population_to_text(packet->pop[i]),
+ 4, packet->bnp[i],
+ 5, packet->mfg[i],
+ 6, packet->cities[i],
+ 7, packet->techs[i],
+ 8, packet->mil_service[i],
+ 9, packet->wonders[i],
+ 10, packet->research[i],
+ 11, packet->landarea[i],
+ 12, packet->settledarea[i],
+ 13, packet->literacy[i],
+ 14, packet->spaceship[i],
-1);
+ if (packet->id[i] == game.player_idx) {
+ gtk_tree_selection_select_iter(selection, &it);
+ }
+ g_object_unref(flag);
}
}
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03/client/gui-gtk/repodlgs.c
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk/repodlgs.c
--- freeciv-cvs-Jul-03/client/gui-gtk/repodlgs.c 2004-04-24
07:11:18.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-1/client/gui-gtk/repodlgs.c 2004-07-05
16:58:22.409931240 +0200
@@ -1190,9 +1190,11 @@
gtk_clist_freeze(GTK_CLIST(scores_list));
gtk_clist_clear(GTK_CLIST(scores_list));
for (i = 0; i < packet->nscores; i++) {
- my_snprintf(stat[0], sizeof(stat[0]), "%s",
get_player(packet->id[i])->name);
+ my_snprintf(stat[0], sizeof(stat[0]), "%s",
+ get_player(packet->id[i])->name);
my_snprintf(stat[1], sizeof(stat[1]), "%d", packet->score[i]);
- my_snprintf(stat[2], sizeof(stat[2]), "%d", packet->pop[i]);
+ my_snprintf(stat[2], sizeof(stat[2]), "%s",
+ population_to_text(packet->pop[i]));
my_snprintf(stat[3], sizeof(stat[3]), "%d", packet->bnp[i]);
my_snprintf(stat[4], sizeof(stat[4]), "%d", packet->mfg[i]);
my_snprintf(stat[5], sizeof(stat[5]), "%d", packet->cities[i]);
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore
freeciv-cvs-Jul-03/client/gui-gtk-2.0/repodlgs.c
freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/repodlgs.c
--- freeciv-cvs-Jul-03/client/gui-gtk-2.0/repodlgs.c 2004-05-12
07:12:28.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-1/client/gui-gtk-2.0/repodlgs.c 2004-07-05
16:57:46.498390624 +0200
@@ -1328,7 +1328,7 @@
static GType model_types[NUM_SCORE_COLS] = {
G_TYPE_STRING,
G_TYPE_INT,
- G_TYPE_INT,
+ G_TYPE_STRING,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
@@ -1392,7 +1392,7 @@
gtk_list_store_set(scores_store, &it,
0, (gchar *)get_player(packet->id[i])->name,
1, packet->score[i],
- 2, packet->pop[i],
+ 2, population_to_text(packet->pop[i]),
3, packet->bnp[i],
4, packet->mfg[i],
5, packet->cities[i],
diff -ruN -Xfreeciv-cvs-Jul-03/diff_ignore freeciv-cvs-Jul-03/server/report.c
freeciv-cvs-Jul-03-endgame-1/server/report.c
--- freeciv-cvs-Jul-03/server/report.c 2004-06-23 07:13:26.000000000 +0200
+++ freeciv-cvs-Jul-03-endgame-1/server/report.c 2004-07-05
16:42:31.042561064 +0200
@@ -1133,7 +1133,7 @@
for (i = 0; i < j; i++) {
packet.id[i] = size[i].player->player_no;
packet.score[i] = size[i].value;
- packet.pop[i] = get_pop(size[i].player) * 1000;
+ packet.pop[i] = get_population(size[i].player);
packet.bnp[i] = get_economics(size[i].player);
packet.mfg[i] = get_production(size[i].player);
packet.cities[i] = get_cities(size[i].player);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#8908) endgame numbers,
andrearo@xxxxxxxxxxxx <=
|
|