Author: sveinung
Date: Mon Feb 15 10:57:46 2016
New Revision: 31928

URL: http://svn.gna.org/viewcvs/freeciv?rev=31928&view=rev
Log:
SDL2: dialog closed -> action decision taken.

Notify the common client code that an action decision has been taken in the
code responsible for closing the dialogs rather than repeating it in every
single action. This is what the other clients do.

See patch #6956

Modified:
    trunk/client/gui-sdl2/action_dialog.c

Modified: trunk/client/gui-sdl2/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/action_dialog.c?rev=31928&r1=31927&r2=31928&view=diff
==============================================================================
--- trunk/client/gui-sdl2/action_dialog.c       (original)
+++ trunk/client/gui-sdl2/action_dialog.c       Mon Feb 15 10:57:46 2016
@@ -68,7 +68,30 @@
 
 
 static struct diplomat_dialog *pDiplomat_Dlg = NULL;
+static bool is_more_user_input_needed = FALSE;
 static action_probability follow_up_act_probs[ACTION_COUNT];
+
+/**************************************************************************
+  The action selection is done.
+**************************************************************************/
+static void act_sel_done_primary(int actor_unit_id)
+{
+  if (!is_more_user_input_needed) {
+    /* The client isn't waiting for more information about the selected
+     * action. */
+    action_decision_taken(actor_unit_id);
+  }
+}
+
+/**************************************************************************
+  A follow up question about the selected action is done.
+**************************************************************************/
+static void act_sel_done_secondary(int actor_unit_id)
+{
+  /* Stop blocking. */
+  is_more_user_input_needed = FALSE;
+  act_sel_done_primary(actor_unit_id);
+}
 
 /* ====================================================================== */
 /* ============================ CARAVAN DIALOG ========================== */
@@ -89,7 +112,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -111,7 +133,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -133,7 +154,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -155,7 +175,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -193,7 +212,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -216,8 +234,6 @@
     }
 
     /* FIXME: Wait for the city display in stead? */
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
-
     popdown_diplomat_dialog();
   }
 
@@ -238,7 +254,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -259,7 +274,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -280,7 +294,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -302,7 +315,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -324,7 +336,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -343,9 +354,9 @@
     request_action_details(ACTION_SPY_TARGETED_SABOTAGE_CITY,
                            pDiplomat_Dlg->actor_unit_id,
                            pDiplomat_Dlg->target_ids[ATK_CITY]);
+    is_more_user_input_needed = TRUE;
     popdown_diplomat_dialog();
   } else {
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -367,7 +378,6 @@
                         B_LAST + 1, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -389,13 +399,16 @@
 }
 
 /****************************************************************
-  Exit spy's steal dialog.
-*****************************************************************/
-static int exit_spy_steal_dlg_callback(struct widget *pWidget)
-{
-  if (Main.event.button.button == SDL_BUTTON_LEFT) {
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
-    popdown_diplomat_dialog();
+  Exit spy's steal or sabotage dialog.
+*****************************************************************/
+static int exit_spy_tgt_dlg_callback(struct widget *pWidget)
+{
+  if (Main.event.button.button == SDL_BUTTON_LEFT) {
+    int actor_id = pDiplomat_Dlg->actor_unit_id;
+
+    fc_assert(is_more_user_input_needed);
+    popdown_diplomat_dialog();
+    act_sel_done_secondary(actor_id);
   }
 
   return -1;
@@ -408,6 +421,7 @@
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
     int steal_advance = MAX_ID - pWidget->ID;
+    int actor_id = pDiplomat_Dlg->actor_unit_id;
 
     if (NULL != game_unit_by_number(pDiplomat_Dlg->actor_unit_id)
         && NULL != game_city_by_number(
@@ -427,8 +441,9 @@
       }
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
-    popdown_diplomat_dialog();
+    fc_assert(is_more_user_input_needed);
+    popdown_diplomat_dialog();
+    act_sel_done_secondary(actor_id);
   }
 
   return -1;
@@ -452,6 +467,7 @@
   int tech, idx;
   SDL_Rect area;
 
+  is_more_user_input_needed = TRUE;
   popdown_diplomat_dialog();
 
   if (pVcity) {
@@ -461,7 +477,7 @@
   fc_assert_ret_val_msg(!pDiplomat_Dlg, 1, "Diplomat dialog already open");
 
   if (!pVictim) {
-    action_decision_taken(id);
+    act_sel_done_secondary(id);
     return 1;
   }
 
@@ -485,7 +501,7 @@
     request_do_action(ACTION_SPY_STEAL_TECH,
                       id, target_id, A_UNSET, "");
 
-    action_decision_taken(id);
+    act_sel_done_secondary(id);
 
     return -1;
   }
@@ -520,7 +536,7 @@
   pBuf->info_label = create_utf8_from_char(_("Close Dialog (Esc)"),
                                            adj_font(12));
   area.w += pBuf->size.w + adj_size(10);
-  pBuf->action = exit_spy_steal_dlg_callback;
+  pBuf->action = exit_spy_tgt_dlg_callback;
   set_wstate(pBuf, FC_WS_NORMAL);
   pBuf->key = SDLK_ESCAPE;
 
@@ -684,7 +700,6 @@
                         A_UNSET, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -703,9 +718,9 @@
       request_action_details(ACTION_SPY_INCITE_CITY,
                              pDiplomat_Dlg->actor_unit_id,
                              pDiplomat_Dlg->target_ids[ATK_CITY]);
+      is_more_user_input_needed = TRUE;
       popdown_diplomat_dialog();
     } else {
-      action_decision_taken(pDiplomat_Dlg->actor_unit_id);
       popdown_diplomat_dialog();
     }
   }
@@ -728,8 +743,7 @@
       request_unit_non_action_move(punit, pWidget->data.tile);
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
-    popdown_diplomat_dialog();  
+    popdown_diplomat_dialog();
   }
 
   return -1;
