Author: mir3x
Date: Mon Oct 31 16:47:41 2016
New Revision: 34302

URL: http://svn.gna.org/viewcvs/freeciv?rev=34302&view=rev
Log:
Qt client - added transport selection dialog
Reported by Marko Lindqvist <cazfi>

See patch #7154

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

Modified: branches/S2_6/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/citydlg.cpp?rev=34302&r1=34301&r2=34302&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/citydlg.cpp     (original)
+++ branches/S2_6/client/gui-qt/citydlg.cpp     Mon Oct 31 16:47:41 2016
@@ -708,7 +708,7 @@
 ****************************************************************************/
 void unit_item::load_unit()
 {
-  request_unit_load(qunit, NULL, unit_tile(qunit));
+  qtg_request_transport(qunit, unit_tile(qunit));
 }
 
 /****************************************************************************

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=34302&r1=34301&r2=34302&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/dialogs.cpp     (original)
+++ branches/S2_6/client/gui-qt/dialogs.cpp     Mon Oct 31 16:47:41 2016
@@ -2791,5 +2791,36 @@
 *****************************************************************/
 bool qtg_request_transport(struct unit *pcargo, struct tile *ptile)
 {
-  return false; /* Unit was not handled here. */
-}
+  int tcount;
+  hud_unit_loader *hul;
+  struct unit_list *potential_transports = unit_list_new();
+  struct unit *best_transport = transporter_for_unit(pcargo);
+
+  unit_list_iterate(ptile->units, ptransport) {
+    if (can_unit_transport(ptransport, pcargo)
+        && get_transporter_occupancy(ptransport) < 
get_transporter_capacity(ptransport)) {
+      unit_list_append(potential_transports, ptransport);
+    }
+  } unit_list_iterate_end;
+
+  tcount = unit_list_size(potential_transports);
+
+  if (tcount == 0) {
+    fc_assert(best_transport == NULL);
+    unit_list_destroy(potential_transports);
+
+    return false; /* Unit was not handled here. */
+  } else if (tcount == 1) {
+    /* There's exactly one potential transport - use it automatically */
+    fc_assert(unit_list_get(potential_transports, 0) == best_transport);
+    request_unit_load(pcargo, unit_list_get(potential_transports, 0), ptile);
+
+    unit_list_destroy(potential_transports);
+
+    return true;
+  }
+
+  hul = new hud_unit_loader(pcargo, ptile);
+  hul->show_me();
+  return true;
+}

Modified: branches/S2_6/client/gui-qt/hudwidget.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.cpp?rev=34302&r1=34301&r2=34302&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/hudwidget.cpp   (original)
+++ branches/S2_6/client/gui-qt/hudwidget.cpp   Mon Oct 31 16:47:41 2016
@@ -21,6 +21,7 @@
 #include <QGridLayout>
 #include <QPaintEvent>
 #include <QLineEdit>
+#include <QHeaderView>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QDialogButtonBox>
@@ -40,6 +41,7 @@
 #include "hudwidget.h"
 #include "fonts.h"
 #include "qtg_cxxside.h"
