From 8165c73b3e21bda013cc34a2625e057114dfda46 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 9 Apr 2023 10:45:04 +0300 Subject: [PATCH 44/44] Ruledit: Add extra editing dialog See osdn #47818 Signed-off-by: Marko Lindqvist --- common/extras.c | 1 + common/extras.h | 1 + meson.build | 2 + tools/ruledit/.gitignore | 1 + tools/ruledit/Makefile.am | 3 + tools/ruledit/edit_extra.cpp | 217 +++++++++++++++++++++++++++++++ tools/ruledit/edit_extra.h | 61 +++++++++ tools/ruledit/tab_extras.cpp | 46 +++++-- tools/ruledit/tab_extras.h | 1 + translations/ruledit/POTFILES.in | 1 + 10 files changed, 325 insertions(+), 9 deletions(-) create mode 100644 tools/ruledit/edit_extra.cpp create mode 100644 tools/ruledit/edit_extra.h diff --git a/common/extras.c b/common/extras.c index 55d794b76d..dd381c0da2 100644 --- a/common/extras.c +++ b/common/extras.c @@ -67,6 +67,7 @@ void extras_init(void) extras[i].rmcauses = 0; extras[i].helptext = NULL; extras[i].ruledit_disabled = FALSE; + extras[i].ruledit_dlg = NULL; extras[i].visibility_req = A_NONE; } } diff --git a/common/extras.h b/common/extras.h index e39b506a3d..ac57684571 100644 --- a/common/extras.h +++ b/common/extras.h @@ -86,6 +86,7 @@ struct extra_type int id; struct name_translation name; bool ruledit_disabled; + void *ruledit_dlg; enum extra_category category; uint16_t causes; uint8_t rmcauses; diff --git a/meson.build b/meson.build index 535aa70ae4..59d0129d83 100644 --- a/meson.build +++ b/meson.build @@ -3699,6 +3699,7 @@ endif mocced_ruledit = qt_mod.preprocess( moc_headers: [ 'tools/ruledit/conversion_log.h', + 'tools/ruledit/edit_extra.h', 'tools/ruledit/edit_impr.h', 'tools/ruledit/edit_terrain.h', 'tools/ruledit/edit_utype.h', @@ -3723,6 +3724,7 @@ mocced_ruledit = qt_mod.preprocess( executable('freeciv-ruledit', 'tools/ruledit/conversion_log.cpp', + 'tools/ruledit/edit_extra.cpp', 'tools/ruledit/edit_impr.cpp', 'tools/ruledit/edit_terrain.cpp', 'tools/ruledit/edit_utype.cpp', diff --git a/tools/ruledit/.gitignore b/tools/ruledit/.gitignore index b46de31e7c..65825d142a 100644 --- a/tools/ruledit/.gitignore +++ b/tools/ruledit/.gitignore @@ -2,6 +2,7 @@ /Makefile /.deps /meta_conversion_log.cpp +/meta_edit_extra.cpp /meta_edit_impr.cpp /meta_edit_utype.cpp /meta_effect_edit.cpp diff --git a/tools/ruledit/Makefile.am b/tools/ruledit/Makefile.am index 896002b4e5..0e33207eaa 100644 --- a/tools/ruledit/Makefile.am +++ b/tools/ruledit/Makefile.am @@ -25,6 +25,7 @@ freeciv_ruledit_CXXFLAGS = $(ruledit_cxxflags) MOC_FILES = \ meta_conversion_log.cpp \ + meta_edit_extra.cpp \ meta_edit_impr.cpp \ meta_edit_terrain.cpp \ meta_edit_utype.cpp \ @@ -49,6 +50,8 @@ MOC_FILES = \ freeciv_ruledit_SOURCES = \ conversion_log.cpp \ conversion_log.h \ + edit_extra.cpp \ + edit_extra.h \ edit_impr.cpp \ edit_impr.h \ edit_terrain.cpp \ diff --git a/tools/ruledit/edit_extra.cpp b/tools/ruledit/edit_extra.cpp new file mode 100644 index 0000000000..30740a04e7 --- /dev/null +++ b/tools/ruledit/edit_extra.cpp @@ -0,0 +1,217 @@ +/*********************************************************************** + Freeciv - Copyright (C) 2023 The Freeciv Team + 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 +#endif + +// Qt +#include +#include +#include + +// common +#include "extras.h" + +// ruledit +#include "ruledit.h" +#include "ruledit_qt.h" + +#include "edit_extra.h" + +/**********************************************************************//** + Setup edit_extra object +**************************************************************************/ +edit_extra::edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in) + : QDialog() +{ + QVBoxLayout *main_layout = new QVBoxLayout(this); + QGridLayout *extra_layout = new QGridLayout(); + QLabel *label; + int row = 0; + + ui = ui_in; + extra = extra_in; + + setWindowTitle(QString::fromUtf8(extra_rule_name(extra))); + + label = new QLabel(QString::fromUtf8(R__("Graphics tag"))); + label->setParent(this); + + gfx_tag = new QLineEdit(this); + connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(gfx_tag, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Alt graphics tag"))); + label->setParent(this); + + gfx_tag_alt = new QLineEdit(this); + connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(gfx_tag_alt, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Activity graphics tag"))); + label->setParent(this); + + act_gfx = new QLineEdit(this); + connect(act_gfx, SIGNAL(returnPressed()), this, SLOT(act_gfx_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(act_gfx, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Alt activity gfx tag"))); + label->setParent(this); + + act_gfx_alt = new QLineEdit(this); + connect(act_gfx_alt, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(act_gfx_alt, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Second alt activity gfx tag"))); + label->setParent(this); + + act_gfx_alt2 = new QLineEdit(this); + connect(act_gfx_alt2, SIGNAL(returnPressed()), this, SLOT(act_gfx_alt2_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(act_gfx_alt2, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Removal activity graphics tag"))); + label->setParent(this); + + rmact_gfx = new QLineEdit(this); + connect(rmact_gfx, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(rmact_gfx, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Alt removal activity gfx tag"))); + label->setParent(this); + + rmact_gfx_alt = new QLineEdit(this); + connect(rmact_gfx_alt, SIGNAL(returnPressed()), this, SLOT(rmact_gfx_alt_given())); + + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(rmact_gfx_alt, row++, 1); + + refresh(); + + main_layout->addLayout(extra_layout); + + setLayout(main_layout); +} + +/**********************************************************************//** + User is closing dialog. +**************************************************************************/ +void edit_extra::closeEvent(QCloseEvent *cevent) +{ + // Save values from text fields. + gfx_tag_given(); + gfx_tag_alt_given(); + act_gfx_given(); + act_gfx_alt_given(); + act_gfx_alt2_given(); + rmact_gfx_given(); + rmact_gfx_alt_given(); + + extra->ruledit_dlg = nullptr; +} + +/**********************************************************************//** + Refresh the information. +**************************************************************************/ +void edit_extra::refresh() +{ + gfx_tag->setText(extra->graphic_str); + gfx_tag_alt->setText(extra->graphic_alt); + act_gfx->setText(extra->activity_gfx); + act_gfx_alt->setText(extra->act_gfx_alt); + act_gfx_alt2->setText(extra->act_gfx_alt2); + rmact_gfx->setText(extra->rmact_gfx); + rmact_gfx_alt->setText(extra->rmact_gfx_alt); +} + +/**********************************************************************//** + User entered new graphics tag. +**************************************************************************/ +void edit_extra::gfx_tag_given() +{ + QByteArray tag_bytes = gfx_tag->text().toUtf8(); + + sz_strlcpy(extra->graphic_str, tag_bytes); +} + +/**********************************************************************//** + User entered new alternative graphics tag. +**************************************************************************/ +void edit_extra::gfx_tag_alt_given() +{ + QByteArray tag_bytes = gfx_tag_alt->text().toUtf8(); + + sz_strlcpy(extra->graphic_alt, tag_bytes); +} + +/**********************************************************************//** + User entered new activity graphics tag. +**************************************************************************/ +void edit_extra::act_gfx_given() +{ + QByteArray tag_bytes = act_gfx_alt->text().toUtf8(); + + sz_strlcpy(extra->activity_gfx, tag_bytes); +} + +/**********************************************************************//** + User entered new alternative activity graphics tag. +**************************************************************************/ +void edit_extra::act_gfx_alt_given() +{ + QByteArray tag_bytes = act_gfx_alt->text().toUtf8(); + + sz_strlcpy(extra->act_gfx_alt, tag_bytes); +} + +/**********************************************************************//** + User entered new secondary alternative activity graphics tag. +**************************************************************************/ +void edit_extra::act_gfx_alt2_given() +{ + QByteArray tag_bytes = act_gfx_alt2->text().toUtf8(); + + sz_strlcpy(extra->act_gfx_alt2, tag_bytes); +} + +/**********************************************************************//** + User entered new alternative graphics tag. +**************************************************************************/ +void edit_extra::rmact_gfx_given() +{ + QByteArray tag_bytes = rmact_gfx->text().toUtf8(); + + sz_strlcpy(extra->rmact_gfx, tag_bytes); +} + +/**********************************************************************//** + User entered new alternative removal activity graphics tag. +**************************************************************************/ +void edit_extra::rmact_gfx_alt_given() +{ + QByteArray tag_bytes = rmact_gfx_alt->text().toUtf8(); + + sz_strlcpy(extra->rmact_gfx_alt, tag_bytes); +} diff --git a/tools/ruledit/edit_extra.h b/tools/ruledit/edit_extra.h new file mode 100644 index 0000000000..2e5e42b4bb --- /dev/null +++ b/tools/ruledit/edit_extra.h @@ -0,0 +1,61 @@ +/*********************************************************************** + Freeciv - Copyright (C) 2023 The Freeciv Team + 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__EDIT_EXTRA_H +#define FC__EDIT_EXTRA_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +// Qt +#include + +class QLineEdit; +class QSpinBox; + +class ruledit_gui; + +class edit_extra : public QDialog +{ + Q_OBJECT + + public: + explicit edit_extra(ruledit_gui *ui_in, struct extra_type *extra_in); + void refresh(); + + private: + ruledit_gui *ui; + struct extra_type *extra; + QLineEdit *gfx_tag; + QLineEdit *gfx_tag_alt; + QLineEdit *act_gfx; + QLineEdit *act_gfx_alt; + QLineEdit *act_gfx_alt2; + QLineEdit *rmact_gfx; + QLineEdit *rmact_gfx_alt; + + protected: + void closeEvent(QCloseEvent *cevent); + + private slots: + void gfx_tag_given(); + void gfx_tag_alt_given(); + void act_gfx_given(); + void act_gfx_alt_given(); + void act_gfx_alt2_given(); + void rmact_gfx_given(); + void rmact_gfx_alt_given(); +}; + +#endif // FC__EDIT_EXTRA_H diff --git a/tools/ruledit/tab_extras.cpp b/tools/ruledit/tab_extras.cpp index 17945211d5..fee5dd11e6 100644 --- a/tools/ruledit/tab_extras.cpp +++ b/tools/ruledit/tab_extras.cpp @@ -33,6 +33,7 @@ #include "extras.h" // ruledit +#include "edit_extra.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -51,6 +52,8 @@ tab_extras::tab_extras(ruledit_gui *ui_in) : QWidget() QPushButton *add_button; QPushButton *delete_button; QPushButton *reqs_button; + QPushButton *edit_button; + int row = 0; ui = ui_in; selected = 0; @@ -67,8 +70,8 @@ tab_extras::tab_extras(ruledit_gui *ui_in) : QWidget() rname = new QLineEdit(this); rname->setText(R__("None")); connect(rname, SIGNAL(returnPressed()), this, SLOT(name_given())); - extra_layout->addWidget(label, 0, 0); - extra_layout->addWidget(rname, 0, 2); + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(rname, row++, 2); label = new QLabel(QString::fromUtf8(R__("Name"))); label->setParent(this); @@ -77,26 +80,30 @@ tab_extras::tab_extras(ruledit_gui *ui_in) : QWidget() name = new QLineEdit(this); name->setText(R__("None")); connect(name, SIGNAL(returnPressed()), this, SLOT(name_given())); - extra_layout->addWidget(label, 1, 0); - extra_layout->addWidget(same_name, 1, 1); - extra_layout->addWidget(name, 1, 2); + extra_layout->addWidget(label, row, 0); + extra_layout->addWidget(same_name, row, 1); + extra_layout->addWidget(name, row++, 2); + + edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this); + connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now())); + extra_layout->addWidget(edit_button, row++, 2); reqs_button = new QPushButton(QString::fromUtf8(R__("Requirements")), this); connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs())); - extra_layout->addWidget(reqs_button, 2, 2); + extra_layout->addWidget(reqs_button, row++, 2); effects_button = new QPushButton(QString::fromUtf8(R__("Effects")), this); connect(effects_button, SIGNAL(pressed()), this, SLOT(edit_effects())); - extra_layout->addWidget(effects_button, 3, 2); + extra_layout->addWidget(effects_button, row++, 2); add_button = new QPushButton(QString::fromUtf8(R__("Add Extra")), this); connect(add_button, SIGNAL(pressed()), this, SLOT(add_now())); - extra_layout->addWidget(add_button, 4, 0); + extra_layout->addWidget(add_button, row, 0); show_experimental(add_button); delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Extra")), this); connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now())); - extra_layout->addWidget(delete_button, 4, 2); + extra_layout->addWidget(delete_button, row++, 2); show_experimental(delete_button); refresh(); @@ -214,6 +221,10 @@ void tab_extras::delete_now() selected->ruledit_disabled = true; + if (selected->ruledit_dlg != nullptr) { + ((edit_extra *)selected->ruledit_dlg)->done(0); + } + refresh(); update_extra_info(nullptr); } @@ -307,3 +318,20 @@ void tab_extras::edit_effects() &uni, EFMC_NORMAL); } } + +/**********************************************************************//** + User requested extra edit dialog +**************************************************************************/ +void tab_extras::edit_now() +{ + if (selected != nullptr) { + if (selected->ruledit_dlg == nullptr) { + edit_extra *edit = new edit_extra(ui, selected); + + edit->show(); + selected->ruledit_dlg = edit; + } else { + ((edit_extra *)selected->ruledit_dlg)->raise(); + } + } +} diff --git a/tools/ruledit/tab_extras.h b/tools/ruledit/tab_extras.h index 50c888036c..55062861ea 100644 --- a/tools/ruledit/tab_extras.h +++ b/tools/ruledit/tab_extras.h @@ -52,6 +52,7 @@ class tab_extras : public QWidget void select_extra(); void add_now(); void delete_now(); + void edit_now(); void same_name_toggle(bool checked); void edit_reqs(); void edit_effects(); diff --git a/translations/ruledit/POTFILES.in b/translations/ruledit/POTFILES.in index e246ffac6e..445795fd76 100644 --- a/translations/ruledit/POTFILES.in +++ b/translations/ruledit/POTFILES.in @@ -1,6 +1,7 @@ # List of source files containing translatable strings. # (Filenames are sorted alphabetically and relative to top-level directory.) tools/ruledit/conversion_log.cpp +tools/ruledit/edit_extra.cpp tools/ruledit/edit_impr.cpp tools/ruledit/edit_terrain.cpp tools/ruledit/edit_utype.cpp -- 2.39.2