Author: mir3x
Date: Fri Nov 18 09:09:34 2016
New Revision: 34551

URL: http://svn.gna.org/viewcvs/freeciv?rev=34551&view=rev
Log:
Qt client - use wheel up over sidebar unit icon to center enemy units

See patch #7998


Modified:
    branches/S2_6/client/gui-qt/menu.cpp
    branches/S2_6/client/gui-qt/pages.cpp

Modified: branches/S2_6/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.cpp?rev=34551&r1=34550&r2=34551&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.cpp        (original)
+++ branches/S2_6/client/gui-qt/menu.cpp        Fri Nov 18 09:09:34 2016
@@ -62,6 +62,7 @@
 
 static bool tradecity_rand(const trade_city *t1, const trade_city *t2);
 static void enable_interface(bool enable);
+extern int last_center_enemy;
 /**************************************************************************
   New turn callback
 **************************************************************************/
@@ -69,6 +70,7 @@
 {
   gui()->rallies.run();
   real_menus_update();
+  last_center_enemy = 0;
 }
 
 /**************************************************************************

Modified: branches/S2_6/client/gui-qt/pages.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/pages.cpp?rev=34551&r1=34550&r2=34551&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/pages.cpp       (original)
+++ branches/S2_6/client/gui-qt/pages.cpp       Fri Nov 18 09:09:34 2016
@@ -62,8 +62,8 @@
 static bool holding_srv_list_mutex = false;
 static enum connection_state connection_status;
 static struct terrain *char2terrain(char ch);
-
-
+static void cycle_enemy_units();
+int last_center_enemy = 0;
 /****************************************************************************
   Helper function for drawing map of savegames. Converts stored map char in
   savefile to proper terrain.
@@ -714,7 +714,7 @@
                                  _("Turn Done"), "", side_finish_turn);
   sw_endturn->set_right_click(side_indicators_menu);
   sw_cunit->set_right_click(side_center_unit);
-  sw_cunit->set_wheel_up(key_recall_previous_focus_unit);
+  sw_cunit->set_wheel_up(cycle_enemy_units);
   sw_cunit->set_wheel_down(key_unit_wait);
   sw_diplo->set_right_click(side_right_click_diplomacy);
 
@@ -2088,3 +2088,38 @@
   }
 }
 
+/***************************************************************************
+  Center on next enemy unit
+***************************************************************************/
+void cycle_enemy_units()
+{
+  bool center_next = false;
+  bool first_tile = false;
+  int first_id;
+  struct tile *ptile = nullptr;
+
+  players_iterate(pplayer) {
+    if (pplayer != client_player()) {
+      unit_list_iterate(pplayer->units, punit) {
+        if (first_tile == false) {
+          first_tile = true;
+          ptile = punit->tile;
+          first_id = punit->id;
+        }
+        if ((last_center_enemy == 0) || center_next == true) {
+          last_center_enemy = punit->id;
+          center_tile_mapcanvas(punit->tile);
+          return;
+        }
+        if (punit->id == last_center_enemy) {
+          center_next = true;
+        }
+      } unit_list_iterate_end;
+    }
+  } players_iterate_end;
+
+  if (ptile != nullptr) {
+    center_tile_mapcanvas(ptile);
+    last_center_enemy = first_id;
+  }
+}


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to