@@ -747,9 +761,9 @@
       request_action_details(ACTION_SPY_BRIBE_UNIT,
                              pDiplomat_Dlg->actor_unit_id,
                              pDiplomat_Dlg->target_ids[ATK_UNIT]);
+      is_more_user_input_needed = TRUE;
       popdown_diplomat_dialog();
     } else {
-      action_decision_taken(pDiplomat_Dlg->actor_unit_id);
       popdown_diplomat_dialog();
     }
   }
@@ -769,8 +783,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_SPY_SABOTAGE_UNIT,
                       diplomat_id, target_id, 0, "");
-
-    action_decision_taken(diplomat_id);
   }
 
   return -1;
@@ -788,8 +800,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_CAPTURE_UNITS,
                       actor_id, target_id, 0, "");
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -807,8 +817,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_EXPEL_UNIT,
                       actor_id, target_id, 0, "");
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -826,8 +834,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_BOMBARD,
                       actor_id, target_id, 0, "");
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -848,7 +854,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -866,8 +871,6 @@
     popdown_diplomat_dialog();
     dsend_packet_city_name_suggestion_req(&client.conn,
                                           actor_id);
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -885,8 +888,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_NUKE,
                       actor_id, target_id, 0, "");
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -904,8 +905,6 @@
     popdown_diplomat_dialog();
     request_do_action(ACTION_DISBAND_UNIT,
                       actor_id, target_id, 0, "");
-
-    action_decision_taken(actor_id);
   }
 
   return -1;
@@ -926,7 +925,6 @@
                         0, "");
     }
 
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -939,7 +937,6 @@
 static int diplomat_close_callback(struct widget *pWidget)
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
-    action_decision_taken(pDiplomat_Dlg->actor_unit_id);
     popdown_diplomat_dialog();
   }
 
@@ -953,6 +950,8 @@
 void popdown_diplomat_dialog(void)
 {
   if (pDiplomat_Dlg) {
+    act_sel_done_primary(pDiplomat_Dlg->actor_unit_id);
+
     is_unit_move_blocked = FALSE;
     popdown_window_group_dialog(pDiplomat_Dlg->pdialog->pBeginWidgetList,
                                pDiplomat_Dlg->pdialog->pEndWidgetList);
@@ -1147,6 +1146,14 @@
 
   fc_assert_ret_msg(!pDiplomat_Dlg, "Diplomat dialog already open");
 
+  /* Could be caused by the server failing to reply to a request for more
+   * information or a bug in the client code. */
+  fc_assert_msg(!is_more_user_input_needed,
+                "Diplomat queue problem. Is another diplomat window open?");
+
+  /* No extra input is required as no action has been chosen yet. */
+  is_more_user_input_needed = FALSE;
+
   is_unit_move_blocked = TRUE;
 
   actor_homecity = game_city_by_number(actor_unit->homecity);
@@ -1402,6 +1409,7 @@
     int diplomat_target_id = pWidget->data.cont->id0;
     int diplomat_id = pWidget->data.cont->id1;
 
+    fc_assert(is_more_user_input_needed);
     popdown_diplomat_dialog();
 
     if (sabotage_improvement == 1000) {
@@ -1423,7 +1431,7 @@
       }
     }
 
-    action_decision_taken(diplomat_id);
+    act_sel_done_secondary(diplomat_id);
   }
 
   return -1;
@@ -1443,8 +1451,11 @@
 
   fc_assert_ret_msg(!pDiplomat_Dlg, "Diplomat dialog already open");
 
+  /* Should be set before sending request to the server. */
+  fc_assert(is_more_user_input_needed);
+
   if (!actor) {
-    action_decision_taken(IDENTITY_NUMBER_ZERO);
+    act_sel_done_secondary(IDENTITY_NUMBER_ZERO);
     return;
   }
 
@@ -1480,7 +1491,7 @@
   pBuf->info_label = create_utf8_from_char(_("Close Dialog (Esc)"),
                                            adj_font(12));
   area.w += pBuf->size.w + adj_size(10);
-  pBuf->action = diplomat_close_callback;
+  pBuf->action = exit_spy_tgt_dlg_callback;
   set_wstate(pBuf, FC_WS_NORMAL);
   pBuf->key = SDLK_ESCAPE;
 
@@ -1686,7 +1697,7 @@
       request_do_action(ACTION_SPY_INCITE_CITY, pIncite_Dlg->actor_unit_id,
                         pIncite_Dlg->target_id, 0, "");
     }
-    action_decision_taken(pIncite_Dlg->target_id);
+
     popdown_incite_dialog();
   }
 
@@ -1699,7 +1710,6 @@
 static int exit_incite_dlg_callback(struct widget *pWidget)
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
-    action_decision_taken(pIncite_Dlg->target_id);
     popdown_incite_dialog();
   }
 
@@ -1713,6 +1723,8 @@
 void popdown_incite_dialog(void)
 {
   if (pIncite_Dlg) {
+    act_sel_done_secondary(pIncite_Dlg->actor_unit_id);
+
     is_unit_move_blocked = FALSE;
     popdown_window_group_dialog(pIncite_Dlg->pdialog->pBeginWidgetList,
                                pIncite_Dlg->pdialog->pEndWidgetList);
@@ -1738,8 +1750,11 @@
     return;
   }
 
+  /* Should be set before sending request to the server. */
+  fc_assert(is_more_user_input_needed);
+
   if (!actor || !unit_can_do_action(actor, ACTION_SPY_INCITE_CITY)) {
-    action_decision_taken(actor ? actor->id : IDENTITY_NUMBER_ZERO);
+    act_sel_done_secondary(actor ? actor->id : IDENTITY_NUMBER_ZERO);
     return;
   }
 
@@ -1944,7 +1959,6 @@
       request_do_action(ACTION_SPY_BRIBE_UNIT, pBribe_Dlg->actor_unit_id,
                         pBribe_Dlg->target_id, 0, "");
     }
-    action_decision_taken(pBribe_Dlg->actor_unit_id);
     popdown_bribe_dialog();
   }
 
@@ -1958,7 +1972,6 @@
 {
   if (Main.event.button.button == SDL_BUTTON_LEFT) {
     popdown_bribe_dialog();
-    action_decision_taken(pBribe_Dlg->actor_unit_id);
   }
 
   return -1;
@@ -1971,6 +1984,8 @@
 void popdown_bribe_dialog(void)
 {
   if (pBribe_Dlg) {
+    act_sel_done_secondary(pBribe_Dlg->actor_unit_id);
+
     is_unit_move_blocked = FALSE;
     popdown_window_group_dialog(pBribe_Dlg->pdialog->pBeginWidgetList,
                                 pBribe_Dlg->pdialog->pEndWidgetList);
@@ -1996,8 +2011,11 @@
     return;
   }
 
+  /* Should be set before sending request to the server. */
+  fc_assert(is_more_user_input_needed);
+
   if (!actor || !unit_can_do_action(actor, ACTION_SPY_BRIBE_UNIT)) {
-    action_decision_taken(actor ? actor->id : IDENTITY_NUMBER_ZERO);
+    act_sel_done_secondary(actor ? actor->id : IDENTITY_NUMBER_ZERO);
     return;
   }
 


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

Reply via email to