1
0

QtBiomeVisualiser: Implemented live-update for the generator setup.

This commit is contained in:
madmaxoft 2014-09-22 21:51:59 +02:00
parent 583532e1b9
commit 83588fb0aa
5 changed files with 49 additions and 17 deletions

View File

@ -171,7 +171,7 @@ void BioGenSource::getChunkBiomes(int a_ChunkX, int a_ChunkZ, ChunkPtr a_DestChu
void BioGenSource::reload()
{
int seed = m_IniFile->GetValueSetI("Seed", "Seed", 0);
int seed = m_IniFile->GetValueSetI("Generator", "Seed", 0);
bool unused = false;
QMutexLocker lock(&m_Mtx);
m_BiomeGen.reset(cBiomeGen::CreateBiomeGen(*m_IniFile, seed, unused));

View File

@ -27,22 +27,27 @@ 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:
// 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->setMinimumWidth(120);
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);
QFormLayout * baseLayout = new QFormLayout();
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:
m_FormLayout = new QFormLayout();
// The main layout joins these two vertically:
m_MainLayout = new QVBoxLayout();
m_MainLayout->addLayout(nameLayout);
m_MainLayout->addLayout(baseLayout);
m_MainLayout->addLayout(m_FormLayout);
m_MainLayout->addStretch();
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))
{
m_cbGenerator->setCurrentText(QString::fromStdString(m_IniFile->GetValue("Generator", "BiomeGen")));
m_eSeed->setText(QString::number(m_IniFile->GetValueI("Generator", "Seed")));
}
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);
delete cBiomeGen::CreateBiomeGen(*m_IniFile, 0, 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)));
// Connect the change events only after the data has been loaded:
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:
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++)
{
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;
}
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:
if (NoCaseCompare(itemName.substr(0, generatorNameLen), generatorName) == 0)
@ -124,8 +149,7 @@ void GeneratorSetup::updateFromIni()
itemName.erase(0, generatorNameLen);
}
QLineEdit * edit = new QLineEdit();
edit->setText(QString::fromStdString(itemValue));
connect(edit, SIGNAL(textChanged(QString)), this, SLOT(editChanged(QString)));
m_FormLayout->addRow(new QLabel(QString::fromStdString(itemName)), edit);
} // for i - INI values[]
}

View File

@ -32,14 +32,21 @@ public:
cIniFilePtr getIniFile() { return m_IniFile; }
signals:
/** Emitted when the generator parameters have changed. */
void generatorUpdated();
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 slots:
/** Called when any of the edit widgets are changed. */
void editChanged(const QString & a_NewValue);
protected:
QComboBox * m_cbGenerator;
QLineEdit * m_eSeed;
QVBoxLayout * m_MainLayout;
QFormLayout * m_FormLayout;

View File

@ -27,7 +27,7 @@ MainWindow::MainWindow(QWidget * parent) :
m_BiomeView = new BiomeView();
m_MainLayout = new QHBoxLayout();
m_MainLayout->addWidget(m_BiomeView);
m_MainLayout->addWidget(m_BiomeView, 1);
m_MainLayout->setMenuBar(menuBar());
m_MainLayout->setMargin(0);
QWidget * central = new QWidget();
@ -57,7 +57,8 @@ void MainWindow::newGenerator()
openGeneratorSetup("");
// 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();
}
@ -260,7 +261,6 @@ QString MainWindow::getWorldName(const AString & a_Path)
return QString();
}
AString name = nbt.GetName(1);
OutputDebugStringA(name.c_str());
int levelNameTag = nbt.FindTagByPath(nbt.GetRoot(), "Data\\LevelName");
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_MainLayout->addWidget(m_LineSeparator);
m_MainLayout->addWidget(m_GeneratorSetup);
// Connect the signals from the setup pane:
connect(m_GeneratorSetup, SIGNAL(generatorUpdated()), m_BiomeView, SLOT(reload()));
}

View File

@ -89,8 +89,6 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \
CONFIG += C++11
OTHER_FILES += \
../../lib/zlib/example.c.txt \
../../lib/zlib/minigzip.c.txt
OTHER_FILES +=