Compare commits

...

4 commits

Author SHA1 Message Date
Marcus Huderle
3ad9af34a6 Add stamp layer buttons 2023-03-12 17:21:56 -05:00
Marcus Huderle
95a1da1930 First stab at generating metatiles 2023-03-01 17:57:11 -06:00
Marcus Huderle
23747d9822 Better handling of generic PaintSelection, and accurate selection cursor size 2023-02-28 16:23:10 -06:00
Marcus Huderle
64004a68f2 Bootstrap stamping 2023-02-28 10:21:08 -06:00
25 changed files with 818 additions and 181 deletions

View file

@ -14,7 +14,7 @@
<string>porymap</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout_15">
<layout class="QGridLayout" name="gridLayout_8">
<property name="leftMargin">
<number>9</number>
</property>
@ -645,7 +645,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab_blocks">
<property name="sizePolicy">
@ -813,8 +813,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>74</height>
<width>428</width>
<height>77</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
@ -1001,10 +1001,10 @@
</property>
<property name="geometry">
<rect>
<x>8</x>
<x>0</x>
<y>0</y>
<width>411</width>
<height>413</height>
<height>449</height>
</rect>
</property>
<property name="sizePolicy">
@ -1155,7 +1155,7 @@
<x>0</x>
<y>0</y>
<width>428</width>
<height>696</height>
<height>704</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -1258,6 +1258,231 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_stamps">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>Stamps</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_stamps">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Edit Stamps</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_stampLayer">
<property name="title">
<string>Stamp Layer</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QRadioButton" name="radioButton_stampTopLayer">
<property name="text">
<string>Top Layer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_stampLayer</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_stampBottomLayer">
<property name="text">
<string>Bottom Layer</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_stampLayer</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Selection</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_7">
<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="QGraphicsView" name="graphicsView_stampSelection">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QScrollArea" name="scrollArea_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>392</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="2" column="0">
<spacer name="horizontalSpacer_4">
<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 row="2" column="2">
<spacer name="horizontalSpacer_5">
<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 row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QGraphicsView" name="graphicsView_Stamps">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_prefabs">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -1615,8 +1840,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1709,8 +1934,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1803,8 +2028,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1903,8 +2128,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -1997,8 +2222,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -2051,8 +2276,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>625</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">
@ -2388,7 +2613,7 @@
<string>Custom fields will be added to the map.json file for the current map.</string>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
@ -2947,7 +3172,7 @@
<x>0</x>
<y>0</y>
<width>1287</width>
<height>22</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -3360,4 +3585,7 @@
<include location="../resources/images.qrc"/>
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup_stampLayer"/>
</buttongroups>
</ui>

11
include/core/stamp.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef STAMP_H
#define STAMP_H
class Stamp
{
public:
Stamp();
};
#endif // STAMP_H

View file

@ -13,6 +13,7 @@
#include "mapconnection.h"
#include "metatileselector.h"
#include "stampselector.h"
#include "movementpermissionsselector.h"
#include "project.h"
#include "ui_mainwindow.h"
@ -54,6 +55,7 @@ public:
void saveEncounterTabData();
bool displayMap();
void displayMetatileSelector();
void displayStampSelector();
void displayMapMetatiles();
void displayMapMovementPermissions();
void displayBorderMetatiles();
@ -127,6 +129,9 @@ public:
QGraphicsScene *scene_elevation_metatiles = nullptr;
MetatileSelector *metatile_selector_item = nullptr;
QGraphicsScene *scene_stamps = nullptr;
StampSelector *stamp_selector_item = nullptr;
BorderMetatilesPixmapItem *selected_border_metatiles_item = nullptr;
CurrentSelectedMetatilesPixmapItem *current_metatile_selection_item = nullptr;
MovementPermissionsSelector *movement_permissions_selector_item = nullptr;
@ -151,6 +156,7 @@ public:
void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const;
bool eventLimitReached(Event::Type type);
StampLayer getSelectedStampLayer();
public slots:
void openMapScripts() const;
@ -159,6 +165,8 @@ public slots:
void maskNonVisibleConnectionTiles();
void onBorderMetatilesChanged();
void selectedEventIndexChanged(int index, Event::Group eventGroup);
void onSelectedMetatilesChanged();
void onSelectedStampsChanged();
private:
void setConnectionItemsVisible(bool);
@ -202,7 +210,6 @@ private slots:
void onHoveredMapMetatileCleared();
void onHoveredMapMovementPermissionChanged(int, int);
void onHoveredMapMovementPermissionCleared();
void onSelectedMetatilesChanged();
void onWheelZoom(int);
void onToggleGridClicked(bool);

View file

@ -2,6 +2,7 @@
#define COLLISIONPIXMAPITEM_H
#include "metatileselector.h"
//#include "stampselector.h"
#include "movementpermissionsselector.h"
#include "mappixmapitem.h"
#include "map.h"
@ -10,8 +11,14 @@
class CollisionPixmapItem : public MapPixmapItem {
Q_OBJECT
public:
CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity)
: MapPixmapItem(map, metatileSelector, settings){
CollisionPixmapItem(Map *map,
MovementPermissionsSelector *movementPermissionsSelector,
MetatileSelector *metatileSelector,
StampSelector *stampSelector,
Settings *settings,
qreal *opacity,
std::function<PaintType(void)> getActivePaintType)
: MapPixmapItem(map, metatileSelector, stampSelector, settings, getActivePaintType){
this->movementPermissionsSelector = movementPermissionsSelector;
this->opacity = opacity;
map->setCollisionItem(this);

View file

@ -18,6 +18,6 @@ public:
void setMap(Map *map) { this->map = map; }
};
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map);
QPixmap drawMetatileSelection(MetatileSelection *selection, Map *map);
#endif // CURRENTSELECTEDMETATILESPIXMAPITEM_H

View file

