Prefer a colors.txt from the world directory (if exist) but allow to use always a static one

master
addi 2016-11-09 10:11:27 +01:00
parent 2daea70c43
commit 7b801e5755
5 changed files with 210 additions and 96 deletions

View File

@ -120,3 +120,8 @@ void ColorsTxtAssistant::on_browseFileNodesTxt_clicked()
tr("TXT File (*.txt)"));
if(fileName!="") ui->fileNodesTxt->setText(fileName);
}
void ColorsTxtAssistant::setNodesTxtFilePath(const QString &nodesTxtFilePath)
{
ui->fileNodesTxt->setText(nodesTxtFilePath);
}

View File

@ -24,6 +24,7 @@ public:
explicit ColorsTxtAssistant(QWidget *parent = 0);
~ColorsTxtAssistant();
void setNodesTxtFilePath(const QString &nodesTxtFilePath);
public slots:
private slots:

View File

@ -267,8 +267,8 @@ void MainWindow::on_button_generate_clicked()
qDebug() << QString("Minetestmapper version: ") + ConfigSettings::getMapperVersion(mapperBinary.fileName(), this);
QDir worldPath = QDir(ui->path_World->text());
if(!worldPath.exists()||worldPath.path()=="."||worldPath.path()=="/"){
QDir worldDir = QDir(ui->path_World->text());
if(!worldDir.exists()||worldDir.path()=="."||worldDir.path()=="/"){
QMessageBox::critical(this, tr("no input world selected"),
tr("ERROR: No MinetestWorld selected<br><br>"
"please select a world"));
@ -303,14 +303,18 @@ void MainWindow::on_button_generate_clicked()
}
QString appDir =QCoreApplication::applicationDirPath();
QString appDir = qApp->applicationDirPath();
qDebug()<<appDir;
QDir dir = QDir(appDir);
QString colorsTxtFilePath = getColorsTxtFilePath(&dir, &worldDir);
if (colorsTxtFilePath.isEmpty()){
return;
}
QStringList arguments;
arguments <<"-i" << ui->path_World->text()//"D:\\Programme\\minetest\\worlds\\server_minetest.king-arthur.eu_30000"
<<"--output" << imgName //"D:\\Users\\Adrian\\Desktop\\test2.png"
<<"--colors" << dir.absoluteFilePath(ui->path_ColorsTxt->text()) //appDir+"\\colors\\colors.txt"
<<"--colors" << colorsTxtFilePath
<<"--progress" //<< "--verbose-search-colors=2" //<<"--verbose"
<<"--drawalpha="+ui->drawAlpha->currentText()
<<"--bgcolor" << ui->bgcolor->text()
@ -782,13 +786,14 @@ void MainWindow::writeProfile(QString strProfile)
profile.endGroup();
profile.beginGroup("colors"); //tab4 Colors
profile.setValue("path_ColorsTxt",ui->path_ColorsTxt->text());
profile.setValue("bgcolor",ui->bgcolor->text());
profile.setValue("blockcolor",ui->blockcolor->text());
profile.setValue("scalecolor",ui->scalecolor->text());
profile.setValue("origincolor",ui->origincolor->text());
profile.setValue("playercolor",ui->playercolor->text());
profile.setValue("tileborderrcolor",ui->tilebordercolor->text());
profile.setValue("path_ColorsTxt", ui->path_ColorsTxt->text());
profile.setValue("useStaticColorsTxt", ui->useStaticColorsTxt->isChecked());
profile.setValue("bgcolor", ui->bgcolor->text());
profile.setValue("blockcolor", ui->blockcolor->text());
profile.setValue("scalecolor", ui->scalecolor->text());
profile.setValue("origincolor", ui->origincolor->text());
profile.setValue("playercolor", ui->playercolor->text());
profile.setValue("tileborderrcolor", ui->tilebordercolor->text());
profile.endGroup();
profile.beginGroup("features"); //tab5 Featurs
@ -880,6 +885,7 @@ void MainWindow::readProfile(QString strProfile)
profile.beginGroup("colors"); //tab4 Colors
ui->path_ColorsTxt->setText(profile.value("path_ColorsTxt","./colors/colors.txt").toString());
ui->useStaticColorsTxt->setChecked(profile.value("useStaticColorsTxt",false).toBool());
ui->bgcolor->setText(profile.value("bgcolor","white").toString());
ui->blockcolor->setText(profile.value("blockcolor","white").toString());
ui->scalecolor->setText(profile.value("scalecolor","black").toString());
@ -1108,3 +1114,76 @@ void MainWindow::startColorsTxtAssistant(void)
ColorsTxtAssistant *assistant = new ColorsTxtAssistant(this);
assistant->exec();
}
/**
* @brief MainWindow::getColorsTxtFilePath
* @param appDir Current applications working dir
* @param worldDir Dir of the selected minetest world
* @return Returns a filepath to a colors.txt file or a empty string.
*/
QString MainWindow::getColorsTxtFilePath(QDir *appDir, QDir *worldDir)
{
QString retval;
if(ui->useStaticColorsTxt->isChecked()){
retval = appDir->absoluteFilePath(ui->path_ColorsTxt->text()); //appDir+"\\colors\\colors.txt"
}
else{
// First check if there is a colors.txt file in world dir
if(QFile::exists( worldDir->absoluteFilePath("colors.txt")))
{
retval = worldDir->absoluteFilePath("colors.txt");
}
//else check if there is a nodes.txt in worldpath
else if(QFile::exists( worldDir->absoluteFilePath("nodes.txt")))
{
// There is a nodes.txt but no colors.txt; Ask if the user want to create a colors.txt file
int ret = QMessageBox::question(this, tr("Create a colors.txt"),
tr("There is a nodes.txt but no colors.txt in the world directory\n"
"Do you want to generate one? \n"
"If you select 'No' the default colors.txt will be used.")
);
if(ret == QMessageBox::Yes)
{
ColorsTxtAssistant assistant(this);
assistant.setNodesTxtFilePath(worldDir->absoluteFilePath("nodes.txt"));
assistant.exec();//maybe exec should return if a colors.txt file could successfuly generated.
if(QFile::exists( worldDir->absoluteFilePath("colors.txt"))){
retval = worldDir->absoluteFilePath("colors.txt");
}
else{
//not shure how to handle this case. We could just return now and do nothing, or we could use the default colors.txt file.
//Let the user decide. even if he have seen way too much messages.
int ret2 = QMessageBox::critical(this, tr("No colors.txt file"),
tr("ERROR: Still no colors.txt file found inside world directory.\n\n"
"Do you want to cancel or proceed with default colors.txt file?"),
tr("Cancel"),
tr("Proceed with default"));
if(ret2 == 1){
//Proceed button pressed
retval = appDir->absoluteFilePath(ui->path_ColorsTxt->text());
}
else {
//case of cancel
retval = QString();//empty string
}
}
}
else{
// User has choose to use the default one
retval = appDir->absoluteFilePath(ui->path_ColorsTxt->text());
}
}
else{
// there is neither a colors.txt nor a nodes.txt file in world dir.
// Use the colors.txt file from colors tab.
retval = appDir->absoluteFilePath(ui->path_ColorsTxt->text());
}
}
return retval;
}

