File indexing completed on 2024-04-21 04:03:08

0001 /***************************************************************************
0002                           cmapmanager.h  -  description
0003                              -------------------
0004     begin                : Wed Mar 7 2001
0005     copyright            : (C) 2001 by KMud Development 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 #ifndef CMAPMANAGER_H
0019 #define CMAPMANAGER_H
0020 
0021 
0022 #include <qfont.h>
0023 #include <qstring.h>
0024 #include <qcolor.h>
0025 #include <qpoint.h>
0026 #include <qobject.h>
0027 #include <QStringList>
0028 #include <qcursor.h>
0029 
0030 #include <kconfig.h>
0031 #include <kselectaction.h>
0032 #include <ktoggleaction.h>
0033 #include <kconfiggroup.h>
0034 
0035 #include "cactionbase.h"
0036 
0037 #include "cmapcommand.h"
0038 #include "cmapdata.h"
0039 
0040 #include <vector>
0041 
0042 #include <kmuddy_export.h>
0043 
0044 class CMapPath;
0045 class CMapText;
0046 class CMapRoom;
0047 class CMapView;
0048 class CMapLevel;
0049 class CMapToolBase;
0050 class CMapPluginBase;
0051 class CMapFilter;
0052 class CMapCmdGroup;
0053 class CMapFileFilterBase;
0054 class CMapClipboard;
0055 class CMapElementUtil;
0056 class CMapPropertiesPaneBase;
0057 class CMapZoneManager;
0058 
0059 class DlgMapRoomProperties;
0060 class DlgMapTextProperties;
0061 class DlgMapPathProperties;
0062 class DlgSpeedwalkProgress;
0063 class DlgMapDirections;
0064 class DlgMapMovement;
0065 class DlgMapColor;
0066 class DlgMapSpeedwalk;
0067 
0068 class KMuddyMapper;
0069 
0070 class QActionGroup;
0071 class QUndoStack;
0072 
0073 /**This is used to make the mapper perform different tasks
0074   *@author KMud Development Team
0075   */
0076 
0077 class KMUDDY_EXPORT CMapManager : public QObject, public cActionBase
0078 {
0079         Q_OBJECT
0080 public:
0081   /** Constructor used to creat the map manager */
0082   CMapManager (QWidget *parent, KMuddyMapper *mapper, int sess);
0083   ~CMapManager() override;
0084 
0085   void eventStringHandler (QString event, int, QString &par1, const QString &) override;
0086 
0087   /** Used to get a list of the plugins */
0088   std::vector<CMapPluginBase *> getPluginList();
0089   /**
0090    * Used to create a new view of the map
0091    * actually returns a CMapView*,  dynamic_cast if necessary
0092    */
0093   void openMapView();
0094   /**
0095    * Used to change the view to the given level
0096    */
0097   void displayLevel(CMapLevel *level, bool centerView);
0098   /**
0099    * Used to create a new view of the a given level and
0100    * center the view on the given position.
0101    */
0102   void openNewMapView(QPoint pos,CMapLevel *level);
0103   /** Create new map */
0104   void createNewMap();
0105   /** Used to set properties of the view widget */
0106   void setPropertiesAllViews(QCursor *cursor,bool mouseTracking);
0107   /** Create new bottom or top level depending on the given direction */
0108   CMapLevel *createLevel(directionTyp dir);
0109   /** Used to create a new room */
0110   void createRoom(QPoint pos,CMapLevel *level);
0111   /** Used to create a new path, this method will display the path properties
0112    * dialog to obtain the porperties of the path to be created               */
0113   CMapPath *createPath(CMapRoom *srcRoom,CMapRoom *destRoom);
0114   /** Used to create a new path*/
0115   CMapPath *createPath(QPoint srcPos,CMapLevel *srcLevel,directionTyp srcDir,
0116                        QPoint destPos,CMapLevel *destLevel,directionTyp destDir);
0117   /** Used to create a new path*/
0118   CMapPath *createPath (CMapRoom *srcRoom,directionTyp srcDir,CMapRoom *destRoom,directionTyp destDir,bool undoable = true,bool twoWay = true);
0119   /** Used to create a new text label */
0120   void createText(QPoint pos,CMapLevel *level,QString str,QFont font,QColor col);
0121   /** Used to create a new text label */
0122   void createText(QPoint pos,CMapLevel *level,QString str="");
0123 
0124   bool isClean() const;
0125   CMapFileFilterBase *nativeFilter(bool isLoad = true);
0126   /** Used to load a map */
0127   void importMap(const QString& url,CMapFileFilterBase *filter);
0128   /** Used to save a map */
0129   void exportMap(const QString& url,CMapFileFilterBase *filter);
0130 
0131   void setDefaultOptions();
0132   /** Used to read the map options */
0133   void readOptions();
0134   /** Used to write the map options */
0135   void saveGlobalConfig();
0136 
0137   /** Used to alter the path properties */
0138   bool propertiesPath(CMapPath *path);
0139   /** Used to alter the room properties */
0140   bool propertiesRoom(CMapRoom *room);
0141   /** Used to alter the text properties */
0142   bool propertiesText(CMapText *text);
0143 
0144   /** This method is used to covert cords so that they snap to the grid */
0145   QPoint cordsSnapGrid(QPoint oldPos);
0146 
0147   /** Used to get a pointer to the map data */
0148   CMapData *getMapData() const;
0149   /** Pointer to the zone info that stores levels */
0150   CMapZone *getZone(bool noCreate = false);
0151 
0152   /** Used to set the login room */
0153   void setLoginRoom(CMapRoom *room);
0154   /** Uesd to return teh login room */
0155   CMapRoom *getLoginRoom();
0156   /** Used to set the current room */
0157   void setCurrentRoom(CMapRoom *room);
0158   /** Uesd to return the current room */
0159   CMapRoom *getCurrentRoom();
0160   /** move the player relative to the current position of the player
0161     * This command has support for special paths, but can only move
0162     * anlong exsiting special paths. In other words, it is unable to
0163     * create special paths.
0164     */
0165   void movePlayerBy(directionTyp dir,bool create,QString specialCmd);
0166   /** move the player relative to the current position of the player
0167     * @param cmd The move command used to move the player */
0168   void movePlayerBy(QString cmd);
0169   /** This method is used to convert a direction into a offset */
0170   void directionToCord(directionTyp dir, QSize distance,QPoint *pos);
0171   /** This method is used to move the elements in a zone by the given vector */
0172   void moveMap(QPoint inc,CMapZone *zone);
0173   /** This method is used to make a path one way */
0174   void makePathOneWay(CMapPath *path);
0175   /** This method is used to make a path two way */
0176   void makePathTwoWay(CMapPath *path);
0177 
0178   /** Used to convert a text direction to a direction type */
0179   directionTyp textToDirection(QString text);
0180   /** Used to convert a direction type to a text direction */
0181   QString directionToText(directionTyp dir, QString specialCmd, bool shortName = false);
0182 
0183   /** Get the level that has focues at the moment */
0184   CMapView *getActiveView();
0185   /** Used to inform the various parts of the mapper that a element has changed */
0186   void changedElement(CMapElement *element);
0187   /** Used to inform the various parts of the mapper that a element has added */
0188   void addedElement(CMapElement *element);
0189   /** Used to walk the player in the mud to a given room */
0190   void walkPlayerTo(CMapRoom *toRoom);
0191   /** Used to inform to change the state of the navigation tools */
0192   void activeViewChanged(void);
0193 
0194   /** Used to cound the diffent elements of the map */
0195   void getCounts(int *levels,int *rooms,int *paths,int *labels);
0196 
0197   /** Get the opsite direction */
0198   directionTyp getOpsiteDirection(directionTyp dir);
0199 
0200   /** Used to add a command to the command history */
0201   void addCommand(CMapCommand *command);
0202 
0203   /** Used to set the current tool */
0204   void setCurrentTool(CMapToolBase *tool);
0205   /** Usd to get the current tool */
0206   CMapToolBase *getCurrentTool(void);
0207   /** Used to unselect all the elements in a level */
0208   void unselectElements(CMapLevel *level);
0209   /** Used to tell that map views that a level has chaned */
0210   void levelChanged(CMapLevel *level);
0211   /** This method puts a element into edit state */
0212   void setEditElement(CMapElement *element);
0213   /** This is used to remove edit state from element being edited */
0214   void unsetEditElement(void);
0215   /** This gets the element that is being edited */
0216   CMapElement *getEditElement(void);
0217   /** This cancels any editing */
0218   void stopEditing(void);
0219   /** Check to see if a string is a valid move command
0220     * @param dirCmd The command that was typed
0221     * @return True, if a valid command otherwise false */
0222   bool validMoveCmd(QString dirCmd);
0223   /** This is used to find a level with a given id
0224     * @param id The id of the level to find
0225     * @return Null if no level is found otherwise a pointer to the level */
0226   CMapLevel *findLevel(unsigned int id);
0227 
0228   /** Obtain the command history */
0229   QUndoStack *getCommandHistory() { return commandHistory; };
0230   /** Used to create a new command group */
0231   void openCommandGroup(QString name);
0232   /** Used to close a command group */
0233   void closeCommandGroup(void);
0234   /** Should only be called by CMapRoom.setCurrentRoom() */
0235   void setCurrentRoomWithoutUndo(CMapRoom *room);
0236   /** Should only be called by CMapRoom.setLoginRoom() */
0237   void setLoginRoomWithoutUndo(CMapRoom *room);
0238   /** Delete a level from the map */
0239   void deleteLevel(CMapLevel *level);
0240   /** Find the first room in the map,if one can't be found then create one */
0241   CMapRoom *findFirstRoom(CMapRoom *exsitingRoom);
0242   /** This is used to tell the mapper if commands should be added to the history list */
0243   void setUndoActive(bool active);
0244   int getUndoActive(void);
0245   /** Used to erase the map. This will erase all elements and can't be undone */
0246   void eraseMap(void);
0247   void eraseZone(CMapZone *zone);
0248 
0249   CMapZoneManager *zoneManager() { return m_zoneManager; }
0250 
0251   /** Used to repaint all the views */
0252   void redrawAllViews(void);
0253 
0254   /** This method is used to find a element from a list of properties
0255       * @param properties The list of proerties
0256       * @return The element if it's found otherwise NULL */
0257   CMapElement *findElement(KConfigGroup properties);
0258 
0259   void createGlobalConfigPanes();
0260   void createProfileConfigPanes();
0261 
0262   /** Return property panes from all the plugins */
0263   virtual QList<CMapPropertiesPaneBase *> createPropertyPanes(elementTyp type,CMapElement *element,QWidget *parent);
0264 
0265   QString defaultSavePath () const;
0266 
0267 public:
0268   /** A count of the number of levels created */
0269   unsigned int m_levelCount;
0270   /** A count of the number of zones created */
0271   unsigned int m_zoneCount;
0272 
0273 public slots:
0274   /** Used to delete a element from the map */
0275   void deleteElement(CMapElement *element,bool delOpsite = true);
0276   /** Used to abort a speedwalk that is in progress */
0277   void slotAbortSpeedwalk(void);
0278   
0279 
0280 private slots:
0281   void slotWalkPlayerAlongPath(void);
0282   
0283 private:
0284   /** Used to delete a element from the map, should only be used by the deleteElementMethod() */
0285   void deleteElementWithoutGroup(CMapElement *element,bool delOpsite = true);
0286   /** This will setup the import/export file filters */
0287   void initFileFilters();
0288   /** Used to create the plugins */
0289   void initPlugins();
0290 
0291 private:
0292   /** A list of import/export filters */
0293   std::vector<CMapFileFilterBase *> m_fileFilter;
0294   /** If this is true then commands are added to the history, otherwise they are not */
0295   bool m_commandsActive;
0296   /** The filter used to proces mud input/output */
0297   CMapFilter *filter;
0298   /** list of all the zones */
0299   CMapZoneManager *m_zoneManager;
0300   /** out session */
0301   int m_sessId;
0302   /** The element currenly being edited */
0303   CMapElement *elementEdit;
0304   /** The current tool */
0305   CMapToolBase *currentTool;
0306   /** A list of all loaded tools */
0307   std::vector<CMapToolBase *> toolList;
0308   /** The undo/redo history */
0309   QUndoStack *commandHistory;
0310   /** Points the command history currently being used */
0311   CMapCmdGroup *historyGroup;
0312   /** Used to store the amount of steps taken in the speedwalk */
0313   int speedwalkProgress;
0314   /** A pointer to the active map view */
0315   CMapView *activeView;
0316   /** The zone combo box */
0317   KSelectAction *zoneMenu;
0318   /** A pointer to the current room */
0319   CMapRoom *currentRoom;
0320   /** A pointer to the login room */
0321   CMapRoom *loginRoom;
0322   /** A pointer to the map data */
0323   CMapData *mapData;
0324   /** A list of all the plugins */
0325   std::vector<CMapPluginBase *> pluginList;
0326   /** pointer to the speedwalk status indicaor */
0327   DlgSpeedwalkProgress *speedwalkProgressDlg;
0328 
0329   // config pages:
0330   DlgMapDirections *mapDirection;
0331   DlgMapMovement *mapMovement;
0332   DlgMapColor *mapColor;
0333   DlgMapSpeedwalk *mapSpeedwalk;
0334 
0335   /** Used to tell if speedwalk is active */
0336   bool speedwalkActive;
0337   /** The rooms that are to be speed walked */
0338   QStringList pathToWalk;
0339 
0340   KMuddyMapper *mapperPlugin;
0341 private:
0342 
0343   /** This is a debug function and not for genreal use */
0344   void changeProperties(CMapElement *element,QString key,QString oldData,QString newData);
0345   /** This is a debug function and not for genreal use */
0346   void changeProperties(CMapElement *element,QString key,int oldData,int newData);
0347 
0348 public:
0349   /** This is a debug function and not for genreal use */
0350   void generateTestMap();
0351 };
0352 
0353 #endif