@ -4,8 +4,14 @@
#include "map.h"
#include "settings.h"
#include "metatileselector.h"
#include "stampselector.h"
#include <QGraphicsPixmapItem>
enum PaintType {
PaintTypeMetatile,
PaintTypeStamp,
};
class MapPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
@ -18,10 +24,12 @@ public:
Metatiles,
EventObjects
};
MapPixmapItem(Map *map_, MetatileSelector *metatileSelector, Settings *settings) {
MapPixmapItem(Map *map_, MetatileSelector *metatileSelector, StampSelector *stampSelector, Settings *settings, std::function<PaintType(void)> getActivePaintType) {
this->map = map_;
this->map->setMapItem(this);
this->metatileSelector = metatileSelector;
this->stampSelector = stampSelector;
this->getActivePaintType = getActivePaintType;
this->settings = settings;
this->paintingMode = PaintMode::Metatiles;
this->lockedAxis = MapPixmapItem::Axis::None;
@ -31,6 +39,8 @@ public:
MapPixmapItem::PaintMode paintingMode;
Map *map;
MetatileSelector *metatileSelector;
StampSelector *stampSelector;
std::function<PaintType(void)> getActivePaintType;
Settings *settings;
bool active;
bool has_mouse = false;
@ -49,7 +59,7 @@ public:
MapPixmapItem::Axis lockedAxis;
QPoint selection_origin;
QList<QPoint> selection;
virtual void paint(QGraphicsSceneMouseEvent*);
virtual void paint(QGraphicsSceneMouseEvent*, StampLayer stampLayer);
virtual void floodFill(QGraphicsSceneMouseEvent*);
virtual void magicFill(QGraphicsSceneMouseEvent*);
void magicFill(int x, int y, uint16_t metatileId, bool fromScriptCall = false);
@ -76,11 +86,12 @@ public:
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
virtual void draw(bool ignoreCache = false);
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
void paintNormal(int x, int y, bool fromScriptCall = false);
void paintNormal(int x, int y, StampLayer stampLayer, bool fromScriptCall = false);
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
QPoint adjustCoords(QPoint pos);
private:
PaintSelection* getActiveSelection();
void paintSmartPath(int x, int y, bool fromScriptCall = false);
static QList<int> smartPathTable;

View file

@ -6,27 +6,7 @@
#include "map.h"
#include "tileset.h"
#include "maplayout.h"
struct MetatileSelectionItem
{
bool enabled;
uint16_t metatileId;
};
struct CollisionSelectionItem
{
bool enabled;
uint16_t collision;
uint16_t elevation;
};
struct MetatileSelection
{
QPoint dimensions;
bool hasCollision;
QList<MetatileSelectionItem> metatileItems;
QList<CollisionSelectionItem> collisionItems;
};
#include "paintselection.h"
class MetatileSelector: public SelectablePixmapItem {
Q_OBJECT
@ -38,7 +18,7 @@ public:
this->map = map;
this->primaryTileset = map->layout->tileset_primary;
this->secondaryTileset = map->layout->tileset_secondary;
this->selection = MetatileSelection{};
this->selection = new MetatileSelection();
setAcceptHoverEvents(true);
}
QPoint getSelectionDimensions();
@ -46,7 +26,7 @@ public:
bool select(uint16_t metatile);
bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
void setTilesets(Tileset*, Tileset*);
MetatileSelection getMetatileSelection();
MetatileSelection* getMetatileSelection();
void setPrefabSelection(MetatileSelection selection);
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
QPoint getMetatileIdCoordsOnWidget(uint16_t);
@ -67,14 +47,13 @@ private:
int externalSelectionWidth;
int externalSelectionHeight;
QList<uint16_t> externalSelectedMetatiles;
MetatileSelection selection;
MetatileSelection *selection;
void updateSelectedMetatiles();
void updateExternalSelectedMetatiles();
uint16_t getMetatileId(int x, int y);
QPoint getMetatileIdCoords(uint16_t);
bool shouldAcceptEvent(QGraphicsSceneMouseEvent*);
bool selectionIsValid();
signals:
void hoveredMetatileSelectionChanged(uint16_t);

View file

@ -0,0 +1,61 @@
#pragma once
#ifndef PAINTSELECTION_H
#define PAINTSELECTION_H
#include "block.h"
#include "map.h"
#include <QList>
#include <QPoint>
enum StampLayer {
STAMP_LAYER_BOTTOM,
STAMP_LAYER_MIDDLE,
STAMP_LAYER_TOP,
};
struct MetatileSelectionItem
{
bool enabled;
uint16_t metatileId;
};
struct CollisionSelectionItem
{
bool enabled;
uint16_t collision;
uint16_t elevation;
};
class PaintSelection
{
public:
QPoint dimensions;
virtual bool paintNormal(int, Block*, Map*, StampLayer stampLayer) = 0;
};
class MetatileSelection: public PaintSelection
{
public:
MetatileSelection() {}
void clone(MetatileSelection other) {
this->dimensions = other.dimensions;
this->hasCollision = other.hasCollision;
this->metatileItems = other.metatileItems;
this->collisionItems = other.collisionItems;
}
bool paintNormal(int index, Block *block, Map*, StampLayer stampLayer) override;
bool hasCollision = false;
QList<MetatileSelectionItem> metatileItems;
QList<CollisionSelectionItem> collisionItems;
};
class StampSelection: public PaintSelection
{
public:
StampSelection() {}
bool paintNormal(int index, Block *block, Map*, StampLayer stampLayer) override;
QList<uint16_t> stampIds;
};
#endif // PAINTSELECTION_H

View file

@ -21,7 +21,7 @@ class Prefab
{
public:
void initPrefabUI(MetatileSelector *selector, QWidget *prefabWidget, QLabel *emptyPrefabLabel, Map *map);
void addPrefab(MetatileSelection selection, Map *map, QString name);
void addPrefab(MetatileSelection *selection, Map *map, QString name);
void updatePrefabUi(Map *map);
void tryImportDefaultPrefabs(Map *map);

View file

@ -22,7 +22,7 @@ public:
private:
Map *map;
Ui::PrefabCreationDialog *ui;
MetatileSelection selection;
MetatileSelection *selection;
};
#endif // PREFABCREATIONDIALOG_H

View file

@ -0,0 +1,47 @@
#ifndef STAMPSELECTOR_H
#define STAMPSELECTOR_H
#include "selectablepixmapitem.h"
#include "map.h"
#include "tileset.h"
#include "maplayout.h"
#include "paintselection.h"
class StampSelector: public SelectablePixmapItem {
Q_OBJECT
public:
StampSelector(int numStampsWide, Map *map): SelectablePixmapItem(16, 16) {
this->numStampsWide = numStampsWide;
this->map = map;
this->primaryTileset = map->layout->tileset_primary;
this->secondaryTileset = map->layout->tileset_secondary;
this->selection = new StampSelection();
}
QPoint getSelectionDimensions();
void draw();
bool select(uint16_t stampId);
void setTilesets(Tileset*, Tileset*);
StampSelection* getStampSelection();
QPoint getStampIdCoordsOnWidget(uint16_t);
void setMap(Map*);
Tileset *primaryTileset;
Tileset *secondaryTileset;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
private:
int numStampsWide;
Map *map;
StampSelection *selection;
void updateSelectedStamps();
uint16_t getStampId(int x, int y);
QPoint getStampIdCoords(uint16_t);
bool shouldAcceptEvent(QGraphicsSceneMouseEvent*);
signals:
void selectedStampsChanged();
};
#endif // STAMPSELECTOR_H

View file

@ -9,6 +9,7 @@
#include "tileseteditortileselector.h"
#include "metatilelayersitem.h"
#include "map.h"
#include "metatile.h"
namespace Ui {
class TilesetEditor;

View file

@ -27,6 +27,7 @@ SOURCES += src/core/block.cpp \
src/core/metatileparser.cpp \
src/core/paletteutil.cpp \
src/core/parseutil.cpp \
src/core/stamp.cpp \
src/core/tile.cpp \
src/core/tileset.cpp \
src/core/regionmap.cpp \
@ -74,6 +75,7 @@ SOURCES += src/core/block.cpp \
src/ui/encountertabledelegates.cpp \
src/ui/paletteeditor.cpp \
src/ui/selectablepixmapitem.cpp \
src/ui/stampselector.cpp \
src/ui/tileseteditor.cpp \
src/ui/tileseteditormetatileselector.cpp \
src/ui/tileseteditortileselector.cpp \
@ -87,6 +89,7 @@ SOURCES += src/core/block.cpp \
src/ui/shortcut.cpp \
src/ui/shortcutseditor.cpp \
src/ui/multikeyedit.cpp \
src/ui/paintselection.cpp \
src/ui/prefabframe.cpp \
src/ui/preferenceeditor.cpp \
src/ui/regionmappropertiesdialog.cpp \
@ -113,6 +116,7 @@ HEADERS += include/core/block.h \
include/core/metatileparser.h \
include/core/paletteutil.h \
include/core/parseutil.h \
include/core/stamp.h \
include/core/tile.h \
include/core/tileset.h \
include/core/regionmap.h \
@ -133,6 +137,7 @@ HEADERS += include/core/block.h \
include/ui/collisionpixmapitem.h \
include/ui/connectionpixmapitem.h \
include/ui/currentselectedmetatilespixmapitem.h \
include/ui/paintselection.h \
include/ui/prefabframe.h \
include/ui/regionmaplayoutpixmapitem.h \
include/ui/regionmapentriespixmapitem.h \
@ -161,6 +166,7 @@ HEADERS += include/core/block.h \
include/ui/adjustingstackedwidget.h \
include/ui/paletteeditor.h \
include/ui/selectablepixmapitem.h \
include/ui/stampselector.h \
include/ui/tileseteditor.h \
include/ui/tileseteditormetatileselector.h \
include/ui/tileseteditortileselector.h \

6
src/core/stamp.cpp Normal file
View file

@ -0,0 +1,6 @@
#include "stamp.h"
Stamp::Stamp()
{
}

View file

@ -12,6 +12,7 @@
#include "config.h"
#include "scripting.h"
#include "customattributestable.h"
#include "mappixmapitem.h"
#include <QCheckBox>
#include <QPainter>
#include <QMouseEvent>
@ -956,6 +957,12 @@ void Editor::onSelectedMetatilesChanged() {
this->redrawCurrentMetatilesSelection();
}
void Editor::onSelectedStampsChanged() {
QPoint size = this->stamp_selector_item->getSelectionDimensions();
this->cursorMapTileRect->updateSelectionSize(size.x(), size.y());
this->redrawCurrentMetatilesSelection();
}
void Editor::onWheelZoom(int s) {
// Don't zoom the map when the user accidentally scrolls while performing a magic fill. (ctrl + middle button click)
if (!(QApplication::mouseButtons() & Qt::MiddleButton)) {
@ -1171,6 +1178,16 @@ void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) {
}
}
StampLayer Editor::getSelectedStampLayer() {
auto stampLayerButton = ui->buttonGroup_stampLayer->checkedButton();
if (stampLayerButton == ui->radioButton_stampTopLayer) {
return StampLayer::STAMP_LAYER_TOP;
} else if (stampLayerButton == ui->radioButton_stampBottomLayer) {
return StampLayer::STAMP_LAYER_BOTTOM;
}
return StampLayer::STAMP_LAYER_MIDDLE;
}
void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item) {
// TODO: add event tab object painting tool buttons stuff here
if (item->paintingMode == MapPixmapItem::PaintMode::Disabled) {
@ -1200,7 +1217,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
item->lockNondominantAxis(event);
pos = item->adjustCoords(pos);
}
item->paint(event);
item->paint(event, getSelectedStampLayer());
}
} else if (map_edit_mode == "select") {
item->select(event);
@ -1345,6 +1362,7 @@ bool Editor::displayMap() {
}
displayMetatileSelector();
displayStampSelector();
displayMovementPermissionSelector();
displayMapMetatiles();
displayMapMovementPermissions();
@ -1400,8 +1418,32 @@ void Editor::displayMetatileSelector() {
scene_metatiles->addItem(metatile_selector_item);
}
void Editor::displayStampSelector() {
if (stamp_selector_item && stamp_selector_item->scene()) {
stamp_selector_item->scene()->removeItem(stamp_selector_item);
delete scene_stamps;
}
scene_stamps = new QGraphicsScene;
if (!stamp_selector_item) {
stamp_selector_item = new StampSelector(8, map);
connect(stamp_selector_item, &StampSelector::selectedStampsChanged,
this, &Editor::onSelectedStampsChanged);
stamp_selector_item->select(0);
} else {
stamp_selector_item->setMap(map);
stamp_selector_item->setTilesets(map->layout->tileset_primary, map->layout->tileset_secondary);
}
scene_stamps->addItem(stamp_selector_item);
}
void Editor::displayMapMetatiles() {
map_item = new MapPixmapItem(map, this->metatile_selector_item, this->settings);
map_item = new MapPixmapItem(map, this->metatile_selector_item, this->stamp_selector_item, this->settings, [=](){
if (this->ui->mapViewTab->currentIndex() == 2) {
return PaintType::PaintTypeStamp;
}
return PaintType::PaintTypeMetatile;
});
connect(map_item, &MapPixmapItem::mouseEvent, this, &Editor::mouseEvent_map);
connect(map_item, &MapPixmapItem::startPaint, this, &Editor::onMapStartPaint);
connect(map_item, &MapPixmapItem::endPaint, this, &Editor::onMapEndPaint);
@ -1426,8 +1468,13 @@ void Editor::displayMapMovementPermissions() {
scene->removeItem(collision_item);
delete collision_item;
}
collision_item = new CollisionPixmapItem(map, this->movement_permissions_selector_item,
this->metatile_selector_item, this->settings, &this->collisionOpacity);
collision_item = new CollisionPixmapItem(map,
this->movement_permissions_selector_item,
this->metatile_selector_item,
this->stamp_selector_item,
this->settings,
&this->collisionOpacity,
[]() {return PaintType::PaintTypeMetatile; });
connect(collision_item, &CollisionPixmapItem::mouseEvent, this, &Editor::mouseEvent_collision);
connect(collision_item, &CollisionPixmapItem::hoveredMapMovementPermissionChanged,
this, &Editor::onHoveredMapMovementPermissionChanged);

View file

@ -696,6 +696,10 @@ void MainWindow::refreshMapScene()
ui->graphicsView_Collision->setFixedSize(editor->movement_permissions_selector_item->pixmap().width() + 2, editor->movement_permissions_selector_item->pixmap().height() + 2);
on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value());
ui->graphicsView_Stamps->setScene(editor->scene_stamps);
//ui->graphicsView_Stamps->setSceneRect(editor->scene_stamps->sceneRect());
ui->graphicsView_Stamps->setFixedSize(editor->stamp_selector_item->pixmap().width() + 2, editor->stamp_selector_item->pixmap().height() + 2);
}
void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_group) {
@ -1330,8 +1334,8 @@ void MainWindow::redrawMetatileSelection()
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
if (size.x() == 1 && size.y() == 1) {
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId);
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection->metatileItems.first().metatileId);
pos *= scale;
ui->scrollArea_2->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale);
}
@ -1341,8 +1345,8 @@ void MainWindow::currentMetatilesSelectionChanged()
{
redrawMetatileSelection();
if (this->tilesetEditor) {
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
this->tilesetEditor->selectMetatile(selection->metatileItems.first().metatileId);
}
}
@ -1415,13 +1419,13 @@ void MainWindow::copy() {
OrderedJson::object copyObject;
copyObject["object"] = "metatile_selection";
OrderedJson::array metatiles;
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
for (auto item : selection.metatileItems) {
MetatileSelection *selection = editor->metatile_selector_item->getMetatileSelection();
for (auto item : selection->metatileItems) {
metatiles.append(static_cast<int>(item.metatileId));
}
OrderedJson::array collisions;
if (selection.hasCollision) {
for (auto item : selection.collisionItems) {
if (selection->hasCollision) {
for (auto item : selection->collisionItems) {
OrderedJson::object collision;
collision["collision"] = item.collision;
collision["elevation"] = item.elevation;
@ -1669,10 +1673,16 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index)
if (index == 0) {
editor->setEditingMap();
editor->onSelectedMetatilesChanged();
} else if (index == 1) {
editor->setEditingCollision();
editor->onSelectedMetatilesChanged();
} else if (index == 2) {
editor->setEditingMap();
editor->onSelectedStampsChanged();
} else if (index == 3) {
editor->setEditingMap();
editor->onSelectedMetatilesChanged();
prefab.tryImportDefaultPrefabs(this->editor->map);
}
editor->setCursorRectVisible(false);
@ -2205,7 +2215,7 @@ void MainWindow::on_toolButton_Paint_clicked()
editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10);
// do not stop single tile mode when editing collision
if (ui->mapViewTab->currentIndex() == 0)
if (ui->mapViewTab->currentIndex() != 1)
editor->cursorMapTileRect->stopSingleTileMode();
ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
@ -2678,8 +2688,8 @@ void MainWindow::on_actionTileset_Editor_triggered()
this->tilesetEditor->activateWindow();
}
MetatileSelection selection = this->editor->metatile_selector_item->getMetatileSelection();
this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId);
MetatileSelection *selection = this->editor->metatile_selector_item->getMetatileSelection();
this->tilesetEditor->selectMetatile(selection->metatileItems.first().metatileId);
}
void MainWindow::initTilesetEditor() {

View file

@ -77,7 +77,7 @@ void MainWindow::setBlock(int x, int y, int rawValue, bool forceRedraw, bool com
void MainWindow::setBlocksFromSelection(int x, int y, bool forceRedraw, bool commitChanges) {
if (this->editor && this->editor->map_item) {
this->editor->map_item->paintNormal(x, y, true);
this->editor->map_item->paintNormal(x, y, StampLayer::STAMP_LAYER_BOTTOM, true);
this->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw);
}

View file

@ -5,16 +5,16 @@
#include <QPainter>
void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
int width = map->getBorderWidth();
int height = map->getBorderHeight();
Blockdata oldBorder = map->layout->border;
for (int i = 0; i < selection.dimensions.x() && (i + pos.x()) < width; i++) {
for (int j = 0; j < selection.dimensions.y() && (j + pos.y()) < height; j++) {
MetatileSelectionItem item = selection.metatileItems.at(j * selection.dimensions.x() + i);
for (int i = 0; i < selection->dimensions.x() && (i + pos.x()) < width; i++) {
for (int j = 0; j < selection->dimensions.y() && (j + pos.y()) < height; j++) {
MetatileSelectionItem item = selection->metatileItems.at(j * selection->dimensions.x() + i);
map->setBorderMetatileId(pos.x() + i, pos.y() + j, item.metatileId, true);
}
}

View file

@ -2,20 +2,20 @@
#include "imageproviders.h"
#include <QPainter>
QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
int width = selection.dimensions.x() * 16;
int height = selection.dimensions.y() * 16;
QPixmap drawMetatileSelection(MetatileSelection *selection, Map *map) {
int width = selection->dimensions.x() * 16;
int height = selection->dimensions.y() * 16;
QImage image(width, height, QImage::Format_RGBA8888);
image.fill(QColor(0, 0, 0, 0));
QPainter painter(&image);
for (int i = 0; i < selection.dimensions.x(); i++) {
for (int j = 0; j < selection.dimensions.y(); j++) {
for (int i = 0; i < selection->dimensions.x(); i++) {
for (int j = 0; j < selection->dimensions.y(); j++) {
int x = i * 16;
int y = j * 16;
QPoint metatile_origin = QPoint(x, y);
int index = j * selection.dimensions.x() + i;
MetatileSelectionItem item = selection.metatileItems.at(index);
int index = j * selection->dimensions.x() + i;
MetatileSelectionItem item = selection->metatileItems.at(index);
if (item.enabled) {
QImage metatile_image = getMetatileImage(
item.metatileId,
@ -33,6 +33,6 @@ QPixmap drawMetatileSelection(MetatileSelection selection, Map *map) {
}
void CurrentSelectedMetatilesPixmapItem::draw() {
MetatileSelection selection = metatileSelector->getMetatileSelection();
MetatileSelection *selection = metatileSelector->getMetatileSelection();
setPixmap(drawMetatileSelection(selection, this->map));
}

View file

@ -7,7 +7,7 @@
#define SWAP(a, b) do { if (a != b) { a ^= b; b ^= a; a ^= b; } } while (0)
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event, StampLayer stampLayer) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
actionId_++;
@ -25,18 +25,19 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
// Paint onto the map.
bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
QPoint selectionDimensions = this->metatileSelector->getSelectionDimensions();
PaintSelection *selection = this->getActiveSelection();
QPoint selectionDimensions = selection->dimensions;
if (settings->smartPathsEnabled) {
if (!shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) {
paintSmartPath(pos.x(), pos.y());
} else {
paintNormal(pos.x(), pos.y());
paintNormal(pos.x(), pos.y(), stampLayer);
}
} else {
if (shiftPressed && selectionDimensions.x() == 3 && selectionDimensions.y() == 3) {
paintSmartPath(pos.x(), pos.y());
} else {
paintNormal(pos.x(), pos.y());
paintNormal(pos.x(), pos.y(), stampLayer);
}
}
}
@ -101,41 +102,44 @@ void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
}
}
void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
PaintSelection* MapPixmapItem::getActiveSelection() {
if (this->getActivePaintType() == PaintType::PaintTypeMetatile) {
return this->metatileSelector->getMetatileSelection();
} else {
return this->stampSelector->getStampSelection();
}
}
void MapPixmapItem::paintNormal(int x, int y, StampLayer stampLayer, bool fromScriptCall) {
PaintSelection *selection = this->getActiveSelection();
int initialX = fromScriptCall ? x : this->paint_tile_initial_x;
int initialY = fromScriptCall ? y : this->paint_tile_initial_y;
int selectionWidth = selection->dimensions.x();
int selectionHeight = selection->dimensions.y();
// Snap the selected position to the top-left of the block boundary.
// This allows painting via dragging the mouse to tile the painted region.
int xDiff = x - initialX;
int yDiff = y - initialY;
if (xDiff < 0 && xDiff % selection.dimensions.x() != 0) xDiff -= selection.dimensions.x();
if (yDiff < 0 && yDiff % selection.dimensions.y() != 0) yDiff -= selection.dimensions.y();
if (xDiff < 0 && xDiff % selectionWidth != 0) xDiff -= selectionWidth;
if (yDiff < 0 && yDiff % selectionHeight != 0) yDiff -= selectionHeight;
x = initialX + (xDiff / selection.dimensions.x()) * selection.dimensions.x();
y = initialY + (yDiff / selection.dimensions.y()) * selection.dimensions.y();
x = initialX + (xDiff / selectionWidth) * selectionWidth;
y = initialY + (yDiff / selectionHeight) * selectionHeight;
// for edit history
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
for (int i = 0; i < selection.dimensions.x() && i + x < map->getWidth(); i++)
for (int j = 0; j < selection.dimensions.y() && j + y < map->getHeight(); j++) {
for (int i = 0; i < selectionWidth && i + x < map->getWidth(); i++)
for (int j = 0; j < selectionHeight && j + y < map->getHeight(); j++) {
int actualX = i + x;
int actualY = j + y;
Block block;
if (map->getBlock(actualX, actualY, &block)) {
int index = j * selection.dimensions.x() + i;
MetatileSelectionItem item = selection.metatileItems.at(index);
if (!item.enabled)
continue;
block.metatileId = item.metatileId;
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
CollisionSelectionItem collisionItem = selection.collisionItems.at(index);
block.collision = collisionItem.collision;
block.elevation = collisionItem.elevation;
int index = j * selectionWidth + i;
if (selection->paintNormal(index, &block, map, stampLayer)) {
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
}
@ -177,12 +181,12 @@ bool isSmartPathTile(QList<MetatileSelectionItem> metatileItems, uint16_t metati
return false;
}
bool isValidSmartPathSelection(MetatileSelection selection) {
if (selection.dimensions.x() != 3 || selection.dimensions.y() != 3)
bool isValidSmartPathSelection(MetatileSelection *selection) {
if (selection->dimensions.x() != 3 || selection->dimensions.y() != 3)
return false;
for (int i = 0; i < selection.metatileItems.length(); i++) {
if (!selection.metatileItems.at(i).enabled)
for (int i = 0; i < selection->metatileItems.length(); i++) {
if (!selection->metatileItems.at(i).enabled)
return false;
}
@ -190,18 +194,21 @@ bool isValidSmartPathSelection(MetatileSelection selection) {
}
void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
if (this->getActivePaintType() != PaintType::PaintTypeMetatile) {
return;
}
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
if (!isValidSmartPathSelection(selection))
return;
// Shift to the middle tile of the smart path selection.
uint16_t openTile = selection.metatileItems.at(4).metatileId;
uint16_t openTile = selection->metatileItems.at(4).metatileId;
uint16_t openTileCollision = 0;
uint16_t openTileElevation = 0;
bool setCollisions = false;
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
openTileCollision = selection.collisionItems.at(4).collision;
openTileElevation = selection.collisionItems.at(4).elevation;
if (selection->hasCollision && selection->collisionItems.length() == selection->metatileItems.length()) {
openTileCollision = selection->collisionItems.at(4).collision;
openTileElevation = selection->collisionItems.at(4).elevation;
setCollisions = true;
}
@ -240,7 +247,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
int actualX = i + x;
int actualY = j + y;
Block block;
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection->metatileItems, block.metatileId)) {
continue;
}
@ -251,18 +258,18 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
Block left;
// Get marching squares value, to determine which tile to use.
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection->metatileItems, top.metatileId))
id += 1;
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection->metatileItems, right.metatileId))
id += 2;
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection->metatileItems, bottom.metatileId))
id += 4;
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection->metatileItems, left.metatileId))
id += 8;
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
block.metatileId = selection->metatileItems.at(smartPathTable[id]).metatileId;
if (setCollisions) {
CollisionSelectionItem collisionItem = selection.collisionItems.at(smartPathTable[id]);
CollisionSelectionItem collisionItem = selection->collisionItems.at(smartPathTable[id]);
block.collision = collisionItem.collision;
block.elevation = collisionItem.elevation;
}
@ -369,11 +376,11 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
} else {
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
Block block;
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
int metatileId = selection.metatileItems.first().metatileId;
if (selection.metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
int metatileId = selection->metatileItems.first().metatileId;
if (selection->metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection.dimensions.x() == 3 && selection.dimensions.y() == 3)
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection->dimensions.x() == 3 && selection->dimensions.y() == 3)
this->floodFillSmartPath(pos.x(), pos.y());
else
this->floodFill(pos.x(), pos.y());
@ -400,8 +407,8 @@ void MapPixmapItem::magicFill(int x, int y, uint16_t metatileId, bool fromScript
}
void MapPixmapItem::magicFill(int x, int y, bool fromScriptCall) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
this->magicFill(x, y, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
this->magicFill(x, y, selection->dimensions, selection->metatileItems, selection->collisionItems, fromScriptCall);
}
void MapPixmapItem::magicFill(
@ -451,8 +458,8 @@ void MapPixmapItem::magicFill(
}
void MapPixmapItem::floodFill(int initialX, int initialY, bool fromScriptCall) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
this->floodFill(initialX, initialY, selection.dimensions, selection.metatileItems, selection.collisionItems, fromScriptCall);
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
this->floodFill(initialX, initialY, selection->dimensions, selection->metatileItems, selection->collisionItems, fromScriptCall);
}
void MapPixmapItem::floodFill(int initialX, int initialY, uint16_t metatileId, bool fromScriptCall) {
@ -526,17 +533,17 @@ void MapPixmapItem::floodFill(
}
void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScriptCall) {
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
MetatileSelection *selection = this->metatileSelector->getMetatileSelection();
if (!isValidSmartPathSelection(selection))
return;
// Shift to the middle tile of the smart path selection.
uint16_t openTile = selection.metatileItems.at(4).metatileId;
uint16_t openTile = selection->metatileItems.at(4).metatileId;
uint16_t openTileCollision = 0;
uint16_t openTileElevation = 0;
bool setCollisions = false;
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
CollisionSelectionItem item = selection.collisionItems.at(4);
if (selection->hasCollision && selection->collisionItems.length() == selection->metatileItems.length()) {
CollisionSelectionItem item = selection->collisionItems.at(4);
openTileCollision = item.collision;
openTileElevation = item.elevation;
setCollisions = true;
@ -602,37 +609,37 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
Block left;
// Get marching squares value, to determine which tile to use.
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection->metatileItems, top.metatileId))
id += 1;
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection->metatileItems, right.metatileId))
id += 2;
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection->metatileItems, bottom.metatileId))
id += 4;
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection->metatileItems, left.metatileId))
id += 8;
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
block.metatileId = selection->metatileItems.at(smartPathTable[id]).metatileId;
if (setCollisions) {
CollisionSelectionItem item = selection.collisionItems.at(smartPathTable[id]);
CollisionSelectionItem item = selection->collisionItems.at(smartPathTable[id]);
block.collision = item.collision;
block.elevation = item.elevation;
}
map->setBlock(x, y, block, !fromScriptCall);
// Visit neighbors if they are smart-path tiles, and don't revisit any.
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
todo.append(QPoint(x + 1, y));
visited.insert(x + 1 + y * map->getWidth());
}
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
todo.append(QPoint(x - 1, y));
visited.insert(x - 1 + y * map->getWidth());
}
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
todo.append(QPoint(x, y + 1));
visited.insert(x + (y + 1) * map->getWidth());
}
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection->metatileItems, block.metatileId)) {
todo.append(QPoint(x, y - 1));
visited.insert(x + (y - 1) * map->getWidth());
}

