From 41678e4ee119d2d98c12ac249ee833b04f55f1ba Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 23 Oct 2021 05:33:30 +0300 Subject: [PATCH 50/53] Ruledit: Add building genus editing support See osdn #43102 Signed-off-by: Marko Lindqvist --- common/improvement.h | 10 ++++++++++ tools/ruledit/edit_impr.cpp | 38 +++++++++++++++++++++++++++++++++++++ tools/ruledit/edit_impr.h | 8 ++++++-- tools/ruledit/univ_value.c | 6 +++--- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/common/improvement.h b/common/improvement.h index c9f1054945..49c6c48e2c 100644 --- a/common/improvement.h +++ b/common/improvement.h @@ -223,6 +223,16 @@ const struct impr_type *improvement_array_last(void); } \ } improvement_iterate_end; +#define genus_iterate(_p) \ + { \ + enum impr_genus_id _p; \ + for (_p = (enum impr_genus_id)0; _p < IG_COUNT; \ + _p = (enum impr_genus_id)((int)_p + 1)) { + +#define genus_iterate_end \ + } \ + } + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tools/ruledit/edit_impr.cpp b/tools/ruledit/edit_impr.cpp index e574f081b1..342f6965f3 100644 --- a/tools/ruledit/edit_impr.cpp +++ b/tools/ruledit/edit_impr.cpp @@ -17,7 +17,9 @@ // Qt #include +#include #include +#include // common #include "improvement.h" @@ -37,6 +39,7 @@ edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : QDialog() QVBoxLayout *main_layout = new QVBoxLayout(this); QGridLayout *impr_layout = new QGridLayout(); QLabel *label; + QMenu *menu; int row; ui = ui_in; @@ -65,6 +68,24 @@ edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : QDialog() impr_layout->addWidget(label, row, 0); impr_layout->addWidget(upkeep, row++, 2); + label = new QLabel(QString::fromUtf8(R__("Genus"))); + label->setParent(this); + genus_button = new QToolButton(); + genus_button->setParent(this); + genus_button->setToolButtonStyle(Qt::ToolButtonTextOnly); + genus_button->setPopupMode(QToolButton::MenuButtonPopup); + menu = new QMenu(); + connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(genus_menu(QAction *))); + + genus_iterate(genus) { + menu->addAction(impr_genus_id_name(genus)); + } genus_iterate_end; + + genus_button->setMenu(menu); + + impr_layout->addWidget(label, row, 0); + impr_layout->addWidget(genus_button, row++, 2); + refresh(); main_layout->addLayout(impr_layout); @@ -87,6 +108,7 @@ void edit_impr::refresh() { bcost->setValue(impr->build_cost); upkeep->setValue(impr->upkeep); + genus_button->setText(impr_genus_id_name(impr->genus)); } /**********************************************************************//** @@ -108,3 +130,19 @@ void edit_impr::set_upkeep_value(int value) refresh(); } + +/**********************************************************************//** + User selected genus +**************************************************************************/ +void edit_impr::genus_menu(QAction *action) +{ + QByteArray gn_bytes; + enum impr_genus_id genus; + + gn_bytes = action->text().toUtf8(); + genus = impr_genus_id_by_name(gn_bytes.data(), fc_strcasecmp); + + impr->genus = genus; + + refresh(); +} diff --git a/tools/ruledit/edit_impr.h b/tools/ruledit/edit_impr.h index ce56686e6b..74deb83805 100644 --- a/tools/ruledit/edit_impr.h +++ b/tools/ruledit/edit_impr.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold 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 @@ -20,7 +20,9 @@ // Qt #include -#include + +class QSpinBox; +class QToolButton; class ruledit_gui; @@ -37,6 +39,7 @@ class edit_impr : public QDialog struct impr_type *impr; QSpinBox *bcost; QSpinBox *upkeep; + QToolButton *genus_button; protected: void closeEvent(QCloseEvent *cevent); @@ -44,6 +47,7 @@ class edit_impr : public QDialog private slots: void set_bcost_value(int value); void set_upkeep_value(int value); + void genus_menu(QAction *action); }; diff --git a/tools/ruledit/univ_value.c b/tools/ruledit/univ_value.c index 4056851df7..4352791576 100644 --- a/tools/ruledit/univ_value.c +++ b/tools/ruledit/univ_value.c @@ -412,9 +412,9 @@ void universal_kind_values(struct universal *univ, } break; case VUT_IMPR_GENUS: - for (i = 0; i < IG_COUNT; i++) { - cb(impr_genus_id_name(i), univ->value.impr_genus == i, data); - } + genus_iterate(genus) { + cb(impr_genus_id_name(genus), univ->value.impr_genus == genus, data); + } genus_iterate_end; break; case VUT_ACTION: action_iterate(act) { -- 2.33.0