View File

@ -134,6 +134,7 @@ private:
QString pathProfiles; // path where the profiles should be stored.
//QSettings profile;
QSettings *settings;
QString getColorsTxtFilePath(QDir *appDir, QDir *worldDir);
};
#endif // MAINWINDOW_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>505</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
@ -235,7 +235,8 @@
<item row="0" column="1">
<widget class="QRadioButton" name="geometrymode_block">
<property name="toolTip">
<string>The requested geometry will be extended so that the map does not contain partial map blocks (of 16x16 nodes each). At least all pixels covered by the geometry will be in the map, but there may be up to 15 more in every direction.</string>
<string>The requested geometry will be extended so that the map does not contain partial map blocks (of 16x16 nodes each).
At least all pixels covered by the geometry will be in the map, but there may be up to 15 more in every direction.</string>
</property>
<property name="statusTip">
<string>round the coodinates to a multiple of 16.</string>
@ -251,7 +252,8 @@
<item row="1" column="1">
<widget class="QRadioButton" name="geometrymode_shrink">
<property name="toolTip">
<string>Currently, shrinking is done with block granularity, and based on which blocks are in the database. As the database always contains a row or and column of empty, or partially empty blocks at the map edges, there will still be empty pixels at the edges of the map. Use --blockcolor to visualize these empty blocks.</string>
<string>Currently, shrinking is done with block granularity, and based on which blocks are in the database.
As the database always contains a row or and column of empty, or partially empty blocks at the map edges, there will still be empty pixels at the edges of the map. Use --blockcolor to visualize these empty blocks.</string>
</property>
<property name="statusTip">
<string>Generate a map of at most the requested geometry. Shrink it to the smallest possible size that still includes the same information.</string>
@ -283,7 +285,8 @@
<item row="0" column="0">
<widget class="QRadioButton" name="geometrymode_pixel">
<property name="toolTip">
<string>A map of exactly the requested size is generated (after adjustments due to the 'shrink' flag, or possible adjustments required by the scale factor).</string>
<string>A map of exactly the requested size is generated
(after adjustments due to the 'shrink' flag, or possible adjustments required by the scale factor).</string>
</property>
<property name="statusTip">
<string>interpret the coordinates with pixel granularity.</string>
@ -326,6 +329,15 @@
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox_minY">
<property name="toolTip">
<string>Specify the upper height limit for the map
Nodes higher than this level will not be drawn. This can be used to avoid floating islands or floating artefacts from obscuring the world below.
</string>
</property>
<property name="statusTip">
<string>Specify the minumum depth of nodes to be included</string>
</property>
<property name="text">
<string>min-Y</string>
</property>
@ -333,8 +345,14 @@
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="checkBox_maxY">
<property name="toolTip">
<string>Specify the upper height limit for the map
Nodes higher than this level will not be drawn. This can be used to avoid floating islands or floating artefacts from obscuring the world below.
</string>
</property>
<property name="statusTip">
<string>Specify the upper height limit for the map</string>
<string>Specify the maximum height of nodes to be included</string>
</property>
<property name="text">
<string>max-Y</string>
@ -1135,14 +1153,68 @@
<string>Colors</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<item row="6" column="0">
<item row="5" column="1">
<widget class="ColorLineEdit" name="origincolor">
<property name="statusTip">
<string> Specify the color for drawing the map origin (0,0)</string>
</property>
<property name="text">
<string notr="true">red</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="ColorLineEdit" name="scalecolor">
<property name="statusTip">
<string> Specify the color for text in the scales on the side</string>
</property>
<property name="text">
<string notr="true">black</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="ColorLineEdit" name="playercolor">
<property name="statusTip">
<string>Specify the color for drawing player locations</string>
</property>
<property name="text">
<string notr="true">yellow</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>tilebordercolor</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<widget class="QLineEdit" name="path_ColorsTxt">
<property name="text">
<string notr="true">./colors/colors.txt</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>playercolor</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="ColorLineEdit" name="blockcolor">
<property name="statusTip">
<string>Specify the color for empty mapblocks</string>
</property>
<property name="text">
<string notr="true">#ffffcc</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="ColorLineEdit" name="bgcolor">
<property name="statusTip">
<string>Specify the background color for the image</string>
@ -1155,58 +1227,34 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>bgcolor</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="path_ColorsTxt">
<property name="text">
<string notr="true">./colors/colors.txt</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>playercolor</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="ColorLineEdit" name="blockcolor">
<property name="statusTip">
<string>Specify the color for empty mapblocks</string>
</property>
<property name="text">
<string notr="true">#ffffcc</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>blockcolor</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>origincolor</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>scalecolor</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>blockcolor</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
@ -1214,7 +1262,7 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -1228,17 +1276,6 @@
</spacer>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="selectTileBorderColor">
<property name="text">
<string>select color</string>
</property>
<property name="icon">
<iconset resource="minetestmappergui.qrc">
<normaloff>:/color</normaloff>:/color</iconset>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QPushButton" name="selectPlayerColor">
<property name="text">
<string>select color</string>
@ -1249,7 +1286,7 @@
</property>
</widget>
</item>
<item row="4" column="2">
<item row="5" column="2">
<widget class="QPushButton" name="selectOriginColor">
<property name="text">
<string>select color</string>
@ -1260,7 +1297,18 @@
</property>
</widget>
</item>
<item row="3" column="2">
<item row="7" column="2">
<widget class="QPushButton" name="selectTileBorderColor">
<property name="text">
<string>select color</string>
</property>
<property name="icon">
<iconset resource="minetestmappergui.qrc">
<normaloff>:/color</normaloff>:/color</iconset>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="selectScaleColor">
<property name="text">
<string>select color</string>
@ -1271,7 +1319,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<item row="3" column="2">
<widget class="QPushButton" name="selectBlockColor">
<property name="text">
<string>select color</string>
@ -1282,7 +1330,7 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="2">
<widget class="QPushButton" name="selectBgColor">
<property name="text">
<string>select color</string>
@ -1304,7 +1352,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="ColorLineEdit" name="tilebordercolor">
<property name="statusTip">
<string>Specify the color for drawing tile borders</string>
@ -1314,33 +1362,13 @@
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="ColorLineEdit" name="playercolor">
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="useStaticColorsTxt">
<property name="statusTip">
<string>Specify the color for drawing player locations</string>
<string>If enabled MinetestMapperGui always uses this file instead of searching one in the World directory</string>
</property>
<property name="text">
<string notr="true">yellow</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="ColorLineEdit" name="origincolor">
<property name="statusTip">
<string> Specify the color for drawing the map origin (0,0)</string>
</property>
<property name="text">
<string notr="true">red</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="ColorLineEdit" name="scalecolor">
<property name="statusTip">
<string> Specify the color for text in the scales on the side</string>
</property>
<property name="text">
<string notr="true">black</string>
<string>Allways use this static colors.txt file</string>
</property>
</widget>
</item>
@ -1927,8 +1955,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>492</width>
<height>308</height>
<width>513</width>
<height>369</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -2249,7 +2277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<width>800</width>
<height>26</height>
</rect>
</property>