[Freeciv-Dev] Re: [PATCH] Happiness display (GTK client) (PR#655)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hi All!
Content-Type: text/plain; charset=us-ascii
Content-Type: multipart/mixed;
boundary="------------07B59762E35525FF8C9D0278"
This is a multi-part message in MIME format.
--------------07B59762E35525FF8C9D0278
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi All!
I kwon that a new city dialog is deeply under work, and it will have
happiness display in it, nontheless for the moment, the actual city
dialog is correct and running, so I've some work to make a patch
submitted by Mike Jing, work in the actual version of CVS.
This 2 diff files add happiness display as a button of city report.
Try it! Is really interesting to see how happiness information are
built, step by step.
If something is wrong or has to be done better, don't hesitate to post
me.
Ciao, Davide
--------------07B59762E35525FF8C9D0278
Content-Type: text/plain; charset=us-ascii;
name="happiness-display-gtk.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="happiness-display-gtk.diff"
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/gui-gtk/citydlg.c
freeciv/client/gui-gtk/citydlg.c
--- freeciv.orig/client/gui-gtk/citydlg.c Sat Sep 1 14:25:08 2001
+++ freeciv/client/gui-gtk/citydlg.c Sat Sep 1 14:28:04 2001
@@ -27,6 +27,7 @@
#include "fcintl.h"
#include "game.h"
#include "genlist.h"
+#include "government.h"
#include "map.h"
#include "mem.h"
#include "packets.h"
@@ -95,6 +96,7 @@
GtkWidget *present_unit_button [2];
GtkWidget *close_command;
GtkWidget *rename_command;
+ GtkWidget *happiness_command;
GtkWidget *trade_command;
GtkWidget *activate_command;
GtkWidget *show_units_command;
@@ -161,6 +163,7 @@
static void worklist_callback (GtkWidget *w, gpointer data);
static void close_callback (GtkWidget *w, gpointer data);
static void rename_callback (GtkWidget *w, gpointer data);
+static void happiness_callback (GtkWidget *w, gpointer data);
static void trade_callback (GtkWidget *w, gpointer data);
static void activate_callback (GtkWidget *w, gpointer data);
static void show_units_callback (GtkWidget *w, gpointer data);
@@ -209,6 +212,40 @@
static gint sell_callback_delete(GtkWidget *widget, GdkEvent *event, gpointer
data);
static gint rename_callback_delete(GtkWidget *widget, GdkEvent *event,
gpointer data);
+/* happiness display */
+#define HAPPINESS_PIX_WIDTH 30
+
+static struct genlist happiness_list;
+static int happiness_list_has_been_initialised;
+
+struct happiness_dialog {
+ struct city *pcity;
+ GtkWidget *shell;
+ GtkWidget *cityname_label;
+ GtkWidget *happiness_pixmaps[5];
+ GtkWidget *cities_label;
+ GtkWidget *luxury_label;
+ GtkWidget *buildings_label;
+ GtkWidget *units_label;
+ GtkWidget *wonders_label;
+ GtkWidget *close;
+};
+
+static GdkPixmap *create_happiness_pixmap(struct city *pcity, int index);
+static struct happiness_dialog *get_happiness_dialog(struct city *pcity);
+static struct happiness_dialog *create_happiness_dialog(struct city *pcity);
+static void happiness_close_callback(GtkWidget *w, gpointer data);
+static void popup_happiness_dialog(struct city *pcity);
+static void refresh_happiness_dialog(struct city *pcity);
+static void close_happiness_dialog(struct happiness_dialog *pdialog);
+static void happiness_dialog_update_cities(struct happiness_dialog *pdialog);
+static void happiness_dialog_update_luxury(struct happiness_dialog *pdialog);
+static void happiness_dialog_update_buildings(struct happiness_dialog
*pdialog);
+static void happiness_dialog_update_units(struct happiness_dialog *pdialog);
+static void happiness_dialog_update_wonders(struct happiness_dialog *pdialog);
+static gint happiness_dialog_delete_callback(GtkWidget *w, GdkEvent *ev,
gpointer data);
+
+
/****************************************************************
...
*****************************************************************/
@@ -280,7 +317,8 @@
void refresh_city_dialog(struct city *pcity)
{
struct city_dialog *pdialog;
-
+ struct happiness_dialog *phdialog;
+
if((pdialog=get_city_dialog(pcity))) {
city_dialog_update_improvement_list(pdialog);
city_dialog_update_title(pdialog);
@@ -304,6 +342,10 @@
?TRUE:FALSE);
gtk_widget_set_sensitive(pdialog->cityopt_command, TRUE);
}
+ /* hitch a ride here for the happiness display */
+ if((phdialog=get_happiness_dialog(pcity))) {
+ refresh_happiness_dialog(pcity);
+ }
if(pcity->owner == game.player_idx) {
city_report_dialog_update_city(pcity);
economy_report_dialog_update();
@@ -741,6 +783,11 @@
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pdialog->shell)->action_area),
pdialog->rename_command, TRUE, TRUE, 0);
+ pdialog->happiness_command=gtk_accelbutton_new(_("_Happiness"), accel);
+ GTK_WIDGET_SET_FLAGS(pdialog->happiness_command, GTK_CAN_DEFAULT);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pdialog->shell)->action_area),
+ pdialog->happiness_command, TRUE, TRUE, 0);
+
pdialog->trade_command=gtk_accelbutton_new(_("_Trade"), accel);
GTK_WIDGET_SET_FLAGS(pdialog->trade_command, GTK_CAN_DEFAULT);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pdialog->shell)->action_area),
@@ -779,6 +826,9 @@
gtk_signal_connect(GTK_OBJECT(pdialog->rename_command), "clicked",
GTK_SIGNAL_FUNC(rename_callback), pdialog);
+ gtk_signal_connect(GTK_OBJECT(pdialog->happiness_command), "clicked",
+ GTK_SIGNAL_FUNC(happiness_callback), pdialog);
+
gtk_signal_connect(GTK_OBJECT(pdialog->trade_command), "clicked",
GTK_SIGNAL_FUNC(trade_callback), pdialog);
@@ -2792,4 +2842,428 @@
gtk_widget_destroy(cityopt_shell);
cityopt_shell = 0;
}
+}
+
+/**************************************************************************
+ Happiness display
+
+I ended up copying off the city dialog code. And it's modeless! --Jing
+**************************************************************************/
+static void happiness_callback(GtkWidget *w, gpointer data)
+{
+ struct city_dialog *pdialog = (struct city_dialog *)data;
+
+ popup_happiness_dialog(pdialog->pcity);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void popup_happiness_dialog(struct city *pcity)
+{
+ struct happiness_dialog *pdialog;
+
+ if(!(pdialog=get_happiness_dialog(pcity)))
+ pdialog = create_happiness_dialog(pcity);
+
+ gtk_widget_show(pdialog->shell);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static struct happiness_dialog *get_happiness_dialog(struct city *pcity)
+{
+ struct genlist_iterator myiter;
+
+ if(!happiness_list_has_been_initialised) {
+ genlist_init(&happiness_list);
+ happiness_list_has_been_initialised=1;
+ }
+
+ genlist_iterator_init(&myiter, &happiness_list, 0);
+
+ for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter))
+ if(((struct happiness_dialog *)ITERATOR_PTR(myiter))->pcity==pcity)
+ return ITERATOR_PTR(myiter);
+
+ return 0;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static struct happiness_dialog *create_happiness_dialog(struct city *pcity)
+{
+ int i;
+ struct happiness_dialog *pdialog;
+ GtkWidget *table, *labels[5];
+ GtkAccelGroup *accel=gtk_accel_group_new();
+
+ pdialog = fc_malloc(sizeof(struct happiness_dialog));
+ pdialog->pcity = pcity;
+
+ pdialog->shell = gtk_dialog_new ();
+ gtk_signal_connect(GTK_OBJECT(pdialog->shell),"delete_event",
+ GTK_SIGNAL_FUNC(happiness_dialog_delete_callback),
+ (gpointer)pdialog);
+ gtk_window_set_title (GTK_WINDOW (pdialog->shell), _("Happiness"));
+ gtk_window_set_position(GTK_WINDOW(pdialog->shell), GTK_WIN_POS_MOUSE);
+ gtk_accel_group_attach(accel, GTK_OBJECT(pdialog->shell));
+ gtk_widget_realize(pdialog->shell);
+
+ pdialog->cityname_label = gtk_frame_new (pcity->name);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pdialog->shell)->vbox),
+ pdialog->cityname_label, TRUE, TRUE, 0);
+ gtk_widget_realize(pdialog->cityname_label);
+
+ gtk_container_border_width(GTK_CONTAINER(pdialog->cityname_label), 5);
+
+ table = gtk_table_new(10, 2, FALSE);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+ gtk_container_add(GTK_CONTAINER(pdialog->cityname_label), table);
+ gtk_container_border_width(GTK_CONTAINER(table), 5);
+ gtk_widget_realize(table);
+
+ labels[0] = gtk_label_new(_("Cities:"));
+ labels[1] = gtk_label_new(_("Luxury:"));
+ labels[2] = gtk_label_new(_("Buildings:"));
+ labels[3] = gtk_label_new(_("Units:"));
+ labels[4] = gtk_label_new(_("Wonders:"));
+
+ for (i=0 ; i<5 ; i++) {
+ pdialog->happiness_pixmaps[i] =
gtk_pixmap_new(create_happiness_pixmap(pcity, i),
+ NULL);
+ gtk_misc_set_alignment (GTK_MISC (pdialog->happiness_pixmaps[i]), 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->happiness_pixmaps[i],
+ 1, 2, 2*i, 2*i+1);
+ gtk_misc_set_alignment (GTK_MISC (labels[i]), 1, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), labels[i],
+ 0, 1, 2*i+1, 2*i+2);
+ }
+
+ pdialog->cities_label = gtk_label_new("");
+ pdialog->luxury_label = gtk_label_new("");
+ pdialog->buildings_label = gtk_label_new("");
+ pdialog->units_label = gtk_label_new("");
+ pdialog->wonders_label = gtk_label_new("");
+ gtk_misc_set_alignment (GTK_MISC (pdialog->cities_label), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (pdialog->luxury_label), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (pdialog->buildings_label), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (pdialog->units_label), 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (pdialog->wonders_label), 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->cities_label,
+ 1, 2, 1, 2);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->luxury_label,
+ 1, 2, 3, 4);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->buildings_label,
+ 1, 2, 5, 6);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->units_label,
+ 1, 2, 7, 8);
+ gtk_table_attach_defaults(GTK_TABLE(table), pdialog->wonders_label,
+ 1, 2, 9, 10);
+
+ pdialog->close = gtk_accelbutton_new (_("Close"), accel);
+ GTK_WIDGET_SET_FLAGS(pdialog->close, GTK_CAN_DEFAULT);
+ gtk_widget_add_accelerator(pdialog->close, "clicked", accel, GDK_Return, 0,
0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG(pdialog->shell)->action_area),
+ pdialog->close, TRUE, TRUE, 0);
+ gtk_signal_connect(GTK_OBJECT(pdialog->close), "clicked",
+ GTK_SIGNAL_FUNC(happiness_close_callback), pdialog);
+
+ gtk_widget_show_all(GTK_DIALOG(pdialog->shell)->vbox);
+ gtk_widget_show_all(GTK_DIALOG(pdialog->shell)->action_area);
+
+ genlist_insert(&happiness_list, pdialog, 0);
+
+ refresh_happiness_dialog(pcity);
+
+ return pdialog;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static GdkPixmap *create_happiness_pixmap(struct city *pcity, int index)
+{
+ int i;
+ int citizen_type;
+ int n1 = pcity->ppl_happy[index];
+ int n2 = n1 + pcity->ppl_content[index];
+ int n3 = n2 + pcity->ppl_unhappy[index];
+ int n4 = n3 + pcity->ppl_elvis;
+ int n5 = n4 + pcity->ppl_scientist;
+ int num_citizens = pcity->size;
+ int pix_width = HAPPINESS_PIX_WIDTH*SMALL_TILE_WIDTH;
+ int offset = MIN(SMALL_TILE_WIDTH, pix_width/num_citizens);
+ int true_pix_width = (num_citizens-1)*offset + SMALL_TILE_WIDTH;
+
+ GdkPixmap *happiness_pixmap = gdk_pixmap_new(root_window, true_pix_width,
+ SMALL_TILE_HEIGHT, -1);
+
+ for (i=0 ; i<num_citizens; i++) {
+ if (i<n1)
+ citizen_type = 5+i%2;
+ else if (i<n2)
+ citizen_type = 3+i%2;
+ else if (i<n3)
+ citizen_type = 7+1%2;
+ else if (i<n4)
+ citizen_type = 0;
+ else if (i<n5)
+ citizen_type = 1;
+ else
+ citizen_type = 2;
+
+ gdk_draw_pixmap(happiness_pixmap, civ_gc,
+ sprites.citizen[citizen_type]->pixmap,
+ 0, 0, i*offset, 0, SMALL_TILE_WIDTH, SMALL_TILE_HEIGHT);
+
+ }
+
+ return happiness_pixmap;
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_close_callback(GtkWidget *w, gpointer data)
+{
+ close_happiness_dialog((struct happiness_dialog *)data);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void refresh_happiness_dialog(struct city *pcity)
+{
+ int i;
+
+ struct happiness_dialog *pdialog = get_happiness_dialog(pcity);
+
+ for (i=0 ; i<5 ; i++) {
+ gtk_pixmap_set(GTK_PIXMAP(pdialog->happiness_pixmaps[i]),
+ create_happiness_pixmap(pdialog->pcity, i),
+ NULL);
+ }
+
+ happiness_dialog_update_cities(pdialog);
+ happiness_dialog_update_luxury(pdialog);
+ happiness_dialog_update_buildings(pdialog);
+ happiness_dialog_update_units(pdialog);
+ happiness_dialog_update_wonders(pdialog);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void close_happiness_dialog(struct happiness_dialog *pdialog)
+{
+ gtk_widget_hide(pdialog->shell);
+ genlist_unlink(&happiness_list, pdialog);
+
+ gtk_widget_destroy(pdialog->shell);
+ free(pdialog);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_dialog_update_cities(struct happiness_dialog *pdialog)
+{
+ char buf[512], *bptr=buf;
+ int nleft = sizeof(buf);
+
+ struct city *pcity = pdialog->pcity;
+ struct player *pplayer = &game.players[pcity->owner];
+ struct government *g = get_gov_pcity(pcity);
+ int cities = city_list_size(&pplayer->cities);
+ int content = game.unhappysize;
+ int basis = game.cityfactor + g->empire_size_mod;
+ int step = g->empire_size_inc;
+ int excess = cities - basis;
+ int penalty = 0;
+
+ if (excess>0) {
+ if (step>0)
+ penalty = 1 + (excess-1)/step;
+ else
+ penalty = 1;
+ }
+ else {
+ excess = 0;
+ penalty = 0;
+ }
+
+ my_snprintf(bptr, nleft, _("%d total, %d over threshold of %d cities. "),
+ cities, excess, basis);
+ bptr = end_of_strn(bptr, &nleft);
+
+ my_snprintf(bptr, nleft, _("%d content before penalty with "), content);
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, _("%d additional unhappy citizens."), penalty);
+ bptr = end_of_strn(bptr, &nleft);
+
+ gtk_set_label(pdialog->cities_label, buf);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_dialog_update_luxury(struct happiness_dialog *pdialog)
+{
+ char buf[512], *bptr=buf;
+ int nleft = sizeof(buf);
+ struct city *pcity=pdialog->pcity;
+
+ my_snprintf(bptr, nleft, _("%d total (maximum %d usable). "),
+ pcity->luxury_total, 2*pcity->size);
+
+ gtk_set_label(pdialog->luxury_label, buf);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_dialog_update_buildings(struct happiness_dialog *pdialog)
+{
+ int faces=0;
+ char buf[512], *bptr=buf;
+ int nleft = sizeof(buf);
+ struct city *pcity=pdialog->pcity;
+ struct government *g = get_gov_pcity(pcity);
+
+ if (city_got_building(pcity, B_TEMPLE)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_TEMPLE));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_got_building(pcity, B_COURTHOUSE) &&
+ g->corruption_level == 0) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_COURTHOUSE));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_got_building(pcity, B_COLOSSEUM)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_COLOSSEUM));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_got_effect(pcity, B_CATHEDRAL)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_CATHEDRAL));
+ bptr = end_of_strn(bptr, &nleft);
+ if (!city_got_building(pcity, B_CATHEDRAL)) {
+ my_snprintf(bptr, nleft, ("("));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, get_improvement_name(B_MICHELANGELO));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (")"));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+
+ if (faces==0) {
+ my_snprintf(bptr, nleft, _("None. "));
+ }
+
+ gtk_set_label(pdialog->buildings_label, buf);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_dialog_update_units(struct happiness_dialog *pdialog)
+{
+ char buf[512], *bptr=buf;
+ int nleft = sizeof(buf);
+ struct city *pcity=pdialog->pcity;
+ struct government *g = get_gov_pcity(pcity);
+ int mlmax = g->martial_law_max;
+
+ if (mlmax > 0) {
+ my_snprintf(bptr, nleft, _("Martial law in effect ("));
+ bptr = end_of_strn(bptr, &nleft);
+
+ if (mlmax == 100 )
+ my_snprintf(bptr, nleft, _("no maximum, "));
+ else
+ my_snprintf(bptr, nleft, _("%d units maximum, "), mlmax);
+ bptr = end_of_strn(bptr, &nleft);
+
+ my_snprintf(bptr, nleft, _("%d per unit). "), g->martial_law_per);
+ }
+ else {
+ if (g->unit_happy_cost_factor)
+ my_snprintf(bptr, nleft,
+ _("Military units in the field may cause unhappiness. "));
+ else my_snprintf(bptr, nleft,_("Martial law has no effect."));
+ }
+
+ gtk_set_label(pdialog->units_label, buf);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static void happiness_dialog_update_wonders(struct happiness_dialog *pdialog)
+{
+ int faces=0;
+ char buf[512], *bptr=buf;
+ int nleft = sizeof(buf);
+ struct city *pcity=pdialog->pcity;
+
+ if (city_affected_by_wonder(pcity, B_HANGING)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_HANGING));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_SHAKESPEARE));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_affected_by_wonder(pcity, B_BACH)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_BACH));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+ if (city_affected_by_wonder(pcity, B_CURE)) {
+ faces++;
+ my_snprintf(bptr, nleft, get_improvement_name(B_CURE));
+ bptr = end_of_strn(bptr, &nleft);
+ my_snprintf(bptr, nleft, (". "));
+ bptr = end_of_strn(bptr, &nleft);
+ }
+
+ if (faces==0) {
+ my_snprintf(bptr, nleft, _("None. "));
+ }
+
+ gtk_set_label(pdialog->wonders_label, buf);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+static gint happiness_dialog_delete_callback(GtkWidget *w, GdkEvent *ev,
+ gpointer data)
+{
+ close_happiness_dialog((struct happiness_dialog *)data);
+ return FALSE;
}
--------------07B59762E35525FF8C9D0278
Content-Type: text/plain; charset=us-ascii;
name="happiness-city-report.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="happiness-city-report.diff"
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/civclient.c
freeciv/client/civclient.c
--- freeciv.orig/client/civclient.c Wed Aug 29 13:58:26 2001
+++ freeciv/client/civclient.c Sat Sep 1 14:29:37 2001
@@ -498,6 +498,7 @@
}
else if(client_state==CLIENT_PRE_GAME_STATE) {
popdown_all_city_dialogs();
+ popdown_all_happiness_dialogs();
close_all_diplomacy_dialogs();
client_remove_all_cli_conn();
game_remove_all_players();
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/climisc.c
freeciv/client/climisc.c
--- freeciv.orig/client/climisc.c Fri Aug 31 13:56:35 2001
+++ freeciv/client/climisc.c Sat Sep 1 14:29:37 2001
@@ -125,6 +125,7 @@
freelog(LOG_DEBUG, "removing city %s, %s, (%d %d)", pcity->name,
get_nation_name(city_owner(pcity)->nation), x, y);
popdown_city_dialog(pcity);
+ popdown_happiness_dialog(pcity);
game_remove_city(pcity);
city_report_dialog_update();
refresh_tile_mapcanvas(x, y, 1);
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/gui-gtk/citydlg.c
freeciv/client/gui-gtk/citydlg.c
--- freeciv.orig/client/gui-gtk/citydlg.c Sat Sep 1 14:28:54 2001
+++ freeciv/client/gui-gtk/citydlg.c Sat Sep 1 14:29:37 2001
@@ -235,7 +235,6 @@
static struct happiness_dialog *get_happiness_dialog(struct city *pcity);
static struct happiness_dialog *create_happiness_dialog(struct city *pcity);
static void happiness_close_callback(GtkWidget *w, gpointer data);
-static void popup_happiness_dialog(struct city *pcity);
static void refresh_happiness_dialog(struct city *pcity);
static void close_happiness_dialog(struct happiness_dialog *pdialog);
static void happiness_dialog_update_cities(struct happiness_dialog *pdialog);
@@ -2859,19 +2858,6 @@
/****************************************************************
...
*****************************************************************/
-static void popup_happiness_dialog(struct city *pcity)
-{
- struct happiness_dialog *pdialog;
-
- if(!(pdialog=get_happiness_dialog(pcity)))
- pdialog = create_happiness_dialog(pcity);
-
- gtk_widget_show(pdialog->shell);
-}
-
-/****************************************************************
-...
-*****************************************************************/
static struct happiness_dialog *get_happiness_dialog(struct city *pcity)
{
struct genlist_iterator myiter;
@@ -3267,3 +3253,41 @@
close_happiness_dialog((struct happiness_dialog *)data);
return FALSE;
}
+
+/****************************************************************
+popup the dialog
+*****************************************************************/
+void popup_happiness_dialog(struct city *pcity)
+{
+ struct happiness_dialog *pdialog;
+
+ if(!(pdialog=get_happiness_dialog(pcity)))
+ pdialog=create_happiness_dialog(pcity);
+
+ gtk_widget_show(pdialog->shell);
+}
+
+/****************************************************************
+popdown the dialog
+*****************************************************************/
+void popdown_happiness_dialog(struct city *pcity)
+{
+ struct happiness_dialog *pdialog;
+
+ if((pdialog=get_happiness_dialog(pcity)))
+ close_happiness_dialog(pdialog);
+}
+
+/****************************************************************
+popdown all dialogs
+*****************************************************************/
+void popdown_all_happiness_dialogs(void)
+{
+ if(!happiness_list_has_been_initialised) {
+ return;
+ }
+ while(genlist_size(&happiness_list)) {
+ close_happiness_dialog(genlist_get(&happiness_list,0));
+ }
+}
+
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/gui-gtk/cityrep.c
freeciv/client/gui-gtk/cityrep.c
--- freeciv.orig/client/gui-gtk/cityrep.c Sat Aug 25 13:56:16 2001
+++ freeciv/client/gui-gtk/cityrep.c Sat Sep 1 14:29:37 2001
@@ -60,6 +60,7 @@
static void city_close_callback(GtkWidget *widget, gpointer data);
static void city_center_callback(GtkWidget *widget, gpointer data);
static void city_popup_callback(GtkWidget *widget, gpointer data);
+static void city_happiness_callback(GtkWidget *widget, gpointer data);
static void city_buy_callback(GtkWidget *widget, gpointer data);
static void city_refresh_callback(GtkWidget *widget, gpointer data);
static void city_change_all_dialog_callback(GtkWidget *w, gpointer data);
@@ -73,8 +74,12 @@
static GtkWidget *city_dialog_shell=NULL;
static GtkWidget *city_label;
static GtkWidget *city_list;
-static GtkWidget *city_center_command, *city_popup_command, *city_buy_command,
- *city_refresh_command, *city_config_command;
+static GtkWidget *city_center_command;
+static GtkWidget *city_popup_command;
+static GtkWidget *city_happiness_command;
+static GtkWidget *city_buy_command;
+static GtkWidget *city_refresh_command;
+static GtkWidget *city_config_command;
static GtkWidget *city_change_command;
static GtkWidget *city_change_all_command;
static GtkWidget *city_change_all_dialog_shell;
@@ -423,6 +428,7 @@
static char buf [NUM_CREPORT_COLS][64];
GtkWidget *close_command, *scrolled;
+ GtkWidget *hbox1, *hbox2, *vbox;
char *report_title;
int i;
GtkAccelGroup *accel=gtk_accel_group_new();
@@ -464,52 +470,58 @@
for (i=0;i<NUM_CREPORT_COLS;i++)
gtk_clist_set_column_auto_resize (GTK_CLIST (city_list), i, TRUE);
- close_command = gtk_accelbutton_new(_("C_lose"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- close_command, TRUE, TRUE, 0 );
- GTK_WIDGET_SET_FLAGS( close_command, GTK_CAN_DEFAULT );
- gtk_widget_grab_default( close_command );
+ hbox1 = gtk_hbox_new (TRUE, 10);
city_center_command = gtk_accelbutton_new(_("Cen_ter"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_center_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox1), city_center_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_center_command, GTK_CAN_DEFAULT );
city_popup_command = gtk_accelbutton_new(_("_Popup"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_popup_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox1), city_popup_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_popup_command, GTK_CAN_DEFAULT );
+ city_happiness_command = gtk_accelbutton_new(_("_Happiness"), accel);
+ gtk_box_pack_start( GTK_BOX(hbox1), city_happiness_command, TRUE, TRUE, 0 );
+ GTK_WIDGET_SET_FLAGS( city_happiness_command, GTK_CAN_DEFAULT );
+
city_buy_command = gtk_accelbutton_new(_("_Buy"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_buy_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox1), city_buy_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_buy_command, GTK_CAN_DEFAULT );
city_change_command = gtk_accelbutton_new(_("_Change"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_change_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox1), city_change_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_change_command, GTK_CAN_DEFAULT );
- city_change_all_command = gtk_accelbutton_new(_("Change _All"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_change_all_command, TRUE, TRUE, 0 );
- GTK_WIDGET_SET_FLAGS( city_change_all_command, GTK_CAN_DEFAULT );
+ hbox2 = gtk_hbox_new (TRUE, 10);
+
+ close_command = gtk_accelbutton_new(_("C_lose"), accel);
+ gtk_box_pack_start( GTK_BOX(hbox2), close_command, TRUE, TRUE, 0 );
+ GTK_WIDGET_SET_FLAGS( close_command, GTK_CAN_DEFAULT );
+ gtk_widget_grab_default( close_command );
city_refresh_command = gtk_accelbutton_new(_("_Refresh"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_refresh_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox2), city_refresh_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_refresh_command, GTK_CAN_DEFAULT );
city_select_command = gtk_accelbutton_new(_("_Select"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_select_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox2), city_select_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_select_command, GTK_CAN_DEFAULT );
city_config_command = gtk_accelbutton_new(_("Con_figure"), accel);
- gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
- city_config_command, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(hbox2), city_config_command, TRUE, TRUE, 0 );
GTK_WIDGET_SET_FLAGS( city_config_command, GTK_CAN_DEFAULT );
+ city_change_all_command = gtk_accelbutton_new(_("Change _All"), accel);
+ gtk_box_pack_start( GTK_BOX(hbox2), city_change_all_command, TRUE, TRUE, 0 );
+ GTK_WIDGET_SET_FLAGS( city_change_all_command, GTK_CAN_DEFAULT );
+
+ vbox = gtk_vbox_new (TRUE, 5);
+
+ gtk_box_pack_start( GTK_BOX(vbox), hbox1, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX(vbox), hbox2, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX( GTK_DIALOG(city_dialog_shell)->action_area ),
+ vbox, TRUE, TRUE, 0 );
+
gtk_signal_connect(GTK_OBJECT(city_select_command), "event",
GTK_SIGNAL_FUNC(city_select_callback), NULL);
gtk_signal_connect(GTK_OBJECT(close_command), "clicked",
@@ -518,6 +530,8 @@
GTK_SIGNAL_FUNC(city_center_callback), NULL);
gtk_signal_connect(GTK_OBJECT(city_popup_command), "clicked",
GTK_SIGNAL_FUNC(city_popup_callback), NULL);
+ gtk_signal_connect(GTK_OBJECT(city_happiness_command), "clicked",
+ GTK_SIGNAL_FUNC(city_happiness_callback), NULL);
gtk_signal_connect(GTK_OBJECT(city_buy_command), "clicked",
GTK_SIGNAL_FUNC(city_buy_callback), NULL);
gtk_signal_connect(GTK_OBJECT(city_refresh_command), "clicked",
@@ -556,6 +570,7 @@
gtk_widget_set_sensitive(city_change_command, TRUE);
gtk_widget_set_sensitive(city_center_command, TRUE);
gtk_widget_set_sensitive(city_popup_command, TRUE);
+ gtk_widget_set_sensitive(city_happiness_command, TRUE);
gtk_widget_set_sensitive(city_buy_command, TRUE);
}
else
@@ -563,6 +578,7 @@
gtk_widget_set_sensitive(city_change_command, FALSE);
gtk_widget_set_sensitive(city_center_command, FALSE);
gtk_widget_set_sensitive(city_popup_command, FALSE);
+ gtk_widget_set_sensitive(city_happiness_command, FALSE);
gtk_widget_set_sensitive(city_buy_command, FALSE);
}
}
@@ -1118,6 +1134,33 @@
for(; copy; copy = g_list_next(copy))
popup_city_dialog(copy->data, 0);
+
+ g_list_free(copy);
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static void city_happiness_callback(GtkWidget *w, gpointer data)
+{
+ GList *current = GTK_CLIST(city_list)->selection;
+ GList *copy = NULL;
+ struct city *pcity;
+
+ if (!current)
+ return;
+
+ pcity = city_from_glist (current);
+ if (center_when_popup_city) {
+ center_tile_mapcanvas(pcity->x, pcity->y);
+ }
+
+ /* I copied all this from city_popup_callback() above */
+ for(; current; current = g_list_next(current))
+ copy = g_list_append (copy, city_from_glist(current));
+
+ for(; copy; copy = g_list_next(copy))
+ popup_happiness_dialog(copy->data);
g_list_free(copy);
}
diff -urN -Xfreeciv/diff_ignore freeciv.orig/client/include/citydlg_g.h
freeciv/client/include/citydlg_g.h
--- freeciv.orig/client/include/citydlg_g.h Tue Jun 26 13:34:39 2001
+++ freeciv/client/include/citydlg_g.h Sat Sep 1 14:29:37 2001
@@ -23,5 +23,8 @@
void refresh_unit_city_dialogs(struct unit *punit);
int city_dialog_is_open(struct city *pcity);
+void popup_happiness_dialog(struct city *pcity);
+void popdown_happiness_dialog(struct city *pcity);
+void popdown_all_happiness_dialogs(void);
#endif /* FC__CITYDLG_G_H */
--------------07B59762E35525FF8C9D0278--
- [Freeciv-Dev] Re: [PATCH] Happiness display (GTK client) (PR#655),
Davide Pagnin <=
|
|