Add transparency slider for overlayed collision tiles on the map
This commit is contained in:
parent
7c51f50d76
commit
022dc899da
11 changed files with 87 additions and 27 deletions
|
@ -1112,7 +1112,7 @@
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QGraphicsView" name="graphicsView_Collision">
|
<widget class="QGraphicsView" name="graphicsView_Collision">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
@ -1128,20 +1128,20 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="1">
|
||||||
<spacer name="horizontalSpacer_18">
|
<spacer name="verticalSpacer_6">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>20</width>
|
||||||
<height>20</height>
|
<height>40</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="2">
|
<item row="2" column="2">
|
||||||
<spacer name="horizontalSpacer_19">
|
<spacer name="horizontalSpacer_19">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
@ -1154,19 +1154,42 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="0">
|
||||||
<spacer name="verticalSpacer_6">
|
<spacer name="horizontalSpacer_18">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>40</width>
|
||||||
<height>40</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSlider" name="horizontalSlider_CollisionTransparency">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>100</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>50</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Transparency</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -31,15 +31,18 @@ public:
|
||||||
this->recentMap = "";
|
this->recentMap = "";
|
||||||
this->mapSortOrder = MapSortOrder::Group;
|
this->mapSortOrder = MapSortOrder::Group;
|
||||||
this->prettyCursors = true;
|
this->prettyCursors = true;
|
||||||
|
this->collisionOpacity = 50;
|
||||||
}
|
}
|
||||||
void setRecentProject(QString project);
|
void setRecentProject(QString project);
|
||||||
void setRecentMap(QString map);
|
void setRecentMap(QString map);
|
||||||
void setMapSortOrder(MapSortOrder order);
|
void setMapSortOrder(MapSortOrder order);
|
||||||
void setPrettyCursors(bool enabled);
|
void setPrettyCursors(bool enabled);
|
||||||
|
void setCollisionOpacity(int opacity);
|
||||||
QString getRecentProject();
|
QString getRecentProject();
|
||||||
QString getRecentMap();
|
QString getRecentMap();
|
||||||
MapSortOrder getMapSortOrder();
|
MapSortOrder getMapSortOrder();
|
||||||
bool getPrettyCursors();
|
bool getPrettyCursors();
|
||||||
|
int getCollisionOpacity();
|
||||||
protected:
|
protected:
|
||||||
QString getConfigFilepath();
|
QString getConfigFilepath();
|
||||||
void parseConfigKeyValue(QString key, QString value);
|
void parseConfigKeyValue(QString key, QString value);
|
||||||
|
@ -50,6 +53,7 @@ private:
|
||||||
QString recentMap;
|
QString recentMap;
|
||||||
MapSortOrder mapSortOrder;
|
MapSortOrder mapSortOrder;
|
||||||
bool prettyCursors;
|
bool prettyCursors;
|
||||||
|
int collisionOpacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern PorymapConfig porymapConfig;
|
extern PorymapConfig porymapConfig;
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
QPixmap render(bool ignoreCache);
|
QPixmap render(bool ignoreCache);
|
||||||
QPixmap renderCollision(bool ignoreCache);
|
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
||||||
bool blockChanged(int, Blockdata*);
|
bool blockChanged(int, Blockdata*);
|
||||||
void cacheBlockdata();
|
void cacheBlockdata();
|
||||||
void cacheCollision();
|
void cacheCollision();
|
||||||
|
|
|
@ -114,6 +114,7 @@ public:
|
||||||
|
|
||||||
int scale_exp = 0;
|
int scale_exp = 0;
|
||||||
double scale_base = sqrt(2); // adjust scale factor with this
|
double scale_base = sqrt(2); // adjust scale factor with this
|
||||||
|
qreal collisionOpacity = 0.5;
|
||||||
|
|
||||||
void objectsView_onMousePress(QMouseEvent *event);
|
void objectsView_onMousePress(QMouseEvent *event);
|
||||||
void objectsView_onMouseMove(QMouseEvent *event);
|
void objectsView_onMouseMove(QMouseEvent *event);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QGraphicsPixmapItem>
|
#include <QGraphicsPixmapItem>
|
||||||
#include <QGraphicsItemGroup>
|
#include <QGraphicsItemGroup>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QCloseEvent>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -52,7 +53,6 @@ private slots:
|
||||||
void on_action_Exit_triggered();
|
void on_action_Exit_triggered();
|
||||||
void on_comboBox_Song_activated(const QString &arg1);
|
void on_comboBox_Song_activated(const QString &arg1);
|
||||||
void on_comboBox_Location_activated(const QString &arg1);
|
void on_comboBox_Location_activated(const QString &arg1);
|
||||||
void on_comboBox_Visibility_activated(const QString &arg1);
|
|
||||||
void on_comboBox_Weather_activated(const QString &arg1);
|
void on_comboBox_Weather_activated(const QString &arg1);
|
||||||
void on_comboBox_Type_activated(const QString &arg1);
|
void on_comboBox_Type_activated(const QString &arg1);
|
||||||
void on_comboBox_BattleScene_activated(const QString &arg1);
|
void on_comboBox_BattleScene_activated(const QString &arg1);
|
||||||
|
@ -137,10 +137,14 @@ private slots:
|
||||||
|
|
||||||
void on_lineEdit_filterBox_textChanged(const QString &arg1);
|
void on_lineEdit_filterBox_textChanged(const QString &arg1);
|
||||||
|
|
||||||
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
void eventTabChanged(int index);
|
void eventTabChanged(int index);
|
||||||
|
|
||||||
void selectedEventIndexChanged(int index);
|
void selectedEventIndexChanged(int index);
|
||||||
|
|
||||||
|
void on_horizontalSlider_CollisionTransparency_valueChanged(int value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
TilesetEditor *tilesetEditor = nullptr;
|
TilesetEditor *tilesetEditor = nullptr;
|
||||||
|
|
|
@ -10,17 +10,19 @@
|
||||||
class CollisionPixmapItem : public MapPixmapItem {
|
class CollisionPixmapItem : public MapPixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings)
|
CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity)
|
||||||
: MapPixmapItem(map, metatileSelector, settings){
|
: MapPixmapItem(map, metatileSelector, settings){
|
||||||
this->movementPermissionsSelector = movementPermissionsSelector;
|
this->movementPermissionsSelector = movementPermissionsSelector;
|
||||||
|
this->opacity = opacity;
|
||||||
}
|
}
|
||||||
MovementPermissionsSelector *movementPermissionsSelector;
|
MovementPermissionsSelector *movementPermissionsSelector;
|
||||||
|
qreal *opacity;
|
||||||
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
||||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||||
virtual void magicFill(QGraphicsSceneMouseEvent*);
|
virtual void magicFill(QGraphicsSceneMouseEvent*);
|
||||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||||
virtual void draw(bool ignoreCache = false);
|
void draw(bool ignoreCache = false);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
||||||
|
|
|
@ -119,6 +119,13 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
this->mapSortOrder = MapSortOrder::Group;
|
this->mapSortOrder = MapSortOrder::Group;
|
||||||
logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value));
|
logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value));
|
||||||
}
|
}
|
||||||
|
} else if (key == "collision_opacity") {
|
||||||
|
bool ok;
|
||||||
|
this->collisionOpacity = qMax(0, qMin(100, value.toInt(&ok)));
|
||||||
|
if (!ok) {
|
||||||
|
logWarn(QString("Invalid config value for collision_opacity: '%1'. Must be an integer.").arg(value));
|
||||||
|
this->collisionOpacity = 50;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
||||||
}
|
}
|
||||||
|
@ -130,6 +137,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
|
||||||
map.insert("recent_map", this->recentMap);
|
map.insert("recent_map", this->recentMap);
|
||||||
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
|
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
|
||||||
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
|
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
|
||||||
|
map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +161,11 @@ void PorymapConfig::setPrettyCursors(bool enabled) {
|
||||||
this->save();
|
this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PorymapConfig::setCollisionOpacity(int opacity) {
|
||||||
|
this->collisionOpacity = opacity;
|
||||||
|
// don't auto-save here because this can be called very frequently.
|
||||||
|
}
|
||||||
|
|
||||||
QString PorymapConfig::getRecentProject() {
|
QString PorymapConfig::getRecentProject() {
|
||||||
return this->recentProject;
|
return this->recentProject;
|
||||||
}
|
}
|
||||||
|
@ -169,6 +182,10 @@ bool PorymapConfig::getPrettyCursors() {
|
||||||
return this->prettyCursors;
|
return this->prettyCursors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PorymapConfig::getCollisionOpacity() {
|
||||||
|
return this->collisionOpacity;
|
||||||
|
}
|
||||||
|
|
||||||
const QMap<BaseGameVersion, QString> baseGameVersionMap = {
|
const QMap<BaseGameVersion, QString> baseGameVersionMap = {
|
||||||
{BaseGameVersion::pokeruby, "pokeruby"},
|
{BaseGameVersion::pokeruby, "pokeruby"},
|
||||||
{BaseGameVersion::pokeemerald, "pokeemerald"},
|
{BaseGameVersion::pokeemerald, "pokeemerald"},
|
||||||
|
|
|
@ -110,7 +110,7 @@ void Map::cacheCollision() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Map::renderCollision(bool ignoreCache) {
|
QPixmap Map::renderCollision(qreal opacity, bool ignoreCache) {
|
||||||
bool changed_any = false;
|
bool changed_any = false;
|
||||||
int width_ = getWidth();
|
int width_ = getWidth();
|
||||||
int height_ = getHeight();
|
int height_ = getHeight();
|
||||||
|
@ -141,7 +141,7 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
||||||
painter.setOpacity(1);
|
painter.setOpacity(1);
|
||||||
painter.drawImage(metatile_origin, metatile_image);
|
painter.drawImage(metatile_origin, metatile_image);
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setOpacity(0.55);
|
painter.setOpacity(opacity);
|
||||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -575,7 +575,7 @@ void Editor::displayMapMovementPermissions() {
|
||||||
scene->removeItem(collision_item);
|
scene->removeItem(collision_item);
|
||||||
delete collision_item;
|
delete collision_item;
|
||||||
}
|
}
|
||||||
collision_item = new CollisionPixmapItem(map, this->movement_permissions_selector_item, this->metatile_selector_item, this->settings);
|
collision_item = new CollisionPixmapItem(map, this->movement_permissions_selector_item, this->metatile_selector_item, this->settings, &this->collisionOpacity);
|
||||||
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
connect(collision_item, SIGNAL(mouseEvent(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)),
|
||||||
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
||||||
connect(collision_item, SIGNAL(hoveredMapMovementPermissionChanged(int, int)),
|
connect(collision_item, SIGNAL(hoveredMapMovementPermissionChanged(int, int)),
|
||||||
|
|
|
@ -204,6 +204,10 @@ void MainWindow::loadUserSettings() {
|
||||||
ui->actionBetter_Cursors->setChecked(porymapConfig.getPrettyCursors());
|
ui->actionBetter_Cursors->setChecked(porymapConfig.getPrettyCursors());
|
||||||
this->editor->settings->betterCursors = porymapConfig.getPrettyCursors();
|
this->editor->settings->betterCursors = porymapConfig.getPrettyCursors();
|
||||||
mapSortOrder = porymapConfig.getMapSortOrder();
|
mapSortOrder = porymapConfig.getMapSortOrder();
|
||||||
|
ui->horizontalSlider_CollisionTransparency->blockSignals(true);
|
||||||
|
this->editor->collisionOpacity = static_cast<qreal>(porymapConfig.getCollisionOpacity()) / 100;
|
||||||
|
ui->horizontalSlider_CollisionTransparency->setValue(porymapConfig.getCollisionOpacity());
|
||||||
|
ui->horizontalSlider_CollisionTransparency->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::openRecentProject() {
|
bool MainWindow::openRecentProject() {
|
||||||
|
@ -482,13 +486,6 @@ void MainWindow::on_comboBox_Location_activated(const QString &location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Visibility_activated(const QString &requiresFlash)
|
|
||||||
{
|
|
||||||
if (editor && editor->map) {
|
|
||||||
editor->map->requiresFlash = requiresFlash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_comboBox_Weather_activated(const QString &weather)
|
void MainWindow::on_comboBox_Weather_activated(const QString &weather)
|
||||||
{
|
{
|
||||||
if (editor && editor->map) {
|
if (editor && editor->map) {
|
||||||
|
@ -1483,6 +1480,12 @@ void MainWindow::selectedEventIndexChanged(int index)
|
||||||
editor->selectMapEvent(selectedEvent);
|
editor->selectMapEvent(selectedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_horizontalSlider_CollisionTransparency_valueChanged(int value) {
|
||||||
|
this->editor->collisionOpacity = static_cast<qreal>(value) / 100;
|
||||||
|
porymapConfig.setCollisionOpacity(value);
|
||||||
|
this->editor->collision_item->draw(true);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_toolButton_deleteObject_clicked()
|
void MainWindow::on_toolButton_deleteObject_clicked()
|
||||||
{
|
{
|
||||||
if (editor && editor->selected_events) {
|
if (editor && editor->selected_events) {
|
||||||
|
@ -1753,3 +1756,9 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
||||||
this->tilesetEditor->activateWindow();
|
this->tilesetEditor->activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
|
porymapConfig.save();
|
||||||
|
|
||||||
|
QMainWindow::closeEvent(event);
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
|
|
||||||
void CollisionPixmapItem::draw(bool ignoreCache) {
|
void CollisionPixmapItem::draw(bool ignoreCache) {
|
||||||
if (map) {
|
if (map) {
|
||||||
setPixmap(map->renderCollision(ignoreCache));
|
setPixmap(map->renderCollision(*this->opacity, ignoreCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue