Pioneer
Loading...
Searching...
No Matches
SectorMap.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _SECTORMAP_H
5#define _SECTORMAP_H
6
7#include "Color.h"
8#include "DeleteEmitter.h"
9#include "Input.h"
10#include "RefCounted.h"
11#include "galaxy/Factions.h"
12#include "galaxy/Sector.h"
13#include "galaxy/SystemPath.h"
14#include "graphics/Drawables.h"
15#include "imgui/imgui.h"
16#include "imgui/imgui_internal.h"
17#include "SectorMapContext.h"
18
19namespace Graphics {
20 class RenderTarget;
21}
22
23class SectorMap : public DeleteEmitter {
24public:
25
26 SectorMap(SectorMapContext &&context);
27 SectorMap(const Json &jsonObj, SectorMapContext &&context);
28 ~SectorMap();
29
30 void Update(float frameTime);
31 void Draw3D();
32 void DrawLabels(bool interactive, const ImVec2 &imagePos = { 0.0, 0.0 });
33 void DrawEmbed();
34
35 vector3f GetPosition() const { return m_pos; }
37 double GetZoomLevel() const;
38 RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
39 bool IsCenteredOn(const SystemPath &path);
40 bool IsManualMove() { return m_manualMove; }
43 SectorMapContext &GetContext() { return m_context; }
44
45 void SetDrawUninhabitedLabels(bool value) { m_drawUninhabitedLabels = value; }
46 void SetDrawVerticalLines(bool value) { m_drawVerticalLines = value; }
47 void SetFactionVisible(const Faction *faction, bool visible);
48 void SetZoomMode(bool enable);
49 void SetRotateMode(bool enable);
50 void SetLabelParams(std::string fontName, int fontSize, float gap, Color highlight, Color shade);
51 void SetLabelsVisibility(bool hideLabels) { m_hideLabels = hideLabels; }
52 void GotoSector(const SystemPath &path);
53 void GotoSystem(const SystemPath &path);
54 void ZoomIn();
55 void ZoomOut();
56 void ResetView();
57
58 void CreateRenderTarget();
59 void SetSize(vector2d size);
60 void SaveToJson(Json &jsonObj);
61
62 // creating objects on the map
63 void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);
64 void AddSphere(const matrix4x4f &trans, const Color &color = Color::WHITE);
65 void AddLineVert(const vector3f &v, const Color &c);
66 // lines are not automatically cleared every frame
67 void ClearLineVerts();
68
69 std::vector<SystemPath> GetNearbyStarSystemsByName(std::string pattern);
70 const std::set<const Faction *> &GetVisibleFactions() { return m_visibleFactions; }
71 const std::set<const Faction *> &GetHiddenFactions() { return m_hiddenFactions; }
72
74 using InputFrame::InputFrame;
75
80
87
88 void RegisterBindings() override;
90
91private:
92 void InitDefaults();
93 void InitObject();
94
95 void DrawNearSectors(const matrix4x4f &modelview);
96 void DrawNearSector(const int sx, const int sy, const int sz, const matrix4x4f &trans);
97 void DrawLabelsInternal(bool interactive, const ImVec2 &imagePos = { 0.0, 0.0 });
98 void PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius);
99 void PutSystemLabel(const Sector::System &sys, bool shadow);
100
101 void DrawFarSectors(const matrix4x4f &modelview);
102 void BuildFarSector(RefCountedPtr<Sector> sec, const vector3f &origin, std::vector<vector3f> &points, std::vector<Color> &colors);
103 void PutFactionLabels(const vector3f &secPos);
104
105 void OnClickLabel(const SystemPath &path);
106
107 void ShrinkCache();
108 void SetSelected(const SystemPath &path);
109
110 void MouseWheel(bool up);
111
112 SectorMapContext m_context;
113
114 vector3f m_pos;
115 vector3f m_posMovingTo;
116
117 float m_rotXDefault, m_rotZDefault, m_zoomDefault;
118
119 float m_rotX, m_rotZ;
120 float m_rotXMovingTo, m_rotZMovingTo;
121
122 float m_zoom;
123 float m_zoomClamped;
124 float m_zoomMovingTo;
125
126 bool m_rotateWithMouseButton = false;
127 bool m_rotateView = false;
128 bool m_zoomView = false;
129 bool m_manualMove = false;
130
131 bool m_drawUninhabitedLabels = false;
132 bool m_drawVerticalLines = false;
133
134 std::set<const Faction *> m_visibleFactions;
135 std::set<const Faction *> m_hiddenFactions;
136
137 Uint8 m_detailBoxVisible;
138
139 sigc::connection m_onToggleSelectionFollowView;
140 sigc::connection m_onWarpToSelected;
141 sigc::connection m_onViewReset;
142
144
145 std::vector<vector3f> m_farstars;
146 std::vector<Color> m_farstarsColor;
147
148 vector3f m_secPosFar;
149 int m_radiusFar;
150 bool m_toggledFaction;
151
152 int m_cacheXMin;
153 int m_cacheXMax;
154 int m_cacheYMin;
155 int m_cacheYMax;
156 int m_cacheZMin;
157 int m_cacheZMax;
158
159 std::unique_ptr<ImDrawList> m_drawList;
160 std::unique_ptr<Graphics::RenderTarget> m_renderTarget;
161 ImVec2 m_size;
162 bool m_needsResize;
163
164 std::unique_ptr<Graphics::VertexArray> m_lineVerts;
165 std::unique_ptr<Graphics::VertexArray> m_secLineVerts;
166 std::unique_ptr<Graphics::VertexArray> m_starVerts;
167 std::unique_ptr<Graphics::VertexArray> m_customLineVerts;
168 bool m_updateCustomLines = false;
169
174
176 Graphics::Drawables::Lines m_customlines;
177 Graphics::Drawables::Lines m_sectorlines;
178 Graphics::Drawables::Points m_farstarsPoints;
179
180 struct SphereParam {
181 matrix4x4f trans;
182 Color color;
183 };
184 std::vector<SphereParam> m_sphereParams;
185 std::unique_ptr<Graphics::Drawables::Sphere3D> m_sphere;
186
187 class Label;
188 class StarLabel;
189 class FactionLabel;
190 struct Labels {
191 // the constructor can only be defined after defining the Label class
192 Labels(SectorMap &map);
193 // settings and globals for labels
194 // this is not hardcode, these are the defaults
195 std::string fontName = "orbiteer";
196 int fontSize = 15;
197 float gap = 2.f;
198 ImFont *starLabelFont = nullptr;
199 ImFont *factionHomeFont = nullptr;
200 ImFont *factionNameFont = nullptr;
201 ImRect starLabelHoverArea;
202 ImRect factionHomeHoverArea;
203 ImRect factionNameHoverArea;
204 ImU32 highlightColor = IM_COL32(255, 255, 255, 100);
205 ImU32 shadeColor = IM_COL32(25, 51, 82, 200);
206 // owning object
207 SectorMap &map;
208 // array
209 std::vector<std::unique_ptr<Label>> array;
210 };
211 Labels m_labels;
212 bool m_hideLabels = false;
213};
214
215#endif /* _SECTORMAP_H */
nlohmann::json Json
Definition: Json.h:8
Definition: DeleteEmitter.h:16
Definition: Factions.h:21
Definition: Drawables.h:83
Definition: Drawables.h:117
Definition: RefCounted.h:36
Definition: SectorMap.h:23
void ZoomIn()
vector3f GetSystemPosition(const SystemPath &path)
Definition: SectorMap.cpp:1324
void SetLabelsVisibility(bool hideLabels)
Definition: SectorMap.h:51
void AddLineVert(const vector3f &v, const Color &c)
Definition: SectorMap.cpp:899
void SetLabelParams(std::string fontName, int fontSize, float gap, Color highlight, Color shade)
Definition: SectorMap.cpp:721
SectorMapContext & GetContext()
Definition: SectorMap.h:43
void GotoSystem(const SystemPath &path)
Definition: SectorMap.cpp:803
std::vector< SystemPath > GetNearbyStarSystemsByName(std::string pattern)
Definition: SectorMap.cpp:1256
void SetZoomMode(bool enable)
Definition: SectorMap.cpp:1295
void CreateRenderTarget()
Definition: SectorMap.cpp:671
void Update(float frameTime)
Definition: SectorMap.cpp:1105
void ClearLineVerts()
Definition: SectorMap.cpp:904
void GotoSector(const SystemPath &path)
Definition: SectorMap.cpp:798
void AddSphere(const matrix4x4f &trans, const Color &color=Color::WHITE)
Definition: SectorMap.cpp:875
void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size)
Definition: SectorMap.cpp:880
void SetDrawUninhabitedLabels(bool value)
Definition: SectorMap.h:45
void SaveToJson(Json &jsonObj)
Definition: SectorMap.cpp:561
RefCountedPtr< Sector > GetCached(const SystemPath &loc)
Definition: SectorMap.h:38
void SetDrawVerticalLines(bool value)
Definition: SectorMap.h:46
void DrawEmbed()
Definition: SectorMap.cpp:689
void ZoomOut()
vector3f GetPosition() const
Definition: SectorMap.h:35
SectorMap::InputBinding InputBindings
const std::set< const Faction * > & GetHiddenFactions()
Definition: SectorMap.h:71
void SetFactionVisible(const Faction *faction, bool visible)
Definition: SectorMap.cpp:1286
bool IsCenteredOn(const SystemPath &path)
Definition: SectorMap.cpp:812
void Draw3D()
Definition: SectorMap.cpp:586
void DrawLabels(bool interactive, const ImVec2 &imagePos={ 0.0, 0.0 })
Definition: SectorMap.cpp:657
SystemPath NearestSystemToPos(const vector3f &pos)
Definition: SectorMap.cpp:361
bool IsManualMove()
Definition: SectorMap.h:40
matrix4x4f PointOfView()
Definition: SectorMap.cpp:577
void ResetView()
Definition: SectorMap.cpp:1313
double GetZoomLevel() const
Definition: SectorMap.cpp:1251
~SectorMap()
Definition: SectorMap.cpp:559
void SetRotateMode(bool enable)
Definition: SectorMap.cpp:1304
const std::set< const Faction * > & GetVisibleFactions()
Definition: SectorMap.h:70
void SetSize(vector2d size)
Definition: SectorMap.cpp:662
Definition: Sector.h:39
Definition: SystemPath.h:13
Definition: Background.h:14
Definition: Color.h:66
static const Color4ub WHITE
Definition: Color.h:156
Definition: InputBindings.h:144
Definition: InputBindings.h:168
Definition: Input.h:48
Definition: SectorMapContext.h:16
Definition: SectorMap.h:73
Axis * mapViewPitch
Definition: SectorMap.h:85
Action * mapWarpToCurrent
Definition: SectorMap.h:77
Axis * mapViewMoveUp
Definition: SectorMap.h:83
Axis * mapViewYaw
Definition: SectorMap.h:84
Axis * mapViewMoveLeft
Definition: SectorMap.h:82
Axis * mapViewMoveForward
Definition: SectorMap.h:81
Axis * mapViewZoom
Definition: SectorMap.h:86
Action * mapViewReset
Definition: SectorMap.h:79
Action * mapToggleSelectionFollowView
Definition: SectorMap.h:76
void RegisterBindings() override
Definition: SectorMap.cpp:449
Action * mapWarpToSelected
Definition: SectorMap.h:78