Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#12902) no way to upgrade units through menu
Home

[Freeciv-Dev] (PR#12902) no way to upgrade units through menu

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12902) no way to upgrade units through menu
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Feb 2006 21:03:41 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12902 >

> [jdorje - Tue Apr 26 19:32:42 2005]:
> 
> The only way to upgrade units is through the citydlg or through the
> units report.
> 
> If you select a unit there should be an "upgrade" entry in the orders
menu.

This rather nice patch should do it.

-jason


Index: client/gui-gtk-2.0/menu.c
===================================================================
--- client/gui-gtk-2.0/menu.c   (revision 11656)
+++ client/gui-gtk-2.0/menu.c   (working copy)
@@ -142,6 +142,7 @@
   MENU_ORDER_GOTO_CITY,
   MENU_ORDER_RETURN,
   MENU_ORDER_DISBAND,
+  MENU_ORDER_UPGRADE,
   MENU_ORDER_DIPLOMAT_DLG,
   MENU_ORDER_NUKE,
   MENU_ORDER_SELECT_SAME_TYPE,
@@ -522,6 +523,9 @@
    case MENU_ORDER_DISBAND:
     key_unit_disband();
     break;
+  case MENU_ORDER_UPGRADE:
+    popup_upgrade_dialog(get_units_in_focus());
+    break;
    case MENU_ORDER_DIPLOMAT_DLG:
     key_unit_diplomat_actions();
     break;
@@ -866,6 +870,8 @@
        NULL,                   0,                                      
"<Separator>"   },
   { "/" N_("Orders") "/" N_("Disband Unit"),           "<shift>d",
        orders_menu_callback,   MENU_ORDER_DISBAND                              
        },
+  { "/" N_("Orders") "/" N_("Upgrade unit"), "<ctrl>u",
+    orders_menu_callback, MENU_ORDER_UPGRADE },
   { "/" N_("Orders") "/" N_("Diplomat\\/Spy Actions"), "d",
        orders_menu_callback,   MENU_ORDER_DIPLOMAT_DLG                         
        },
   { "/" N_("Orders") "/" N_("Explode Nuclear"),        "<shift>n",
@@ -1348,6 +1354,8 @@
                          can_units_do_activity(punits, ACTIVITY_PILLAGE));
       menus_set_sensitive("<main>/_Orders/_Disband Unit",
                          units_have_flag(punits, F_UNDISBANDABLE, FALSE));
+      menus_set_sensitive("<main>/_Orders/_Upgrade unit",
+                         TRUE /* FIXME: what check should we do? */);
       menus_set_sensitive("<main>/_Orders/Make _Homecity",
                          can_units_do(punits, can_unit_change_homecity));
       menus_set_sensitive("<main>/_Orders/_Unload Transporter",
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c        (revision 11656)
+++ client/gui-gtk-2.0/dialogs.c        (working copy)
@@ -51,6 +51,7 @@
 #include "mapview.h"
 #include "options.h"
 #include "packhand.h"
+#include "text.h"
 #include "tilespec.h"
 
 #include "dialogs.h"
@@ -1258,6 +1259,43 @@
   return TRUE;
 }
 
