Author: mir3x
Date: Sun Nov  6 22:07:37 2016
New Revision: 34410

URL: http://svn.gna.org/viewcvs/freeciv?rev=34410&view=rev
Log:
Qt client - added menu to choose default unit action bypassing choice dialog

See patch #7932

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

Modified: branches/S2_6/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/dialogs.cpp?rev=34410&r1=34409&r2=34410&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/dialogs.cpp     (original)
+++ branches/S2_6/client/gui-qt/dialogs.cpp     Sun Nov  6 22:07:37 2016
@@ -103,6 +103,8 @@
 /* Don't remove a unit's action decision want or move on to the next actor
  unit that wants a decision in the current unit selection. */
 static bool did_not_decide = false;
+
+qdef_act* qdef_act::m_instance = 0;
 
 /**********************************************************************
   Initialize a mapping between an action and the function to call if
@@ -734,6 +736,68 @@
   destroy();
 }
 
+/****************************************************************************
+  Default actions provider constructor
+****************************************************************************/
+qdef_act::qdef_act()
+{
+  vs_city = -1;
+  vs_unit = -1;
+}
+
+/****************************************************************************
+  Returns instance of qdef_act
+****************************************************************************/
+qdef_act *qdef_act::action()
+{
+  if (!m_instance)
+    m_instance = new qdef_act;
+  return m_instance;
+}
+
+/****************************************************************************
+  Deletes qdef_act instance
+****************************************************************************/
+void qdef_act::drop()
+{
+  if (m_instance) {
+    delete m_instance;
+    m_instance = 0;
+  }
+}
+
+/****************************************************************************
+  Sets default action vs city
+****************************************************************************/
+void qdef_act::vs_city_set(int i)
+{
+  vs_city = i;
+}
+
+/****************************************************************************
+  Sets default action vs unit
+****************************************************************************/
+void qdef_act::vs_unit_set(int i)
+{
+  vs_unit = i;
+}
+
+/****************************************************************************
+  Returns default action vs city
+****************************************************************************/
+int qdef_act::vs_city_get()
+{
+  return vs_city;
+}
+
+/****************************************************************************
+  Returns default action vs unit
+****************************************************************************/
+int qdef_act::vs_unit_get()
+{
+  return vs_unit;
+}
+
 /***************************************************************************
   Button canceling all selections has been pressed. 
 ***************************************************************************/
@@ -1119,6 +1183,41 @@
 }
 
 /***************************************************************************
+  Try to pick up default unit action
+***************************************************************************/
+bool try_default_unit_action(QVariant q1, QVariant q2)
+{
+  int action;
+  pfcn_void func;
+
+  action = qdef_act::action()->vs_unit_get();
+  if (action == -1) {
+    return false;
+  }
+  func = af_map[static_cast<gen_action>(action)];
+
+  func(q1, q2);
+  return true;
+}
+
+/***************************************************************************
+  Try to pick up default city action
+***************************************************************************/
+bool try_default_city_action(QVariant q1, QVariant q2)
+{
+  int action;
+  pfcn_void func;
+
+  action = qdef_act::action()->vs_city_get();
+  if (action == -1) {
+    return false;
+  }
+  func = af_map[static_cast<gen_action>(action)];
+  func(q1, q2);
+  return true;
+}
+
+/***************************************************************************
   Run chosen action and close dialog
 ***************************************************************************/
 void choice_dialog::execute_action(const int action)
@@ -1326,7 +1425,25 @@
   QVariant qv1, qv2;
   pfcn_void func;
   struct city *actor_homecity;
