Merge pull request #716 from GriffinRichards/read-map-offsets

Read MAP_OFFSET_W, MAP_OFFSET_H from project
This commit is contained in:
GriffinR 2025-04-21 17:40:37 -04:00 committed by GitHub
commit 18f1b95e1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 421 additions and 312 deletions

View File

@ -97,6 +97,8 @@ In addition to these files, there are some specific symbol and macro names that
``define_pals_total``, ``NUM_PALS_TOTAL``,
``define_tiles_per_metatile``, ``NUM_TILES_PER_METATILE``, to determine if triple-layer metatiles are in use. Values other than 8 or 12 are ignored
``define_map_size``, ``MAX_MAP_DATA_SIZE``, to limit map dimensions
``define_map_offset_width``, ``MAP_OFFSET_W``, to limit map dimensions
``define_map_offset_height``, ``MAP_OFFSET_H``, to limit map dimensions
``define_mask_metatile``, ``MAPGRID_METATILE_ID_MASK``, optionally read to get settings on ``Maps`` tab
``define_mask_collision``, ``MAPGRID_COLLISION_MASK``, optionally read to get settings on ``Maps`` tab
``define_mask_elevation``, ``MAPGRID_ELEVATION_MASK``, optionally read to get settings on ``Maps`` tab

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<height>600</height>
<width>642</width>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
@ -38,8 +38,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>589</height>
<width>570</width>
<height>692</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -280,6 +280,91 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_PlayerViewDistance">
<property name="title">
<string>Player View Distance</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QFormLayout" name="formLayout_PlayerViewDistanceCol1">
<item row="0" column="0">
<widget class="QLabel" name="label_PlayerViewDistance_North">
<property name="text">
<string>North</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_PlayerViewDistance_South">
<property name="text">
<string>South</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollSpinBox" name="spinBox_PlayerViewDistance_North">
<property name="minimum">
<number>0</number>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The distance (in pixels) that a player is able to see North of their character's position in-game. By default this is the distance from the center 16x16 to the edge of the 160 pixel tall GBA screen.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="NoScrollSpinBox" name="spinBox_PlayerViewDistance_South">
<property name="minimum">
<number>0</number>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The distance (in pixels) that a player is able to see South of their character's position in-game. By default this is the distance from the center 16x16 to the edge of the 160 pixel tall GBA screen.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_PlayerViewDistanceCol2">
<item row="0" column="0">
<widget class="QLabel" name="label_PlayerViewDistance_West">
<property name="text">
<string>West</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_PlayerViewDistance_East">
<property name="text">
<string>East</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="NoScrollSpinBox" name="spinBox_PlayerViewDistance_West">
<property name="minimum">
<number>0</number>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The distance (in pixels) that a player is able to see West of their character's position in-game. By default this is the distance from the center 16x16 to the edge of the 240 pixel wide GBA screen.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="NoScrollSpinBox" name="spinBox_PlayerViewDistance_East">
<property name="minimum">
<number>0</number>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The distance (in pixels) that a player is able to see East of their character's position in-game. By default this is the distance from the center 16x16 to the edge of the 240 pixel wide GBA screen.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_Warning">
<property name="styleSheet">
@ -378,8 +463,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>560</height>
<width>561</width>
<height>622</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_16">
@ -389,37 +474,6 @@
<string>Map Data Defaults</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1" colspan="3">
<widget class="QWidget" name="widget_CustomSizeBorderMetatiles" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="NoScrollSpinBox" name="spinBox_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_Elevation">
<property name="text">
@ -427,6 +481,44 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_MapWidth">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox_CreateTextFile">
<property name="toolTip">
<string>Whether a separate text.inc or text.pory file will be created for new maps, alongside the scripts file</string>
</property>
<property name="text">
<string>Create separate text file</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="NoScrollSpinBox" name="spinBox_MapWidth">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="NoScrollSpinBox" name="spinBox_MapHeight">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_FillMetatile">
<property name="text">
@ -434,13 +526,10 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox_CreateTextFile">
<property name="toolTip">
<string>Whether a separate text.inc or text.pory file will be created for new maps, alongside the scripts file</string>
</property>
<item row="4" column="0">
<widget class="QLabel" name="label_Collision">
<property name="text">
<string>Create separate text file</string>
<string>Collision</string>
</property>
</widget>
</item>
@ -451,6 +540,20 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="UIntHexSpinBox" name="spinBox_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Collision">
<property name="toolTip">
<string>The default collision that will be used to fill new maps</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QStackedWidget" name="stackedWidget_BorderMetatiles">
<widget class="QWidget" name="page_CustomBorderSize">
@ -491,79 +594,59 @@
<number>0</number>
</property>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile1">
<widget class="UIntHexSpinBox" name="spinBox_BorderMetatile1">
<property name="toolTip">
<string>The default metatile value that will be used for the top-left border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile2">
<widget class="UIntHexSpinBox" name="spinBox_BorderMetatile2">
<property name="toolTip">
<string>The default metatile value that will be used for the top-right border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile3">
<widget class="UIntHexSpinBox" name="spinBox_BorderMetatile3">
<property name="toolTip">
<string>The default metatile value that will be used for the bottom-left border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
<item>
<widget class="NoScrollSpinBox" name="spinBox_BorderMetatile4">
<widget class="UIntHexSpinBox" name="spinBox_BorderMetatile4">
<property name="toolTip">
<string>The default metatile value that will be used for the bottom-right border metatile on new maps.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
<property name="displayIntegerBase">
<number>16</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="5" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
<item row="1" column="1" colspan="3">
<widget class="QWidget" name="widget_CustomSizeBorderMetatiles" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_Collision">
<item row="7" column="0">
<widget class="QLabel" name="label_MapHeight">
<property name="text">
<string>Collision</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="NoScrollSpinBox" name="spinBox_Collision">
<property name="toolTip">
<string>The default collision that will be used to fill new maps</string>
<string>Height</string>
</property>
</widget>
</item>
@ -751,7 +834,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<width>561</width>
<height>798</height>
</rect>
</property>
@ -1093,7 +1176,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<width>561</width>
<height>840</height>
</rect>
</property>
@ -1475,8 +1558,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>490</height>
<width>561</width>
<height>593</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
@ -1522,8 +1605,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<height>428</height>
<width>535</width>
<height>531</height>
</rect>
</property>
<layout class="QFormLayout" name="layout_ProjectPaths">
@ -1564,8 +1647,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>559</width>
<height>490</height>
<width>561</width>
<height>593</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
@ -1611,8 +1694,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>533</width>
<height>428</height>
<width>535</width>
<height>531</height>
</rect>
</property>
<layout class="QFormLayout" name="layout_Identifiers">

View File

