| 1 |
/* |
| 2 |
Copyright (c) 2010 Peter "Corsix" Cawley |
| 3 |
|
| 4 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 |
this software and associated documentation files (the "Software"), to deal in |
| 6 |
the Software without restriction, including without limitation the rights to |
| 7 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 9 |
so, subject to the following conditions: |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in all |
| 12 |
copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 |
SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef CORSIX_TH_TH_MAP_OVERLAYS_H_ |
| 24 |
#define CORSIX_TH_TH_MAP_OVERLAYS_H_ |
| 25 |
|
| 26 |
#include <cstddef> |
| 27 |
#include <string> |
| 28 |
#include <string_view> |
| 29 |
|
| 30 |
class font; |
| 31 |
class level_map; |
| 32 |
class render_target; |
| 33 |
class sprite_sheet; |
| 34 |
|
| 35 |
class map_overlay { |
| 36 |
public: |
| 37 |
virtual ~map_overlay() = default; |
| 38 |
|
| 39 |
virtual void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY, |
| 40 |
const level_map* pMap, int iNodeX, int iNodeY) = 0; |
| 41 |
}; |
| 42 |
|
| 43 |
class map_overlay_pair : public map_overlay { |
| 44 |
public: |
| 45 |
map_overlay_pair() = default; |
| 46 |
~map_overlay_pair() override; |
| 47 |
|
| 48 |
void set_first(map_overlay* pOverlay, bool bTakeOwnership); |
| 49 |
void set_second(map_overlay* pOverlay, bool bTakeOwnership); |
| 50 |
|
| 51 |
void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY, |
| 52 |
const level_map* pMap, int iNodeX, int iNodeY) override; |
| 53 |
|
| 54 |
private: |
| 55 |
map_overlay *first{nullptr}, *second{nullptr}; |
| 56 |
bool owns_first{false}, owns_second{false}; |
| 57 |
}; |
| 58 |
|
| 59 |
class map_typical_overlay : public map_overlay { |
| 60 |
public: |
| 61 |
map_typical_overlay() = default; |
| 62 |
~map_typical_overlay() override; |
| 63 |
|
| 64 |
void set_sprites(sprite_sheet* pSheet, bool bTakeOwnership); |
| 65 |
void set_font(::font* font, bool take_ownership); |
| 66 |
|
| 67 |
protected: |
| 68 |
void draw_text(render_target* pCanvas, int iX, int iY, std::string_view str); |
| 69 |
|
| 70 |
sprite_sheet* sprites{nullptr}; |
| 71 |
::font* font{nullptr}; |
| 72 |
|
| 73 |
private: |
| 74 |
bool owns_sprites{false}; |
| 75 |
bool owns_font{false}; |
| 76 |
}; |
| 77 |
|
| 78 |
class map_text_overlay : public map_typical_overlay { |
| 79 |
public: |
| 80 |
map_text_overlay() = default; |
| 81 |
~map_text_overlay() override = default; |
| 82 |
|
| 83 |
void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY, |
| 84 |
const level_map* pMap, int iNodeX, int iNodeY) override; |
| 85 |
|
| 86 |
void set_background_sprite(size_t iSprite); |
| 87 |
virtual const std::string get_text(const level_map* pMap, int iNodeX, |
| 88 |
int iNodeY) = 0; |
| 89 |
|
| 90 |
private: |
| 91 |
size_t background_sprite{}; |
| 92 |
}; |
| 93 |
|
| 94 |
class map_positions_overlay final : public map_text_overlay { |
| 95 |
public: |
| 96 |
const std::string get_text(const level_map* pMap, int iNodeX, |
| 97 |
int iNodeY) override; |
| 98 |
}; |
| 99 |
|
| 100 |
class map_flags_overlay final : public map_typical_overlay { |
| 101 |
public: |
| 102 |
void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY, |
| 103 |
const level_map* pMap, int iNodeX, int iNodeY) override; |
| 104 |
}; |
| 105 |
|
| 106 |
class map_parcels_overlay final : public map_typical_overlay { |
| 107 |
public: |
| 108 |
void draw_cell(render_target* pCanvas, int iCanvasX, int iCanvasY, |
| 109 |
const level_map* pMap, int iNodeX, int iNodeY) override; |
| 110 |
}; |
| 111 |
|
| 112 |
#endif |