Freeciv21
Develop your civilization from humble roots to a global empire
layer_city.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 // SPDX-FileCopyrightText: Freeciv authors
3 // SPDX-FileCopyrightText: Freeciv21 authors
4 // SPDX-FileCopyrightText: Louis Moureaux <m_louis30@yahoo.com>
5 
6 #pragma once
7 
8 #include "layer.h"
9 #include "utils/colorizer.h"
10 
11 #include <QPoint>
12 
13 #include <array>
14 #include <memory>
15 
16 class QPixmap;
17 
18 namespace freeciv {
19 
20 class layer_city : public layer {
21 public:
22  using styles = std::vector<std::unique_ptr<freeciv::colorizer>>;
23  using city_sprite = std::vector<styles>;
24  constexpr static int NUM_WALL_TYPES = 7;
25 
26  explicit layer_city(struct tileset *ts, const QPoint &city_offset,
27  const QPoint &city_flag_offset,
28  const QPoint &occupied_offset);
29  virtual ~layer_city() = default;
30 
31  void load_sprites() override;
32 
33  void initialize_city_style(const citystyle &style, int index) override;
34 
35  std::vector<drawn_sprite>
36  fill_sprite_array(const tile *ptile, const tile_edge *pedge,
37  const tile_corner *pcorner,
38  const unit *punit) const override;
39 
40  std::vector<drawn_sprite>
41  fill_sprite_array_no_flag(const city *pcity, bool show_occupied) const;
42 
46  QPixmap sample_sprite(int style_index = 0) const
47  {
48  // Pick the largest size -- looks more interesting.
49  return m_tile[style_index].back().get()->base();
50  }
51 
52  void reset_ruleset() override;
53 
54 private:
55  layer_city::styles load_city_size_sprites(const QString &tag,
56  const citystyle &style);
57 
59  QPixmap *m_disorder, *m_happy;
60 
62  std::array<city_sprite, NUM_WALL_TYPES> m_walls;
63 };
64 
65 } // namespace freeciv
layer_city::styles load_city_size_sprites(const QString &tag, const citystyle &style)
Loads a set of size-dependent city sprites, with tags of the form graphic_tag_size.
Definition: layer_city.cpp:39
constexpr static int NUM_WALL_TYPES
Definition: layer_city.h:24
std::vector< std::unique_ptr< freeciv::colorizer > > styles
Definition: layer_city.h:22
city_sprite m_occupied
Definition: layer_city.h:61
void initialize_city_style(const citystyle &style, int index) override
Loads all sprites for a city style.
Definition: layer_city.cpp:87
QPixmap * m_disorder
Definition: layer_city.h:59
city_sprite m_tile
Definition: layer_city.h:61
std::array< city_sprite, NUM_WALL_TYPES > m_walls
Definition: layer_city.h:62
QPixmap * m_happy
Definition: layer_city.h:59
QPoint m_occupied_offset
Definition: layer_city.h:58
QPixmap sample_sprite(int style_index=0) const
Returns an example of what a city might look like.
Definition: layer_city.h:46
std::vector< styles > city_sprite
Definition: layer_city.h:23
QPoint m_city_flag_offset
Definition: layer_city.h:58
layer_city(struct tileset *ts, const QPoint &city_offset, const QPoint &city_flag_offset, const QPoint &occupied_offset)
Definition: layer_city.cpp:17
void reset_ruleset() override
All sprites depend on the ruleset-defined city styles and need to be reset.
Definition: layer_city.cpp:268
city_sprite m_single_wall
Definition: layer_city.h:61
virtual ~layer_city()=default
void load_sprites() override
Loads the disorder and happy sprites.
Definition: layer_city.cpp:29
std::vector< drawn_sprite > fill_sprite_array_no_flag(const city *pcity, bool show_occupied) const
Fill in the given sprite array with any city sprites.
Definition: layer_city.cpp:200
std::vector< drawn_sprite > fill_sprite_array(const tile *ptile, const tile_edge *pedge, const tile_corner *pcorner, const unit *punit) const override
Fill in the given sprite array with any needed city sprites.
Definition: layer_city.cpp:165
A layer when drawing the map.
Definition: layer.h:153
Definition: path.cpp:10
Definition: city.h:291
Definition: tile.h:42
Definition: unit.h:134
int style_index(const struct nation_style *pstyle)
Return the style index.
Definition: style.cpp:64