Author: mir3x
Date: Wed Aug 31 16:24:32 2016
New Revision: 33728

URL: http://svn.gna.org/viewcvs/freeciv?rev=33728&view=rev
Log:
Qt client - Added policies (effect multipliers)
Sumbitted by Marko Lindqvist <cazfi>

See patch #5067


Modified:
    trunk/client/gui-qt/menu.cpp
    trunk/client/gui-qt/menu.h
    trunk/client/gui-qt/ratesdlg.cpp
    trunk/client/gui-qt/ratesdlg.h

Modified: trunk/client/gui-qt/menu.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.cpp?rev=33728&r1=33727&r2=33728&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.cpp        (original)
+++ trunk/client/gui-qt/menu.cpp        Wed Aug 31 16:24:32 2016
@@ -1498,6 +1498,11 @@
   connect(act, SIGNAL(triggered()), this, SLOT(slot_popup_tax_rates()));
   menu->addSeparator();
 
+  act = menu->addAction(_("Policies..."));
+  menu_list.insertMulti(MULTIPLIERS, act);
+  connect(act, SIGNAL(triggered()), this, SLOT(slot_popup_mult_rates()));
+  menu->addSeparator();
+
   menu->addMenu(new class gov_menu());
   menu->addSeparator();
 
@@ -1758,6 +1763,15 @@
         if (client_is_observer() == false) {
           i.value()->setEnabled(true);
         }
+        break;
+      case MULTIPLIERS:
+        if (client_is_observer() == false && multiplier_count() > 0) {
+          i.value()->setEnabled(true);
+          i.value()->setVisible(true);
+        } else {
+          i.value()->setVisible(false);
+        }
+        break;
       default:
         break;
       }
@@ -2923,6 +2937,14 @@
 }
 
 /****************************************************************
+  Action "MULTIPLERS RATES"
+*****************************************************************/
+void mr_menu::slot_popup_mult_rates()
+{
+  popup_multiplier_dialog();
+}
+
+/****************************************************************
   Actions "HELP_*"
 *****************************************************************/
 void mr_menu::slot_help(const QString &topic)

Modified: trunk/client/gui-qt/menu.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/menu.h?rev=33728&r1=33727&r2=33728&view=diff
==============================================================================
--- trunk/client/gui-qt/menu.h  (original)
+++ trunk/client/gui-qt/menu.h  Wed Aug 31 16:24:32 2016
@@ -74,6 +74,7 @@
   MIGRANT,
   GO_AND_BUILD_CITY,
   NOT_4_OBS,
+  MULTIPLIERS,
   SAVE
 };
 
@@ -417,6 +418,7 @@
   void slot_show_map();
   void calc_trade_routes();
   void slot_popup_tax_rates();
+  void slot_popup_mult_rates();
   void slot_show_eco_report();
   void slot_show_units_report();
   void slot_show_nations();

Modified: trunk/client/gui-qt/ratesdlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/ratesdlg.cpp?rev=33728&r1=33727&r2=33728&view=diff
==============================================================================
--- trunk/client/gui-qt/ratesdlg.cpp    (original)
+++ trunk/client/gui-qt/ratesdlg.cpp    Wed Aug 31 16:24:32 2016
@@ -15,12 +15,17 @@
 #include <fc_config.h>
 #endif
 
+// client
+#include "multipliers.h"
+
 // gui-qt
 #include "fc_client.h"
 #include "qtg_cxxside.h"
 
 #include "ratesdlg.h"
 
+static int scale_to_mult(const struct multiplier *pmul, int scale);
+static int mult_to_scale(const struct multiplier *pmul, int val);
 /**************************************************************************
   Dialog constructor for changing rates with sliders.
   Automatic destructor will clean qobjects, so there is no one
@@ -275,6 +280,124 @@
 }
 
 /**************************************************************************
+  Multipler rates dialog constructor
+**************************************************************************/
+multipler_rates_dialog::multipler_rates_dialog (QWidget *parent,
+                                                Qt::WindowFlags f)
+  : QDialog (parent)
+{
+  QGroupBox *group_box;
+  QHBoxLayout *some_layout;
+  QLabel *label;
+  QSlider *slider;
+  QString str;
+  QVBoxLayout *main_layout;
+  struct player *pplayer = client_player();
+
+  cancel_button = new QPushButton;
+  ok_button = new QPushButton;
+  setWindowTitle(_("Change governments modifiers"));
+  main_layout = new QVBoxLayout;
+
+  multipliers_iterate(pmul) {
+    QHBoxLayout *hb = new QHBoxLayout;
+    int val = player_multiplier_target_value(pplayer, pmul);
+    group_box = new QGroupBox(multiplier_name_translation(pmul));
+    slider = new QSlider(Qt::Horizontal, this);
+    slider->setMinimum(mult_to_scale(pmul, pmul->start));
+    slider->setMaximum(mult_to_scale(pmul, pmul->stop));
+    slider->setValue(val);
+    connect(slider, SIGNAL(valueChanged(int)),
+            SLOT(slot_set_value(int)));
+    slider_list.append(slider);
+    label = new QLabel(QString::number(val));
+    hb->addWidget(slider);
+    hb->addWidget(label);
+    group_box->setLayout(hb);
+    slider->setProperty("lab", QVariant::fromValue((void *) label));
+    main_layout->addWidget(group_box);
+
+  } multipliers_iterate_end;
+  some_layout = new QHBoxLayout;
+  cancel_button->setText(_("Cancel"));
+  ok_button->setText(_("Ok"));
+  connect(cancel_button, SIGNAL(pressed()),
+          SLOT(slot_cancel_button_pressed()));
+  connect(ok_button, SIGNAL(pressed()),
+          SLOT(slot_ok_button_pressed()));
+  some_layout->addWidget(cancel_button);
+  some_layout->addWidget(ok_button);
+  main_layout->addSpacing(20);
+  main_layout->addLayout(some_layout);
+  setLayout(main_layout);
+}
+
+/**************************************************************************
+  Slider value changed
+**************************************************************************/
+void multipler_rates_dialog::slot_set_value(int i)
+{
+  QSlider *qo;
+  QString str;
+  qo = (QSlider *) QObject::sender();
+  QString sender;
+  QVariant qvar;
+  QLabel *lab;
+
+  qvar = qo->property("lab");
+  lab =  reinterpret_cast<QLabel *>(qvar.value<void *>());
+  lab->setText(QString::number(qo->value()));
+}
+
+
+/***************************************************************************
+  Cancel pressed
+***************************************************************************/
+void multipler_rates_dialog::slot_cancel_button_pressed()
+{
+  close();
+  deleteLater();
+}
+
+/***************************************************************************
+  Ok pressed - send mulipliers value.
+***************************************************************************/
+void multipler_rates_dialog::slot_ok_button_pressed()
+{
+  int j = 0;
+  int value;
+  struct packet_player_multiplier mul;
+
+  multipliers_iterate(pmul) {
+    Multiplier_type_id i = multiplier_index(pmul);
+    value = slider_list.at(j)->value();
+    mul.multipliers[i] = scale_to_mult(pmul, value);
+    j++;
+  } multipliers_iterate_end;
+  mul.count = multiplier_count();
+  send_packet_player_multiplier(&client.conn, &mul);
+  close();
+  deleteLater();
+}
+
+
+/**************************************************************************
+  Convert real multiplier display value to scale value
+**************************************************************************/
+int mult_to_scale(const struct multiplier *pmul, int val)
+{
+  return (val - pmul->start) / pmul->step;
+}
+
+/**************************************************************************
+  Convert scale units to real multiplier display value
+**************************************************************************/
+int scale_to_mult(const struct multiplier *pmul, int scale)
+{
+  return scale * pmul->step + pmul->start;
+}
+
+/**************************************************************************
   Popup (or raise) the (tax/science/luxury) rates selection dialog.
 **************************************************************************/
 void popup_rates_dialog(void)
@@ -290,3 +413,17 @@
 {
   /* PORTME */
 }
+
+/**************************************************************************
+  Popups multiplier dialog
+**************************************************************************/
+void popup_multiplier_dialog(void)
+{
+  multipler_rates_dialog* mrd;
+  if (!can_client_issue_orders()) {
+    return;
+  }
+  mrd = new multipler_rates_dialog(gui()->central_wdg);
+  mrd->show();
+}
+

Modified: trunk/client/gui-qt/ratesdlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/ratesdlg.h?rev=33728&r1=33727&r2=33728&view=diff
==============================================================================
--- trunk/client/gui-qt/ratesdlg.h      (original)
+++ trunk/client/gui-qt/ratesdlg.h      Wed Aug 31 16:24:32 2016
@@ -76,5 +76,26 @@
   void slot_ok_button_pressed();
   void slot_cancel_button_pressed();
 };
- 
+
+/**************************************************************************
+ * Dialog used to change policies
+ *************************************************************************/
+class multipler_rates_dialog: public  QDialog
+{
+  Q_OBJECT
+
+public:
+  explicit multipler_rates_dialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
+private:
+  QList<QSlider*> slider_list;
+  QPushButton *cancel_button;
+  QPushButton *ok_button;
+private slots:
+  void slot_set_value(int i);
+  void slot_ok_button_pressed();
+  void slot_cancel_button_pressed();
+};
+
+void popup_multiplier_dialog(void);
+
 #endif /* FC__RATESDLG_H */


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

Reply via email to