void LVL_ModeFill::mouseMove(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->clearSelection(); if((!LvlPlacingItems::layer.isEmpty() && LvlPlacingItems::layer!="Default")|| (mouseEvent->modifiers() & Qt::ControlModifier) ) s->setMessageBoxItem(true, mouseEvent->scenePos(), ((!LvlPlacingItems::layer.isEmpty() && LvlPlacingItems::layer!="Default")? LvlPlacingItems::layer + ", ":"") + (s->cursor? ( QString::number( s->cursor->scenePos().toPoint().x() ) + "x" + QString::number( s->cursor->scenePos().toPoint().y() ) ) :"") ); else s->setMessageBoxItem(false); if(s->cursor) { s->cursor->setPos( QPointF(s->applyGrid( QPointF(mouseEvent->scenePos()- QPointF(LvlPlacingItems::c_offset_x, LvlPlacingItems::c_offset_y)).toPoint(), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset))); s->cursor->show(); } }
void HistoryElementRemoveWarp::undo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; lvlScene->m_data->doors.insert(m_removedDoor.meta.index, m_removedDoor); QComboBox* warplist = MainWinConnect::pMainWin->dock_LvlWarpProps->getWarpList(); warplist->insertItem(m_removedDoor.meta.index, QString("%1: x%2y%3 <=> x%4y%5") .arg(m_removedDoor.meta.array_id).arg(m_removedDoor.ix).arg(m_removedDoor.iy).arg(m_removedDoor.ox).arg(m_removedDoor.oy), m_removedDoor.meta.array_id); if(warplist->count() > (int)m_removedDoor.meta.index) { warplist->setCurrentIndex( m_removedDoor.meta.index ); } else { warplist->setCurrentIndex( warplist->count()-1 ); } if(m_removedDoor.isSetOut){ lvlScene->placeDoorExit(m_removedDoor); } if(m_removedDoor.isSetIn){ lvlScene->placeDoorEnter(m_removedDoor); } MainWinConnect::pMainWin->dock_LvlWarpProps->setDoorData(-2); }
void HistoryElementRemoveWarp::redo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; lvlScene->doorPointsSync( m_removedDoor.meta.array_id, true); for(int i=0;i<lvlScene->m_data->doors.size();i++) { if(lvlScene->m_data->doors[i].meta.array_id==m_removedDoor.meta.array_id) { lvlScene->m_data->doors.removeAt(i); break; } } QComboBox* warplist = MainWinConnect::pMainWin->dock_LvlWarpProps->getWarpList(); for(int i = 0; i < warplist->count(); i++){ if((unsigned int)warplist->itemData(i).toInt() == m_removedDoor.meta.array_id){ warplist->removeItem(i); break; } } if(warplist->count()<=0) MainWinConnect::pMainWin->dock_LvlWarpProps->setWarpRemoveButtonEnabled(false); MainWinConnect::pMainWin->dock_LvlWarpProps->setDoorData(-2); }
void LVL_ModeCircle::mouseMove(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if(!LvlPlacingItems::layer.isEmpty() && LvlPlacingItems::layer!="Default") s->setLabelBoxItem(true, mouseEvent->scenePos(), LvlPlacingItems::layer + ", " + QString::number( mouseEvent->scenePos().toPoint().x() ) + "x" + QString::number( mouseEvent->scenePos().toPoint().y() ) ); else s->setLabelBoxItem(false); if(s->m_cursorItemImg && s->m_cursorItemImg->isVisible()) { QGraphicsEllipseItem * cur = dynamic_cast<QGraphicsEllipseItem *>(s->m_cursorItemImg); QPoint hw = s->applyGrid( mouseEvent->scenePos().toPoint(), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset); QSize hs = QSize( (long)fabs(drawStartPos.x() - hw.x()), (long)fabs( drawStartPos.y() - hw.y() ) ); cur->setRect(0,0, hs.width(), hs.height()); cur->setPos(((hw.x() < drawStartPos.x() )? hw.x() : drawStartPos.x()), ((hw.y() < drawStartPos.y() )? hw.y() : drawStartPos.y())); } }
void HistoryElementReplacePlayerPoint::historyRemovePlayerPoint(const PlayerPoint &/*plr*/, QGraphicsItem* item) { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; dynamic_cast<ItemPlayerPoint *>(item)->removeFromArray(); lvlScene->removeItem(item); delete item; bool wasPlaced = false; PlayerPoint oPoint; if(!m_oldPos.isNull()) { if(m_oldPos.type() == QVariant::List) { QList<QVariant> mData = m_oldPos.toList(); if(mData.size() == 5) { oPoint.id = (unsigned int)mData[0].toInt(); oPoint.x = (long)mData[1].toLongLong(); oPoint.y = (long)mData[2].toLongLong(); oPoint.w = (long)mData[3].toLongLong(); oPoint.h = (long)mData[4].toLongLong(); if(oPoint.id>0 && !(oPoint.x == 0 && oPoint.y == 0)) wasPlaced = true; } } } if(wasPlaced) lvlScene->placePlayerPoint(oPoint); }
void LVL_ModeResize::mousePress(QGraphicsSceneMouseEvent *mouseEvent) { Q_UNUSED(mouseEvent); if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->m_skipChildMousePressEvent = true; s->mousePressEvent(mouseEvent); dontCallEvent = true; }
void LVL_ModeResize::mouseMove(QGraphicsSceneMouseEvent *mouseEvent) { Q_UNUSED(mouseEvent); if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->clearSelection(); s->MouseMoveEventOnly = true; s->mouseMoveEvent(mouseEvent); dontCallEvent = true; }
void HistoryElementReplacePlayerPoint::redo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; lvlScene->placePlayerPoint(m_plr); }
void HistoryElementSettingsSection::undo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; int sectionID = m_sectionID; QVariant extraData = m_extraData; if(m_subtype == HistorySettings::SETTING_SECWRAPH){ lvlScene->m_data->sections[sectionID].wrap_h = !extraData.toBool(); } else if(m_subtype == HistorySettings::SETTING_SECWRAPV){ lvlScene->m_data->sections[sectionID].wrap_v = !extraData.toBool(); } else if(m_subtype == HistorySettings::SETTING_SECOFFSCREENEXIT){ lvlScene->m_data->sections[sectionID].OffScreenEn = !extraData.toBool(); } else if(m_subtype == HistorySettings::SETTING_SECNOBACK){ lvlScene->m_data->sections[sectionID].lock_left_scroll = !extraData.toBool(); } else if(m_subtype == HistorySettings::SETTING_SECUNDERWATER){ lvlScene->m_data->sections[sectionID].underwater = !extraData.toBool(); } else if(m_subtype == HistorySettings::SETTING_SECBACKGROUNDIMG){ lvlScene->ChangeSectionBG(extraData.toList()[0].toInt(), m_sectionID); } else if(m_subtype == HistorySettings::SETTING_SECMUSIC){ lvlScene->m_data->sections[sectionID].music_id = extraData.toList()[0].toInt(); } else if(m_subtype == HistorySettings::SETTING_SECCUSTOMMUSIC){ lvlScene->m_data->sections[sectionID].music_file = extraData.toList()[0].toString(); } MainWinConnect::pMainWin->dock_LvlSectionProps->refreshFileData(); LvlMusPlay::updateMusic(); MainWinConnect::pMainWin->setMusic(LvlMusPlay::musicButtonChecked); }
void LVL_ModeResize::set() { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->clearSelection(); s->resetCursor(); s->m_eraserIsEnabled=false; s->m_pastingMode=false; s->m_busyMode=true; s->m_disableMoveItems=true; s->m_viewPort->setInteractive(true); s->m_viewPort->setCursor(Themes::Cursor(Themes::cursor_resizing)); s->m_viewPort->setDragMode(QGraphicsView::NoDrag); }
void LVL_ModeResize::set() { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->EraserEnabled=false; s->PasteFromBuffer=false; s->DrawMode=true; s->disableMoveItems=true; s->clearSelection(); s->resetCursor(); s->_viewPort->setInteractive(true); s->_viewPort->setCursor(Themes::Cursor(Themes::cursor_resizing)); s->_viewPort->setDragMode(QGraphicsView::NoDrag); }
void HistoryElementResizeSection::redo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; lvlScene->m_data->sections[m_sectionID].size_left = m_newSize.left(); lvlScene->m_data->sections[m_sectionID].size_right = m_newSize.right(); lvlScene->m_data->sections[m_sectionID].size_top = m_newSize.top(); lvlScene->m_data->sections[m_sectionID].size_bottom = m_newSize.bottom(); lvlScene->ChangeSectionBG(lvlScene->m_data->sections[m_sectionID].background, m_sectionID); if(m_sectionID == lvlScene->m_data->CurSection){ lvlScene->drawSpace(); } }
void LVL_ModeCircle::set() { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->clearSelection(); s->resetResizers(); s->m_eraserIsEnabled=false; s->m_pastingMode=false; s->m_busyMode=true; s->m_disableMoveItems=false; s->m_viewPort->setInteractive(true); s->m_viewPort->setCursor(Themes::Cursor(Themes::cursor_square_fill)); s->m_viewPort->setDragMode(QGraphicsView::NoDrag); s->m_viewPort->setRenderHint(QPainter::Antialiasing, true); s->m_viewPort->viewport()->setMouseTracking(true); }
void LVL_ModeResize::keyRelease(QKeyEvent *keyEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); switch(keyEvent->key()) { case (Qt::Key_Escape): s->resetResizers(); break; case (Qt::Key_Enter): case (Qt::Key_Return): s->applyResizers(); //setSectionResizer(false, true); break; default: break; } }
void LVL_ModePlace::set() { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); s->EraserEnabled=false; s->PasteFromBuffer=false; s->DrawMode=true; s->disableMoveItems=false; s->clearSelection(); s->resetResizers(); s->_viewPort->setInteractive(true); s->_viewPort->setCursor(Themes::Cursor(Themes::cursor_placing)); s->_viewPort->setDragMode(QGraphicsView::NoDrag); s->_viewPort->setRenderHint(QPainter::Antialiasing, true); s->_viewPort->viewport()->setMouseTracking(true); }
void LVL_ModeFill::mousePress(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if( mouseEvent->buttons() & Qt::RightButton ) { MainWinConnect::pMainWin->on_actionSelect_triggered(); dontCallEvent = true; s->IsMoved = true; return; } if(! mouseEvent->buttons() & Qt::LeftButton) return; if(s->cursor) { attemptFlood(s); s->Debugger_updateItemList(); } }
void LVL_ModePlace::mouseRelease(QGraphicsSceneMouseEvent *mouseEvent) { Q_UNUSED(mouseEvent); if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if(s->placingItem == LvlScene::PLC_Door) { MainWinConnect::pMainWin->on_actionSelect_triggered(); dontCallEvent = true; return; } else { if(!s->overwritedItems.blocks.isEmpty()|| !s->overwritedItems.bgo.isEmpty()|| !s->overwritedItems.npc.isEmpty() ) { s->addOverwriteHistory(s->overwritedItems, s->placingItems); s->overwritedItems.blocks.clear(); s->overwritedItems.bgo.clear(); s->overwritedItems.npc.clear(); s->placingItems.blocks.clear(); s->placingItems.bgo.clear(); s->placingItems.npc.clear(); } else if(!s->placingItems.blocks.isEmpty()|| !s->placingItems.bgo.isEmpty()|| !s->placingItems.npc.isEmpty()) { s->addPlaceHistory(s->placingItems); s->placingItems.blocks.clear(); s->placingItems.bgo.clear(); s->placingItems.npc.clear(); } } }
void LVL_ModePlace::mousePress(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if( mouseEvent->buttons() & Qt::RightButton ) { item_rectangles::clearArray(); MainWinConnect::pMainWin->on_actionSelect_triggered(); dontCallEvent = true; s->IsMoved = true; return; } s->last_block_arrayID=s->LvlData->blocks_array_id; s->last_bgo_arrayID=s->LvlData->bgo_array_id; s->last_npc_arrayID=s->LvlData->npc_array_id; if(LvlPlacingItems::npcSpecialAutoIncrement) s->IncrementingNpcSpecialSpin = LvlPlacingItems::npcSpecialAutoIncrement_begin; if(s->cursor) { s->cursor->setPos( QPointF(s->applyGrid( mouseEvent->scenePos().toPoint()- QPoint(LvlPlacingItems::c_offset_x, LvlPlacingItems::c_offset_y), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset))); } s->placeItemUnderCursor(); s->Debugger_updateItemList(); s->MousePressEventOnly = true; s->mousePressEvent(mouseEvent); dontCallEvent = true; }
void LVL_ModeCircle::mousePress(QGraphicsSceneMouseEvent *mouseEvent) { if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); MainWindow* mw = s->m_mw; if( mouseEvent->buttons() & Qt::RightButton ) { item_rectangles::clearArray(); QMetaObject::invokeMethod(mw, "on_actionSelect_triggered"); dontCallEvent = true; s->m_mouseIsMovedAfterKey = true; return; } s->m_lastBlockArrayID=s->m_data->blocks_array_id; s->m_lastBgoArrayID=s->m_data->bgo_array_id; s->m_lastNpcArrayID=s->m_data->npc_array_id; LogDebug(QString("Circle mode %1").arg(s->m_editMode)); if(s->m_cursorItemImg) { drawStartPos = QPointF(s->applyGrid( mouseEvent->scenePos().toPoint(), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset)); s->m_cursorItemImg->setPos( drawStartPos ); s->m_cursorItemImg->setVisible(true); QPoint hw = s->applyGrid( mouseEvent->scenePos().toPoint(), LvlPlacingItems::gridSz, LvlPlacingItems::gridOffset); QSize hs = QSize( (long)fabs(drawStartPos.x() - hw.x()), (long)fabs( drawStartPos.y() - hw.y() ) ); dynamic_cast<QGraphicsEllipseItem *>(s->m_cursorItemImg)->setRect(0,0, hs.width(), hs.height()); } }
void HistoryElementAddWarp::undo() { if(!m_scene) return; LvlScene* lvlScene; if(!(lvlScene = qobject_cast<LvlScene*>(m_scene))) return; lvlScene->doorPointsSync((unsigned int)m_array_id,true); for(int i = 0; i < lvlScene->m_data->doors.size(); i++) { if(lvlScene->m_data->doors[i].meta.array_id==(unsigned int)m_array_id) { lvlScene->m_data->doors.removeAt(i); break; } } bool found = false; QComboBox* warplist = MainWinConnect::pMainWin->dock_LvlWarpProps->getWarpList(); if((warplist->currentIndex()==m_listindex)&&(warplist->count()>2)) { warplist->setCurrentIndex(warplist->currentIndex()-1); } LogDebug("HistoryManager -> check index"); if(m_listindex < warplist->count()){ if(m_array_id == warplist->itemData(m_listindex).toInt()){ found = true; warplist->removeItem(m_listindex); } } LogDebug(QString("HistoryManager -> found = %1").arg(found)); if(!found) { found=false; for(int i = 0; i < warplist->count(); i++) { if(m_array_id == warplist->itemData(i).toInt()) { warplist->removeItem(i); found=true; break; } } } LogDebug(QString("HistoryManager -> found and removed = %1").arg(found)); if(warplist->count()<=0) MainWinConnect::pMainWin->dock_LvlWarpProps->setWarpRemoveButtonEnabled(false); MainWinConnect::pMainWin->dock_LvlWarpProps->setDoorData(-2); //warplist->update(); //warplist->repaint(); }
void MainWindow::on_actionClear_NPC_garbadge_triggered() { if(activeChildWindow() != WND_Level) return; LevelEdit *box = activeLvlEditWin(); if(!box) return; if(!box->sceneCreated) return; QList<LevelNPC> _fine_npcs; QList<LevelNPC> _found_garbage; for(int i = 0; i < box->LvlData.npc.size(); i++) { LevelNPC npc = box->LvlData.npc[i]; bool fine = true; for(int j = 0; j < _fine_npcs.size(); j++) { if(npc.id != _fine_npcs[j].id) continue; if(npc.x != _fine_npcs[j].x) continue; if(npc.y != _fine_npcs[j].y) continue; if(npc.layer != _fine_npcs[j].layer) continue; if(npc.generator != _fine_npcs[j].generator) continue; if(npc.msg != _fine_npcs[j].msg) continue; if(npc.event_activate != _fine_npcs[j].event_activate) continue; if(npc.event_die != _fine_npcs[j].event_die) continue; if(npc.event_talk != _fine_npcs[j].event_talk) continue; if(npc.event_emptylayer != _fine_npcs[j].event_emptylayer) continue; fine = false; _found_garbage.push_back(npc); break; } if(fine) _fine_npcs.push_back(npc); } if(_found_garbage.isEmpty()) QMessageBox::information(this, tr("NPC garbage clean-up"), tr("Everything is fine, level has no NPC garbage!"), QMessageBox::Ok); else { QMessageBox::StandardButton x = QMessageBox::question(this, tr("NPC garbage clean-up"), tr("Found %1 junk NPC's. Do you want to remove them?\nPress \"Help\" to show info about the junk NPCs we found.").arg(_found_garbage.size()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Help); if((x != QMessageBox::Yes) && (x != QMessageBox::Help)) return; bool help = (x == QMessageBox::Help); LvlScene *sc = box->scene; sc->clearSelection(); LvlScene::PGE_ItemList items = sc->items(); LevelData removedItems; QPointF jumpTo; for(int i = 0; i < items.size(); i++) { if(items[i]->data(ITEM_TYPE).toString() == "NPC") { ItemNPC *npc = qgraphicsitem_cast<ItemNPC *>(items[i]); if(!npc) continue; for(int j = 0; j < _found_garbage.size(); j++) { if(npc->m_data.meta.array_id == _found_garbage[j].meta.array_id) { if(help) //Select & jump { npc->setSelected(true); jumpTo = npc->scenePos(); } else //Delete actual NPC { removedItems.npc.push_back(npc->m_data); npc->removeFromArray(); delete npc; } break; } } } } if(!help) { if(!removedItems.npc.isEmpty()) sc->m_history->addRemove(removedItems); QMessageBox::information(this, tr("NPC garbage clean-up"), tr("NPC garbabe has been removed!\nThis operation can be undone with Ctrl+Z or Edit/Undo action."), QMessageBox::Ok); } else { box->goTo(jumpTo.x(), jumpTo.y(), true, QPoint(0, 0), true); } } }
void LVL_ModeCircle::mouseRelease(QGraphicsSceneMouseEvent *mouseEvent) { Q_UNUSED(mouseEvent); if(!scene) return; LvlScene *s = dynamic_cast<LvlScene *>(scene); if(s->m_cursorItemImg) { QGraphicsEllipseItem * cur = dynamic_cast<QGraphicsEllipseItem *>(s->m_cursorItemImg); // /////////// Don't draw with zero width or height ////////////// if( (cur->rect().width()==0) || (cur->rect().height()==0)) { s->m_cursorItemImg->hide(); dontCallEvent = true; return; } // /////////////////////////////////////////////////////////////// if( ((s->m_placingItemType==LvlScene::PLC_Block)&&(!LvlPlacingItems::sizableBlock))|| (s->m_placingItemType==LvlScene::PLC_BGO)) { item_rectangles::drawRound(s, QRect(cur->x(), cur->y(), cur->rect().width(), cur->rect().height()), QSize(LvlPlacingItems::itemW, LvlPlacingItems::itemH) ); } switch(s->m_placingItemType) { case LvlScene::PLC_Block: { //LvlPlacingItems::waterSet.quicksand = (LvlPlacingItems::waterType==1); if(LvlPlacingItems::sizableBlock) { LvlPlacingItems::blockSet.x = s->m_cursorItemImg->scenePos().x(); LvlPlacingItems::blockSet.y = s->m_cursorItemImg->scenePos().y(); LvlPlacingItems::blockSet.w = cur->rect().width(); LvlPlacingItems::blockSet.h = cur->rect().height(); //here define placing water item. s->m_data->blocks_array_id++; LvlPlacingItems::blockSet.meta.array_id = s->m_data->blocks_array_id; s->m_data->blocks.push_back(LvlPlacingItems::blockSet); s->placeBlock(LvlPlacingItems::blockSet, true); LevelData plSzBlock; plSzBlock.blocks.push_back(LvlPlacingItems::blockSet); s->m_history->addPlace(plSzBlock); s->Debugger_updateItemList(); break; } else { s->placeItemsByRectArray(); //LogDebug("clear collision buffer"); s->m_emptyCollisionCheck = false; s->collisionCheckBuffer.clear(); #ifdef _DEBUG_ LogDebug("Done"); #endif s->Debugger_updateItemList(); break; } } case LvlScene::PLC_BGO: { s->placeItemsByRectArray(); s->m_emptyCollisionCheck = false; s->collisionCheckBuffer.clear(); s->Debugger_updateItemList(); break; } } s->m_data->meta.modified = true; s->m_cursorItemImg->hide(); } }