Start refactoring core + ui. Create selectable pixmap item
This commit is contained in:
parent
3808750c23
commit
6dc1e0eea3
27 changed files with 637 additions and 465 deletions
64
block.cpp → core/block.cpp
Executable file → Normal file
64
block.cpp → core/block.cpp
Executable file → Normal file
|
@ -1,32 +1,32 @@
|
||||||
#include "block.h"
|
#include "core/block.h"
|
||||||
|
|
||||||
Block::Block() {
|
Block::Block() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::Block(uint16_t word)
|
Block::Block(uint16_t word)
|
||||||
{
|
{
|
||||||
tile = word & 0x3ff;
|
tile = word & 0x3ff;
|
||||||
collision = (word >> 10) & 0x3;
|
collision = (word >> 10) & 0x3;
|
||||||
elevation = (word >> 12) & 0xf;
|
elevation = (word >> 12) & 0xf;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::Block(const Block &block) {
|
Block::Block(const Block &block) {
|
||||||
tile = block.tile;
|
tile = block.tile;
|
||||||
collision = block.collision;
|
collision = block.collision;
|
||||||
elevation = block.elevation;
|
elevation = block.elevation;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Block::rawValue() {
|
uint16_t Block::rawValue() {
|
||||||
return static_cast<uint16_t>(
|
return static_cast<uint16_t>(
|
||||||
(tile & 0x3ff) +
|
(tile & 0x3ff) +
|
||||||
((collision & 0x3) << 10) +
|
((collision & 0x3) << 10) +
|
||||||
((elevation & 0xf) << 12));
|
((elevation & 0xf) << 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Block::operator ==(Block other) {
|
bool Block::operator ==(Block other) {
|
||||||
return (tile == other.tile) && (collision == other.collision) && (elevation == other.elevation);
|
return (tile == other.tile) && (collision == other.collision) && (elevation == other.elevation);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Block::operator !=(Block other) {
|
bool Block::operator !=(Block other) {
|
||||||
return !(operator ==(other));
|
return !(operator ==(other));
|
||||||
}
|
}
|
40
block.h → core/block.h
Executable file → Normal file
40
block.h → core/block.h
Executable file → Normal file
|
@ -1,20 +1,20 @@
|
||||||
#ifndef BLOCK_H
|
#ifndef BLOCK_H
|
||||||
#define BLOCK_H
|
#define BLOCK_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class Block
|
class Block
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Block();
|
Block();
|
||||||
Block(uint16_t);
|
Block(uint16_t);
|
||||||
Block(const Block&);
|
Block(const Block&);
|
||||||
bool operator ==(Block);
|
bool operator ==(Block);
|
||||||
bool operator !=(Block);
|
bool operator !=(Block);
|
||||||
uint16_t tile:10;
|
uint16_t tile:10;
|
||||||
uint16_t collision:2;
|
uint16_t collision:2;
|
||||||
uint16_t elevation:4;
|
uint16_t elevation:4;
|
||||||
uint16_t rawValue();
|
uint16_t rawValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOCK_H
|
#endif // BLOCK_H
|
109
blockdata.cpp → core/blockdata.cpp
Executable file → Normal file
109
blockdata.cpp → core/blockdata.cpp
Executable file → Normal file
|
@ -1,55 +1,54 @@
|
||||||
#include "blockdata.h"
|
#include "core/blockdata.h"
|
||||||
#include <QDebug>
|
|
||||||
|
Blockdata::Blockdata(QObject *parent) : QObject(parent)
|
||||||
Blockdata::Blockdata(QObject *parent) : QObject(parent)
|
{
|
||||||
{
|
blocks = new QList<Block>;
|
||||||
blocks = new QList<Block>;
|
}
|
||||||
}
|
|
||||||
|
void Blockdata::addBlock(uint16_t word) {
|
||||||
void Blockdata::addBlock(uint16_t word) {
|
Block block(word);
|
||||||
Block block(word);
|
blocks->append(block);
|
||||||
blocks->append(block);
|
}
|
||||||
}
|
|
||||||
|
void Blockdata::addBlock(Block block) {
|
||||||
void Blockdata::addBlock(Block block) {
|
blocks->append(block);
|
||||||
blocks->append(block);
|
}
|
||||||
}
|
|
||||||
|
QByteArray Blockdata::serialize() {
|
||||||
QByteArray Blockdata::serialize() {
|
QByteArray data;
|
||||||
QByteArray data;
|
for (int i = 0; i < blocks->length(); i++) {
|
||||||
for (int i = 0; i < blocks->length(); i++) {
|
Block block = blocks->value(i);
|
||||||
Block block = blocks->value(i);
|
uint16_t word = block.rawValue();
|
||||||
uint16_t word = block.rawValue();
|
data.append(static_cast<char>(word & 0xff));
|
||||||
data.append(static_cast<char>(word & 0xff));
|
data.append(static_cast<char>((word >> 8) & 0xff));
|
||||||
data.append(static_cast<char>((word >> 8) & 0xff));
|
}
|
||||||
}
|
return data;
|
||||||
return data;
|
}
|
||||||
}
|
|
||||||
|
void Blockdata::copyFrom(Blockdata* other) {
|
||||||
void Blockdata::copyFrom(Blockdata* other) {
|
blocks->clear();
|
||||||
blocks->clear();
|
for (int i = 0; i < other->blocks->length(); i++) {
|
||||||
for (int i = 0; i < other->blocks->length(); i++) {
|
addBlock(other->blocks->value(i));
|
||||||
addBlock(other->blocks->value(i));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Blockdata* Blockdata::copy() {
|
||||||
Blockdata* Blockdata::copy() {
|
Blockdata* blockdata = new Blockdata;
|
||||||
Blockdata* blockdata = new Blockdata;
|
blockdata->copyFrom(this);
|
||||||
blockdata->copyFrom(this);
|
return blockdata;
|
||||||
return blockdata;
|
}
|
||||||
}
|
|
||||||
|
bool Blockdata::equals(Blockdata *other) {
|
||||||
bool Blockdata::equals(Blockdata *other) {
|
if (!other) {
|
||||||
if (!other) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (blocks->length() != other->blocks->length()) {
|
||||||
if (blocks->length() != other->blocks->length()) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
for (int i = 0; i < blocks->length(); i++) {
|
||||||
for (int i = 0; i < blocks->length(); i++) {
|
if (blocks->value(i) != other->blocks->value(i)) {
|
||||||
if (blocks->value(i) != other->blocks->value(i)) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
|
64
blockdata.h → core/blockdata.h
Executable file → Normal file
64
blockdata.h → core/blockdata.h
Executable file → Normal file
|
@ -1,32 +1,32 @@
|
||||||
#ifndef BLOCKDATA_H
|
#ifndef BLOCKDATA_H
|
||||||
#define BLOCKDATA_H
|
#define BLOCKDATA_H
|
||||||
|
|
||||||
#include "block.h"
|
#include "block.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
|
||||||
class Blockdata : public QObject
|
class Blockdata : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Blockdata(QObject *parent = nullptr);
|
explicit Blockdata(QObject *parent = nullptr);
|
||||||
~Blockdata() {
|
~Blockdata() {
|
||||||
if (blocks) delete blocks;
|
if (blocks) delete blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QList<Block> *blocks = nullptr;
|
QList<Block> *blocks = nullptr;
|
||||||
void addBlock(uint16_t);
|
void addBlock(uint16_t);
|
||||||
void addBlock(Block);
|
void addBlock(Block);
|
||||||
QByteArray serialize();
|
QByteArray serialize();
|
||||||
void copyFrom(Blockdata*);
|
void copyFrom(Blockdata*);
|
||||||
Blockdata* copy();
|
Blockdata* copy();
|
||||||
bool equals(Blockdata *);
|
bool equals(Blockdata *);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOCKDATA_H
|
#endif // BLOCKDATA_H
|
16
core/metatile.cpp
Normal file
16
core/metatile.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "core/metatile.h"
|
||||||
|
#include "project.h"
|
||||||
|
#include "core/tileset.h"
|
||||||
|
|
||||||
|
Metatile::Metatile()
|
||||||
|
{
|
||||||
|
tiles = new QList<Tile>;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Metatile::getBlockIndex(int index) {
|
||||||
|
if (index < Project::getNumMetatilesPrimary()) {
|
||||||
|
return index;
|
||||||
|
} else {
|
||||||
|
return index - Project::getNumMetatilesPrimary();
|
||||||
|
}
|
||||||
|
}
|
17
core/metatile.h
Normal file
17
core/metatile.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef METATILE_H
|
||||||
|
#define METATILE_H
|
||||||
|
|
||||||
|
#include "tile.h"
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
class Metatile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Metatile();
|
||||||
|
public:
|
||||||
|
QList<Tile> *tiles = nullptr;
|
||||||
|
|
||||||
|
static int getBlockIndex(int);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // METATILE_H
|
6
core/tile.cpp
Normal file
6
core/tile.cpp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include "core/tile.h"
|
||||||
|
|
||||||
|
Tile::Tile()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
32
tile.h → core/tile.h
Executable file → Normal file
32
tile.h → core/tile.h
Executable file → Normal file
|
@ -1,16 +1,16 @@
|
||||||
#ifndef TILE_H
|
#ifndef TILE_H
|
||||||
#define TILE_H
|
#define TILE_H
|
||||||
|
|
||||||
|
|
||||||
class Tile
|
class Tile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tile();
|
Tile();
|
||||||
public:
|
public:
|
||||||
int tile;
|
int tile;
|
||||||
int xflip;
|
int xflip;
|
||||||
int yflip;
|
int yflip;
|
||||||
int palette;
|
int palette;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILE_H
|
#endif // TILE_H
|
220
tileset.cpp → core/tileset.cpp
Executable file → Normal file
220
tileset.cpp → core/tileset.cpp
Executable file → Normal file
|
@ -1,116 +1,104 @@
|
||||||
#include "tileset.h"
|
#include "core/tileset.h"
|
||||||
#include "project.h"
|
#include "core/metatile.h"
|
||||||
|
#include "project.h"
|
||||||
#include <QPainter>
|
|
||||||
#include <QImage>
|
#include <QPainter>
|
||||||
#include <QDebug>
|
#include <QImage>
|
||||||
|
#include <QDebug>
|
||||||
Tileset::Tileset()
|
|
||||||
{
|
Tileset::Tileset()
|
||||||
|
{
|
||||||
}
|
|
||||||
|
}
|
||||||
Metatile::Metatile()
|
|
||||||
{
|
Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
tiles = new QList<Tile>;
|
if (metatile_index < Project::getNumMetatilesPrimary()) {
|
||||||
}
|
return primaryTileset;
|
||||||
|
} else {
|
||||||
QImage Metatile::getMetatileImage(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
return secondaryTileset;
|
||||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
}
|
||||||
|
}
|
||||||
Metatile* metatile = Metatile::getMetatile(tile, primaryTileset, secondaryTileset);
|
|
||||||
if (!metatile || !metatile->tiles) {
|
QImage Tileset::getMetatileImage(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
metatile_image.fill(0xffffffff);
|
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
||||||
return metatile_image;
|
|
||||||
}
|
Metatile* metatile = Tileset::getMetatile(tile, primaryTileset, secondaryTileset);
|
||||||
|
if (!metatile || !metatile->tiles) {
|
||||||
Tileset* blockTileset = Metatile::getBlockTileset(tile, primaryTileset, secondaryTileset);
|
metatile_image.fill(0xffffffff);
|
||||||
if (!blockTileset) {
|
return metatile_image;
|
||||||
metatile_image.fill(0xffffffff);
|
}
|
||||||
return metatile_image;
|
|
||||||
}
|
Tileset* blockTileset = Tileset::getBlockTileset(tile, primaryTileset, secondaryTileset);
|
||||||
QList<QList<QRgb>> palettes = Metatile::getBlockPalettes(primaryTileset, secondaryTileset);
|
if (!blockTileset) {
|
||||||
|
metatile_image.fill(0xffffffff);
|
||||||
QPainter metatile_painter(&metatile_image);
|
return metatile_image;
|
||||||
for (int layer = 0; layer < 2; layer++)
|
}
|
||||||
for (int y = 0; y < 2; y++)
|
QList<QList<QRgb>> palettes = Tileset::getBlockPalettes(primaryTileset, secondaryTileset);
|
||||||
for (int x = 0; x < 2; x++) {
|
|
||||||
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
QPainter metatile_painter(&metatile_image);
|
||||||
QImage tile_image = Metatile::getMetatileTile(tile_.tile, primaryTileset, secondaryTileset);
|
for (int layer = 0; layer < 2; layer++)
|
||||||
if (tile_image.isNull()) {
|
for (int y = 0; y < 2; y++)
|
||||||
// Some metatiles specify tiles that are outside the valid range.
|
for (int x = 0; x < 2; x++) {
|
||||||
// These are treated as completely transparent, so they can be skipped without
|
Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4));
|
||||||
// being drawn.
|
QImage tile_image = Tileset::getMetatileTile(tile_.tile, primaryTileset, secondaryTileset);
|
||||||
continue;
|
if (tile_image.isNull()) {
|
||||||
}
|
// Some metatiles specify tiles that are outside the valid range.
|
||||||
|
// These are treated as completely transparent, so they can be skipped without
|
||||||
// Colorize the metatile tiles with its palette.
|
// being drawn.
|
||||||
if (tile_.palette < palettes.length()) {
|
continue;
|
||||||
QList<QRgb> palette = palettes.value(tile_.palette);
|
}
|
||||||
for (int j = 0; j < palette.length(); j++) {
|
|
||||||
tile_image.setColor(j, palette.value(j));
|
// Colorize the metatile tiles with its palette.
|
||||||
}
|
if (tile_.palette < palettes.length()) {
|
||||||
} else {
|
QList<QRgb> palette = palettes.value(tile_.palette);
|
||||||
qDebug() << "Tile is referring to invalid palette number: " << tile_.palette;
|
for (int j = 0; j < palette.length(); j++) {
|
||||||
}
|
tile_image.setColor(j, palette.value(j));
|
||||||
|
}
|
||||||
// The top layer of the metatile has its first color displayed at transparent.
|
} else {
|
||||||
if (layer > 0) {
|
qDebug() << "Tile is referring to invalid palette number: " << tile_.palette;
|
||||||
QColor color(tile_image.color(0));
|
}
|
||||||
color.setAlpha(0);
|
|
||||||
tile_image.setColor(0, color.rgba());
|
// The top layer of the metatile has its first color displayed at transparent.
|
||||||
}
|
if (layer > 0) {
|
||||||
|
QColor color(tile_image.color(0));
|
||||||
QPoint origin = QPoint(x*8, y*8);
|
color.setAlpha(0);
|
||||||
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
tile_image.setColor(0, color.rgba());
|
||||||
}
|
}
|
||||||
metatile_painter.end();
|
|
||||||
|
QPoint origin = QPoint(x*8, y*8);
|
||||||
return metatile_image;
|
metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1));
|
||||||
}
|
}
|
||||||
|
metatile_painter.end();
|
||||||
Metatile* Metatile::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
|
||||||
Tileset *tileset = Metatile::getBlockTileset(index, primaryTileset, secondaryTileset);
|
return metatile_image;
|
||||||
int local_index = Metatile::getBlockIndex(index);
|
}
|
||||||
if (!tileset || !tileset->metatiles) {
|
|
||||||
return nullptr;
|
Metatile* Tileset::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
}
|
Tileset *tileset = Tileset::getBlockTileset(index, primaryTileset, secondaryTileset);
|
||||||
Metatile *metatile = tileset->metatiles->value(local_index, nullptr);
|
int local_index = Metatile::getBlockIndex(index);
|
||||||
return metatile;
|
if (!tileset || !tileset->metatiles) {
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
QImage Metatile::getMetatileTile(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
Metatile *metatile = tileset->metatiles->value(local_index, nullptr);
|
||||||
Tileset *tileset = Metatile::getBlockTileset(tile, primaryTileset, secondaryTileset);
|
return metatile;
|
||||||
int local_index = Metatile::getBlockIndex(tile);
|
}
|
||||||
if (!tileset || !tileset->tiles) {
|
|
||||||
return QImage();
|
QImage Tileset::getMetatileTile(int tile, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
}
|
Tileset *tileset = Tileset::getBlockTileset(tile, primaryTileset, secondaryTileset);
|
||||||
return tileset->tiles->value(local_index, QImage());
|
int local_index = Metatile::getBlockIndex(tile);
|
||||||
}
|
if (!tileset || !tileset->tiles) {
|
||||||
|
return QImage();
|
||||||
Tileset* Metatile::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
}
|
||||||
if (metatile_index < Project::getNumMetatilesPrimary()) {
|
return tileset->tiles->value(local_index, QImage());
|
||||||
return primaryTileset;
|
}
|
||||||
} else {
|
|
||||||
return secondaryTileset;
|
QList<QList<QRgb>> Tileset::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||||
}
|
QList<QList<QRgb>> palettes;
|
||||||
}
|
for (int i = 0; i < Project::getNumPalettesPrimary(); i++) {
|
||||||
|
palettes.append(primaryTileset->palettes->at(i));
|
||||||
int Metatile::getBlockIndex(int index) {
|
}
|
||||||
if (index < Project::getNumMetatilesPrimary()) {
|
for (int i = Project::getNumPalettesPrimary(); i < Project::getNumPalettesTotal(); i++) {
|
||||||
return index;
|
palettes.append(secondaryTileset->palettes->at(i));
|
||||||
} else {
|
}
|
||||||
return index - Project::getNumMetatilesPrimary();
|
return palettes;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QList<QList<QRgb>> Metatile::getBlockPalettes(Tileset *primaryTileset, Tileset *secondaryTileset) {
|
|
||||||
QList<QList<QRgb>> palettes;
|
|
||||||
for (int i = 0; i < Project::getNumPalettesPrimary(); i++) {
|
|
||||||
palettes.append(primaryTileset->palettes->at(i));
|
|
||||||
}
|
|
||||||
for (int i = Project::getNumPalettesPrimary(); i < Project::getNumPalettesTotal(); i++) {
|
|
||||||
palettes.append(secondaryTileset->palettes->at(i));
|
|
||||||
}
|
|
||||||
return palettes;
|
|
||||||
}
|
|
79
tileset.h → core/tileset.h
Executable file → Normal file
79
tileset.h → core/tileset.h
Executable file → Normal file
|
@ -1,45 +1,34 @@
|
||||||
#ifndef TILESET_H
|
#ifndef TILESET_H
|
||||||
#define TILESET_H
|
#define TILESET_H
|
||||||
|
|
||||||
#include "tile.h"
|
#include "core/metatile.h"
|
||||||
#include <QImage>
|
#include "core/tile.h"
|
||||||
|
#include <QImage>
|
||||||
class Metatile;
|
|
||||||
|
class Tileset
|
||||||
class Tileset
|
{
|
||||||
{
|
public:
|
||||||
public:
|
Tileset();
|
||||||
Tileset();
|
public:
|
||||||
public:
|
QString name;
|
||||||
QString name;
|
QString is_compressed;
|
||||||
QString is_compressed;
|
QString is_secondary;
|
||||||
QString is_secondary;
|
QString padding;
|
||||||
QString padding;
|
QString tiles_label;
|
||||||
QString tiles_label;
|
QString palettes_label;
|
||||||
QString palettes_label;
|
QString metatiles_label;
|
||||||
QString metatiles_label;
|
QString callback_label;
|
||||||
QString callback_label;
|
QString metatile_attrs_label;
|
||||||
QString metatile_attrs_label;
|
|
||||||
|
QList<QImage> *tiles = nullptr;
|
||||||
QList<QImage> *tiles = nullptr;
|
QList<Metatile*> *metatiles = nullptr;
|
||||||
QList<Metatile*> *metatiles = nullptr;
|
QList<QList<QRgb>> *palettes = nullptr;
|
||||||
QList<QList<QRgb>> *palettes = nullptr;
|
|
||||||
};
|
static Tileset* getBlockTileset(int, Tileset*, Tileset*);
|
||||||
|
static QImage getMetatileImage(int, Tileset*, Tileset*);
|
||||||
class Metatile
|
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
||||||
{
|
static QImage getMetatileTile(int, Tileset*, Tileset*);
|
||||||
public:
|
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*);
|
||||||
Metatile();
|
};
|
||||||
public:
|
|
||||||
QList<Tile> *tiles = nullptr;
|
#endif // TILESET_H
|
||||||
int attr;
|
|
||||||
|
|
||||||
static QImage getMetatileImage(int, Tileset*, Tileset*);
|
|
||||||
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
|
||||||
static QImage getMetatileTile(int, Tileset*, Tileset*);
|
|
||||||
static Tileset* getBlockTileset(int, Tileset*, Tileset*);
|
|
||||||
static int getBlockIndex(int);
|
|
||||||
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TILESET_H
|
|
81
editor.cpp
81
editor.cpp
|
@ -314,6 +314,14 @@ void Editor::onBorderMetatilesChanged() {
|
||||||
displayMapBorder();
|
displayMapBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::onHoveredMovementPermissionChanged(uint16_t collision, uint16_t elevation) {
|
||||||
|
map->hoveredMovementPermissionTileChanged(collision, elevation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::onHoveredMovementPermissionCleared() {
|
||||||
|
map->clearHoveredMovementPermissionTile();
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::setConnectionsVisibility(bool visible) {
|
void Editor::setConnectionsVisibility(bool visible) {
|
||||||
for (QGraphicsPixmapItem* item : connection_items) {
|
for (QGraphicsPixmapItem* item : connection_items) {
|
||||||
item->setVisible(visible);
|
item->setVisible(visible);
|
||||||
|
@ -500,15 +508,20 @@ void Editor::redrawCurrentMetatilesSelection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayCollisionMetatiles() {
|
void Editor::displayCollisionMetatiles() {
|
||||||
if (collision_metatiles_item && collision_metatiles_item->scene()) {
|
if (movement_permissions_selector_item && movement_permissions_selector_item->scene()) {
|
||||||
collision_metatiles_item->scene()->removeItem(collision_metatiles_item);
|
movement_permissions_selector_item->scene()->removeItem(movement_permissions_selector_item);
|
||||||
delete collision_metatiles_item;
|
delete movement_permissions_selector_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
scene_collision_metatiles = new QGraphicsScene;
|
scene_collision_metatiles = new QGraphicsScene;
|
||||||
collision_metatiles_item = new MovementPermissionsPixmapItem(map);
|
movement_permissions_selector_item = new MovementPermissionsSelector();
|
||||||
collision_metatiles_item->draw();
|
connect(movement_permissions_selector_item, SIGNAL(hoveredMovementPermissionChanged(uint16_t, uint16_t)),
|
||||||
scene_collision_metatiles->addItem(collision_metatiles_item);
|
this, SLOT(onHoveredMovementPermissionChanged(uint16_t, uint16_t)));
|
||||||
|
connect(movement_permissions_selector_item, SIGNAL(hoveredMovementPermissionCleared()),
|
||||||
|
this, SLOT(onHoveredMovementPermissionCleared()));
|
||||||
|
movement_permissions_selector_item->select(0, 3);
|
||||||
|
movement_permissions_selector_item->draw();
|
||||||
|
scene_collision_metatiles->addItem(movement_permissions_selector_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::displayMapEvents() {
|
void Editor::displayMapEvents() {
|
||||||
|
@ -975,7 +988,7 @@ void BorderMetatilesPixmapItem::draw() {
|
||||||
int x = i * 16;
|
int x = i * 16;
|
||||||
int y = j * 16;
|
int y = j * 16;
|
||||||
int index = j * 2 + i;
|
int index = j * 2 + i;
|
||||||
QImage metatile_image = Metatile::getMetatileImage(blocks->value(index).tile, map->layout->tileset_primary, map->layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(blocks->value(index).tile, map->layout->tileset_primary, map->layout->tileset_secondary);
|
||||||
QPoint metatile_origin = QPoint(x, y);
|
QPoint metatile_origin = QPoint(x, y);
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
}
|
}
|
||||||
|
@ -996,7 +1009,7 @@ void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||||
int x = i * 16;
|
int x = i * 16;
|
||||||
int y = j * 16;
|
int y = j * 16;
|
||||||
int index = j * map->selected_metatiles_width + i;
|
int index = j * map->selected_metatiles_width + i;
|
||||||
QImage metatile_image = Metatile::getMetatileImage(map->selected_metatiles->at(index), map->layout->tileset_primary, map->layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(map->selected_metatiles->at(index), map->layout->tileset_primary, map->layout->tileset_secondary);
|
||||||
QPoint metatile_origin = QPoint(x, y);
|
QPoint metatile_origin = QPoint(x, y);
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
}
|
}
|
||||||
|
@ -1005,42 +1018,6 @@ void CurrentSelectedMetatilesPixmapItem::draw() {
|
||||||
setPixmap(QPixmap::fromImage(image));
|
setPixmap(QPixmap::fromImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovementPermissionsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
|
||||||
QPointF pos = event->pos();
|
|
||||||
int x = static_cast<int>(pos.x()) / 32;
|
|
||||||
int y = static_cast<int>(pos.y()) / 32;
|
|
||||||
int width = pixmap().width() / 32;
|
|
||||||
int height = pixmap().height() / 32;
|
|
||||||
|
|
||||||
// Snap to a valid position inside the selection area.
|
|
||||||
if (x < 0) x = 0;
|
|
||||||
if (x >= width) x = width - 1;
|
|
||||||
if (y < 0) y = 0;
|
|
||||||
if (y >= height) y = height - 1;
|
|
||||||
pick(static_cast<uint16_t>(x), static_cast<uint16_t>(y));
|
|
||||||
}
|
|
||||||
void MovementPermissionsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
|
|
||||||
updateCurHoveredMetatile(event->pos());
|
|
||||||
mousePressEvent(event);
|
|
||||||
}
|
|
||||||
void MovementPermissionsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
|
|
||||||
mousePressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MovementPermissionsPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
|
||||||
int x = static_cast<int>(pos.x()) / 32;
|
|
||||||
int y = static_cast<int>(pos.y()) / 32;
|
|
||||||
int width = pixmap().width() / 32;
|
|
||||||
int height = pixmap().height() / 32;
|
|
||||||
|
|
||||||
// Snap to a valid position inside the selection area.
|
|
||||||
if (x < 0) x = 0;
|
|
||||||
if (x >= width) x = width - 1;
|
|
||||||
if (y < 0) y = 0;
|
|
||||||
if (y >= height) y = height - 1;
|
|
||||||
map->hoveredMovementPermissionTileChanged(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ConnectionPixmapItem::getMinOffset() {
|
int ConnectionPixmapItem::getMinOffset() {
|
||||||
if (connection->direction == "up" || connection->direction == "down")
|
if (connection->direction == "up" || connection->direction == "down")
|
||||||
return 1 - (this->pixmap().width() / 16);
|
return 1 - (this->pixmap().width() / 16);
|
||||||
|
@ -1608,8 +1585,8 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
if (block) {
|
if (block) {
|
||||||
block->collision = map->paint_collision;
|
block->collision = editor->movement_permissions_selector_item->getSelectedCollision();
|
||||||
block->elevation = map->paint_elevation;
|
block->elevation = editor->movement_permissions_selector_item->getSelectedElevation();
|
||||||
map->_setBlock(x, y, *block);
|
map->_setBlock(x, y, *block);
|
||||||
}
|
}
|
||||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
@ -1624,7 +1601,9 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||||
QPointF pos = event->pos();
|
QPointF pos = event->pos();
|
||||||
int x = static_cast<int>(pos.x()) / 16;
|
int x = static_cast<int>(pos.x()) / 16;
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
map->floodFillCollisionElevation(x, y, map->paint_collision, map->paint_elevation);
|
uint16_t collision = editor->movement_permissions_selector_item->getSelectedCollision();
|
||||||
|
uint16_t elevation = editor->movement_permissions_selector_item->getSelectedElevation();
|
||||||
|
map->floodFillCollisionElevation(x, y, collision, elevation);
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1635,8 +1614,7 @@ void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
||||||
int y = static_cast<int>(pos.y()) / 16;
|
int y = static_cast<int>(pos.y()) / 16;
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
if (block) {
|
if (block) {
|
||||||
map->paint_collision = block->collision;
|
editor->movement_permissions_selector_item->select(block->collision, block->elevation);
|
||||||
map->paint_elevation = block->elevation;
|
|
||||||
emit map->paintCollisionChanged(map);
|
emit map->paintCollisionChanged(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1653,9 +1631,8 @@ void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseE
|
||||||
if (y >= map->getHeight()) y = map->getHeight() - 1;
|
if (y >= map->getHeight()) y = map->getHeight() - 1;
|
||||||
|
|
||||||
Block *block = map->getBlock(x, y);
|
Block *block = map->getBlock(x, y);
|
||||||
map->paint_collision = block->collision;
|
editor->movement_permissions_selector_item->select(block->collision, block->elevation);
|
||||||
map->paint_elevation = block->elevation;
|
editor->movement_permissions_selector_item->draw();
|
||||||
editor->collision_metatiles_item->draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
|
|
31
editor.h
31
editor.h
|
@ -9,6 +9,7 @@
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
|
|
||||||
|
#include "ui/movementpermissionsselector.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
@ -19,7 +20,6 @@ class ConnectionPixmapItem;
|
||||||
class MetatilesPixmapItem;
|
class MetatilesPixmapItem;
|
||||||
class BorderMetatilesPixmapItem;
|
class BorderMetatilesPixmapItem;
|
||||||
class CurrentSelectedMetatilesPixmapItem;
|
class CurrentSelectedMetatilesPixmapItem;
|
||||||
class MovementPermissionsPixmapItem;
|
|
||||||
|
|
||||||
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
|
|
||||||
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
|
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
|
||||||
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = nullptr;
|
CurrentSelectedMetatilesPixmapItem *scene_current_metatile_selection_item = nullptr;
|
||||||
MovementPermissionsPixmapItem *collision_metatiles_item = nullptr;
|
MovementPermissionsSelector *movement_permissions_selector_item = nullptr;
|
||||||
|
|
||||||
QList<DraggablePixmapItem*> *events = nullptr;
|
QList<DraggablePixmapItem*> *events = nullptr;
|
||||||
QList<DraggablePixmapItem*> *selected_events = nullptr;
|
QList<DraggablePixmapItem*> *selected_events = nullptr;
|
||||||
|
@ -149,6 +149,8 @@ private slots:
|
||||||
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
||||||
void onConnectionDirectionChanged(QString newDirection);
|
void onConnectionDirectionChanged(QString newDirection);
|
||||||
void onBorderMetatilesChanged();
|
void onBorderMetatilesChanged();
|
||||||
|
void onHoveredMovementPermissionChanged(uint16_t, uint16_t);
|
||||||
|
void onHoveredMovementPermissionCleared();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void objectsChanged();
|
void objectsChanged();
|
||||||
|
@ -409,29 +411,4 @@ public:
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MovementPermissionsPixmapItem : public MetatilesPixmapItem {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
MovementPermissionsPixmapItem(Map *map_): MetatilesPixmapItem(map_) {
|
|
||||||
connect(map, SIGNAL(paintCollisionChanged(Map*)), this, SLOT(paintCollisionChanged(Map *)));
|
|
||||||
}
|
|
||||||
virtual void pick(uint16_t collision, uint16_t elevation) {
|
|
||||||
map->paint_collision = collision;
|
|
||||||
map->paint_elevation = elevation;
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
virtual void draw() {
|
|
||||||
setPixmap(map->renderCollisionMetatiles());
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
||||||
virtual void updateCurHoveredMetatile(QPointF pos);
|
|
||||||
private slots:
|
|
||||||
void paintCollisionChanged(Map *) {
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EDITOR_H
|
#endif // EDITOR_H
|
||||||
|
|
2
event.h
2
event.h
|
@ -1,7 +1,7 @@
|
||||||
#ifndef EVENT_H
|
#ifndef EVENT_H
|
||||||
#define EVENT_H
|
#define EVENT_H
|
||||||
|
|
||||||
#include "heallocation.h"
|
#include "core/heallocation.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
|
@ -205,7 +205,7 @@ void MainWindow::redrawMapScene()
|
||||||
|
|
||||||
ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
|
ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
|
||||||
//ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
|
//ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
|
||||||
ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2);
|
ui->graphicsView_Collision->setFixedSize(editor->movement_permissions_selector_item->pixmap().width() + 2, editor->movement_permissions_selector_item->pixmap().height() + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
|
void MainWindow::openWarpMap(QString map_name, QString warp_num) {
|
||||||
|
|
27
map.cpp
27
map.cpp
|
@ -11,8 +11,6 @@
|
||||||
Map::Map(QObject *parent) : QObject(parent)
|
Map::Map(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
paint_tile_index = 1;
|
paint_tile_index = 1;
|
||||||
paint_collision = 0;
|
|
||||||
paint_elevation = 3;
|
|
||||||
selected_metatiles_width = 1;
|
selected_metatiles_width = 1;
|
||||||
selected_metatiles_height = 1;
|
selected_metatiles_height = 1;
|
||||||
selected_metatiles = new QList<uint16_t>;
|
selected_metatiles = new QList<uint16_t>;
|
||||||
|
@ -165,7 +163,7 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = layout->blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
QImage collision_metatile_image = getCollisionMetatileImage(block);
|
||||||
int map_y = width_ ? i / width_ : 0;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = width_ ? i % width_ : 0;
|
int map_x = width_ ? i % width_ : 0;
|
||||||
|
@ -209,7 +207,7 @@ QPixmap Map::render(bool ignoreCache = false) {
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = layout->blockdata->blocks->value(i);
|
Block block = layout->blockdata->blocks->value(i);
|
||||||
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
int map_y = width_ ? i / width_ : 0;
|
int map_y = width_ ? i / width_ : 0;
|
||||||
int map_x = width_ ? i % width_ : 0;
|
int map_x = width_ ? i % width_ : 0;
|
||||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||||
|
@ -243,7 +241,7 @@ QPixmap Map::renderBorder() {
|
||||||
}
|
}
|
||||||
changed_any = true;
|
changed_any = true;
|
||||||
Block block = layout->border->blocks->value(i);
|
Block block = layout->border->blocks->value(i);
|
||||||
QImage metatile_image = Metatile::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(block.tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
int map_y = i / width_;
|
int map_y = i / width_;
|
||||||
int map_x = i % width_;
|
int map_x = i % width_;
|
||||||
painter.drawImage(QPoint(map_x * 16, map_y * 16), metatile_image);
|
painter.drawImage(QPoint(map_x * 16, map_y * 16), metatile_image);
|
||||||
|
@ -291,23 +289,6 @@ QPixmap Map::renderConnection(Connection connection) {
|
||||||
return QPixmap::fromImage(connection_image);
|
return QPixmap::fromImage(connection_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderCollisionMetatiles() {
|
|
||||||
int width_ = 2;
|
|
||||||
int height_ = 16;
|
|
||||||
QImage image(width_ * 32, height_ * 32, QImage::Format_RGBA8888);
|
|
||||||
QPainter painter(&image);
|
|
||||||
for (int i = 0; i < width_; i++) {
|
|
||||||
for (int j = 0; j < height_; j++) {
|
|
||||||
QPoint origin(i * 32, j * 32);
|
|
||||||
QImage metatile_image = getCollisionMetatileImage(i, j).scaled(32, 32);
|
|
||||||
painter.drawImage(origin, metatile_image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
drawSelection(paint_collision + paint_elevation * width_, width_, 1, 1, &painter, 32);
|
|
||||||
painter.end();
|
|
||||||
return QPixmap::fromImage(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth) {
|
void Map::drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth) {
|
||||||
int x = i % w;
|
int x = i % w;
|
||||||
int y = i / w;
|
int y = i / w;
|
||||||
|
@ -340,7 +321,7 @@ QPixmap Map::renderMetatiles() {
|
||||||
if (i >= primary_length) {
|
if (i >= primary_length) {
|
||||||
tile += Project::getNumMetatilesPrimary() - primary_length;
|
tile += Project::getNumMetatilesPrimary() - primary_length;
|
||||||
}
|
}
|
||||||
QImage metatile_image = Metatile::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
|
QImage metatile_image = Tileset::getMetatileImage(tile, layout->tileset_primary, layout->tileset_secondary);
|
||||||
int map_y = i / width_;
|
int map_y = i / width_;
|
||||||
int map_x = i % width_;
|
int map_x = i % width_;
|
||||||
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
|
||||||
|
|
9
map.h
9
map.h
|
@ -1,8 +1,8 @@
|
||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|
||||||
#include "tileset.h"
|
#include "core/tileset.h"
|
||||||
#include "blockdata.h"
|
#include "core/blockdata.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
@ -165,7 +165,6 @@ public:
|
||||||
QPixmap collision_pixmap;
|
QPixmap collision_pixmap;
|
||||||
QImage getCollisionMetatileImage(Block);
|
QImage getCollisionMetatileImage(Block);
|
||||||
QImage getCollisionMetatileImage(int, int);
|
QImage getCollisionMetatileImage(int, int);
|
||||||
QPixmap renderCollisionMetatiles();
|
|
||||||
|
|
||||||
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth);
|
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth);
|
||||||
|
|
||||||
|
@ -186,8 +185,6 @@ public:
|
||||||
int selected_metatiles_width;
|
int selected_metatiles_width;
|
||||||
int selected_metatiles_height;
|
int selected_metatiles_height;
|
||||||
QList<uint16_t> *selected_metatiles = nullptr;
|
QList<uint16_t> *selected_metatiles = nullptr;
|
||||||
uint16_t paint_collision;
|
|
||||||
uint16_t paint_elevation;
|
|
||||||
|
|
||||||
Block *getBlock(int x, int y);
|
Block *getBlock(int x, int y);
|
||||||
void setBlock(int x, int y, Block block);
|
void setBlock(int x, int y, Block block);
|
||||||
|
@ -219,7 +216,6 @@ public:
|
||||||
void clearHoveredTile();
|
void clearHoveredTile();
|
||||||
void hoveredMetatileChanged(int block);
|
void hoveredMetatileChanged(int block);
|
||||||
void clearHoveredMetatile();
|
void clearHoveredMetatile();
|
||||||
void hoveredMovementPermissionTileChanged(int collision, int elevation);
|
|
||||||
void clearHoveredMovementPermissionTile();
|
void clearHoveredMovementPermissionTile();
|
||||||
void setSelectedMetatilesFromTilePicker();
|
void setSelectedMetatilesFromTilePicker();
|
||||||
|
|
||||||
|
@ -231,6 +227,7 @@ signals:
|
||||||
void statusBarMessage(QString);
|
void statusBarMessage(QString);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void hoveredMovementPermissionTileChanged(int collision, int elevation);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_H
|
#endif // MAP_H
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef PARSEUTIL_H
|
#ifndef PARSEUTIL_H
|
||||||
#define PARSEUTIL_H
|
#define PARSEUTIL_H
|
||||||
|
|
||||||
#include "heallocation.h"
|
#include "core/heallocation.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
52
porymap.pro
52
porymap.pro
|
@ -14,40 +14,46 @@ RC_ICONS = resources/icons/porymap-icon-1.ico
|
||||||
ICON = resources/icons/porymap-icon-1.ico
|
ICON = resources/icons/porymap-icon-1.ico
|
||||||
|
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
SOURCES += core/block.cpp \
|
||||||
mainwindow.cpp \
|
core/blockdata.cpp \
|
||||||
project.cpp \
|
core/heallocation.cpp \
|
||||||
map.cpp \
|
core/metatile.cpp \
|
||||||
blockdata.cpp \
|
core/tile.cpp \
|
||||||
block.cpp \
|
core/tileset.cpp \
|
||||||
tileset.cpp \
|
ui/movementpermissionsselector.cpp \
|
||||||
tile.cpp \
|
ui/selectablepixmapitem.cpp \
|
||||||
event.cpp \
|
|
||||||
editor.cpp \
|
editor.cpp \
|
||||||
objectpropertiesframe.cpp \
|
event.cpp \
|
||||||
graphicsview.cpp \
|
graphicsview.cpp \
|
||||||
parseutil.cpp \
|
main.cpp \
|
||||||
|
mainwindow.cpp \
|
||||||
|
map.cpp \
|
||||||
neweventtoolbutton.cpp \
|
neweventtoolbutton.cpp \
|
||||||
noscrollcombobox.cpp \
|
noscrollcombobox.cpp \
|
||||||
noscrollspinbox.cpp \
|
noscrollspinbox.cpp \
|
||||||
heallocation.cpp
|
objectpropertiesframe.cpp \
|
||||||
|
parseutil.cpp \
|
||||||
|
project.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += core/block.h \
|
||||||
project.h \
|
core/blockdata.h \
|
||||||
map.h \
|
core/heallocation.h \
|
||||||
blockdata.h \
|
core/metatile.h \
|
||||||
block.h \
|
core/tile.h \
|
||||||
tileset.h \
|
core/tileset.h \
|
||||||
tile.h \
|
ui/movementpermissionsselector.h \
|
||||||
event.h \
|
ui/selectablepixmapitem.h \
|
||||||
editor.h \
|
editor.h \
|
||||||
objectpropertiesframe.h \
|
event.h \
|
||||||
graphicsview.h \
|
graphicsview.h \
|
||||||
parseutil.h \
|
mainwindow.h \
|
||||||
|
map.h \
|
||||||
neweventtoolbutton.h \
|
neweventtoolbutton.h \
|
||||||
noscrollcombobox.h \
|
noscrollcombobox.h \
|
||||||
noscrollspinbox.h \
|
noscrollspinbox.h \
|
||||||
heallocation.h
|
objectpropertiesframe.h \
|
||||||
|
parseutil.h \
|
||||||
|
project.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
objectpropertiesframe.ui
|
objectpropertiesframe.ui
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "parseutil.h"
|
#include "parseutil.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "tile.h"
|
#include "core/tile.h"
|
||||||
#include "tileset.h"
|
#include "core/tileset.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -849,11 +849,6 @@ void Project::loadTilesetAssets(Tileset* tileset) {
|
||||||
if (num_metatiles > num_metatileAttrs)
|
if (num_metatiles > num_metatileAttrs)
|
||||||
num_metatiles = num_metatileAttrs;
|
num_metatiles = num_metatileAttrs;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < num_metatiles; i++) {
|
|
||||||
uint16_t word = data[i*2] & 0xff;
|
|
||||||
word += (data[i*2 + 1] & 0xff) << 8;
|
|
||||||
tileset->metatiles->value(i)->attr = word;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << QString("Could not open '%1'").arg(metatile_attrs_path);
|
qDebug() << QString("Could not open '%1'").arg(metatile_attrs_path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define PROJECT_H
|
#define PROJECT_H
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "blockdata.h"
|
#include "core/blockdata.h"
|
||||||
#include "heallocation.h"
|
#include "core/heallocation.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
6
tile.cpp
6
tile.cpp
|
@ -1,6 +0,0 @@
|
||||||
#include "tile.h"
|
|
||||||
|
|
||||||
Tile::Tile()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
59
ui/movementpermissionsselector.cpp
Normal file
59
ui/movementpermissionsselector.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include "movementpermissionsselector.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::draw() {
|
||||||
|
QPixmap pixmap(":/images/collisions.png");
|
||||||
|
this->setPixmap(pixmap.scaled(64, 512));
|
||||||
|
this->drawSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t MovementPermissionsSelector::getSelectedCollision() {
|
||||||
|
return static_cast<uint16_t>(this->selectionInitialX);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t MovementPermissionsSelector::getSelectedElevation() {
|
||||||
|
return static_cast<uint16_t>(this->selectionInitialY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::select(uint16_t collision, uint16_t elevation) {
|
||||||
|
SelectablePixmapItem::select(collision, elevation, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
|
SelectablePixmapItem::mousePressEvent(event);
|
||||||
|
this->setSelectedMovementPermissions(event->pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
|
SelectablePixmapItem::mouseMoveEvent(event);
|
||||||
|
this->setSelectedMovementPermissions(event->pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
|
||||||
|
SelectablePixmapItem::mouseReleaseEvent(event);
|
||||||
|
this->setSelectedMovementPermissions(event->pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::setSelectedMovementPermissions(QPointF pos) {
|
||||||
|
int x = static_cast<int>(pos.x()) / 32;
|
||||||
|
int y = static_cast<int>(pos.y()) / 32;
|
||||||
|
int width = this->pixmap().width() / 32;
|
||||||
|
int height = this->pixmap().height() / 32;
|
||||||
|
|
||||||
|
// Snap to a valid position inside the selection area.
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (x >= width) x = width - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (y >= height) y = height - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
uint16_t collision = static_cast<uint16_t>(pos.x());
|
||||||
|
uint16_t elevation = static_cast<uint16_t>(pos.y());
|
||||||
|
emit this->hoveredMovementPermissionChanged(collision, elevation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MovementPermissionsSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
||||||
|
emit this->hoveredMovementPermissionCleared();
|
||||||
|
}
|
32
ui/movementpermissionsselector.h
Normal file
32
ui/movementpermissionsselector.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef MOVEMENTPERMISSIONSSELECTOR_H
|
||||||
|
#define MOVEMENTPERMISSIONSSELECTOR_H
|
||||||
|
|
||||||
|
#include "selectablepixmapitem.h"
|
||||||
|
|
||||||
|
class MovementPermissionsSelector: public SelectablePixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MovementPermissionsSelector(): SelectablePixmapItem(32, 32, 1, 1) {
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
}
|
||||||
|
void draw();
|
||||||
|
uint16_t getSelectedCollision();
|
||||||
|
uint16_t getSelectedElevation();
|
||||||
|
void select(uint16_t collision, uint16_t elevation);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setSelectedMovementPermissions(QPointF);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hoveredMovementPermissionChanged(uint16_t, uint16_t);
|
||||||
|
void hoveredMovementPermissionCleared();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MOVEMENTPERMISSIONSSELECTOR_H
|
100
ui/selectablepixmapitem.cpp
Normal file
100
ui/selectablepixmapitem.cpp
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#include "selectablepixmapitem.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
QPoint SelectablePixmapItem::getSelectionDimensions()
|
||||||
|
{
|
||||||
|
return QPoint(abs(this->selectionOffsetX) + 1, abs(this->selectionOffsetY) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint SelectablePixmapItem::getSelectionStart()
|
||||||
|
{
|
||||||
|
return QPoint(this->selectionInitialX + this->selectionOffsetX,
|
||||||
|
this->selectionInitialY + this->selectionOffsetY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::select(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
this->selectionInitialX = x;
|
||||||
|
this->selectionInitialY = y;
|
||||||
|
this->selectionOffsetX = qMax(0, qMin(width, this->maxSelectionWidth));
|
||||||
|
this->selectionOffsetY = qMax(0, qMin(height, this->maxSelectionHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
this->selectionInitialX = pos.x();
|
||||||
|
this->selectionInitialY = pos.y();
|
||||||
|
this->selectionOffsetX = 0;
|
||||||
|
this->selectionOffsetY = 0;
|
||||||
|
this->updateSelection(pos.x(), pos.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
this->updateSelection(pos.x(), pos.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
this->updateSelection(pos.x(), pos.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::updateSelection(int x, int y)
|
||||||
|
{
|
||||||
|
// Snap to a valid position inside the selection area.
|
||||||
|
int width = pixmap().width() / this->cellWidth;
|
||||||
|
int height = pixmap().height() / this->cellHeight;
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (x >= width) x = width - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (y >= height) y = height - 1;
|
||||||
|
|
||||||
|
this->selectionOffsetX = x - this->selectionInitialX;
|
||||||
|
this->selectionOffsetY = y - this->selectionInitialY;
|
||||||
|
|
||||||
|
// Respect max selection dimensions by moving the selection's origin.
|
||||||
|
if (this->selectionOffsetX >= this->maxSelectionWidth) {
|
||||||
|
this->selectionInitialX += this->selectionOffsetX - this->maxSelectionWidth + 1;
|
||||||
|
this->selectionOffsetX = this->maxSelectionWidth - 1;
|
||||||
|
} else if (this->selectionOffsetX <= -this->maxSelectionWidth) {
|
||||||
|
this->selectionInitialX += this->selectionOffsetX + this->maxSelectionWidth - 1;
|
||||||
|
this->selectionOffsetX = -this->maxSelectionWidth + 1;
|
||||||
|
}
|
||||||
|
if (this->selectionOffsetY >= this->maxSelectionHeight) {
|
||||||
|
this->selectionInitialY += this->selectionOffsetY - this->maxSelectionHeight + 1;
|
||||||
|
this->selectionOffsetY = this->maxSelectionHeight - 1;
|
||||||
|
} else if (this->selectionOffsetY <= -this->maxSelectionHeight) {
|
||||||
|
this->selectionInitialY += this->selectionOffsetY + this->maxSelectionHeight - 1;
|
||||||
|
this->selectionOffsetY = -this->maxSelectionHeight + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint SelectablePixmapItem::getCellPos(QPointF pos)
|
||||||
|
{
|
||||||
|
return QPoint(static_cast<int>(pos.x()) / this->cellWidth,
|
||||||
|
static_cast<int>(pos.y()) / this->cellHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectablePixmapItem::drawSelection()
|
||||||
|
{
|
||||||
|
QPixmap pixmap = this->pixmap();
|
||||||
|
QPainter painter(&pixmap);
|
||||||
|
QPoint origin = this->getSelectionStart();
|
||||||
|
QPoint dimensions = this->getSelectionDimensions();
|
||||||
|
|
||||||
|
int rectWidth = dimensions.x() * this->cellWidth;
|
||||||
|
int rectHeight = dimensions.y() * this->cellHeight;
|
||||||
|
|
||||||
|
painter.setPen(QColor(0xff, 0xff, 0xff));
|
||||||
|
painter.drawRect(origin.x() * this->cellWidth, origin.y() * this->cellHeight, rectWidth - 1, rectHeight -1);
|
||||||
|
painter.setPen(QColor(0, 0, 0));
|
||||||
|
painter.drawRect(origin.x() * this->cellWidth - 1, origin.y() * this->cellHeight - 1, rectWidth + 1, rectHeight + 1);
|
||||||
|
painter.drawRect(origin.x() * this->cellWidth + 1, origin.y() * this->cellHeight + 1, rectWidth - 3, rectHeight - 3);
|
||||||
|
|
||||||
|
this->setPixmap(pixmap);
|
||||||
|
}
|
39
ui/selectablepixmapitem.h
Normal file
39
ui/selectablepixmapitem.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef SELECTABLEPIXMAPITEM_H
|
||||||
|
#define SELECTABLEPIXMAPITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
|
class SelectablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SelectablePixmapItem(int cellWidth, int cellHeight, int maxSelectionWidth, int maxSelectionHeight) {
|
||||||
|
this->cellWidth = cellWidth;
|
||||||
|
this->cellHeight = cellHeight;
|
||||||
|
this->maxSelectionWidth = maxSelectionWidth;
|
||||||
|
this->maxSelectionHeight = maxSelectionHeight;
|
||||||
|
}
|
||||||
|
QPoint getSelectionDimensions();
|
||||||
|
QPoint getSelectionStart();
|
||||||
|
virtual void draw() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int cellWidth;
|
||||||
|
int cellHeight;
|
||||||
|
int maxSelectionWidth;
|
||||||
|
int maxSelectionHeight;
|
||||||
|
int selectionInitialX;
|
||||||
|
int selectionInitialY;
|
||||||
|
int selectionOffsetX;
|
||||||
|
int selectionOffsetY;
|
||||||
|
|
||||||
|
void select(int, int, int, int);
|
||||||
|
void updateSelection(int, int);
|
||||||
|
QPoint getCellPos(QPointF);
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||||
|
virtual void drawSelection();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SELECTABLEPIXMAPITEM_H
|
Loading…
Reference in a new issue