Freeciv21
Develop your civilization from humble roots to a global empire
layer_darkness.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 2021-2023 Freeciv21 contributors.
3 \_ \ / __/ This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "fc_types.h"
16 #include "layer.h"
17 #include "tilespec.h"
18 
19 #include <QPixmap>
20 
21 #include <array>
22 
23 namespace freeciv {
24 
25 #define SPECENUM_NAME darkness_style
26 // No darkness sprites are drawn.
27 #define SPECENUM_VALUE0 DARKNESS_NONE
28 #define SPECENUM_VALUE0NAME "None"
29 /* 1 sprite that is split into 4 parts and treated as a darkness4. Only
30  * works in iso-view. */
31 #define SPECENUM_VALUE1 DARKNESS_ISORECT
32 #define SPECENUM_VALUE1NAME "IsoRect"
33 /* 4 sprites, one per direction. More than one sprite per tile may be
34  * drawn. */
35 #define SPECENUM_VALUE2 DARKNESS_CARD_SINGLE
36 #define SPECENUM_VALUE2NAME "CardinalSingle"
37 /* 15=2^4-1 sprites. A single sprite is drawn, chosen based on whether
38  * there's darkness in _each_ of the cardinal directions. */
39 #define SPECENUM_VALUE3 DARKNESS_CARD_FULL
40 #define SPECENUM_VALUE3NAME "CardinalFull"
41 // Corner darkness & fog. 3^4 = 81 sprites.
42 #define SPECENUM_VALUE4 DARKNESS_CORNER
43 #define SPECENUM_VALUE4NAME "Corner"
44 #include "specenum_gen.h"
45 
46 class layer_darkness : public layer {
47 public:
48  explicit layer_darkness(struct tileset *ts, darkness_style style);
49  virtual ~layer_darkness() = default;
50 
54  void load_sprites() override;
55 
56  std::vector<drawn_sprite>
57  fill_sprite_array(const tile *ptile, const tile_edge *pedge,
58  const tile_corner *pcorner,
59  const unit *punit) const override;
60 
61 private:
65  void set_sprite(std::size_t index, const QPixmap &p)
66  {
67  m_sprites[index] = p;
68  }
69 
70  darkness_style m_style;
71 
72  // First unused
73  std::array<QPixmap, MAX_INDEX_CARDINAL> m_sprites;
74 };
75 
76 } // namespace freeciv
std::array< QPixmap, MAX_INDEX_CARDINAL > m_sprites
std::vector< drawn_sprite > fill_sprite_array(const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner, const unit *punit) const override
Returns the list of sprites drawn by this layer somewhere on the map.
void set_sprite(std::size_t index, const QPixmap &p)
Sets one of the sprites used to draw the darkness.
darkness_style m_style
virtual ~layer_darkness()=default
layer_darkness(struct tileset *ts, darkness_style style)
void load_sprites() override
Loads all the sprites needed to draw the darkness.
A layer when drawing the map.
Definition: layer.h:153
Definition: path.cpp:10
Definition: tile.h:42
Definition: unit.h:134