~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to client/gui-gtk-2.0/menu.c

  • Committer: Package Import Robot
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2011-08-28 22:40:00 UTC
  • mfrom: (1.2.19 upstream)
  • Revision ID: package-import@ubuntu.com-20110828224000-j2r1erewlem25dox
Tags: 2.3.0-1
[ Karl Goetz ]
* New upstream version.
* Fix themes_sdl_use_system_fonts.diff to apply cleanly on 2.3.0
* Massage work_around_unity_induced_breakage.diff to get it
  applying to the new codebase (The patch assumes commits made
  after 2.3.0 was tagged upstream).

[ Clint Adams ]
* Fudge build system to think there is no libtool mismatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "options.h"
40
40
#include "tilespec.h"
41
41
 
42
 
/* gui-gtk-2.0 */
 
42
/* client/gui-gtk-2.0 */
43
43
#include "chatline.h"
44
44
#include "cityrep.h"
45
45
#include "dialogs.h"
109
109
*****************************************************************/
110
110
static void local_options_callback(GtkAction *action, gpointer data)
111
111
{
112
 
  popup_option_dialog();
 
112
  option_dialog_popup(_("Set local options"), client_optset);
113
113
}
114
114
 
115
115
/****************************************************************
125
125
*****************************************************************/
126
126
static void server_options_callback(GtkAction *action, gpointer data)
127
127
{
128
 
  popup_settable_options_dialog();
 
128
  option_dialog_popup(_("Game Settings"), server_optset);
129
129
}
130
130
 
131
131
/****************************************************************
257
257
*****************************************************************/
258
258
static void report_messages_callback(GtkAction *action, gpointer data)
259
259
{
260
 
  popup_meswin_dialog(TRUE);
 
260
  meswin_dialog_popup(TRUE);
261
261
}
262
262
 
263
263
/****************************************************************
437
437
}
438
438
 
439
439
/****************************************************************
 
440
  Action "HELP_NATIONS" callback.
 
441
*****************************************************************/
 
442
static void help_nations_callback(GtkAction *action, gpointer data)
 
443
{
 
444
  popup_help_dialog_string(HELP_NATIONS_ITEM);
 
445
}
 
446
 
 
447
/****************************************************************
440
448
  Action "HELP_COPYING" callback.
441
449
*****************************************************************/
442
450
static void help_copying_callback(GtkAction *action, gpointer data)
468
476
{
469
477
  if (game.info.is_edit_mode ^ gtk_toggle_action_get_active(action)) {
470
478
    key_editor_toggle();
471
 
    popdown_science_dialog(); /* Unreachbale techs in reqtree on/off */
 
479
    /* Unreachbale techs in reqtree on/off */
 
480
    science_report_dialog_popdown();
472
481
  }
473
482
}
474
483
 
953
962
}
954
963
 
955
964
/****************************************************************
 
965
  Action "UNIT_CONVERT" callback.
 
966
*****************************************************************/
 
967
static void unit_convert_callback(GtkAction *action, gpointer data)
 
968
{
 
969
  key_unit_convert();
 
970
}
 
971
 
 
972
/****************************************************************
956
973
  Action "UNIT_DISBAND" callback.
957
974
*****************************************************************/
958
975
static void unit_disband_callback(GtkAction *action, gpointer data)
970
987
     * not good! */
971
988
    /* Enable the button for adding to a city in all cases, so we
972
989
       get an eventual error message from the server if we try. */
973
 
    if (can_unit_add_or_build_city(punit)) {
 
990
    if (unit_can_add_or_build_city(punit)) {
974
991
      request_unit_build_city(punit);
975
992
    } else if (unit_has_type_flag(punit, F_HELP_WONDER)) {
976
993
      request_unit_caravan_action(punit, PACKET_UNIT_HELP_BUILD_WONDER);
1178
1195
*****************************************************************/
1179
1196
static void report_units_callback(GtkAction *action, gpointer data)
1180
1197
{
1181
 
  popup_activeunits_report_dialog(TRUE);
 
1198
  units_report_dialog_popup(TRUE);
1182
1199
}
1183
1200
 
1184
1201
/****************************************************************
1186
1203
*****************************************************************/
1187
1204
static void report_cities_callback(GtkAction *action, gpointer data)
1188
1205
{
1189
 
  popup_city_report_dialog(TRUE);
 
1206
  city_report_dialog_popup(TRUE);
1190
1207
}
1191
1208
 
1192
1209
/****************************************************************
1194
1211
*****************************************************************/
1195
1212
static void report_economy_callback(GtkAction *action, gpointer data)
1196
1213
{
1197
 
  popup_economy_report_dialog(TRUE);
 
1214
  economy_report_dialog_popup(TRUE);
1198
1215
}
1199
1216
 
1200
1217
/****************************************************************
1202
1219
*****************************************************************/
1203
1220
static void report_research_callback(GtkAction *action, gpointer data)
1204
1221
{
1205
 
  popup_science_dialog(TRUE);
 
1222
  science_report_dialog_popup(TRUE);
1206
1223
}
1207
1224
 
1208
1225
/****************************************************************
1273
1290
      /* Civilization menu. */
1274
1291
      {"MAP_VIEW", NULL, Q_("?noun:_View"),
1275
1292
       "F1", NULL, G_CALLBACK(map_view_callback)},
 
1293
      {"REPORT_UNITS", NULL, _("_Units"),
 
1294
       "F2", NULL, G_CALLBACK(report_units_callback)},
1276
1295
      {"REPORT_NATIONS", NULL, _("_Nations"),
1277
1296
       "F3", NULL, G_CALLBACK(report_nations_callback)},
 
1297
      {"REPORT_CITIES", NULL, _("_Cities"),
 
1298
       "F4", NULL, G_CALLBACK(report_cities_callback)},
1278
1299
 
1279
1300
      {"REPORT_WOW", NULL, _("_Wonders of the World"),
1280
1301
       "F7", NULL, G_CALLBACK(report_wow_callback)},
1317
1338
       NULL, NULL, G_CALLBACK(help_space_rate_callback)},
1318
1339
      {"HELP_RULESET", NULL, _("About Ruleset"),
1319
1340
       NULL, NULL, G_CALLBACK(help_ruleset_callback)},
 
1341
      {"HELP_NATIONS", NULL, _("About Nations"),
 
1342
       NULL, NULL, G_CALLBACK(help_nations_callback)},
1320
1343
 
1321
1344
      {"HELP_CONNECTING", NULL, _("Connecting"),
1322
1345
       NULL, NULL, G_CALLBACK(help_connecting_callback)},
1404
1427
      {"SHOW_BETTER_FOG_OF_WAR", NULL, _("Better Fog of War"),
1405
1428
       NULL, NULL, G_CALLBACK(show_better_fog_of_war_callback), FALSE},
1406
1429
 
1407
 
      {"FULL_SCREEN", NULL, _("_Full Screen"),
 
1430
      {"FULL_SCREEN", NULL, _("_Fullscreen"),
1408
1431
       "<Alt>Return", NULL, G_CALLBACK(full_screen_callback), FALSE}
1409
1432
    };
1410
1433
 
1513
1536
       "h", NULL, G_CALLBACK(unit_homecity_callback)},
1514
1537
      {"UNIT_UPGRADE", NULL, _("Upgr_ade"),
1515
1538
       "<Shift>u", NULL, G_CALLBACK(unit_upgrade_callback)},
 
1539
      {"UNIT_CONVERT", NULL, _("C_onvert"),
 
1540
       "<Shift>o", NULL, G_CALLBACK(unit_convert_callback)},
1516
1541
      {"UNIT_DISBAND", NULL, _("_Disband"),
1517
1542
       "<Shift>d", NULL, G_CALLBACK(unit_disband_callback)},
1518
1543
 
1546
1571
       "n", NULL, G_CALLBACK(clean_fallout_callback)},
1547
1572
 
1548
1573
      /* Combat menu. */
1549
 
      {"BUILD_FORTRESS", NULL, _("Build _Fortress"),
 
1574
      {"BUILD_FORTRESS", NULL, _("Build Type A Base"),
1550
1575
       "f", NULL, G_CALLBACK(build_fortress_callback)},
1551
 
      {"BUILD_AIRBASE", NULL, _("Build Airbas_e"),
 
1576
      {"BUILD_AIRBASE", NULL, _("Build Type B Base"),
1552
1577
       "e", NULL, G_CALLBACK(build_airbase_callback)},
1553
1578
 
1554
1579
      {"DO_PILLAGE", NULL, _("_Pillage"),
1619
1644
       "c", NULL, G_CALLBACK(center_view_callback)},
1620
1645
 
1621
1646
      /* Civilization menu. */
1622
 
      {"REPORT_UNITS", NULL, _("_Units"),
1623
 
       "F2", NULL, G_CALLBACK(report_units_callback)},
1624
 
      {"REPORT_CITIES", NULL, _("_Cities"),
1625
 
       "F4", NULL, G_CALLBACK(report_cities_callback)},
1626
1647
      {"REPORT_ECONOMY", NULL, _("_Economy"),
1627
1648
       "F5", NULL, G_CALLBACK(report_economy_callback)},
1628
1649
      {"REPORT_RESEARCH", NULL, _("_Research"),
1646
1667
static const gchar *get_ui_filename(void)
1647
1668
{
1648
1669
  static char filename[256];
1649
 
  char *name;
 
1670
  const char *name;
1650
1671
 
1651
1672
  if ((name = getenv("FREECIV_MENUS"))
1652
 
      || (name = datafilename("gtk_menus.xml"))) {
 
1673
      || (name = fileinfoname(get_data_dirs(), "gtk_menus.xml"))) {
1653
1674
    sz_strlcpy(filename, name);
1654
1675
  } else {
1655
 
    freelog(LOG_ERROR, "Gtk menus: file definition not found");
 
1676
    log_error("Gtk menus: file definition not found");
1656
1677
    filename[0] = '\0';
1657
1678
  }
1658
1679
 
1659
 
  freelog(LOG_VERBOSE, "ui menu file is \"%s\".", filename);
 
1680
  log_verbose("ui menu file is \"%s\".", filename);
1660
1681
  return filename;
1661
1682
}
1662
1683
 
1698
1719
  /* Load the menus. */
1699
1720
  if (0 == gtk_ui_manager_add_ui_from_file(ui_manager,
1700
1721
                                           get_ui_filename(), &error)) {
1701
 
    freelog(LOG_ERROR, "Gtk menus: %s", error->message);
 
1722
    log_error("Gtk menus: %s", error->message);
1702
1723
    g_error_free(error);
1703
1724
  }
1704
1725
 
1719
1740
  GtkAction *action = gtk_action_group_get_action(group, action_name);
1720
1741
 
1721
1742
  if (!action) {
1722
 
    freelog(LOG_ERROR, "Can't set active for non-existent "
1723
 
            "action \"%s\" in group \"%s\".",
1724
 
            action_name, gtk_action_group_get_name(group));
 
1743
    log_error("Can't set active for non-existent "
 
1744
              "action \"%s\" in group \"%s\".",
 
1745
              action_name, gtk_action_group_get_name(group));
1725
1746
    return;
1726
1747
  }
1727
1748
 
1728
1749
  if (!GTK_IS_TOGGLE_ACTION(action)) {
1729
 
    freelog(LOG_ERROR, "Can't set active for non-togglable "
1730
 
            "action \"%s\" in group \"%s\".",
1731
 
            action_name, gtk_action_group_get_name(group));
 
1750
    log_error("Can't set active for non-togglable "
 
1751
              "action \"%s\" in group \"%s\".",
 
1752
              action_name, gtk_action_group_get_name(group));
1732
1753
    return;
1733
1754
  }
1734
1755
 
1745
1766
  GtkAction *action = gtk_action_group_get_action(group, action_name);
1746
1767
 
1747
1768
  if (!action) {
1748
 
    freelog(LOG_ERROR, "Can't set active for non-existent "
1749
 
            "action \"%s\" in group \"%s\".",
1750
 
            action_name, gtk_action_group_get_name(group));
 
1769
    log_error("Can't set active for non-existent "
 
1770
              "action \"%s\" in group \"%s\".",
 
1771
              action_name, gtk_action_group_get_name(group));
1751
1772
    return;
1752
1773
  }
1753
1774
 
1765
1786
  GtkAction *action = gtk_action_group_get_action(group, action_name);
1766
1787
 
1767
1788
  if (!action) {
1768
 
    freelog(LOG_ERROR, "Can't set visible for non-existent "
1769
 
            "action \"%s\" in group \"%s\".",
1770
 
            action_name, gtk_action_group_get_name(group));
 
1789
    log_error("Can't set visible for non-existent "
 
1790
              "action \"%s\" in group \"%s\".",
 
1791
              action_name, gtk_action_group_get_name(group));
1771
1792
    return;
1772
1793
  }
1773
1794
 
1785
1806
  GtkAction *action = gtk_action_group_get_action(group, action_name);
1786
1807
 
1787
1808
  if (!action) {
1788
 
    freelog(LOG_ERROR, "Can't rename non-existent "
1789
 
            "action \"%s\" in group \"%s\".",
1790
 
            action_name, gtk_action_group_get_name(group));
 
1809
    log_error("Can't rename non-existent "
 
1810
              "action \"%s\" in group \"%s\".",
 
1811
              action_name, gtk_action_group_get_name(group));
1791
1812
    return;
1792
1813
  }
1793
1814
 
1857
1878
static const char *get_tile_change_menu_text(struct tile *ptile,
1858
1879
                                             enum unit_activity activity)
1859
1880
{
1860
 
  struct tile newtile = *ptile;
 
1881
  struct tile *newtile = tile_virtual_new(ptile);
 
1882
  const char *text;
1861
1883
 
1862
 
  tile_apply_activity(&newtile, activity);
1863
 
  return tile_get_info_text(&newtile, 0);
 
1884
  tile_apply_activity(newtile, activity);
 
1885
  text = tile_get_info_text(newtile, 0);
 
1886
  tile_virtual_destroy(newtile);
 
1887
  return text;
1864
1888
}
1865
1889
 
1866
1890
/****************************************************************
1867
1891
  Updates the menus.
1868
1892
*****************************************************************/
1869
 
static gboolean update_menus_callback(gpointer data)
 
1893
void real_menus_update(void)
1870
1894
{
1871
1895
  GtkActionGroup *safe_group;
1872
1896
  GtkActionGroup *edit_group;
1874
1898
  GtkActionGroup *playing_group;
1875
1899
  GtkActionGroup *player_group;
1876
1900
  struct unit_list *punits = NULL;
1877
 
  bool units_all_same_tile = TRUE;
 
1901
  bool units_all_same_tile = TRUE, units_all_same_type = TRUE;
1878
1902
  GtkMenu *menu;
1879
 
  char irrtext[128], mintext[128], transtext[128];
 
1903
  char acttext[128], irrtext[128], mintext[128], transtext[128];
1880
1904
  struct terrain *pterrain;
1881
1905
 
1882
 
  /* Remove GSource id. */
1883
 
  *((guint *) data) = 0;
1884
 
  if (!ui_manager) {
1885
 
    return FALSE;
 
1906
  if (NULL == ui_manager && !can_client_change_view()) {
 
1907
    return;
1886
1908
  }
1887
1909
 
1888
1910
  safe_group = get_safe_group();
1891
1913
  playing_group = get_playing_group();
1892
1914
  player_group = get_player_group();
1893
1915
 
1894
 
  menus_set_active(safe_group, "SAVE_OPTIONS_ON_EXIT", save_options_on_exit);
1895
 
  menus_set_sensitive(safe_group, "SERVER_OPTIONS", client.conn.established);
1896
 
 
1897
 
  menus_set_sensitive(safe_group, "GAME_SAVE_AS",
1898
 
                      can_client_access_hack()
1899
 
                      && C_S_RUNNING <= client_state());
1900
 
  menus_set_sensitive(safe_group, "GAME_SAVE",
1901
 
                      can_client_access_hack()
1902
 
                      && C_S_RUNNING <= client_state());
1903
 
  menus_set_sensitive(safe_group, "LEAVE",
1904
 
                      client.conn.established);
1905
 
 
1906
 
  if (!can_client_change_view()) {
1907
 
    gtk_action_group_set_sensitive(safe_group, FALSE);
1908
 
    gtk_action_group_set_sensitive(edit_group, FALSE);
1909
 
    gtk_action_group_set_sensitive(unit_group, FALSE);
1910
 
    gtk_action_group_set_sensitive(player_group, FALSE);
1911
 
    gtk_action_group_set_sensitive(playing_group, FALSE);
1912
 
    return FALSE;
1913
 
  }
1914
 
 
1915
1916
  if (get_num_units_in_focus() > 0) {
1916
1917
    const struct tile *ptile = NULL;
 
1918
    const struct unit_type *ptype = NULL;
1917
1919
    punits = get_units_in_focus();
1918
1920
    unit_list_iterate(punits, punit) {
1919
 
      if (ptile) {
 
1921
      fc_assert((ptile==NULL) == (ptype==NULL));
 
1922
      if (ptile || ptype) {
1920
1923
        if (punit->tile != ptile) {
1921
1924
          units_all_same_tile = FALSE;
1922
 
          break;
 
1925
        }
 
1926
        if (unit_type(punit) != ptype) {
 
1927
          units_all_same_type = FALSE;
1923
1928
        }
1924
1929
      } else {
1925
1930
        ptile = punit->tile;
 
1931
        ptype = unit_type(punit);
1926
1932
      }
1927
1933
    } unit_list_iterate_end;
1928
1934
  }
1929
1935
 
1930
 
  if ((menu = find_action_menu(playing_group, "MENU_GOVERNMENT"))) {
1931
 
    GList *list, *iter;
1932
 
    GtkWidget *item, *image;
1933
 
    struct sprite *gsprite;
1934
 
    char buf[256];
1935
 
 
1936
 
    /* Remove previous government entries. */
1937
 
    list = gtk_container_get_children(GTK_CONTAINER(menu));
1938
 
    for (iter = list; iter; iter = g_list_next(iter)) {
1939
 
      if (g_object_get_data(G_OBJECT(iter->data), "government") != NULL
1940
 
          || GTK_IS_SEPARATOR_MENU_ITEM(iter->data)) {
1941
 
        gtk_widget_destroy(GTK_WIDGET(iter->data));
1942
 
      }
1943
 
    }
1944
 
    g_list_free(list);
1945
 
 
1946
 
    /* Add new government entries. */
1947
 
    item = gtk_separator_menu_item_new();
1948
 
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1949
 
    gtk_widget_show(item);
1950
 
 
1951
 
    government_iterate(g) {
1952
 
      if (g != game.government_during_revolution) {
1953
 
        /* TRANS: %s is a government name */
1954
 
        my_snprintf(buf, sizeof(buf), _("%s..."),
1955
 
                    government_name_translation(g));
1956
 
        item = gtk_image_menu_item_new_with_label(buf);
1957
 
        g_object_set_data(G_OBJECT(item), "government", g);
1958
 
 
1959
 
        if ((gsprite = get_government_sprite(tileset, g))) {
1960
 
          image = gtk_image_new_from_pixbuf(sprite_get_pixbuf(gsprite));
1961
 
          gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
1962
 
          gtk_widget_show(image);
1963
 
        }
1964
 
 
1965
 
        g_signal_connect(item, "activate",
1966
 
                         G_CALLBACK(government_callback), g);
1967
 
 
1968
 
        if (!can_change_to_government(client.conn.playing, g)) {
1969
 
          gtk_widget_set_sensitive(item, FALSE);
1970
 
        }
1971
 
 
1972
 
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1973
 
        gtk_widget_show(item);
1974
 
      }
1975
 
    } government_iterate_end;
1976
 
  }
1977
 
 
1978
 
  if ((menu = find_action_menu(unit_group, "MENU_BUILD_BASE"))) {
1979
 
    GList *list, *iter;
1980
 
    GtkWidget *item;
1981
 
 
1982
 
    /* Remove previous base entries. */
1983
 
    list = gtk_container_get_children(GTK_CONTAINER(menu));
1984
 
    for (iter = list; iter; iter = g_list_next(iter)) {
1985
 
      gtk_widget_destroy(GTK_WIDGET(iter->data));
1986
 
    }
1987
 
    g_list_free(list);
1988
 
 
1989
 
    /* Add new base entries. */
1990
 
    base_type_iterate(p) {
1991
 
      if (p->buildable) {
1992
 
        item = gtk_menu_item_new_with_label(base_name_translation(p));
1993
 
 
1994
 
        g_signal_connect(item, "activate", G_CALLBACK(base_callback), p);
1995
 
 
1996
 
         if (punits) {
1997
 
           gtk_widget_set_sensitive(item, can_units_do_base(punits,
1998
 
                                                            base_number(p)));
1999
 
         }
2000
 
 
2001
 
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2002
 
        gtk_widget_show(item);
2003
 
      }
2004
 
    } base_type_iterate_end;
2005
 
  }
2006
 
 
2007
 
  gtk_action_group_set_sensitive(safe_group, TRUE);
2008
1936
  gtk_action_group_set_sensitive(edit_group,
2009
1937
                                 editor_is_active());
2010
 
  gtk_action_group_set_sensitive(player_group, client_has_player());
2011
1938
  gtk_action_group_set_sensitive(playing_group, can_client_issue_orders()
2012
1939
                                 && !editor_is_active());
2013
1940
  gtk_action_group_set_sensitive(unit_group, can_client_issue_orders()
2014
1941
                                 && !editor_is_active() && punits != NULL);
2015
1942
 
2016
 
  menus_set_sensitive(playing_group, "TAX_RATE",
2017
 
                      game.info.changable_tax
2018
 
                      && can_client_issue_orders());
2019
 
 
2020
1943
  menus_set_active(safe_group, "EDIT_MODE", game.info.is_edit_mode);
2021
1944
  menus_set_sensitive(safe_group, "EDIT_MODE",
2022
1945
                      can_conn_enable_editing(&client.conn));
2023
1946
  editgui_refresh();
2024
1947
 
2025
 
  menus_set_active(safe_group, "SHOW_CITY_OUTLINES", draw_city_outlines);
2026
 
  menus_set_active(safe_group, "SHOW_CITY_OUTPUT", draw_city_output);
2027
 
  menus_set_active(safe_group, "SHOW_MAP_GRID", draw_map_grid);
2028
 
  menus_set_active(safe_group, "SHOW_NATIONAL_BORDERS", draw_borders);
2029
 
  menus_set_sensitive(safe_group, "SHOW_NATIONAL_BORDERS",
2030
 
                      game.info.borders > 0);
2031
 
  menus_set_active(safe_group, "SHOW_CITY_FULL_BAR", draw_full_citybar);
2032
 
  menus_set_active(safe_group, "SHOW_CITY_NAMES", draw_city_names);
2033
 
  menus_set_active(safe_group, "SHOW_CITY_GROWTH", draw_city_growth);
2034
 
  menus_set_active(safe_group, "SHOW_CITY_PRODUCTIONS",
2035
 
                   draw_city_productions);
2036
 
  menus_set_active(safe_group, "SHOW_CITY_BUY_COST", draw_city_buycost);
2037
 
  menus_set_active(safe_group, "SHOW_CITY_TRADE_ROUTES",
2038
 
                   draw_city_trade_routes);
2039
 
  menus_set_active(safe_group, "SHOW_TERRAIN", draw_terrain);
2040
 
  menus_set_active(safe_group, "SHOW_COASTLINE", draw_coastline);
2041
 
  menus_set_active(safe_group, "SHOW_ROADS_RAILS", draw_roads_rails);
2042
 
  menus_set_active(safe_group, "SHOW_IRRIGATION", draw_irrigation);
2043
 
  menus_set_active(safe_group, "SHOW_MINES", draw_mines);
2044
 
  menus_set_active(safe_group, "SHOW_FORTRESS_AIRBASE",
2045
 
                   draw_fortress_airbase);
2046
 
  menus_set_active(safe_group, "SHOW_SPECIALS", draw_specials);
2047
 
  menus_set_active(safe_group, "SHOW_POLLUTION", draw_pollution);
2048
 
  menus_set_active(safe_group, "SHOW_CITIES", draw_cities);
2049
 
  menus_set_active(safe_group, "SHOW_UNITS", draw_units);
2050
 
  menus_set_active(safe_group, "SHOW_UNIT_SOLID_BG",
2051
 
                   solid_color_behind_units);
2052
 
  menus_set_active(safe_group, "SHOW_UNIT_SHIELDS", draw_unit_shields);
2053
 
  menus_set_active(safe_group, "SHOW_FOCUS_UNIT", draw_focus_unit);
2054
 
  menus_set_active(safe_group, "SHOW_FOG_OF_WAR", draw_fog_of_war);
2055
 
  if (tileset_use_hard_coded_fog(tileset)) {
2056
 
    menus_set_visible(safe_group, "SHOW_BETTER_FOG_OF_WAR", TRUE, TRUE);
2057
 
    menus_set_active(safe_group, "SHOW_BETTER_FOG_OF_WAR",
2058
 
                     gui_gtk2_better_fog);
2059
 
  } else {
2060
 
    menus_set_visible(safe_group, "SHOW_BETTER_FOG_OF_WAR", FALSE, FALSE);
2061
 
  }
2062
 
 
2063
 
  view_menu_update_sensitivity();
2064
 
 
2065
 
  menus_set_active(safe_group, "FULL_SCREEN", fullscreen_mode);
 
1948
  if (!can_client_issue_orders()) {
 
1949
    return;
 
1950
  }
 
1951
 
 
1952
  /* Set government sensitivity. */
 
1953
  if ((menu = find_action_menu(playing_group, "MENU_GOVERNMENT"))) {
 
1954
    GList *list, *iter;
 
1955
    struct government *pgov;
 
1956
 
 
1957
    list = gtk_container_get_children(GTK_CONTAINER(menu));
 
1958
    for (iter = list; NULL != iter; iter = g_list_next(iter)) {
 
1959
      pgov = g_object_get_data(G_OBJECT(iter->data), "government");
 
1960
      if (NULL != pgov) {
 
1961
        gtk_widget_set_sensitive(GTK_WIDGET(iter->data),
 
1962
                                 can_change_to_government(client_player(),
 
1963
                                                          pgov));
 
1964
      }
 
1965
    }
 
1966
    g_list_free(list);
 
1967
  }
 
1968
 
 
1969
  if (!punits) {
 
1970
    return;
 
1971
  }
2066
1972
 
2067
1973
  /* Remaining part of this function: Update Unit, Work, and Combat menus */
2068
1974
 
2069
 
  if (!can_client_issue_orders() || !punits) {
2070
 
    return FALSE;
 
1975
  /* Set base sensitivity. */
 
1976
  if ((menu = find_action_menu(unit_group, "MENU_BUILD_BASE"))) {
 
1977
    GList *list, *iter;
 
1978
    struct base_type *pbase;
 
1979
 
 
1980
    list = gtk_container_get_children(GTK_CONTAINER(menu));
 
1981
    for (iter = list; NULL != iter; iter = g_list_next(iter)) {
 
1982
      pbase = g_object_get_data(G_OBJECT(iter->data), "base");
 
1983
      if (NULL != pbase) {
 
1984
        gtk_widget_set_sensitive(GTK_WIDGET(iter->data),
 
1985
                                 can_units_do_base(punits,
 
1986
                                                   base_number(pbase)));
 
1987
      }
 
1988
    }
 
1989
    g_list_free(list);
2071
1990
  }
2072
1991
 
2073
1992
  /* Enable the button for adding to a city in all cases, so we
2074
1993
   * get an eventual error message from the server if we try. */
2075
1994
  menus_set_sensitive(unit_group, "BUILD_CITY",
2076
 
            (can_units_do(punits, can_unit_add_or_build_city)
 
1995
            (can_units_do(punits, unit_can_add_or_build_city)
2077
1996
             || can_units_do(punits, unit_can_help_build_wonder_here)));
2078
1997
  menus_set_sensitive(unit_group, "GO_BUILD_CITY",
2079
1998
                      units_have_flag(punits, F_CITIES, TRUE));
2108
2027
  menus_set_sensitive(unit_group, "UNIT_DISBAND",
2109
2028
                      units_have_flag(punits, F_UNDISBANDABLE, FALSE));
2110
2029
  menus_set_sensitive(unit_group, "UNIT_UPGRADE",
2111
 
                      TRUE /* FIXME: what check should we do? */);
 
2030
                      units_can_upgrade(punits));
 
2031
  /* "UNIT_CONVERT" dealt with below */
2112
2032
  menus_set_sensitive(unit_group, "UNIT_HOMECITY",
2113
2033
                      can_units_do(punits, can_unit_change_homecity));
2114
2034
  menus_set_sensitive(unit_group, "UNIT_UNLOAD_TRANSPORTER",
2151
2071
    } unit_list_iterate_end;
2152
2072
    
2153
2073
    if (city_on_tile && units_have_flag(punits, F_ADD_TO_CITY, TRUE)) {
2154
 
      menus_rename(unit_group, "BUILD_CITY", _("Add to City (_B)"));
 
2074
      menus_rename(unit_group, "BUILD_CITY", _("Add to City"));
2155
2075
    } else {
2156
2076
      /* refresh default order */
2157
2077
      menus_rename(unit_group, "BUILD_CITY", _("_Build City"));
2181
2101
    menus_rename(unit_group, "BUILD_ROAD", _("Build _Road"));
2182
2102
  }
2183
2103
 
 
2104
  if (units_all_same_type) {
 
2105
    struct unit *punit = unit_list_get(punits, 0);
 
2106
    struct unit_type *to_unittype =
 
2107
      can_upgrade_unittype(client_player(), unit_type(punit));
 
2108
    if (to_unittype) {
 
2109
      /* TRANS: %s is a unit type. */
 
2110
      fc_snprintf(acttext, sizeof(acttext), _("Upgr_ade to %s"),
 
2111
                  utype_name_translation(
 
2112
                    can_upgrade_unittype(client_player(), unit_type(punit))));
 
2113
    } else {
 
2114
      acttext[0] = '\0';
 
2115
    }
 
2116
  } else {
 
2117
    acttext[0] = '\0';
 
2118
  }
 
2119
  if ('\0' != acttext[0]) {
 
2120
    menus_rename(unit_group, "UNIT_UPGRADE", acttext);
 
2121
  } else {
 
2122
    menus_rename(unit_group, "UNIT_UPGRADE", _("Upgr_ade"));
 
2123
  }
 
2124
 
 
2125
  if (units_can_convert(punits)) {
 
2126
    menus_set_sensitive(unit_group, "UNIT_CONVERT", TRUE);
 
2127
    if (units_all_same_type) {
 
2128
      struct unit *punit = unit_list_get(punits, 0);
 
2129
      /* TRANS: %s is a unit type. */
 
2130
      fc_snprintf(acttext, sizeof(acttext), _("C_onvert to %s"),
 
2131
                  utype_name_translation(unit_type(punit)->converted_to));
 
2132
    } else {
 
2133
      acttext[0] = '\0';
 
2134
    }
 
2135
  } else {
 
2136
    menus_set_sensitive(unit_group, "UNIT_CONVERT", FALSE);
 
2137
    acttext[0] = '\0';
 
2138
  }
 
2139
  if ('\0' != acttext[0]) {
 
2140
    menus_rename(unit_group, "UNIT_CONVERT", acttext);
 
2141
  } else {
 
2142
    menus_rename(unit_group, "UNIT_CONVERT", _("C_onvert"));
 
2143
  }
 
2144
 
2184
2145
  if (units_all_same_tile) {
2185
2146
    struct unit *punit = unit_list_get(punits, 0);
2186
2147
 
2187
2148
    pterrain = tile_terrain(punit->tile);
2188
2149
    if (pterrain->irrigation_result != T_NONE
2189
2150
        && pterrain->irrigation_result != pterrain) {
2190
 
      my_snprintf(irrtext, sizeof(irrtext), _("Change to %s (_I)"),
 
2151
      fc_snprintf(irrtext, sizeof(irrtext), _("Change to %s"),
2191
2152
                  get_tile_change_menu_text(punit->tile,
2192
2153
                                            ACTIVITY_IRRIGATE));
2193
2154
    } else if (tile_has_special(punit->tile, S_IRRIGATION)
2200
2161
 
2201
2162
    if (pterrain->mining_result != T_NONE
2202
2163
        && pterrain->mining_result != pterrain) {
2203
 
      my_snprintf(mintext, sizeof(mintext), _("Change to %s (_M)"),
 
2164
      fc_snprintf(mintext, sizeof(mintext), _("Change to %s"),
2204
2165
                  get_tile_change_menu_text(punit->tile, ACTIVITY_MINE));
2205
2166
    } else {
2206
2167
      sz_strlcpy(mintext, _("Build _Mine"));
2208
2169
 
2209
2170
    if (pterrain->transform_result != T_NONE
2210
2171
        && pterrain->transform_result != pterrain) {
2211
 
      my_snprintf(transtext, sizeof(transtext), _("Transf_orm to %s"),
 
2172
      fc_snprintf(transtext, sizeof(transtext), _("Transf_orm to %s"),
2212
2173
                  get_tile_change_menu_text(punit->tile,
2213
2174
                                            ACTIVITY_TRANSFORM));
2214
2175
    } else {
2227
2188
  if (can_units_do_activity(punits, ACTIVITY_FORTIFYING)) {
2228
2189
    menus_rename(unit_group, "BUILD_FORTRESS", _("_Fortify Unit"));
2229
2190
  } else {
2230
 
    menus_rename(unit_group, "BUILD_FORTRESS", _("Build _Fortress"));
 
2191
    menus_rename(unit_group, "BUILD_FORTRESS", _("Build Type A Base"));
2231
2192
  }
2232
2193
 
2233
2194
  if (units_have_flag(punits, F_PARATROOPERS, TRUE)) {
2235
2196
  } else {
2236
2197
    menus_rename(unit_group, "CLEAN_POLLUTION", _("Clean _Pollution"));
2237
2198
  }
2238
 
 
2239
 
  return FALSE;
2240
2199
}
2241
2200
 
2242
 
/****************************************************************
2243
 
  Updates the menus.
2244
 
*****************************************************************/
2245
 
void update_menus(void)
 
2201
/**************************************************************************
 
2202
  Initialize menus (sensitivity, name, etc.) based on the
 
2203
  current state and current ruleset, etc.  Call menus_update().
 
2204
**************************************************************************/
 
2205
void real_menus_init(void)
2246
2206
{
2247
 
  static guint callback_id = 0;
2248
 
 
2249
 
  if (NULL != ui_manager && 0 == callback_id) {
2250
 
    callback_id = g_idle_add(update_menus_callback, &callback_id);
2251
 
  }
 
2207
  GtkActionGroup *safe_group;
 
2208
  GtkActionGroup *edit_group;
 
2209
  GtkActionGroup *unit_group;
 
2210
  GtkActionGroup *playing_group;
 
2211
  GtkActionGroup *player_group;
 
2212
  GtkMenu *menu;
 
2213
 
 
2214
  if (NULL == ui_manager) {
 
2215
    return;
 
2216
  }
 
2217
 
 
2218
  safe_group = get_safe_group();
 
2219
  edit_group = get_edit_group();
 
2220
  unit_group = get_unit_group();
 
2221
  playing_group = get_playing_group();
 
2222
  player_group = get_player_group();
 
2223
 
 
2224
  menus_set_sensitive(safe_group, "GAME_SAVE_AS",
 
2225
                      can_client_access_hack()
 
2226
                      && C_S_RUNNING <= client_state());
 
2227
  menus_set_sensitive(safe_group, "GAME_SAVE",
 
2228
                      can_client_access_hack()
 
2229
                      && C_S_RUNNING <= client_state());
 
2230
 
 
2231
  menus_set_active(safe_group, "SAVE_OPTIONS_ON_EXIT", save_options_on_exit);
 
2232
  menus_set_sensitive(safe_group, "SERVER_OPTIONS", client.conn.established);
 
2233
 
 
2234
  menus_set_sensitive(safe_group, "LEAVE",
 
2235
                      client.conn.established);
 
2236
 
 
2237
  if (!can_client_change_view()) {
 
2238
    gtk_action_group_set_sensitive(safe_group, FALSE);
 
2239
    gtk_action_group_set_sensitive(edit_group, FALSE);
 
2240
    gtk_action_group_set_sensitive(unit_group, FALSE);
 
2241
    gtk_action_group_set_sensitive(player_group, FALSE);
 
2242
    gtk_action_group_set_sensitive(playing_group, FALSE);
 
2243
    return;
 
2244
  }
 
2245
 
 
2246
  if ((menu = find_action_menu(playing_group, "MENU_GOVERNMENT"))) {
 
2247
    GList *list, *iter;
 
2248
    GtkWidget *item, *image;
 
2249
    struct sprite *gsprite;
 
2250
    char buf[256];
 
2251
 
 
2252
    /* Remove previous government entries. */
 
2253
    list = gtk_container_get_children(GTK_CONTAINER(menu));
 
2254
    for (iter = list; NULL != iter; iter = g_list_next(iter)) {
 
2255
      if (g_object_get_data(G_OBJECT(iter->data), "government") != NULL
 
2256
          || GTK_IS_SEPARATOR_MENU_ITEM(iter->data)) {
 
2257
        gtk_widget_destroy(GTK_WIDGET(iter->data));
 
2258
      }
 
2259
    }
 
2260
    g_list_free(list);
 
2261
 
 
2262
    /* Add new government entries. */
 
2263
    item = gtk_separator_menu_item_new();
 
2264
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
2265
    gtk_widget_show(item);
 
2266
 
 
2267
    governments_iterate(g) {
 
2268
      if (g != game.government_during_revolution) {
 
2269
        /* TRANS: %s is a government name */
 
2270
        fc_snprintf(buf, sizeof(buf), _("%s..."),
 
2271
                    government_name_translation(g));
 
2272
        item = gtk_image_menu_item_new_with_label(buf);
 
2273
        g_object_set_data(G_OBJECT(item), "government", g);
 
2274
 
 
2275
        if ((gsprite = get_government_sprite(tileset, g))) {
 
2276
          image = gtk_image_new_from_pixbuf(sprite_get_pixbuf(gsprite));
 
2277
          gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
 
2278
          gtk_widget_show(image);
 
2279
        }
 
2280
 
 
2281
        g_signal_connect(item, "activate",
 
2282
                         G_CALLBACK(government_callback), g);
 
2283
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
2284
        gtk_widget_show(item);
 
2285
      }
 
2286
    } governments_iterate_end;
 
2287
  }
 
2288
 
 
2289
  if ((menu = find_action_menu(unit_group, "MENU_BUILD_BASE"))) {
 
2290
    GList *list, *iter;
 
2291
    GtkWidget *item;
 
2292
 
 
2293
    /* Remove previous base entries. */
 
2294
    list = gtk_container_get_children(GTK_CONTAINER(menu));
 
2295
    for (iter = list; NULL != iter; iter = g_list_next(iter)) {
 
2296
      gtk_widget_destroy(GTK_WIDGET(iter->data));
 
2297
    }
 
2298
    g_list_free(list);
 
2299
 
 
2300
    /* Add new base entries. */
 
2301
    base_type_iterate(p) {
 
2302
      if (p->buildable) {
 
2303
        item = gtk_menu_item_new_with_label(base_name_translation(p));
 
2304
        g_object_set_data(G_OBJECT(item), "base", p);
 
2305
        g_signal_connect(item, "activate", G_CALLBACK(base_callback), p);
 
2306
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
2307
        gtk_widget_show(item);
 
2308
      }
 
2309
    } base_type_iterate_end;
 
2310
  }
 
2311
 
 
2312
  gtk_action_group_set_sensitive(safe_group, TRUE);
 
2313
  gtk_action_group_set_sensitive(player_group, client_has_player());
 
2314
 
 
2315
  menus_set_sensitive(playing_group, "TAX_RATE",
 
2316
                      game.info.changable_tax
 
2317
                      && can_client_issue_orders());
 
2318
 
 
2319
  menus_set_active(safe_group, "SHOW_CITY_OUTLINES", draw_city_outlines);
 
2320
  menus_set_active(safe_group, "SHOW_CITY_OUTPUT", draw_city_output);
 
2321
  menus_set_active(safe_group, "SHOW_MAP_GRID", draw_map_grid);
 
2322
  menus_set_active(safe_group, "SHOW_NATIONAL_BORDERS", draw_borders);
 
2323
  menus_set_sensitive(safe_group, "SHOW_NATIONAL_BORDERS",
 
2324
                      BORDERS_DISABLED != game.info.borders);
 
2325
  menus_set_active(safe_group, "SHOW_CITY_FULL_BAR", draw_full_citybar);
 
2326
  menus_set_active(safe_group, "SHOW_CITY_NAMES", draw_city_names);
 
2327
  menus_set_active(safe_group, "SHOW_CITY_GROWTH", draw_city_growth);
 
2328
  menus_set_active(safe_group, "SHOW_CITY_PRODUCTIONS",
 
2329
                   draw_city_productions);
 
2330
  menus_set_active(safe_group, "SHOW_CITY_BUY_COST", draw_city_buycost);
 
2331
  menus_set_active(safe_group, "SHOW_CITY_TRADE_ROUTES",
 
2332
                   draw_city_trade_routes);
 
2333
  menus_set_active(safe_group, "SHOW_TERRAIN", draw_terrain);
 
2334
  menus_set_active(safe_group, "SHOW_COASTLINE", draw_coastline);
 
2335
  menus_set_active(safe_group, "SHOW_ROADS_RAILS", draw_roads_rails);
 
2336
  menus_set_active(safe_group, "SHOW_IRRIGATION", draw_irrigation);
 
2337
  menus_set_active(safe_group, "SHOW_MINES", draw_mines);
 
2338
  menus_set_active(safe_group, "SHOW_FORTRESS_AIRBASE",
 
2339
                   draw_fortress_airbase);
 
2340
  menus_set_active(safe_group, "SHOW_SPECIALS", draw_specials);
 
2341
  menus_set_active(safe_group, "SHOW_POLLUTION", draw_pollution);
 
2342
  menus_set_active(safe_group, "SHOW_CITIES", draw_cities);
 
2343
  menus_set_active(safe_group, "SHOW_UNITS", draw_units);
 
2344
  menus_set_active(safe_group, "SHOW_UNIT_SOLID_BG",
 
2345
                   solid_color_behind_units);
 
2346
  menus_set_active(safe_group, "SHOW_UNIT_SHIELDS", draw_unit_shields);
 
2347
  menus_set_active(safe_group, "SHOW_FOCUS_UNIT", draw_focus_unit);
 
2348
  menus_set_active(safe_group, "SHOW_FOG_OF_WAR", draw_fog_of_war);
 
2349
  if (tileset_use_hard_coded_fog(tileset)) {
 
2350
    menus_set_visible(safe_group, "SHOW_BETTER_FOG_OF_WAR", TRUE, TRUE);
 
2351
    menus_set_active(safe_group, "SHOW_BETTER_FOG_OF_WAR",
 
2352
                     gui_gtk2_better_fog);
 
2353
  } else {
 
2354
    menus_set_visible(safe_group, "SHOW_BETTER_FOG_OF_WAR", FALSE, FALSE);
 
2355
  }
 
2356
 
 
2357
  view_menu_update_sensitivity();
 
2358
 
 
2359
  menus_set_active(safe_group, "FULL_SCREEN", fullscreen_mode);
2252
2360
}