-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapView.hpp
127 lines (101 loc) · 2.77 KB
/
MapView.hpp
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
#pragma once
#include "Notification.h"
#include "Map.hpp"
#include "Buffor.hpp"
class MapView : public IMapView, public sf::Drawable
{
Map * mapHandler;
sf::VertexArray squares;
sf::Color mainColor;
int squareSize;
int margin;
int fontSize = 18;
Notification notification;
sf::Font font;
sf::Texture textures;
void renderTextures();
void setColor(int y, int x, sf::Color color); // Set tile color to any color
void setColor(int y, int x); // Set the tile color based at current map status
// (you can set all default tiles colors here)
void setTexture(int y, int x); // Set the tile texture
// Here's mapped number textures to proper map value
Buffor<sf::Vector2i> focusBuffor; // Buffor needed to preceed focus on the tiles
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const;
public:
MapView();
void handleMap(Map * map); // set the mapHandler pointer
// IMapView
virtual void notify(int y, int x); // Update tile (check IMapView description for more)
virtual void reload(); // Reloading view (check IMapView description for more)
///...................
void setMarginBetweenSquares(unsigned int size); // set the margin between the squares
void setSquareSize(int size); // set the square size
void setMainColor(sf::Color color);
// Getters
int getSquareSize();
int getMargin();
int getSizeX();
int getSizeY();
///...................
// Focus methods (called from MapController)
void removeFocus();
void addFocus();
void addToFocusBuffor(const sf::Vector2i & vector);
void popup(const std::string & str, int msDuration);
void hideNotifications();
void updateBottomLine();
int getFontSize();
};
// INLINE METHODS
///..............
inline void MapView::setMarginBetweenSquares(unsigned int size)
{
margin = size;
}
inline void MapView::setSquareSize(int size)
{
if (size > 300)
throw std::logic_error("Square size cannot be more that 300px!");
squareSize = size;
renderTextures();
}
inline void MapView::handleMap(Map * map)
{
mapHandler = map;
}
inline int MapView::getSizeX()
{
return (squareSize + margin) * mapHandler->getSizeX() - margin;
}
inline int MapView::getSizeY()
{
return (squareSize + margin) * mapHandler->getSizeY() - margin;
}
inline void MapView::setMainColor(sf::Color color)
{
mainColor = color;
}
inline int MapView::getSquareSize()
{
return squareSize;
}
inline int MapView::getMargin()
{
return margin;
}
inline void MapView::addToFocusBuffor(const sf::Vector2i & vector)
{
focusBuffor.push(vector);
}
inline void MapView::popup(const std::string & str, int msDuration)
{
notification.popupNotification(str, msDuration);
}
inline void MapView::hideNotifications()
{
notification.hide();
}
inline int MapView::getFontSize()
{
return fontSize;
}