+#include "sprite.h"
 
 /****************************************************************************
   Custom message box constructor
@@ -888,3 +890,107 @@
   setUpdatesEnabled(true);
 }
 
+/****************************************************************************
+  Constructor for widget allowing loading units on transports
+****************************************************************************/
+hud_unit_loader::hud_unit_loader(struct unit *pcargo, struct tile *ptile)
+{
+  setProperty("showGrid", "false");
+  setProperty("selectionBehavior", "SelectRows");
+  setEditTriggers(QAbstractItemView::NoEditTriggers);
+  setSelectionMode(QAbstractItemView::SingleSelection);
+  verticalHeader()->setVisible(false);
+  horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
+  horizontalHeader()->setVisible(false);
+  setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+  connect(selectionModel(),
+          SIGNAL(selectionChanged(const QItemSelection &,
+                                  const QItemSelection &)), this,
+          SLOT(selection_changed(const QItemSelection &,
+                                 const QItemSelection &)));
+  cargo = pcargo;
+  qtile = ptile;
+
+}
+
+/****************************************************************************
+  Destructor for units loader
+****************************************************************************/
+hud_unit_loader::~hud_unit_loader()
+{
+
+}
+
+/****************************************************************************
+  Shows unit loader, adds possible tranportsand units to table
+  Calculates table size
+****************************************************************************/
+void hud_unit_loader::show_me()
+{
+  QTableWidgetItem *new_item;
+  int max_size = 0;
+  int i, j;
+  int w,h;
+  sprite *spite;
+
+  unit_list_iterate(qtile->units, ptransport) {
+    if (can_unit_transport(ptransport, cargo)
+        && get_transporter_occupancy(ptransport)
+        < get_transporter_capacity(ptransport)) {
+      transports.append(ptransport);
+      max_size = qMax(max_size, get_transporter_occupancy(ptransport));
+    }
+  } unit_list_iterate_end;
+
+  setRowCount(transports.count());
+  setColumnCount(max_size + 1);
+  for (i = 0 ; i < transports.count(); i++) {
+    QString str;
+    spite = get_unittype_sprite(tileset, transports.at(i)->utype,
+                                direction8_invalid(), true);
+    str = utype_rule_name(transports.at(i)->utype);
+    /* TRANS: MP - just movement points */
+    str = str + " ("
+          + QString(move_points_text(transports.at(i)->moves_left, false))
+          + _("MP") + ")";
+    new_item = new QTableWidgetItem(QIcon(*spite->pm), str);
+    setItem(i, 0, new_item);
+    j = 1;
+    unit_list_iterate(transports.at(i)->transporting, tunit) {
+      spite = get_unittype_sprite(tileset, tunit->utype,
+                                  direction8_invalid(), true);
+      new_item = new QTableWidgetItem(QIcon(*spite->pm), "");
+      setItem(i, j, new_item);
+      j++;
+    } unit_list_iterate_end;
+  }
+
+   w = verticalHeader()->width() + 4;
+   for (i = 0; i < columnCount(); i++) {
+      w += columnWidth(i);
+   }
+   h = horizontalHeader()->height() + 4;
+   for (i = 0; i < rowCount(); i++) {
+      h += rowHeight(i);
+   }
+
+  resize(w, h);
+  setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
+                 | Qt::FramelessWindowHint);
+  show();
+}
+
+/****************************************************************************
+  Selects given tranport and closes widget
+****************************************************************************/
+void hud_unit_loader::selection_changed(const QItemSelection& s1,
+                                        const QItemSelection& s2)
+{
+  int curr_row;
+
+  curr_row = s1.indexes().at(0).row();
+  request_unit_load(cargo, transports.at(curr_row), qtile);
+  close();
+}
+

Modified: branches/S2_6/client/gui-qt/hudwidget.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/hudwidget.h?rev=34302&r1=34301&r2=34302&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/hudwidget.h     (original)
+++ branches/S2_6/client/gui-qt/hudwidget.h     Mon Oct 31 16:47:41 2016
@@ -20,6 +20,7 @@
 #include <QMessageBox>
 #include <QElapsedTimer>
 #include <QLineEdit>
+#include <QTableWidget>
 
 #include "shortcuts.h"
 
@@ -175,6 +176,23 @@
   tile *current_tile;
 };
 
+/****************************************************************************
+  Widget allowing load units on transport
+****************************************************************************/
+class hud_unit_loader : public QTableWidget
+{
+  QList<unit * > transports;
+  Q_OBJECT
+public:
+  hud_unit_loader(struct unit *pcargo, struct tile *ptile);
+  ~hud_unit_loader();
+  void show_me();
+protected slots:
+  void selection_changed(const QItemSelection&, const QItemSelection&);
+private:
+  struct unit *cargo;
+  struct tile *qtile;
+};
 
 #endif /* FC__HUDWIDGET_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=34302&r1=34301&r2=34302&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/menu.cpp        (original)
+++ branches/S2_6/client/gui-qt/menu.cpp        Mon Oct 31 16:47:41 2016
@@ -2484,7 +2484,7 @@
 void mr_menu::slot_load()
 {
   unit_list_iterate(get_units_in_focus(), punit) {
-    request_unit_load(punit, NULL, unit_tile(punit));
+    qtg_request_transport(punit, unit_tile(punit));
   } unit_list_iterate_end;
 }
 


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

Reply via email to