1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#ifndef PROGS_MANAPLUS_GUI_VIEWPORT_H |
25 |
|
|
#define PROGS_MANAPLUS_GUI_VIEWPORT_H |
26 |
|
|
|
27 |
|
|
#include "position.h" |
28 |
|
|
|
29 |
|
|
#include "enums/simpletypes/beingid.h" |
30 |
|
|
|
31 |
|
|
#include "gui/widgets/windowcontainer.h" |
32 |
|
|
|
33 |
|
|
#include "listeners/mouselistener.h" |
34 |
|
|
|
35 |
|
|
class ActorSprite; |
36 |
|
|
class Being; |
37 |
|
|
class FloorItem; |
38 |
|
|
class Graphics; |
39 |
|
|
class Map; |
40 |
|
|
class MapItem; |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* The viewport on the map. Displays the current map and handles mouse input |
44 |
|
|
* and the popup menu. |
45 |
|
|
*/ |
46 |
|
|
class Viewport final : public WindowContainer, |
47 |
|
|
public MouseListener, |
48 |
|
|
public ConfigListener |
49 |
|
|
{ |
50 |
|
|
public: |
51 |
|
|
/** |
52 |
|
|
* Constructor. |
53 |
|
|
*/ |
54 |
|
|
Viewport(); |
55 |
|
|
|
56 |
|
|
A_DELETE_COPY(Viewport) |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Destructor. |
60 |
|
|
*/ |
61 |
|
|
~Viewport() override final; |
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* Sets the map displayed by the viewport. |
65 |
|
|
*/ |
66 |
|
|
void setMap(Map *const map); |
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* Draws the viewport. |
70 |
|
|
*/ |
71 |
|
|
void draw(Graphics *const graphics) override final A_NONNULL(2); |
72 |
|
|
|
73 |
|
|
void safeDraw(Graphics *const graphics) override final A_NONNULL(2); |
74 |
|
|
|
75 |
|
|
/** |
76 |
|
|
* Implements player to keep following mouse. |
77 |
|
|
*/ |
78 |
|
|
void logic() override final; |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Toggles whether the path debug graphics are shown. normal, |
82 |
|
|
* debug with all images and grid, debug with out big images |
83 |
|
|
* and with out grid. |
84 |
|
|
*/ |
85 |
|
|
void toggleMapDrawType(); |
86 |
|
|
|
87 |
|
|
void toggleCameraMode(); |
88 |
|
|
|
89 |
|
|
/** |
90 |
|
|
* Handles mouse press on map. |
91 |
|
|
*/ |
92 |
|
|
void mousePressed(MouseEvent &event) override final; |
93 |
|
|
|
94 |
|
|
/** |
95 |
|
|
* Handles mouse move on map |
96 |
|
|
*/ |
97 |
|
|
void mouseDragged(MouseEvent &event) override final; |
98 |
|
|
|
99 |
|
|
/** |
100 |
|
|
* Handles mouse button release on map. |
101 |
|
|
*/ |
102 |
|
|
void mouseReleased(MouseEvent &event) override final; |
103 |
|
|
|
104 |
|
|
/** |
105 |
|
|
* Handles mouse move on map. |
106 |
|
|
*/ |
107 |
|
|
void mouseMoved(MouseEvent &event) override final; |
108 |
|
|
|
109 |
|
|
/** |
110 |
|
|
* A relevant config option changed. |
111 |
|
|
*/ |
112 |
|
|
void optionChanged(const std::string &name) override final; |
113 |
|
|
|
114 |
|
|
/** |
115 |
|
|
* Returns camera x offset in pixels. |
116 |
|
|
*/ |
117 |
|
|
int getCameraX() const noexcept2 A_WARN_UNUSED |
118 |
|
|
{ return mPixelViewX; } |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Returns camera y offset in pixels. |
122 |
|
|
*/ |
123 |
|
|
int getCameraY() const noexcept2 A_WARN_UNUSED |
124 |
|
|
{ return mPixelViewY; } |
125 |
|
|
|
126 |
|
|
/** |
127 |
|
|
* Changes viewpoint by relative pixel coordinates. |
128 |
|
|
*/ |
129 |
|
|
void scrollBy(const int x, const int y) |
130 |
|
|
{ mPixelViewX += x; mPixelViewY += y; } |
131 |
|
|
|
132 |
|
|
/** |
133 |
|
|
* Clear all hover item, being etc |
134 |
|
|
*/ |
135 |
|
|
void cleanHoverItems(); |
136 |
|
|
|
137 |
|
|
Map *getMap() const noexcept2 A_WARN_UNUSED |
138 |
|
|
{ return mMap; } |
139 |
|
|
|
140 |
|
|
void moveCamera(const int dx, const int dy); |
141 |
|
|
|
142 |
|
|
int getCameraRelativeX() const noexcept2 A_WARN_UNUSED |
143 |
|
|
{ return mCameraRelativeX; } |
144 |
|
|
|
145 |
|
|
int getCameraRelativeY() const noexcept2 A_WARN_UNUSED |
146 |
|
|
{ return mCameraRelativeY; } |
147 |
|
|
|
148 |
|
|
void setCameraRelativeX(const int n) |
149 |
|
|
{ mCameraRelativeX = n; updateMidVars(); } |
150 |
|
|
|
151 |
|
|
void setCameraRelativeY(const int n) |
152 |
|
|
{ mCameraRelativeY = n; updateMidVars(); } |
153 |
|
|
|
154 |
|
|
void moveCameraToActor(const BeingId actorId, |
155 |
|
|
const int x, |
156 |
|
|
const int y); |
157 |
|
|
|
158 |
|
|
void moveCameraToPosition(const int x, const int y); |
159 |
|
|
|
160 |
|
|
void moveCameraRelative(const int x, const int y); |
161 |
|
|
|
162 |
|
|
void returnCamera(); |
163 |
|
|
|
164 |
|
|
void getMouseTile(int &destX, int &destY) const; |
165 |
|
|
|
166 |
|
|
void videoResized(); |
167 |
|
|
|
168 |
|
|
int mMouseX; /**< Current mouse position in pixels. */ |
169 |
|
|
int mMouseY; /**< Current mouse position in pixels. */ |
170 |
|
|
|
171 |
|
|
protected: |
172 |
|
|
friend class ActorManager; |
173 |
|
|
|
174 |
|
|
/// Clears any matching hovers |
175 |
|
|
void clearHover(const ActorSprite *const actor); |
176 |
|
|
|
177 |
|
|
void updateMidVars(); |
178 |
|
|
|
179 |
|
|
void updateMaxVars(); |
180 |
|
|
|
181 |
|
|
static void validateSpeed(); |
182 |
|
|
|
183 |
|
|
private: |
184 |
|
|
/** |
185 |
|
|
* Finds a path from the player to the mouse, and draws it. This is for |
186 |
|
|
* debug purposes. |
187 |
|
|
*/ |
188 |
|
|
void drawDebugPath(Graphics *const graphics) A_NONNULL(2); |
189 |
|
|
|
190 |
|
|
/** |
191 |
|
|
* Draws the given path. |
192 |
|
|
*/ |
193 |
|
|
void drawPath(Graphics *const graphics, |
194 |
|
|
const Path &path, |
195 |
|
|
const Color &color) |
196 |
|
|
const A_NONNULL(2); |
197 |
|
|
|
198 |
|
|
bool leftMouseAction(); |
199 |
|
|
|
200 |
|
|
bool openContextMenu(const MouseEvent &event); |
201 |
|
|
|
202 |
|
|
void walkByMouse(const MouseEvent &event); |
203 |
|
|
|
204 |
|
|
void getMouseTile(const int x, |
205 |
|
|
const int y, |
206 |
|
|
int &destX, |
207 |
|
|
int &destY) const; |
208 |
|
|
|
209 |
|
|
/** |
210 |
|
|
* Make the player go to the mouse position. |
211 |
|
|
*/ |
212 |
|
|
void followMouse(); |
213 |
|
|
|
214 |
|
|
Map *mMap; /**< The current map. */ |
215 |
|
|
|
216 |
|
|
Being *mHoverBeing; /**< Being mouse is currently over. */ |
217 |
|
|
FloorItem *mHoverItem; /**< FloorItem mouse is currently over. */ |
218 |
|
|
MapItem *mHoverSign; /**< Map sign mouse is currently over. */ |
219 |
|
|
|
220 |
|
|
int mScrollRadius; |
221 |
|
|
int mScrollLaziness; |
222 |
|
|
int mScrollCenterOffsetX; |
223 |
|
|
int mScrollCenterOffsetY; |
224 |
|
|
int mMousePressX; |
225 |
|
|
int mMousePressY; |
226 |
|
|
int mPixelViewX; /**< Current viewpoint in pixels. */ |
227 |
|
|
int mPixelViewY; /**< Current viewpoint in pixels. */ |
228 |
|
|
int mMidTileX; |
229 |
|
|
int mMidTileY; |
230 |
|
|
int mViewXmax; |
231 |
|
|
int mViewYmax; |
232 |
|
|
|
233 |
|
|
time_t mLocalWalkTime; |
234 |
|
|
|
235 |
|
|
int mCameraRelativeX; |
236 |
|
|
int mCameraRelativeY; |
237 |
|
|
|
238 |
|
|
bool mShowBeingPopup; |
239 |
|
|
bool mSelfMouseHeal; |
240 |
|
|
bool mEnableLazyScrolling; |
241 |
|
|
bool mMouseDirectionMove; |
242 |
|
|
bool mLongMouseClick; |
243 |
|
|
bool mAllowMoveByMouse; |
244 |
|
|
bool mMouseClicked; |
245 |
|
|
bool mPlayerFollowMouse; |
246 |
|
|
}; |
247 |
|
|
|
248 |
|
|
extern Viewport *viewport; /**< The viewport. */ |
249 |
|
|
|
250 |
|
|
#endif // PROGS_MANAPLUS_GUI_VIEWPORT_H |