Author: cazfi Date: Wed May 10 18:55:59 2017 New Revision: 35496 URL: http://svn.gna.org/viewcvs/freeciv?rev=35496&view=rev Log: Add initial version of effect edit dialog to ruledit
See hrm Feature #658566 Added: trunk/tools/ruledit/effect_edit.cpp trunk/tools/ruledit/effect_edit.h Modified: trunk/tools/ruledit/Makefile.am trunk/tools/ruledit/tab_building.cpp trunk/tools/ruledit/tab_building.h trunk/tools/ruledit/validity.c trunk/tools/ruledit/validity.h Modified: trunk/tools/ruledit/Makefile.am URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/Makefile.am?rev=35496&r1=35495&r2=35496&view=diff ============================================================================== --- trunk/tools/ruledit/Makefile.am (original) +++ trunk/tools/ruledit/Makefile.am Wed May 10 18:55:59 2017 @@ -25,6 +25,7 @@ MOC_FILES = \ meta_edit_utype.cpp \ + meta_effect_edit.cpp \ meta_req_edit.cpp \ meta_requirers_dlg.cpp \ meta_ruledit_qt.cpp \ @@ -42,6 +43,8 @@ freeciv_ruledit_SOURCES = \ edit_utype.cpp \ edit_utype.h \ + effect_edit.cpp \ + effect_edit.h \ tab_building.cpp \ tab_building.h \ tab_enablers.cpp \ Added: trunk/tools/ruledit/effect_edit.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/effect_edit.cpp?rev=35496&view=auto ============================================================================== --- trunk/tools/ruledit/effect_edit.cpp (added) +++ trunk/tools/ruledit/effect_edit.cpp Wed May 10 18:55:59 2017 @@ -0,0 +1,203 @@ +/*********************************************************************** + 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 <QLabel> +#include <QLineEdit> +#include <QMenu> +#include <QPushButton> + +// utility +#include "fcintl.h" + +// common +#include "effects.h" + +// ruledit +#include "ruledit.h" +#include "validity.h" + +#include "effect_edit.h" + +/************************************************************************** + Setup effect_edit object +**************************************************************************/ +effect_edit::effect_edit(ruledit_gui *ui_in, QString target, + struct universal *filter_in) : QDialog() +{ + QVBoxLayout *main_layout = new QVBoxLayout(this); + QGridLayout *effect_edit_layout = new QGridLayout(); + QHBoxLayout *active_layout = new QHBoxLayout(); + QPushButton *close_button; + QMenu *menu; + QLabel *lbl; + enum effect_type eff; + + ui = ui_in; + selected = nullptr; + filter = *filter_in; + + list_widget = new QListWidget(this); + effects = effect_list_new(); + + connect(list_widget, SIGNAL(itemSelectionChanged()), this, SLOT(select_effect())); + main_layout->addWidget(list_widget); + + lbl = new QLabel(R__("Type:")); + active_layout->addWidget(lbl, 0, 0); + edit_type_button = new QToolButton(); + menu = new QMenu(); + edit_type_button->setToolButtonStyle(Qt::ToolButtonTextOnly); + edit_type_button->setPopupMode(QToolButton::MenuButtonPopup); + connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(effect_type_menu(QAction *))); + edit_type_button->setMenu(menu); + for (eff = (enum effect_type)0; eff < EFT_COUNT; + eff = (enum effect_type)(eff + 1)) { + menu->addAction(effect_type_name(eff)); + } + active_layout->addWidget(edit_type_button, 1, 0); + + main_layout->addLayout(active_layout); + + close_button = new QPushButton(QString::fromUtf8(R__("Close")), this); + connect(close_button, SIGNAL(pressed()), this, SLOT(close_now())); + effect_edit_layout->addWidget(close_button, 0, 0); + + refresh(); + + main_layout->addLayout(effect_edit_layout); + + setLayout(main_layout); + setWindowTitle(target); +} + +/************************************************************************** + Effect edit destructor +**************************************************************************/ +effect_edit::~effect_edit() +{ + effect_list_destroy(effects); +} + +/************************************************************************** + Callback to fill effects list from iterate_effect_cache() +**************************************************************************/ +static bool effect_list_fill_cb(struct effect *peffect, void *data) +{ + struct effect_list_fill_data *cbdata = (struct effect_list_fill_data *)data; + + if (cbdata->filter == nullptr) { + // Look for empty req lists. + if (requirement_vector_size(&peffect->reqs) == 0) { + cbdata->edit->add_effect_to_list(peffect, cbdata); + } + } else if (universal_in_req_vec(cbdata->filter, &peffect->reqs)) { + cbdata->edit->add_effect_to_list(peffect, cbdata); + } + + return true; +} + +/************************************************************************** + Refresh the information. +**************************************************************************/ +void effect_edit::refresh() +{ + struct effect_list_fill_data cb_data; + + list_widget->clear(); + effect_list_clear(effects); + cb_data.filter = &filter; + cb_data.edit = this; + cb_data.num = 0; + + iterate_effect_cache(effect_list_fill_cb, &cb_data); + + fill_active(); +} + +/************************************************************************** + Add entry to effect list. +**************************************************************************/ +void effect_edit::add_effect_to_list(struct effect *peffect, + struct effect_list_fill_data *data) +{ + char buf[512]; + QListWidgetItem *item; + + fc_snprintf(buf, sizeof(buf), _("Effect #%d: %s"), + data->num, effect_type_name(peffect->type)); + + item = new QListWidgetItem(QString::fromUtf8(buf)); + list_widget->insertItem(data->num++, item); + effect_list_append(effects, peffect); + if (selected == peffect) { + item->setSelected(true); + } +} + +/************************************************************************** + User pushed close button +**************************************************************************/ +void effect_edit::close_now() +{ + done(0); +} + +/************************************************************************** + User selected effect from the list. +**************************************************************************/ +void effect_edit::select_effect() +{ + int i = 0; + + effect_list_iterate(effects, peffect) { + QListWidgetItem *item = list_widget->item(i++); + + if (item != nullptr && item->isSelected()) { + selected = peffect; + fill_active(); + return; + } + } effect_list_iterate_end; +} + +/************************************************************************** + Fill active menus from selected effect. +**************************************************************************/ +void effect_edit::fill_active() +{ + if (selected != nullptr) { + edit_type_button->setText(effect_type_name(selected->type)); + } +} + +/************************************************************************** + User selected type for the effect. +**************************************************************************/ +void effect_edit::effect_type_menu(QAction *action) +{ + enum effect_type type = effect_type_by_name(action->text().toUtf8().data(), + fc_strcasecmp); + + if (selected != nullptr) { + selected->type = type; + } + + refresh(); +} Added: trunk/tools/ruledit/effect_edit.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/effect_edit.h?rev=35496&view=auto ============================================================================== --- trunk/tools/ruledit/effect_edit.h (added) +++ trunk/tools/ruledit/effect_edit.h Wed May 10 18:55:59 2017 @@ -0,0 +1,70 @@ +/*********************************************************************** + 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__EFFECT_EDIT_H +#define FC__EFFECT_EDIT_H + +#ifdef HAVE_CONFIG_H +#include <fc_config.h> +#endif + +// Qt +#include <QDialog> +#include <QListWidget> +#include <QToolButton> + +// common +#include "requirements.h" + +class ruledit_gui; + +struct effect_list_fill_data +{ + struct universal *filter; + class effect_edit *edit; + int num; +}; + +class effect_edit : public QDialog +{ + Q_OBJECT + + public: + explicit effect_edit(ruledit_gui *ui_in, QString target, + struct universal *filter_in); + ~effect_edit(); + void refresh(); + void add(const char *msg); + void add_effect_to_list(struct effect *peffect, + struct effect_list_fill_data *data); + + private: + ruledit_gui *ui; + + QListWidget *list_widget; + struct universal filter; + struct effect_list *effects; + + struct effect *selected; + + QToolButton *edit_type_button; + + private slots: + void select_effect(); + void fill_active(); + void close_now(); + + void effect_type_menu(QAction *action); +}; + +#endif // FC__EFFECT_EDIT_H Modified: trunk/tools/ruledit/tab_building.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_building.cpp?rev=35496&r1=35495&r2=35496&view=diff ============================================================================== --- trunk/tools/ruledit/tab_building.cpp (original) +++ trunk/tools/ruledit/tab_building.cpp Wed May 10 18:55:59 2017 @@ -33,6 +33,7 @@ #include "improvement.h" // ruledit +#include "effect_edit.h" #include "req_edit.h" #include "ruledit.h" #include "ruledit_qt.h" @@ -51,6 +52,7 @@ QPushButton *add_button; QPushButton *delete_button; QPushButton *reqs_button; + QPushButton *effects_button; ui = ui_in; selected = 0; @@ -85,14 +87,19 @@ connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs())); bldg_layout->addWidget(reqs_button, 2, 2); + effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this); + connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects())); + bldg_layout->addWidget(effects_button, 3, 2); + show_experimental(effects_button); + add_button = new QPushButton(QString::fromUtf8(R__("Add Building")), this); connect(add_button, SIGNAL(pressed()), this, SLOT(add_now2())); - bldg_layout->addWidget(add_button, 3, 0); + bldg_layout->addWidget(add_button, 4, 0); show_experimental(add_button); delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Building")), this); connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now())); - bldg_layout->addWidget(delete_button, 3, 2); + bldg_layout->addWidget(delete_button, 4, 2); show_experimental(delete_button); refresh(); @@ -277,3 +284,22 @@ redit->show(); } } + +/************************************************************************** + User wants to edit effects +**************************************************************************/ +void tab_building::edit_effects() +{ + if (selected != nullptr) { + effect_edit *e_edit; + struct universal uni; + + uni.value.building = selected; + uni.kind = VUT_IMPROVEMENT; + + e_edit = new effect_edit(ui, QString::fromUtf8(improvement_rule_name(selected)), + &uni); + + e_edit->show(); + } +} Modified: trunk/tools/ruledit/tab_building.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_building.h?rev=35496&r1=35495&r2=35496&view=diff ============================================================================== --- trunk/tools/ruledit/tab_building.h (original) +++ trunk/tools/ruledit/tab_building.h Wed May 10 18:55:59 2017 @@ -54,6 +54,7 @@ void delete_now(); void same_name_toggle(bool checked); void edit_reqs(); + void edit_effects(); }; Modified: trunk/tools/ruledit/validity.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/validity.c?rev=35496&r1=35495&r2=35496&view=diff ============================================================================== --- trunk/tools/ruledit/validity.c (original) +++ trunk/tools/ruledit/validity.c Wed May 10 18:55:59 2017 @@ -33,8 +33,8 @@ /************************************************************************** Check if universal is mentioned in the requirement vector. **************************************************************************/ -static bool universal_in_req_vec(const struct universal *uni, - const struct requirement_vector *preqs) +bool universal_in_req_vec(const struct universal *uni, + const struct requirement_vector *preqs) { requirement_vector_iterate(preqs, preq) { if (are_universals_equal(uni, &preq->source)) { Modified: trunk/tools/ruledit/validity.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/validity.h?rev=35496&r1=35495&r2=35496&view=diff ============================================================================== --- trunk/tools/ruledit/validity.h (original) +++ trunk/tools/ruledit/validity.h Wed May 10 18:55:59 2017 @@ -17,6 +17,9 @@ extern "C" { #endif /* __cplusplus */ +bool universal_in_req_vec(const struct universal *uni, + const struct requirement_vector *preqs); + typedef void (*requirers_cb)(const char *msg, void *data); bool is_tech_needed(struct advance *padv, requirers_cb cb, void *data); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits