diff -Nur -Xfreeciv/diff_ignore freeciv/client/gui-gtk/citydlg.c test-buy5/client/gui-gtk/citydlg.c --- freeciv/client/gui-gtk/citydlg.c Tue Feb 12 21:15:57 2002 +++ test-buy5/client/gui-gtk/citydlg.c Mon Feb 18 22:27:06 2002 @@ -105,7 +105,9 @@ GtkWidget *map_canvas_pixmap; GtkWidget *tradelist; GtkWidget *currently_building_frame; - GtkWidget *progress_label; + GtkWidget *shields_label; + GtkWidget *turns_label; + GtkWidget *cost_label; GtkWidget *improvement_list; GtkWidget *buy_command; GtkWidget *change_command; @@ -602,7 +604,7 @@ { int i; GtkWidget *halves, *hbox, *vbox, *page, *align; - GtkWidget *frame, *table, *label, *scrolledwin; + GtkWidget *frame, *table, *label, *scrolledwin, *sep; char *improvement_title[] = { N_("City improvements"), N_("Upkeep") @@ -813,16 +815,23 @@ gtk_container_add(GTK_CONTAINER (pdialog->overview.currently_building_frame), hbox); - pdialog->overview.progress_label = gtk_progress_bar_new(); - gtk_box_pack_start(GTK_BOX(hbox), pdialog->overview.progress_label, - TRUE, TRUE, 0); - gtk_progress_configure(GTK_PROGRESS(pdialog->overview.progress_label), - 50, 0, 100); - gtk_progress_set_show_text(GTK_PROGRESS - (pdialog->overview.progress_label), TRUE); - gtk_progress_set_format_string(GTK_PROGRESS - (pdialog->overview.progress_label), - _("%d/%d %d turns")); + pdialog->overview.shields_label = gtk_label_new(_("999/999")); + gtk_box_pack_start(GTK_BOX(hbox), pdialog->overview.shields_label, + TRUE, TRUE, 5); + + sep = gtk_vseparator_new(); + gtk_box_pack_start(GTK_BOX(hbox), sep, TRUE, TRUE, 0); + + pdialog->overview.turns_label = gtk_label_new(_("999 turns")); + gtk_box_pack_start(GTK_BOX(hbox), pdialog->overview.turns_label, + TRUE, TRUE, 5); + + sep = gtk_vseparator_new(); + gtk_box_pack_start(GTK_BOX(hbox), sep, TRUE, TRUE, 0); + + pdialog->overview.cost_label = gtk_label_new(_("cost: 9999")); + gtk_box_pack_start(GTK_BOX(hbox), pdialog->overview.cost_label, + TRUE, TRUE, 5); pdialog->overview.buy_command = gtk_accelbutton_new(_("_Buy"), pdialog->accel); @@ -1889,65 +1898,54 @@ *****************************************************************/ static void city_dialog_update_building(struct city_dialog *pdialog) { - char buf[32], buf2[200], *descr; - int turns; + char sbuf[10], tbuf[20], cbuf[20], dbuf[200], *descr; struct city *pcity = pdialog->pcity; - gfloat pct; - - gtk_widget_set_sensitive(pdialog->overview.buy_command, !pcity->did_buy); - gtk_widget_set_sensitive(pdialog->overview.sell_command, - !pcity->did_sell); + int turns, cost = city_buy_cost(pcity); + + gtk_widget_set_sensitive(pdialog->overview.buy_command, !pcity->did_buy + && game.player_ptr->economic.gold >= cost); + gtk_widget_set_sensitive(pdialog->overview.sell_command, !pcity->did_sell); if (pcity->is_building_unit) { - turns = - city_turns_to_build(pcity, pcity->currently_building, TRUE, TRUE); - my_snprintf(buf, sizeof(buf), - concise_city_production ? "%3d/%3d:%3d" : - PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns), - pcity->shield_stock, - get_unit_type(pcity->currently_building)->build_cost, - turns); + turns = city_turns_to_build(pcity, pcity->currently_building, TRUE, TRUE); descr = get_unit_type(pcity->currently_building)->name; - pct = - (gfloat) pcity->shield_stock / - (get_unit_type(pcity->currently_building)->build_cost + 0.1); - pct = CLAMP(pct, 0.0, 1.0); + + my_snprintf(sbuf, sizeof(sbuf), "%3d/%-3d", pcity->shield_stock, + get_unit_type(pcity->currently_building)->build_cost); + my_snprintf(tbuf, sizeof(tbuf), PL_("%3d turn", "%3d turns", turns), turns); + my_snprintf(cbuf, sizeof(cbuf), "cost: %-5d", cost); + } else { if (pcity->currently_building == B_CAPITAL) { /* Capitalization is special, you can't buy it or finish making it */ - my_snprintf(buf, sizeof(buf), - concise_city_production ? "%3d/XXX:XXX" : - _("%3d/XXX XXX turns"), pcity->shield_stock); + + my_snprintf(sbuf, sizeof(sbuf), "%3d/XXX", pcity->shield_stock); + my_snprintf(tbuf, sizeof(tbuf), "XXX turns"); + my_snprintf(cbuf, sizeof(cbuf), "cost: XXX "); + gtk_widget_set_sensitive(pdialog->overview.buy_command, FALSE); - pct = 1.0; } else { - turns = - city_turns_to_build(pcity, pcity->currently_building, FALSE, - TRUE); - my_snprintf(buf, sizeof(buf), - concise_city_production ? "%3d/%3d:%3d" : - PL_("%3d/%3d %3d turn", "%3d/%3d %3d turns", turns), - pcity->shield_stock, - get_improvement_type(pcity->currently_building)-> - build_cost, turns); - - pct = (gfloat) pcity->shield_stock / - (get_improvement_type(pcity->currently_building)->build_cost + - 0.1); - pct = CLAMP(pct, 0.0, 1.0); + turns = city_turns_to_build(pcity, pcity->currently_building, FALSE, + TRUE); + + my_snprintf(sbuf, sizeof(sbuf), "%3d/%-3d", pcity->shield_stock, + get_improvement_type(pcity->currently_building)->build_cost); + my_snprintf(tbuf, sizeof(tbuf), PL_("%3d turn", "%3d turns", turns), + turns); + my_snprintf(cbuf, sizeof(cbuf), "cost: %-5d", cost); } + descr = get_impr_name_ex(pcity, pcity->currently_building); } - my_snprintf(buf2, sizeof(buf2), "%s%s", descr, + my_snprintf(dbuf, sizeof(dbuf), "%s%s", descr, worklist_is_empty(pcity->worklist) ? "" : _(" (worklist)")); - gtk_frame_set_label(GTK_FRAME - (pdialog->overview.currently_building_frame), buf2); - gtk_progress_set_percentage(GTK_PROGRESS - (pdialog->overview.progress_label), pct); - gtk_progress_set_format_string(GTK_PROGRESS - (pdialog->overview.progress_label), buf); + gtk_frame_set_label(GTK_FRAME(pdialog->overview.currently_building_frame), + dbuf); + gtk_label_set_text(GTK_LABEL(pdialog->overview.shields_label), sbuf); + gtk_label_set_text(GTK_LABEL(pdialog->overview.turns_label), tbuf); + gtk_label_set_text(GTK_LABEL(pdialog->overview.cost_label), cbuf); } /**************************************************************** @@ -2932,47 +2930,37 @@ /********* Callbacks for Buy, Change, Sell, Worklist ************/ /**************************************************************** -... + popup for Buy button *****************************************************************/ static void buy_callback(GtkWidget * w, gpointer data) { - struct city_dialog *pdialog; - int value; + struct city_dialog *pdialog = (struct city_dialog *) data; + int value = city_buy_cost(pdialog->pcity); char *name; char buf[512]; - pdialog = (struct city_dialog *) data; - if (pdialog->pcity->is_building_unit) { name = get_unit_type(pdialog->pcity->currently_building)->name; } else { - name = - get_impr_name_ex(pdialog->pcity, - pdialog->pcity->currently_building); - } - value = city_buy_cost(pdialog->pcity); - - if (game.player_ptr->economic.gold >= value) { - my_snprintf(buf, sizeof(buf), - _("Buy %s for %d gold?\nTreasury contains %d gold."), - name, value, game.player_ptr->economic.gold); - - pdialog->buy_shell = - popup_message_dialog(pdialog->shell, /*"buydialog" */ _("Buy It!"), - buf, _("_Yes"), buy_callback_yes, pdialog, - _("_No"), buy_callback_no, pdialog, 0); - } else { - my_snprintf(buf, sizeof(buf), - _("%s costs %d gold.\nTreasury contains %d gold."), - name, value, game.player_ptr->economic.gold); - - pdialog->buy_shell = popup_message_dialog(pdialog->shell, - _("Buy It!"), buf, _("Darn"), - buy_callback_no, pdialog, 0); + name = get_impr_name_ex(pdialog->pcity, + pdialog->pcity->currently_building); } + assert(game.player_ptr->economic.gold >= value); + + my_snprintf(buf, sizeof(buf), + _("Buy %s for %d gold?\nTreasury contains %d gold."), + name, value, game.player_ptr->economic.gold); + + pdialog->buy_shell = popup_message_dialog(pdialog->shell, + _("Buy It!"), buf, + _("_Yes"), buy_callback_yes, + pdialog, + _("_No"), buy_callback_no, + pdialog, 0); + gtk_signal_connect(GTK_OBJECT(pdialog->buy_shell), "delete_event", - GTK_SIGNAL_FUNC(buy_callback_delete), data); + GTK_SIGNAL_FUNC(buy_callback_delete), data); } /**************************************************************** @@ -3303,8 +3291,8 @@ GList *selection = GTK_CLIST(pdialog->overview.improvement_list)->selection; - if (!selection || pdialog->pcity->did_buy || pdialog->pcity->did_sell || - pdialog->pcity->owner != game.player_idx) { + if (!selection || pdialog->pcity->did_sell + || pdialog->pcity->owner != game.player_idx) { gtk_set_label(GTK_BUTTON(pdialog->overview.sell_command)->child, _("Sell")); gtk_widget_set_sensitive(pdialog->overview.sell_command, FALSE);