From 85c49f08ab927ae598139a9df62bda9199d51fb0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 1 Apr 2021 05:18:03 +0300 Subject: [PATCH 22/22] Ruledit: Add building details editing dialog Thre only value that one can edit in the initial version is build cost. See osdn #41891 Signed-off-by: Marko Lindqvist --- tools/ruledit/Makefile.am | 3 ++ tools/ruledit/edit_impr.cpp | 79 ++++++++++++++++++++++++++++++++ tools/ruledit/edit_impr.h | 45 ++++++++++++++++++ tools/ruledit/tab_building.cpp | 22 ++++++++- tools/ruledit/tab_building.h | 1 + translations/ruledit/POTFILES.in | 1 + 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 tools/ruledit/edit_impr.cpp create mode 100644 tools/ruledit/edit_impr.h diff --git a/tools/ruledit/Makefile.am b/tools/ruledit/Makefile.am index cdfdf702d4..8dab9b98ec 100644 --- a/tools/ruledit/Makefile.am +++ b/tools/ruledit/Makefile.am @@ -26,6 +26,7 @@ freeciv_ruledit_CXXFLAGS = $(ruledit_cxxflags) MOC_FILES = \ meta_conversion_log.cpp \ + meta_edit_impr.cpp \ meta_edit_utype.cpp \ meta_req_edit.cpp \ meta_req_vec_fix.cpp \ @@ -45,6 +46,8 @@ MOC_FILES = \ freeciv_ruledit_SOURCES = \ conversion_log.cpp \ conversion_log.h \ + edit_impr.cpp \ + edit_impr.h \ edit_utype.cpp \ edit_utype.h \ tab_building.cpp \ diff --git a/tools/ruledit/edit_impr.cpp b/tools/ruledit/edit_impr.cpp new file mode 100644 index 0000000000..a3e5074e54 --- /dev/null +++ b/tools/ruledit/edit_impr.cpp @@ -0,0 +1,79 @@ +/*********************************************************************** + 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 + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +// Qt +#include +#include + +// common +#include "improvement.h" + +// ruledit +#include "ruledit.h" +#include "ruledit_qt.h" +#include "tab_tech.h" + +#include "edit_impr.h" + +/************************************************************************** + Setup edit_impr object +**************************************************************************/ +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; + + ui = ui_in; + impr = impr_in; + + setWindowTitle(QString::fromUtf8(improvement_rule_name(impr))); + + label = new QLabel(QString::fromUtf8(R__("Build Cost"))); + label->setParent(this); + + bcost = new QSpinBox(this); + bcost->setRange(0, 10000); + connect(bcost, SIGNAL(valueChanged(int)), this, SLOT(set_bcost_value(int))); + + impr_layout->addWidget(label, 0, 0); + impr_layout->addWidget(bcost, 0, 2); + + refresh(); + + main_layout->addLayout(impr_layout); + + setLayout(main_layout); +} + +/************************************************************************** + Refresh the information. +**************************************************************************/ +void edit_impr::refresh() +{ + bcost->setValue(impr->build_cost); +} + +/************************************************************************** + Read build cost value from spinbox +**************************************************************************/ +void edit_impr::set_bcost_value(int value) +{ + impr->build_cost = value; + + refresh(); +} diff --git a/tools/ruledit/edit_impr.h b/tools/ruledit/edit_impr.h new file mode 100644 index 0000000000..184d19c7cd --- /dev/null +++ b/tools/ruledit/edit_impr.h @@ -0,0 +1,45 @@ +/********************************************************************** + 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 + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifndef FC__EDIT_IMPR_H +#define FC__EDIT_IMPR_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +// Qt +#include +#include + +class ruledit_gui; + +class edit_impr : public QDialog +{ + Q_OBJECT + + public: + explicit edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in); + void refresh(); + + private: + ruledit_gui *ui; + struct impr_type *impr; + QSpinBox *bcost; + + private slots: + void set_bcost_value(int value); +}; + + +#endif // FC__EDIT_IMPR_H diff --git a/tools/ruledit/tab_building.cpp b/tools/ruledit/tab_building.cpp index d73fba3362..678b7b34f2 100644 --- a/tools/ruledit/tab_building.cpp +++ b/tools/ruledit/tab_building.cpp @@ -33,6 +33,7 @@ #include "improvement.h" // ruledit +#include "edit_impr.h" #include "ruledit.h" #include "ruledit_qt.h" #include "validity.h" @@ -50,6 +51,7 @@ tab_building::tab_building(ruledit_gui *ui_in) : QWidget() QPushButton *add_button; QPushButton *delete_button; QPushButton *reqs_button; + QPushButton *edit_button; ui = ui_in; selected = 0; @@ -84,14 +86,18 @@ tab_building::tab_building(ruledit_gui *ui_in) : QWidget() connect(reqs_button, SIGNAL(pressed()), this, SLOT(edit_reqs())); bldg_layout->addWidget(reqs_button, 2, 2); + edit_button = new QPushButton(QString::fromUtf8(R__("Edit Values")), this); + connect(edit_button, SIGNAL(pressed()), this, SLOT(edit_now())); + bldg_layout->addWidget(edit_button, 3, 2); + add_button = new QPushButton(QString::fromUtf8(R__("Add Building")), this); connect(add_button, SIGNAL(pressed()), this, SLOT(add_now2())); - bldg_layout->addWidget(add_button, 3, 0); + bldg_layout->addWidget(add_button, 4, 0); show_experimental(add_button); delete_button = new QPushButton(QString::fromUtf8(R__("Remove this Building")), this); connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now())); - bldg_layout->addWidget(delete_button, 3, 2); + bldg_layout->addWidget(delete_button, 4, 2); show_experimental(delete_button); refresh(); @@ -284,3 +290,15 @@ void tab_building::edit_reqs() &selected->reqs); } } + +/************************************************************************** + User requested building edit dialog +**************************************************************************/ +void tab_building::edit_now() +{ + if (selected != nullptr) { + edit_impr *edit = new edit_impr(ui, selected); + + edit->show(); + } +} diff --git a/tools/ruledit/tab_building.h b/tools/ruledit/tab_building.h index 150f316d38..873a8f69d1 100644 --- a/tools/ruledit/tab_building.h +++ b/tools/ruledit/tab_building.h @@ -52,6 +52,7 @@ class tab_building : public QWidget void select_bldg(); void add_now2(); // "2" in name to workaround segfault on program start. Due to compiler bug? void delete_now(); + void edit_now(); void same_name_toggle(bool checked); void edit_reqs(); }; diff --git a/translations/ruledit/POTFILES.in b/translations/ruledit/POTFILES.in index 916d85ffdc..b0755e54fc 100644 --- a/translations/ruledit/POTFILES.in +++ b/translations/ruledit/POTFILES.in @@ -1,6 +1,7 @@ # List of source files containing translatable strings. # (Filenames are sorted alphabetically and relative to top-level directory.) tools/ruledit/conversion_log.cpp +tools/ruledit/edit_impr.cpp tools/ruledit/edit_utype.cpp tools/ruledit/req_vec_fix.cpp tools/ruledit/requirers_dlg.cpp -- 2.30.2