Added colors.txt assistant which helps to create a colors.txt file.
parent
63d42b9af9
commit
1bccc3488f
|
@ -17,16 +17,21 @@ SOURCES += main.cpp\
|
|||
mainwindow.cpp \
|
||||
colorlineedit.cpp \
|
||||
geometrywidget.cpp \
|
||||
configdialog.cpp
|
||||
configdialog.cpp \
|
||||
colorstxtassistant.cpp \
|
||||
makecolors.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
colorlineedit.h \
|
||||
geometrywidget.h \
|
||||
configdialog.h
|
||||
configdialog.h \
|
||||
colorstxtassistant.h \
|
||||
makecolors.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
geometrywidget.ui \
|
||||
configdialog.ui
|
||||
configdialog.ui \
|
||||
colorstxtassistant.ui
|
||||
|
||||
RESOURCES += \
|
||||
minetestmappergui.qrc
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
#include "colorstxtassistant.h"
|
||||
#include "ui_colorstxtassistant.h"
|
||||
|
||||
ColorsTxtAssistant::ColorsTxtAssistant(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ColorsTxtAssistant)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
ui->buttonPrevious->setVisible(false);
|
||||
ui->buttonFinished->setVisible(false);
|
||||
parent->
|
||||
}
|
||||
|
||||
ColorsTxtAssistant::~ColorsTxtAssistant()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonGenerate_clicked()
|
||||
{
|
||||
MakeColors *makeColors = new MakeColors();
|
||||
QString fileNodesTxt = ui->fileNodesTxt->text();
|
||||
QString fileColorsTxt = ui->fileColorsTxt->text();
|
||||
if(fileColorsTxt.isEmpty()){
|
||||
fileColorsTxt = QFileInfo(fileNodesTxt).dir().absoluteFilePath("colors.txt");
|
||||
}
|
||||
makeColors->setFileColorsTxt(fileColorsTxt);
|
||||
makeColors->setFileNodesTxt(fileNodesTxt);
|
||||
makeColors->setTextureSearchDirectorys(getAllSearchDirs());
|
||||
|
||||
connect(makeColors,SIGNAL(outputLog(QString, int)), this, SLOT(reciveOuputLog(QString, int)) );
|
||||
connect(makeColors,SIGNAL(progressChanged(int)), this, SLOT(reciveProgressChanged(int)));
|
||||
connect(makeColors,SIGNAL(maxProgressChanged(int)) ,this, SLOT(reciveMaxProgressChanged(int)));
|
||||
makeColors->startProcess();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ColorsTxtAssistant::reciveOuputLog(QString text, int level)
|
||||
{
|
||||
QMetaEnum metaEnumLogLevel = QMetaEnum::fromType<MakeColors::LogLevel>();
|
||||
QString msg = QString("%1:\t%2").arg(metaEnumLogLevel.key(level)).arg(text);
|
||||
ui->output->appendPlainText(msg);
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::reciveProgressChanged(int newProgress)
|
||||
{
|
||||
ui->progressBar->setValue(newProgress);
|
||||
//ui->output->appendPlainText(QString("Progress changed to %1").arg(newProgress));
|
||||
}
|
||||
void ColorsTxtAssistant::reciveMaxProgressChanged(int newProgress)
|
||||
{
|
||||
ui->progressBar->setMaximum(newProgress);
|
||||
//ui->output->appendPlainText(QString("Max Progress changed to %1").arg(newProgress));
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonPrevious_clicked()
|
||||
{
|
||||
int currentIndex = ui->stackedWidget->currentIndex();
|
||||
ui->stackedWidget->setCurrentIndex(--currentIndex);
|
||||
ui->buttonNext->setVisible(currentIndex != ui->stackedWidget->children().size());
|
||||
ui->buttonPrevious->setVisible(currentIndex > 0);
|
||||
ui->buttonFinished->setVisible((currentIndex+1) == ui->stackedWidget->children().size());//only visible on last page
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonNext_clicked()
|
||||
{
|
||||
int currentIndex = ui->stackedWidget->currentIndex();
|
||||
ui->stackedWidget->setCurrentIndex(++currentIndex);
|
||||
ui->buttonPrevious->setVisible(currentIndex > 0);//Visible if not on page 0
|
||||
ui->buttonNext->setVisible((currentIndex+1) < ui->stackedWidget->children().size());// Visible if not on last page
|
||||
ui->buttonFinished->setVisible((currentIndex+1) == ui->stackedWidget->children().size());//visible on last page
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonAddSearchDir_clicked()
|
||||
{
|
||||
QFileIconProvider *p = new QFileIconProvider();
|
||||
QString folder = QFileDialog::getExistingDirectory(this,tr("Select Folder"));
|
||||
|
||||
QListWidgetItem *item = new QListWidgetItem(p->icon(QFileIconProvider::Folder),folder);
|
||||
item->setFlags(item->flags()|Qt::ItemIsEditable);
|
||||
|
||||
ui->listSearchDirs->addItem(item);
|
||||
//ui->listSearchDirs->setE
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonRemoveSearchDir_clicked()
|
||||
{
|
||||
qDeleteAll(ui->listSearchDirs->selectedItems());
|
||||
}
|
||||
|
||||
QStringList ColorsTxtAssistant::getAllSearchDirs(void)
|
||||
{
|
||||
QStringList textureSearchDirecotries;
|
||||
for(int i = 0; i < ui->listSearchDirs->count(); ++i)
|
||||
{
|
||||
QListWidgetItem* item = ui->listSearchDirs->item(i);
|
||||
textureSearchDirecotries<< item->data(Qt::DisplayRole).toString();
|
||||
}
|
||||
return textureSearchDirecotries;
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_buttonFinished_clicked()
|
||||
{
|
||||
this->accept();
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_browseColorsTxt_clicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open colors.txt File"),
|
||||
ui->fileColorsTxt->text(),
|
||||
tr("TXT File (*.txt)"));
|
||||
if(fileName!="") ui->fileColorsTxt->setText(fileName);
|
||||
}
|
||||
|
||||
void ColorsTxtAssistant::on_browseFileNodesTxt_clicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open colors.txt File"),
|
||||
ui->fileNodesTxt->text(),
|
||||
tr("TXT File (*.txt)"));
|
||||
if(fileName!="") ui->fileNodesTxt->setText(fileName);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef COLORSTXTASSISTANT_H
|
||||
#define COLORSTXTASSISTANT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QStringList>
|
||||
#include <QFileIconProvider>
|
||||
#include <QFileDialog>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include "makecolors.h"
|
||||
|
||||
namespace Ui {
|
||||
class ColorsTxtAssistant;
|
||||
}
|
||||
|
||||
class ColorsTxtAssistant : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ColorsTxtAssistant(QWidget *parent = 0);
|
||||
~ColorsTxtAssistant();
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void on_buttonGenerate_clicked();
|
||||
|
||||
void on_buttonPrevious_clicked();
|
||||
|
||||
void on_buttonNext_clicked();
|
||||
|
||||
void on_buttonAddSearchDir_clicked();
|
||||
|
||||
void on_buttonRemoveSearchDir_clicked();
|
||||
|
||||
void reciveOuputLog(QString text, int level);
|
||||
|
||||
void reciveProgressChanged(int newProgress);
|
||||
void reciveMaxProgressChanged(int newProgress);
|
||||
void on_buttonFinished_clicked();
|
||||
|
||||
void on_browseColorsTxt_clicked();
|
||||
|
||||
void on_browseFileNodesTxt_clicked();
|
||||
|
||||
private:
|
||||
Ui::ColorsTxtAssistant *ui;
|
||||
|
||||
QStringList getAllSearchDirs(void);
|
||||
};
|
||||
|
||||
#endif // COLORSTXTASSISTANT_H
|
|
@ -0,0 +1,235 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ColorsTxtAssistant</class>
|
||||
<widget class="QDialog" name="ColorsTxtAssistant">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>546</width>
|
||||
<height>328</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonPrevious">
|
||||
<property name="text">
|
||||
<string>Previous</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonNext">
|
||||
<property name="text">
|
||||
<string>Next</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonFinished">
|
||||
<property name="text">
|
||||
<string>Finished</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="stackedWidgetPage1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;">This Assistant will help you to generate a new colors.txt that fits to your mods and games.</span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;"><br /></span></p>
|
||||
<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;">To proceed click the Next button</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage2">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLineEdit" name="fileNodesTxt">
|
||||
<property name="placeholderText">
|
||||
<string notr="true">nodes.txt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="browseFileNodesTxt">
|
||||
<property name="text">
|
||||
<string>browse</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="minetestmappergui.qrc">
|
||||
<normaloff>:/open</normaloff>:/open</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QTextBrowser" name="textBrowser_2">
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;">
|
||||
<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;">First, you have to install and enable the mod &quot;dumpnodes&quot; You can download it here: </span><a href="https://bitbucket.org/adrido/dumpnodes/overview"><span style=" font-size:9pt; text-decoration: underline; color:#0000ff;">https://bitbucket.org/adrido/dumpnodes/overview</span></a></li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">extract it like each other mod into your mods folder. </li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Activate it in the world configuration </li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Start the game normaly </li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">if you are ingame type /dumpnodes </li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Now there should be a file called nodes.txt inside the world folder. If its there, click the next button if not, start with step 1.</li>
|
||||
<li style=" font-size:9pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Select the generated nodes.txt file down there</li></ol></body></html></string>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Now you have to specify one or more folders where the textures can be found.</p><p>Recomended is the minetest_game folder and the mods folder.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="buttonAddSearchDir">
|
||||
<property name="text">
|
||||
<string>add new</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="minetestmappergui.qrc">
|
||||
<normaloff>:/open</normaloff>:/open</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="buttonRemoveSearchDir">
|
||||
<property name="text">
|
||||
<string>remove selected</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QListWidget" name="listSearchDirs">
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::MoveAction</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage5">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="fileColorsTxt">
|
||||
<property name="placeholderText">
|
||||
<string notr="true">colors.txt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="browseColorsTxt">
|
||||
<property name="text">
|
||||
<string>browse</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="minetestmappergui.qrc">
|
||||
<normaloff>:/open</normaloff>:/open</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;">Optionaly you can specify a colors.txt here.</span></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt;">If you leave this field empty, a colors.txt file will created in the same place as the nodes.txt</span></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage6">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Finished! Click the button Generate now to generate the colors.txt file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonGenerate">
|
||||
<property name="text">
|
||||
<string>Generate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="maximum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="output"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="minetestmappergui.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -88,6 +88,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
progressBar->setMinimum(0);
|
||||
progressBar->hide();
|
||||
connect(ui->actionAbout_QT, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||
connect(ui->actionStart_colors_txt_assistant,SIGNAL(triggered()),this,SLOT(startColorsTxtAssistant()));
|
||||
createLanguageMenu();
|
||||
createProfilesMenu();
|
||||
|
||||
|
@ -1102,3 +1103,8 @@ void MainWindow::updateConfigSettings(const ConfigSettings &newSettings)
|
|||
currentSettings = newSettings;
|
||||
}
|
||||
|
||||
void MainWindow::startColorsTxtAssistant(void)
|
||||
{
|
||||
ColorsTxtAssistant *assistant = new ColorsTxtAssistant(this);
|
||||
assistant->exec();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#endif
|
||||
|
||||
#include "configdialog.h"
|
||||
#include "colorstxtassistant.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -36,6 +37,8 @@ public:
|
|||
void closeConfigDialog(void);
|
||||
void updateConfigSettings(const ConfigSettings &newSettings);
|
||||
|
||||
public slots:
|
||||
void startColorsTxtAssistant();
|
||||
protected:
|
||||
void closeEvent(QCloseEvent* event);
|
||||
// this event is called, when a new translator is loaded or the system language is changed
|
||||
|
|
112
mainwindow.ui
112
mainwindow.ui
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>760</width>
|
||||
<height>424</height>
|
||||
<height>505</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -876,8 +876,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>509</width>
|
||||
<height>360</height>
|
||||
<width>503</width>
|
||||
<height>427</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
|
@ -1927,8 +1927,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>261</height>
|
||||
<width>492</width>
|
||||
<height>308</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
|
@ -1962,11 +1962,11 @@
|
|||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="tile_chunk">
|
||||
<property name="toolTip">
|
||||
<string>A chunk is the unit of map generation. Usually 5x5x5 blocks.</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>A chunk is the unit of map generation. Usually 5x5x5 blocks.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>chunk-aligned</string>
|
||||
<string>chunk-aligned</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -1979,11 +1979,11 @@
|
|||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="tile_block">
|
||||
<property name="toolTip">
|
||||
<string>A block is 16x16x16 nodes</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>A block is 16x16x16 nodes</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>block-aligned</string>
|
||||
<string>block-aligned</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
|
@ -2014,28 +2014,28 @@
|
|||
<property name="title">
|
||||
<string>arrange</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_12" columnstretch="1,2">
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_12" columnstretch="1,2">
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="tilecenter">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>tilecenter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="tileorigin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>tileorigin</string>
|
||||
</property>
|
||||
|
@ -2044,29 +2044,29 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Arrange:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Arrange:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="3">
|
||||
<widget class="QGroupBox" name="groupBox_13">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>at:</string>
|
||||
<string>at:</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_13">
|
||||
<item row="0" column="0">
|
||||
|
@ -2079,7 +2079,7 @@
|
|||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="tiles_world">
|
||||
<property name="text">
|
||||
<string>world center (0,0)</string>
|
||||
<string>world center (0,0)</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
|
@ -2089,7 +2089,7 @@
|
|||
<item row="2" column="0">
|
||||
<widget class="QRadioButton" name="tiles_map">
|
||||
<property name="text">
|
||||
<string>map origin (top-left)</string>
|
||||
<string>map origin (top-left)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -2250,7 +2250,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>760</width>
|
||||
<height>21</height>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -2302,6 +2302,7 @@
|
|||
</property>
|
||||
<addaction name="actionExpert_Mode"/>
|
||||
<addaction name="actionOpen_map_after_creation"/>
|
||||
<addaction name="actionStart_colors_txt_assistant"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
|
@ -2370,7 +2371,7 @@
|
|||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="source">
|
||||
|
@ -2570,6 +2571,11 @@ p, li { white-space: pre-wrap; }
|
|||
<string>&Preferences</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStart_colors_txt_assistant">
|
||||
<property name="text">
|
||||
<string>Start colors.txt assistant</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
|
|
@ -0,0 +1,246 @@
|
|||
#include "makecolors.h"
|
||||
#include <QMetaEnum>
|
||||
|
||||
MakeColors::MakeColors(const QString nodesTxt, const QString colorsTxt, const QStringList searchPaths, QObject *parent)
|
||||
: QThread(parent)
|
||||
{
|
||||
textureFileFilter << "*.png";
|
||||
setFileNodesTxt(nodesTxt);
|
||||
setFileColorsTxt(colorsTxt);
|
||||
setTextureSearchDirectorys(searchPaths);
|
||||
|
||||
abort = false;
|
||||
}
|
||||
|
||||
MakeColors::MakeColors()
|
||||
{
|
||||
textureFileFilter << "*.png";
|
||||
|
||||
abort = false;
|
||||
}
|
||||
|
||||
MakeColors::~MakeColors()
|
||||
{
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
mutex.unlock();
|
||||
|
||||
wait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QColor MakeColors::processImage(QString path)
|
||||
{
|
||||
//create a new image and load from path
|
||||
QImage img(path);
|
||||
QColor color;
|
||||
//convert to RGB32 format
|
||||
img = img.convertToFormat(QImage::Format_ARGB32);
|
||||
int w = img.width();
|
||||
int h = img.height();
|
||||
long r,g,b;
|
||||
r=g=b=0;
|
||||
int counter =0;
|
||||
for(int i = 0; i<h; i++)
|
||||
{
|
||||
//QRgb *line = static_cast<QRgb*>img.constScanLine(i);
|
||||
|
||||
//Dont access rowData directly! it depends on platform. always use QRgb()
|
||||
QRgb *rowData = (QRgb*)img.constScanLine(i);
|
||||
for(int j = 0;j<w; j++){
|
||||
|
||||
QRgb pixelData = rowData[j];
|
||||
if (qAlpha(pixelData) < 128)
|
||||
continue;
|
||||
int red = qRed(pixelData);
|
||||
int gre = qGreen(pixelData);
|
||||
int blu = qBlue(pixelData);
|
||||
|
||||
r+=red;
|
||||
g+=gre;
|
||||
b+=blu;
|
||||
|
||||
counter++;
|
||||
|
||||
}
|
||||
}
|
||||
if(counter == 0)
|
||||
{
|
||||
output("could not generate color of " +path +" too much transparency", WARNING);
|
||||
color = QColor();//invalid color
|
||||
}
|
||||
else{
|
||||
color = QColor(r/counter,g/counter,b/counter);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
bool MakeColors::parseNodesTxt(QString nodesTxt)
|
||||
{
|
||||
output("Parsing "+nodesTxt, INFO);
|
||||
QFile inputFile(nodesTxt);
|
||||
if (inputFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QTextStream in(&inputFile);
|
||||
while (!in.atEnd())
|
||||
{
|
||||
|
||||
QString line = in.readLine();
|
||||
if(line.isEmpty() || line.startsWith('#'))
|
||||
continue;
|
||||
else{
|
||||
//qDebug()<< line;
|
||||
QStringList lineS = line.split(' ');
|
||||
const QString textureName = lineS[1];//get the filename out of the line
|
||||
|
||||
//Insert the texturename and a invalid Color. The color will be set by searchAndProgrssTextures
|
||||
requiredColors.insert(textureName,QColor());
|
||||
|
||||
//Insert Nodename and texturename into QMap to be sorted in alphabetical order
|
||||
nodeList.insert(lineS[0],lineS[1]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
inputFile.close();
|
||||
numberOfNodes = requiredColors.size();
|
||||
}
|
||||
else{
|
||||
output("Could not open "+nodesTxt+" for reading!", ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MakeColors::searchAndProgressTextures(const QString path)
|
||||
{
|
||||
QDirIterator it(path, textureFileFilter, QDir::Files, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()){
|
||||
const QString textureFilePath = it.next();
|
||||
const QString textureFileName = it.fileName();
|
||||
if(requiredColors.contains(textureFileName)){
|
||||
output("Processing "+textureFileName, VERBOSE);
|
||||
const QColor color = processImage(textureFilePath);
|
||||
|
||||
|
||||
//inserting over an existing item will override it. We set the color in this place.
|
||||
requiredColors.insert(textureFileName, color);
|
||||
//numberOfColors++;
|
||||
emit progressChanged(++numberOfColors);
|
||||
}
|
||||
else{
|
||||
output("Not required: "+textureFileName, VERBOSE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MakeColors::setLogLevel(const LogLevel &value)
|
||||
{
|
||||
logLevel = value;
|
||||
}
|
||||
|
||||
void MakeColors::setTextureSearchDirectorys(const QStringList &value)
|
||||
{
|
||||
textureSearchDirectorys = value;
|
||||
}
|
||||
|
||||
void MakeColors::setFileColorsTxt(const QString &value)
|
||||
{
|
||||
this->fileColorsTxt = value;
|
||||
}
|
||||
|
||||
void MakeColors::setFileNodesTxt(const QString &value)
|
||||
{
|
||||
fileNodesTxt = value;
|
||||
}
|
||||
|
||||
bool MakeColors::writeColorsTxt(const QString file)
|
||||
{
|
||||
QFile outputFile(file);
|
||||
output("Writing colors.txt file to "+file ,INFO);
|
||||
if (outputFile.open(QIODevice::WriteOnly| QIODevice::Truncate | QIODevice::Text)) {
|
||||
//QTextStream in(&inputFile);
|
||||
QMapIterator<QString,QString> mi(nodeList);
|
||||
QTextStream out(&outputFile);
|
||||
|
||||
QString lastMod = "";//Used for some nicer formating
|
||||
out << "# Autogenerated colors.txt file from MinetestMapperGui"<<endl;
|
||||
out << "# Generated at " << QDateTime::currentDateTime().toString() <<endl;
|
||||
while (mi.hasNext())
|
||||
{
|
||||
mi.next();
|
||||
const QString fullNodeName = mi.key();
|
||||
const QString currentMod = fullNodeName.split(':')[0];
|
||||
|
||||
//write a new paragraph
|
||||
if(currentMod != lastMod){
|
||||
out<<endl<<"# "<<fullNodeName.split(':')[0]<<endl;
|
||||
lastMod = currentMod;
|
||||
}
|
||||
//read the color for texture out of requiredColors QHash
|
||||
QColor color = requiredColors.value(mi.value());
|
||||
if( color.isValid()){
|
||||
out<<fullNodeName<< QString(" %1 %2 %3").arg(color.red(),3).arg(color.green(),3).arg(color.blue(),3) <<endl;
|
||||
}
|
||||
else{
|
||||
output("No color found for " +fullNodeName, WARNING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
outputFile.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void MakeColors::run(void)
|
||||
{
|
||||
parseNodesTxt(fileNodesTxt);
|
||||
emit maxProgressChanged(requiredColors.size());
|
||||
emit progressChanged(0);
|
||||
output(QString("Found %1 nodes").arg(nodeList.size()), INFO);
|
||||
output(QString("Searching and parsing %1 texture files").arg(requiredColors.size()), INFO);
|
||||
msleep(1000);
|
||||
for(int i = 0; i < textureSearchDirectorys.size(); i++)
|
||||
{
|
||||
//emit stateChanged("search and process textures "+ i +" of "+textureSearchDirectorys.size());
|
||||
searchAndProgressTextures(textureSearchDirectorys.at(i));
|
||||
|
||||
}
|
||||
msleep(500);
|
||||
writeColorsTxt(fileColorsTxt);
|
||||
output("Done! :)",INFO);
|
||||
//msleep(10);
|
||||
}
|
||||
|
||||
void MakeColors::startProcess(void)
|
||||
{
|
||||
output("Starting...",VERBOSE);
|
||||
|
||||
// Set this to 0 and -1 makes the progressbar shows busy
|
||||
emit maxProgressChanged(0);
|
||||
emit progressChanged(-1);
|
||||
msleep(500);
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
void MakeColors::stopProcess()
|
||||
{
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void MakeColors::output(QString message, LogLevel level)
|
||||
{
|
||||
if(logLevel <= level){
|
||||
emit outputLog(message,level);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef MAKECOLORS_H
|
||||
#define MAKECOLORS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDirIterator>
|
||||
#include <QImage>
|
||||
#include <QDebug>
|
||||
#include <QMutex>
|
||||
#include <QColor>
|
||||
#include <QRgb>
|
||||
#include <QDateTime>
|
||||
|
||||
class MakeColors : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MakeColors(const QString nodesTxt, const QString colorsTxt, const QStringList searchPaths, QObject *parent);
|
||||
explicit MakeColors();
|
||||
~MakeColors();
|
||||
void startProcess();
|
||||
void setFileNodesTxt(const QString &value);
|
||||
|
||||
void setFileColorsTxt(const QString &value);
|
||||
|
||||
void setTextureSearchDirectorys(const QStringList &value);
|
||||
|
||||
enum LogLevel {
|
||||
NONE,
|
||||
VERBOSE,
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR
|
||||
};
|
||||
Q_ENUM(LogLevel)
|
||||
|
||||
void setLogLevel(const LogLevel &value);
|
||||
|
||||
signals:
|
||||
void outputLog(QString message, int level);
|
||||
void progressChanged(int);
|
||||
void maxProgressChanged(int);
|
||||
|
||||
public slots:
|
||||
void stopProcess();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
private slots:
|
||||
QColor processImage(QString path);
|
||||
bool parseNodesTxt(QString nodesTxt);
|
||||
bool searchAndProgressTextures(const QString path);
|
||||
private:
|
||||
bool abort;
|
||||
int numberOfNodes = 0;
|
||||
int numberOfColors = 0;
|
||||
QString fileNodesTxt;
|
||||
QString fileColorsTxt;
|
||||
QStringList textureSearchDirectorys;
|
||||
QStringList textureFileFilter;
|
||||
LogLevel logLevel = INFO;
|
||||
|
||||
QHash<QString, QColor> requiredColors;
|
||||
QMap<QString, QString> nodeList;
|
||||
bool writeColorsTxt(const QString file);
|
||||
void output(QString message, LogLevel level = NONE);
|
||||
QMutex mutex;
|
||||
};
|
||||
|
||||
#endif // MAKECOLORS_H
|
Loading…
Reference in New Issue