+/****************************************************************************
+  Pops up a dialog to confirm upgrading of the unit.
+****************************************************************************/
+void popup_upgrade_dialog(struct unit_list *punits)
+{
+  GtkWidget *shell;
+  char buf[512];
+
+  if (!punits || unit_list_size(punits) == 0) {
+    return;
+  }
+
+  if (!get_units_upgrade_info(buf, sizeof(buf), punits)) {
+    shell = gtk_message_dialog_new(NULL, 0,
+                                  GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, buf);
+    gtk_window_set_title(GTK_WINDOW(shell), _("Upgrade Unit!"));
+    setup_dialog(shell, toplevel);
+    g_signal_connect(shell, "response", G_CALLBACK(gtk_widget_destroy),
+                    NULL);
+    gtk_window_present(GTK_WINDOW(shell));
+  } else {
+    shell = gtk_message_dialog_new(NULL, 0,
+                                  GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+                                  buf);
+    gtk_window_set_title(GTK_WINDOW(shell), _("Upgrade Obsolete Units"));
+    setup_dialog(shell, toplevel);
+    gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_YES);
+
+    if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
+      unit_list_iterate(punits, punit) {
+       request_unit_upgrade(punit);
+      } unit_list_iterate_end;
+    }
+    gtk_widget_destroy(shell);
+  }
+}
+
 /********************************************************************** 
   This function is called when the client disconnects or the game is
   over.  It should close all dialog windows for that game.
Index: client/text.c
===================================================================
--- client/text.c       (revision 11656)
+++ client/text.c       (working copy)
@@ -797,6 +797,57 @@
 }
 
 /****************************************************************************
+  Return text about upgrading these unit lists.
+
+  Returns TRUE iff any units can be upgraded.
+****************************************************************************/
+bool get_units_upgrade_info(char *buf, size_t bufsz,
+                           struct unit_list *punits)
+{
+  if (unit_list_size(punits) == 0) {
+    my_snprintf(buf, bufsz, _("No units to upgrade!"));
+    return FALSE;
+  } else if (unit_list_size(punits) == 1) {
+    return (get_unit_upgrade_info(buf, bufsz, unit_list_get(punits, 0))
+           == UR_OK);
+  } else {
+    int upgrade_cost = 0;
+    int num_upgraded = 0;
+    int min_upgrade_cost = FC_INFINITY;
+
+    unit_list_iterate(punits, punit) {
+      if (punit->owner == game.player_ptr
+         && test_unit_upgrade(punit, FALSE) == UR_OK) {
+       struct unit_type *from_unittype = punit->type;
+       struct unit_type *to_unittype = can_upgrade_unittype(game.player_ptr,
+                                                            punit->type);
+       int cost = unit_upgrade_price(punit->owner,
+                                          from_unittype, to_unittype);
+
+       num_upgraded++;
+       upgrade_cost += cost;
+       min_upgrade_cost = MIN(min_upgrade_cost, cost);
+      }
+    } unit_list_iterate_end;
+    if (num_upgraded == 0) {
+      my_snprintf(buf, bufsz, _("None of these units may be upgraded."));
+      return FALSE;
+    } else {
+      /* This may trigger sometimes if you don't have enough money for
+       * a full upgrade.  If you have enough to upgrade at least one, it
+       * will do it. */
+      my_snprintf(buf, bufsz, PL_("Upgrade %d unit for %d gold?\n"
+                                 "Treasury contains %d gold.", 
+                                 "Upgrade %d units for %d gold?\n"
+                                 "Treasury contains %d gold.",
+                                 num_upgraded),
+                 num_upgraded, upgrade_cost, game.player_ptr->economic.gold);
+      return TRUE;
+    }
+  }
+}
+
+/****************************************************************************
   Get a tooltip text for the info panel research indicator.  See
   client_research_sprite().
 ****************************************************************************/
Index: client/text.h
===================================================================
--- client/text.h       (revision 11656)
+++ client/text.h       (working copy)
@@ -37,6 +37,8 @@
 const char *get_government_tooltip(void);
 const char *get_unit_info_label_text1(struct unit_list *punits);
 const char *get_unit_info_label_text2(struct unit_list *punits);
+bool get_units_upgrade_info(char *buf, size_t bufsz,
+                           struct unit_list *punits);
 const char *get_spaceship_descr(struct player_spaceship *pship);
 const char *get_timeout_label_text(void);
 const char *format_duration(int duration);
Index: client/include/dialogs_g.h
===================================================================
--- client/include/dialogs_g.h  (revision 11656)
+++ client/include/dialogs_g.h  (working copy)
@@ -45,6 +45,7 @@
 void popup_bribe_dialog(struct unit *punit);
 void popup_sabotage_dialog(struct city *pcity);
 void popup_pillage_dialog(struct unit *punit, bv_special may_pillage);
+void popup_upgrade_dialog(struct unit_list *punits);
 
 void popdown_all_game_dialogs(void);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12902) no way to upgrade units through menu, Jason Short <=