@ -15,11 +15,11 @@
#include "events.h"
static const QVersionNumber porymapVersion = QVersionNumber::fromString(PORYMAP_VERSION);
extern const QVersionNumber porymapVersion;
// In both versions the default new map border is a generic tree
#define DEFAULT_BORDER_RSE (QList<uint16_t>{0x1D4, 0x1D5, 0x1DC, 0x1DD})
#define DEFAULT_BORDER_FRLG (QList<uint16_t>{0x14, 0x15, 0x1C, 0x1D})
// Distance in pixels from the edge of a GBA screen (240x160) to the center 16x16 pixels.
#define GBA_H_DIST_TO_CENTER ((240-16)/2)
#define GBA_V_DIST_TO_CENTER ((160-16)/2)
#define CONFIG_BACKWARDS_COMPATABILITY
@ -214,6 +214,8 @@ enum ProjectIdentifier {
define_pals_total,
define_tiles_per_metatile,
define_map_size,
define_map_offset_width,
define_map_offset_height,
define_mask_metatile,
define_mask_collision,
define_mask_elevation,
@ -317,6 +319,7 @@ public:
this->defaultMetatileId = 1;
this->defaultElevation = 3;
this->defaultCollision = 0;
this->defaultMapSize = QSize(20,20);
this->defaultPrimaryTileset = "gTileset_General";
this->prefabFilepath = QString();
this->prefabImportPrompted = false;
@ -328,8 +331,8 @@ public:
this->eventIconPaths.clear();
this->pokemonIconPaths.clear();
this->collisionSheetPath = QString();
this->collisionSheetWidth = 2;
this->collisionSheetHeight = 16;
this->collisionSheetSize = QSize(2, 16);
this->playerViewDistance = QMargins(GBA_H_DIST_TO_CENTER, GBA_V_DIST_TO_CENTER, GBA_H_DIST_TO_CENTER, GBA_V_DIST_TO_CENTER);
this->blockMetatileIdMask = 0x03FF;
this->blockCollisionMask = 0x0C00;
this->blockElevationMask = 0xF000;
@ -382,6 +385,7 @@ public:
uint16_t defaultMetatileId;
uint16_t defaultElevation;
uint16_t defaultCollision;
QSize defaultMapSize;
QList<uint16_t> newMapBorderMetatileIds;
QString defaultPrimaryTileset;
QString defaultSecondaryTileset;
@ -404,8 +408,8 @@ public:
uint16_t unusedTileSplit;
bool mapAllowFlagsEnabled;
QString collisionSheetPath;
int collisionSheetWidth;
int collisionSheetHeight;
QSize collisionSheetSize;
QMargins playerViewDistance;
QList<uint32_t> warpBehaviors;
int maxEventsPerGroup;

View File

@ -22,10 +22,6 @@
#define MAX_BORDER_WIDTH 255
#define MAX_BORDER_HEIGHT 255
// Number of metatiles to draw out from edge of map. Could allow modification of this in the future.
// porymap will reflect changes to it, but the value is hard-coded in the projects at the moment
#define BORDER_DISTANCE 7
class LayoutPixmapItem;
class CollisionPixmapItem;
class BorderMetatilesPixmapItem;

View File

@ -96,8 +96,8 @@ public:
int getHeight() const { return height; }
int getBorderWidth() const { return border_width; }
int getBorderHeight() const { return border_height; }
int getBorderDrawWidth() const;
int getBorderDrawHeight() const;
QMargins getBorderMargins() const;
QRect getVisibleRect() const;
bool isWithinBounds(int x, int y) const;
bool isWithinBounds(const QRect &rect) const;

View File

@ -119,6 +119,7 @@ public:
void redrawEventPixmapItem(DraggablePixmapItem *item);
qreal getEventOpacity(const Event *event) const;
void setPlayerViewRect(const QRectF &rect);
void updateCursorRectPos(int x, int y);
void setCursorRectVisible(bool visible);

View File

@ -226,30 +226,34 @@ public:
static QString getExistingFilepath(QString filepath);
void applyParsedLimits();
void setRegionMapEntries(const QHash<QString, MapSectionEntry> &entries);
QHash<QString, MapSectionEntry> getRegionMapEntries() const;
QSet<QString> getTopLevelMapFields() const;
int getMapDataSize(int width, int height) const;
int getMaxMapDataSize() const { return this->maxMapDataSize; }
int getMaxMapWidth() const;
int getMaxMapHeight() const;
bool mapDimensionsValid(int width, int height) const;
bool calculateDefaultMapSize();
QSize getDefaultMapSize() const { return this->defaultMapSize; }
QSize getMapSizeAddition() const { return this->mapSizeAddition; }
int getMaxEvents(Event::Group group) const;
static QString getEmptyMapDefineName();
static QString getDynamicMapDefineName();
static QString getDynamicMapName();
static QString getEmptySpeciesName();
static int getNumTilesPrimary();
static int getNumTilesTotal();
static int getNumMetatilesPrimary();
static int getNumMetatilesTotal();
static int getNumPalettesPrimary();
static int getNumPalettesTotal();
static int getMaxMapDataSize();
static int getDefaultMapDimension();
static int getMaxMapWidth();
static int getMaxMapHeight();
static int getMapDataSize(int width, int height);
static bool mapDimensionsValid(int width, int height);
bool calculateDefaultMapSize();
int getMaxEvents(Event::Group group);
static QMargins getMetatileViewDistance();
static int getNumTilesPrimary() { return num_tiles_primary; }
static int getNumTilesTotal() { return num_tiles_total; }
static int getNumMetatilesPrimary() { return num_metatiles_primary; }
static int getNumMetatilesTotal() { return Block::getMaxMetatileId() + 1; }
static int getNumPalettesPrimary(){ return num_pals_primary; }
static int getNumPalettesTotal() { return num_pals_total; }
static QString getEmptyMapsecName();
static QString getMapGroupPrefix();
@ -315,15 +319,19 @@ private:
QString findSpeciesIconPath(const QStringList &names) const;
int maxEventsPerGroup;
int maxObjectEvents;
int maxMapDataSize;
QSize defaultMapSize;
QSize mapSizeAddition;
// TODO: These really shouldn't be static, they're specific to a single project.
// We're making an assumption here that we only have one project open at a single time
// (which is true, but then if that's the case we should have some global Project instance instead)
static int num_tiles_primary;
static int num_tiles_total;
static int num_metatiles_primary;
static int num_pals_primary;
static int num_pals_total;
static int max_map_data_size;
static int default_map_dimension;
signals:
void fileChanged(const QString &filepath);

View File

@ -10,27 +10,28 @@
class MovableRect : public QGraphicsRectItem
{
public:
MovableRect(bool *enabled, int width, int height, QRgb color);
MovableRect(bool *enabled, const QRectF &rect, const QRgb &color);
QRectF boundingRect() const override {
qreal penWidth = 4;
return QRectF(-penWidth,
-penWidth,
30 * 8 + penWidth * 2,
20 * 8 + penWidth * 2);
this->rect().width() + penWidth * 2,
this->rect().height() + penWidth * 2);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override {
if (!(*enabled)) return;
painter->setPen(this->color);
painter->drawRect(this->rect().x() - 2, this->rect().y() - 2, this->rect().width() + 3, this->rect().height() + 3);
painter->setPen(QColor(0, 0, 0));
painter->drawRect(this->rect().x() - 3, this->rect().y() - 3, this->rect().width() + 5, this->rect().height() + 5);
painter->drawRect(this->rect().x() - 1, this->rect().y() - 1, this->rect().width() + 1, this->rect().height() + 1);
painter->drawRect(this->rect() + QMargins(1,1,1,1)); // Fill
painter->setPen(Qt::black);
painter->drawRect(this->rect() + QMargins(2,2,2,2)); // Outer border
painter->drawRect(this->rect()); // Inner border
}
void updateLocation(int x, int y);
bool *enabled;
protected:
QRectF baseRect;
QRgb color;
};

View File

@ -18,6 +18,12 @@
#include <QAction>
#include <QAbstractButton>
const QVersionNumber porymapVersion = QVersionNumber::fromString(PORYMAP_VERSION);
// In both versions the default new map border is a generic tree
const QList<uint16_t> defaultBorder_RSE = {0x1D4, 0x1D5, 0x1DC, 0x1DD};
const QList<uint16_t> defaultBorder_FRLG = {0x14, 0x15, 0x1C, 0x1D};
const QList<uint32_t> defaultWarpBehaviors_RSE = {
0x0E, // MB_MOSSDEEP_GYM_WARP
0x0F, // MB_MT_PYRE_HOLE
@ -89,6 +95,8 @@ const QMap<ProjectIdentifier, QPair<QString, QString>> ProjectConfig::defaultIde
{ProjectIdentifier::define_pals_total, {"define_pals_total", "NUM_PALS_TOTAL"}},
{ProjectIdentifier::define_tiles_per_metatile, {"define_tiles_per_metatile", "NUM_TILES_PER_METATILE"}},
{ProjectIdentifier::define_map_size, {"define_map_size", "MAX_MAP_DATA_SIZE"}},
{ProjectIdentifier::define_map_offset_width, {"define_map_offset_width", "MAP_OFFSET_W"}},
{ProjectIdentifier::define_map_offset_height, {"define_map_offset_height", "MAP_OFFSET_H"}},
{ProjectIdentifier::define_mask_metatile, {"define_mask_metatile", "MAPGRID_METATILE_ID_MASK"}},
{ProjectIdentifier::define_mask_collision, {"define_mask_collision", "MAPGRID_COLLISION_MASK"}},
{ProjectIdentifier::define_mask_elevation, {"define_mask_elevation", "MAPGRID_ELEVATION_MASK"}},
@ -265,7 +273,7 @@ int KeyValueConfigBase::getConfigInteger(QString key, QString value, int min, in
int result = value.toInt(&ok, 0);
if (!ok) {
logWarn(QString("Invalid config value for %1: '%2'. Must be an integer.").arg(key).arg(value));
return defaultValue;
result = defaultValue;
}
return qMin(max, qMax(min, result));
}
@ -275,7 +283,7 @@ uint32_t KeyValueConfigBase::getConfigUint32(QString key, QString value, uint32_
uint32_t result = value.toUInt(&ok, 0);
if (!ok) {
logWarn(QString("Invalid config value for %1: '%2'. Must be an integer.").arg(key).arg(value));
return defaultValue;
result = defaultValue;
}
return qMin(max, qMax(min, result));
}
@ -739,6 +747,10 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
this->defaultElevation = getConfigUint32(key, value, 0, Block::maxValue);
} else if (key == "default_collision") {
this->defaultCollision = getConfigUint32(key, value, 0, Block::maxValue);
} else if (key == "default_map_width") {
this->defaultMapSize.setWidth(getConfigInteger(key, value, 1));
} else if (key == "default_map_height") {
this->defaultMapSize.setHeight(getConfigInteger(key, value, 1));
} else if (key == "new_map_border_metatiles") {
this->newMapBorderMetatileIds.clear();
QList<QString> metatileIds = value.split(",");
@ -828,9 +840,17 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
} else if (key == "collision_sheet_path") {
this->collisionSheetPath = value;
} else if (key == "collision_sheet_width") {
this->collisionSheetWidth = getConfigUint32(key, value, 1, Block::maxValue);
this->collisionSheetSize.setWidth(getConfigInteger(key, value, 1, Block::maxValue));
} else if (key == "collision_sheet_height") {
this->collisionSheetHeight = getConfigUint32(key, value, 1, Block::maxValue);
this->collisionSheetSize.setHeight(getConfigInteger(key, value, 1, Block::maxValue));
} else if (key == "player_view_north") {
this->playerViewDistance.setTop(getConfigInteger(key, value, 0, INT_MAX, GBA_V_DIST_TO_CENTER));
} else if (key == "player_view_south") {
this->playerViewDistance.setBottom(getConfigInteger(key, value, 0, INT_MAX, GBA_V_DIST_TO_CENTER));
} else if (key == "player_view_west") {
this->playerViewDistance.setLeft(getConfigInteger(key, value, 0, INT_MAX, GBA_H_DIST_TO_CENTER));
} else if (key == "player_view_east") {
this->playerViewDistance.setRight(getConfigInteger(key, value, 0, INT_MAX, GBA_H_DIST_TO_CENTER));
} else if (key == "warp_behaviors") {
this->warpBehaviors.clear();
value.remove(" ");
@ -864,7 +884,7 @@ void ProjectConfig::setUnreadKeys() {
if (!readKeys.contains("enable_event_clone_object")) this->eventCloneObjectEnabled = isPokefirered;
if (!readKeys.contains("enable_floor_number")) this->floorNumberEnabled = isPokefirered;
if (!readKeys.contains("create_map_text_file")) this->createMapTextFileEnabled = (this->baseGameVersion != BaseGameVersion::pokeemerald);
if (!readKeys.contains("new_map_border_metatiles")) this->newMapBorderMetatileIds = isPokefirered ? DEFAULT_BORDER_FRLG : DEFAULT_BORDER_RSE;
if (!readKeys.contains("new_map_border_metatiles")) this->newMapBorderMetatileIds = isPokefirered ? defaultBorder_FRLG : defaultBorder_RSE;
if (!readKeys.contains("default_secondary_tileset")) this->defaultSecondaryTileset = isPokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg";
if (!readKeys.contains("metatile_attributes_size")) this->metatileAttributesSize = Metatile::getDefaultAttributesSize(this->baseGameVersion);
if (!readKeys.contains("metatile_behavior_mask")) this->metatileBehaviorMask = Metatile::getDefaultAttributesMask(this->baseGameVersion, Metatile::Attr::Behavior);
@ -892,6 +912,8 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("default_metatile", Metatile::getMetatileIdString(this->defaultMetatileId));
map.insert("default_elevation", QString::number(this->defaultElevation));
map.insert("default_collision", QString::number(this->defaultCollision));
map.insert("default_map_width", QString::number(this->defaultMapSize.width()));
map.insert("default_map_height", QString::number(this->defaultMapSize.height()));
map.insert("new_map_border_metatiles", Metatile::getMetatileIdStrings(this->newMapBorderMetatileIds));
map.insert("default_primary_tileset", this->defaultPrimaryTileset);
map.insert("default_secondary_tileset", this->defaultSecondaryTileset);
@ -929,8 +951,12 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
map.insert("ident/"+defaultIdentifiers.value(i.key()).first, i.value());
}
map.insert("collision_sheet_path", this->collisionSheetPath);
map.insert("collision_sheet_width", QString::number(this->collisionSheetWidth));
map.insert("collision_sheet_height", QString::number(this->collisionSheetHeight));
map.insert("collision_sheet_width", QString::number(this->collisionSheetSize.width()));
map.insert("collision_sheet_height", QString::number(this->collisionSheetSize.height()));
map.insert("player_view_north", QString::number(this->playerViewDistance.top()));
map.insert("player_view_south", QString::number(this->playerViewDistance.bottom()));
map.insert("player_view_west", QString::number(this->playerViewDistance.left()));
map.insert("player_view_east", QString::number(this->playerViewDistance.right()));
QStringList warpBehaviorStrs;
for (const auto &value : this->warpBehaviors)
warpBehaviorStrs.append("0x" + QString("%1").arg(value, 2, 16, QChar('0')).toUpper());

View File

@ -83,16 +83,17 @@ QRect Map::getConnectionRect(const QString &direction, Layout * fromLayout) cons
int x = 0, y = 0;
int w = getWidth(), h = getHeight();
QMargins viewDistance = Project::getMetatileViewDistance();
if (direction == "up") {
h = qMin(h, BORDER_DISTANCE);
h = qMin(h, viewDistance.top());
y = getHeight() - h;
} else if (direction == "down") {
h = qMin(h, BORDER_DISTANCE);
h = qMin(h, viewDistance.bottom());
} else if (direction == "left") {
w = qMin(w, BORDER_DISTANCE);
w = qMin(w, viewDistance.left());
x = getWidth() - w;
} else if (direction == "right") {
w = qMin(w, BORDER_DISTANCE);
w = qMin(w, viewDistance.right());
} else if (MapConnection::isDiving(direction)) {
if (fromLayout) {
w = qMin(w, fromLayout->getWidth());

View File

@ -63,17 +63,11 @@ bool Layout::isWithinBorderBounds(int x, int y) const {
return (x >= 0 && x < this->getBorderWidth() && y >= 0 && y < this->getBorderHeight());
}
int Layout::getBorderDrawWidth() const {
return getBorderDrawDistance(border_width, BORDER_DISTANCE);
}
int Layout::getBorderDrawHeight() const {
return getBorderDrawDistance(border_height, BORDER_DISTANCE);
}
// We need to draw sufficient border blocks to fill the area that gets loaded around the player in-game (BORDER_DISTANCE).
// Note that this is not the same as the player's view distance.
// The result will be some multiple of the input dimension, because we only draw the border in increments of its full width/height.
// Calculate the distance away from the layout's edge that we need to start drawing border blocks.
// We need to fulfill two requirements here:
// - We should draw enough to fill the player's in-game view
// - The value should be some multiple of the border's dimension
// (otherwise the border won't be positioned the same as it would in-game).
int Layout::getBorderDrawDistance(int dimension, qreal minimum) {
if (dimension >= minimum)
return dimension;
@ -81,6 +75,23 @@ int Layout::getBorderDrawDistance(int dimension, qreal minimum) {
// Get first multiple of dimension >= the minimum
return dimension * qCeil(minimum / qMax(dimension, 1));
}
QMargins Layout::getBorderMargins() const {
QMargins minimum = Project::getMetatileViewDistance();
QMargins distance;
distance.setTop(getBorderDrawDistance(this->border_height, minimum.top()));
distance.setBottom(getBorderDrawDistance(this->border_height, minimum.bottom()));
distance.setLeft(getBorderDrawDistance(this->border_width, minimum.left()));
distance.setRight(getBorderDrawDistance(this->border_width, minimum.right()));
return distance;
}
// Get a rectangle that represents (in pixels) the layout's map area and the visible area of its border.
// At maximum, this is equal to the map size plus the border margins.
// If the border is large (and so beyond player the view) it may be smaller than that.
QRect Layout::getVisibleRect() const {
QRect area = QRect(0, 0, this->width * 16, this->height * 16);
return area += (Project::getMetatileViewDistance() * 16);
}
bool Layout::getBlock(int x, int y, Block *out) {
if (isWithinBounds(x, y)) {

View File

@ -30,7 +30,6 @@ Editor::Editor(Ui::MainWindow* ui)
{
this->ui = ui;
this->settings = new Settings();
this->playerViewRect = new MovableRect(&this->settings->playerViewRectEnabled, 30 * 8, 20 * 8, qRgb(255, 255, 255));
this->cursorMapTileRect = new CursorTileRect(&this->settings->cursorTileRectEnabled, qRgb(255, 255, 255));
this->map_ruler = new MapRuler(4);
connect(this->map_ruler, &MapRuler::statusChanged, this, &Editor::mapRulerStatusChanged);
@ -1064,6 +1063,13 @@ void Editor::scaleMapView(int s) {
ui->graphicsView_Connections->setTransform(transform);
}
void Editor::setPlayerViewRect(const QRectF &rect) {
delete this->playerViewRect;
this->playerViewRect = new MovableRect(&this->settings->playerViewRectEnabled, rect, qRgb(255, 255, 255));
if (ui->graphicsView_Map->scene())
ui->graphicsView_Map->scene()->update();
}
void Editor::updateCursorRectPos(int x, int y) {
if (this->playerViewRect)
this->playerViewRect->updateLocation(x, y);
@ -1563,14 +1569,8 @@ void Editor::displayMapMetatiles() {
map_item->draw(true);
scene->addItem(map_item);
int tw = 16;
int th = 16;
scene->setSceneRect(
-BORDER_DISTANCE * tw,
-BORDER_DISTANCE * th,
map_item->pixmap().width() + BORDER_DISTANCE * 2 * tw,
map_item->pixmap().height() + BORDER_DISTANCE * 2 * th
);
// Scene rect is the map plus a margin that gives enough space to scroll and see the edge of the player view rectangle.
scene->setSceneRect(this->layout->getVisibleRect() + QMargins(3,3,3,3));
}
void Editor::clearMapMovementPermissions() {
@ -1763,18 +1763,13 @@ void Editor::clearConnectionMask() {
}
}
// Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE).
// Hides connected map tiles that cannot be seen from the current map
void Editor::maskNonVisibleConnectionTiles() {
clearConnectionMask();
QPainterPath mask;
mask.addRect(scene->itemsBoundingRect().toRect());
mask.addRect(
-BORDER_DISTANCE * 16,
-BORDER_DISTANCE * 16,
(layout->getWidth() + BORDER_DISTANCE * 2) * 16,
(layout->getHeight() + BORDER_DISTANCE * 2) * 16
);
mask.addRect(layout->getVisibleRect());
// Mask the tiles with the current theme's background color.
QPen pen(ui->graphicsView_Map->palette().color(QPalette::Active, QPalette::Base));
@ -1796,13 +1791,10 @@ void Editor::clearMapBorder() {
void Editor::displayMapBorder() {
clearMapBorder();
int borderWidth = this->layout->getBorderWidth();
int borderHeight = this->layout->getBorderHeight();
int borderHorzDist = this->layout->getBorderDrawWidth();
int borderVertDist = this->layout->getBorderDrawHeight();
QPixmap pixmap = this->layout->renderBorder();
for (int y = -borderVertDist; y < this->layout->getHeight() + borderVertDist; y += borderHeight)
for (int x = -borderHorzDist; x < this->layout->getWidth() + borderHorzDist; x += borderWidth) {
const QMargins borderMargins = layout->getBorderMargins();
for (int y = -borderMargins.top(); y < this->layout->getHeight() + borderMargins.bottom(); y += this->layout->getBorderHeight())
for (int x = -borderMargins.left(); x < this->layout->getWidth() + borderMargins.right(); x += this->layout->getBorderWidth()) {
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
item->setX(x * 16);
item->setY(y * 16);
@ -2341,8 +2333,8 @@ void Editor::setCollisionGraphics() {
// Users are not required to provide an image that gives an icon for every elevation/collision combination.
// Instead they tell us how many are provided in their image by specifying the number of columns and rows.
const int imgColumns = projectConfig.collisionSheetWidth;
const int imgRows = projectConfig.collisionSheetHeight;
const int imgColumns = projectConfig.collisionSheetSize.width();
const int imgRows = projectConfig.collisionSheetSize.height();
// Create a pixmap for the selector on the Collision tab. If a project was previously opened we'll also need to refresh the selector.
this->collisionSheetPixmap = QPixmap::fromImage(imgSheet).scaled(MovementPermissionsSelector::CellWidth * imgColumns,

View File

@ -1171,6 +1171,8 @@ bool MainWindow::setProjectUI() {
ui->newEventToolButton->setEventTypeVisible(Event::Type::SecretBase, projectConfig.eventSecretBaseEnabled);
ui->newEventToolButton->setEventTypeVisible(Event::Type::CloneObject, projectConfig.eventCloneObjectEnabled);
this->editor->setPlayerViewRect(QRectF(0, 0, 16, 16).marginsAdded(projectConfig.playerViewDistance));
editor->setCollisionGraphics();
ui->spinBox_SelectedElevation->setMaximum(Block::getMaxElevation());
ui->spinBox_SelectedCollision->setMaximum(Block::getMaxCollision());

View File

@ -29,8 +29,6 @@ int Project::num_tiles_total = 1024;
int Project::num_metatiles_primary = 512;
int Project::num_pals_primary = 6;
int Project::num_pals_total = 13;
int Project::max_map_data_size = 10240; // 0x2800
int Project::default_map_dimension = 20;
Project::Project(QObject *parent) :
QObject(parent),
@ -1995,8 +1993,8 @@ void Project::initNewMapSettings() {
this->newMapSettings.layout.folderName = this->newMapSettings.name;
this->newMapSettings.layout.name = QString();
this->newMapSettings.layout.id = Layout::layoutConstantFromName(this->newMapSettings.name);
this->newMapSettings.layout.width = getDefaultMapDimension();
this->newMapSettings.layout.height = getDefaultMapDimension();
this->newMapSettings.layout.width = this->defaultMapSize.width();
this->newMapSettings.layout.height = this->defaultMapSize.height();
this->newMapSettings.layout.borderWidth = DEFAULT_BORDER_WIDTH;
this->newMapSettings.layout.borderHeight = DEFAULT_BORDER_HEIGHT;
this->newMapSettings.layout.primaryTilesetLabel = getDefaultPrimaryTilesetLabel();
@ -2018,8 +2016,8 @@ void Project::initNewMapSettings() {
void Project::initNewLayoutSettings() {
this->newLayoutSettings.name = QString();
this->newLayoutSettings.id = Layout::layoutConstantFromName(this->newLayoutSettings.name);
this->newLayoutSettings.width = getDefaultMapDimension();
this->newLayoutSettings.height = getDefaultMapDimension();
this->newLayoutSettings.width = this->defaultMapSize.width();
this->newLayoutSettings.height = this->defaultMapSize.height();
this->newLayoutSettings.borderWidth = DEFAULT_BORDER_WIDTH;
this->newLayoutSettings.borderHeight = DEFAULT_BORDER_HEIGHT;
this->newLayoutSettings.primaryTilesetLabel = getDefaultPrimaryTilesetLabel();
@ -2112,7 +2110,12 @@ bool Project::readFieldmapProperties() {
const QString numPalsTotalName = projectConfig.getIdentifier(ProjectIdentifier::define_pals_total);
const QString maxMapSizeName = projectConfig.getIdentifier(ProjectIdentifier::define_map_size);
const QString numTilesPerMetatileName = projectConfig.getIdentifier(ProjectIdentifier::define_tiles_per_metatile);
const QSet<QString> names = {
const QString mapOffsetWidthName = projectConfig.getIdentifier(ProjectIdentifier::define_map_offset_width);
const QString mapOffsetHeightName = projectConfig.getIdentifier(ProjectIdentifier::define_map_offset_height);
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_fieldmap);
fileWatcher.addPath(root + "/" + filename);
const QMap<QString, int> defines = parser.readCDefinesByName(filename, {
numTilesPrimaryName,
numTilesTotalName,
numMetatilesPrimaryName,
@ -2120,24 +2123,23 @@ bool Project::readFieldmapProperties() {
numPalsTotalName,
maxMapSizeName,
numTilesPerMetatileName,
};
const QString filename = projectConfig.getFilePath(ProjectFilePath::constants_fieldmap);
fileWatcher.addPath(root + "/" + filename);
const QMap<QString, int> defines = parser.readCDefinesByName(filename, names);
mapOffsetWidthName,
mapOffsetHeightName,
});
auto loadDefine = [defines](const QString name, int * dest, int min, int max) {
auto it = defines.find(name);
if (it != defines.end()) {
*dest = it.value();
if (*dest < min) {
logWarn(QString("Value for tileset property '%1' (%2) is below the minimum (%3). Defaulting to minimum.").arg(name).arg(*dest).arg(min));
logWarn(QString("Value for '%1' (%2) is below the minimum (%3). Defaulting to minimum.").arg(name).arg(*dest).arg(min));
*dest = min;
} else if (*dest > max) {
logWarn(QString("Value for tileset property '%1' (%2) is above the maximum (%3). Defaulting to maximum.").arg(name).arg(*dest).arg(max));
logWarn(QString("Value for '%1' (%2) is above the maximum (%3). Defaulting to maximum.").arg(name).arg(*dest).arg(max));
*dest = max;
}
} else {
logWarn(QString("Value for tileset property '%1' not found. Using default (%2) instead.").arg(name).arg(*dest));
logWarn(QString("Value for '%1' not found. Using default (%2) instead.").arg(name).arg(*dest));
}
};
loadDefine(numPalsTotalName, &Project::num_pals_total, 2, INT_MAX); // In reality the max would be 16, but as far as Porymap is concerned it doesn't matter.
@ -2149,25 +2151,42 @@ bool Project::readFieldmapProperties() {
// we don't actually know what the maximum number of metatiles is.
loadDefine(numMetatilesPrimaryName, &Project::num_metatiles_primary, 1, 0xFFFF - 1);
int w = 15, h = 14; // Default values of MAP_OFFSET_W, MAP_OFFSET_H
loadDefine(mapOffsetWidthName, &w, 0, INT_MAX);
loadDefine(mapOffsetHeightName, &h, 0, INT_MAX);
this->mapSizeAddition = QSize(w, h);
this->maxMapDataSize = 10240; // Default value of MAX_MAP_DATA_SIZE
this->defaultMapSize = projectConfig.defaultMapSize;
auto it = defines.find(maxMapSizeName);
if (it != defines.end()) {
int min = getMapDataSize(1, 1);
if (it.value() >= min) {
Project::max_map_data_size = it.value();
calculateDefaultMapSize();
this->maxMapDataSize = it.value();
if (getMapDataSize(this->defaultMapSize.width(), this->defaultMapSize.height()) > this->maxMapDataSize) {
// The specified map size is too small to use the default map dimensions.
// Calculate the largest square map size that we can use instead.
int dimension = qFloor((qSqrt(4 * this->maxMapDataSize + 1) - (w + h)) / 2);
logWarn(QString("Value for '%1' (%2) is too small to support the default %3x%4 map. Default changed to %5x%5.")
.arg(maxMapSizeName)
.arg(it.value())
.arg(this->defaultMapSize.width())
.arg(this->defaultMapSize.height())
.arg(dimension));
this->defaultMapSize = QSize(dimension, dimension);
}
} else {
// must be large enough to support a 1x1 map
logWarn(QString("Value for map property '%1' is %2, must be at least %3. Using default (%4) instead.")
logWarn(QString("Value for '%1' (%2) is too small to support a 1x1 map. Must be at least %3. Using default (%4) instead.")
.arg(maxMapSizeName)
.arg(it.value())
.arg(min)
.arg(Project::max_map_data_size));
.arg(this->maxMapDataSize));
}
}
else {
logWarn(QString("Value for map property '%1' not found. Using default (%2) instead.")
logWarn(QString("Value for '%1' not found. Using default (%2) instead.")
.arg(maxMapSizeName)
.arg(Project::max_map_data_size));
.arg(this->maxMapDataSize));
}
it = defines.find(numTilesPerMetatileName);
@ -3144,91 +3163,28 @@ QPixmap Project::getSpeciesIcon(const QString &species) {
return pixmap;
}
int Project::getNumTilesPrimary()
{
return Project::num_tiles_primary;
int Project::getMapDataSize(int width, int height) const {
return (width + this->mapSizeAddition.width())
* (height + this->mapSizeAddition.height());
}
int Project::getNumTilesTotal()
{
return Project::num_tiles_total;
int Project::getMaxMapWidth() const {
return (getMaxMapDataSize() / (1 + this->mapSizeAddition.height())) - this->mapSizeAddition.width();
}
int Project::getNumMetatilesPrimary()
{
return Project::num_metatiles_primary;
int Project::getMaxMapHeight() const {
return (getMaxMapDataSize() / (1 + this->mapSizeAddition.width())) - this->mapSizeAddition.height();
}
int Project::getNumMetatilesTotal()
{
return Block::getMaxMetatileId() + 1;
}
int Project::getNumPalettesPrimary()
{
return Project::num_pals_primary;
}
int Project::getNumPalettesTotal()
{
return Project::num_pals_total;
}
int Project::getMaxMapDataSize()
{
return Project::max_map_data_size;
}
int Project::getMapDataSize(int width, int height)
{
// + 15 and + 14 come from fieldmap.c in pokeruby/pokeemerald/pokefirered.
return (width + 15) * (height + 14);
}
int Project::getDefaultMapDimension()
{
return Project::default_map_dimension;
}
int Project::getMaxMapWidth()
{
return (getMaxMapDataSize() / (1 + 14)) - 15;
}
int Project::getMaxMapHeight()
{
return (getMaxMapDataSize() / (1 + 15)) - 14;
}
bool Project::mapDimensionsValid(int width, int height) {
bool Project::mapDimensionsValid(int width, int height) const {
return getMapDataSize(width, height) <= getMaxMapDataSize();
}
// Get largest possible square dimensions for a map up to maximum of 20x20 (arbitrary)
bool Project::calculateDefaultMapSize(){
int max = getMaxMapDataSize();
if (max >= getMapDataSize(20, 20)) {
default_map_dimension = 20;
} else if (max >= getMapDataSize(1, 1)) {
// Below equation derived from max >= (x + 15) * (x + 14)
// x^2 + 29x + (210 - max), then complete the square and simplify
default_map_dimension = qFloor((qSqrt(4 * getMaxMapDataSize() + 1) - 29) / 2);
} else {
logError(QString("'%1' of %2 is too small to support a 1x1 map. Must be at least %3.")
.arg(projectConfig.getIdentifier(ProjectIdentifier::define_map_size))
.arg(max)
.arg(getMapDataSize(1, 1)));
return false;
}
return true;
}
// Object events have their own limit specified by ProjectIdentifier::define_obj_event_count.
// The default value for this is 64. All events (object events included) are also limited by
// the data types of the event counters in the project. This would normally be u8, so the limit is 255.
// We let the users tell us this limit in case they change these data types.
int Project::getMaxEvents(Event::Group group) {
int Project::getMaxEvents(Event::Group group) const {
if (group == Event::Group::Object)
return qMin(this->maxObjectEvents, projectConfig.maxEventsPerGroup);
return projectConfig.maxEventsPerGroup;
@ -3250,6 +3206,17 @@ QString Project::getEmptySpeciesName() {
return projectConfig.getIdentifier(ProjectIdentifier::define_species_prefix) + projectConfig.getIdentifier(ProjectIdentifier::define_species_empty);
}
// Get the distance in metatiles (rounded up) that the player is able to see in each direction in-game.
// For the default view distance (i.e. assuming the player is centered in a 240x160 pixel GBA screen) this is 7x5 metatiles.
QMargins Project::getMetatileViewDistance() {
QMargins viewDistance = projectConfig.playerViewDistance;
viewDistance.setTop(qCeil(viewDistance.top() / 16.0));
viewDistance.setBottom(qCeil(viewDistance.bottom() / 16.0));
viewDistance.setLeft(qCeil(viewDistance.left() / 16.0));
viewDistance.setRight(qCeil(viewDistance.right() / 16.0));
return viewDistance;
}
// If the provided filepath is an absolute path to an existing file, return filepath.
// If not, and the provided filepath is a relative path from the project dir to an existing file, return the relative path.
// Otherwise return empty string.
@ -3283,8 +3250,8 @@ void Project::applyParsedLimits() {
projectConfig.defaultMetatileId = qMin(projectConfig.defaultMetatileId, Block::getMaxMetatileId());
projectConfig.defaultElevation = qMin(projectConfig.defaultElevation, Block::getMaxElevation());
projectConfig.defaultCollision = qMin(projectConfig.defaultCollision, Block::getMaxCollision());
projectConfig.collisionSheetHeight = qMin(qMax(projectConfig.collisionSheetHeight, 1), Block::getMaxElevation() + 1);
projectConfig.collisionSheetWidth = qMin(qMax(projectConfig.collisionSheetWidth, 1), Block::getMaxCollision() + 1);
projectConfig.collisionSheetSize.setHeight(qMin(qMax(projectConfig.collisionSheetSize.height(), 1), Block::getMaxElevation() + 1));
projectConfig.collisionSheetSize.setWidth(qMin(qMax(projectConfig.collisionSheetSize.width(), 1), Block::getMaxCollision() + 1));
}
bool Project::hasUnsavedChanges() {

View File

@ -227,7 +227,7 @@ int MainWindow::getHeight() {
void MainWindow::setDimensions(int width, int height) {
if (!this->editor || !this->editor->layout)
return;
if (!Project::mapDimensionsValid(width, height))
if (this->editor->project && !this->editor->project->mapDimensionsValid(width, height))
return;
this->editor->layout->setDimensions(width, height);
this->tryCommitMapChanges(true);
@ -237,7 +237,7 @@ void MainWindow::setDimensions(int width, int height) {
void MainWindow::setWidth(int width) {
if (!this->editor || !this->editor->layout)
return;
if (!Project::mapDimensionsValid(width, this->editor->layout->getHeight()))
if (this->editor->project && !this->editor->project->mapDimensionsValid(width, this->editor->layout->getHeight()))
return;
this->editor->layout->setDimensions(width, this->editor->layout->getHeight());
this->tryCommitMapChanges(true);
@ -247,7 +247,7 @@ void MainWindow::setWidth(int width) {
void MainWindow::setHeight(int height) {
if (!this->editor || !this->editor->layout)
return;
if (!Project::mapDimensionsValid(this->editor->layout->getWidth(), height))
if (this->editor->project && !this->editor->project->mapDimensionsValid(this->editor->layout->getWidth(), height))
return;
this->editor->layout->setDimensions(this->editor->layout->getWidth(), height);
this->tryCommitMapChanges(true);

View File

@ -606,9 +606,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap() {
QMargins MapImageExporter::getMargins(const Map *map) {
QMargins margins;
if (m_settings.showBorder) {
// The border may technically extend beyond BORDER_DISTANCE, but when the border is painted
// we will be limiting it to the visible sight range.
margins = QMargins(BORDER_DISTANCE, BORDER_DISTANCE, BORDER_DISTANCE, BORDER_DISTANCE) * 16;
margins = m_project->getMetatileViewDistance() * 16;
} else if (map && connectionsEnabled()) {
for (const auto &connection : map->getConnections()) {
const QString dir = connection->direction();
@ -649,15 +647,12 @@ void MapImageExporter::paintBorder(QPainter *painter, Layout *layout) {
layout->renderBorder(true);
// Clip parts of the border that would be beyond player visibility.
QRect visibleArea(0, 0, layout->getWidth() * 16, layout->getHeight() * 16);
visibleArea += (QMargins(BORDER_DISTANCE, BORDER_DISTANCE, BORDER_DISTANCE, BORDER_DISTANCE) * 16);
painter->save();
painter->setClipRect(visibleArea);
painter->setClipRect(layout->getVisibleRect());
int borderHorzDist = layout->getBorderDrawWidth();
int borderVertDist = layout->getBorderDrawHeight();
for (int y = -borderVertDist; y < layout->getHeight() + borderVertDist; y += layout->getBorderHeight())
for (int x = -borderHorzDist; x < layout->getWidth() + borderHorzDist; x += layout->getBorderWidth()) {
const QMargins borderMargins = layout->getBorderMargins();
for (int y = -borderMargins.top(); y < layout->getHeight() + borderMargins.bottom(); y += layout->getBorderHeight())
for (int x = -borderMargins.left(); x < layout->getWidth() + borderMargins.right(); x += layout->getBorderWidth()) {
// Skip border painting if it would be fully covered by the rest of the map
if (layout->isWithinBounds(QRect(x, y, layout->getBorderWidth(), layout->getBorderHeight())))
continue;

View File

@ -5,17 +5,21 @@
#include "movablerect.h"
#include "utility.h"
MovableRect::MovableRect(bool *enabled, int width, int height, QRgb color)
: QGraphicsRectItem(0, 0, width, height)
MovableRect::MovableRect(bool *enabled, const QRectF &rect, const QRgb &color)
: QGraphicsRectItem(rect),
enabled(enabled),
baseRect(rect),
color(color)
{
this->enabled = enabled;
this->color = color;
this->setVisible(*enabled);
}
/// Center rect on grid position (x, y)
void MovableRect::updateLocation(int x, int y) {
this->setRect((x * 16) - this->rect().width() / 2 + 8, (y * 16) - this->rect().height() / 2 + 8, this->rect().width(), this->rect().height());
this->setRect(this->baseRect.x() + (x * 16),
this->baseRect.y() + (y * 16),
this->baseRect.width(),
this->baseRect.height());
this->setVisible(*this->enabled);
}
@ -25,7 +29,7 @@ void MovableRect::updateLocation(int x, int y) {
ResizableRect::ResizableRect(QObject *parent, bool *enabled, int width, int height, QRgb color)
: QObject(parent),
MovableRect(enabled, width * 16, height * 16, color)
MovableRect(enabled, QRect(0, 0, width * 16, height * 16), color)
{
setZValue(0xFFFFFFFF); // ensure on top of view
setAcceptHoverEvents(true);

View File

@ -86,17 +86,14 @@ bool NewLayoutForm::validateMapDimensions() {
int size = m_project->getMapDataSize(ui->spinBox_MapWidth->value(), ui->spinBox_MapHeight->value());
int maxSize = m_project->getMaxMapDataSize();
// TODO: Get from project
const int additionalWidth = 15;
const int additionalHeight = 14;
QString errorText;
if (size > maxSize) {
QSize addition = m_project->getMapSizeAddition();
errorText = QString("The specified width and height are too large.\n"
"The maximum map width and height is the following: (width + %1) * (height + %2) <= %3\n"
"The specified map width and height was: (%4 + %1) * (%5 + %2) = %6")
.arg(additionalWidth)
.arg(additionalHeight)
.arg(addition.width())
.arg(addition.height())
.arg(maxSize)
.arg(ui->spinBox_MapWidth->value())
.arg(ui->spinBox_MapHeight->value())

View File

@ -136,6 +136,12 @@ void ProjectSettingsEditor::initUi() {
ui->spinBox_UnusedTileCovered->setMaximum(Tile::maxValue);
ui->spinBox_UnusedTileSplit->setMaximum(Tile::maxValue);
ui->spinBox_MaxEvents->setMaximum(INT_MAX);
ui->spinBox_MapWidth->setMaximum(INT_MAX);
ui->spinBox_MapHeight->setMaximum(INT_MAX);
ui->spinBox_PlayerViewDistance_West->setMaximum(INT_MAX);
ui->spinBox_PlayerViewDistance_North->setMaximum(INT_MAX);
ui->spinBox_PlayerViewDistance_East->setMaximum(INT_MAX);
ui->spinBox_PlayerViewDistance_South->setMaximum(INT_MAX);
// The values for some of the settings we provide in this window can be determined using constants in the user's projects.
// If the user has these constants we disable these settings in the UI -- they can modify them using their constants.
@ -456,8 +462,10 @@ void ProjectSettingsEditor::refresh() {
ui->spinBox_Elevation->setValue(projectConfig.defaultElevation);
ui->spinBox_Collision->setValue(projectConfig.defaultCollision);
ui->spinBox_FillMetatile->setValue(projectConfig.defaultMetatileId);
ui->spinBox_MaxElevation->setValue(projectConfig.collisionSheetHeight - 1);
ui->spinBox_MaxCollision->setValue(projectConfig.collisionSheetWidth - 1);
ui->spinBox_MapWidth->setValue(projectConfig.defaultMapSize.width());
ui->spinBox_MapHeight->setValue(projectConfig.defaultMapSize.height());
ui->spinBox_MaxElevation->setValue(projectConfig.collisionSheetSize.height() - 1);
ui->spinBox_MaxCollision->setValue(projectConfig.collisionSheetSize.width() - 1);
ui->spinBox_BehaviorMask->setValue(projectConfig.metatileBehaviorMask & ui->spinBox_BehaviorMask->maximum());
ui->spinBox_EncounterTypeMask->setValue(projectConfig.metatileEncounterTypeMask & ui->spinBox_EncounterTypeMask->maximum());
ui->spinBox_LayerTypeMask->setValue(projectConfig.metatileLayerTypeMask & ui->spinBox_LayerTypeMask->maximum());
@ -469,6 +477,10 @@ void ProjectSettingsEditor::refresh() {
ui->spinBox_UnusedTileCovered->setValue(projectConfig.unusedTileCovered);
ui->spinBox_UnusedTileSplit->setValue(projectConfig.unusedTileSplit);
ui->spinBox_MaxEvents->setValue(projectConfig.maxEventsPerGroup);
ui->spinBox_PlayerViewDistance_West->setValue(projectConfig.playerViewDistance.left());
ui->spinBox_PlayerViewDistance_North->setValue(projectConfig.playerViewDistance.top());
ui->spinBox_PlayerViewDistance_East->setValue(projectConfig.playerViewDistance.right());
ui->spinBox_PlayerViewDistance_South->setValue(projectConfig.playerViewDistance.bottom());
// Set (and sync) border metatile IDs
this->setBorderMetatileIds(false, projectConfig.newMapBorderMetatileIds);
@ -532,8 +544,8 @@ void ProjectSettingsEditor::save() {
projectConfig.defaultElevation = ui->spinBox_Elevation->value();
projectConfig.defaultCollision = ui->spinBox_Collision->value();
projectConfig.defaultMetatileId = ui->spinBox_FillMetatile->value();
projectConfig.collisionSheetHeight = ui->spinBox_MaxElevation->value() + 1;
projectConfig.collisionSheetWidth = ui->spinBox_MaxCollision->value() + 1;
projectConfig.defaultMapSize = QSize(ui->spinBox_MapWidth->value(), ui->spinBox_MapHeight->value());
projectConfig.collisionSheetSize = QSize(ui->spinBox_MaxElevation->value() + 1, ui->spinBox_MaxCollision->value() + 1);
projectConfig.metatileBehaviorMask = ui->spinBox_BehaviorMask->value();
projectConfig.metatileTerrainTypeMask = ui->spinBox_TerrainTypeMask->value();
projectConfig.metatileEncounterTypeMask = ui->spinBox_EncounterTypeMask->value();
@ -545,6 +557,10 @@ void ProjectSettingsEditor::save() {
projectConfig.unusedTileCovered = ui->spinBox_UnusedTileCovered->value();
projectConfig.unusedTileSplit = ui->spinBox_UnusedTileSplit->value();
projectConfig.maxEventsPerGroup = ui->spinBox_MaxEvents->value();
projectConfig.playerViewDistance = QMargins(ui->spinBox_PlayerViewDistance_West->value(),
ui->spinBox_PlayerViewDistance_North->value(),
ui->spinBox_PlayerViewDistance_East->value(),
ui->spinBox_PlayerViewDistance_South->value());
// Save line edit settings
projectConfig.prefabFilepath = ui->lineEdit_PrefabsPath->text();

View File

@ -145,15 +145,18 @@ void ResizeLayoutPopup::setupLayoutView() {
// Upper limits: maximum metatiles in a map formula:
// max = (width + 15) * (height + 14)
// This limit can be found in fieldmap.c in pokeruby/pokeemerald/pokefirered.
int numMetatiles = editor->project->getMapDataSize(rect.width() / 16, rect.height() / 16);
int maxMetatiles = editor->project->getMaxMapDataSize();
if (numMetatiles > maxMetatiles) {
QString errorText = QString("The maximum layout width and height is the following: (width + 15) * (height + 14) <= %1\n"
"The specified layout width and height was: (%2 + 15) * (%3 + 14) = %4")
.arg(maxMetatiles)
int size = editor->project->getMapDataSize(rect.width() / 16, rect.height() / 16);
int maxSize = editor->project->getMaxMapDataSize();
if (size > maxSize) {
QSize addition = editor->project->getMapSizeAddition();
QString errorText = QString("The maximum layout width and height is the following: (width + %1) * (height + %2) <= %3\n"
"The specified layout width and height was: (%4 + %1) * (%5 + %2) = %6")
.arg(addition.width())
.arg(addition.height())
.arg(maxSize)
.arg(rect.width() / 16)
.arg(rect.height() / 16)
.arg(numMetatiles);
.arg(size);
QMessageBox warning;
warning.setIcon(QMessageBox::Warning);
warning.setText("The specified width and height are too large.");