-
+  int unit_act;
+  int city_act;
+
+  unit_act = qdef_act::action()->vs_unit_get();
+  city_act = qdef_act::action()->vs_city_get();
+
+  if (target_city
+      && try_default_city_action(actor_unit->id, target_city->id)
+      && action_prob_possible(act_probs[static_cast<gen_action>(unit_act)])) {
+    diplomat_queue_handle_primary(actor_unit->id);
+    return;
+  }
+
+  if (target_unit
+      && try_default_unit_action(actor_unit->id, target_unit->id)
+      && action_prob_possible(act_probs[static_cast<gen_action>(city_act)])) {
+    diplomat_queue_handle_primary(actor_unit->id);
+    return;
+  }
   /* 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,

Modified: branches/S2_6/client/gui-qt/dialogs.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/dialogs.h?rev=34410&r1=34409&r2=34410&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/dialogs.h       (original)
+++ branches/S2_6/client/gui-qt/dialogs.h       Sun Nov  6 22:07:37 2016
@@ -47,6 +47,25 @@
 void update_nationset_combo();
 void popup_races_dialog(struct player *pplayer);
 void restart_notify_dialogs();
+
+
+class qdef_act
+{
+  Q_DISABLE_COPY(qdef_act);
+
+private:
+  explicit qdef_act();
+  static qdef_act* m_instance;
+  int vs_city;
+  int vs_unit;
+public:
+  static qdef_act* action();
+  static void drop();
+  void vs_city_set(int i);
+  void vs_unit_set(int i);
+  int vs_city_get();
+  int vs_unit_get();
+};
 
 /***************************************************************************
   Nonmodal message box for disbanding units
@@ -247,5 +266,7 @@
 void revolution_response(struct government *government);
 void popup_upgrade_dialog(struct unit_list *punits);
 void popup_disband_dialog(struct unit_list *punits);
+bool try_default_unit_action(QVariant q1, QVariant q2);
+bool try_default_city_action(QVariant q1, QVariant q2);
 
 #endif /* FC__DIALOGS_H */

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=34410&r1=34409&r2=34410&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.cpp        (original)
+++ branches/S2_6/client/gui-qt/menu.cpp        Sun Nov  6 22:07:37 2016
@@ -1149,6 +1149,75 @@
   airlift_type = new QActionGroup(this);
   airlift_menu = multiplayer_menu->addMenu(_("Unit type for quickairlifting"));
 
+  /* Default diplo */
+  action_vs_city = new QActionGroup(this);
+  action_vs_unit = new QActionGroup(this);
+  action_unit_menu = multiplayer_menu->addMenu(_("Default action vs unit"));
+
+  act = action_unit_menu->addAction(_("Ask"));
+  act->setCheckable(true);
+  act->setChecked(true);
+  act->setData(-1);
+  action_vs_unit->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
+
+  act = action_unit_menu->addAction(_("Bribe"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_BRIBE_UNIT);
+  action_vs_unit->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
+
+  act = action_unit_menu->addAction(_("Sabotage"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_SABOTAGE_UNIT);
+  action_vs_unit->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_unit()));
+
+  action_city_menu = multiplayer_menu->addMenu(_("Default action vs city"));
+  act = action_city_menu->addAction(_("Ask"));
+  act->setCheckable(true);
+  act->setChecked(true);
+  act->setData(-1);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
+  act = action_city_menu->addAction(_("Investigate city"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_INVESTIGATE_CITY);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
+  act = action_city_menu->addAction(_("Establish embassy"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_ESTABLISH_EMBASSY);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
+  act = action_city_menu->addAction(_("Steal technology"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_STEAL_TECH);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
+  act = action_city_menu->addAction(_("Incite a revolt"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_INCITE_CITY);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
+  act = action_city_menu->addAction(_("Poison city"));
+  act->setCheckable(true);
+  act->setChecked(false);
+  act->setData(ACTION_SPY_POISON);
+  action_vs_city->addAction(act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_action_vs_city()));
+
   /* Civilization menu */
   menu = this->addMenu(_("Civilization"));
   act = menu->addAction(_("Tax Rates..."));
@@ -2209,6 +2278,29 @@
 }
 
 /**************************************************************************
+  Slot for choosing default action vs unit
+**************************************************************************/
+void mr_menu::slot_action_vs_unit()
+{
+  QAction *act;
+
+  act = qobject_cast<QAction *>(sender());
+  qdef_act::action()->vs_unit_set(act->data().toInt());
+}
+
+
+/**************************************************************************
+  Slot for choosing default action vs city
+**************************************************************************/
+void mr_menu::slot_action_vs_city()
+{
+  QAction *act;
+
+  act = qobject_cast<QAction *>(sender());
+  qdef_act::action()->vs_city_set(act->data().toInt());
+}
+
+/**************************************************************************
   Slot for quick airlifting
 **************************************************************************/
 void mr_menu::slot_quickairlift()

Modified: branches/S2_6/client/gui-qt/menu.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/menu.h?rev=34410&r1=34409&r2=34410&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.h  (original)
+++ branches/S2_6/client/gui-qt/menu.h  Sun Nov  6 22:07:37 2016
@@ -258,6 +258,10 @@
   QMenu *airlift_menu;
   QMenu *multiplayer_menu;
   QActionGroup *airlift_type;
+  QActionGroup *action_vs_city;
+  QActionGroup *action_vs_unit;
+  QMenu *action_unit_menu;
+  QMenu *action_city_menu;
   QHash<munit, QAction*> menu_list;
   qfc_units_list units_list;
 public:
@@ -364,6 +368,8 @@
   void slot_rally();
   void slot_quickairlift_set();
   void slot_quickairlift();
+  void slot_action_vs_unit();
+  void slot_action_vs_city();
 
   /*used by civilization menu */
   void slot_show_map();


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

Reply via email to