QtBiomeVisualiser: Added the base for INI editting.
This commit is contained in:
parent
cb70925077
commit
dda66ea6ef
125
Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp
Normal file
125
Tools/QtBiomeVisualiser/GeneratorSetupDlg.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include "Globals.h"
|
||||
#include "GeneratorSetupDlg.h"
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include "Generating/BioGen.h"
|
||||
#include "inifile/iniFile.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static const QString s_GeneratorNames[] =
|
||||
{
|
||||
QString("Checkerboard"),
|
||||
QString("Constant"),
|
||||
QString("DistortedVoronoi"),
|
||||
QString("MultiStepMap"),
|
||||
QString("TwoLevel"),
|
||||
QString("Voronoi"),
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GeneratorSetupDlg::GeneratorSetupDlg(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);
|
||||
for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++)
|
||||
{
|
||||
m_cbGenerator->addItem(s_GeneratorNames[i]);
|
||||
}
|
||||
QFormLayout * nameLayout = new QFormLayout();
|
||||
nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator);
|
||||
|
||||
// The rest of the controls are in a dynamically created form layout:
|
||||
m_FormLayout = new QFormLayout();
|
||||
|
||||
// The main layout joins these two vertically:
|
||||
m_MainLayout = new QVBoxLayout();
|
||||
m_MainLayout->addLayout(nameLayout);
|
||||
m_MainLayout->addLayout(m_FormLayout);
|
||||
setLayout(m_MainLayout);
|
||||
|
||||
// Load the INI file, if specified, otherwise set defaults:
|
||||
if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName))
|
||||
{
|
||||
m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen")));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_IniFile->SetValue("Generator", "Generator", "Composable");
|
||||
m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString());
|
||||
bool dummy;
|
||||
delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy);
|
||||
}
|
||||
updateFromIni();
|
||||
|
||||
// Connect the combo change even only after the data has been loaded:
|
||||
connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void GeneratorSetupDlg::generatorChanged(const QString & a_NewName)
|
||||
{
|
||||
// Clear the current contents of the form layout by assigning it to a stack temporary:
|
||||
{
|
||||
m_MainLayout->takeAt(1);
|
||||
QWidget().setLayout(m_FormLayout);
|
||||
}
|
||||
|
||||
// Re-create the layout:
|
||||
m_FormLayout = new QFormLayout();
|
||||
m_MainLayout->addLayout(m_FormLayout);
|
||||
|
||||
// Recreate the INI file:
|
||||
m_IniFile->Clear();
|
||||
m_IniFile->SetValue("Generator", "Generator", "Composable");
|
||||
m_IniFile->SetValue("Generator", "BiomeGen", a_NewName.toStdString());
|
||||
|
||||
// Create a dummy biome gen from the INI file, this will create the defaults in the INI file:
|
||||
bool dummy;
|
||||
delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy);
|
||||
|
||||
// Read all values from the INI file and put them into the form layout:
|
||||
updateFromIni();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void GeneratorSetupDlg::updateFromIni()
|
||||
{
|
||||
int keyID = m_IniFile->FindKey("Generator");
|
||||
if (keyID <= -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int numItems = m_IniFile->GetNumValues(keyID);
|
||||
for (int i = 0; i < numItems; i++)
|
||||
{
|
||||
AString itemName = m_IniFile->GetValueName(keyID, i);
|
||||
AString itemValue = m_IniFile->GetValue(keyID, i);
|
||||
if ((itemName == "Generator") || (itemName == "BiomeGen"))
|
||||
{
|
||||
// These special cases are not to be added
|
||||
continue;
|
||||
}
|
||||
QLineEdit * edit = new QLineEdit();
|
||||
edit->setText(QString::fromStdString(itemValue));
|
||||
m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit);
|
||||
} // for i - INI values[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
53
Tools/QtBiomeVisualiser/GeneratorSetupDlg.h
Normal file
53
Tools/QtBiomeVisualiser/GeneratorSetupDlg.h
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFormLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cIniFile;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class GeneratorSetupDlg :
|
||||
public QDialog
|
||||
{
|
||||
typedef QDialog 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);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
/** Called when the user selects a different generator from the top combobox.
|
||||
Re-creates m_IniFile and updates the form layout. */
|
||||
void generatorChanged(const QString & a_NewName);
|
||||
|
||||
protected:
|
||||
QComboBox * m_cbGenerator;
|
||||
QVBoxLayout * m_MainLayout;
|
||||
QFormLayout * m_FormLayout;
|
||||
|
||||
std::unique_ptr<cIniFile> m_IniFile;
|
||||
|
||||
int m_Seed;
|
||||
|
||||
|
||||
/** Updates the form layout with the values from m_IniFile. */
|
||||
void updateFromIni();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Generating/BioGen.h"
|
||||
#include "StringCompression.h"
|
||||
#include "WorldStorage/FastNBT.h"
|
||||
#include "GeneratorSetupDlg.h"
|
||||
|
||||
|
||||
|
||||
@ -42,13 +43,37 @@ MainWindow::~MainWindow()
|
||||
|
||||
|
||||
|
||||
void MainWindow::generate()
|
||||
void MainWindow::newGenerator()
|
||||
{
|
||||
// TODO
|
||||
|
||||
// (Re-)open the generator setup dialog:
|
||||
m_GeneratorSetupDlg.reset(new GeneratorSetupDlg(""));
|
||||
m_GeneratorSetupDlg->show();
|
||||
m_GeneratorSetupDlg->raise();
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void MainWindow::openGenerator()
|
||||
{
|
||||
// Let the user specify the world.ini file:
|
||||
QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)"));
|
||||
if (worldIni.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// (Re-)open the generator setup dialog:
|
||||
m_GeneratorSetupDlg.reset(new GeneratorSetupDlg(worldIni.toStdString()));
|
||||
m_GeneratorSetupDlg->show();
|
||||
m_GeneratorSetupDlg->raise();
|
||||
|
||||
// Set the chunk source:
|
||||
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(worldIni)));
|
||||
m_BiomeView->redraw();
|
||||
}
|
||||
@ -57,13 +82,23 @@ void MainWindow::generate()
|
||||
|
||||
|
||||
|
||||
void MainWindow::open()
|
||||
void MainWindow::openWorld()
|
||||
{
|
||||
// Let the user specify the world:
|
||||
QString regionFolder = QFileDialog::getExistingDirectory(this, tr("Select the region folder"), QString());
|
||||
if (regionFolder.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the generator setup dialog, if open:
|
||||
if (m_GeneratorSetupDlg.get() != nullptr)
|
||||
{
|
||||
m_GeneratorSetupDlg->hide();
|
||||
m_GeneratorSetupDlg.reset(nullptr);
|
||||
}
|
||||
|
||||
// Set the chunk source:
|
||||
m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(regionFolder)));
|
||||
m_BiomeView->redraw();
|
||||
}
|
||||
@ -74,11 +109,21 @@ void MainWindow::open()
|
||||
|
||||
void MainWindow::openVanillaWorld()
|
||||
{
|
||||
// The world is stored in the sender action's data, retrieve it:
|
||||
QAction * action = qobject_cast<QAction *>(sender());
|
||||
if (action == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the generator setup dialog, if open:
|
||||
if (m_GeneratorSetupDlg.get() != nullptr)
|
||||
{
|
||||
m_GeneratorSetupDlg->hide();
|
||||
m_GeneratorSetupDlg.reset(nullptr);
|
||||
}
|
||||
|
||||
// Set the chunk source:
|
||||
m_BiomeView->setChunkSource(std::shared_ptr<AnvilSource>(new AnvilSource(action->data().toString())));
|
||||
m_BiomeView->redraw();
|
||||
}
|
||||
@ -107,19 +152,24 @@ void MainWindow::createActions()
|
||||
{
|
||||
createWorldActions();
|
||||
|
||||
m_actGen = new QAction(tr("&Generate..."), this);
|
||||
m_actGen->setShortcut(tr("Ctrl+N"));
|
||||
m_actGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
|
||||
connect(m_actGen, SIGNAL(triggered()), this, SLOT(generate()));
|
||||
m_actNewGen = new QAction(tr("&New generator"), this);
|
||||
m_actNewGen->setShortcut(tr("Ctrl+N"));
|
||||
m_actNewGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
|
||||
connect(m_actNewGen, SIGNAL(triggered()), this, SLOT(newGenerator()));
|
||||
|
||||
m_actOpen = new QAction(tr("&Open world..."), this);
|
||||
m_actOpen->setShortcut(tr("Ctrl+O"));
|
||||
m_actOpen->setStatusTip(tr("Open an existing world and display its biomes"));
|
||||
connect(m_actOpen, SIGNAL(triggered()), this, SLOT(open()));
|
||||
m_actOpenGen = new QAction(tr("&Open generator..."), this);
|
||||
m_actOpenGen->setShortcut(tr("Ctrl+G"));
|
||||
m_actOpenGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
|
||||
connect(m_actOpenGen, SIGNAL(triggered()), this, SLOT(openGenerator()));
|
||||
|
||||
m_actOpenWorld = new QAction(tr("&Open world..."), this);
|
||||
m_actOpenWorld->setShortcut(tr("Ctrl+O"));
|
||||
m_actOpenWorld->setStatusTip(tr("Open an existing world and display its biomes"));
|
||||
connect(m_actOpenWorld, SIGNAL(triggered()), this, SLOT(openWorld()));
|
||||
|
||||
m_actReload = new QAction(tr("&Reload"), this);
|
||||
m_actReload->setShortcut(tr("F5"));
|
||||
m_actReload->setStatusTip(tr("Open an existing world and display its biomes"));
|
||||
m_actReload->setStatusTip(tr("Clear the view cache and force a reload of all the data"));
|
||||
connect(m_actReload, SIGNAL(triggered()), m_BiomeView, SLOT(reload()));
|
||||
|
||||
m_actExit = new QAction(tr("E&xit"), this);
|
||||
@ -174,7 +224,8 @@ void MainWindow::createWorldActions()
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
QMenu * file = menuBar()->addMenu(tr("&Map"));
|
||||
file->addAction(m_actGen);
|
||||
file->addAction(m_actNewGen);
|
||||
file->addAction(m_actOpenGen);
|
||||
file->addSeparator();
|
||||
QMenu * worlds = file->addMenu(tr("Open existing"));
|
||||
worlds->addActions(m_WorldActions);
|
||||
@ -182,7 +233,7 @@ void MainWindow::createMenus()
|
||||
{
|
||||
worlds->setEnabled(false);
|
||||
}
|
||||
file->addAction(m_actOpen);
|
||||
file->addAction(m_actOpenWorld);
|
||||
file->addSeparator();
|
||||
file->addAction(m_actReload);
|
||||
file->addSeparator();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QList>
|
||||
#include <QMainWindow>
|
||||
#include "BiomeView.h"
|
||||
@ -8,6 +9,13 @@
|
||||
|
||||
|
||||
|
||||
// fwd:
|
||||
class GeneratorSetupDlg;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MainWindow :
|
||||
public QMainWindow
|
||||
{
|
||||
@ -16,23 +24,27 @@ class MainWindow :
|
||||
BiomeView * m_BiomeView;
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
MainWindow(QWidget * parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
/** Creates a generator definition from scratch, lets user modify generator params in realtime. */
|
||||
void newGenerator();
|
||||
|
||||
/** Opens a generator definition and generates the biomes based on that. */
|
||||
void generate();
|
||||
void openGenerator();
|
||||
|
||||
/** Opens an existing world and displays the loaded biomes. */
|
||||
void open();
|
||||
void openWorld();
|
||||
|
||||
/** Opens a vanilla world that is specified by the calling action. */
|
||||
void openVanillaWorld();
|
||||
|
||||
protected:
|
||||
// Actions:
|
||||
QAction * m_actGen;
|
||||
QAction * m_actOpen;
|
||||
QAction * m_actNewGen;
|
||||
QAction * m_actOpenGen;
|
||||
QAction * m_actOpenWorld;
|
||||
QAction * m_actReload;
|
||||
QAction * m_actExit;
|
||||
|
||||
@ -42,6 +54,9 @@ protected:
|
||||
/** Path to the vanilla folder. */
|
||||
QString m_MinecraftPath;
|
||||
|
||||
/** The dialog for setting up the generator. */
|
||||
std::unique_ptr<GeneratorSetupDlg> m_GeneratorSetupDlg;
|
||||
|
||||
|
||||
/** Initializes the m_MinecraftPath based on the proper MC path */
|
||||
void initMinecraftPath();
|
||||
|
@ -46,7 +46,8 @@ SOURCES += main.cpp\
|
||||
../../lib/zlib/inftrees.c \
|
||||
../../lib/zlib/trees.c \
|
||||
../../lib/zlib/uncompr.c \
|
||||
../../lib/zlib/zutil.c
|
||||
../../lib/zlib/zutil.c \
|
||||
GeneratorSetupDlg.cpp
|
||||
|
||||
HEADERS += MainWindow.h \
|
||||
Globals.h \
|
||||
@ -78,7 +79,8 @@ HEADERS += MainWindow.h \
|
||||
../../lib/zlib/trees.h \
|
||||
../../lib/zlib/zconf.h \
|
||||
../../lib/zlib/zlib.h \
|
||||
../../lib/zlib/zutil.h
|
||||
../../lib/zlib/zutil.h \
|
||||
GeneratorSetupDlg.h
|
||||
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_ \
|
||||
$$_PRO_FILE_PWD_/../../src \
|
||||
|
Loading…
Reference in New Issue
Block a user