2012-01-30 01:00:12 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MAPVIEW_H
|
|
|
|
#define MAPVIEW_H
|
|
|
|
|
|
|
|
#include "declarations.h"
|
2012-07-29 05:34:40 +02:00
|
|
|
#include <framework/graphics/paintershaderprogram.h>
|
2012-01-30 01:00:12 +01:00
|
|
|
#include <framework/graphics/declarations.h>
|
2012-07-14 03:10:24 +02:00
|
|
|
#include <framework/luaengine/luaobject.h>
|
2012-01-31 18:06:55 +01:00
|
|
|
#include <framework/core/declarations.h>
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-06-22 05:14:13 +02:00
|
|
|
// @bindclass
|
2012-01-30 01:00:12 +01:00
|
|
|
class MapView : public LuaObject
|
|
|
|
{
|
2012-04-07 01:12:46 +02:00
|
|
|
public:
|
|
|
|
enum ViewMode {
|
2012-01-31 18:06:55 +01:00
|
|
|
NEAR_VIEW,
|
|
|
|
MID_VIEW,
|
|
|
|
FAR_VIEW,
|
|
|
|
HUGE_VIEW
|
2012-01-30 01:00:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
MapView();
|
2012-06-18 10:13:52 +02:00
|
|
|
~MapView();
|
2012-01-30 01:00:12 +01:00
|
|
|
void draw(const Rect& rect);
|
|
|
|
|
|
|
|
private:
|
2012-04-07 01:12:46 +02:00
|
|
|
void updateGeometry(const Size& visibleDimension, const Size& optimizedSize);
|
2012-01-31 18:06:55 +01:00
|
|
|
void updateVisibleTilesCache(int start = 0);
|
2012-01-30 01:00:12 +01:00
|
|
|
void requestVisibleTilesCacheUpdate() { m_mustUpdateVisibleTilesCache = true; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onTileUpdate(const Position& pos);
|
2012-06-22 07:26:22 +02:00
|
|
|
void onMapCenterChange(const Position& pos);
|
2012-01-30 01:00:12 +01:00
|
|
|
|
|
|
|
friend class Map;
|
|
|
|
|
|
|
|
public:
|
2012-04-07 01:12:46 +02:00
|
|
|
// floor visibility related
|
2012-01-30 01:00:12 +01:00
|
|
|
void lockFirstVisibleFloor(int firstVisibleFloor);
|
|
|
|
void unlockFirstVisibleFloor();
|
2012-04-07 01:12:46 +02:00
|
|
|
int getLockedFirstVisibleFloor() { return m_lockedFirstVisibleFloor; }
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
void setMultifloor(bool enable) { m_multifloor = enable; requestVisibleTilesCacheUpdate(); }
|
|
|
|
bool isMultifloor() { return m_multifloor; }
|
|
|
|
|
|
|
|
// map dimension related
|
2012-01-30 01:00:12 +01:00
|
|
|
void setVisibleDimension(const Size& visibleDimension);
|
2012-04-07 01:12:46 +02:00
|
|
|
Size getVisibleDimension() { return m_visibleDimension; }
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
// view mode related
|
|
|
|
void setViewMode(ViewMode viewMode);
|
|
|
|
ViewMode getViewMode() { return m_viewMode; }
|
|
|
|
void optimizeForSize(const Size& visibleSize);
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
void setAutoViewMode(bool enable);
|
|
|
|
bool isAutoViewModeEnabled() { return m_autoViewMode; }
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
// camera related
|
|
|
|
void followCreature(const CreaturePtr& creature);
|
2012-01-30 01:00:12 +01:00
|
|
|
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
2012-07-09 13:37:47 +02:00
|
|
|
bool isFollowingCreature() { return m_followingCreature && m_follow; }
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
void setCameraPosition(const Position& pos);
|
|
|
|
Position getCameraPosition();
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
// drawing related
|
|
|
|
void setDrawFlags(Otc::DrawFlags drawFlags) { m_drawFlags = drawFlags; requestVisibleTilesCacheUpdate(); }
|
|
|
|
Otc::DrawFlags getDrawFlags() { return m_drawFlags; }
|
|
|
|
|
|
|
|
void setDrawTexts(bool enable) { m_drawTexts = enable; }
|
|
|
|
bool isDrawingTexts() { return m_drawTexts; }
|
|
|
|
|
2012-06-22 07:26:22 +02:00
|
|
|
void setDrawMinimapColors(bool enable);
|
2012-04-07 01:12:46 +02:00
|
|
|
bool isDrawingMinimapColors() { return m_drawMinimapColors; }
|
|
|
|
|
|
|
|
void setAnimated(bool animated) { m_animated = animated; requestVisibleTilesCacheUpdate(); }
|
|
|
|
bool isAnimating() { return m_animated; }
|
|
|
|
|
2012-06-14 20:26:55 +02:00
|
|
|
void setShader(const PainterShaderProgramPtr& shader) { m_shader = shader; }
|
|
|
|
PainterShaderProgramPtr getShader() { return m_shader; }
|
|
|
|
|
2012-04-07 01:12:46 +02:00
|
|
|
// get tile
|
|
|
|
TilePtr getTile(const Point& mousePos, const Rect& mapRect);
|
2012-01-30 01:00:12 +01:00
|
|
|
|
2012-08-01 09:49:09 +02:00
|
|
|
MapViewPtr asMapView() { return static_self_cast<MapView>(); }
|
2012-01-30 01:00:12 +01:00
|
|
|
|
|
|
|
private:
|
2012-04-07 01:12:46 +02:00
|
|
|
int calcFirstVisibleFloor();
|
|
|
|
int calcLastVisibleFloor();
|
2012-06-05 17:36:27 +02:00
|
|
|
Point transformPositionTo2D(const Position& position, const Position& relativePosition) {
|
|
|
|
return Point((m_virtualCenterOffset.x + (position.x - relativePosition.x) - (relativePosition.z - position.z)) * m_tileSize,
|
|
|
|
(m_virtualCenterOffset.y + (position.y - relativePosition.y) - (relativePosition.z - position.z)) * m_tileSize);
|
|
|
|
}
|
2012-04-07 01:12:46 +02:00
|
|
|
|
2012-01-30 01:00:12 +01:00
|
|
|
int m_lockedFirstVisibleFloor;
|
|
|
|
int m_cachedFirstVisibleFloor;
|
|
|
|
int m_cachedLastVisibleFloor;
|
|
|
|
int m_tileSize;
|
2012-07-19 08:34:22 +02:00
|
|
|
int m_updateTilesPos;
|
2012-01-30 01:00:12 +01:00
|
|
|
Size m_drawDimension;
|
|
|
|
Size m_visibleDimension;
|
2012-04-07 01:12:46 +02:00
|
|
|
Size m_optimizedSize;
|
2012-01-30 01:00:12 +01:00
|
|
|
Point m_virtualCenterOffset;
|
2012-03-23 21:36:58 +01:00
|
|
|
Point m_visibleCenterOffset;
|
2012-01-30 01:00:12 +01:00
|
|
|
Position m_customCameraPosition;
|
2012-07-29 12:32:44 +02:00
|
|
|
stdext::boolean<true> m_mustUpdateVisibleTilesCache;
|
|
|
|
stdext::boolean<true> m_mustDrawVisibleTilesCache;
|
|
|
|
stdext::boolean<true> m_mustCleanFramebuffer;
|
|
|
|
stdext::boolean<true> m_multifloor;
|
|
|
|
stdext::boolean<true> m_animated;
|
|
|
|
stdext::boolean<true> m_autoViewMode;
|
|
|
|
stdext::boolean<true> m_drawTexts;
|
|
|
|
stdext::boolean<true> m_smooth;
|
|
|
|
stdext::boolean<false> m_drawMinimapColors;
|
|
|
|
stdext::boolean<true> m_follow;
|
2012-01-30 01:00:12 +01:00
|
|
|
std::vector<TilePtr> m_cachedVisibleTiles;
|
|
|
|
std::vector<CreaturePtr> m_cachedFloorVisibleCreatures;
|
|
|
|
CreaturePtr m_followingCreature;
|
|
|
|
FrameBufferPtr m_framebuffer;
|
2012-06-14 20:26:55 +02:00
|
|
|
PainterShaderProgramPtr m_shader;
|
2012-04-07 01:12:46 +02:00
|
|
|
ViewMode m_viewMode;
|
|
|
|
Otc::DrawFlags m_drawFlags;
|
2012-07-19 08:34:22 +02:00
|
|
|
std::vector<Point> m_spiral;
|
2012-01-30 01:00:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|