File indexing completed on 2024-04-28 11:50:09

0001 /***************************************************************************
0002                                cmapcmdmovemap.cpp
0003                              -------------------
0004     begin                : Thu Feb 28 2002
0005     copyright            : (C) 2002 by Kmud Developer Team
0006     email                : kmud-devel@kmud.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cmapcmdmovemap.h"
0019 
0020 #include "cmaplevel.h"
0021 #include "cmaproom.h"
0022 #include "cmappath.h"
0023 #include "cmapmanager.h"
0024 
0025 CMapCmdMoveMap::CMapCmdMoveMap(CMapManager *manager,QPoint offset,QString name) : CMapCommand(name)
0026 {
0027   m_Offset = offset;
0028   m_manager = manager;
0029 }
0030 
0031 CMapCmdMoveMap::~CMapCmdMoveMap()
0032 {
0033 }
0034 
0035 
0036 void CMapCmdMoveMap::redo()
0037 {
0038   moveMap(m_Offset);
0039 }
0040 
0041 void CMapCmdMoveMap::undo()
0042 {
0043   moveMap(QPoint(0, 0) - m_Offset);
0044 }
0045 
0046 /** This method is used to move the elements in a zone by the given vector */
0047 void CMapCmdMoveMap::moveMap(QPoint inc)
0048 {
0049   for (unsigned int idx = 0; idx < m_manager->getZone()->levelCount(); ++idx)
0050   {
0051     CMapLevel *level = m_manager->getZone()->getLevel(idx);
0052 
0053     foreach (CMapElement *el, level->getAllElements())
0054     {
0055       el->moveBy(inc);
0056       CMapRoom *room = dynamic_cast<CMapRoom *>(el);
0057       if (room) {
0058         foreach (CMapPath *path, *room->getPathList())
0059           path->moveBy(inc);
0060       }
0061     }
0062   }
0063 }