From 2a85592b36c1be57562f33af29a0305908fa7c92 Mon Sep 17 00:00:00 2001 From: alve Date: Sat, 14 Oct 2006 10:53:58 +0000 Subject: [PATCH] fixed forcing the path machine to specific room git-svn-id: svn://svn.code.sf.net/p/mmapper/code/trunk/mmapper@100 14c008a5-6e10-0410-bf79-c100e0f1932b --- src/display/mapcanvas.cpp | 45 ++++++++++++++++++++------------ src/display/mapcanvas.h | 3 +++ src/mainwindow/mainwindow.cpp | 12 ++++++++- src/mainwindow/mainwindow.h | 2 ++ src/mapdata/roomfactory.cpp | 4 +-- src/pathmachine/pathmachine.cpp | 44 ++++++++++++------------------- src/pathmachine/pathmachine.h | 19 ++++++++------ src/resources/icons/force.png | Bin 0 -> 220 bytes src/resources/mmapper2.qrc | 1 + 9 files changed, 76 insertions(+), 54 deletions(-) create mode 100644 src/resources/icons/force.png diff --git a/src/display/mapcanvas.cpp b/src/display/mapcanvas.cpp index b5fa9c951..bc86cd848 100644 --- a/src/display/mapcanvas.cpp +++ b/src/display/mapcanvas.cpp @@ -261,6 +261,28 @@ void MapCanvas::wheelEvent ( QWheelEvent * event ) } +void MapCanvas::forceMapperToRoom() { +const RoomSelection *tmpSel = NULL; +if (m_roomSelection) { + tmpSel = m_roomSelection; + m_roomSelection = 0; +} +else { + tmpSel = m_data->select(Coordinate(GLtoMap(m_selX1), GLtoMap(m_selY1), m_selLayer1)); +} + if(tmpSel->size() == 1) + { + if (Config().m_mapMode == 2) + { + const Room *r = tmpSel->values().front(); + emit charMovedEvent(createEvent( CID_UNKNOWN, getName(r), getDynamicDescription(r), getDescription(r), 0, 0)); + } + else + emit setCurrentRoom(tmpSel->keys().front()); + } + m_data->unselect(tmpSel); + updateGL(); +} void MapCanvas::mousePressEvent(QMouseEvent *event) { @@ -302,23 +324,14 @@ void MapCanvas::mousePressEvent(QMouseEvent *event) if ((event->buttons() & Qt::LeftButton) && (event->modifiers() & Qt::CTRL ) && (event->modifiers() & Qt::ALT ) ) - { - m_ctrlPressed = true; - m_altPressed = true; - - const RoomSelection *tmpSel = m_data->select(Coordinate(GLtoMap(m_selX1), GLtoMap(m_selY1), m_selLayer1)); - if(tmpSel->size() > 0) - { - if (Config().m_mapMode == 2) - { - const Room *r = tmpSel->values().front(); - emit charMovedEvent(createEvent( CID_UNKNOWN, getName(r), getDynamicDescription(r), getDescription(r), 0, 0)); - } - else - emit setCurrentRoom(tmpSel->keys().front()); + { + if (m_roomSelection) { + m_data->unselect(m_roomSelection); + m_roomSelection = 0; } - m_data->unselect(tmpSel); - updateGL(); + m_ctrlPressed = true; + m_altPressed = true; + forceMapperToRoom(); break; } diff --git a/src/display/mapcanvas.h b/src/display/mapcanvas.h index 550faa01e..8b9098861 100644 --- a/src/display/mapcanvas.h +++ b/src/display/mapcanvas.h @@ -69,7 +69,10 @@ class MapCanvas : public QGLWidget//, public RoomRecipient void drawRoom(const Room* room, const std::vector & rooms, const std::vector > & locks); + + public slots: + void forceMapperToRoom(); void onInfoMarksEditDlgClose(); void setCanvasMouseMode(CanvasMouseMode); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index c76638b4a..8d2e73c3b 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -397,6 +397,11 @@ void MainWindow::createActions() releaseAllPathsAct->setCheckable(false); connect(releaseAllPathsAct, SIGNAL(triggered()), m_pathMachine, SLOT(releaseAllPaths())); + forceRoomAct = new QAction(QIcon(":/icons/force.png"), tr("Force Path Machine to selected Room"), this); + forceRoomAct->setStatusTip(tr("Force Path Machine to selected Room")); + forceRoomAct->setCheckable(false); + connect(forceRoomAct, SIGNAL(triggered()), getCurrentMapWindow()->getCanvas(), SLOT(forceMapperToRoom())); + roomActGroup = new QActionGroup(this); roomActGroup->setExclusive(false); roomActGroup->addAction(editRoomSelectionAct); @@ -637,7 +642,11 @@ void MainWindow::setupToolBars() viewToolBar->addAction(zoomOutAct); viewToolBar->addAction(layerUpAct); viewToolBar->addAction(layerDownAct); - viewToolBar->addAction(releaseAllPathsAct); + + pathMachineToolBar = addToolBar(tr("Path Machine")); + pathMachineToolBar->setObjectName("PathMachineToolBar"); + pathMachineToolBar->addAction(releaseAllPathsAct); + pathMachineToolBar->addAction(forceRoomAct); //viewToolBar->addAction(m_dockDialog->toggleViewAction()); roomToolBar = addToolBar(tr("Rooms")); @@ -656,6 +665,7 @@ void MainWindow::setupToolBars() connectionToolBar->addAction(deleteConnectionSelectionAct); settingsToolBar = addToolBar(tr("Preferences")); + settingsToolBar->setObjectName("PreferencesToolBar"); settingsToolBar->addAction(preferencesAct); } diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 45c610f19..629a6392f 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -142,6 +142,7 @@ public slots: QToolBar *modeToolBar; QToolBar *mapModeToolBar; QToolBar *viewToolBar; + QToolBar *pathMachineToolBar; QToolBar *roomToolBar; QToolBar *connectionToolBar; QToolBar *settingsToolBar; @@ -205,6 +206,7 @@ public slots: QAction *mergeDownRoomSelectionAct; QAction *connectToNeighboursRoomSelectionAct; + QAction *forceRoomAct; QAction *releaseAllPathsAct; void createActions(); diff --git a/src/mapdata/roomfactory.cpp b/src/mapdata/roomfactory.cpp index d91f2c615..700cda3af 100644 --- a/src/mapdata/roomfactory.cpp +++ b/src/mapdata/roomfactory.cpp @@ -127,9 +127,9 @@ ComparisonResult RoomFactory::compare(const Room * room, const ParseEvent * even return CR_EQUAL; } - if (m_name.isEmpty() && m_desc.isEmpty() && (!updated)) + if (tolerance >= 100 || (m_name.isEmpty() && m_desc.isEmpty() && (!updated))) { - // user-created + // user-created oder explicit update return CR_TOLERANCE; } diff --git a/src/pathmachine/pathmachine.cpp b/src/pathmachine/pathmachine.cpp index 098283f20..f38b7cac5 100644 --- a/src/pathmachine/pathmachine.cpp +++ b/src/pathmachine/pathmachine.cpp @@ -41,24 +41,31 @@ PathMachine::PathMachine(AbstractRoomFactory * in_factory, bool threaded) : paths(new list) {} -void PathMachine::setCurrentRoom(uint id) +void PathMachine::setCurrentRoom(Approved * app) { + releaseAllPaths(); + const Room * perhaps = app->oneMatch(); + if (perhaps) { - Approved app(factory, lastEvent, params.matchingTolerance); - emit lookingForRooms(&app, id); + mostLikelyRoom = *perhaps; + emit playerMoved(mostLikelyRoom.getPosition()); + state = APPROVED; } - retry(); } void PathMachine::setCurrentRoom(const Coordinate & pos) { - { - Approved app(factory, lastEvent, params.matchingTolerance); - emit lookingForRooms(&app, pos); - } - retry(); + Approved app(factory, lastEvent, 100); + emit lookingForRooms(&app, pos); + setCurrentRoom(&app); } +void PathMachine::setCurrentRoom(uint id) +{ + Approved app(factory, lastEvent, 100); + emit lookingForRooms(&app, id); + setCurrentRoom(&app); +} void PathMachine::init() @@ -103,24 +110,7 @@ void PathMachine::retry() state = SYNCING; break; case EXPERIMENTING: - set prevPaths; - list * newPaths = new list; - for (list::iterator i = paths->begin(); i != paths->end(); ++i) - { - Path * working = *i; - Path * previous = working->getParent(); - previous->removeChild(working); - working->setParent(0); - working->deny(); - if (previous && (prevPaths.find(previous) == prevPaths.end())) - { - newPaths->push_back(previous); - prevPaths.insert(previous); - } - } - delete paths; - paths = newPaths; - if (paths->empty()) state = SYNCING; + releaseAllPaths(); break; } if (lastEvent) event(lastEvent); diff --git a/src/pathmachine/pathmachine.h b/src/pathmachine/pathmachine.h index d6026092f..1542610cf 100644 --- a/src/pathmachine/pathmachine.h +++ b/src/pathmachine/pathmachine.h @@ -53,9 +53,10 @@ class Approved; * and decides if rooms have to be added (and where) and where the player is * the results are published via signals */ -class PathMachine : public Component { -Q_OBJECT - public slots: +class PathMachine : public Component +{ + Q_OBJECT +public slots: virtual void event(ParseEvent *); virtual void deleteMostLikelyRoom(); virtual void releaseAllPaths(); @@ -63,7 +64,7 @@ Q_OBJECT virtual void setCurrentRoom(uint id); virtual void setCurrentRoom(const Coordinate & pos); - signals: +signals: void lookingForRooms(RoomRecipient *,ParseEvent *); void lookingForRooms(RoomRecipient *,uint); void lookingForRooms(RoomRecipient *,const Coordinate &); @@ -71,17 +72,18 @@ Q_OBJECT void createRoom(ParseEvent *, const Coordinate &); void scheduleAction(MapAction *); - public: +public: PathMachine(AbstractRoomFactory * factory, bool threaded = true); virtual void init(); virtual Qt::ConnectionType requiredConnectionType(const QString &); - - protected: + +protected: PathParameters params; void experimenting(ParseEvent * event); void syncing(ParseEvent * event); void approved(ParseEvent * event); void evaluatePaths(); + void setCurrentRoom(Approved * app); void tryExits(const Room *, RoomRecipient *, ParseEvent *, bool out); void tryExit(const Exit & possible, RoomRecipient * recipient, bool out); void tryCoordinate(const Room *, RoomRecipient *, ParseEvent *); @@ -94,7 +96,8 @@ Q_OBJECT char state; std::list * paths; -}; +} +; #endif diff --git a/src/resources/icons/force.png b/src/resources/icons/force.png new file mode 100644 index 0000000000000000000000000000000000000000..8e0d003d16ef614bc8722913fd3f8d11c67fce74 GIT binary patch literal 220 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJ#hxyXArY-_r+M=oP~dP``10?1 zAM;Y@zYYxQzH{aV8v8p;dBLF*mVEPVb*_;N7hi$@vy!Ssua=3+F$y;bbc%?s&}I@9 zcqfwLJcA)ZG)1jt^`)&F*`o9R|0?=o!q=ha@I%Utf5IhpC4v7LF4~sehT;lI|K4q1 z{YdK7^$oi<4%TRVP7X=TV_RWV&YUt^_-wt)(qq0K+)TO;Ow+frVJc`)-XSNOA#e8L Sihvlicons/mapmove.png icons/layerup.png icons/layerdown.png + icons/force.png pixmaps/splash20.png pixmaps/terrain0.png pixmaps/terrain1.png