[Freeciv-Dev] gtk tax rates display functions
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
G'day,
This patch does most of the work to clean up the rates_set_values()
function, and modify the behaivour of the locks, and display the Current
surplus, Turns/advance and no. of cities in disorder.
The locks now work so that at most one can be selected at one time (as
civ1/2 do it).
A slider now can't be dragged above the maximum it can be set to.
Everything works except that it is not receiving the updated city data
before it updates the values in the dialog, so it displays the values for
the previous update :)
Does anyone know an easy way to wait for updates from the server? Or is
this dynamic thing just too network intensive?
Richard
--------
Richard Atkins rja@xxxxxxxxxxx
http://www.pcug.org.au/~rja/
"All these moments will be lost in
time, like tears in the rain."
Blade Runner
--------
--- cvs-freeciv/client/gui-gtk/gamedlgs.c Mon Jan 3 22:50:24 2000
+++ mod-freeciv/client/gui-gtk/gamedlgs.c Tue Apr 25 12:31:00 2000
@@ -49,38 +49,91 @@
GtkWidget *rates_gov_label;
GtkWidget *rates_tax_toggle, *rates_lux_toggle, *rates_sci_toggle;
GtkWidget *rates_tax_label, *rates_lux_label, *rates_sci_label;
+GtkWidget *rates_tax_surplus, *rates_lux_disorder, *rates_sci_turns;
GtkObject *rates_tax_adj, *rates_lux_adj, *rates_sci_adj;
guint rates_tax_sig, rates_lux_sig, rates_sci_sig;
/******************************************************************/
int rates_tax_value, rates_lux_value, rates_sci_value;
+int rates_tax_old, rates_lux_old, rates_sci_old;
void rates_changed_callback(GtkAdjustment *adj);
/**************************************************************************
+ Deactivates the toggles that were not just activated.
+ Makes the toggles act like radio buttons, except (unlike radios) all three
+ can be deactivated.
+**************************************************************************/
+static void rates_toggle_callback(GtkWidget *w, gpointer data)
+{
+ GtkToggleButton *tax, *lux, *sci;
+ tax = GTK_TOGGLE_BUTTON(rates_tax_toggle);
+ lux = GTK_TOGGLE_BUTTON(rates_lux_toggle);
+ sci = GTK_TOGGLE_BUTTON(rates_sci_toggle);
+
+ if (GTK_TOGGLE_BUTTON(w)->active) {
+ if (w == rates_tax_toggle) {
+ gtk_toggle_button_set_active(lux, FALSE);
+ gtk_toggle_button_set_active(sci, FALSE);
+ } else if (w == rates_lux_toggle) {
+ gtk_toggle_button_set_active(tax, FALSE);
+ gtk_toggle_button_set_active(sci, FALSE);
+ } else {/* w == rates_sci_toggle */
+ gtk_toggle_button_set_active(tax, FALSE);
+ gtk_toggle_button_set_active(lux, FALSE);
+ }
+ }
+}
+
+static void send_rates_change_request(int tax, int lux, int sci)
+{
+ struct packet_player_request packet;
+
+ packet.tax=tax;
+ packet.science=sci;
+ packet.luxury=lux;
+ send_packet_player_request(&aconnection, &packet, PACKET_PLAYER_RATES);
+}
+
+/**************************************************************************
...
**************************************************************************/
-static void rates_set_values(int tax, int no_tax_scroll,
- int lux, int no_lux_scroll,
- int sci, int no_sci_scroll)
+static void rates_set_values(int tax, int lux, int sci)
{
char buf[64];
int tax_lock, lux_lock, sci_lock;
int maxrate;
-
+ int update_tax;
+ int update_lux;
+ int update_sci;
+
+ int surplus, disorder;
+ /* struct city *pcity;*/
+
+ update_tax = update_lux = update_sci = FALSE;
+
tax_lock = GTK_TOGGLE_BUTTON(rates_tax_toggle)->active;
lux_lock = GTK_TOGGLE_BUTTON(rates_lux_toggle)->active;
sci_lock = GTK_TOGGLE_BUTTON(rates_sci_toggle)->active;
maxrate=get_government_max_rate(game.player_ptr->government);
- /* This's quite a simple-minded "double check".. */
- tax=MIN(tax, maxrate);
- lux=MIN(lux, maxrate);
- sci=MIN(sci, maxrate);
-
+
+ if (tax > maxrate) {
+ tax = maxrate;
+ update_tax = TRUE;
+ }
+ if (lux > maxrate) {
+ lux = maxrate;
+ update_lux = TRUE;
+ }
+ if (sci > maxrate) {
+ sci = maxrate;
+ update_sci = TRUE;
+ }
+
if(tax+sci+lux!=100)
{
if((tax!=rates_tax_value))
@@ -110,85 +163,111 @@
lux=rates_lux_value;
sci=rates_sci_value;
- rates_tax_value=-1;
- rates_lux_value=-1;
- rates_sci_value=-1;
-
- no_tax_scroll=0;
- no_lux_scroll=0;
- no_sci_scroll=0;
+ update_tax = update_lux = update_sci = TRUE;
}
+ }
+
+ if (tax != rates_tax_value ||
+ lux != rates_lux_value ||
+ sci != rates_sci_value) {
+ if (tax != rates_tax_value)
+ update_tax = TRUE;
+ if (lux != rates_lux_value)
+ update_lux = TRUE;
+ if (sci != rates_sci_value)
+ update_sci = TRUE;
+ send_rates_change_request(tax, lux, sci);
}
- if(tax!=rates_tax_value) {
- my_snprintf(buf, sizeof(buf), "%3d%%", tax);
- if ( strcmp( buf, GTK_LABEL(rates_tax_label)->label) )
- gtk_set_label(rates_tax_label,buf);
- if(!no_tax_scroll)
- {
- gtk_signal_handler_block(GTK_OBJECT(rates_tax_adj),rates_tax_sig);
- gtk_adjustment_set_value( GTK_ADJUSTMENT(rates_tax_adj), tax/10 );
- gtk_signal_handler_unblock(GTK_OBJECT(rates_tax_adj),rates_tax_sig);
+ if (update_tax) {
+ if (tax != rates_tax_value) {
+ my_snprintf(buf, sizeof(buf), "%3d%%", tax);
+ if (strcmp(buf, GTK_LABEL(rates_tax_label)->label))
+ gtk_set_label(rates_tax_label, buf);
+ rates_tax_value = tax;
+
+ /* update surplus */
+ surplus = 0;
+ city_list_iterate(game.player_ptr->cities, pcity) {
+ surplus += city_gold_surplus(pcity);
+ } city_list_iterate_end;
+ my_snprintf(buf, sizeof(buf), _("%s%d surplus gold"),
+ (surplus < 0) ? "-" : (surplus > 0) ? "+" : "",
+ (surplus < 0) ? (-surplus) : surplus);
+ if (strcmp(buf, GTK_LABEL(rates_tax_surplus)->label))
+ gtk_set_label(rates_tax_surplus, buf);
}
- rates_tax_value=tax;
+ gtk_signal_handler_block(GTK_OBJECT(rates_tax_adj), rates_tax_sig);
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(rates_tax_adj), tax / 10);
+ gtk_signal_handler_unblock(GTK_OBJECT(rates_tax_adj), rates_tax_sig);
}
- if(lux!=rates_lux_value) {
- my_snprintf(buf, sizeof(buf), "%3d%%", lux);
- if ( strcmp( buf, GTK_LABEL(rates_lux_label)->label) )
- gtk_set_label(rates_lux_label,buf);
- if(!no_lux_scroll)
- {
- gtk_signal_handler_block(GTK_OBJECT(rates_lux_adj),rates_lux_sig);
- gtk_adjustment_set_value( GTK_ADJUSTMENT(rates_lux_adj), lux/10 );
- gtk_signal_handler_unblock(GTK_OBJECT(rates_lux_adj),rates_lux_sig);
+ if (update_lux) {
+ if (lux != rates_lux_value) {
+ my_snprintf(buf, sizeof(buf), "%3d%%", lux);
+ if ( strcmp(buf, GTK_LABEL(rates_lux_label)->label))
+ gtk_set_label(rates_lux_label, buf);
+ rates_lux_value = lux;
+
+ /* update disorder count */
+ disorder = 0;
+ city_list_iterate(game.player_ptr->cities, pcity) {
+ disorder += city_unhappy(pcity);
+ } city_list_iterate_end;
+ my_snprintf(buf, sizeof(buf), _("%d cities in disorder"), disorder);
+ if (strcmp(buf, GTK_LABEL(rates_lux_disorder)->label))
+ gtk_set_label(rates_lux_disorder, buf);
}
- rates_lux_value=lux;
+ gtk_signal_handler_block(GTK_OBJECT(rates_lux_adj), rates_lux_sig);
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(rates_lux_adj), lux / 10);
+ gtk_signal_handler_unblock(GTK_OBJECT(rates_lux_adj), rates_lux_sig);
}
- if(sci!=rates_sci_value) {
- my_snprintf(buf, sizeof(buf), "%3d%%", sci);
- if ( strcmp( buf, GTK_LABEL(rates_sci_label)->label) )
- gtk_set_label(rates_sci_label,buf);
- if(!no_sci_scroll)
- {
- gtk_signal_handler_block(GTK_OBJECT(rates_sci_adj),rates_sci_sig);
- gtk_adjustment_set_value( GTK_ADJUSTMENT(rates_sci_adj), sci/10 );
- gtk_signal_handler_unblock(GTK_OBJECT(rates_sci_adj),rates_sci_sig);
+ if(update_sci) {
+ if (sci != rates_sci_value) {
+ my_snprintf(buf, sizeof(buf), "%3d%%", sci);
+ if (strcmp( buf, GTK_LABEL(rates_sci_label)->label))
+ gtk_set_label(rates_sci_label, buf);
+ rates_sci_value = sci;
+
+ /* update turn count */
+ my_snprintf(buf, sizeof(buf), _("%d turns/advance"),
+ tech_turns_to_advance(game.player_ptr));
+ if (strcmp( buf, GTK_LABEL(rates_sci_turns)->label))
+ gtk_set_label(rates_sci_turns, buf);
}
- rates_sci_value=sci;
+ gtk_signal_handler_block(GTK_OBJECT(rates_sci_adj), rates_sci_sig);
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(rates_sci_adj), sci / 10);
+ gtk_signal_handler_unblock(GTK_OBJECT(rates_sci_adj), rates_sci_sig);
}
}
-
/**************************************************************************
...
**************************************************************************/
void rates_changed_callback(GtkAdjustment *adj)
{
- int percent=adj->value;
-
- if(adj==GTK_ADJUSTMENT(rates_tax_adj)) {
+ if (adj == GTK_ADJUSTMENT(rates_tax_adj)) {
int tax_value;
- tax_value=10*percent;
- tax_value=MIN(tax_value, 100);
- rates_set_values(tax_value,1, rates_lux_value,0, rates_sci_value,0);
+ tax_value = adj->value * 10;
+ tax_value = MIN(tax_value, 100);
+ rates_set_values(tax_value, rates_lux_value, rates_sci_value);
}
- else if(adj==GTK_ADJUSTMENT(rates_lux_adj)) {
+ else if (adj == GTK_ADJUSTMENT(rates_lux_adj)) {
int lux_value;
- lux_value=10*percent;
- lux_value=MIN(lux_value, 100);
- rates_set_values(rates_tax_value,0, lux_value,1, rates_sci_value,0);
+ lux_value = adj->value * 10;
+ lux_value = MIN(lux_value, 100);
+ rates_set_values(rates_tax_value, lux_value, rates_sci_value);
}
else {
int sci_value;
- sci_value=10*percent;
- sci_value=MIN(sci_value, 100);
- rates_set_values(rates_tax_value,0, rates_lux_value,0, sci_value,1);
+ sci_value = adj->value * 10;
+ sci_value = MIN(sci_value, 100);
+ rates_set_values(rates_tax_value, rates_lux_value, sci_value);
}
}
@@ -198,15 +277,11 @@
**************************************************************************/
static void rates_ok_command_callback(GtkWidget *widget, gpointer data)
{
- struct packet_player_request packet;
-
gtk_widget_set_sensitive(toplevel, TRUE);
gtk_widget_destroy(rates_dialog_shell);
-
- packet.tax=rates_tax_value;
- packet.science=rates_sci_value;
- packet.luxury=rates_lux_value;
- send_packet_player_request(&aconnection, &packet, PACKET_PLAYER_RATES);
+ /*
+ send_rates_change_request(rates_tax_value, rates_sci_value, rates_lux_value);
+ */
}
@@ -217,6 +292,11 @@
{
gtk_widget_set_sensitive(toplevel, TRUE);
gtk_widget_destroy(rates_dialog_shell);
+
+ if (rates_tax_value != rates_tax_old ||
+ rates_lux_value != rates_lux_old ||
+ rates_sci_value != rates_sci_old)
+ send_rates_change_request(rates_tax_old, rates_lux_old, rates_sci_old);
}
@@ -226,7 +306,7 @@
*****************************************************************/
static void create_rates_dialog(void)
{
- GtkWidget *frame, *hbox;
+ GtkWidget *frame, *hbox, *vbox;
GtkWidget *scale;
GtkWidget *button;
@@ -249,11 +329,17 @@
hbox = gtk_hbox_new( FALSE, 10 );
gtk_container_add( GTK_CONTAINER( frame ), hbox );
- rates_tax_adj = gtk_adjustment_new( 0.0, 0.0, 11.0, 1.0, 1.0, 1.0 );
+ /* adjustments: value, lower, upper, step_incr, page_incr, page_size */
+ /* the maximum value possible is upper - page_size */
+ /* step_incr of 10.0 seems to allow unit changes to scale, so we use
+ step_incr of 1.0 here, and scale accordingly in rates_set_values() and
+ rates_changed_callback(). */
+ rates_tax_adj = gtk_adjustment_new(0.0, 0.0, 10.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new( GTK_ADJUSTMENT( rates_tax_adj ) );
gtk_widget_set_usize( GTK_WIDGET( scale ), 300, 40 );
gtk_scale_set_digits( GTK_SCALE( scale ), 0 );
gtk_scale_set_draw_value( GTK_SCALE( scale ), FALSE );
+ gtk_range_set_update_policy(GTK_RANGE(scale), GTK_UPDATE_CONTINUOUS);
gtk_box_pack_start( GTK_BOX( hbox ), scale, TRUE, TRUE, 0 );
rates_tax_label = gtk_label_new(" 0%");
@@ -269,11 +355,12 @@
hbox = gtk_hbox_new( FALSE, 10 );
gtk_container_add( GTK_CONTAINER( frame ), hbox );
- rates_lux_adj = gtk_adjustment_new( 0.0, 0.0, 11.0, 1.0, 1.0, 1.0 );
+ rates_lux_adj = gtk_adjustment_new(0.0, 0.0, 10.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new( GTK_ADJUSTMENT( rates_lux_adj ) );
gtk_widget_set_usize( GTK_WIDGET( scale ), 300, 40 );
gtk_scale_set_digits( GTK_SCALE( scale ), 0 );
gtk_scale_set_draw_value( GTK_SCALE( scale ), FALSE );
+ gtk_range_set_update_policy(GTK_RANGE(scale), GTK_UPDATE_CONTINUOUS);
gtk_box_pack_start( GTK_BOX( hbox ), scale, TRUE, TRUE, 0 );
rates_lux_label = gtk_label_new(" 0%");
@@ -289,11 +376,12 @@
hbox = gtk_hbox_new( FALSE, 10 );
gtk_container_add( GTK_CONTAINER( frame ), hbox );
- rates_sci_adj = gtk_adjustment_new( 0.0, 0.0, 11.0, 1.0, 1.0, 1.0 );
+ rates_sci_adj = gtk_adjustment_new(0.0, 0.0, 10.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new( GTK_ADJUSTMENT( rates_sci_adj ) );
gtk_widget_set_usize( GTK_WIDGET( scale ), 300, 40 );
gtk_scale_set_digits( GTK_SCALE( scale ), 0 );
gtk_scale_set_draw_value( GTK_SCALE( scale ), FALSE );
+ gtk_range_set_update_policy(GTK_RANGE(scale), GTK_UPDATE_CONTINUOUS);
gtk_box_pack_start( GTK_BOX( hbox ), scale, TRUE, TRUE, 0 );
rates_sci_label = gtk_label_new(" 0%");
@@ -303,6 +391,25 @@
rates_sci_toggle = gtk_check_button_new_with_label( _("Lock") );
gtk_box_pack_start( GTK_BOX( hbox ), rates_sci_toggle, TRUE, TRUE, 0 );
+ vbox = gtk_vbox_new(FALSE, 5);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(rates_dialog_shell)->vbox), vbox,
+ TRUE, TRUE, 5 );
+
+ rates_tax_surplus = gtk_label_new("0 surplus gold");
+ gtk_box_pack_start(GTK_BOX(vbox), rates_tax_surplus, TRUE, TRUE, 0);
+
+ rates_lux_disorder = gtk_label_new("0 cities in disorder");
+ gtk_box_pack_start(GTK_BOX(vbox), rates_lux_disorder, TRUE, TRUE, 0);
+
+ rates_sci_turns = gtk_label_new("0 turns/advance");
+ gtk_box_pack_start(GTK_BOX(vbox), rates_sci_turns, TRUE, TRUE, 0);
+
+ gtk_signal_connect(GTK_OBJECT(rates_tax_toggle), "toggled",
+ GTK_SIGNAL_FUNC(rates_toggle_callback), NULL);
+ gtk_signal_connect(GTK_OBJECT(rates_lux_toggle), "toggled",
+ GTK_SIGNAL_FUNC(rates_toggle_callback), NULL);
+ gtk_signal_connect(GTK_OBJECT(rates_sci_toggle), "toggled",
+ GTK_SIGNAL_FUNC(rates_toggle_callback), NULL);
button = gtk_button_new_with_label( _("Ok") );
@@ -339,9 +446,13 @@
gtk_signal_connect_after( GTK_OBJECT( rates_sci_adj ), "value_changed",
GTK_SIGNAL_FUNC( rates_changed_callback ), NULL );
- rates_set_values( game.player_ptr->economic.tax, 0,
- game.player_ptr->economic.luxury, 0,
- game.player_ptr->economic.science, 0 );
+ rates_tax_old = game.player_ptr->economic.tax;
+ rates_lux_old = game.player_ptr->economic.luxury;
+ rates_sci_old = game.player_ptr->economic.science;
+
+ rates_set_values(game.player_ptr->economic.tax,
+ game.player_ptr->economic.luxury,
+ game.player_ptr->economic.science);
return;
}
- [Freeciv-Dev] gtk tax rates display functions,
Richard Atkins <=
|
|