decouple map and event edit modes

This commit is contained in:
garakmon 2020-05-17 21:25:28 -04:00 committed by huderlem
parent 9f5b13c287
commit 4ee22fa06a
4 changed files with 50 additions and 22 deletions

View file

@ -130,7 +130,8 @@ public:
QList<DraggablePixmapItem*> *events = nullptr;
QList<DraggablePixmapItem*> *selected_events = nullptr;
QString map_edit_mode;
QString map_edit_mode = "paint";
QString obj_edit_mode = "select";
int scale_exp = 0;
double scale_base = sqrt(2); // adjust scale factor with this

View file

@ -1058,10 +1058,10 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
item->shift(event);
}
} else if (item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
if (map_edit_mode == "paint" && event->type() == QEvent::GraphicsSceneMousePress) {
if (obj_edit_mode == "paint" && event->type() == QEvent::GraphicsSceneMousePress) {
// Right-clicking while in paint mode will change mode to select.
if (event->buttons() & Qt::RightButton) {
this->map_edit_mode = "select";
this->obj_edit_mode = "select";
this->settings->mapCursor = QCursor();
this->cursorMapTileRect->setSingleTileMode();
this->ui->toolButton_Paint->setChecked(false);
@ -1079,9 +1079,9 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
}
}
}
} else if (map_edit_mode == "select") {
} else if (obj_edit_mode == "select") {
// do nothing here, at least for now
} else if (map_edit_mode == "shift" && item->map) {
} else if (obj_edit_mode == "shift" && item->map) {
static QPoint selection_origin;
if (event->type() == QEvent::GraphicsSceneMouseRelease) {

View file

@ -1238,12 +1238,11 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index)
if (index == 0) {
ui->stackedWidget_MapEvents->setCurrentIndex(0);
on_tabWidget_2_currentChanged(ui->tabWidget_2->currentIndex());
clickToolButtonFromEditMode(editor->map_edit_mode);
} else if (index == 1) {
ui->stackedWidget_MapEvents->setCurrentIndex(1);
editor->setEditingObjects();
QStringList validOptions = {"select", "move", "paint", "shift"};
QString newEditMode = validOptions.contains(editor->map_edit_mode) ? editor->map_edit_mode : "select";
clickToolButtonFromEditMode(newEditMode);
clickToolButtonFromEditMode(editor->obj_edit_mode);
} else if (index == 3) {
editor->setEditingConnections();
}
@ -2054,7 +2053,11 @@ void MainWindow::on_toolButton_Open_Scripts_clicked()
void MainWindow::on_toolButton_Paint_clicked()
{
editor->map_edit_mode = "paint";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "paint";
else
editor->obj_edit_mode = "paint";
editor->settings->mapCursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10);
// do not stop single tile mode when editing collision
@ -2070,7 +2073,11 @@ void MainWindow::on_toolButton_Paint_clicked()
void MainWindow::on_toolButton_Select_clicked()
{
editor->map_edit_mode = "select";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "select";
else
editor->obj_edit_mode = "select";
editor->settings->mapCursor = QCursor();
editor->cursorMapTileRect->setSingleTileMode();
@ -2083,7 +2090,11 @@ void MainWindow::on_toolButton_Select_clicked()
void MainWindow::on_toolButton_Fill_clicked()
{
editor->map_edit_mode = "fill";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "fill";
else
editor->obj_edit_mode = "fill";
editor->settings->mapCursor = QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode();
@ -2096,7 +2107,11 @@ void MainWindow::on_toolButton_Fill_clicked()
void MainWindow::on_toolButton_Dropper_clicked()
{
editor->map_edit_mode = "pick";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "pick";
else
editor->obj_edit_mode = "pick";
editor->settings->mapCursor = QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode();
@ -2109,7 +2124,11 @@ void MainWindow::on_toolButton_Dropper_clicked()
void MainWindow::on_toolButton_Move_clicked()
{
editor->map_edit_mode = "move";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "move";
else
editor->obj_edit_mode = "move";
editor->settings->mapCursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7);
editor->cursorMapTileRect->setSingleTileMode();
@ -2122,7 +2141,11 @@ void MainWindow::on_toolButton_Move_clicked()
void MainWindow::on_toolButton_Shift_clicked()
{
editor->map_edit_mode = "shift";
if (ui->mainTabBar->currentIndex() == 0)
editor->map_edit_mode = "shift";
else
editor->obj_edit_mode = "shift";
editor->settings->mapCursor = QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10);
editor->cursorMapTileRect->setSingleTileMode();
@ -2134,12 +2157,18 @@ void MainWindow::on_toolButton_Shift_clicked()
}
void MainWindow::checkToolButtons() {
ui->toolButton_Paint->setChecked(editor->map_edit_mode == "paint");
ui->toolButton_Select->setChecked(editor->map_edit_mode == "select");
ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill");
ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
ui->toolButton_Move->setChecked(editor->map_edit_mode == "move");
ui->toolButton_Shift->setChecked(editor->map_edit_mode == "shift");
QString edit_mode;
if (ui->mainTabBar->currentIndex() == 0)
edit_mode = editor->map_edit_mode;
else
edit_mode = editor->obj_edit_mode;
ui->toolButton_Paint->setChecked(edit_mode == "paint");
ui->toolButton_Select->setChecked(edit_mode == "select");
ui->toolButton_Fill->setChecked(edit_mode == "fill");
ui->toolButton_Dropper->setChecked(edit_mode == "pick");
ui->toolButton_Move->setChecked(edit_mode == "move");
ui->toolButton_Shift->setChecked(edit_mode == "shift");
}
void MainWindow::clickToolButtonFromEditMode(QString editMode) {

View file

@ -71,8 +71,6 @@ void NewMapPopup::connectSignals() {
ui->spinBox_NewMap_Height->setMinimum(1);
ui->spinBox_NewMap_Width->setMaximum(project->getMaxMapWidth());
ui->spinBox_NewMap_Height->setMaximum(project->getMaxMapHeight());
ui->toolButton_NewMap_DimensionWarning->setIcon();
//ui->icon_NewMap_WarningIcon->setPixmap();
connect(ui->spinBox_NewMap_Width, QOverload<int>::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();});