Author: cazfi
Date: Tue Sep 13 15:29:27 2016
New Revision: 33792

URL: http://svn.gna.org/viewcvs/freeciv?rev=33792&view=rev
Log:
Added Action Enablers tab to ruledit.

See patch #7682

Added:
    trunk/tools/ruledit/tab_enablers.cpp
    trunk/tools/ruledit/tab_enablers.h
Modified:
    trunk/common/actions.c
    trunk/common/actions.h
    trunk/tools/ruledit/Makefile.am
    trunk/tools/ruledit/ruledit_qt.cpp
    trunk/tools/ruledit/ruledit_qt.h

Modified: trunk/common/actions.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=33792&r1=33791&r2=33792&view=diff
==============================================================================
--- trunk/common/actions.c      (original)
+++ trunk/common/actions.c      Tue Sep 13 15:29:27 2016
@@ -689,6 +689,7 @@
   struct action_enabler *enabler;
 
   enabler = fc_malloc(sizeof(*enabler));
+  enabler->disabled = FALSE;
   requirement_vector_init(&enabler->actor_reqs);
   requirement_vector_init(&enabler->target_reqs);
 

Modified: trunk/common/actions.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=33792&r1=33791&r2=33792&view=diff
==============================================================================
--- trunk/common/actions.h      (original)
+++ trunk/common/actions.h      Tue Sep 13 15:29:27 2016
@@ -179,10 +179,13 @@
 
 struct action_enabler
 {
+  bool disabled;
   enum gen_action action;
   struct requirement_vector actor_reqs;
   struct requirement_vector target_reqs;
 };
+
+#define enabler_get_action(_enabler_) action_by_number(_enabler_->action)
 
 #define SPECLIST_TAG action_enabler
 #define SPECLIST_TYPE struct action_enabler
@@ -204,7 +207,7 @@
 {                                                        \
   action_iterate(_act_) {                                \
     action_enabler_list_iterate(                         \
-      action_enablers_for_action(_act_), _enabler_) {
+      action_enablers_for_action((enum gen_action)_act_), _enabler_) {
 
 #define action_enablers_iterate_end                      \
     } action_enabler_list_iterate_end;                   \

Modified: trunk/tools/ruledit/Makefile.am
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/Makefile.am?rev=33792&r1=33791&r2=33792&view=diff
==============================================================================
--- trunk/tools/ruledit/Makefile.am     (original)
+++ trunk/tools/ruledit/Makefile.am     Tue Sep 13 15:29:27 2016
@@ -28,6 +28,7 @@
            meta_req_edit.cpp   \
             meta_requirers_dlg.cpp \
             meta_ruledit_qt.cpp \
+            meta_tab_enablers.cpp \
             meta_tab_misc.cpp  \
             meta_tab_nation.cpp        \
             meta_tab_tech.cpp  \
@@ -41,6 +42,8 @@
                edit_utype.h    \
                tab_building.cpp \
                tab_building.h  \
+               tab_enablers.cpp \
+               tab_enablers.h  \
                tab_good.cpp    \
                tab_good.h      \
                tab_gov.cpp     \

Modified: trunk/tools/ruledit/ruledit_qt.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.cpp?rev=33792&r1=33791&r2=33792&view=diff
==============================================================================
--- trunk/tools/ruledit/ruledit_qt.cpp  (original)
+++ trunk/tools/ruledit/ruledit_qt.cpp  Tue Sep 13 15:29:27 2016
@@ -42,6 +42,7 @@
 #include "requirers_dlg.h"
 #include "ruledit.h"
 #include "tab_building.h"
+#include "tab_enablers.h"
 #include "tab_good.h"
 #include "tab_gov.h"
 #include "tab_misc.h"
@@ -165,6 +166,8 @@
   stack->addTab(good, QString::fromUtf8(R__("Goods")));
   gov = new tab_gov(this);
   stack->addTab(gov, QString::fromUtf8(R__("Governments")));
+  enablers = new tab_enabler(this);
+  stack->addTab(enablers, QString::fromUtf8(R__("Enablers")));
   nation = new tab_nation(this);
   stack->addTab(nation, QString::fromUtf8(R__("Nations")));
 
@@ -209,6 +212,7 @@
     unit->refresh();
     good->refresh();
     gov->refresh();
+    enablers->refresh();
     main_layout->setCurrentIndex(1);
   } else {
     display_msg(R__("Ruleset loading failed!"));

Modified: trunk/tools/ruledit/ruledit_qt.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit_qt.h?rev=33792&r1=33791&r2=33792&view=diff
==============================================================================
--- trunk/tools/ruledit/ruledit_qt.h    (original)
+++ trunk/tools/ruledit/ruledit_qt.h    Tue Sep 13 15:29:27 2016
@@ -35,6 +35,7 @@
 class tab_tech;
 class tab_unit;
 class tab_nation;
+class tab_enabler;
 
 class ruledit_main : public QMainWindow
 {
@@ -78,6 +79,7 @@
     tab_unit *unit;
     tab_good *good;
     tab_gov *gov;
+    tab_enabler *enablers;
     tab_nation *nation;
 
   private slots:

Added: trunk/tools/ruledit/tab_enablers.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.cpp?rev=33792&view=auto
==============================================================================
--- trunk/tools/ruledit/tab_enablers.cpp        (added)
+++ trunk/tools/ruledit/tab_enablers.cpp        Tue Sep 13 15:29:27 2016
@@ -0,0 +1,228 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+// Qt
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QListWidget>
+#include <QMenu>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QToolButton>
+
+// utility
+#include "fcintl.h"
+#include "log.h"
+
+// common
+#include "game.h"
+#include "government.h"
+
+// ruledit
+#include "req_edit.h"
+#include "ruledit.h"
+#include "ruledit_qt.h"
+#include "validity.h"
+
+#include "tab_enablers.h"
+
+/**************************************************************************
+  Setup tab_enabler object
+**************************************************************************/
+tab_enabler::tab_enabler(ruledit_gui *ui_in) : QWidget()
+{
+  QVBoxLayout *main_layout = new QVBoxLayout(this);
+  QGridLayout *enabler_layout = new QGridLayout();
+  QLabel *label;
+  QPushButton *add_button;
+  QPushButton *delete_button;
+  QPushButton *reqs_button;
+
+  ui = ui_in;
+  selected = 0;
+
+  enabler_list = new QListWidget(this);
+
+  connect(enabler_list, SIGNAL(itemSelectionChanged()), this, 
SLOT(select_enabler()));
+  main_layout->addWidget(enabler_list);
+
+  enabler_layout->setSizeConstraint(QLayout::SetMaximumSize);
+
+  label = new QLabel(QString::fromUtf8(R__("Type")));
+  label->setParent(this);
+  enabler_layout->addWidget(label, 0, 0);
+  type = new QLabel();
+  enabler_layout->addWidget(type, 0, 2);
+
+  reqs_button = new QPushButton(QString::fromUtf8(R__("Actor Requirements")), 
this);
+  connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_actor_reqs()));
+  enabler_layout->addWidget(reqs_button, 1, 2);
+  show_experimental(reqs_button);
+
+  reqs_button = new QPushButton(QString::fromUtf8(R__("Target Requirements")), 
this);
+  connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_target_reqs()));
+  enabler_layout->addWidget(reqs_button, 2, 2);
+  show_experimental(reqs_button);
+
+  add_button = new QPushButton(QString::fromUtf8(R__("Add Enabler")), this);
+  connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
+  enabler_layout->addWidget(add_button, 3, 0);
+  show_experimental(add_button);
+
+  delete_button = new QPushButton(QString::fromUtf8(R__("Remove this 
Enabler")), this);
+  connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
+  enabler_layout->addWidget(delete_button, 3, 2);
+  show_experimental(delete_button);
+
+  refresh();
+
+  main_layout->addLayout(enabler_layout);
+
+  setLayout(main_layout);
+}
+
+/**************************************************************************
+  Refresh the information.
+**************************************************************************/
+void tab_enabler::refresh()
+{
+  int n = 0;
+
+  enabler_list->clear();
+
+  action_enablers_iterate(enabler) {
+    if (!enabler->disabled) {
+      char buffer[512];
+      QListWidgetItem *item;
+
+      fc_snprintf(buffer, sizeof(buffer), "#%d: %s", n,
+                  action_rule_name(enabler_get_action(enabler)));
+
+      item = new QListWidgetItem(QString::fromUtf8(buffer));
+
+      enabler_list->insertItem(n++, item);
+    }
+  } action_enablers_iterate_end;
+}
+
+/**************************************************************************
+  Update info of the enabler
+**************************************************************************/
+void tab_enabler::update_enabler_info(struct action_enabler *enabler)
+{
+  selected = enabler;
+
+  if (selected != nullptr) {
+    QString dispn = 
QString::fromUtf8(action_rule_name(enabler_get_action(enabler)));
+
+    type->setText(dispn);
+  } else {
+    type->setText("None");
+  }
+}
+
+/**************************************************************************
+  User selected enabler from the list.
+**************************************************************************/
+void tab_enabler::select_enabler()
+{
+  int i = 0;
+
+  action_enablers_iterate(enabler) {
+    QListWidgetItem *item = enabler_list->item(i++);
+
+    if (item != nullptr && item->isSelected()) {
+      update_enabler_info(enabler);
+    }
+  } action_enablers_iterate_end;
+}
+
+/**************************************************************************
+  User requested enabler deletion 
+**************************************************************************/
+void tab_enabler::delete_now()
+{
+  if (selected != nullptr) {
+    selected->disabled = true;
+
+    refresh();
+    update_enabler_info(nullptr);
+  }
+}
+
+/**************************************************************************
+  Initialize new enabler for use.
+**************************************************************************/
+bool tab_enabler::initialize_new_enabler(struct action_enabler *enabler)
+{
+  return true;
+}
+
+/**************************************************************************
+  User requested new enabler
+**************************************************************************/
+void tab_enabler::add_now()
+{
+  struct action_enabler *new_enabler;
+
+  // Try to reuse freed enabler slot
+  action_enablers_iterate(enabler) {
+    if (enabler->disabled) {
+      if (initialize_new_enabler(enabler)) {
+        enabler->disabled = false;
+        update_enabler_info(enabler);
+        refresh();
+      }
+      return;
+    }
+  } action_enablers_iterate_end;
+
+  // Try to add completely new enabler
+  new_enabler = action_enabler_new();
+
+  new_enabler->action = ACTION_MARKETPLACE;
+
+  action_enabler_list_append(action_enablers_for_action(ACTION_MARKETPLACE),
+                             new_enabler);
+}
+
+/**************************************************************************
+  User wants to edit target reqs
+**************************************************************************/
+void tab_enabler::edit_target_reqs()
+{
+  if (selected != nullptr) {
+    req_edit *redit = new req_edit(ui, QString::fromUtf8(R__("Enabler 
(target)")),
+                                   &selected->target_reqs);
+
+    redit->show();
+  }
+}
+
+/**************************************************************************
+  User wants to edit actor reqs
+**************************************************************************/
+void tab_enabler::edit_actor_reqs()
+{
+  if (selected != nullptr) {
+    req_edit *redit = new req_edit(ui, QString::fromUtf8(R__("Enabler 
(actor)")),
+                                   &selected->actor_reqs);
+
+    redit->show();
+  }
+}
+

Added: trunk/tools/ruledit/tab_enablers.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_enablers.h?rev=33792&view=auto
==============================================================================
--- trunk/tools/ruledit/tab_enablers.h  (added)
+++ trunk/tools/ruledit/tab_enablers.h  Tue Sep 13 15:29:27 2016
@@ -0,0 +1,58 @@
+/***********************************************************************
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__TAB_ENABLERS_H
+#define FC__TAB_ENABLERS_H
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+// Qt
+#include <QWidget>
+
+class QLabel;
+class QLineEdit;
+class QListWidget;
+class QRadioButton;
+
+class ruledit_gui;
+
+class tab_enabler : public QWidget
+{
+  Q_OBJECT
+
+  public:
+    explicit tab_enabler(ruledit_gui *ui_in);
+    void refresh();
+
+  private:
+    ruledit_gui *ui;
+    void update_enabler_info(struct action_enabler *enabler);
+    bool initialize_new_enabler(struct action_enabler *enabler);
+
+    QLabel *type;
+    QListWidget *enabler_list;
+
+    struct action_enabler *selected;
+
+  private slots:
+    void select_enabler();
+    void add_now();
+    void delete_now();
+    void edit_target_reqs();
+    void edit_actor_reqs();
+};
+
+
+#endif // FC__TAB_ENABLERS_H


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

Reply via email to