From 6a9efd50932e33a744818dc62e23dc37a7501abc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 18 Feb 2023 00:27:58 +0200 Subject: [PATCH 11/23] Ruledit: Skip ruleset selection if one given from commandline See osdn #46007 Signed-off-by: Marko Lindqvist --- tools/ruledit/ruledit_qt.cpp | 68 ++++++++++++++++++++++-------------- tools/ruledit/ruledit_qt.h | 4 ++- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index 5b0559dadf..492c63b2d3 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -106,8 +106,6 @@ void ruledit_qt_display_requirers(const char *msg, void *data) void ruledit_gui::setup(QWidget *central_in) { QVBoxLayout *full_layout = new QVBoxLayout(); - QVBoxLayout *preload_layout = new QVBoxLayout(); - QWidget *preload_widget = new QWidget(); QVBoxLayout *edit_layout = new QVBoxLayout(); QWidget *edit_widget = new QWidget(); QPushButton *ruleset_accept; @@ -140,29 +138,30 @@ void ruledit_gui::setup(QWidget *central_in) main_layout = new QStackedLayout(); - preload_layout->setSizeConstraint(QLayout::SetMaximumSize); - version_label = new QLabel(verbuf); - version_label->setAlignment(Qt::AlignHCenter); - version_label->setParent(central); - preload_layout->addWidget(version_label); - rs_label = new QLabel(QString::fromUtf8(R__("Give ruleset to use as starting point."))); - rs_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); - preload_layout->addWidget(rs_label); - ruleset_select = new QLineEdit(central); - if (reargs.ruleset) { - ruleset_select->setText(reargs.ruleset); - } else { + if (reargs.ruleset == nullptr) { + QVBoxLayout *preload_layout = new QVBoxLayout(); + QWidget *preload_widget = new QWidget(); + + preload_layout->setSizeConstraint(QLayout::SetMaximumSize); + version_label = new QLabel(verbuf); + version_label->setAlignment(Qt::AlignHCenter); + version_label->setParent(central); + preload_layout->addWidget(version_label); + rs_label = new QLabel(QString::fromUtf8(R__("Give ruleset to use as starting point."))); + rs_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + preload_layout->addWidget(rs_label); + ruleset_select = new QLineEdit(central); ruleset_select->setText(GAME_DEFAULT_RULESETDIR); + connect(ruleset_select, SIGNAL(returnPressed()), + this, SLOT(rulesetdir_given())); + preload_layout->addWidget(ruleset_select); + ruleset_accept = new QPushButton(QString::fromUtf8(R__("Start editing"))); + connect(ruleset_accept, SIGNAL(pressed()), this, SLOT(rulesetdir_given())); + preload_layout->addWidget(ruleset_accept); + + preload_widget->setLayout(preload_layout); + main_layout->addWidget(preload_widget); } - connect(ruleset_select, SIGNAL(returnPressed()), - this, SLOT(launch_now())); - preload_layout->addWidget(ruleset_select); - ruleset_accept = new QPushButton(QString::fromUtf8(R__("Start editing"))); - connect(ruleset_accept, SIGNAL(pressed()), this, SLOT(launch_now())); - preload_layout->addWidget(ruleset_accept); - - preload_widget->setLayout(preload_layout); - main_layout->addWidget(preload_widget); stack = new QTabWidget(central); @@ -210,6 +209,11 @@ void ruledit_gui::setup(QWidget *central_in) req_edits = req_edit_list_new(); this->req_vec_fixers = req_vec_fix_list_new(); effect_edits = effect_edit_list_new(); + + if (reargs.ruleset != nullptr) { + sz_strlcpy(game.server.rulesetdir, reargs.ruleset); + launch_now(); + } } /**********************************************************************//** @@ -221,17 +225,27 @@ static void conversion_log_cb(const char *msg) } /**********************************************************************//** - User entered savedir + User entered rulesetdir to load. **************************************************************************/ -void ruledit_gui::launch_now() +void ruledit_gui::rulesetdir_given() { QByteArray rn_bytes; - convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format"))); - rn_bytes = ruleset_select->text().toUtf8(); sz_strlcpy(game.server.rulesetdir, rn_bytes.data()); + launch_now(); +} + +/**********************************************************************//** + Launch the main page. + + game.server.rulesetdir must be correctly set beforehand. +**************************************************************************/ +void ruledit_gui::launch_now() +{ + convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format"))); + if (load_rulesets(NULL, NULL, TRUE, conversion_log_cb, FALSE, TRUE, TRUE)) { display_msg(R__("Ruleset loaded")); diff --git a/tools/ruledit/ruledit_qt.h b/tools/ruledit/ruledit_qt.h index e65192b316..d56680bd0d 100644 --- a/tools/ruledit/ruledit_qt.h +++ b/tools/ruledit/ruledit_qt.h @@ -124,6 +124,8 @@ signals: void req_vec_may_have_changed(const requirement_vector *vec); private: + void launch_now(); + QLabel *msg_dspl; QTabWidget *stack; QLineEdit *ruleset_select; @@ -148,7 +150,7 @@ signals: struct effect_edit_list *effect_edits; private slots: - void launch_now(); + void rulesetdir_given(); void incoming_req_vec_change(const requirement_vector *vec); }; -- 2.39.1