Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] (PR#3700) Recall previous focus unit
Home

[Freeciv-Dev] (PR#3700) Recall previous focus unit

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3700) Recall previous focus unit
From: "a-l@xxxxxxx" <a-l@xxxxxxx>
Date: Tue, 11 Mar 2003 13:20:50 -0800
Reply-to: rt@xxxxxxxxxxxxxx

I find it useful with a key that returns focus to the previous
focus unit, for many reasons.

This patch puts that on the "Keypad 5" key, which
previously was focus_to_next_unit(), in the GDK clients.
I did not delete the previously used function. Should I?

Of course, with the current code there is a subtle difference
between pressing Keypad 5 and pressing W, in that Keypad 5
does not set the unit's status to "wait".

But I suspect nobody uses Keypad 5. If someone did,
this long standing bug would probably have been reported:

        (GTK1 and GTK2) When the numlock LED is off, Keypad 5
        will end turn instead of advance focus.

If you prefere, the other patch, bugfix.diff, simply fixes this bug.


Arnstein

diff -ruN -Xdiff_ignore cvs/client/control.c recall_focus/client/control.c
--- cvs/client/control.c        Sat Feb 22 10:43:01 2003
+++ recall_focus/client/control.c       Tue Mar 11 20:06:02 2003
@@ -48,6 +48,9 @@
 /* unit_focus points to the current unit in focus */
 static struct unit *punit_focus;
 
+/* recall unit with Keypad 5 */
+static int previous_focus_id = 0;
+
 /* These should be set via set_hover_state() */
 int hover_unit = 0; /* id of unit hover_state applies to */
 enum cursor_hover_state hover_state = HOVER_NONE;
@@ -68,6 +71,7 @@
 /*************************************************************************/
 
 static struct unit *find_best_focus_candidate(void);
+static void store_focus(void);
 
 /**************************************************************************
 ...
@@ -104,6 +108,10 @@
 {
   struct unit *punit_old_focus=punit_focus;
 
+  if (punit != punit_focus) {
+    store_focus();
+  }
+
   punit_focus=punit;
 
   if(punit) {
@@ -139,6 +147,10 @@
 **************************************************************************/
 void set_unit_focus_no_center(struct unit *punit)
 {
+  if (punit != punit_focus) {
+    store_focus();
+  }
+
   punit_focus=punit;
 
   if(punit) {
@@ -159,6 +171,25 @@
 }
 
 /**************************************************************************
+...
+**************************************************************************/
+static void store_focus(void)
+{
+    if (punit_focus) {
+      previous_focus_id = punit_focus->id;
+    }
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void recall_previous_focus(void)
+{
+    int id = previous_focus_id;
+    set_unit_focus_and_select(find_unit_by_id(id));
+}
+
+/**************************************************************************
 If there is no unit currently in focus, or if the current unit in
 focus should not be in focus, then get a new focus unit.
 We let GOTO-ing units stay in focus, so that if they have moves left
@@ -190,6 +221,7 @@
 {
   struct unit *punit_old_focus=punit_focus;
 
+  store_focus();
   punit_focus=find_best_focus_candidate();
 
   set_hover_state(NULL, HOVER_NONE);
diff -ruN -Xdiff_ignore cvs/client/control.h recall_focus/client/control.h
--- cvs/client/control.h        Thu Feb  6 05:58:16 2003
+++ recall_focus/client/control.h       Tue Mar 11 20:11:37 2003
@@ -87,6 +87,7 @@
 void set_unit_focus(struct unit *punit);
 void set_unit_focus_no_center(struct unit *punit);
 void set_unit_focus_and_select(struct unit *punit);
+void recall_previous_focus(void);
 void update_unit_focus(void);
 struct unit *find_visible_unit(struct tile *ptile);
 void set_units_in_combat(struct unit *pattacker, struct unit *pdefender);
diff -ruN -Xdiff_ignore cvs/client/gui-gtk/gui_main.c 
recall_focus/client/gui-gtk/gui_main.c
--- cvs/client/gui-gtk/gui_main.c       Fri Feb 28 12:52:16 2003
+++ recall_focus/client/gui-gtk/gui_main.c      Tue Mar 11 20:26:41 2003
@@ -302,7 +302,6 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
-      case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
         key_end_turn();
@@ -310,7 +309,8 @@
   
       case GDK_5:
       case GDK_KP_5: 
-        focus_to_next_unit(); 
+      case GDK_KP_Begin:
+        recall_previous_focus();
         break;
   
       case GDK_Escape:
diff -ruN -Xdiff_ignore cvs/client/gui-gtk-2.0/gui_main.c 
recall_focus/client/gui-gtk-2.0/gui_main.c
--- cvs/client/gui-gtk-2.0/gui_main.c   Fri Mar  7 12:16:16 2003
+++ recall_focus/client/gui-gtk-2.0/gui_main.c  Tue Mar 11 20:26:18 2003
@@ -426,7 +426,6 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
-      case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
         key_end_turn();
@@ -434,7 +433,8 @@
   
       case GDK_5:
       case GDK_KP_5: 
-        focus_to_next_unit(); 
+      case GDK_KP_Begin:
+        recall_previous_focus(); 
         break;
   
       case GDK_Escape:
diff -ruN -Xdiff_ignore cvs/client/gui-gtk/gui_main.c 
bugfix/client/gui-gtk/gui_main.c
--- cvs/client/gui-gtk/gui_main.c       Fri Feb 28 12:52:16 2003
+++ bugfix/client/gui-gtk/gui_main.c    Tue Mar 11 20:52:32 2003
@@ -302,7 +302,6 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
-      case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
         key_end_turn();
@@ -310,6 +309,7 @@
   
       case GDK_5:
       case GDK_KP_5: 
+      case GDK_KP_Begin:
         focus_to_next_unit(); 
         break;
   
diff -ruN -Xdiff_ignore cvs/client/gui-gtk-2.0/gui_main.c 
bugfix/client/gui-gtk-2.0/gui_main.c
--- cvs/client/gui-gtk-2.0/gui_main.c   Fri Mar  7 12:16:16 2003
+++ bugfix/client/gui-gtk-2.0/gui_main.c        Tue Mar 11 20:52:16 2003
@@ -426,7 +426,6 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
-      case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
         key_end_turn();
@@ -434,6 +433,7 @@
   
       case GDK_5:
       case GDK_KP_5: 
+      case GDK_KP_Begin:
         focus_to_next_unit(); 
         break;
   

[Prev in Thread] Current Thread [Next in Thread]