From 326d8fbeff95debd8a0c58773ad051ec7e8ccd9b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 8 Apr 2021 16:18:38 +0300 Subject: [PATCH 22/22] 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 | 56 ++++++++++++++++++++++++++++++++++++ tools/ruledit/tab_misc.h | 5 ++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index 092c766ed9..4d55db1b78 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -195,7 +195,7 @@ void ruledit_gui::launch_now() } bldg->refresh(); - misc->refresh(); + misc->ruleset_loaded(); nation->refresh(); tech->refresh(); unit->refresh(); @@ -237,6 +237,7 @@ void ruledit_gui::show_required(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 38d50f80bb..72ff1e7e7b 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -16,6 +16,7 @@ #endif // Qt +#include #include #include #include @@ -48,6 +49,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() { QGridLayout *main_layout = new QGridLayout(this); QLabel *save_label; + QLabel *label; QLabel *name_label; QLabel *version_label; QPushButton *save_button; @@ -79,6 +81,19 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() 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); + stats = new QTableWidget(this); stats->setColumnCount(8); stats->setRowCount(6); @@ -156,6 +171,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. **************************************************************************/ @@ -255,3 +285,29 @@ void tab_misc::refresh_stats() stats->resizeColumnsToContents(); } + +/************************************************************************** + 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 7458d8dbfc..d21a1d9c95 100644 --- a/tools/ruledit/tab_misc.h +++ b/tools/ruledit/tab_misc.h @@ -17,6 +17,7 @@ // Qt #include +class QCheckBox; class QLineEdit; class QTableWidget; @@ -28,12 +29,14 @@ class tab_misc : public QWidget public: explicit tab_misc(ruledit_gui *ui_in); + void ruleset_loaded(); void refresh(); void flush_widgets(); private slots: void save_now(); void refresh_stats(); + void desc_file_toggle(bool checked); private: ruledit_gui *ui; @@ -41,6 +44,8 @@ class tab_misc : public QWidget QLineEdit *version; QLineEdit *savedir; QTableWidget *stats; + QCheckBox *desc_via_file; + QLineEdit *desc_file; }; -- 2.30.2