View file

@ -4,7 +4,7 @@
#include <QPainter>
QPoint MetatileSelector::getSelectionDimensions() {
return selection.dimensions;
return selection->dimensions;
}
void MetatileSelector::draw() {
@ -45,12 +45,10 @@ bool MetatileSelector::select(uint16_t metatileId) {
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
this->externalSelection = false;
this->prefabSelection = false;
this->selection = MetatileSelection{
QPoint(1, 1),
false,
QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}}),
QList<CollisionSelectionItem>(),
};
this->selection->dimensions = QPoint(1, 1);
this->selection->hasCollision = false;
this->selection->metatileItems = QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}});
this->selection->collisionItems = QList<CollisionSelectionItem>();
QPoint coords = this->getMetatileIdCoords(metatileId);
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
this->updateSelectedMetatiles();
@ -60,8 +58,8 @@ bool MetatileSelector::select(uint16_t metatileId) {
bool MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) {
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
this->select(metatileId);
this->selection.collisionItems.append(CollisionSelectionItem{true, collision, elevation});
this->selection.hasCollision = true;
this->selection->collisionItems.append(CollisionSelectionItem{true, collision, elevation});
this->selection->hasCollision = true;
return true;
}
@ -75,7 +73,7 @@ void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTi
this->draw();
}
MetatileSelection MetatileSelector::getMetatileSelection() {
MetatileSelection* MetatileSelector::getMetatileSelection() {
return selection;
}
@ -85,18 +83,18 @@ void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_
this->externalSelectionWidth = width;
this->externalSelectionHeight = height;
this->externalSelectedMetatiles.clear();
this->selection.metatileItems.clear();
this->selection.collisionItems.clear();
this->selection.hasCollision = true;
this->selection.dimensions = QPoint(width, height);
this->selection->metatileItems.clear();
this->selection->collisionItems.clear();
this->selection->hasCollision = true;
this->selection->dimensions = QPoint(width, height);
for (int i = 0; i < metatiles.length(); i++) {
auto collision = collisions.at(i);
this->selection.collisionItems.append(CollisionSelectionItem{true, collision.first, collision.second});
this->selection->collisionItems.append(CollisionSelectionItem{true, collision.first, collision.second});
uint16_t metatileId = metatiles.at(i);
this->externalSelectedMetatiles.append(metatileId);
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
metatileId = 0;
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
}
this->draw();
@ -107,7 +105,7 @@ void MetatileSelector::setPrefabSelection(MetatileSelection selection) {
this->externalSelection = false;
this->prefabSelection = true;
this->externalSelectedMetatiles.clear();
this->selection = selection;
this->selection->clone(selection);
this->draw();
emit selectedMetatilesChanged();
}
@ -152,30 +150,30 @@ void MetatileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
void MetatileSelector::updateSelectedMetatiles() {
this->externalSelection = false;
this->prefabSelection = false;
this->selection.metatileItems.clear();
this->selection.collisionItems.clear();
this->selection.hasCollision = false;
this->selection.dimensions = SelectablePixmapItem::getSelectionDimensions();
this->selection->metatileItems.clear();
this->selection->collisionItems.clear();
this->selection->hasCollision = false;
this->selection->dimensions = SelectablePixmapItem::getSelectionDimensions();
QPoint origin = this->getSelectionStart();
for (int j = 0; j < this->selection.dimensions.y(); j++) {
for (int i = 0; i < this->selection.dimensions.x(); i++) {
for (int j = 0; j < this->selection->dimensions.y(); j++) {
for (int i = 0; i < this->selection->dimensions.x(); i++) {
uint16_t metatileId = this->getMetatileId(origin.x() + i, origin.y() + j);
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
metatileId = 0;
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
}
}
emit selectedMetatilesChanged();
}
void MetatileSelector::updateExternalSelectedMetatiles() {
this->selection.metatileItems.clear();
this->selection.dimensions = QPoint(this->externalSelectionWidth, this->externalSelectionHeight);
this->selection->metatileItems.clear();
this->selection->dimensions = QPoint(this->externalSelectionWidth, this->externalSelectionHeight);
for (int i = 0; i < this->externalSelectedMetatiles.count(); ++i) {
uint16_t metatileId = this->externalSelectedMetatiles.at(i);
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset))
metatileId = 0;
this->selection.metatileItems.append(MetatileSelectionItem{true, metatileId});
this->selection->metatileItems.append(MetatileSelectionItem{true, metatileId});
}
emit selectedMetatilesChanged();
}

80
src/ui/paintselection.cpp Normal file
View file

@ -0,0 +1,80 @@
#include "paintselection.h"
#include "project.h"
#include "metatile.h"
#include "log.h"
bool MetatileSelection::paintNormal(int index, Block *block, Map *map, StampLayer stampLayer) {
MetatileSelectionItem item = this->metatileItems.at(index);
if (!item.enabled)
return false;
block->metatileId = item.metatileId;
if (this->hasCollision && this->collisionItems.length() == this->metatileItems.length()) {
CollisionSelectionItem collisionItem = this->collisionItems.at(index);
block->collision = collisionItem.collision;
block->elevation = collisionItem.elevation;
}
return true;
}
int getLayerOffset(StampLayer stampLayer) {
switch (stampLayer)
{
case StampLayer::STAMP_LAYER_BOTTOM:
return 0;
case StampLayer::STAMP_LAYER_TOP:
return 4;
default:
return 0;
}
}
bool StampSelection::paintNormal(int index, Block *block, Map *map, StampLayer stampLayer) {
Tileset *primaryTileset = map->layout->tileset_primary;
Tileset *secondaryTileset = map->layout->tileset_secondary;
// 1. Build metatile by applying the stamp to the existing block.
Metatile metatile = *(Tileset::getMetatile(block->metatileId, map->layout->tileset_primary, map->layout->tileset_secondary));
int baseOffset = getLayerOffset(stampLayer);
metatile.tiles[baseOffset] = Tile(0x5, false, false, 2);
metatile.tiles[baseOffset + 1] = Tile(0x5, true, false, 2);
metatile.tiles[baseOffset + 2] = Tile(0x15, false, false, 2);
metatile.tiles[baseOffset + 3] = Tile(0x15, true, false, 2);
// 2. Check if the metatile already exists in the map layout's primary or secondary tilesets.
bool exists = false;
uint16_t metatileId = 0;
uint16_t i = 0;
for (auto m : primaryTileset->metatiles) {
if (*m == metatile) {
exists = true;
metatileId = i;
break;
}
i++;
}
if (!exists) {
i = Project::getNumMetatilesPrimary();
for (auto m : secondaryTileset->metatiles) {
if (*m == metatile) {
exists = true;
metatileId = i;
break;
}
i++;
}
}
// 3. If the metatile doesn't exist, append the new metatile to the secondary tileset.
if (!exists) {
int maxSecondaryMetatiles = Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary();
if (secondaryTileset->metatiles.length() >= maxSecondaryMetatiles) {
return false;
}
secondaryTileset->metatiles.append(new Metatile(metatile));
metatileId = Project::getNumMetatilesPrimary() + secondaryTileset->metatiles.length() - 1;
}
// 4. Set the block's metatile id.
block->metatileId = metatileId;
return true;
}

View file

@ -199,7 +199,7 @@ void Prefab::updatePrefabUi(Map *map) {
frame->ui->label_Name->setText(item.name);
auto scene = new QGraphicsScene;
scene->addPixmap(drawMetatileSelection(item.selection, map));
scene->addPixmap(drawMetatileSelection(&item.selection, map));
scene->setSceneRect(scene->itemsBoundingRect());
frame->ui->graphicsView_Prefab->setScene(scene);
frame->ui->graphicsView_Prefab->setFixedSize(scene->itemsBoundingRect().width() + 2,
@ -243,12 +243,12 @@ void Prefab::updatePrefabUi(Map *map) {
prefabWidget->layout()->addItem(verticalSpacer);
}
void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
void Prefab::addPrefab(MetatileSelection *selection, Map *map, QString name) {
// First, determine which tilesets are actually used in this new prefab,
// based on the metatile ids.
bool usesPrimaryTileset = false;
bool usesSecondaryTileset = false;
for (auto metatile : selection.metatileItems) {
for (auto metatile : selection->metatileItems) {
if (!metatile.enabled)
continue;
if (metatile.metatileId < Project::getNumMetatilesPrimary()) {
@ -263,7 +263,7 @@ void Prefab::addPrefab(MetatileSelection selection, Map *map, QString name) {
name,
usesPrimaryTileset ? map->layout->tileset_primary_label : "",
usesSecondaryTileset ? map->layout->tileset_secondary_label: "",
selection
*selection
});
this->savePrefabs();
this->updatePrefabUi(map);

View file

@ -23,17 +23,17 @@ PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *me
QObject::connect(this->ui->graphicsView_Prefab, &ClickableGraphicsView::clicked, [=](QMouseEvent *event){
auto pos = event->pos();
int selectionWidth = this->selection.dimensions.x() * 16;
int selectionHeight = this->selection.dimensions.y() * 16;
int selectionWidth = this->selection->dimensions.x() * 16;
int selectionHeight = this->selection->dimensions.y() * 16;
if (pos.x() < 0 || pos.x() >= selectionWidth || pos.y() < 0 || pos.y() >= selectionHeight)
return;
int metatileX = pos.x() / 16;
int metatileY = pos.y() / 16;
int index = metatileY * this->selection.dimensions.x() + metatileX;
bool toggledState = !this->selection.metatileItems[index].enabled;
this->selection.metatileItems[index].enabled = toggledState;
if (this->selection.hasCollision) {
this->selection.collisionItems[index].enabled = toggledState;
int index = metatileY * this->selection->dimensions.x() + metatileX;
bool toggledState = !this->selection->metatileItems[index].enabled;
this->selection->metatileItems[index].enabled = toggledState;
if (this->selection->hasCollision) {
this->selection->collisionItems[index].enabled = toggledState;
}
pixmapItem->setPixmap(drawMetatileSelection(this->selection, map));
});

131
src/ui/stampselector.cpp Normal file
View file

@ -0,0 +1,131 @@
#include "stampselector.h"
#include "imageproviders.h"
#include "project.h"
#include <QPainter>
QPoint StampSelector::getSelectionDimensions() {
return selection->dimensions;
}
void StampSelector::draw() {
if (!this->primaryTileset || !this->secondaryTileset) {
this->setPixmap(QPixmap());
}
int primaryLength = this->primaryTileset->metatiles.length();
int length_ = primaryLength + this->secondaryTileset->metatiles.length();
int height_ = length_ / this->numStampsWide;
if (length_ % this->numStampsWide != 0) {
height_++;
}
QImage image(this->numStampsWide * 16, height_ * 16, QImage::Format_RGBA8888);
image.fill(Qt::magenta);
QPainter painter(&image);
for (int i = 0; i < length_; i++) {
int tile = i;
if (i >= primaryLength) {
tile += Project::getNumMetatilesPrimary() - primaryLength;
}
QImage metatile_image = getMetatileImage(tile, this->primaryTileset, this->secondaryTileset, map->metatileLayerOrder, map->metatileLayerOpacity);
int map_y = i / this->numStampsWide;
int map_x = i % this->numStampsWide;
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
painter.drawImage(metatile_origin, metatile_image);
}
painter.end();
this->setPixmap(QPixmap::fromImage(image));
this->drawSelection();
}
bool StampSelector::select(uint16_t stampId) {
// TODO:
if (stampId > 9999999999999) return false;
this->selection->dimensions = QPoint(1, 1);
this->selection->stampIds = QList<uint16_t>(stampId);
QPoint coords = this->getStampIdCoords(stampId);
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
this->updateSelectedStamps();
return true;
}
void StampSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) {
this->primaryTileset = primaryTileset;
this->secondaryTileset = secondaryTileset;
this->updateSelectedStamps();
this->draw();
}
StampSelection* StampSelector::getStampSelection() {
return selection;
}
bool StampSelector::shouldAcceptEvent(QGraphicsSceneMouseEvent *event) {
// QPoint pos = this->getCellPos(event->pos());
// return Tileset::metatileIsValid(getStampId(pos.x(), pos.y()), this->primaryTileset, this->secondaryTileset);
// TODO:
return true;
}
void StampSelector::mousePressEvent(QGraphicsSceneMouseEvent *event) {
if (!shouldAcceptEvent(event)) return;
SelectablePixmapItem::mousePressEvent(event);
this->updateSelectedStamps();
}
void StampSelector::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if (!shouldAcceptEvent(event)) return;
SelectablePixmapItem::mouseMoveEvent(event);
this->updateSelectedStamps();
}
void StampSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if (!shouldAcceptEvent(event)) return;
SelectablePixmapItem::mouseReleaseEvent(event);
this->updateSelectedStamps();
}
void StampSelector::updateSelectedStamps() {
this->selection->stampIds.clear();
this->selection->dimensions = SelectablePixmapItem::getSelectionDimensions();
QPoint origin = this->getSelectionStart();
for (int j = 0; j < this->selection->dimensions.y(); j++) {
for (int i = 0; i < this->selection->dimensions.x(); i++) {
uint16_t stampId = this->getStampId(origin.x() + i, origin.y() + j);
// TODO: check if stamp id is valid
if (false)
stampId = 0;
this->selection->stampIds.append(stampId);
}
}
emit selectedStampsChanged();
}
uint16_t StampSelector::getStampId(int x, int y) {
return y * this->numStampsWide + x;
}
QPoint StampSelector::getStampIdCoords(uint16_t stampId) {
// TODO: check if stamp id is valid
if (false)
{
// Invalid stamp id.
return QPoint(0, 0);
}
return QPoint(stampId % this->numStampsWide, stampId / this->numStampsWide);
}
QPoint StampSelector::getStampIdCoordsOnWidget(uint16_t stampId) {
QPoint pos = getStampIdCoords(stampId);
pos.rx() = (pos.x() * this->cellWidth) + (this->cellWidth / 2);
pos.ry() = (pos.y() * this->cellHeight) + (this->cellHeight / 2);
return pos;
}
void StampSelector::setMap(Map *map) {
this->map = map;
}