-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.hpp
144 lines (111 loc) · 3.84 KB
/
renderer.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include "game_event_manager.hpp"
#include "level.hpp"
#include "animation.hpp"
#include "animated_sprite.hpp"
#include "texture_cache.hpp"
#include "virtual_window_manager.hpp"
#include "virtual_window.hpp"
namespace rogue
{
class Level;
class Party;
class GameState;
class WindowEventManager;
class Renderer;
class AnimationManager;
//-----------------------------------------------------------------------------
class MainWindow : public VirtualWindow
{
public:
MainWindow(const string& title, const Vector2f& pos, const Vector2f& size, Renderer* renderer);
virtual void Draw();
virtual bool Init();
int TileAtPos(const GameState& state, int x, int y) const;
Pos PlayerToWorld(const Pos& pos) const;
Vector2f PlayerToWorldF(const Pos& pos) const;
private:
bool OnResize(const Event& event);
bool OnKeyPressed(const Event& event);
bool OnMouseButtonReleased(const Event& event);
bool OnMouseMove(const Event& event);
void VisibleArea(const Level* level, int* rows, int* cols) const;
void DrawQuad(const Pos& topLeft, u32 size, sf::Color color);
void DrawParty();
void DrawLevel();
void DrawMonsters();
void DrawAnimations();
void DrawHealthBar(int health, int maxHealth, const Pos &pos);
// Convert a pos in world (global) space to window space
Pos ToLocal(const Pos& pos) const;
Pos ToGlobal(const Pos& pos) const;
void PlayerInView();
Renderer* _renderer;
int _zoomLevel;
Pos _offset;
};
//-----------------------------------------------------------------------------
class CombatLogWindow : public VirtualWindow
{
public:
CombatLogWindow(const string& title, const Vector2f& pos, const Vector2f& size, Renderer* renderer);
virtual void Draw();
private:
Renderer* _renderer;
};
//-----------------------------------------------------------------------------
class PartyWindow : public VirtualWindow
{
public:
PartyWindow(const string& title, const Vector2f& pos, const Vector2f& size, Renderer* renderer);
virtual void Draw();
private:
Renderer* _renderer;
};
//-----------------------------------------------------------------------------
class Renderer
{
friend class PartyWindow;
friend class CombatLogWindow;
friend class MainWindow;
public:
Renderer(RenderWindow* window, WindowEventManager* eventManager, AnimationManager* animationManager);
~Renderer();
bool Init(const GameState& state);
void DrawWorld(const GameState& state);
void Update(const GameState& state, const sf::Event* event);
// Given the x/y window coordinates, return the tile at that position
int TileAtPos(const GameState& state, int x, int y) const;
void AddAnimation(
Animation::Id id,
const Pos& startPos,
const Pos& endPos,
const time_duration& duration);
private:
void OnAttack(const GameEvent& event);
void OnHeal(const GameEvent& event);
void OnDeath(const GameEvent& event);
void OnItemGained(const GameEvent& event);
void OnLevelGained(const GameEvent& event);
void DrawHealthBar(int health, int maxHealth, const Pos &pos);
void VisibleArea(const Level* level, int* rows, int* cols) const;
void AddToCombatLog(const string& msg);
RenderWindow *_window;
int _prevSelected;
vector<string> _combatLog;
map<LootItem::Type, Rect> _objectToTextureRect;
vector<HotloadSprite> _tileSprites;
Font _font;
TextureHandle _environmentTexture;
TextureHandle _characterTexture;
TextureHandle _objectTexture;
HotloadSprite _objectSprite;
VirtualWindowManager _windowManager;
deque<AnimationInstance> _activeAnimations;
EntityPtr _debugDump;
MainWindow* _mainWindow;
CombatLogWindow* _combatLogWindow;
PartyWindow* _partyWindow;
AnimationManager* _animationManager;
};
}