From 4790b4a1f9864e0641551ecc2c2520f986a2ea28 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 9 Apr 2023 10:54:27 +0300 Subject: [PATCH 25/25] Ruledit: Add extra editing dialog See osdn #47818 Signed-off-by: Marko Lindqvist --- common/extras.c | 1 + common/extras.h | 1 + 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 | 44 +++++-- tools/ruledit/tab_extras.h | 1 + translations/ruledit/POTFILES.in | 1 + 9 files changed, 322 insertions(+), 8 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 0c24a4e2af..a8bae36b8e 100644 --- a/common/extras.c +++ b/common/extras.c @@ -66,6 +66,7 @@ void extras_init(void) extras[i].rmcauses = 0; extras[i].helptext = NULL; extras[i].disabled = FALSE; + extras[i].ruledit_dlg = NULL; extras[i].visibility_req = A_NONE; } } diff --git a/common/extras.h b/common/extras.h index 196777e97e..b70b930ef7 100644 --- a/common/extras.h +++ b/common/extras.h @@ -83,6 +83,7 @@ struct extra_type int id; struct name_translation name; bool disabled; + void *ruledit_dlg; enum extra_category category; uint16_t causes; uint8_t rmcauses; diff --git a/tools/ruledit/.gitignore b/tools/ruledit/.gitignore index 5fb6c6f7ba..9ae2651418 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_req_edit.cpp diff --git a/tools/ruledit/Makefile.am b/tools/ruledit/Makefile.am index 079974172a..41bbcfebaa 100644 --- a/tools/ruledit/Makefile.am +++ b/tools/ruledit/Makefile.am @@ -27,6 +27,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 \ @@ -48,6 +49,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..6735af9182 --- /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 6a930462eb..393edadaab 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" @@ -50,6 +51,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; @@ -66,8 +69,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); @@ -76,22 +79,26 @@ 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); add_button = new QPushButton(QString::fromUtf8(R__("Add Extra")), this); connect(add_button, SIGNAL(pressed()), this, SLOT(add_now())); - extra_layout->addWidget(add_button, 5, 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, 5, 2); + extra_layout->addWidget(delete_button, row++, 2); show_experimental(delete_button); refresh(); @@ -209,6 +216,10 @@ void tab_extras::delete_now() selected->disabled = true; + if (selected->ruledit_dlg != nullptr) { + ((edit_extra *)selected->ruledit_dlg)->done(0); + } + refresh(); update_extra_info(nullptr); } @@ -286,3 +297,20 @@ void tab_extras::edit_reqs() &selected->reqs); } } + +/**********************************************************************//** + 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 eed144b190..ca9d8a927b 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(); }; diff --git a/translations/ruledit/POTFILES.in b/translations/ruledit/POTFILES.in index a20109b916..2b25630e67 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