Split "Establish Embassy".
[freeciv.git] / client / gui-qt / menu.cpp
blob3d0fc61e13de28fabfd4c5b7b7d128b3a2fdc9a1
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 // Qt
19 #include <QApplication>
20 #include <QFileDialog>
21 #include <QMainWindow>
22 #include <QMessageBox>
23 #include <QScrollArea>
24 #include <QSignalMapper>
25 #include <QStandardPaths>
26 #include <QVBoxLayout>
28 // utility
29 #include "string_vector.h"
31 // common
32 #include "game.h"
33 #include "government.h"
34 #include "goto.h"
35 #include "name_translation.h"
36 #include "road.h"
37 #include "unit.h"
39 // client
40 #include "connectdlg_common.h"
41 #include "control.h"
42 #include "helpdata.h"
44 // gui-qt
45 #include "fc_client.h"
46 #include "chatline.h"
47 #include "cityrep.h"
48 #include "dialogs.h"
49 #include "gotodlg.h"
50 #include "gui_main.h"
51 #include "hudwidget.h"
52 #include "mapctrl.h"
53 #include "messagedlg.h"
54 #include "plrdlg.h"
55 #include "ratesdlg.h"
56 #include "repodlgs.h"
57 #include "shortcuts.h"
58 #include "spaceshipdlg.h"
59 #include "sprite.h"
61 #include "menu.h"
63 extern QApplication *qapp;
65 static bool tradecity_rand(const trade_city *t1, const trade_city *t2);
66 static void enable_interface(bool enable);
67 extern int last_center_enemy;
68 extern int last_center_capital;
69 extern int last_center_player_city;
70 extern int last_center_enemy_city;
71 /**************************************************************************
72 New turn callback
73 **************************************************************************/
74 void qt_start_turn()
76 gui()->rallies.run();
77 real_menus_update();
78 show_new_turn_info();
79 last_center_enemy = 0;
80 last_center_capital = 0;
81 last_center_player_city = 0;
82 last_center_enemy_city = 0;
85 /**************************************************************************
86 Sends new built units to target tile
87 **************************************************************************/
88 void qfc_rally_list::run()
90 qfc_rally *rally;
91 struct unit_list *units;
92 struct unit *last_unit;;
93 int max;
95 if (rally_list.isEmpty()) {
96 return;
99 foreach (rally, rally_list) {
100 max = 0;
101 last_unit = nullptr;
103 if (rally->pcity->turn_last_built == game.info.turn - 1) {
104 units = rally->pcity->units_supported;
106 unit_list_iterate(units, punit) {
107 if (punit->id > max) {
108 last_unit = punit;
109 max = punit->id;
111 } unit_list_iterate_end;
113 if (last_unit && rally->pcity->production.kind == VUT_UTYPE) {
114 send_goto_tile(last_unit, rally->ptile);
120 /**************************************************************************
121 Adds rally point
122 **************************************************************************/
123 void qfc_rally_list::add(qfc_rally* rally)
125 rally_list.append(rally);
128 /**************************************************************************
129 Clears rally point. Returns false if rally was not set for that city.
130 **************************************************************************/
131 bool qfc_rally_list::clear(city* rcity)
133 qfc_rally *rally;
135 foreach (rally, rally_list) {
136 if (rally->pcity == rcity) {
137 rally_list.removeAll(rally);
138 return true;
142 return false;
146 /**************************************************************************
147 Constructor for trade city used to trade calculation
148 **************************************************************************/
149 trade_city::trade_city(struct city *pcity)
151 city = pcity;
152 tile = nullptr;
153 trade_num = 0;
154 poss_trade_num = 0;
158 /**************************************************************************
159 Constructor for trade calculator
160 **************************************************************************/
161 trade_generator::trade_generator()
163 hover_city = false;
166 /**************************************************************************
167 Adds all cities to trade generator
168 **************************************************************************/
169 void trade_generator::add_all_cities()
171 int i, s;
172 struct city *pcity;
173 clear_trade_planing();
174 s = city_list_size(client.conn.playing->cities);
175 if (s == 0) {
176 return;
178 for (i = 0; i < s; i++) {
179 pcity = city_list_get(client.conn.playing->cities, i);
180 add_city(pcity);
184 /**************************************************************************
185 Clears genrated routes, virtual cities, cities
186 **************************************************************************/
187 void trade_generator::clear_trade_planing()
189 struct city *pcity;
190 trade_city *tc;
191 foreach(pcity, virtual_cities) {
192 destroy_city_virtual(pcity);
194 virtual_cities.clear();
195 foreach(tc, cities) {
196 delete tc;
198 cities.clear();
199 lines.clear();
200 gui()->mapview_wdg->repaint();
204 /**************************************************************************
205 Adds single city to trade generator
206 **************************************************************************/
207 void trade_generator::add_city(struct city *pcity)
209 trade_city *tc = new trade_city(pcity);
210 cities.append(tc);
211 gui()->infotab->chtwdg->append(QString(_("Adding city %1 to trade planning"))
212 .arg(tc->city->name));
215 /**************************************************************************
216 Adds/removes tile to trade generator
217 **************************************************************************/
218 void trade_generator::add_tile(struct tile *ptile)
220 struct city *pcity;
221 trade_city *tc;
223 pcity = tile_city(ptile);
225 foreach (tc, cities) {
226 if (pcity != nullptr) {
227 if (tc->city == pcity) {
228 remove_city(pcity);
229 return;
232 if (tc->city->tile == ptile) {
233 remove_virtual_city(ptile);
234 return;
238 if (pcity != nullptr) {
239 add_city(pcity);
240 return;
243 pcity = create_city_virtual(client_player(), ptile, "Virtual");
244 add_city(pcity);
245 virtual_cities.append(pcity);
248 /**************************************************************************
249 Removes single city from trade generator
250 **************************************************************************/
251 void trade_generator::remove_city(struct city* pcity)
253 trade_city *tc;
255 foreach (tc, cities) {
256 if (tc->city->tile == pcity->tile) {
257 cities.removeAll(tc);
258 gui()->infotab->chtwdg->append(
259 QString(_("Removing city %1 from trade planning"))
260 .arg(tc->city->name));
261 return;
266 /**************************************************************************
267 Removes virtual city from trade generator
268 **************************************************************************/
269 void trade_generator::remove_virtual_city(tile *ptile)
271 struct city *c;
272 trade_city *tc;
274 foreach (c, virtual_cities) {
275 if (c->tile == ptile) {
276 virtual_cities.removeAll(c);
277 gui()->infotab->chtwdg->append(
278 QString(_("Removing city %1 from trade planning")).arg(c->name));
282 foreach (tc, cities) {
283 if (tc->city->tile == ptile) {
284 cities.removeAll(tc);
285 return;
291 /**************************************************************************
292 Finds trade routes to establish
293 **************************************************************************/
294 void trade_generator::calculate()
296 trade_city *tc;
297 trade_city *ttc;
298 int i;
299 bool tdone;
301 for (i = 0; i < 100; i++) {
302 tdone = true;
303 qSort(cities.begin(), cities.end(), tradecity_rand);
304 lines.clear();
305 foreach (tc, cities) {
306 tc->pos_cities.clear();
307 tc->new_tr_cities.clear();
308 tc->curr_tr_cities.clear();
310 foreach (tc, cities) {
311 tc->trade_num = city_num_trade_routes(tc->city);
312 tc->poss_trade_num = 0;
313 tc->pos_cities.clear();
314 tc->new_tr_cities.clear();
315 tc->curr_tr_cities.clear();
316 tc->done = false;
317 foreach (ttc, cities) {
318 if (have_cities_trade_route(tc->city, ttc->city) == false
319 && can_establish_trade_route(tc->city, ttc->city)) {
320 tc->poss_trade_num++;
321 tc->pos_cities.append(ttc->city);
323 tc->over_max = tc->trade_num + tc->poss_trade_num
324 - max_trade_routes(tc->city);
328 find_certain_routes();
329 discard();
330 find_certain_routes();
332 foreach (tc, cities) {
333 if (!tc->done) {
334 tdone = false;
337 if (tdone) {
338 break;
341 foreach (tc, cities) {
342 if (!tc->done) {
343 char text[1024];
344 fc_snprintf(text, sizeof(text),
345 PL_("City %s - 1 free trade route.",
346 "City %s - %d free trade routes.",
347 max_trade_routes(tc->city) - tc->trade_num),
348 city_link(tc->city),
349 max_trade_routes(tc->city) - tc->trade_num);
350 output_window_append(ftc_client, text);
354 gui()->mapview_wdg->repaint();
357 /**************************************************************************
358 Finds highest number of trade routes over maximum for all cities,
359 skips given city
360 **************************************************************************/
361 int trade_generator::find_over_max(struct city *pcity = nullptr)
363 trade_city *tc;
364 int max = 0;
366 foreach (tc, cities) {
367 if (pcity != tc->city) {
368 max = qMax(max, tc->over_max);
371 return max;
374 /**************************************************************************
375 Finds city with highest trade routes possible
376 **************************************************************************/
377 trade_city* trade_generator::find_most_free()
379 trade_city *tc;
380 trade_city *rc = nullptr;
381 int max = 0;
383 foreach (tc, cities) {
384 if (max < tc->over_max) {
385 max = tc->over_max;
386 rc = tc;
389 return rc;
392 /**************************************************************************
393 Drops all possible trade routes.
394 **************************************************************************/
395 void trade_generator::discard()
397 trade_city *tc;
398 int j = 5;
400 for (int i = j; i > -j; i--) {
401 while ((tc = find_most_free())) {
402 if (discard_one(tc) == false) {
403 if (discard_any(tc, i) == false) {
404 break;
411 /**************************************************************************
412 Drops trade routes between given cities
413 **************************************************************************/
414 void trade_generator::discard_trade(trade_city* tc, trade_city* ttc)
416 tc->pos_cities.removeOne(ttc->city);
417 ttc->pos_cities.removeOne(tc->city);
418 tc->poss_trade_num--;
419 ttc->poss_trade_num--;
420 tc->over_max--;
421 ttc->over_max--;
422 check_if_done(tc, ttc);
425 /**************************************************************************
426 Drops one trade route for given city if possible
427 **************************************************************************/
428 bool trade_generator::discard_one(trade_city *tc)
430 int best = 0;
431 int current_candidate = 0;
432 int best_id;
433 trade_city *ttc;
435 for (int i = cities.size() - 1 ; i >= 0; i--) {
436 ttc = cities.at(i);
437 current_candidate = ttc->over_max;
438 if (current_candidate > best) {
439 best_id = i;
442 if (best == 0) {
443 return false;
446 ttc = cities.at(best_id);
447 discard_trade(tc, ttc);
448 return true;
452 /**************************************************************************
453 Drops all trade routes for given city
454 **************************************************************************/
455 bool trade_generator::discard_any(trade_city* tc, int freeroutes)
457 trade_city *ttc;
459 for (int i = cities.size() - 1 ; i >= 0; i--) {
460 ttc = cities.at(i);
461 if (tc->pos_cities.contains(ttc->city)
462 && ttc->pos_cities.contains(tc->city)
463 && ttc->over_max > freeroutes) {
464 discard_trade(tc, ttc);
465 return true;
468 return false;
471 /**************************************************************************
472 Helper function ato randomize list
473 **************************************************************************/
474 bool tradecity_rand(const trade_city *t1, const trade_city *t2)
476 return (qrand() % 2);
479 /**************************************************************************
480 Adds routes for cities which can only have maximum possible trade routes
481 **************************************************************************/
482 void trade_generator::find_certain_routes()
484 trade_city *tc;
485 trade_city *ttc;
487 foreach (tc, cities) {
488 if (tc->done || tc->over_max > 0) {
489 continue;
491 foreach (ttc, cities) {
492 if (ttc->done || ttc->over_max > 0
493 || tc == ttc || tc->done || tc->over_max > 0) {
494 continue;
496 if (tc->pos_cities.contains(ttc->city)
497 && ttc->pos_cities.contains(tc->city)) {
498 struct qtiles gilles;
499 tc->pos_cities.removeOne(ttc->city);
500 ttc->pos_cities.removeOne(tc->city);
501 tc->poss_trade_num--;
502 ttc->poss_trade_num--;
503 tc->new_tr_cities.append(ttc->city);
504 ttc->new_tr_cities.append(ttc->city);
505 tc->trade_num++;
506 ttc->trade_num++;
507 tc->over_max--;
508 ttc->over_max--;
509 check_if_done(tc, ttc);
510 gilles.t1 = tc->city->tile;
511 gilles.t2 = ttc->city->tile;
512 gilles.autocaravan = nullptr;
513 lines.append(gilles);
519 /**************************************************************************
520 Marks cities with full trade routes to finish searching
521 **************************************************************************/
522 void trade_generator::check_if_done(trade_city* tc1, trade_city* tc2)
524 if (tc1->trade_num == max_trade_routes(tc1->city)) {
525 tc1->done = true;
527 if (tc2->trade_num == max_trade_routes(tc2->city)) {
528 tc2->done = true;
532 /**************************************************************************
533 Constructor for units used in delayed orders
534 **************************************************************************/
535 qfc_units_list::qfc_units_list()
539 /**************************************************************************
540 Adds givent unit to list
541 **************************************************************************/
542 void qfc_units_list::add(qfc_delayed_unit_item* fui)
544 unit_list.append(fui);
547 /**************************************************************************
548 Clears list of units
549 **************************************************************************/
550 void qfc_units_list::clear()
552 unit_list.clear();
555 /**************************************************************************
556 Initialize menus (sensitivity, name, etc.) based on the
557 current state and current ruleset, etc. Call menus_update().
558 **************************************************************************/
559 void real_menus_init(void)
561 gui()->menu_bar->clear();
562 gui()->menu_bar->setup_menus();
564 gov_menu::create_all();
566 /* A new ruleset may have been loaded. */
567 go_act_menu::reset_all();
570 /**************************************************************************
571 Update all of the menus (sensitivity, name, etc.) based on the
572 current state.
573 **************************************************************************/
574 void real_menus_update(void)
576 if (C_S_RUNNING <= client_state()) {
577 gui()->menuBar()->setVisible(true);
578 if (is_waiting_turn_change() == false) {
579 gui()->menu_bar->menus_sensitive();
580 gui()->menu_bar->update_airlift_menu();
581 gov_menu::update_all();
582 go_act_menu::update_all();
583 gui()->unitinfo_wdg->update_actions(nullptr);
585 } else {
586 gui()->menuBar()->setVisible(false);
590 /****************************************************************************
591 Return the text for the tile, changed by the activity.
592 Should only be called for irrigation, mining, or transformation, and
593 only when the activity changes the base terrain type.
594 ****************************************************************************/
595 static const char *get_tile_change_menu_text(struct tile *ptile,
596 enum unit_activity activity)
598 struct tile *newtile = tile_virtual_new(ptile);
599 const char *text;
601 tile_apply_activity(newtile, activity, NULL);
602 text = tile_get_info_text(newtile, FALSE, 0);
603 tile_virtual_destroy(newtile);
604 return text;
608 /****************************************************************************
609 Creates a new government menu.
610 ****************************************************************************/
611 gov_menu::gov_menu(QWidget* parent) :
612 QMenu(_("Government"), parent),
613 gov_mapper(new QSignalMapper())
615 // Register ourselves to get updates for free.
616 instances << this;
617 setAttribute(Qt::WA_TranslucentBackground);
620 /****************************************************************************
621 Destructor.
622 ****************************************************************************/
623 gov_menu::~gov_menu()
625 delete gov_mapper;
626 qDeleteAll(actions);
627 instances.remove(this);
630 /****************************************************************************
631 Creates the menu once the government list is known.
632 ****************************************************************************/
633 void gov_menu::create() {
634 QAction *action;
635 struct government *gov, *revol_gov;
636 int gov_count, i;
638 // Clear any content
639 foreach(action, QWidget::actions()) {
640 removeAction(action);
641 action->deleteLater();
643 actions.clear();
644 gov_mapper->deleteLater();
645 gov_mapper = new QSignalMapper();
647 gov_count = government_count();
648 actions.reserve(gov_count + 1);
649 action = addAction(_("Revolution..."));
650 connect(action, &QAction::triggered, this, &gov_menu::revolution);
651 actions.append(action);
653 addSeparator();
655 // Add an action for each government. There is no icon yet.
656 revol_gov = game.government_during_revolution;
657 for (i = 0; i < gov_count; ++i) {
658 gov = government_by_number(i);
659 if (gov != revol_gov) { // Skip revolution goverment
660 action = addAction(government_name_translation(gov));
661 // We need to keep track of the gov <-> action mapping to be able to
662 // set enabled/disabled depending on available govs.
663 actions.append(action);
664 connect(action, SIGNAL(triggered()), gov_mapper, SLOT(map()));
665 gov_mapper->setMapping(action, i);
668 connect(gov_mapper, SIGNAL(mapped(int)), this, SLOT(change_gov(int)));
671 /****************************************************************************
672 Updates the menu to take gov availability into account.
673 ****************************************************************************/
674 void gov_menu::update()
676 struct government *gov, *revol_gov;
677 struct sprite *sprite;
678 int gov_count, i, j;
680 gov_count = government_count();
681 revol_gov = game.government_during_revolution;
682 for (i = 0, j = 0; i < gov_count; ++i) {
683 gov = government_by_number(i);
684 if (gov != revol_gov) { // Skip revolution goverment
685 sprite = get_government_sprite(tileset, gov);
686 if (sprite != NULL) {
687 actions[j + 1]->setIcon(QIcon(*(sprite->pm)));
689 actions[j + 1]->setEnabled(
690 can_change_to_government(client.conn.playing, gov));
691 ++j;
692 } else {
693 actions[0]->setEnabled(!client_is_observer());
698 /****************************************************************************
699 Shows the dialog asking for confirmation before starting a revolution.
700 ****************************************************************************/
701 void gov_menu::revolution()
703 popup_revolution_dialog();
706 /****************************************************************************
707 Shows the dialog asking for confirmation before starting a revolution.
708 ****************************************************************************/
709 void gov_menu::change_gov(int target_gov)
711 popup_revolution_dialog(government_by_number(target_gov));
714 /****************************************************************************
715 Keeps track of all gov_menu instances.
716 ****************************************************************************/
717 QSet<gov_menu *> gov_menu::instances = QSet<gov_menu *>();
719 /****************************************************************************
720 * Updates all gov_menu instances.
721 ****************************************************************************/
722 void gov_menu::create_all()
724 foreach (gov_menu *m, instances) {
725 m->create();
729 /****************************************************************************
730 Updates all gov_menu instances.
731 ****************************************************************************/
732 void gov_menu::update_all()
734 foreach (gov_menu *m, instances) {
735 m->update();
739 /**************************************************************************
740 Instantiate a new goto and act sub menu.
741 **************************************************************************/
742 go_act_menu::go_act_menu(QWidget* parent)
743 : QMenu(_("Go to and..."), parent)
745 go_act_mapper = new QSignalMapper(this);
747 /* Will need auto updates etc. */
748 instances << this;
751 /**************************************************************************
752 Destructor.
753 **************************************************************************/
754 go_act_menu::~go_act_menu()
756 /* Updates are no longer needed. */
757 instances.remove(this);
760 /**************************************************************************
761 Reset the goto and act menu so it will be recreated.
762 **************************************************************************/
763 void go_act_menu::reset()
765 QAction *action;
767 /* Clear out each existing menu item. */
768 foreach(action, QWidget::actions()) {
769 removeAction(action);
770 action->deleteLater();
773 /* Clear menu item to action ID mapping. */
774 items.clear();
776 /* Reset the Qt signal mapper */
777 go_act_mapper->deleteLater();
778 go_act_mapper = new QSignalMapper(this);
781 /**************************************************************************
782 Fill the new goto and act sub menu with menu items.
783 **************************************************************************/
784 void go_act_menu::create()
786 QAction *item;
787 int tgt_kind_group;
789 /* Group goto and perform action menu items by target kind. */
790 for (tgt_kind_group = 0; tgt_kind_group < ATK_COUNT; tgt_kind_group++) {
791 action_iterate(action_id) {
792 if (action_id_get_actor_kind(action_id) != AAK_UNIT) {
793 /* This action isn't performed by a unit. */
794 continue;
797 if (action_id_get_target_kind(action_id) != tgt_kind_group) {
798 /* Wrong group. */
799 continue;
802 if (action_requires_details(action_id)) {
803 /* This menu doesn't support specifying a detailed target (think
804 * "Go to and..."->"Industrial Sabotage"->"City Walls") for the
805 * action order. */
806 continue;
809 if (action_id_distance_inside_max(action_id, 2)) {
810 /* The order system doesn't support actions that can be done to a
811 * target that isn't at or next to the actor unit's tile.
813 * Full explanation in handle_unit_orders(). */
814 continue;
817 /* Create and add the menu item. It will be hidden or shown based on
818 * unit type. */
819 item = addAction(action_id_name_translation(action_id));
820 items.insert(item, action_id);
821 connect(item, SIGNAL(triggered()),
822 go_act_mapper, SLOT(map()));
823 go_act_mapper->setMapping(item, action_id);
824 } action_iterate_end;
827 connect(go_act_mapper, SIGNAL(mapped(int)), this, SLOT(start_go_act(int)));
830 /**************************************************************************
831 Update the goto and act menu based on the selected unit(s)
832 **************************************************************************/
833 void go_act_menu::update()
835 bool can_do_something = false;
837 if (!actions_are_ready()) {
838 /* Nothing to do. */
839 return;
842 if (items.isEmpty()) {
843 /* The goto and act menu needs menu items. */
844 create();
847 /* Enable a menu item if it is theoretically possible that one of the
848 * selected units can perform it. Checking if the action can be performed
849 * at the current tile is pointless since it should be performed at the
850 * target tile. */
851 foreach(QAction *item, items.keys()) {
852 if (units_can_do_action(get_units_in_focus(),
853 items.value(item), TRUE)) {
854 item->setVisible(true);
855 can_do_something = true;
856 } else {
857 item->setVisible(false);
861 if (can_do_something) {
862 /* At least one menu item is enabled for one of the selected units. */
863 setEnabled(true);
864 } else {
865 /* No menu item is enabled any of the selected units. */
866 setEnabled(false);
870 /**************************************************************************
871 Activate the goto system
872 **************************************************************************/
873 void go_act_menu::start_go_act(int action_id)
875 /* This menu doesn't support specifying a detailed target (think
876 * "Go to and..."->"Industrial Sabotage"->"City Walls") for the
877 * action order. */
878 fc_assert_ret_msg(!action_requires_details(action_id),
879 "Underspecified target for %s.",
880 action_id_name_translation(action_id));
882 request_unit_goto(ORDER_PERFORM_ACTION, action_id, EXTRA_NONE);
885 /**************************************************************************
886 Store all goto and act menu items so they can be updated etc
887 **************************************************************************/
888 QSet<go_act_menu *> go_act_menu::instances;
890 /**************************************************************************
891 Reset all goto and act menu instances.
892 **************************************************************************/
893 void go_act_menu::reset_all()
895 foreach (go_act_menu *m, instances) {
896 m->reset();
900 /**************************************************************************
901 Update all goto and act menu instances
902 **************************************************************************/
903 void go_act_menu::update_all()
905 foreach (go_act_menu *m, instances) {
906 m->update();
911 /****************************************************************************
912 Predicts last unit position
913 ****************************************************************************/
914 struct tile *mr_menu::find_last_unit_pos(unit *punit, int pos)
916 qfc_delayed_unit_item *fui;
917 struct tile *ptile = nullptr;
918 struct unit *zunit;
919 struct unit *qunit;
921 int i = 0;
922 qunit = punit;
923 foreach (fui, units_list.unit_list) {
924 zunit = unit_list_find(client_player()->units, fui->id);
925 i++;
926 if (i >= pos) {
927 punit = qunit;
928 return ptile;
930 if (zunit == nullptr) {
931 continue;
934 if (punit == zunit) { /* Unit found */
935 /* Unit was ordered to attack city so it might stay in
936 front of that city */
937 if (is_non_allied_city_tile(fui->ptile, unit_owner(punit))) {
938 ptile = tile_before_end_path(punit, fui->ptile);
939 if (ptile == nullptr) {
940 ptile = fui->ptile;
942 } else {
943 ptile = fui->ptile;
945 /* unit found in tranporter */
946 } else if (unit_contained_in(punit, zunit)) {
947 ptile = fui->ptile;
950 return nullptr;
953 /****************************************************************************
954 Constructor for global menubar in gameview
955 ****************************************************************************/
956 mr_menu::mr_menu() : QMenuBar()
960 /****************************************************************************
961 Initializes menu system, and add custom enum(munit) for most of options
962 Notice that if you set option for QAction->setChecked(option) it will
963 check/uncheck automatically without any intervention
964 ****************************************************************************/
965 void mr_menu::setup_menus()
967 QAction *act;
968 QMenu *pr;
969 QList<QMenu*> menus;
970 int i;
972 delayed_order = false;
973 airlift_type_id = 0;
974 quick_airlifting = false;
976 /* Game Menu */
977 menu = this->addMenu(_("Game"));
978 pr = menu;
979 menu = menu->addMenu(_("Options"));
980 act = menu->addAction(_("Set local options"));
981 connect(act, SIGNAL(triggered()), this, SLOT(local_options()));
982 act = menu->addAction(_("Server Options"));
983 connect(act, SIGNAL(triggered()), this, SLOT(server_options()));
984 act = menu->addAction(_("Messages"));
985 connect(act, SIGNAL(triggered()), this, SLOT(messages_options()));
986 act = menu->addAction(_("Shortcuts"));
987 connect(act, SIGNAL(triggered()), this, SLOT(shortcut_options()));
988 act = menu->addAction(_("Load another tileset"));
989 connect(act, SIGNAL(triggered()), this, SLOT(tileset_custom_load()));
990 act = menu->addAction(_("Save Options Now"));
991 act->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
992 connect(act, SIGNAL(triggered()), this, SLOT(save_options_now()));
993 act = menu->addAction(_("Save Options on Exit"));
994 act->setCheckable(true);
995 act->setChecked(gui_options.save_options_on_exit);
996 menu = pr;
997 menu->addSeparator();
998 act = menu->addAction(_("Save Game"));
999 act->setShortcut(QKeySequence(tr("Ctrl+s")));
1000 act->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
1001 menu_list.insertMulti(SAVE, act);
1002 connect(act, SIGNAL(triggered()), this, SLOT(save_game()));
1003 act = menu->addAction(_("Save Game As..."));
1004 menu_list.insertMulti(SAVE, act);
1005 act->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
1006 connect(act, SIGNAL(triggered()), this, SLOT(save_game_as()));
1007 act = menu->addAction(_("Save Map to Image"));
1008 connect(act, SIGNAL(triggered()), this, SLOT(save_image()));
1009 menu->addSeparator();
1010 act = menu->addAction(_("Leave game"));
1011 act->setIcon(style()->standardIcon(QStyle::SP_DialogDiscardButton));
1012 connect(act, SIGNAL(triggered()), this, SLOT(back_to_menu()));
1013 act = menu->addAction(_("Quit"));
1014 act->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
1015 connect(act, SIGNAL(triggered()), this, SLOT(quit_game()));
1017 /* View Menu */
1018 menu = this->addMenu(Q_("?verb:View"));
1019 act = menu->addAction(_("Center View"));
1020 act->setShortcut(QKeySequence(shortcut_to_string(
1021 fc_shortcuts::sc()->get_shortcut(SC_CENTER_VIEW))));
1022 connect(act, SIGNAL(triggered()), this, SLOT(slot_center_view()));
1023 menu->addSeparator();
1024 act = menu->addAction(_("Fullscreen"));
1025 act->setShortcut(QKeySequence(shortcut_to_string(
1026 fc_shortcuts::sc()->get_shortcut(SC_FULLSCREEN))));
1027 act->setCheckable(true);
1028 act->setChecked(gui_options.gui_qt_fullscreen);
1029 connect(act, SIGNAL(triggered()), this, SLOT(slot_fullscreen()));
1030 menu->addSeparator();
1031 minimap_status = menu->addAction(_("Minimap"));
1032 minimap_status->setCheckable(true);
1033 minimap_status->setShortcut(QKeySequence(shortcut_to_string(
1034 fc_shortcuts::sc()->get_shortcut(SC_MINIMAP))));
1035 minimap_status->setChecked(true);
1036 connect(minimap_status, SIGNAL(triggered()), this,
1037 SLOT(slot_minimap_view()));
1038 osd_status = menu->addAction(_("Show new turn information"));
1039 osd_status->setCheckable(true);
1040 osd_status->setChecked(gui()->qt_settings.show_new_turn_text);
1041 connect(osd_status, SIGNAL(triggered()), this,
1042 SLOT(slot_show_new_turn_text()));
1043 btlog_status = menu->addAction(_("Show combat detailed information"));
1044 btlog_status->setCheckable(true);
1045 btlog_status->setChecked(gui()->qt_settings.show_battle_log);
1046 connect(btlog_status, SIGNAL(triggered()), this, SLOT(slot_battlelog()));
1047 lock_status = menu->addAction(_("Lock interface"));
1048 lock_status->setCheckable(true);
1049 lock_status->setShortcut(QKeySequence(shortcut_to_string(
1050 fc_shortcuts::sc()->get_shortcut(SC_IFACE_LOCK))));
1051 lock_status->setChecked(false);
1052 connect(lock_status, SIGNAL(triggered()), this, SLOT(slot_lock()));
1053 connect(minimap_status, SIGNAL(triggered()), this, SLOT(slot_lock()));
1054 menu->addSeparator();
1055 act = menu->addAction(_("Zoom in"));
1056 act->setShortcut(QKeySequence(shortcut_to_string(
1057 fc_shortcuts::sc()->get_shortcut(SC_ZOOM_IN))));
1058 connect(act, SIGNAL(triggered()), this, SLOT(zoom_in()));
1059 act = menu->addAction(_("Zoom out"));
1060 act->setShortcut(QKeySequence(shortcut_to_string(
1061 fc_shortcuts::sc()->get_shortcut(SC_ZOOM_OUT))));
1062 connect(act, SIGNAL(triggered()), this, SLOT(zoom_out()));
1063 menu->addSeparator();
1064 act = menu->addAction(_("City Outlines"));
1065 act->setCheckable(true);
1066 act->setChecked(gui_options.draw_city_outlines);
1067 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_outlines()));
1068 act = menu->addAction(_("City Output"));
1069 act->setCheckable(true);
1070 act->setChecked(gui_options.draw_city_output);
1071 act->setShortcut(QKeySequence(shortcut_to_string(
1072 fc_shortcuts::sc()->get_shortcut(SC_CITY_OUTPUT))));
1073 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_output()));
1074 act = menu->addAction(_("Map Grid"));
1075 act->setShortcut(QKeySequence(shortcut_to_string(
1076 fc_shortcuts::sc()->get_shortcut(SC_MAP_GRID))));
1077 act->setCheckable(true);
1078 act->setChecked(gui_options.draw_map_grid);
1079 connect(act, SIGNAL(triggered()), this, SLOT(slot_map_grid()));
1080 act = menu->addAction(_("National Borders"));
1081 act->setCheckable(true);
1082 act->setChecked(gui_options.draw_borders);
1083 act->setShortcut(QKeySequence(shortcut_to_string(
1084 fc_shortcuts::sc()->get_shortcut(SC_NAT_BORDERS))));
1085 connect(act, SIGNAL(triggered()), this, SLOT(slot_borders()));
1086 act = menu->addAction(_("Native Tiles"));
1087 act->setCheckable(true);
1088 act->setChecked(gui_options.draw_native);
1089 act->setShortcut(QKeySequence(tr("ctrl+shift+n")));
1090 connect(act, SIGNAL(triggered()), this, SLOT(slot_native_tiles()));
1091 act = menu->addAction(_("City Full Bar"));
1092 act->setCheckable(true);
1093 act->setShortcut(QKeySequence(shortcut_to_string(
1094 fc_shortcuts::sc()->get_shortcut(SC_SHOW_FULLBAR))));
1095 act->setChecked(gui_options.draw_full_citybar);
1096 connect(act, SIGNAL(triggered()), this, SLOT(slot_fullbar()));
1097 act = menu->addAction(_("City Names"));
1098 act->setCheckable(true);
1099 act->setChecked(gui_options.draw_city_names);
1100 act->setShortcut(QKeySequence(shortcut_to_string(
1101 fc_shortcuts::sc()->get_shortcut(SC_CITY_NAMES))));
1102 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_names()));
1103 act = menu->addAction(_("City Growth"));
1104 act->setCheckable(true);
1105 act->setChecked(gui_options.draw_city_growth);
1106 act->setShortcut(QKeySequence(tr("ctrl+r")));
1107 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_growth()));
1108 act = menu->addAction(_("City Production Levels"));
1109 act->setCheckable(true);
1110 act->setChecked(gui_options.draw_city_productions);
1111 act->setShortcut(QKeySequence(shortcut_to_string(
1112 fc_shortcuts::sc()->get_shortcut(SC_CITY_PROD))));
1113 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_production()));
1114 act = menu->addAction(_("City Buy Cost"));
1115 act->setCheckable(true);
1116 act->setChecked(gui_options.draw_city_buycost);
1117 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_buycost()));
1118 act = menu->addAction(_("City Traderoutes"));
1119 act->setCheckable(true);
1120 act->setChecked(gui_options.draw_city_trade_routes);
1121 act->setShortcut(QKeySequence(shortcut_to_string(
1122 fc_shortcuts::sc()->get_shortcut(SC_TRADE_ROUTES))));
1123 connect(act, SIGNAL(triggered()), this, SLOT(slot_city_traderoutes()));
1125 /* Select Menu */
1126 menu = this->addMenu(_("Select"));
1127 act = menu->addAction(_("Single Unit (Unselect Others)"));
1128 act->setShortcut(QKeySequence(tr("shift+z")));
1129 menu_list.insertMulti(STANDARD, act);
1130 connect(act, SIGNAL(triggered()), this, SLOT(slot_select_one()));
1131 act = menu->addAction(_("All On Tile"));
1132 act->setShortcut(QKeySequence(tr("v")));
1133 menu_list.insertMulti(STANDARD, act);
1134 connect(act, SIGNAL(triggered()), this, SLOT(slot_select_all_tile()));
1135 menu->addSeparator();
1136 act = menu->addAction(_("Same Type on Tile"));
1137 act->setShortcut(QKeySequence(tr("shift+v")));
1138 menu_list.insertMulti(STANDARD, act);
1139 connect(act, SIGNAL(triggered()), this, SLOT(slot_select_same_tile()));
1140 act = menu->addAction(_("Same Type on Continent"));
1141 act->setShortcut(QKeySequence(tr("shift+c")));
1142 menu_list.insertMulti(STANDARD, act);
1143 connect(act, SIGNAL(triggered()), this,
1144 SLOT(slot_select_same_continent()));
1145 act = menu->addAction(_("Same Type Everywhere"));
1146 act->setShortcut(QKeySequence(tr("shift+x")));
1147 menu_list.insertMulti(STANDARD, act);
1148 connect(act, SIGNAL(triggered()), this,
1149 SLOT(slot_select_same_everywhere()));
1150 menu->addSeparator();
1151 act = menu->addAction(_("Wait"));
1152 act->setShortcut(QKeySequence(shortcut_to_string(
1153 fc_shortcuts::sc()->get_shortcut(SC_WAIT))));
1154 menu_list.insertMulti(STANDARD, act);
1155 connect(act, SIGNAL(triggered()), this, SLOT(slot_wait()));
1156 act = menu->addAction(_("Done"));
1157 act->setShortcut(QKeySequence(shortcut_to_string(
1158 fc_shortcuts::sc()->get_shortcut(SC_DONE_MOVING))));
1159 menu_list.insertMulti(STANDARD, act);
1160 connect(act, SIGNAL(triggered()), this, SLOT(slot_done_moving()));
1162 act = menu->addAction(_("Advanced unit selection"));
1163 act->setShortcut(QKeySequence(tr("ctrl+e")));
1164 menu_list.insertMulti(NOT_4_OBS, act);
1165 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_filter()));
1168 /* Unit Menu */
1169 menu = this->addMenu(_("Unit"));
1170 act = menu->addAction(_("Go to Tile"));
1171 act->setShortcut(QKeySequence(shortcut_to_string(
1172 fc_shortcuts::sc()->get_shortcut(SC_GOTO))));
1173 menu_list.insertMulti(STANDARD, act);
1174 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_goto()));
1176 /* The goto and act sub menu is handled as a separate object. */
1177 menu->addMenu(new go_act_menu());
1179 act = menu->addAction(_("Go to Nearest City"));
1180 act->setShortcut(QKeySequence(tr("shift+g")));
1181 menu_list.insertMulti(GOTO_CITY, act);
1182 connect(act, SIGNAL(triggered()), this, SLOT(slot_return_to_city()));
1183 act = menu->addAction(_("Go to/Airlift to City..."));
1184 act->setShortcut(QKeySequence(shortcut_to_string(
1185 fc_shortcuts::sc()->get_shortcut(SC_GOTOAIRLIFT))));
1186 menu_list.insertMulti(AIRLIFT, act);
1187 connect(act, SIGNAL(triggered()), this, SLOT(slot_airlift()));
1188 menu->addSeparator();
1189 act = menu->addAction(_("Auto Explore"));
1190 menu_list.insertMulti(EXPLORE, act);
1191 act->setShortcut(QKeySequence(shortcut_to_string(
1192 fc_shortcuts::sc()->get_shortcut(SC_AUTOEXPLORE))));
1193 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_explore()));
1194 act = menu->addAction(_("Patrol"));
1195 menu_list.insertMulti(STANDARD, act);
1196 act->setEnabled(false);
1197 act->setShortcut(QKeySequence(shortcut_to_string(
1198 fc_shortcuts::sc()->get_shortcut(SC_PATROL))));
1199 connect(act, SIGNAL(triggered()), this, SLOT(slot_patrol()));
1200 menu->addSeparator();
1201 act = menu->addAction(_("Sentry"));
1202 act->setShortcut(QKeySequence(shortcut_to_string(
1203 fc_shortcuts::sc()->get_shortcut(SC_SENTRY))));
1204 menu_list.insertMulti(SENTRY, act);
1205 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_sentry()));
1206 act = menu->addAction(_("Unsentry All On Tile"));
1207 act->setShortcut(QKeySequence(shortcut_to_string(
1208 fc_shortcuts::sc()->get_shortcut(SC_UNSENTRY_TILE))));
1209 menu_list.insertMulti(WAKEUP, act);
1210 connect(act, SIGNAL(triggered()), this, SLOT(slot_unsentry()));
1211 menu->addSeparator();
1212 act = menu->addAction(_("Load"));
1213 act->setShortcut(QKeySequence(shortcut_to_string(
1214 fc_shortcuts::sc()->get_shortcut(SC_LOAD))));
1215 menu_list.insertMulti(LOAD, act);
1216 connect(act, SIGNAL(triggered()), this, SLOT(slot_load()));
1217 act = menu->addAction(_("Unload"));
1218 act->setShortcut(QKeySequence(shortcut_to_string(
1219 fc_shortcuts::sc()->get_shortcut(SC_UNLOAD))));
1220 menu_list.insertMulti(UNLOAD, act);
1221 connect(act, SIGNAL(triggered()), this, SLOT(slot_unload()));
1222 act = menu->addAction(_("Unload All From Transporter"));
1223 act->setShortcut(QKeySequence(tr("shift+u")));
1224 menu_list.insertMulti(TRANSPORTER, act);
1225 connect(act, SIGNAL(triggered()), this, SLOT(slot_unload_all()));
1226 menu->addSeparator();
1227 act = menu->addAction(action_id_name_translation(ACTION_HOME_CITY));
1228 menu_list.insertMulti(HOMECITY, act);
1229 act->setShortcut(QKeySequence(shortcut_to_string(
1230 fc_shortcuts::sc()->get_shortcut(SC_SETHOME))));
1231 connect(act, SIGNAL(triggered()), this, SLOT(slot_set_home()));
1232 act = menu->addAction(_("Upgrade"));
1233 act->setShortcut(QKeySequence(shortcut_to_string(
1234 fc_shortcuts::sc()->get_shortcut(SC_UPGRADE_UNIT))));
1235 menu_list.insertMulti(UPGRADE, act);
1236 connect(act, SIGNAL(triggered()), this, SLOT(slot_upgrade()));
1237 act = menu->addAction(_("Convert"));
1238 act->setShortcut(QKeySequence(tr("ctrl+o")));
1239 menu_list.insertMulti(CONVERT, act);
1240 connect(act, SIGNAL(triggered()), this, SLOT(slot_convert()));
1241 act = menu->addAction(_("Disband"));
1242 act->setShortcut(QKeySequence(tr("shift+d")));
1243 menu_list.insertMulti(DISBAND, act);
1244 connect(act, SIGNAL(triggered()), this, SLOT(slot_disband()));
1246 /* Combat Menu */
1247 menu = this->addMenu(_("Combat"));
1248 act = menu->addAction(_("Fortify Unit"));
1249 menu_list.insertMulti(FORTIFY, act);
1250 act->setShortcut(QKeySequence(shortcut_to_string(
1251 fc_shortcuts::sc()->get_shortcut(SC_FORTIFY))));
1252 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_fortify()));
1253 act = menu->addAction(Q_(terrain_control.gui_type_base0));
1254 menu_list.insertMulti(FORTRESS, act);
1255 act->setShortcut(QKeySequence(tr("shift+f")));
1256 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_fortress()));
1257 act = menu->addAction(Q_(terrain_control.gui_type_base1));
1258 menu_list.insertMulti(AIRBASE, act);
1259 act->setShortcut(QKeySequence(tr("shift+e")));
1260 connect(act, SIGNAL(triggered()), this, SLOT(slot_unit_airbase()));
1261 menu->addSeparator();
1262 act = menu->addAction(_("Pillage"));
1263 menu_list.insertMulti(PILLAGE, act);
1264 act->setShortcut(QKeySequence(tr("shift+p")));
1265 connect(act, SIGNAL(triggered()), this, SLOT(slot_pillage()));
1266 /* TRANS: Menu item to bring up the action selection dialog. */
1267 act = menu->addAction(_("Do..."));
1268 menu_list.insertMulti(ORDER_DIPLOMAT_DLG, act);
1269 act->setShortcut(QKeySequence(shortcut_to_string(
1270 fc_shortcuts::sc()->get_shortcut(SC_DO))));
1271 connect(act, SIGNAL(triggered()), this, SLOT(slot_action()));
1272 act = menu->addAction(action_id_name_translation(ACTION_NUKE));
1273 menu_list.insertMulti(NUKE, act);
1274 act->setShortcut(QKeySequence(shortcut_to_string(
1275 fc_shortcuts::sc()->get_shortcut(SC_NUKE))));
1276 connect(act, SIGNAL(triggered()), this, SLOT(slot_nuke()));
1278 /* Work Menu */
1279 menu = this->addMenu(_("Work"));
1280 act = menu->addAction(action_id_name_translation(ACTION_FOUND_CITY));
1281 act->setShortcut(QKeySequence(shortcut_to_string(
1282 fc_shortcuts::sc()->get_shortcut(SC_BUILDCITY))));
1283 menu_list.insertMulti(BUILD, act);
1284 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_city()));
1285 act = menu->addAction(_("Go And Build City"));
1286 menu_list.insertMulti(GO_AND_BUILD_CITY, act);
1287 act->setShortcut(QKeySequence(tr("shift+b")));
1288 connect(act, SIGNAL(triggered()), this, SLOT(slot_go_build_city()));
1289 act = menu->addAction(_("Go And Join City"));
1290 menu_list.insertMulti(MIGRANT, act);
1291 act->setShortcut(QKeySequence(tr("shift+j")));
1292 connect(act, SIGNAL(triggered()), this, SLOT(slot_go_join_city()));
1293 act = menu->addAction(_("Auto Settler"));
1294 act->setShortcut(QKeySequence(shortcut_to_string(
1295 fc_shortcuts::sc()->get_shortcut(SC_AUTOMATE))));
1296 menu_list.insertMulti(AUTOSETTLER, act);
1297 connect(act, SIGNAL(triggered()), this, SLOT(slot_auto_settler()));
1298 menu->addSeparator();
1299 act = menu->addAction(_("Build Road"));
1300 menu_list.insertMulti(ROAD, act);
1301 act->setShortcut(QKeySequence(shortcut_to_string(
1302 fc_shortcuts::sc()->get_shortcut(SC_BUILDROAD))));
1303 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_road()));
1304 act = menu->addAction(_("Build Irrigation"));
1305 act->setShortcut(QKeySequence(shortcut_to_string(
1306 fc_shortcuts::sc()->get_shortcut(SC_BUILDIRRIGATION))));
1307 menu_list.insertMulti(IRRIGATION, act);
1308 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_irrigation()));
1309 act = menu->addAction(_("Build Mine"));
1310 act->setShortcut(QKeySequence(shortcut_to_string(
1311 fc_shortcuts::sc()->get_shortcut(SC_BUILDMINE))));
1312 menu_list.insertMulti(MINE, act);
1313 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_mine()));
1314 menu->addSeparator();
1315 act = menu->addAction(_("Connect With Road"));
1316 act->setShortcut(QKeySequence(tr("shift+r")));
1317 menu_list.insertMulti(CONNECT_ROAD, act);
1318 connect(act, SIGNAL(triggered()), this, SLOT(slot_conn_road()));
1319 act = menu->addAction(_("Connect With Railroad"));
1320 menu_list.insertMulti(CONNECT_RAIL, act);
1321 act->setShortcut(QKeySequence(tr("shift+l")));
1322 connect(act, SIGNAL(triggered()), this, SLOT(slot_conn_rail()));
1323 act = menu->addAction(_("Connect With Irrigation"));
1324 menu_list.insertMulti(CONNECT_IRRIGATION, act);
1325 act->setShortcut(QKeySequence(tr("shift+i")));
1326 connect(act, SIGNAL(triggered()), this, SLOT(slot_conn_irrigation()));
1327 menu->addSeparator();
1328 act = menu->addAction(_("Transform Terrain"));
1329 menu_list.insertMulti(TRANSFORM, act);
1330 act->setShortcut(QKeySequence(shortcut_to_string(
1331 fc_shortcuts::sc()->get_shortcut(SC_TRANSFORM))));
1332 connect(act, SIGNAL(triggered()), this, SLOT(slot_transform()));
1333 act = menu->addAction(_("Clean Pollution"));
1334 menu_list.insertMulti(POLLUTION, act);
1335 act->setShortcut(QKeySequence(shortcut_to_string(
1336 fc_shortcuts::sc()->get_shortcut(SC_PARADROP))));
1337 connect(act, SIGNAL(triggered()), this, SLOT(slot_clean_pollution()));
1338 act = menu->addAction(_("Clean Nuclear Fallout"));
1339 menu_list.insertMulti(FALLOUT, act);
1340 act->setShortcut(QKeySequence(tr("n")));
1341 connect(act, SIGNAL(triggered()), this, SLOT(slot_clean_fallout()));
1342 act = menu->addAction(action_id_name_translation(ACTION_HELP_WONDER));
1343 act->setShortcut(QKeySequence(tr("b")));
1344 menu_list.insertMulti(BUILD_WONDER, act);
1345 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_city()));
1346 act = menu->addAction(action_id_name_translation(ACTION_TRADE_ROUTE));
1347 act->setShortcut(QKeySequence(tr("r")));
1348 menu_list.insertMulti(ORDER_TRADEROUTE, act);
1349 connect(act, SIGNAL(triggered()), this, SLOT(slot_build_road()));
1351 multiplayer_menu = this->addMenu(_("Multiplayer"));
1352 act = multiplayer_menu->addAction(_("Delayed Goto"));
1353 act->setShortcut(QKeySequence(tr("z")));
1354 connect(act, SIGNAL(triggered()), this, SLOT(slot_delayed_goto()));
1355 act = multiplayer_menu->addAction(_("Delayed Orders Execute"));
1356 act->setShortcut(QKeySequence(tr("ctrl+z")));
1357 connect(act, SIGNAL(triggered()), this, SLOT(slot_execute_orders()));
1358 act = multiplayer_menu->addAction(_("Clear Orders"));
1359 act->setShortcut(QKeySequence(tr("ctrl+shift+c")));
1360 connect(act, SIGNAL(triggered()), this, SLOT(slot_orders_clear()));
1361 act = multiplayer_menu->addAction(_("Add all cities to trade planning"));
1362 connect(act, SIGNAL(triggered()), this, SLOT(slot_trade_add_all()));
1363 act = multiplayer_menu->addAction(_("Calculate trade planning"));
1364 connect(act, SIGNAL(triggered()), this, SLOT(slot_calculate()));
1365 act = multiplayer_menu->addAction(_("Add/Remove City"));
1366 act->setShortcut(QKeySequence(tr("ctrl+t")));
1367 connect(act, SIGNAL(triggered()), this, SLOT(slot_trade_city()));
1368 act = multiplayer_menu->addAction(_("Clear Trade Planning"));
1369 connect(act, SIGNAL(triggered()), this, SLOT(slot_clear_trade()));
1370 act = multiplayer_menu->addAction(_("Automatic caravan"));
1371 menu_list.insertMulti(AUTOTRADEROUTE, act);
1372 connect(act, SIGNAL(triggered()), this, SLOT(slot_autocaravan()));
1373 act->setShortcut(QKeySequence(tr("ctrl+j")));
1374 act = multiplayer_menu->addAction(_("Set/Unset rally point"));
1375 act->setShortcut(QKeySequence(tr("shift+s")));
1376 connect(act, SIGNAL(triggered()), this, SLOT(slot_rally()));
1377 act = multiplayer_menu->addAction(_("Quick Airlift"));
1378 act->setShortcut(QKeySequence(tr("ctrl+y")));
1379 connect(act, SIGNAL(triggered()), this, SLOT(slot_quickairlift()));
1380 airlift_type = new QActionGroup(this);
1381 airlift_menu = multiplayer_menu->addMenu(_("Unit type for quickairlifting"));
1383 /* Default diplo */
1384 action_vs_city = new QActionGroup(this);
1385 action_vs_unit = new QActionGroup(this);
1386 action_unit_menu = multiplayer_menu->addMenu(_("Default action vs unit"));
1388 act = action_unit_menu->addAction(_("Ask"));
1389 act->setCheckable(true);
1390 act->setChecked(true);
1391 act->setData(-1);
1392 action_vs_unit->addAction(act);
1393 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
1395 act = action_unit_menu->addAction(_("Bribe"));
1396 act->setCheckable(true);
1397 act->setChecked(false);
1398 act->setData(ACTION_SPY_BRIBE_UNIT);
1399 action_vs_unit->addAction(act);
1400 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
1402 act = action_unit_menu->addAction(_("Sabotage"));
1403 act->setCheckable(true);
1404 act->setChecked(false);
1405 act->setData(ACTION_SPY_SABOTAGE_UNIT);
1406 action_vs_unit->addAction(act);
1407 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
1409 action_city_menu = multiplayer_menu->addMenu(_("Default action vs city"));
1410 act = action_city_menu->addAction(_("Ask"));
1411 act->setCheckable(true);
1412 act->setChecked(true);
1413 act->setData(-1);
1414 action_vs_city->addAction(act);
1415 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1417 act = action_city_menu->addAction(_("Investigate city"));
1418 act->setCheckable(true);
1419 act->setChecked(false);
1420 act->setData(ACTION_SPY_INVESTIGATE_CITY);
1421 action_vs_city->addAction(act);
1422 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1424 act = action_city_menu->addAction(_("Investigate city (spends the unit)"));
1425 act->setCheckable(true);
1426 act->setChecked(false);
1427 act->setData(ACTION_INV_CITY_SPEND);
1428 action_vs_city->addAction(act);
1429 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1431 act = action_city_menu->addAction(_("Establish embassy"));
1432 act->setCheckable(true);
1433 act->setChecked(false);
1434 act->setData(ACTION_ESTABLISH_EMBASSY);
1435 action_vs_city->addAction(act);
1436 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1438 act = action_city_menu->addAction(_("Establish embassy (and stay)"));
1439 act->setCheckable(true);
1440 act->setChecked(false);
1441 act->setData(ACTION_ESTABLISH_EMBASSY_STAY);
1442 action_vs_city->addAction(act);
1443 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1445 act = action_city_menu->addAction(_("Steal technology"));
1446 act->setCheckable(true);
1447 act->setChecked(false);
1448 act->setData(ACTION_SPY_STEAL_TECH);
1449 action_vs_city->addAction(act);
1450 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1452 act = action_city_menu->addAction(_("Incite a revolt"));
1453 act->setCheckable(true);
1454 act->setChecked(false);
1455 act->setData(ACTION_SPY_INCITE_CITY);
1456 action_vs_city->addAction(act);
1457 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1459 act = action_city_menu->addAction(_("Poison city"));
1460 act->setCheckable(true);
1461 act->setChecked(false);
1462 act->setData(ACTION_SPY_POISON);
1463 action_vs_city->addAction(act);
1464 connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
1466 /* Civilization menu */
1467 menu = this->addMenu(_("Civilization"));
1468 act = menu->addAction(_("Tax Rates..."));
1469 menu_list.insertMulti(NOT_4_OBS, act);
1470 connect(act, SIGNAL(triggered()), this, SLOT(slot_popup_tax_rates()));
1471 menu->addSeparator();
1473 act = menu->addAction(_("Policies..."));
1474 menu_list.insertMulti(MULTIPLIERS, act);
1475 connect(act, SIGNAL(triggered()), this, SLOT(slot_popup_mult_rates()));
1476 menu->addSeparator();
1478 menu->addMenu(new class gov_menu(this));
1479 menu->addSeparator();
1481 act = menu->addAction(Q_("?noun:View"));
1482 act->setShortcut(QKeySequence(tr("F1")));
1483 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_map()));
1485 act = menu->addAction(_("Units"));
1486 act->setShortcut(QKeySequence(tr("F2")));
1487 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_units_report()));
1489 /* TRANS: Also menu item, but 'headers' should be good enough. */
1490 act = menu->addAction(Q_("?header:Players"));
1491 act->setShortcut(QKeySequence(tr("F3")));
1492 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_nations()));
1494 act = menu->addAction(_("Cities"));
1495 act->setShortcut(QKeySequence(tr("F4")));
1496 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_cities()));
1498 act = menu->addAction(_("Economy"));
1499 act->setShortcut(QKeySequence(tr("F5")));
1500 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_eco_report()));
1502 act = menu->addAction(_("Research"));
1503 act->setShortcut(QKeySequence(tr("F6")));
1504 connect(act, SIGNAL(triggered()), this, SLOT(slot_show_research_tab()));
1506 act = menu->addAction(_("Wonders of the World"));
1507 act->setShortcut(QKeySequence(tr("F7")));
1508 connect(act, SIGNAL(triggered()), this, SLOT(slot_traveler()));
1510 act = menu->addAction(_("Top Five Cities"));
1511 act->setShortcut(QKeySequence(tr("F8")));
1512 connect(act, SIGNAL(triggered()), this, SLOT(slot_top_five()));
1514 act = menu->addAction(_("Demographics"));
1515 act->setShortcut(QKeySequence(tr("F11")));
1516 connect(act, SIGNAL(triggered()), this, SLOT(slot_demographics()));
1518 act = menu->addAction(_("Spaceship"));
1519 act->setShortcut(QKeySequence(tr("F12")));
1520 connect(act, SIGNAL(triggered()), this, SLOT(slot_spaceship()));
1522 act = menu->addAction(_("Achievements"));
1523 connect(act, SIGNAL(triggered()), this, SLOT(slot_achievements()));
1525 act = menu->addAction(_("Endgame report"));
1526 menu_list.insertMulti(ENDGAME, act);
1527 connect(act, SIGNAL(triggered()), this, SLOT(slot_endgame()));
1529 /* Help Menu */
1530 menu = this->addMenu(_("Help"));
1532 signal_help_mapper = new QSignalMapper(this);
1533 connect(signal_help_mapper, SIGNAL(mapped(const QString &)),
1534 this, SLOT(slot_help(const QString &)));
1536 act = menu->addAction(Q_(HELP_OVERVIEW_ITEM));
1537 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1538 signal_help_mapper->setMapping(act, HELP_OVERVIEW_ITEM);
1540 act = menu->addAction(Q_(HELP_PLAYING_ITEM));
1541 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1542 signal_help_mapper->setMapping(act, HELP_PLAYING_ITEM);
1544 act = menu->addAction(Q_(HELP_TERRAIN_ITEM));
1545 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1546 signal_help_mapper->setMapping(act, HELP_TERRAIN_ITEM);
1548 act = menu->addAction(Q_(HELP_ECONOMY_ITEM));
1549 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1550 signal_help_mapper->setMapping(act, HELP_ECONOMY_ITEM);
1552 act = menu->addAction(Q_(HELP_CITIES_ITEM));
1553 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1554 signal_help_mapper->setMapping(act, HELP_CITIES_ITEM);
1556 act = menu->addAction(Q_(HELP_IMPROVEMENTS_ITEM));
1557 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1558 signal_help_mapper->setMapping(act, HELP_IMPROVEMENTS_ITEM);
1560 act = menu->addAction(Q_(HELP_WONDERS_ITEM));
1561 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1562 signal_help_mapper->setMapping(act, HELP_WONDERS_ITEM);
1564 act = menu->addAction(Q_(HELP_UNITS_ITEM));
1565 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1566 signal_help_mapper->setMapping(act, HELP_UNITS_ITEM);
1568 act = menu->addAction(Q_(HELP_COMBAT_ITEM));
1569 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1570 signal_help_mapper->setMapping(act, HELP_COMBAT_ITEM);
1572 act = menu->addAction(Q_(HELP_ZOC_ITEM));
1573 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1574 signal_help_mapper->setMapping(act, HELP_ZOC_ITEM);
1576 act = menu->addAction(Q_(HELP_GOVERNMENT_ITEM));
1577 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1578 signal_help_mapper->setMapping(act, HELP_GOVERNMENT_ITEM);
1580 act = menu->addAction(Q_(HELP_ECONOMY_ITEM));
1581 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1582 signal_help_mapper->setMapping(act, HELP_ECONOMY_ITEM);
1584 act = menu->addAction(Q_(HELP_DIPLOMACY_ITEM));
1585 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1586 signal_help_mapper->setMapping(act, HELP_DIPLOMACY_ITEM);
1588 act = menu->addAction(Q_(HELP_TECHS_ITEM));
1589 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1590 signal_help_mapper->setMapping(act, HELP_TECHS_ITEM);
1592 act = menu->addAction(Q_(HELP_SPACE_RACE_ITEM));
1593 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1594 signal_help_mapper->setMapping(act, HELP_SPACE_RACE_ITEM);
1596 act = menu->addAction(Q_(HELP_IMPROVEMENTS_ITEM));
1597 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1598 signal_help_mapper->setMapping(act, HELP_IMPROVEMENTS_ITEM);
1600 act = menu->addAction(Q_(HELP_RULESET_ITEM));
1601 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1602 signal_help_mapper->setMapping(act, HELP_RULESET_ITEM);
1604 act = menu->addAction(Q_(HELP_NATIONS_ITEM));
1605 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1606 signal_help_mapper->setMapping(act, HELP_NATIONS_ITEM);
1608 menu->addSeparator();
1610 act = menu->addAction(Q_(HELP_CONNECTING_ITEM));
1611 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1612 signal_help_mapper->setMapping(act, HELP_CONNECTING_ITEM);
1614 act = menu->addAction(Q_(HELP_CONTROLS_ITEM));
1615 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1616 signal_help_mapper->setMapping(act, HELP_CONTROLS_ITEM);
1618 act = menu->addAction(Q_(HELP_CMA_ITEM));
1619 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1620 signal_help_mapper->setMapping(act, HELP_CMA_ITEM);
1622 act = menu->addAction(Q_(HELP_CHATLINE_ITEM));
1623 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1624 signal_help_mapper->setMapping(act, HELP_CHATLINE_ITEM);
1626 act = menu->addAction(Q_(HELP_WORKLIST_EDITOR_ITEM));
1627 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1628 signal_help_mapper->setMapping(act, HELP_WORKLIST_EDITOR_ITEM);
1630 menu->addSeparator();
1632 act = menu->addAction(Q_(HELP_LANGUAGES_ITEM));
1633 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1634 signal_help_mapper->setMapping(act, HELP_LANGUAGES_ITEM);
1636 act = menu->addAction(Q_(HELP_COPYING_ITEM));
1637 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1638 signal_help_mapper->setMapping(act, HELP_COPYING_ITEM);
1640 act = menu->addAction(Q_(HELP_ABOUT_ITEM));
1641 connect(act, SIGNAL(triggered()), signal_help_mapper, SLOT(map()));
1642 signal_help_mapper->setMapping(act, HELP_ABOUT_ITEM);
1644 menus = this->findChildren<QMenu*>();
1645 for (i = 0; i < menus.count(); i++) {
1646 menus[i]->setAttribute(Qt::WA_TranslucentBackground);
1648 this->setVisible(false);
1651 /****************************************************************************
1652 Sets given tile for delayed order
1653 ****************************************************************************/
1654 void mr_menu::set_tile_for_order(tile *ptile)
1656 for (int i=0; i < units_list.nr_units; i++) {
1657 units_list.unit_list.at(units_list.unit_list.count() - i -1)->ptile = ptile;
1661 /****************************************************************************
1662 Finds QAction bounded to given shortcut and triggers it
1663 ****************************************************************************/
1664 void mr_menu::execute_shortcut(int sid)
1666 QList<QMenu*> menu_list;
1667 QMenu *m;
1668 QAction* a;
1669 QKeySequence seq;
1670 fc_shortcut *fcs;
1672 if (sid == SC_GOTO) {
1673 gui()->mapview_wdg->menu_click = true;
1674 slot_unit_goto();
1675 return;
1677 fcs = fc_shortcuts::sc()->get_shortcut(static_cast<shortcut_id>(sid));
1678 seq = QKeySequence(shortcut_to_string(fcs));
1680 menu_list = findChildren<QMenu*>();
1681 foreach (m, menu_list) {
1682 foreach (a, m->actions()) {
1683 if (a->shortcut() == seq && a->isEnabled()) {
1684 a->activate(QAction::Trigger);
1685 return;
1691 /****************************************************************************
1692 Returns string assigned to shortcut or empty string if doesnt exist
1693 ****************************************************************************/
1694 QString mr_menu::shortcut_exist(fc_shortcut *fcs)
1696 QList<QMenu*> menu_list;
1697 QMenu *m;
1698 QKeySequence seq;
1699 QAction* a;
1701 seq = QKeySequence(shortcut_to_string(fcs));
1702 menu_list = findChildren<QMenu *>();
1703 foreach (m, menu_list) {
1704 foreach (a, m->actions()) {
1705 if (a->shortcut() == seq && fcs->mouse == Qt::AllButtons) {
1706 return a->text();
1711 return QString();
1714 /****************************************************************************
1715 Returns string bounded to given shortcut
1716 ****************************************************************************/
1717 QString mr_menu::shortcut_2_menustring(int sid)
1719 QList<QMenu *> menu_list;
1720 QMenu *m;
1721 QAction *a;
1722 QKeySequence seq;
1723 fc_shortcut *fcs;
1725 fcs = fc_shortcuts::sc()->get_shortcut(static_cast<shortcut_id>(sid));
1726 seq = QKeySequence(shortcut_to_string(fcs));
1728 menu_list = findChildren<QMenu *>();
1729 foreach (m, menu_list) {
1730 foreach (a, m->actions()) {
1731 if (a->shortcut() == seq) {
1732 return (a->text() + " ("
1733 + a->shortcut().toString(QKeySequence::NativeText) + ")");
1737 return QString();
1740 /****************************************************************************
1741 Updates airlift menu
1742 ****************************************************************************/
1743 void mr_menu::update_airlift_menu()
1745 Unit_type_id utype_id;
1746 QAction *act;
1748 airlift_menu->clear();
1749 if (client_is_observer()) {
1750 return;
1752 unit_type_iterate(utype) {
1753 utype_id = utype_index(utype);
1755 if (!can_player_build_unit_now(client.conn.playing, utype)
1756 || !utype_can_do_action(utype, ACTION_AIRLIFT)) {
1757 continue;
1759 if (!can_player_build_unit_now(client.conn.playing, utype)
1760 && !has_player_unit_type(utype_id)) {
1761 continue;
1763 act = airlift_menu->addAction(utype_name_translation(utype));
1764 act->setCheckable(true);
1765 act->setData(utype_id);
1766 if (airlift_type_id == utype_id) {
1767 act->setChecked(true);
1769 connect(act, SIGNAL(triggered()), this, SLOT(slot_quickairlift_set()));
1770 airlift_type->addAction(act);
1771 } unit_type_iterate_end;
1776 /****************************************************************************
1777 Enables/disables menu items and renames them depending on key in menu_list
1778 ****************************************************************************/
1779 void mr_menu::menus_sensitive()
1781 QList <QAction * >values;
1782 QList <munit > keys;
1783 QHash <munit, QAction *>::iterator i;
1784 struct unit_list *punits = NULL;
1785 struct road_type *proad;
1786 struct extra_type *tgt;
1787 bool any_cities = false;
1788 bool city_on_tile = false;
1789 bool units_all_same_tile = true;
1790 const struct tile *ptile = NULL;
1791 struct terrain *pterrain;
1792 const struct unit_type *ptype = NULL;
1794 players_iterate(pplayer) {
1795 if (city_list_size(pplayer->cities)) {
1796 any_cities = true;
1797 break;
1799 } players_iterate_end;
1801 /** Disable first all sensitive menus */
1802 foreach(QAction * a, menu_list) {
1803 a->setEnabled(false);
1806 if (client_is_observer()) {
1807 multiplayer_menu->setDisabled(true);
1808 } else {
1809 multiplayer_menu->setDisabled(false);
1812 /* Non unit menus */
1813 keys = menu_list.keys();
1814 foreach (munit key, keys) {
1815 i = menu_list.find(key);
1816 while (i != menu_list.end() && i.key() == key) {
1817 switch (key) {
1818 case SAVE:
1819 if (can_client_access_hack() && C_S_RUNNING <= client_state()) {
1820 i.value()->setEnabled(true);
1822 break;
1823 case NOT_4_OBS:
1824 if (client_is_observer() == false) {
1825 i.value()->setEnabled(true);
1827 break;
1828 case MULTIPLIERS:
1829 if (client_is_observer() == false && multiplier_count() > 0) {
1830 i.value()->setEnabled(true);
1831 i.value()->setVisible(true);
1832 } else {
1833 i.value()->setVisible(false);
1835 break;
1836 case ENDGAME:
1837 if (gui()->is_repo_dlg_open("END")) {
1838 i.value()->setEnabled(true);
1839 i.value()->setVisible(true);
1840 } else {
1841 i.value()->setVisible(false);
1843 break;
1844 default:
1845 break;
1847 i++;
1851 if (can_client_issue_orders() == false || get_num_units_in_focus() == 0) {
1852 return;
1855 punits = get_units_in_focus();
1856 unit_list_iterate(punits, punit) {
1857 if (tile_city(unit_tile(punit))) {
1858 city_on_tile = true;
1859 break;
1861 } unit_list_iterate_end;
1863 unit_list_iterate(punits, punit) {
1864 fc_assert((ptile == NULL) == (ptype == NULL));
1865 if (ptile || ptype) {
1866 if (unit_tile(punit) != ptile) {
1867 units_all_same_tile = false;
1869 if (unit_type_get(punit) == ptype) {
1870 ptile = unit_tile(punit);
1871 ptype = unit_type_get(punit);
1874 } unit_list_iterate_end;
1876 keys = menu_list.keys();
1877 foreach(munit key, keys) {
1878 i = menu_list.find(key);
1879 while (i != menu_list.end() && i.key() == key) {
1880 switch (key) {
1881 case STANDARD:
1882 i.value()->setEnabled(true);
1883 break;
1885 case EXPLORE:
1886 if (can_units_do_activity(punits, ACTIVITY_EXPLORE)) {
1887 i.value()->setEnabled(true);
1889 break;
1891 case LOAD:
1892 if (units_can_load(punits)) {
1893 i.value()->setEnabled(true);
1895 break;
1897 case UNLOAD:
1898 if (units_can_unload(punits)) {
1899 i.value()->setEnabled(true);
1901 break;
1903 case TRANSPORTER:
1904 if (units_are_occupied(punits)) {
1905 i.value()->setEnabled(true);
1907 break;
1909 case CONVERT:
1910 if (units_can_convert(punits)) {
1911 i.value()->setEnabled(true);
1913 break;
1915 case MINE:
1916 if (can_units_do_activity(punits, ACTIVITY_MINE)) {
1917 i.value()->setEnabled(true);
1920 if (units_all_same_tile) {
1921 struct unit *punit = unit_list_get(punits, 0);
1923 pterrain = tile_terrain(unit_tile(punit));
1924 if (pterrain->mining_result != T_NONE
1925 && pterrain->mining_result != pterrain) {
1926 i.value()->setText(
1927 QString(_("Transform to %1")).
1928 /* TRANS: Transfrom terrain to specific type */
1929 arg(QString(get_tile_change_menu_text
1930 (unit_tile(punit), ACTIVITY_MINE))));
1931 } else if (units_have_type_flag(punits, UTYF_SETTLERS, TRUE)){
1932 struct extra_type *pextra = NULL;
1934 /* FIXME: this overloading doesn't work well with multiple focus
1935 * units. */
1936 unit_list_iterate(punits, builder) {
1937 pextra = next_extra_for_tile(unit_tile(builder), EC_MINE,
1938 unit_owner(builder), builder);
1939 if (pextra != NULL) {
1940 break;
1942 } unit_list_iterate_end;
1944 if (pextra != NULL) {
1945 /* TRANS: Build mine of specific type */
1946 i.value()->setText(QString(_("Build %1"))
1947 .arg(extra_name_translation(pextra)));
1948 } else {
1949 i.value()->setText(QString(_("Build Mine")));
1951 } else {
1952 i.value()->setText(QString(_("Build Mine")));
1955 break;
1957 case IRRIGATION:
1958 if (can_units_do_activity(punits, ACTIVITY_IRRIGATE)) {
1959 i.value()->setEnabled(true);
1961 if (units_all_same_tile) {
1962 struct unit *punit = unit_list_get(punits, 0);
1964 pterrain = tile_terrain(unit_tile(punit));
1965 if (pterrain->irrigation_result != T_NONE
1966 && pterrain->irrigation_result != pterrain) {
1967 i.value()->setText(QString(_("Transform to %1")).
1968 /* TRANS: Transfrom terrain to specific type */
1969 arg(QString(get_tile_change_menu_text
1970 (unit_tile(punit), ACTIVITY_IRRIGATE))));
1971 } else if (units_have_type_flag(punits, UTYF_SETTLERS, TRUE)){
1972 struct extra_type *pextra = NULL;
1974 /* FIXME: this overloading doesn't work well with multiple focus
1975 * units. */
1976 unit_list_iterate(punits, builder) {
1977 pextra = next_extra_for_tile(unit_tile(builder), EC_IRRIGATION,
1978 unit_owner(builder), builder);
1979 if (pextra != NULL) {
1980 break;
1982 } unit_list_iterate_end;
1984 if (pextra != NULL) {
1985 /* TRANS: Build irrigation of specific type */
1986 i.value()->setText(QString(_("Build %1"))
1987 .arg(extra_name_translation(pextra)));
1988 } else {
1989 i.value()->setText(QString(_("Build Irrigation")));
1991 } else {
1992 i.value()->setText(QString(_("Build Irrigation")));
1995 break;
1997 case TRANSFORM:
1998 if (can_units_do_activity(punits, ACTIVITY_TRANSFORM)) {
1999 i.value()->setEnabled(true);
2000 } else {
2001 break;
2003 if (units_all_same_tile) {
2004 struct unit *punit = unit_list_get(punits, 0);
2005 pterrain = tile_terrain(unit_tile(punit));
2006 punit = unit_list_get(punits, 0);
2007 pterrain = tile_terrain(unit_tile(punit));
2008 if (pterrain->transform_result != T_NONE
2009 && pterrain->transform_result != pterrain) {
2010 i.value()->setText(QString(_("Transform to %1")).
2011 /* TRANS: Transfrom terrain to specific type */
2012 arg(QString(get_tile_change_menu_text
2013 (unit_tile(punit), ACTIVITY_TRANSFORM))));
2014 } else {
2015 i.value()->setText(_("Transform Terrain"));
2018 break;
2020 case BUILD:
2021 if (can_units_do(punits, unit_can_add_or_build_city)) {
2022 i.value()->setEnabled(true);
2024 if (city_on_tile
2025 && units_can_do_action(punits, ACTION_JOIN_CITY, true)) {
2026 i.value()->setText(action_id_name_translation(ACTION_JOIN_CITY));
2027 } else {
2028 i.value()->setText(action_id_name_translation(ACTION_FOUND_CITY));
2030 break;
2032 case ROAD:
2034 char road_item[500];
2035 struct extra_type *pextra = nullptr;
2037 if (can_units_do_any_road(punits)) {
2038 i.value()->setEnabled(true);
2040 unit_list_iterate(punits, punit) {
2041 pextra = next_extra_for_tile(unit_tile(punit), EC_ROAD,
2042 unit_owner(punit), punit);
2043 if (pextra != nullptr) {
2044 break;
2046 } unit_list_iterate_end;
2048 if (pextra != nullptr) {
2049 fc_snprintf(road_item, sizeof(road_item), _("Build %s"),
2050 extra_name_translation(pextra));
2051 i.value()->setText(road_item);
2054 break;
2056 case MIGRANT:
2057 if (units_can_do_action(punits, ACTION_JOIN_CITY, true)) {
2058 i.value()->setEnabled(true);
2060 break;
2062 case FORTIFY:
2063 if (can_units_do_activity(punits, ACTIVITY_FORTIFYING)) {
2064 i.value()->setEnabled(true);
2066 break;
2068 case FORTRESS:
2069 if (can_units_do_base_gui(punits, BASE_GUI_FORTRESS)) {
2070 i.value()->setEnabled(true);
2072 break;
2074 case AIRBASE:
2075 if (can_units_do_base_gui(punits, BASE_GUI_AIRBASE)) {
2076 i.value()->setEnabled(true);
2078 break;
2080 case POLLUTION:
2081 if (can_units_do_activity(punits, ACTIVITY_POLLUTION)
2082 || can_units_do(punits, can_unit_paradrop)) {
2083 i.value()->setEnabled(true);
2085 if (units_can_do_action(punits, ACTION_PARADROP, true)) {
2086 i.value()->setText(action_id_name_translation(ACTION_PARADROP));
2087 } else {
2088 i.value()->setText(_("Clean Pollution"));
2090 break;
2092 case FALLOUT:
2093 if (can_units_do_activity(punits, ACTIVITY_FALLOUT)) {
2094 i.value()->setEnabled(true);
2096 break;
2098 case SENTRY:
2099 if (can_units_do_activity(punits, ACTIVITY_SENTRY)) {
2100 i.value()->setEnabled(true);
2102 break;
2104 case PILLAGE:
2105 if (can_units_do_activity(punits, ACTIVITY_PILLAGE)) {
2106 i.value()->setEnabled(true);
2108 break;
2110 case HOMECITY:
2111 if (can_units_do(punits, can_unit_change_homecity)) {
2112 i.value()->setEnabled(true);
2114 break;
2116 case WAKEUP:
2117 if (units_have_activity_on_tile(punits, ACTIVITY_SENTRY)) {
2118 i.value()->setEnabled(true);
2120 break;
2122 case AUTOSETTLER:
2123 if (can_units_do(punits, can_unit_do_autosettlers)) {
2124 i.value()->setEnabled(true);
2126 if (units_contain_cityfounder(punits)) {
2127 i.value()->setText(_("Auto Settler"));
2128 } else {
2129 i.value()->setText(_("Auto Worker"));
2131 break;
2132 case GO_AND_BUILD_CITY:
2133 if (units_contain_cityfounder(punits)) {
2134 i.value()->setEnabled(true);
2136 break;
2137 case CONNECT_ROAD:
2138 proad = road_by_compat_special(ROCO_ROAD);
2139 if (proad != NULL) {
2140 tgt = road_extra_get(proad);
2141 } else {
2142 break;
2144 if (can_units_do_connect(punits, ACTIVITY_GEN_ROAD, tgt)) {
2145 i.value()->setEnabled(true);
2147 break;
2149 case DISBAND:
2150 if (units_can_do_action(punits, ACTION_DISBAND_UNIT, true)) {
2151 i.value()->setEnabled(true);
2154 case CONNECT_RAIL:
2155 proad = road_by_compat_special(ROCO_RAILROAD);
2156 if (proad != NULL) {
2157 tgt = road_extra_get(proad);
2158 } else {
2159 break;
2161 if (can_units_do_connect(punits, ACTIVITY_GEN_ROAD, tgt)) {
2162 i.value()->setEnabled(true);
2164 break;
2166 case CONNECT_IRRIGATION:
2168 struct extra_type_list *extras = extra_type_list_by_cause(EC_IRRIGATION);
2170 if (extra_type_list_size(extras) > 0) {
2171 struct extra_type *pextra;
2173 pextra = extra_type_list_get(extra_type_list_by_cause(EC_IRRIGATION), 0);
2174 if (can_units_do_connect(punits, ACTIVITY_IRRIGATE, pextra)) {
2175 i.value()->setEnabled(true);
2179 break;
2181 case GOTO_CITY:
2182 if (any_cities) {
2183 i.value()->setEnabled(true);
2185 break;
2187 case AIRLIFT:
2188 if (any_cities) {
2189 i.value()->setEnabled(true);
2191 break;
2193 case BUILD_WONDER:
2194 i.value()->setText(action_id_name_translation(ACTION_HELP_WONDER));
2195 if (can_units_do(punits, unit_can_help_build_wonder_here)) {
2196 i.value()->setEnabled(true);
2198 break;
2200 case AUTOTRADEROUTE:
2201 if (units_can_do_action(punits, ACTION_TRADE_ROUTE, TRUE)) {
2202 i.value()->setEnabled(true);
2204 break;
2206 case ORDER_TRADEROUTE:
2207 i.value()->setText(action_id_name_translation(ACTION_TRADE_ROUTE));
2208 if (can_units_do(punits, unit_can_est_trade_route_here)) {
2209 i.value()->setEnabled(true);
2211 break;
2213 case ORDER_DIPLOMAT_DLG:
2214 if (units_can_do_action(punits, ACTION_ANY, TRUE)) {
2215 i.value()->setEnabled(true);
2217 break;
2219 case NUKE:
2220 i.value()->setText(action_id_name_translation(ACTION_NUKE));
2221 if (units_can_do_action(punits, ACTION_NUKE, TRUE)) {
2222 i.value()->setEnabled(true);
2224 break;
2226 case UPGRADE:
2227 if (units_can_upgrade(punits)) {
2228 i.value()->setEnabled(true);
2230 break;
2231 default:
2232 break;
2235 i++;
2240 /***************************************************************************
2241 Slot for showing research tab
2242 ***************************************************************************/
2243 void mr_menu::slot_show_research_tab()
2245 science_report_dialog_popup(true);
2248 /***************************************************************************
2249 Slot for showing spaceship
2250 ***************************************************************************/
2251 void mr_menu::slot_spaceship()
2253 if (NULL != client.conn.playing) {
2254 popup_spaceship_dialog(client.conn.playing);
2258 /***************************************************************************
2259 Slot for showing economy tab
2260 ***************************************************************************/
2261 void mr_menu::slot_show_eco_report()
2263 economy_report_dialog_popup(false);
2266 /***************************************************************************
2267 Changes tab to mapview
2268 ***************************************************************************/
2269 void mr_menu::slot_show_map()
2271 ::gui()->game_tab_widget->setCurrentIndex(0);
2274 /***************************************************************************
2275 Slot for showing units tab
2276 ***************************************************************************/
2277 void mr_menu::slot_show_units_report()
2279 toggle_units_report(true);
2282 /***************************************************************************
2283 Slot for showing nations report
2284 ***************************************************************************/
2285 void mr_menu::slot_show_nations()
2287 popup_players_dialog(false);
2290 /***************************************************************************
2291 Slot for showing cities report
2292 ***************************************************************************/
2293 void mr_menu::slot_show_cities()
2295 city_report_dialog_popup(false);
2298 /****************************************************************
2299 Action "BUILD_CITY"
2300 *****************************************************************/
2301 void mr_menu::slot_build_city()
2303 unit_list_iterate(get_units_in_focus(), punit) {
2304 /* FIXME: this can provide different actions for different units...
2305 * not good! */
2306 /* Enable the button for adding to a city in all cases, so we
2307 get an eventual error message from the server if we try. */
2308 if (unit_can_add_or_build_city(punit)) {
2309 request_unit_build_city(punit);
2310 } else if (utype_can_do_action(unit_type_get(punit), ACTION_HELP_WONDER)) {
2311 request_unit_caravan_action(punit, ACTION_HELP_WONDER);
2313 } unit_list_iterate_end;
2316 /***************************************************************************
2317 Action "CLEAN FALLOUT"
2318 ***************************************************************************/
2319 void mr_menu::slot_clean_fallout()
2321 key_unit_fallout();
2324 /***************************************************************************
2325 Action "CLEAN POLLUTION and PARADROP"
2326 ***************************************************************************/
2327 void mr_menu::slot_clean_pollution()
2329 unit_list_iterate(get_units_in_focus(), punit) {
2330 /* FIXME: this can provide different actions for different units...
2331 * not good! */
2332 struct extra_type *pextra;
2334 pextra = prev_extra_in_tile(unit_tile(punit), ERM_CLEANPOLLUTION,
2335 unit_owner(punit), punit);
2336 if (pextra != NULL) {
2337 request_new_unit_activity_targeted(punit, ACTIVITY_POLLUTION, pextra);
2338 } else if (can_unit_paradrop(punit)) {
2339 /* FIXME: This is getting worse, we use a key_unit_*() function
2340 * which assign the order for all units! Very bad! */
2341 key_unit_paradrop();
2343 } unit_list_iterate_end;
2346 /***************************************************************************
2347 Action "CONNECT WITH IRRIGATION"
2348 ***************************************************************************/
2349 void mr_menu::slot_conn_irrigation()
2351 struct extra_type_list *extras = extra_type_list_by_cause(EC_IRRIGATION);
2353 if (extra_type_list_size(extras) > 0) {
2354 struct extra_type *pextra;
2356 pextra = extra_type_list_get(extra_type_list_by_cause(EC_IRRIGATION), 0);
2358 key_unit_connect(ACTIVITY_IRRIGATE, pextra);
2362 /***************************************************************************
2363 Action "CONNECT WITH RAILROAD"
2364 ***************************************************************************/
2365 void mr_menu::slot_conn_rail()
2367 struct road_type *prail = road_by_compat_special(ROCO_RAILROAD);
2369 if (prail != NULL) {
2370 struct extra_type *tgt;
2372 tgt = road_extra_get(prail);
2373 key_unit_connect(ACTIVITY_GEN_ROAD, tgt);
2377 /***************************************************************************
2378 Action "BUILD FORTRESS"
2379 ***************************************************************************/
2380 void mr_menu::slot_unit_fortress()
2382 key_unit_fortress();
2385 /***************************************************************************
2386 Action "BUILD AIRBASE"
2387 ***************************************************************************/
2388 void mr_menu::slot_unit_airbase()
2390 key_unit_airbase();
2393 /***************************************************************************
2394 Action "CONNECT WITH ROAD"
2395 ***************************************************************************/
2396 void mr_menu::slot_conn_road()
2398 struct road_type *proad = road_by_compat_special(ROCO_ROAD);
2400 if (proad != NULL) {
2401 struct extra_type *tgt;
2403 tgt = road_extra_get(proad);
2404 key_unit_connect(ACTIVITY_GEN_ROAD, tgt);
2408 /***************************************************************************
2409 Action "GO TO AND BUILD CITY"
2410 ***************************************************************************/
2411 void mr_menu::slot_go_build_city()
2413 request_unit_goto(ORDER_PERFORM_ACTION, ACTION_FOUND_CITY, EXTRA_NONE);
2416 /***************************************************************************
2417 Action "GO TO AND JOIN CITY"
2418 ***************************************************************************/
2419 void mr_menu::slot_go_join_city()
2421 request_unit_goto(ORDER_PERFORM_ACTION, ACTION_JOIN_CITY, EXTRA_NONE);
2424 /***************************************************************************
2425 Action "TRANSFROM TERRAIN"
2426 ***************************************************************************/
2427 void mr_menu::slot_transform()
2429 key_unit_transform();
2432 /***************************************************************************
2433 Action "PILLAGE"
2434 ***************************************************************************/
2435 void mr_menu::slot_pillage()
2437 key_unit_pillage();
2440 /***************************************************************************
2441 Do... the selected action
2442 ***************************************************************************/
2443 void mr_menu::slot_action()
2445 key_unit_action_select_tgt();
2448 /***************************************************************************
2449 Explode Nuclear
2450 ***************************************************************************/
2451 void mr_menu::slot_nuke()
2453 key_unit_nuke();
2457 /****************************************************************
2458 Action "AUTO_SETTLER"
2459 *****************************************************************/
2460 void mr_menu::slot_auto_settler()
2462 key_unit_auto_settle();
2465 /****************************************************************
2466 Action "BUILD_ROAD"
2467 *****************************************************************/
2468 void mr_menu::slot_build_road()
2470 unit_list_iterate(get_units_in_focus(), punit) {
2471 /* FIXME: this can provide different actions for different units...
2472 * not good! */
2473 struct extra_type *tgt = next_extra_for_tile(unit_tile(punit),
2474 EC_ROAD,
2475 unit_owner(punit),
2476 punit);
2477 bool building_road = false;
2479 if (tgt != NULL
2480 && can_unit_do_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt)) {
2481 request_new_unit_activity_targeted(punit, ACTIVITY_GEN_ROAD, tgt);
2482 building_road = true;
2485 if (!building_road && unit_can_est_trade_route_here(punit)) {
2486 request_unit_caravan_action(punit, ACTION_TRADE_ROUTE);
2488 } unit_list_iterate_end;
2491 /****************************************************************
2492 Action "BUILD_IRRIGATION"
2493 *****************************************************************/
2494 void mr_menu::slot_build_irrigation()
2496 key_unit_irrigate();
2499 /****************************************************************
2500 Action "BUILD_MINE"
2501 *****************************************************************/
2502 void mr_menu::slot_build_mine()
2504 key_unit_mine();
2506 /****************************************************************
2507 Action "FORTIFY"
2508 *****************************************************************/
2509 void mr_menu::slot_unit_fortify()
2511 key_unit_fortify();
2514 /****************************************************************
2515 Action "SENTRY"
2516 *****************************************************************/
2517 void mr_menu::slot_unit_sentry()
2519 key_unit_sentry();
2522 /***************************************************************************
2523 Action "CONVERT"
2524 ***************************************************************************/
2525 void mr_menu::slot_convert()
2527 key_unit_convert();
2530 /***************************************************************************
2531 Action "DISBAND UNIT"
2532 ***************************************************************************/
2533 void mr_menu::slot_disband()
2535 popup_disband_dialog(get_units_in_focus());
2538 /***************************************************************************
2539 Clears delayed orders
2540 ***************************************************************************/
2541 void mr_menu::slot_orders_clear()
2543 delayed_order = false;
2544 units_list.clear();
2547 /***************************************************************************
2548 Sets/unset rally point
2549 ***************************************************************************/
2550 void mr_menu::slot_rally()
2552 gui()->rallies.hover_tile = false;
2553 gui()->rallies.hover_city = true;
2556 /***************************************************************************
2557 Adds one city to trade planning
2558 ***************************************************************************/
2559 void mr_menu::slot_trade_city()
2561 gui()->trade_gen.hover_city = true;
2563 /***************************************************************************
2564 Adds all cities to trade planning
2565 ***************************************************************************/
2566 void mr_menu::slot_trade_add_all()
2568 gui()->trade_gen.add_all_cities();
2571 /***************************************************************************
2572 Trade calculation slot
2573 ***************************************************************************/
2574 void mr_menu::slot_calculate()
2576 gui()->trade_gen.calculate();
2579 /**************************************************************************
2580 Slot for clearing trade routes
2581 **************************************************************************/
2582 void mr_menu::slot_clear_trade()
2584 gui()->trade_gen.clear_trade_planing();
2587 /***************************************************************************
2588 Sends automatic caravan
2589 ***************************************************************************/
2590 void mr_menu::slot_autocaravan()
2592 qtiles gilles;
2593 struct unit *punit;
2594 struct city *homecity;
2595 struct tile *home_tile;
2596 struct tile *dest_tile;
2597 bool sent = false;
2599 punit = head_of_units_in_focus();
2600 homecity = game_city_by_number(punit->homecity);
2601 home_tile = homecity->tile;
2602 foreach(gilles, gui()->trade_gen.lines) {
2603 if ((gilles.t1 == home_tile || gilles.t2 == home_tile)
2604 && gilles.autocaravan == nullptr) {
2605 /* send caravan */
2606 if (gilles.t1 == home_tile) {
2607 dest_tile = gilles.t2;
2608 } else {
2609 dest_tile = gilles.t1;
2611 if (send_goto_tile(punit, dest_tile)) {
2612 int i;
2613 i = gui()->trade_gen.lines.indexOf(gilles);
2614 gilles = gui()->trade_gen.lines.takeAt(i);
2615 gilles.autocaravan = punit;
2616 gui()->trade_gen.lines.append(gilles);
2617 sent = true;
2618 break;
2623 if (!sent) {
2624 gui()->infotab->chtwdg->append(_("Didn't find any trade route"
2625 " to establish"));
2629 /**************************************************************************
2630 Slot for setting quick airlift
2631 **************************************************************************/
2632 void mr_menu::slot_quickairlift_set()
2634 QVariant v;
2635 QAction *act;
2637 act = qobject_cast<QAction *>(sender());
2638 v = act->data();
2639 airlift_type_id = v.toInt();
2642 /**************************************************************************
2643 Slot for choosing default action vs unit
2644 **************************************************************************/
2645 void mr_menu::slot_action_vs_unit()
2647 QAction *act;
2649 act = qobject_cast<QAction *>(sender());
2650 qdef_act::action()->vs_unit_set(act->data().toInt());
2654 /**************************************************************************
2655 Slot for choosing default action vs city
2656 **************************************************************************/
2657 void mr_menu::slot_action_vs_city()
2659 QAction *act;
2661 act = qobject_cast<QAction *>(sender());
2662 qdef_act::action()->vs_city_set(act->data().toInt());
2665 /**************************************************************************
2666 Slot for quick airlifting
2667 **************************************************************************/
2668 void mr_menu::slot_quickairlift()
2670 quick_airlifting = true;
2674 /***************************************************************************
2675 Delayed goto
2676 ***************************************************************************/
2677 void mr_menu::slot_delayed_goto()
2679 qfc_delayed_unit_item *unit_item;
2680 int i = 0;
2681 delay_order dg;
2682 delayed_order = true;
2683 dg = D_GOTO;
2685 struct unit_list *punits = get_units_in_focus();
2686 if (unit_list_size(punits) == 0) {
2687 return;
2689 if (hover_state != HOVER_GOTO) {
2690 set_hover_state(punits, HOVER_GOTO, ACTIVITY_LAST, NULL,
2691 EXTRA_NONE, ACTION_NONE, ORDER_LAST);
2692 enter_goto_state(punits);
2693 create_line_at_mouse_pos();
2694 control_mouse_cursor(NULL);
2696 unit_list_iterate(get_units_in_focus(), punit) {
2697 i++;
2698 unit_item = new qfc_delayed_unit_item(dg, punit->id);
2699 units_list.add(unit_item);
2700 units_list.nr_units = i;
2701 } unit_list_iterate_end;
2704 /***************************************************************************
2705 Executes stored orders
2706 ***************************************************************************/
2707 void mr_menu::slot_execute_orders()
2709 qfc_delayed_unit_item *fui;
2710 struct unit *punit;
2711 struct tile *last_tile;
2712 struct tile *new_tile;
2713 int i = 0;
2715 foreach (fui, units_list.unit_list) {
2716 i++;
2717 punit = unit_list_find(client_player()->units, fui->id);
2718 if (punit == nullptr) {
2719 continue;
2721 last_tile = punit->tile;
2722 new_tile = find_last_unit_pos(punit, i);
2723 if (new_tile != nullptr) {
2724 punit->tile = new_tile;
2726 if (is_tiles_adjacent(punit->tile, fui->ptile)) {
2727 request_move_unit_direction(punit, get_direction_for_step(punit->tile,
2728 fui->ptile));
2729 } else {
2730 send_attack_tile(punit, fui->ptile);
2732 punit->tile = last_tile;
2734 units_list.clear();
2737 /***************************************************************************
2738 Action "LOAD INTO TRANSPORTER"
2739 ***************************************************************************/
2740 void mr_menu::slot_load()
2742 unit_list_iterate(get_units_in_focus(), punit) {
2743 qtg_request_transport(punit, unit_tile(punit));
2744 } unit_list_iterate_end;
2747 /***************************************************************************
2748 Action "UNIT PATROL"
2749 ***************************************************************************/
2750 void mr_menu::slot_patrol()
2752 key_unit_patrol();
2755 /***************************************************************************
2756 Action "RETURN TO NEAREST CITY"
2757 ***************************************************************************/
2758 void mr_menu::slot_return_to_city()
2760 unit_list_iterate(get_units_in_focus(), punit) {
2761 request_unit_return(punit);
2762 } unit_list_iterate_end;
2765 /***************************************************************************
2766 Action "GOTO/AIRLIFT TO CITY"
2767 ***************************************************************************/
2768 void mr_menu::slot_airlift()
2770 popup_goto_dialog();
2773 /***************************************************************************
2774 Action "SET HOMECITY"
2775 ***************************************************************************/
2776 void mr_menu::slot_set_home()
2778 key_unit_homecity();
2781 /***************************************************************************
2782 Action "UNLOAD FROM TRANSPORTED"
2783 ***************************************************************************/
2784 void mr_menu::slot_unload()
2786 unit_list_iterate(get_units_in_focus(), punit) {
2787 request_unit_unload(punit);
2788 } unit_list_iterate_end;
2791 /***************************************************************************
2792 Action "UNLOAD ALL UNITS FROM TRANSPORTER"
2793 ***************************************************************************/
2794 void mr_menu::slot_unload_all()
2796 key_unit_unload_all();
2799 /***************************************************************************
2800 Action "UNSENTRY(WAKEUP) ALL UNITS"
2801 ***************************************************************************/
2802 void mr_menu::slot_unsentry()
2804 key_unit_wakeup_others();
2807 /***************************************************************************
2808 Action "UPGRADE UNITS"
2809 ***************************************************************************/
2810 void mr_menu::slot_upgrade()
2812 popup_upgrade_dialog(get_units_in_focus());
2815 /****************************************************************
2816 Action "GOTO"
2817 *****************************************************************/
2818 void mr_menu::slot_unit_goto()
2820 key_unit_goto();
2823 /****************************************************************
2824 Action "EXPLORE"
2825 *****************************************************************/
2826 void mr_menu::slot_unit_explore()
2828 key_unit_auto_explore();
2831 /****************************************************************
2832 Action "CENTER VIEW"
2833 *****************************************************************/
2834 void mr_menu::slot_center_view()
2836 request_center_focus_unit();
2839 /****************************************************************
2840 Action "Lock interface"
2841 *****************************************************************/
2842 void mr_menu::slot_lock()
2844 if (gui()->interface_locked) {
2845 enable_interface(false);
2846 } else {
2847 enable_interface(true);
2849 gui()->interface_locked = !gui()->interface_locked;
2852 /****************************************************************
2853 Helper function to hide/show widgets
2854 *****************************************************************/
2855 void enable_interface(bool enable)
2857 QList<close_widget *> lc;
2858 QList<move_widget *> lm;
2859 QList<resize_widget *> lr;
2860 int i;
2862 lc = gui()->findChildren<close_widget *>();
2863 lm = gui()->findChildren<move_widget *>();
2864 lr = gui()->findChildren<resize_widget *>();
2866 for (i = 0; i < lc.size(); ++i) {
2867 lc.at(i)->setVisible(!enable);
2869 for (i = 0; i < lm.size(); ++i) {
2870 lm.at(i)->setVisible(!enable);
2872 for (i = 0; i < lr.size(); ++i) {
2873 lr.at(i)->setVisible(!enable);
2877 /***************************************************************************
2878 Action "SET FULLSCREEN"
2879 ***************************************************************************/
2880 void mr_menu::slot_fullscreen()
2882 if (!gui_options.gui_qt_fullscreen) {
2883 gui()->showFullScreen();
2884 gui()->game_tab_widget->showFullScreen();
2885 } else {
2886 // FIXME Doesnt return properly, probably something with sidebar
2887 gui()->showNormal();
2888 gui()->game_tab_widget->showNormal();
2890 gui_options.gui_qt_fullscreen = !gui_options.gui_qt_fullscreen;
2893 /****************************************************************
2894 Action "VIEW/HIDE MINIMAP"
2895 *****************************************************************/
2896 void mr_menu::slot_minimap_view()
2898 if (minimap_status->isChecked()) {
2899 ::gui()->minimapview_wdg->show();
2900 } else {
2901 ::gui()->minimapview_wdg->hide();
2905 /****************************************************************
2906 Action "Show/Dont show new turn info"
2907 *****************************************************************/
2908 void mr_menu::slot_show_new_turn_text()
2910 if (osd_status->isChecked()) {
2911 gui()->qt_settings.show_new_turn_text = true;
2912 } else {
2913 gui()->qt_settings.show_new_turn_text = false;
2917 /****************************************************************
2918 Action "Show/Dont battle log"
2919 *****************************************************************/
2920 void mr_menu::slot_battlelog()
2922 if (btlog_status->isChecked()) {
2923 gui()->qt_settings.show_battle_log = true;
2924 } else {
2925 gui()->qt_settings.show_battle_log = false;
2929 /****************************************************************
2930 Action "SHOW BORDERS"
2931 *****************************************************************/
2932 void mr_menu::slot_borders()
2934 key_map_borders_toggle();
2937 /****************************************************************
2938 Action "SHOW NATIVE TILES"
2939 *****************************************************************/
2940 void mr_menu::slot_native_tiles()
2942 key_map_native_toggle();
2945 /***************************************************************************
2946 Action "SHOW BUY COST"
2947 ***************************************************************************/
2948 void mr_menu::slot_city_buycost()
2950 key_city_buycost_toggle();
2953 /***************************************************************************
2954 Action "SHOW CITY GROWTH"
2955 ***************************************************************************/
2956 void mr_menu::slot_city_growth()
2958 key_city_growth_toggle();
2961 /***************************************************************************
2962 Action "RELOAD ZOOMED IN TILESET"
2963 ***************************************************************************/
2964 void mr_menu::zoom_in()
2966 gui()->map_scale = gui()->map_scale * 1.2f;
2967 tilespec_reread(tileset_basename(tileset), true, gui()->map_scale);
2970 /***************************************************************************
2971 Action "RELOAD ZOOMED OUT TILESET"
2972 ***************************************************************************/
2973 void mr_menu::zoom_out()
2975 gui()->map_scale = gui()->map_scale / 1.2f;
2976 tilespec_reread(tileset_basename(tileset), true, gui()->map_scale);
2979 /***************************************************************************
2980 Action "SHOW CITY NAMES"
2981 ***************************************************************************/
2982 void mr_menu::slot_city_names()
2984 key_city_names_toggle();
2987 /***************************************************************************
2988 Action "SHOW CITY OUTLINES"
2989 ***************************************************************************/
2990 void mr_menu::slot_city_outlines()
2992 key_city_outlines_toggle();
2995 /***************************************************************************
2996 Action "SHOW CITY OUTPUT"
2997 ***************************************************************************/
2998 void mr_menu::slot_city_output()
3000 key_city_output_toggle();
3003 /***************************************************************************
3004 Action "SHOW CITY PRODUCTION"
3005 ***************************************************************************/
3006 void mr_menu::slot_city_production()
3008 key_city_productions_toggle();
3011 /***************************************************************************
3012 Action "SHOW CITY TRADEROUTES"
3013 ***************************************************************************/
3014 void mr_menu::slot_city_traderoutes()
3016 key_city_trade_routes_toggle();
3019 /***************************************************************************
3020 Action "SHOW FULLBAR"
3021 ***************************************************************************/
3022 void mr_menu::slot_fullbar()
3024 key_city_full_bar_toggle();
3027 /***************************************************************************
3028 Action "SHOW MAP GRID"
3029 ***************************************************************************/
3030 void mr_menu::slot_map_grid()
3032 key_map_grid_toggle();
3035 /***************************************************************************
3036 Action "DONE MOVING"
3037 ***************************************************************************/
3038 void mr_menu::slot_done_moving()
3040 key_unit_done();
3043 /***************************************************************************
3044 Action "SELECT ALL UNITS ON TILE"
3045 ***************************************************************************/
3046 void mr_menu::slot_select_all_tile()
3048 request_unit_select(get_units_in_focus(), SELTYPE_ALL, SELLOC_TILE);
3051 /***************************************************************************
3052 Action "SELECT ONE UNITS/DESELECT OTHERS"
3053 ***************************************************************************/
3054 void mr_menu::slot_select_one()
3056 request_unit_select(get_units_in_focus(), SELTYPE_SINGLE, SELLOC_TILE);
3059 /***************************************************************************
3060 Action "SELLECT SAME UNITS ON CONTINENT"
3061 ***************************************************************************/
3062 void mr_menu::slot_select_same_continent()
3064 request_unit_select(get_units_in_focus(), SELTYPE_SAME, SELLOC_CONT);
3067 /***************************************************************************
3068 Action "SELECT SAME TYPE EVERYWHERE"
3069 ***************************************************************************/
3070 void mr_menu::slot_select_same_everywhere()
3072 request_unit_select(get_units_in_focus(), SELTYPE_SAME, SELLOC_WORLD);
3075 /***************************************************************************
3076 Action "SELECT SAME TYPE ON TILE"
3077 ***************************************************************************/
3078 void mr_menu::slot_select_same_tile()
3080 request_unit_select(get_units_in_focus(), SELTYPE_SAME, SELLOC_TILE);
3084 /***************************************************************************
3085 Action "WAIT"
3086 ***************************************************************************/
3087 void mr_menu::slot_wait()
3089 key_unit_wait();
3092 /***************************************************************************
3093 Shows units filter
3094 ***************************************************************************/
3095 void mr_menu::slot_unit_filter()
3097 unit_hud_selector *uhs;
3098 uhs = new unit_hud_selector(gui()->central_wdg);
3099 uhs->show_me();
3103 /****************************************************************
3104 Action "SHOW DEMOGRAPGHICS REPORT"
3105 *****************************************************************/
3106 void mr_menu::slot_demographics()
3108 send_report_request(REPORT_DEMOGRAPHIC);
3111 /****************************************************************
3112 Action "SHOW ACHIEVEMENTS REPORT"
3113 *****************************************************************/
3114 void mr_menu::slot_achievements()
3116 send_report_request(REPORT_ACHIEVEMENTS);
3119 /****************************************************************
3120 Action "SHOW ENDGAME REPORT"
3121 *****************************************************************/
3122 void mr_menu::slot_endgame()
3124 popup_endgame_report();
3128 /****************************************************************
3129 Action "SHOW TOP FIVE CITIES"
3130 *****************************************************************/
3131 void mr_menu::slot_top_five()
3133 send_report_request(REPORT_TOP_5_CITIES);
3136 /****************************************************************
3137 Action "SHOW WONDERS REPORT"
3138 *****************************************************************/
3139 void mr_menu::slot_traveler()
3141 send_report_request(REPORT_WONDERS_OF_THE_WORLD);
3144 /****************************************************************
3145 Shows rulesets to load
3146 *****************************************************************/
3147 void mr_menu::tileset_custom_load()
3149 QDialog *dialog = new QDialog(this);
3150 QLabel *label;
3151 QPushButton *but;
3152 QVBoxLayout *layout;
3153 const struct strvec *tlset_list;
3154 const struct option *poption;
3155 QStringList sl;
3156 QString s;
3158 sl << "default_tileset_overhead_name" << "default_tileset_iso_name"
3159 << "default_tileset_hex_name" << "default_tileset_isohex_name";
3160 layout = new QVBoxLayout;
3161 dialog->setWindowTitle(_("Available tilesets"));
3162 label = new QLabel;
3163 label->setText(_("Some tilesets might be not compatible with current"
3164 " map topology!"));
3165 layout->addWidget(label);
3167 foreach (s, sl) {
3168 poption = optset_option_by_name(client_optset, s.toLocal8Bit().data());
3169 tlset_list = get_tileset_list(poption);
3170 strvec_iterate(tlset_list, value) {
3171 but = new QPushButton(value);
3172 connect(but, SIGNAL(clicked()), this, SLOT(load_new_tileset()));
3173 layout->addWidget(but);
3174 } strvec_iterate_end;
3176 dialog->setSizeGripEnabled(true);
3177 dialog->setLayout(layout);
3178 dialog->show();
3181 /****************************************************************
3182 Slot for loading new tileset
3183 *****************************************************************/
3184 void mr_menu::load_new_tileset()
3186 QPushButton *but;
3188 but = qobject_cast<QPushButton *>(sender());
3189 tilespec_reread(but->text().toLocal8Bit().data(), true, 1.0f);
3190 gui()->map_scale = 1.0f;
3191 but->parentWidget()->close();
3194 /****************************************************************
3195 Action "Calculate trade routes"
3196 *****************************************************************/
3197 void mr_menu::calc_trade_routes()
3199 gui()->trade_gen.calculate();
3202 /****************************************************************
3203 Action "TAX RATES"
3204 *****************************************************************/
3205 void mr_menu::slot_popup_tax_rates()
3207 popup_rates_dialog();
3210 /****************************************************************
3211 Action "MULTIPLERS RATES"
3212 *****************************************************************/
3213 void mr_menu::slot_popup_mult_rates()
3215 popup_multiplier_dialog();
3218 /****************************************************************
3219 Actions "HELP_*"
3220 *****************************************************************/
3221 void mr_menu::slot_help(const QString &topic)
3223 popup_help_dialog_typed(Q_(topic.toStdString().c_str()), HELP_ANY);
3226 /****************************************************************
3227 Invoke dialog with local options
3228 *****************************************************************/
3229 void mr_menu::local_options()
3231 gui()->popup_client_options();
3234 /****************************************************************
3235 Invoke dialog with shortcut options
3236 *****************************************************************/
3237 void mr_menu::shortcut_options()
3239 popup_shortcuts_dialog();
3243 /****************************************************************
3244 Invoke dialog with server options
3245 *****************************************************************/
3246 void mr_menu::server_options()
3248 gui()->pr_options->popup_server_options();
3251 /****************************************************************
3252 Invoke dialog with server options
3253 *****************************************************************/
3254 void mr_menu::messages_options()
3256 popup_messageopt_dialog();
3259 /****************************************************************
3260 Menu Save Options Now
3261 *****************************************************************/
3262 void mr_menu::save_options_now()
3264 options_save(NULL);
3267 /***************************************************************************
3268 Invoke popup for quiting game
3269 ***************************************************************************/
3270 void mr_menu::quit_game()
3272 popup_quit_dialog();
3275 /***************************************************************************
3276 Menu Save Map Image
3277 ***************************************************************************/
3278 void mr_menu::save_image()
3280 int current_width, current_height;
3281 int full_size_x, full_size_y;
3282 QString path, storage_path;
3283 hud_message_box saved(gui()->central_wdg);
3284 bool map_saved;
3285 QString img_name;
3287 full_size_x = (wld.map.xsize + 2) * tileset_tile_width(tileset);
3288 full_size_y = (wld.map.ysize + 2) * tileset_tile_height(tileset);
3289 current_width = gui()->mapview_wdg->width();
3290 current_height = gui()->mapview_wdg->height();
3291 if (tileset_hex_width(tileset) > 0) {
3292 full_size_y = full_size_y * 11 / 20;
3293 } else if (tileset_is_isometric(tileset)) {
3294 full_size_y = full_size_y / 2;
3296 map_canvas_resized(full_size_x, full_size_y);
3297 img_name = QString("FreeCiv-Turn%1").arg(game.info.turn);
3298 if (client_has_player() == true) {
3299 img_name = img_name + "-"
3300 + QString(nation_plural_for_player(client_player()));
3302 storage_path = freeciv_storage_dir();
3303 path = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
3304 if (storage_path.isEmpty() == false && QDir(storage_path).isReadable()) {
3305 img_name = storage_path + DIR_SEPARATOR + img_name;
3306 } else if (path.isEmpty() == false) {
3307 img_name = path + DIR_SEPARATOR + img_name;
3308 } else {
3309 img_name = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
3310 + DIR_SEPARATOR + img_name;
3312 map_saved = mapview.store->map_pixmap.save(img_name, "png");
3313 map_canvas_resized(current_width, current_height);
3314 saved.setStandardButtons(QMessageBox::Ok);
3315 saved.setDefaultButton(QMessageBox::Cancel);
3316 if (map_saved) {
3317 saved.set_text_title("Image saved as:\n" + img_name, _("Succeess"));
3318 } else {
3319 saved.set_text_title(_("Failed to save image of the map"), _("Error"));
3321 saved.exec();
3324 /***************************************************************************
3325 Menu Save Game
3326 ***************************************************************************/
3327 void mr_menu::save_game()
3329 send_save_game(NULL);
3332 /***************************************************************************
3333 Menu Save Game As...
3334 ***************************************************************************/
3335 void mr_menu::save_game_as()
3337 QString str;
3338 QString current_file;
3339 QString location;
3341 strvec_iterate(get_save_dirs(), dirname) {
3342 location = dirname;
3343 // choose last location
3344 } strvec_iterate_end;
3346 str = QString(_("Save Games"))
3347 + QString(" (*.sav *.sav.bz2 *.sav.gz *.sav.xz)");
3348 current_file = QFileDialog::getSaveFileName(gui()->central_wdg,
3349 _("Save Game As..."),
3350 location, str);
3351 if (current_file.isEmpty() == false) {
3352 send_save_game(current_file.toLocal8Bit().data());
3356 /***************************************************************************
3357 Back to Main Menu
3358 ***************************************************************************/
3359 void mr_menu::back_to_menu()
3361 hud_message_box ask(gui()->central_wdg);
3362 int ret;
3364 if (is_server_running()) {
3365 ask.set_text_title(_("Leaving a local game will end it!"), "Leave game");
3366 ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3367 ask.setDefaultButton(QMessageBox::Cancel);
3368 ret = ask.exec();
3370 switch (ret) {
3371 case QMessageBox::Cancel:
3372 break;
3373 case QMessageBox::Ok:
3374 if (client.conn.used) {
3375 disconnect_from_server();
3377 break;
3379 } else {
3380 disconnect_from_server();
3384 /***************************************************************************
3385 Airlift unit type to city acity from each city
3386 ***************************************************************************/
3387 void multiairlift(struct city *acity, Unit_type_id ut)
3389 struct tile *ptile;
3390 city_list_iterate(client.conn.playing->cities, pcity) {
3391 if (get_city_bonus(pcity, EFT_AIRLIFT) > 0) {
3392 ptile = city_tile(pcity);
3393 unit_list_iterate(ptile->units, punit) {
3394 if (punit->utype == utype_by_number(ut)) {
3395 request_unit_airlift(punit, acity);
3396 break;
3398 } unit_list_iterate_end;
3400 } city_list_iterate_end;