From 1229a2acb03dffa44cb328f50f5272542de0530a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 8 Apr 2021 16:10:31 +0300 Subject: [PATCH 51/51] Ruledit: Add support for description file reference editing See osdn #41946 Signed-off-by: Marko Lindqvist --- tools/ruledit/ruledit_qt.cpp | 3 +- tools/ruledit/tab_misc.cpp | 57 ++++++++++++++++++++++++++++++++++++ tools/ruledit/tab_misc.h | 5 ++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index afefb9e952..46086059bc 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -232,7 +232,7 @@ void ruledit_gui::launch_now() } bldg->refresh(); - misc->refresh(); + misc->ruleset_loaded(); nation->refresh(); tech->refresh(); unit->refresh(); @@ -295,6 +295,7 @@ void ruledit_gui::show_required(requirers_dlg *requirers, const char *msg) **************************************************************************/ void ruledit_gui::flush_widgets() { + misc->flush_widgets(); nation->flush_widgets(); } diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp index ff639dcffb..a8c7a73fca 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -16,6 +16,7 @@ #endif // Qt +#include #include #include #include @@ -53,6 +54,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() QGridLayout *main_layout = new QGridLayout(this); QLabel *save_label; QLabel *save_ver_label; + QLabel *label; QLabel *name_label; QLabel *version_label; QPushButton *save_button; @@ -91,6 +93,20 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() save_button = new QPushButton(QString::fromUtf8(R__("Save now")), this); connect(save_button, SIGNAL(pressed()), this, SLOT(save_now())); main_layout->addWidget(save_button, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Description from file"))); + label->setParent(this); + main_layout->addWidget(label, row, 0); + desc_via_file = new QCheckBox(this); + connect(desc_via_file, SIGNAL(toggled(bool)), this, SLOT(desc_file_toggle(bool))); + main_layout->addWidget(desc_via_file, row++, 1); + + label = new QLabel(QString::fromUtf8(R__("Description file"))); + label->setParent(this); + main_layout->addWidget(label, row, 0); + desc_file = new QLineEdit(this); + main_layout->addWidget(desc_file, row++, 1); + always_active_effects = new QPushButton(QString::fromUtf8(R__("Always active Effects")), this); connect(always_active_effects, SIGNAL(pressed()), this, SLOT(edit_aae_effects())); main_layout->addWidget(always_active_effects, row++, 1); @@ -190,6 +206,21 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() setLayout(main_layout); } +/**********************************************************************//** + Setup the information from loaded ruleset +**************************************************************************/ +void tab_misc::ruleset_loaded() +{ + if (game.server.ruledit.description_file != NULL) { + desc_via_file->setChecked(true); + desc_file->setText(game.server.ruledit.description_file); + } else { + desc_file->setEnabled(false); + } + + refresh(); +} + /**********************************************************************//** Refresh the information. **************************************************************************/ @@ -376,3 +407,29 @@ void tab_misc::edit_all_effects() ui->open_effect_edit(QString::fromUtf8(R__("All effects")), nullptr, EFMC_ALL); } + +/**********************************************************************//** + Flush information from widgets to stores where it can be saved from. +**************************************************************************/ +void tab_misc::flush_widgets() +{ + if (desc_via_file->isChecked()) { + QByteArray df_bytes; + + df_bytes = desc_file->text().toUtf8(); + game.server.ruledit.description_file = fc_strdup(df_bytes.data()); + } else { + if (game.server.ruledit.description_file != NULL) { + free(game.server.ruledit.description_file); + } + game.server.ruledit.description_file = NULL; + } +} + +/**********************************************************************//** + Toggled description from file setting +**************************************************************************/ +void tab_misc::desc_file_toggle(bool checked) +{ + desc_file->setEnabled(checked); +} diff --git a/tools/ruledit/tab_misc.h b/tools/ruledit/tab_misc.h index d7bb9cf4d6..b6b0f1a5b4 100644 --- a/tools/ruledit/tab_misc.h +++ b/tools/ruledit/tab_misc.h @@ -17,6 +17,7 @@ // Qt #include +class QCheckBox; class QLineEdit; class QRadioButton; class QTableWidget; @@ -29,6 +30,7 @@ class tab_misc : public QWidget public: explicit tab_misc(ruledit_gui *ui_in); + void ruleset_loaded(); void refresh(); void flush_widgets(); @@ -37,6 +39,7 @@ class tab_misc : public QWidget void refresh_stats(); void edit_aae_effects(); void edit_all_effects(); + void desc_file_toggle(bool checked); private: ruledit_gui *ui; @@ -45,6 +48,8 @@ class tab_misc : public QWidget QLineEdit *savedir; QRadioButton *savedir_version; QTableWidget *stats; + QCheckBox *desc_via_file; + QLineEdit *desc_file; }; -- 2.30.2