File indexing completed on 2023-10-03 03:28:37

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