QtBiomeVisualiser: Implemented live-update for the generator setup.
This commit is contained in:
parent
583532e1b9
commit
83588fb0aa
@ -171,7 +171,7 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu
|
|||||||
|
|
||||||
void BioGenSource::reload()
|
void BioGenSource::reload()
|
||||||
{
|
{
|
||||||
int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0);
|
int seed = m_IniFile->GetValueSetI("Generator", "Seed", 0);
|
||||||
bool unused = false;
|
bool unused = false;
|
||||||
QMutexLocker lock(&m_Mtx);
|
QMutexLocker lock(&m_Mtx);
|
||||||
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused));
|
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused));
|
||||||
|
@ -27,22 +27,27 @@ GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent
|
|||||||
super(a_Parent),
|
super(a_Parent),
|
||||||
m_IniFile(new cIniFile())
|
m_IniFile(new cIniFile())
|
||||||
{
|
{
|
||||||
// The generator name is in a separate form layout at the top, always present:
|
// The seed and generator name is in a separate form layout at the top, always present:
|
||||||
|
m_eSeed = new QLineEdit();
|
||||||
|
m_eSeed->setValidator(new QIntValidator());
|
||||||
|
m_eSeed->setText("0");
|
||||||
|
m_eSeed->setProperty("INI.ItemName", QVariant("Seed"));
|
||||||
m_cbGenerator = new QComboBox();
|
m_cbGenerator = new QComboBox();
|
||||||
m_cbGenerator->setMinimumWidth(120);
|
m_cbGenerator->setMinimumWidth(120);
|
||||||
for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++)
|
for (size_t i = 0; i < ARRAYCOUNT(s_GeneratorNames); i++)
|
||||||
{
|
{
|
||||||
m_cbGenerator->addItem(s_GeneratorNames[i]);
|
m_cbGenerator->addItem(s_GeneratorNames[i]);
|
||||||
}
|
}
|
||||||
QFormLayout * nameLayout = new QFormLayout();
|
QFormLayout * baseLayout = new QFormLayout();
|
||||||
nameLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator);
|
baseLayout->addRow(new QLabel(tr("Seed")), m_eSeed);
|
||||||
|
baseLayout->addRow(new QLabel(tr("Generator")), m_cbGenerator);
|
||||||
|
|
||||||
// The rest of the controls are in a dynamically created form layout:
|
// The rest of the controls are in a dynamically created form layout:
|
||||||
m_FormLayout = new QFormLayout();
|
m_FormLayout = new QFormLayout();
|
||||||
|
|
||||||
// The main layout joins these two vertically:
|
// The main layout joins these two vertically:
|
||||||
m_MainLayout = new QVBoxLayout();
|
m_MainLayout = new QVBoxLayout();
|
||||||
m_MainLayout->addLayout(nameLayout);
|
m_MainLayout->addLayout(baseLayout);
|
||||||
m_MainLayout->addLayout(m_FormLayout);
|
m_MainLayout->addLayout(m_FormLayout);
|
||||||
m_MainLayout->addStretch();
|
m_MainLayout->addStretch();
|
||||||
setLayout(m_MainLayout);
|
setLayout(m_MainLayout);
|
||||||
@ -51,18 +56,20 @@ GeneratorSetup::GeneratorSetup(const AString & a_IniFileName, QWidget * a_Parent
|
|||||||
if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName))
|
if (!a_IniFileName.empty() && m_IniFile->ReadFile(a_IniFileName))
|
||||||
{
|
{
|
||||||
m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen")));
|
m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen")));
|
||||||
|
m_eSeed->setText(QString::number(m_IniFile->GetValueI("Generator", "Seed")));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_IniFile->SetValue("Generator", "Generator", "Composable");
|
m_IniFile->SetValue("Generator", "Generator", "Composable");
|
||||||
m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString());
|
m_IniFile->SetValue("Generator", "BiomeGen", m_cbGenerator->currentText().toStdString());
|
||||||
bool dummy;
|
bool dummy;
|
||||||
delete cBiomeGen::CreateBiomeGen(*m_IniFile, m_Seed, dummy);
|
delete cBiomeGen::CreateBiomeGen(*m_IniFile, 0, dummy);
|
||||||
}
|
}
|
||||||
updateFromIni();
|
updateFromIni();
|
||||||
|
|
||||||
// Connect the combo change even only after the data has been loaded:
|
// Connect the change events only after the data has been loaded:
|
||||||
connect(m_cbGenerator, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(generatorChanged(QString)));
|
connect(m_cbGenerator, SIGNAL(currentIndexChanged(QString)), this, SLOT(generatorChanged(QString)));
|
||||||
|
connect(m_eSeed, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -92,6 +99,20 @@ void GeneratorSetup::generatorChanged(const QString & a_NewName)
|
|||||||
|
|
||||||
// Read all values from the INI file and put them into the form layout:
|
// Read all values from the INI file and put them into the form layout:
|
||||||
updateFromIni();
|
updateFromIni();
|
||||||
|
|
||||||
|
// Notify of the changes:
|
||||||
|
emit generatorUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void GeneratorSetup::editChanged(const QString & a_NewValue)
|
||||||
|
{
|
||||||
|
QString itemName = sender()->property("INI.ItemName").toString();
|
||||||
|
m_IniFile->SetValue("Generator", itemName.toStdString(), a_NewValue.toStdString());
|
||||||
|
emit generatorUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,12 +132,16 @@ void GeneratorSetup::updateFromIni()
|
|||||||
for (int i = 0; i < numItems; i++)
|
for (int i = 0; i < numItems; i++)
|
||||||
{
|
{
|
||||||
AString itemName = m_IniFile->GetValueName(keyID, i);
|
AString itemName = m_IniFile->GetValueName(keyID, i);
|
||||||
AString itemValue = m_IniFile->GetValue(keyID, i);
|
|
||||||
if ((itemName == "Generator") || (itemName == "BiomeGen"))
|
if ((itemName == "Generator") || (itemName == "BiomeGen"))
|
||||||
{
|
{
|
||||||
// These special cases are not to be added
|
// These special cases are not to be added
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
AString itemValue = m_IniFile->GetValue(keyID, i);
|
||||||
|
|
||||||
|
QLineEdit * edit = new QLineEdit();
|
||||||
|
edit->setText(QString::fromStdString(itemValue));
|
||||||
|
edit->setProperty("INI.ItemName", QVariant(QString::fromStdString(itemName)));
|
||||||
|
|
||||||
// Remove the generator name prefix from the item name, for clarity purposes:
|
// Remove the generator name prefix from the item name, for clarity purposes:
|
||||||
if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0)
|
if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0)
|
||||||
@ -124,8 +149,7 @@ void GeneratorSetup::updateFromIni()
|
|||||||
itemName.erase(0, generatorNameLen);
|
itemName.erase(0, generatorNameLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit * edit = new QLineEdit();
|
connect(edit, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString)));
|
||||||
edit->setText(QString::fromStdString(itemValue));
|
|
||||||
m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit);
|
m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit);
|
||||||
} // for i - INI values[]
|
} // for i - INI values[]
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,21 @@ public:
|
|||||||
cIniFilePtr getIniFile() { return m_IniFile; }
|
cIniFilePtr getIniFile() { return m_IniFile; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
/** Emitted when the generator parameters have changed. */
|
||||||
|
void generatorUpdated();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/** Called when the user selects a different generator from the top combobox.
|
/** Called when the user selects a different generator from the top combobox.
|
||||||
Re-creates m_IniFile and updates the form layout. */
|
Re-creates m_IniFile and updates the form layout. */
|
||||||
void generatorChanged(const QString & a_NewName);
|
void generatorChanged(const QString & a_NewName);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
/** Called when any of the edit widgets are changed. */
|
||||||
|
void editChanged(const QString & a_NewValue);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QComboBox * m_cbGenerator;
|
QComboBox * m_cbGenerator;
|
||||||
|
QLineEdit * m_eSeed;
|
||||||
QVBoxLayout * m_MainLayout;
|
QVBoxLayout * m_MainLayout;
|
||||||
QFormLayout * m_FormLayout;
|
QFormLayout * m_FormLayout;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ MainWindow::MainWindow(QWidget * parent) :
|
|||||||
|
|
||||||
m_BiomeView = new BiomeView();
|
m_BiomeView = new BiomeView();
|
||||||
m_MainLayout = new QHBoxLayout();
|
m_MainLayout = new QHBoxLayout();
|
||||||
m_MainLayout->addWidget(m_BiomeView);
|
m_MainLayout->addWidget(m_BiomeView, 1);
|
||||||
m_MainLayout->setMenuBar(menuBar());
|
m_MainLayout->setMenuBar(menuBar());
|
||||||
m_MainLayout->setMargin(0);
|
m_MainLayout->setMargin(0);
|
||||||
QWidget * central = new QWidget();
|
QWidget * central = new QWidget();
|
||||||
@ -57,7 +57,8 @@ void MainWindow::newGenerator()
|
|||||||
openGeneratorSetup("");
|
openGeneratorSetup("");
|
||||||
|
|
||||||
// Set the chunk source:
|
// Set the chunk source:
|
||||||
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(m_GeneratorSetup->getIniFile())));
|
cIniFilePtr iniFile = m_GeneratorSetup->getIniFile();
|
||||||
|
m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(iniFile)));
|
||||||
m_BiomeView->redraw();
|
m_BiomeView->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +261,6 @@ QString MainWindow::getWorldName(const AString & a_Path)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
AString name = nbt.GetName(1);
|
AString name = nbt.GetName(1);
|
||||||
OutputDebugStringA(name.c_str());
|
|
||||||
int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName");
|
int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName");
|
||||||
if ((levelNameTag <= 0) || (nbt.GetType(levelNameTag) != TAG_String))
|
if ((levelNameTag <= 0) || (nbt.GetType(levelNameTag) != TAG_String))
|
||||||
{
|
{
|
||||||
@ -286,6 +286,9 @@ void MainWindow::openGeneratorSetup(const AString & a_IniFileName)
|
|||||||
m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;"));
|
m_LineSeparator->setStyleSheet(QString("background-color: #c0c0c0;"));
|
||||||
m_MainLayout->addWidget(m_LineSeparator);
|
m_MainLayout->addWidget(m_LineSeparator);
|
||||||
m_MainLayout->addWidget(m_GeneratorSetup);
|
m_MainLayout->addWidget(m_GeneratorSetup);
|
||||||
|
|
||||||
|
// Connect the signals from the setup pane:
|
||||||
|
connect(m_GeneratorSetup, SIGNAL(generatorUpdated()), m_BiomeView, SLOT(reload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,8 +89,6 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \
|
|||||||
|
|
||||||
CONFIG += C++11
|
CONFIG += C++11
|
||||||
|
|
||||||
OTHER_FILES += \
|
OTHER_FILES +=
|
||||||
../../lib/zlib/example.c.txt \
|
|
||||||
../../lib/zlib/minigzip.c.txt
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user