diff options
author | madmaxoft <github@xoft.cz> | 2014-09-22 18:26:35 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-09-22 21:52:37 +0200 |
commit | 10c5d5056691f0a03798c7e9439138126da30b8a (patch) | |
tree | c07994699a9d5bc1891fb47cb70620d47e9114c4 /Tools/QtBiomeVisualiser | |
parent | Merge pull request #1398 from mc-server/1.8-Protocol (diff) | |
download | cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar.gz cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar.bz2 cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar.lz cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar.xz cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.tar.zst cuberite-10c5d5056691f0a03798c7e9439138126da30b8a.zip |
Diffstat (limited to 'Tools/QtBiomeVisualiser')
-rw-r--r-- | Tools/QtBiomeVisualiser/GeneratorSetup.cpp (renamed from Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp) | 22 | ||||
-rw-r--r-- | Tools/QtBiomeVisualiser/GeneratorSetup.h (renamed from Tools/QtBiomeVisualiser/GeneratorSetupDlg.h) | 16 | ||||
-rw-r--r-- | Tools/QtBiomeVisualiser/MainWindow.cpp | 69 | ||||
-rw-r--r-- | Tools/QtBiomeVisualiser/MainWindow.h | 24 | ||||
-rw-r--r-- | Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro | 4 |
5 files changed, 96 insertions, 39 deletions
diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp index e6037fa9b..d512d2b90 100644 --- a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.cpp @@ -1,5 +1,5 @@ #include "Globals.h" -#include "GeneratorSetupDlg.h" +#include "GeneratorSetup.h" #include <QLabel> #include <QLineEdit> #include "Generating/BioGen.h" @@ -23,13 +23,13 @@ static const QString s_GeneratorNames[] = -GeneratorSetupDlg::GeneratorSetupDlg(const AString & a_IniFileName, QWidget * a_Parent) : +GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent) : super(a_Parent), m_IniFile(new cIniFile()) { // The generator name is in a separate form layout at the top, always present: m_cbGenerator = new QComboBox(); - m_cbGenerator->setMinimumWidth(300); + m_cbGenerator->setMinimumWidth(120); for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++) { m_cbGenerator->addItem(s_GeneratorNames[i]); @@ -44,6 +44,7 @@ GeneratorSetupDlg::GeneratorSetupDlg(const AString & a_IniFileName, QWidget * a_ m_MainLayout = new QVBoxLayout(); m_MainLayout->addLayout(nameLayout); m_MainLayout->addLayout(m_FormLayout); + m_MainLayout->addStretch(); setLayout(m_MainLayout); // Load the INI file, if specified, otherwise set defaults: @@ -68,7 +69,7 @@ GeneratorSetupDlg::GeneratorSetupDlg(const AString & a_IniFileName, QWidget * a_ -void GeneratorSetupDlg::generatorChanged(const QString & a_NewName) +void GeneratorSetup::generatorChanged(const QString & a_NewName) { // Clear the current contents of the form layout by assigning it to a stack temporary: { @@ -78,7 +79,7 @@ void GeneratorSetupDlg::generatorChanged(const QString & a_NewName) // Re-create the layout: m_FormLayout = new QFormLayout(); - m_MainLayout->addLayout(m_FormLayout); + m_MainLayout->insertLayout(1, m_FormLayout); // Recreate the INI file: m_IniFile->Clear(); @@ -97,7 +98,7 @@ void GeneratorSetupDlg::generatorChanged(const QString & a_NewName) -void GeneratorSetupDlg::updateFromIni() +void GeneratorSetup::updateFromIni() { int keyID = m_IniFile->FindKey("Generator"); if (keyID <= -1) @@ -105,6 +106,8 @@ void GeneratorSetupDlg::updateFromIni() return; } int numItems = m_IniFile->GetNumValues(keyID); + AString generatorName = m_IniFile->GetValue("Generator", "BiomeGen"); + size_t generatorNameLen = generatorName.length(); for (int i = 0; i < numItems; i++) { AString itemName = m_IniFile->GetValueName(keyID, i); @@ -114,6 +117,13 @@ void GeneratorSetupDlg::updateFromIni() // These special cases are not to be added continue; } + + // Remove the generator name prefix from the item name, for clarity purposes: + if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0) + { + itemName.erase(0, generatorNameLen); + } + QLineEdit * edit = new QLineEdit(); edit->setText(QString::fromStdString(itemValue)); m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit); diff --git a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h b/Tools/QtBiomeVisualiser/GeneratorSetup.h index d7070e331..0594e1998 100644 --- a/Tools/QtBiomeVisualiser/GeneratorSetupDlg.h +++ b/Tools/QtBiomeVisualiser/GeneratorSetup.h @@ -11,21 +11,25 @@ class cIniFile; +typedef std::shared_ptr<cIniFile> cIniFilePtr; -class GeneratorSetupDlg : - public QDialog +class GeneratorSetup : + public QWidget { - typedef QDialog super; + typedef QWidget super; Q_OBJECT public: - /** Creates the dialog and loads the contents of the INI file, if not empty. */ - explicit GeneratorSetupDlg(const std::string & a_IniFileName, QWidget * parent = nullptr); + /** Creates the widget and loads the contents of the INI file, if not empty. */ + explicit GeneratorSetup(const std::string & a_IniFileName, QWidget * parent = nullptr); + + /** Returns the cIniFile instance that is being edited by this widget. */ + cIniFilePtr getIniFile() { return m_IniFile; } signals: @@ -39,7 +43,7 @@ protected: QVBoxLayout * m_MainLayout; QFormLayout * m_FormLayout; - std::unique_ptr<cIniFile> m_IniFile; + cIniFilePtr m_IniFile; int m_Seed; diff --git a/Tools/QtBiomeVisualiser/MainWindow.cpp b/Tools/QtBiomeVisualiser/MainWindow.cpp index d2c1ae2c1..f9915901d 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.cpp +++ b/Tools/QtBiomeVisualiser/MainWindow.cpp @@ -12,19 +12,27 @@ #include "Generating/BioGen.h" #include "StringCompression.h" #include "WorldStorage/FastNBT.h" -#include "GeneratorSetupDlg.h" +#include "GeneratorSetup.h" MainWindow::MainWindow(QWidget * parent) : - QMainWindow(parent) + QMainWindow(parent), + m_GeneratorSetup(nullptr), + m_LineSeparator(nullptr) { initMinecraftPath(); - m_BiomeView = new BiomeView(this); - setCentralWidget(m_BiomeView); + m_BiomeView = new BiomeView(); + m_MainLayout = new QHBoxLayout(); + m_MainLayout->addWidget(m_BiomeView); + m_MainLayout->setMenuBar(menuBar()); + m_MainLayout->setMargin(0); + QWidget * central = new QWidget(); + central->setLayout(m_MainLayout); + setCentralWidget(central); createActions(); createMenus(); @@ -48,9 +56,7 @@ void MainWindow::newGenerator() // TODO // (Re-)open the generator setup dialog: - m_GeneratorSetupDlg.reset(new GeneratorSetupDlg("")); - m_GeneratorSetupDlg->show(); - m_GeneratorSetupDlg->raise(); + openGeneratorSetup(""); // TODO } @@ -69,9 +75,7 @@ void MainWindow::openGenerator() } // (Re-)open the generator setup dialog: - m_GeneratorSetupDlg.reset(new GeneratorSetupDlg(worldIni.toStdString())); - m_GeneratorSetupDlg->show(); - m_GeneratorSetupDlg->raise(); + openGeneratorSetup(worldIni.toStdString()); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(worldIni))); @@ -92,11 +96,7 @@ void MainWindow::openWorld() } // Remove the generator setup dialog, if open: - if (m_GeneratorSetupDlg.get() != nullptr) - { - m_GeneratorSetupDlg->hide(); - m_GeneratorSetupDlg.reset(nullptr); - } + closeGeneratorSetup(); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(regionFolder))); @@ -117,11 +117,7 @@ void MainWindow::openVanillaWorld() } // Remove the generator setup dialog, if open: - if (m_GeneratorSetupDlg.get() != nullptr) - { - m_GeneratorSetupDlg->hide(); - m_GeneratorSetupDlg.reset(nullptr); - } + closeGeneratorSetup(); // Set the chunk source: m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(action->data().toString()))); @@ -276,3 +272,36 @@ QString MainWindow::getWorldName(const AString & a_Path) + +void MainWindow::openGeneratorSetup(const AString & a_IniFileName) +{ + // Close any previous editor: + closeGeneratorSetup(); + + // Open up a new editor: + m_GeneratorSetup = new GeneratorSetup(a_IniFileName); + m_LineSeparator = new QWidget(); + m_LineSeparator->setFixedWidth(2); + m_LineSeparator->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;")); + m_MainLayout->addWidget(m_LineSeparator); + m_MainLayout->addWidget(m_GeneratorSetup); +} + + + + + +void MainWindow::closeGeneratorSetup() +{ + delete m_MainLayout->takeAt(2); + delete m_MainLayout->takeAt(1); + delete m_GeneratorSetup; + delete m_LineSeparator; + m_GeneratorSetup = nullptr; + m_LineSeparator = nullptr; +} + + + + diff --git a/Tools/QtBiomeVisualiser/MainWindow.h b/Tools/QtBiomeVisualiser/MainWindow.h index 840e01b0f..6490a937f 100644 --- a/Tools/QtBiomeVisualiser/MainWindow.h +++ b/Tools/QtBiomeVisualiser/MainWindow.h @@ -3,6 +3,7 @@ #include <memory> #include <QList> #include <QMainWindow> +#include <QHBoxLayout> #include "BiomeView.h" @@ -10,7 +11,7 @@ // fwd: -class GeneratorSetupDlg; +class GeneratorSetup; @@ -21,8 +22,6 @@ class MainWindow : { Q_OBJECT - BiomeView * m_BiomeView; - public: MainWindow(QWidget * parent = nullptr); ~MainWindow(); @@ -54,8 +53,17 @@ protected: /** Path to the vanilla folder. */ QString m_MinecraftPath; - /** The dialog for setting up the generator. */ - std::unique_ptr<GeneratorSetupDlg> m_GeneratorSetupDlg; + /** The pane for setting up the generator, available when visualising a generator. */ + GeneratorSetup * m_GeneratorSetup; + + /** The main biome display widget. */ + BiomeView * m_BiomeView; + + /** The layout for the window. */ + QHBoxLayout * m_MainLayout; + + /** The separator line between biome view and generator setup. */ + QWidget * m_LineSeparator; /** Initializes the m_MinecraftPath based on the proper MC path */ @@ -73,6 +81,12 @@ protected: /** Returns the name of the vanilla world in the specified path. Reads the level.dat file for the name. Returns an empty string on failure. */ QString getWorldName(const AString & a_Path); + + /** Opens the generator setup pane, if not already open, and loads the specified INI file to it. */ + void openGeneratorSetup(const AString & a_IniFileName); + + /** Closes and destroys the generator setup pane, if there is one. */ + void closeGeneratorSetup(); }; diff --git a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro index 7171562bb..2ed1be719 100644 --- a/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro +++ b/Tools/QtBiomeVisualiser/QtBiomeVisualiser.pro @@ -47,7 +47,7 @@ SOURCES += main.cpp\ ../../lib/zlib/trees.c \ ../../lib/zlib/uncompr.c \ ../../lib/zlib/zutil.c \ - GeneratorSetupDlg.cpp + GeneratorSetup.cpp HEADERS += MainWindow.h \ Globals.h \ @@ -80,7 +80,7 @@ HEADERS += MainWindow.h \ ../../lib/zlib/zconf.h \ ../../lib/zlib/zlib.h \ ../../lib/zlib/zutil.h \ - GeneratorSetupDlg.h + GeneratorSetup.h INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/../../src \ |