forked from thoth-medievia/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathT2DMap.h
261 lines (232 loc) · 8.95 KB
/
T2DMap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#ifndef MUDLET_T2DMAP_H
#define MUDLET_T2DMAP_H
/***************************************************************************
* Copyright (C) 2008-2012 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016, 2018-2019 by Stephen Lyons *
* - slysven@virginmedia.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pre_guard.h"
#include <QCache>
#include <QColor>
#include <QFont>
#include <QPixmap>
#include <QPointer>
#include <QString>
#include <QTreeWidget>
#include <QWidget>
#include "post_guard.h"
class Host;
class TArea;
class TMap;
class TRoom;
class QCheckBox;
class QComboBox;
class QElapsedTimer;
class QListWidgetItem;
class QPushButton;
class QTreeWidgetItem;
class T2DMap : public QWidget
{
Q_OBJECT
public:
Q_DISABLE_COPY(T2DMap)
explicit T2DMap(QWidget* parent = nullptr);
void paintMap();
void setMapZoom(int zoom);
QColor getColor(int id);
void init();
void exportAreaImage(int);
void paintEvent(QPaintEvent*) override;
void mousePressEvent(QMouseEvent*) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
bool event(QEvent* event) override;
void wheelEvent(QWheelEvent*) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* e) override;
// Was getTopLeft() which returned an index into mMultiSelectionList but that
// has been been changed to mMultiSelectionSet which cannot be accessed via
// an index in the same way - this function now sets
// mMultiSelectionHighlightRoomId and returns a (bool) on success or failure
// to do so.
bool getCenterSelection();
int getCenterSelectedRoomId() const { return mMultiSelectionHighlightRoomId; }
void setRoomSize(double);
void setExitSize(double);
void createLabel(QRectF labelRectangle);
// Clears cache so new symbols are built at next paintEvent():
void flushSymbolPixmapCache() {mSymbolPixmapCache.clear();}
void addSymbolToPixmapCache(const QString, const bool);
TMap* mpMap;
QPointer<Host> mpHost;
int xyzoom;
int mRX;
int mRY;
QPoint mPHighlight;
bool mPick;
int mTarget;
bool mStartSpeedWalk;
QMap<int, QPoint> mAreaExitsList;
// string list: 0 is event name, 1 is menu it is under if it is
QMap<QString, QStringList> mUserActions;
// unique name, List:parent name ("" if null), display name
QMap<QString, QStringList> mUserMenus;
bool mRoomBeingMoved;
// These are the on-screen width and height pixel numbers of the area for a
// room symbol, (for the non-grid map mode case what gets filled in is
// multipled by rsize which is 1.0 to exactly fill space between adjacent
// coordinates):
float mRoomWidth;
float mRoomHeight;
int mChosenRoomColor;
float xspan;
float yspan;
// Flag that the "drag to select rectangle"
// (mMultiRect) is active and is being *resized*
// by dragging
bool mMultiSelection;
QRectF mMultiRect;
bool mPopupMenu;
QSet<int> mMultiSelectionSet;
bool mNewMoveAction;
QRectF mMapInfoRect;
int mFontHeight;
bool mShowRoomID;
QMap<int, QPixmap> mPixMap;
int gzoom;
double rSize;
double eSize;
int mRoomID;
int mAreaID;
int mOx;
int mOy;
int mOz;
bool mShiftMode;
bool mShowInfo;
QComboBox* arealist_combobox;
QPointer<QDialog> mpCustomLinesDialog;
int mCustomLinesRoomFrom;
int mCustomLinesRoomTo;
QString mCustomLinesRoomExit;
// Pointers to controls that hold the settings
QPointer<QComboBox> mpCurrentLineStyle;
QPointer<QPushButton> mpCurrentLineColor;
QPointer<QCheckBox> mpCurrentLineArrow;
// Variables that hold the current or last used setting:
Qt::PenStyle mCurrentLineStyle;
QColor mCurrentLineColor;
bool mCurrentLineArrow;
bool mBubbleMode;
bool mMapperUseAntiAlias;
bool mLabelHighlighted;
bool mMoveLabel;
int mCustomLineSelectedRoom;
QString mCustomLineSelectedExit;
int mCustomLineSelectedPoint;
QTreeWidget mMultiSelectionListWidget;
bool mSizeLabel;
bool isCenterViewCall;
QString mHelpMsg;
void setPlayerRoomStyle(const int style);
public slots:
void slot_roomSelectionChanged();
void slot_deleteCustomExitLine();
void slot_moveLabel();
void slot_deleteLabel();
void slot_editLabel();
void slot_setPlayerLocation();
void slot_createLabel();
void slot_customLineColor();
void shiftZup();
void shiftZdown();
void slot_switchArea(const QString&);
void toggleShiftMode();
void shiftUp();
void shiftDown();
void shiftLeft();
void shiftRight();
void slot_setSymbol();
void slot_setImage();
void slot_movePosition();
void slot_defineNewColor();
void slot_selectRoomColor(QListWidgetItem* pI);
void slot_moveRoom();
void slot_deleteRoom();
void slot_changeColor();
void slot_spread();
void slot_shrink();
void slot_setExits();
void slot_setUserData();
void slot_lockRoom();
void slot_unlockRoom();
void slot_setRoomWeight();
void slot_setArea();
void slot_setCustomLine();
void slot_setCustomLine2();
void slot_userAction(QString);
void slot_setCustomLine2B(QTreeWidgetItem*, int);
void slot_undoCustomLineLastPoint();
void slot_doneCustomLine();
void slot_customLineProperties();
void slot_customLineAddPoint();
void slot_customLineRemovePoint();
void slot_cancelCustomLineDialog();
void slot_loadMap();
void slot_newMap();
private:
void resizeMultiSelectionWidget();
std::pair<int, int> getMousePosition();
bool checkButtonIsForGivenDirection(const QPushButton*, const QString&, const int&);
bool sizeFontToFitTextInRect(QFont&, const QRectF&, const QString&, const quint8 percentageMargin = 10);
void drawRoom(QPainter&, QFont&, QPen&, TRoom*, const bool isGridMode, const bool areRoomIdsLegible, const int, const float, const float, const bool);
void paintMapInfo(const QElapsedTimer& renderTimer, QPainter& painter, const bool showingCurrentArea, QColor& infoColor);
void paintAreaExits(QPainter& painter, QPen& pen, QList<int>& exitList, QList<int>& oneWayExits, const TArea* pArea, int zLevel, float exitWidth);
void initiateSpeeWalk(const int speedWalkStartRoomId, const int speedWalkTargetRoomId);
bool mDialogLock;
// When more than zero rooms are selected this
// is either the first (only) room in the set
// or if getCenterSelectionId() is used the
// room that is selected - this is so that it
// can be painted in yellow rather than orange
// when more than one room is selected to
// indicate the particular room that will be
// modified or be the center of those
// modifications. {for slot_spread(),
// slot_shrink(), slot_setUserData() - if ever
// implemented, slot_setExits(),
// slot_movePosition(), etc.} - previously have
// used -1 but is now reset to 0 if it is not valid.
int mMultiSelectionHighlightRoomId;
bool mIsSelectionSorting;
bool mIsSelectionSortByNames;
// Used to keep track of if sorting the multiple
// room listing/selection widget, and by what,
// as we now show room names (if present) as well.
bool mIsSelectionUsingNames;
QCache<QString, QPixmap> mSymbolPixmapCache;
ushort mSymbolFontSize;
QFont mMapSymbolFont;
QPointer<QAction> mpCreateRoomAction;
// in the players current area, how many digits does the biggest room number have?
quint8 mMaxRoomIdDigits;
// Holds the QRadialGradient details to use for the player room:
QGradientStops mPlayerRoomColorGradentStops;
private slots:
void slot_createRoom();
};
#endif // MUDLET_T2DMAP_H