From f21094ff08baf0c7761ac1bf9c333cf687469265 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 21 Mar 2024 20:08:50 +0200
Subject: [PATCH 17/17] Ruledit: Add initial version of helpeditor

- Only shows the current helptext, no editing possible yet
- Only available for buildings

See RM #326

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 meson.build                  |  2 ++
 tools/ruledit/Makefile.am    |  8 +++--
 tools/ruledit/edit_impr.cpp  | 17 ++++++++++
 tools/ruledit/edit_impr.h    |  1 +
 tools/ruledit/helpeditor.cpp | 62 ++++++++++++++++++++++++++++++++++++
 tools/ruledit/helpeditor.h   | 44 +++++++++++++++++++++++++
 6 files changed, 131 insertions(+), 3 deletions(-)
 create mode 100644 tools/ruledit/helpeditor.cpp
 create mode 100644 tools/ruledit/helpeditor.h

diff --git a/meson.build b/meson.build
index b6a07c3e7e..1e72666e28 100644
--- a/meson.build
+++ b/meson.build
@@ -3645,6 +3645,7 @@ mocced_ruledit = qt_mod.preprocess(
    'tools/ruledit/edit_terrain.h',
    'tools/ruledit/edit_utype.h',
    'tools/ruledit/effect_edit.h',
+   'tools/ruledit/helpeditor.h',
    'tools/ruledit/req_edit.h',
    'tools/ruledit/req_vec_fix.h',
    'tools/ruledit/requirers_dlg.h',
@@ -3670,6 +3671,7 @@ executable('freeciv-ruledit',
   'tools/ruledit/edit_terrain.cpp',
   'tools/ruledit/edit_utype.cpp',
   'tools/ruledit/effect_edit.cpp',
+  'tools/ruledit/helpeditor.cpp',
   'tools/ruledit/req_edit.cpp',
   'tools/ruledit/requirers_dlg.cpp',
   'tools/ruledit/req_vec_fix.cpp',
diff --git a/tools/ruledit/Makefile.am b/tools/ruledit/Makefile.am
index 6c5fa16e7d..1dc73bfaff 100644
--- a/tools/ruledit/Makefile.am
+++ b/tools/ruledit/Makefile.am
@@ -25,11 +25,12 @@ freeciv_ruledit_CXXFLAGS = $(ruledit_cxxflags)
 
 MOC_FILES = \
             meta_conversion_log.cpp \
-            meta_edit_extra.cpp \
+            meta_edit_extra.cpp	\
             meta_edit_impr.cpp \
-            meta_edit_terrain.cpp \
+            meta_edit_terrain.cpp	\
             meta_edit_utype.cpp \
-	    meta_effect_edit.cpp \
+	    meta_effect_edit.cpp	\
+	    meta_helpeditor.cpp	\
 	    meta_req_edit.cpp	\
 	    meta_req_vec_fix.cpp	\
             meta_requirers_dlg.cpp \
@@ -60,6 +61,7 @@ freeciv_ruledit_SOURCES =	\
 		edit_utype.h	\
 		effect_edit.cpp	\
 		effect_edit.h	\
+		helpeditor.cpp	\
 		tab_achievement.cpp	\
 		tab_achievement.h	\
 		tab_building.cpp \
diff --git a/tools/ruledit/edit_impr.cpp b/tools/ruledit/edit_impr.cpp
index 8d76b9a951..7a835f3dfb 100644
--- a/tools/ruledit/edit_impr.cpp
+++ b/tools/ruledit/edit_impr.cpp
@@ -20,6 +20,7 @@
 #include <QGridLayout>
 #include <QLineEdit>
 #include <QMenu>
+#include <QPushButton>
 #include <QSpinBox>
 #include <QToolButton>
 
@@ -27,6 +28,7 @@
 #include "improvement.h"
 
 // ruledit
+#include "helpeditor.h"
 #include "ruledit.h"
 #include "ruledit_qt.h"
 #include "tab_tech.h"
@@ -41,6 +43,7 @@ edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : QDialog()
   QHBoxLayout *main_layout = new QHBoxLayout(this);
   QGridLayout *impr_layout = new QGridLayout();
   QLabel *label;
+  QPushButton *button;
   QMenu *menu;
   int row;
 
@@ -126,6 +129,10 @@ edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : QDialog()
   impr_layout->addWidget(label, row, 0);
   impr_layout->addWidget(sound_tag_alt, row++, 1);
 
+  button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
+  connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
+  impr_layout->addWidget(button, row++, 1);
+
   for (int i = 0; i < IF_COUNT; i++) {
     enum impr_flag_id flag = (enum impr_flag_id)i;
     QCheckBox *check = new QCheckBox();
@@ -257,3 +264,13 @@ void edit_impr::sound_tag_alt_given()
 
   sz_strlcpy(impr->soundtag_alt, tag_bytes);
 }
+
+/**********************************************************************//**
+  User pressed helptext button
+**************************************************************************/
+void edit_impr::helptext()
+{
+  helpeditor *editor = new helpeditor(impr->helptext);
+
+  editor->show();
+}
diff --git a/tools/ruledit/edit_impr.h b/tools/ruledit/edit_impr.h
index a00dceae0f..4965c656be 100644
--- a/tools/ruledit/edit_impr.h
+++ b/tools/ruledit/edit_impr.h
@@ -60,6 +60,7 @@ class edit_impr : public QDialog
     void gfx_tag_alt_given();
     void sound_tag_given();
     void sound_tag_alt_given();
+    void helptext();
 };
 
 
diff --git a/tools/ruledit/helpeditor.cpp b/tools/ruledit/helpeditor.cpp
new file mode 100644
index 0000000000..f417537a81
--- /dev/null
+++ b/tools/ruledit/helpeditor.cpp
@@ -0,0 +1,62 @@
+/***********************************************************************
+ 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 <fc_config.h>
+#endif
+
+// Qt
+#include <QGridLayout>
+#include <QPushButton>
+
+// utility
+#include "fcintl.h"
+#include "string_vector.h"
+
+#include "helpeditor.h"
+
+/**********************************************************************//**
+  Setup helpeditor object
+**************************************************************************/
+helpeditor::helpeditor(struct strvec *helptext_in) : QDialog()
+{
+  QGridLayout *main_layout = new QGridLayout(this);
+  QPushButton *close_button;
+  int row = 0;
+
+  helptext = helptext_in;
+
+  area = new QTextEdit();
+  area->setParent(this);
+  area->setReadOnly(true);
+  main_layout->addWidget(area, row++, 0);
+
+  strvec_iterate(helptext, text) {
+    area->append(QString::fromUtf8(text));
+    area->append("\n\n");
+  } strvec_iterate_end;
+
+  close_button = new QPushButton(QString::fromUtf8(R__("Close")), this);
+  connect(close_button, SIGNAL(pressed()), this, SLOT(close_now()));
+  main_layout->addWidget(close_button, row++, 0);
+
+  setLayout(main_layout);
+}
+
+/**********************************************************************//**
+  User pushed close button
+**************************************************************************/
+void helpeditor::close_now()
+{
+  done(0);
+}
diff --git a/tools/ruledit/helpeditor.h b/tools/ruledit/helpeditor.h
new file mode 100644
index 0000000000..366323f147
--- /dev/null
+++ b/tools/ruledit/helpeditor.h
@@ -0,0 +1,44 @@
+/***********************************************************************
+ 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__HELPEDITOR_H
+#define FC__HELPEDITOR_H
+
+#ifdef HAVE_CONFIG_H
+#include <fc_config.h>
+#endif
+
+// Qt
+#include <QDialog>
+#include <QTextEdit>
+
+class ruledit_gui;
+
+class helpeditor : public QDialog
+{
+  Q_OBJECT
+
+  public:
+    explicit helpeditor(struct strvec *helptext_in);
+
+  private:
+    struct strvec *helptext;
+
+    QTextEdit *area;
+
+  private slots:
+    void close_now();
+};
+
+
+#endif // FC__HELPEDITOR_H
-- 
2.43.0

