From 6b5916dfccd932180646d9a8f1eeed6034e81f4f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 18 Feb 2023 00:33:24 +0200 Subject: [PATCH 06/10] Ruledit: Skip ruleset selection if one given from commandline See osdn #46007 Signed-off-by: Marko Lindqvist --- tools/ruledit/ruledit_qt.cpp | 72 +++++++++++++++++++++--------------- tools/ruledit/ruledit_qt.h | 4 +- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index 54b68f7e2c..c32238bc3b 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -103,8 +103,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; @@ -129,29 +127,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); @@ -194,6 +193,11 @@ void ruledit_gui::setup(QWidget *central_in) req_edits = req_edit_list_new(); this->req_vec_fixers = req_vec_fix_list_new(); + + if (reargs.ruleset != nullptr) { + sz_strlcpy(game.server.rulesetdir, reargs.ruleset); + launch_now(); + } } /************************************************************************** @@ -205,16 +209,26 @@ 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; + 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. - rn_bytes = ruleset_select->text().toUtf8(); - sz_strlcpy(game.server.rulesetdir, rn_bytes.data()); + 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, TRUE, conversion_log_cb, FALSE, TRUE)) { display_msg(R__("Ruleset loaded")); diff --git a/tools/ruledit/ruledit_qt.h b/tools/ruledit/ruledit_qt.h index 260387d3a5..7d7f6725fb 100644 --- a/tools/ruledit/ruledit_qt.h +++ b/tools/ruledit/ruledit_qt.h @@ -107,6 +107,8 @@ signals: void req_vec_may_have_changed(const requirement_vector *vec); private: + void launch_now(); + QLabel *msg_dspl; QTabWidget *stack; QLineEdit *ruleset_select; @@ -128,7 +130,7 @@ signals: struct req_vec_fix_list *req_vec_fixers; private slots: - void launch_now(); + void rulesetdir_given(); void incoming_req_vec_change(const requirement_vector *vec); }; -- 2.39.1