Mana
Loading...
Searching...
No Matches
viewport.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "eventlistener.h"
25#include "position.h"
26
27#include "utils/time.h"
28
30
31#include <guichan/mouselistener.hpp>
32
33#include <list>
34
35class ActorSprite;
36class Being;
37class BeingPopup;
38class FloorItem;
39class Graphics;
40class ImageSet;
41class Item;
42class Map;
43class PopupMenu;
44class Window;
45
47const int walkingMouseDelay = 500;
48
57class Viewport : public WindowContainer, public gcn::MouseListener,
58 public EventListener
59{
60 public:
61 Viewport();
62
63 ~Viewport() override;
64
68 void setMap(Map *map);
69
73 void draw(gcn::Graphics *graphics) override;
74
78 void logic() override;
79
83 void setDebugFlags(int debugFlags);
84
88 void mousePressed(gcn::MouseEvent &event) override;
89
93 void mouseDragged(gcn::MouseEvent &event) override;
94
98 void mouseReleased(gcn::MouseEvent &event) override;
99
103 void mouseMoved(gcn::MouseEvent &event) override;
104
109 void showPopup(Window *parent, int x, int y, Item *item,
110 bool isInventory = true, bool canDrop = true);
111
116 void closePopupMenu();
117
121 int getCameraX() const { return (int) mPixelViewX; }
122
126 int getCameraY() const { return (int) mPixelViewY; }
127
131 int getMouseX() const { return mMouseX; }
132
136 int getMouseY() const { return mMouseY; }
137
141 void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; }
142
146 Map *getCurrentMap() const { return mMap; }
147
151 void hideBeingPopup();
152
156 void shakeScreen(int intensity);
157
161 void shakeScreen(float x, float y, float decay = 0.95f, unsigned duration = 0);
162
167 { mShakeEffects.clear(); }
168
169 void event(Event::Channel channel, const Event &event) override;
170
171 private:
177
181 void _drawPath(Graphics *graphics, const Path &path,
182 gcn::Color color = gcn::Color(255, 0, 0));
183
187 void _followMouse();
188
192 void updateCursorType();
193
194 Map *mMap = nullptr;
196 int mMouseX = 0;
197 int mMouseY = 0;
198 float mPixelViewX = 0.0f;
199 float mPixelViewY = 0.0f;
200 int mDebugFlags = 0;
203 {
204 float x;
205 float y;
206 float decay;
207 float age = 0.0f;
209 };
210 std::list<ShakeEffect> mShakeEffects;
211
212 bool mPlayerFollowMouse = false;
213
217 Being *mHoverBeing = nullptr;
220};
221
222extern Viewport *viewport;
A popup that displays information about a being.
Definition beingpopup.h:32
Definition being.h:65
Definition event.h:42
Channel
Definition event.h:45
An item lying on the floor.
Definition flooritem.h:32
A central point of control for graphics.
Definition graphics.h:78
Stores a set of subimages originating from a single image.
Definition imageset.h:34
Represents one or more instances of a certain item type.
Definition item.h:35
A tile map.
Definition map.h:147
Window showing popup menu.
Definition popupmenu.h:37
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
The viewport on the map.
Definition viewport.h:59
Map * getCurrentMap() const
Returns the current map object.
Definition viewport.h:146
int mMouseX
Current mouse position in pixels.
Definition viewport.h:196
int getMouseY() const
Returns mouse y in pixels.
Definition viewport.h:136
void mousePressed(gcn::MouseEvent &event) override
Handles mouse press on map.
Definition viewport.cpp:411
void _drawPath(Graphics *graphics, const Path &path, gcn::Color color=gcn::Color(255, 0, 0))
Draws the given path.
Definition viewport.cpp:392
void logic() override
Implements player to keep following mouse.
Definition viewport.cpp:262
std::list< ShakeEffect > mShakeEffects
Definition viewport.h:210
void mouseMoved(gcn::MouseEvent &event) override
Handles mouse move on map.
Definition viewport.cpp:549
Being * mHoverBeing
Being mouse is currently over.
Definition viewport.h:217
int getMouseX() const
Returns mouse x in pixels.
Definition viewport.h:131
Timer mLocalWalkTimer
Timer for sending walk messages.
Definition viewport.h:214
void setMap(Map *map)
Sets the map displayed by the viewport.
Definition viewport.cpp:66
PopupMenu * mPopupMenu
Popup menu.
Definition viewport.h:216
void event(Event::Channel channel, const Event &event) override
Definition viewport.cpp:605
float mPixelViewY
Current viewpoint in pixels.
Definition viewport.h:199
bool mPlayerFollowMouse
Definition viewport.h:212
void mouseDragged(gcn::MouseEvent &event) override
Handles mouse move on map.
Definition viewport.cpp:516
int mDebugFlags
Flags for showing debug graphics.
Definition viewport.h:200
BeingPopup * mBeingPopup
Being information popup.
Definition viewport.h:219
void closePopupMenu()
Closes the popup menu.
Definition viewport.cpp:544
void shakeScreenStop()
Stops all active screen shake effects.
Definition viewport.h:166
void draw(gcn::Graphics *graphics) override
Draws the viewport.
Definition viewport.cpp:75
void scrollBy(float x, float y)
Changes viewpoint by relative pixel coordinates.
Definition viewport.h:141
Map * mMap
The current map.
Definition viewport.h:194
float mPixelViewX
Current viewpoint in pixels.
Definition viewport.h:198
void _followMouse()
Make the player go to the mouse position.
Definition viewport.cpp:271
int getCameraY() const
Returns camera y offset in pixels.
Definition viewport.h:126
void _drawDebugPath(Graphics *graphics)
Finds a path from the player to the mouse, and draws it.
Definition viewport.cpp:300
void setDebugFlags(int debugFlags)
Sets which debug flags (see Map::DebugFlags) should be enabled.
Definition viewport.cpp:593
~Viewport() override
Definition viewport.cpp:60
void hideBeingPopup()
Hides the BeingPopup.
Definition viewport.cpp:600
void updateCursorType()
Updates the cursor type.
Definition viewport.cpp:567
void mouseReleased(gcn::MouseEvent &event) override
Handles mouse button release on map.
Definition viewport.cpp:533
void showPopup(Window *parent, int x, int y, Item *item, bool isInventory=true, bool canDrop=true)
Shows a popup for an item.
Definition viewport.cpp:538
int getCameraX() const
Returns camera x offset in pixels.
Definition viewport.h:121
FloorItem * mHoverItem
FloorItem mouse is currently over.
Definition viewport.h:218
void shakeScreen(int intensity)
Makes the screen shake in a random direction.
Definition viewport.cpp:243
int mMouseY
Current mouse position in pixels.
Definition viewport.h:197
A window container.
A window.
Definition window.h:59
Graphics * graphics
Definition client.cpp:104
std::list< Position > Path
Definition position.h:40
Viewport * viewport
The viewport.
Definition game.cpp:115
const int walkingMouseDelay
Delay between two mouse calls when dragging mouse and move the player.
Definition viewport.h:47