Symphony Of Empires
map.hpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // client/map.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <vector>
28 #include <memory>
29 #include <utility>
30 #include <functional>
31 #include <cstddef>
32 #include "eng3d/color.hpp"
33 #include "eng3d/primitive.hpp"
34 #include "eng3d/shader.hpp"
35 #include "eng3d/font_sdf.hpp"
36 #include "eng3d/event.hpp"
37 
38 namespace Eng3D {
39  class Texture;
40  class TextureArray;
41  struct Model;
42  class Camera;
43  namespace OpenGL {
44  class Sphere;
45  class Program;
46  class Framebuffer;
47  }
48 }
49 
50 namespace UI {
51  class Context;
52  class Group;
53  class Tooltip;
54 }
55 namespace Interface {
56  class UnitWidget;
57  class BattleWidget;
58 }
59 
60 #include "province.hpp"
61 #include "indpobj.hpp"
62 
63 enum class MapView {
65  PLANE_VIEW,
66 };
67 
68 class World;
69 class Nation;
70 class MapRender;
71 class GameState;
72 class Input;
73 class Rivers;
74 class Borders;
75 
76 struct ProvinceColor {
79  ProvinceColor(ProvinceId _id, Eng3D::Color _color): id{ _id }, color{ _color } {}
80 };
81 typedef std::function<std::string(const World& world, const ProvinceId id)> mapmode_tooltip;
82 typedef std::function<std::vector<ProvinceColor>(const World& world)> mapmode_generator;
83 class Map;
84 typedef std::function<void(const World& world, Map& map, const Province& province)> selector_func;
85 std::vector<ProvinceColor> political_map_mode(const World& world);
86 std::string political_province_tooltip(const World& world, const ProvinceId id);
87 std::string empty_province_tooltip(const World& world, const ProvinceId id);
88 
89 class Map {
90  mapmode_generator mapmode_func = nullptr;
91  mapmode_tooltip mapmode_tooltip_func = nullptr;
92  selector_func selector = nullptr;
93  GameState& gs;
94 
95  Eng3D::Sphere skybox;
96  std::unique_ptr<Eng3D::FontSDF> map_font;
97  std::shared_ptr<Eng3D::Texture> line_tex;
98  std::shared_ptr<Eng3D::Texture> skybox_tex;
99  std::unique_ptr<Eng3D::OpenGL::Program> tree_shder;
100 
101  void check_left_mouse_release();
102  void check_right_mouse_release();
103 
104 public:
105  Map(GameState& gs, const World& world, UI::Group* map_ui_layer, int screen_width, int screen_height);
106  ~Map();
107  void update_mapmode();
108  void draw_flag(const Eng3D::OpenGL::Program& shader, const Nation& nation);
109  void draw();
110  void set_map_mode(mapmode_generator mapmode_func, mapmode_tooltip tooltip_func);
111  void set_selected_province(bool selected, ProvinceId id);
112  void set_view(MapView view);
113  void reload_shaders();
114  void update_nation_label(const Nation& nation);
115  void create_labels();
116 
117  void handle_resize();
120 
121  bool province_selected = false;
124 
125  std::vector<std::shared_ptr<Eng3D::Model>> building_type_models;
126  std::vector<std::shared_ptr<Eng3D::Model>> unit_type_models;
127  std::vector<std::shared_ptr<Eng3D::Model>> tree_type_models;
128  std::vector<glm::vec2> tree_spawn_pos; // Location of where to place trees
129  std::vector<std::shared_ptr<Eng3D::Texture>> building_type_icons;
130  std::vector<std::shared_ptr<Eng3D::Texture>> unit_type_icons;
131  std::vector<std::shared_ptr<Eng3D::Texture>> nation_flags;
132 
133 #ifndef E3D_TARGET_SWITCH
134  std::vector<std::unique_ptr<Eng3D::Label3D>> province_labels;
135 #endif
136  std::vector<std::unique_ptr<Eng3D::Label3D>> nation_labels;
137  bool gen_labels = true;
138 
140  float wind_osc = 0.f;
142  bool is_drag = false;
144 
145  void set_selection(selector_func selector);
146 
147  const World& world;
148  UI::Tooltip* tooltip = nullptr;
150 
151  std::unique_ptr<Eng3D::Camera> camera;
152  std::unique_ptr<MapRender> map_render;
153  std::vector<Interface::UnitWidget*> unit_widgets;
154  std::vector<Interface::BattleWidget*> battle_widgets;
155  std::unique_ptr<Eng3D::OpenGL::Program> obj_shader;
156 };
157 
Definition: map.hpp:89
std::unique_ptr< Eng3D::Camera > camera
Definition: map.hpp:151
void reload_shaders()
Definition: map.cpp:281
MapView view_mode
Definition: map.hpp:123
void create_labels()
Definition: map.cpp:225
void handle_resize()
Definition: map.cpp:519
std::vector< glm::vec2 > tree_spawn_pos
Definition: map.hpp:128
std::unique_ptr< Eng3D::OpenGL::Program > obj_shader
Definition: map.hpp:155
glm::vec2 last_camera_drag_pos
Definition: map.hpp:143
void update_mapmode()
Definition: map.cpp:362
void set_selected_province(bool selected, ProvinceId id)
Definition: map.cpp:331
std::vector< std::shared_ptr< Eng3D::Texture > > nation_flags
Definition: map.hpp:131
void handle_mouse_button(const Eng3D::Event::MouseButton &e)
Definition: map.cpp:599
Map(GameState &gs, const World &world, UI::Group *map_ui_layer, int screen_width, int screen_height)
Definition: map.cpp:118
std::vector< Interface::UnitWidget * > unit_widgets
Definition: map.hpp:153
std::vector< std::unique_ptr< Eng3D::Label3D > > province_labels
Definition: map.hpp:134
void set_selection(selector_func selector)
Definition: map.cpp:321
const World & world
Definition: map.hpp:147
void set_map_mode(mapmode_generator mapmode_func, mapmode_tooltip tooltip_func)
Definition: map.cpp:325
void draw()
Definition: map.cpp:414
UI::Group * map_ui_layer
Definition: map.hpp:149
std::unique_ptr< MapRender > map_render
Definition: map.hpp:152
void set_view(MapView view)
Definition: map.cpp:254
std::vector< std::unique_ptr< Eng3D::Label3D > > nation_labels
Definition: map.hpp:136
std::vector< std::shared_ptr< Eng3D::Texture > > unit_type_icons
Definition: map.hpp:130
void draw_flag(const Eng3D::OpenGL::Program &shader, const Nation &nation)
Definition: map.cpp:337
~Map()
Definition: map.cpp:163
void handle_mouse_motions(const Eng3D::Event::MouseMotion &e)
Definition: map.cpp:623
bool province_selected
Definition: map.hpp:121
bool gen_labels
Definition: map.hpp:137
void update_nation_label(const Nation &nation)
Definition: map.cpp:167
std::vector< Interface::BattleWidget * > battle_widgets
Definition: map.hpp:154
std::vector< std::shared_ptr< Eng3D::Model > > building_type_models
Definition: map.hpp:125
std::vector< std::shared_ptr< Eng3D::Texture > > building_type_icons
Definition: map.hpp:129
float wind_osc
Wind oscillator (for flags)
Definition: map.hpp:140
ProvinceId selected_province_id
Definition: map.hpp:122
std::vector< std::shared_ptr< Eng3D::Model > > tree_type_models
Definition: map.hpp:127
UI::Tooltip * tooltip
Definition: map.hpp:148
bool is_drag
Input states.
Definition: map.hpp:142
std::vector< std::shared_ptr< Eng3D::Model > > unit_type_models
Definition: map.hpp:126
A single province, which is used to simulate economy in a "bulk-tiles" way instead of doing economica...
Definition: province.hpp:48
Grouping to keep widgets together without triggering events.
Definition: group.hpp:44
Tooltip widget, used entirely for hovering purpouses, don't use any other widget for hovering unless ...
Definition: tooltip.hpp:38
Definition: world.hpp:114
std::function< std::string(const World &world, const ProvinceId id)> mapmode_tooltip
Definition: map.hpp:81
MapView
Definition: map.hpp:63
std::string political_province_tooltip(const World &world, const ProvinceId id)
Definition: map.cpp:262
std::string empty_province_tooltip(const World &world, const ProvinceId id)
Definition: map.cpp:277
std::function< void(const World &world, Map &map, const Province &province)> selector_func
Definition: map.hpp:83
std::function< std::vector< ProvinceColor >const World &world)> mapmode_generator
Definition: map.hpp:82
std::vector< ProvinceColor > political_map_mode(const World &world)
Definition: map.cpp:270
Primitive color type used through the engine.
Definition: color.hpp:32
ProvinceColor(ProvinceId _id, Eng3D::Color _color)
Definition: map.hpp:79
ProvinceId id
Definition: map.hpp:77
Eng3D::Color color
Definition: map.hpp:78