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">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QGraphicsView" name="graphicsView_Collision">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
|
@ -1128,20 +1128,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<spacer name="horizontalSpacer_18">
|
||||
<item row="3" column="1">
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<item row="2" column="2">
|
||||
<spacer name="horizontalSpacer_19">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
|
@ -1154,19 +1154,42 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="verticalSpacer_6">
|
||||
<item row="2" column="0">
|
||||
<spacer name="horizontalSpacer_18">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
|
@ -31,15 +31,18 @@ public:
|
|||
this->recentMap = "";
|
||||
this->mapSortOrder = MapSortOrder::Group;
|
||||
this->prettyCursors = true;
|
||||
this->collisionOpacity = 50;
|
||||
}
|
||||
void setRecentProject(QString project);
|
||||
void setRecentMap(QString map);
|
||||
void setMapSortOrder(MapSortOrder order);
|
||||
void setPrettyCursors(bool enabled);
|
||||
void setCollisionOpacity(int opacity);
|
||||
QString getRecentProject();
|
||||
QString getRecentMap();
|
||||
MapSortOrder getMapSortOrder();
|
||||
bool getPrettyCursors();
|
||||
int getCollisionOpacity();
|
||||
protected:
|
||||
QString getConfigFilepath();
|
||||
void parseConfigKeyValue(QString key, QString value);
|
||||
|
@ -50,6 +53,7 @@ private:
|
|||
QString recentMap;
|
||||
MapSortOrder mapSortOrder;
|
||||
bool prettyCursors;
|
||||
int collisionOpacity;
|
||||
};
|
||||
|
||||
extern PorymapConfig porymapConfig;
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
int getWidth();
|
||||
int getHeight();
|
||||
QPixmap render(bool ignoreCache);
|
||||
QPixmap renderCollision(bool ignoreCache);
|
||||
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
||||
bool blockChanged(int, Blockdata*);
|
||||
void cacheBlockdata();
|
||||
void cacheCollision();
|
||||
|
|
|
@ -114,6 +114,7 @@ public:
|
|||
|
||||
int scale_exp = 0;
|
||||
double scale_base = sqrt(2); // adjust scale factor with this
|
||||
qreal collisionOpacity = 0.5;
|
||||
|
||||
void objectsView_onMousePress(QMouseEvent *event);
|
||||
void objectsView_onMouseMove(QMouseEvent *event);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QCloseEvent>
|
||||
#include <QAbstractItemModel>
|
||||
#include "project.h"
|
||||
#include "config.h"
|
||||
|
@ -52,7 +53,6 @@ private slots:
|
|||
void on_action_Exit_triggered();
|
||||
void on_comboBox_Song_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_Type_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 closeEvent(QCloseEvent *);
|
||||
|
||||
void eventTabChanged(int index);
|
||||
|
||||
void selectedEventIndexChanged(int index);
|
||||
|
||||
void on_horizontalSlider_CollisionTransparency_valueChanged(int value);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
TilesetEditor *tilesetEditor = nullptr;
|
||||
|
|
|
@ -10,17 +10,19 @@
|
|||
class CollisionPixmapItem : public MapPixmapItem {
|
||||
Q_OBJECT
|
||||
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){
|
||||
this->movementPermissionsSelector = movementPermissionsSelector;
|
||||
this->opacity = opacity;
|
||||
}
|
||||
MovementPermissionsSelector *movementPermissionsSelector;
|
||||
qreal *opacity;
|
||||
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void magicFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
virtual void draw(bool ignoreCache = false);
|
||||
void draw(bool ignoreCache = false);
|
||||
|
||||
signals:
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
||||
|
|
|
@ -119,6 +119,13 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
|||
this->mapSortOrder = MapSortOrder::Group;
|
||||
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 {
|
||||
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("pretty_cursors", this->prettyCursors ? "1" : "0");
|
||||
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
|
||||
map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -153,6 +161,11 @@ void PorymapConfig::setPrettyCursors(bool enabled) {
|
|||
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() {
|
||||
return this->recentProject;
|
||||
}
|
||||
|
@ -169,6 +182,10 @@ bool PorymapConfig::getPrettyCursors() {
|
|||
return this->prettyCursors;
|
||||
}
|
||||
|
||||
int PorymapConfig::getCollisionOpacity() {
|
||||
return this->collisionOpacity;
|
||||
}
|
||||
|
||||
const QMap<BaseGameVersion, QString> baseGameVersionMap = {
|
||||
{BaseGameVersion::pokeruby, "pokeruby"},
|
||||
{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;
|
||||
int width_ = getWidth();
|
||||
int height_ = getHeight();
|
||||
|
@ -141,7 +141,7 @@ QPixmap Map::renderCollision(bool ignoreCache) {
|
|||
painter.setOpacity(1);
|
||||
painter.drawImage(metatile_origin, metatile_image);
|
||||
painter.save();
|
||||
painter.setOpacity(0.55);
|
||||
painter.setOpacity(opacity);
|
||||
painter.drawImage(metatile_origin, collision_metatile_image);
|
||||
painter.restore();
|
||||
}
|
||||
|
|
|
@ -575,7 +575,7 @@ 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);
|
||||
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*)),
|
||||
this, SLOT(mouseEvent_collision(QGraphicsSceneMouseEvent*,CollisionPixmapItem*)));
|
||||
connect(collision_item, SIGNAL(hoveredMapMovementPermissionChanged(int, int)),
|
||||
|
|
|
@ -204,6 +204,10 @@ void MainWindow::loadUserSettings() {
|
|||
ui->actionBetter_Cursors->setChecked(porymapConfig.getPrettyCursors());
|
||||
this->editor->settings->betterCursors = porymapConfig.getPrettyCursors();
|
||||
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() {
|
||||
|
@ -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)
|
||||
{
|
||||
if (editor && editor->map) {
|
||||
|
@ -1483,6 +1480,12 @@ void MainWindow::selectedEventIndexChanged(int index)
|
|||
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()
|
||||
{
|
||||
if (editor && editor->selected_events) {
|
||||
|
@ -1753,3 +1756,9 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
|||
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) {
|
||||
if (map) {
|
||||
setPixmap(map->renderCollision(ignoreCache));
|
||||
setPixmap(map->renderCollision(*this->opacity, ignoreCache));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue