Skip to content

Commit

Permalink
Merge pull request #78 from Zegeri/development
Browse files Browse the repository at this point in the history
Improve project importing and event page
  • Loading branch information
Ghabry committed Apr 29, 2016
2 parents d4bea43 + 0fde2ab commit 77681fc
Show file tree
Hide file tree
Showing 10 changed files with 1,537 additions and 1,921 deletions.
20 changes: 8 additions & 12 deletions EasyRPG-Editor.pro
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-28T16:21:38
#
#-------------------------------------------------
lessThan(QT_MAJOR_VERSION, 5): error("Qt 5 required")

QT += core gui multimedia concurrent widgets
win32:QT += winextras

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

win32:TARGET = EasyRPG-Editor
TEMPLATE = app

Expand Down Expand Up @@ -189,8 +183,10 @@ win32 {
QMAKE_LFLAGS_RELEASE = /LTCG
}

!win32:TARGET = easyrpg-editor
!win32:QMAKE_CXXFLAGS += -Wall -Wextra -ansi -pedantic -std=c++0x
!win32:QMAKE_CXXFLAGS_DEBUG += -O0 -g3
!win32:CONFIG += link_pkgconfig silent
!win32:PKGCONFIG += liblcf
unix {
TARGET = easyrpg-editor
QMAKE_CXXFLAGS += -Wall -Wextra -pedantic
QMAKE_CXXFLAGS_DEBUG += -O0 -g3
CONFIG += link_pkgconfig silent
PKGCONFIG += liblcf
}
4 changes: 4 additions & 0 deletions src/dialogimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ QString DialogImportProject::getDefDir()
return ui->lineProjectPath->text();
}

bool DialogImportProject::getConvertXYZ() const {
return ui->checkConvertXYZ->isChecked();
}

void DialogImportProject::on_lineGameFolder_textChanged(const QString &arg1)
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!arg1.isEmpty());
Expand Down
1 change: 1 addition & 0 deletions src/dialogimportproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DialogImportProject : public QDialog
QString getDefDir();
QString getProjectFolder() const;
QString getSourceFolder() const;
bool getConvertXYZ() const;
private slots:
void on_lineGameFolder_textChanged(const QString &arg1);

Expand Down
15 changes: 11 additions & 4 deletions src/dialogimportproject.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
<x>0</x>
<y>0</y>
<width>396</width>
<height>195</height>
<height>234</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>396</width>
<height>195</height>
<height>234</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>396</width>
<height>195</height>
<height>234</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Import Project</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
Expand Down Expand Up @@ -94,6 +94,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkConvertXYZ">
<property name="text">
<string>Convert XYZ images to PNG</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
143 changes: 65 additions & 78 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
#include "dialogmapproperties.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
#include <QToolBar>
#include <QCloseEvent>
#include <QApplication>
#include <QFileInfo>
#include <QFileDialog>
#include <QMessageBox>
#include <QProgressDialog>
#include <QScrollBar>
#include <QStringList>
#include <QDir>
#include <cassert>
#include <sstream>
#include <iomanip>
#include "core.h"
Expand All @@ -29,6 +32,10 @@
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<float>)

const std::vector<QString> resource_dirs =
{BACKDROP, BATTLE, BATTLE2, BATTLECHARSET, BATTLEWEAPON, CHARSET, CHIPSET, FACESET,
GAMEOVER, MONSTER, MOVIE, MUSIC, PANORAMA, PICTURE, SOUND, SYSTEM, SYSTEM2, TITLE};

static void recurseAddDir(QDir d, QStringList & list) {

QStringList qsl = d.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files);
Expand Down Expand Up @@ -230,7 +237,7 @@ void MainWindow::LoadProject(QString foldername)
update_actions();
}

void MainWindow::ImportProject(QString p_path, QString d_folder)
void MainWindow::ImportProject(QString p_path, QString d_folder, bool convert_xyz)
{
Data::Clear();
mCore->setProjectFolder(d_folder);
Expand Down Expand Up @@ -276,45 +283,15 @@ void MainWindow::ImportProject(QString p_path, QString d_folder)
m_settings.setValue(CURRENT_PROJECT_KEY, mCore->projectFolder());
LDB_Reader::SaveXml(mCore->filePath(ROOT, EASY_DB).toStdString());
LMT_Reader::SaveXml(mCore->filePath(ROOT, EASY_MT).toStdString());
QDir srcDir(p_path+BACKDROP);
QStringList entries;
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+PANORAMA);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+BATTLE);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+BATTLE2);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+BATTLECHARSET);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+BATTLEWEAPON);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+CHARSET);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+CHIPSET);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+FACESET);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+GAMEOVER);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+MONSTER);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+MOVIE);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+MUSIC);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+PICTURE);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+SOUND);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+SYSTEM);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+SYSTEM2);
recurseAddDir(srcDir, entries);
srcDir = QDir(p_path+TITLE);
recurseAddDir(srcDir, entries);
for (const QString& dir : resource_dirs)
recurseAddDir(QDir(p_path+dir), entries);

QProgressDialog progress("Importing resources...", "", 0, entries.count(), this);
progress.setWindowModality(Qt::WindowModal);
for (int i = 0; i < entries.count(); i++)
{
progress.setValue(i);
QFileInfo info(entries[i]);
QString dest_file = mCore->filePath(info.dir().dirName()+"/",info.fileName());
if (!QFile::copy(entries[i], dest_file))
Expand All @@ -335,7 +312,23 @@ void MainWindow::ImportProject(QString p_path, QString d_folder)
on_action_Close_Project_triggered();
return;
}
if (convert_xyz && info.dir().dirName() != MUSIC && info.dir().dirName() != SOUND)
{
QFile file(dest_file);
file.open(QIODevice::ReadOnly);
if (file.read(4) == "XYZ1")
{
QString conv_path = mCore->filePath(info.dir().dirName()+"/",
info.completeBaseName() + ".png");
if (convertXYZtoPNG(file, conv_path))
file.remove();
else
qWarning() << QString("Failed to convert %1 to PNG").arg(dest_file);
}
}

}
progress.setValue(entries.count());

QList<QVariant> m_mapList;
QList<QVariant> m_scaleList;
Expand Down Expand Up @@ -382,9 +375,12 @@ void MainWindow::ImportProject(QString p_path, QString d_folder)
m_treeItems[maps.maps[i].ID]->setExpanded(maps.maps[i].expanded_node);
}
//Import Maps
progress.setLabelText("Importing maps...");
progress.setMaximum(maps.maps.size());
std::stringstream ss;
for (unsigned int i = 1; i < maps.maps.size(); i++)
{
progress.setValue(i);
if (maps.maps[i].type == 2)
continue;
ss.str("");
Expand All @@ -404,6 +400,7 @@ void MainWindow::ImportProject(QString p_path, QString d_folder)
<< ".emu";
LMU_Reader::SaveXml(ss.str(),map);
}
progress.setValue(maps.maps.size());
m_projSett = new QSettings(mCore->filePath(ROOT, EASY_CFG),
QSettings::IniFormat,
this);
Expand All @@ -415,6 +412,30 @@ void MainWindow::ImportProject(QString p_path, QString d_folder)
this->on_treeMap_itemDoubleClicked(m_treeItems[m_mapList[0].toInt()], 0);
}

bool MainWindow::convertXYZtoPNG(QFile &xyz_file, QString out_path)
{
QByteArray compressed_data(xyz_file.readAll());
assert(!compressed_data.isEmpty());
uint16_t width = (uint8_t)compressed_data[0] + ((uint8_t)compressed_data[1] << 8);
uint16_t height = (uint8_t)compressed_data[2] + ((uint8_t)compressed_data[3] << 8);
uint32_t size = width * height;
// Put the total size in the first 4 bytes to make it valid for qUncompress
for (int i = 0; i < 4; ++i)
compressed_data[i] = ((uint8_t*)&size)[3-i];

QByteArray xyz_data(qUncompress(compressed_data));

if (xyz_data.isEmpty())
return false;

QImage image((uchar*)xyz_data.data() + 768, width, height, QImage::Format_Indexed8);
// Add color table
for (int i = 0; i < 256; ++i)
image.setColor(i, qRgb(xyz_data[i * 3], xyz_data[i * 3 + 1], xyz_data[i * 3 + 2]));

return image.save(out_path, "PNG");
}

void MainWindow::on_action_Quit_triggered()
{
saveAll();
Expand Down Expand Up @@ -550,25 +571,8 @@ void MainWindow::on_action_New_Project_triggered()
mCore->setTileSize(dlg.getTileSize());
mCore->setDefDir(dlg.getDefDir());
Data::Clear();
d_gamepath.mkpath(mCore->filePath(BACKDROP));
d_gamepath.mkpath(mCore->filePath(PANORAMA));
d_gamepath.mkpath(mCore->filePath(BATTLE));
d_gamepath.mkpath(mCore->filePath(BATTLE2));
d_gamepath.mkpath(mCore->filePath(BATTLECHARSET));
d_gamepath.mkpath(mCore->filePath(BATTLEWEAPON));
d_gamepath.mkpath(mCore->filePath(CHARSET));
d_gamepath.mkpath(mCore->filePath(CHIPSET));
d_gamepath.mkpath(mCore->filePath(FACESET));
d_gamepath.mkpath(mCore->filePath(FRAME));
d_gamepath.mkpath(mCore->filePath(GAMEOVER));
d_gamepath.mkpath(mCore->filePath(MONSTER));
d_gamepath.mkpath(mCore->filePath(MOVIE));
d_gamepath.mkpath(mCore->filePath(MUSIC));
d_gamepath.mkpath(mCore->filePath(PICTURE));
d_gamepath.mkpath(mCore->filePath(SOUND));
d_gamepath.mkpath(mCore->filePath(SYSTEM));
d_gamepath.mkpath(mCore->filePath(SYSTEM2));
d_gamepath.mkpath(mCore->filePath(TITLE));
for (const QString& dir : resource_dirs)
d_gamepath.mkpath(mCore->filePath(dir));
m_settings.setValue(DEFAULT_DIR_KEY,dlg.getDefDir());
setWindowTitle("EasyRPG Editor - " + mCore->gameTitle());
m_settings.setValue(CURRENT_PROJECT_KEY, mCore->gameTitle());
Expand Down Expand Up @@ -931,29 +935,12 @@ void MainWindow::on_actionImport_Project_triggered()
}
else
d_gamepath.mkpath(".");
mCore->setTileSize(16);
mCore->setProjectFolder(dlg.getProjectFolder());
d_gamepath.mkpath(mCore->filePath(BACKDROP));
d_gamepath.mkpath(mCore->filePath(PANORAMA));
d_gamepath.mkpath(mCore->filePath(BATTLE));
d_gamepath.mkpath(mCore->filePath(BATTLE2));
d_gamepath.mkpath(mCore->filePath(BATTLECHARSET));
d_gamepath.mkpath(mCore->filePath(BATTLEWEAPON));
d_gamepath.mkpath(mCore->filePath(CHARSET));
d_gamepath.mkpath(mCore->filePath(CHIPSET));
d_gamepath.mkpath(mCore->filePath(FACESET));
d_gamepath.mkpath(mCore->filePath(FRAME));
d_gamepath.mkpath(mCore->filePath(GAMEOVER));
d_gamepath.mkpath(mCore->filePath(MONSTER));
d_gamepath.mkpath(mCore->filePath(MOVIE));
d_gamepath.mkpath(mCore->filePath(MUSIC));
d_gamepath.mkpath(mCore->filePath(PICTURE));
d_gamepath.mkpath(mCore->filePath(SOUND));
d_gamepath.mkpath(mCore->filePath(SYSTEM));
d_gamepath.mkpath(mCore->filePath(SYSTEM2));
d_gamepath.mkpath(mCore->filePath(TITLE));
mCore->setTileSize(16);
mCore->setProjectFolder(dlg.getProjectFolder());
for (const QString& dir : resource_dirs)
d_gamepath.mkpath(mCore->filePath(dir));
m_settings.setValue(CURRENT_PROJECT_KEY, dlg.getProjectFolder());
ImportProject(dlg.getSourceFolder(), dlg.getProjectFolder());
ImportProject(dlg.getSourceFolder(), dlg.getProjectFolder(), dlg.getConvertXYZ());
}
m_settings.setValue(DEFAULT_DIR_KEY,dlg.getDefDir());
update_actions();
Expand Down
4 changes: 3 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QFile>
#include <QMainWindow>
#include <QSettings>
#include <QTreeWidgetItem>
Expand All @@ -24,7 +25,7 @@ class MainWindow : public QMainWindow

void LoadLastProject();
void LoadProject(QString foldername);
void ImportProject(QString p_path, QString d_folder);
void ImportProject(QString p_path, QString d_folder, bool convert_xyz);

private slots:
void on_action_Quit_triggered();
Expand Down Expand Up @@ -118,6 +119,7 @@ private slots:
QGraphicsMapScene *currentScene();
void removeView(int id);
void removeMap(const int id);
bool convertXYZtoPNG(QFile &xyz_file, QString out_path);

Ui::MainWindow *ui;
DialogResourceManager *dlg_resource;
Expand Down

0 comments on commit 77681fc

Please sign in to comment.