Pioneer
SectorView.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _SECTORVIEW_H
5 #define _SECTORVIEW_H
6 
7 #include "ConnectionTicket.h"
8 #include "DeleteEmitter.h"
9 #include "Input.h"
10 #include "galaxy/Sector.h"
11 #include "galaxy/SystemPath.h"
12 #include "graphics/Drawables.h"
13 #include "imgui/imgui.h"
14 #include "imgui/imgui_internal.h"
15 #include "pigui/PiGuiView.h"
16 #include <set>
17 #include <string>
18 #include <vector>
19 
20 class Game;
21 class Galaxy;
22 
23 class SectorView : public PiGuiView, public DeleteEmitter {
24 public:
25  SectorView(Game *game);
26  SectorView(const Json &jsonObj, Game *game);
27  ~SectorView() override;
28 
29  void Update() override;
30  // void ShowAll() override;
31  void Draw3D() override;
32 
33  void DrawPiGui() override;
34 
35  vector3f GetPosition() const { return m_pos; }
36  SystemPath GetCurrent() const { return m_current; }
37  SystemPath GetSelected() const { return m_selected; }
38  void SwitchToPath(const SystemPath &path);
39  SystemPath GetHyperspaceTarget() const { return m_hyperspaceTarget; }
40  void SetHyperspaceTarget(const SystemPath &path);
41  void ResetHyperspaceTarget();
42  void GotoSector(const SystemPath &path);
43  void GotoSystem(const SystemPath &path);
44  void GotoCurrentSystem() { GotoSystem(m_current); }
45  void GotoSelectedSystem() { GotoSystem(m_selected); }
46  void GotoHyperspaceTarget() { GotoSystem(m_hyperspaceTarget); }
47  bool IsCenteredOn(const SystemPath &path);
48  void SaveToJson(Json &jsonObj) override;
49 
50  sigc::signal<void> onHyperspaceTargetChanged;
51 
52  double GetZoomLevel() const;
53  void ZoomIn();
54  void ZoomOut();
56  double GetCenterDistance();
57  void SetDrawUninhabitedLabels(bool value) { m_drawUninhabitedLabels = value; }
58  void SetDrawVerticalLines(bool value) { m_drawVerticalLines = value; }
59  void SetDrawOutRangeLabels(bool value) { m_drawOutRangeLabels = value; }
60  void SetAutomaticSystemSelection(bool value) { m_automaticSystemSelection = value; }
61  std::vector<SystemPath> GetNearbyStarSystemsByName(std::string pattern);
62  const std::set<const Faction *> &GetVisibleFactions() { return m_visibleFactions; }
63  const std::set<const Faction *> &GetHiddenFactions() { return m_hiddenFactions; }
64  void SetFactionVisible(const Faction *faction, bool visible);
65  void SetZoomMode(bool enable);
66  void SetRotateMode(bool enable);
67  void ResetView();
68  void SetLabelParams(std::string fontName, int fontSize, float gap, Color highlight, Color shade);
69  void DrawLabels();
70  void SetLabelsVisibility(bool hideLabels) { m_hideLabels = hideLabels; }
71 
72  // HyperJump Route Planner
73  bool MoveRouteItemUp(const std::vector<SystemPath>::size_type element);
74  bool MoveRouteItemDown(const std::vector<SystemPath>::size_type element);
75  void UpdateRouteItem(const std::vector<SystemPath>::size_type element, const SystemPath &path);
76  void AddToRoute(const SystemPath &path);
77  bool RemoveRouteItem(const std::vector<SystemPath>::size_type element);
78  void ClearRoute();
79  std::vector<SystemPath> GetRoute();
80  const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const;
81  void SetDrawRouteLines(bool value) { m_drawRouteLines = value; }
82 
83 protected:
84  void OnSwitchTo() override;
85  void OnSwitchFrom() override;
86 
87  struct InputBinding : public Input::InputFrame {
88  using InputFrame::InputFrame;
89 
94 
101 
102  void RegisterBindings() override;
104 
105 private:
106  void InitDefaults();
107  void InitObject();
108 
109  void DrawNearSectors(const matrix4x4f &modelview);
110  void DrawNearSector(const int sx, const int sy, const int sz, const matrix4x4f &trans);
111  void PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius);
112  void PutSystemLabel(const Sector::System &sys);
113 
114  void DrawFarSectors(const matrix4x4f &modelview);
115  void BuildFarSector(RefCountedPtr<Sector> sec, const vector3f &origin, std::vector<vector3f> &points, std::vector<Color> &colors);
116  void PutFactionLabels(const vector3f &secPos);
117  void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);
118 
119  void OnClickSystem(const SystemPath &path);
120  const SystemPath &CheckPathInRoute(const SystemPath &path);
121 
122  RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
123  void ShrinkCache();
124  void SetSelected(const SystemPath &path);
125 
126  void MouseWheel(bool up);
127 
128  RefCountedPtr<Galaxy> m_galaxy;
129 
130  bool m_inSystem;
131 
132  SystemPath m_current;
133  SystemPath m_selected;
134 
135  vector3f m_pos;
136  vector3f m_posMovingTo;
137 
138  float m_rotXDefault, m_rotZDefault, m_zoomDefault;
139 
140  float m_rotX, m_rotZ;
141  float m_rotXMovingTo, m_rotZMovingTo;
142 
143  float m_zoom;
144  float m_zoomClamped;
145  float m_zoomMovingTo;
146 
147  bool m_rotateWithMouseButton = false;
148  bool m_rotateView = false;
149  bool m_zoomView = false;
150  bool m_manualMove = false;
151 
152  SystemPath m_hyperspaceTarget;
153  bool m_automaticSystemSelection;
154 
155  bool m_drawUninhabitedLabels;
156  bool m_drawOutRangeLabels;
157  bool m_drawVerticalLines;
158 
159  //Gui::LabelSet *m_clickableLabels;
160 
161  std::set<const Faction *> m_visibleFactions;
162  std::set<const Faction *> m_hiddenFactions;
163 
164  Uint8 m_detailBoxVisible;
165 
166  ConnectionTicket m_onMouseWheelCon;
167  ConnectionTicket m_onToggleSelectionFollowView;
168  ConnectionTicket m_onWarpToCurrent;
169  ConnectionTicket m_onWarpToSelected;
170  ConnectionTicket m_onViewReset;
171 
172  RefCountedPtr<SectorCache::Slave> m_sectorCache;
173  std::string m_previousSearch;
174 
175  float m_playerHyperspaceRange;
176 
177  // HyperJump Route Planner Stuff
178  std::vector<SystemPath> m_route;
179 
180  bool m_drawRouteLines;
181  bool m_setupRouteLines;
182  void DrawRouteLines(const matrix4x4f &trans);
183  void SetupRouteLines(const vector3f &playerAbsPos);
184  void GetPlayerPosAndStarSize(vector3f &playerPosOut, float &currentStarSizeOut);
185 
186  std::vector<vector3f> m_farstars;
187  std::vector<Color> m_farstarsColor;
188 
189  vector3f m_secPosFar;
190  int m_radiusFar;
191  bool m_toggledFaction;
192 
193  int m_cacheXMin;
194  int m_cacheXMax;
195  int m_cacheYMin;
196  int m_cacheYMax;
197  int m_cacheZMin;
198  int m_cacheZMax;
199 
200  std::unique_ptr<ImDrawList> m_drawList;
201 
202  std::unique_ptr<Graphics::VertexArray> m_lineVerts;
203  std::unique_ptr<Graphics::VertexArray> m_secLineVerts;
204  std::unique_ptr<Graphics::VertexArray> m_starVerts;
205 
206  RefCountedPtr<Graphics::Material> m_starMaterial;
209  RefCountedPtr<Graphics::Material> m_farStarsMat;
210 
211  std::unique_ptr<Graphics::Drawables::Sphere3D> m_jumpSphere;
212 
214  Graphics::Drawables::Lines m_sectorlines;
215  Graphics::Drawables::Lines m_routeLines;
216  Graphics::Drawables::Points m_farstarsPoints;
217 
218  class Label;
219  class StarLabel;
220  class FactionLabel;
221  struct Labels {
222  // the constructor can only be defined after defining the Label class
223  Labels(SectorView &view);
224  // settings and globals for labels
225  // this is not hardcode, these are the defaults
226  std::string fontName = "orbiteer";
227  int fontSize = 15;
228  float gap = 2.f;
229  ImFont *starLabelFont = nullptr;
230  ImFont *factionHomeFont = nullptr;
231  ImFont *factionNameFont = nullptr;
232  ImRect starLabelHoverArea;
233  ImRect factionHomeHoverArea;
234  ImRect factionNameHoverArea;
235  ImU32 highlightColor = IM_COL32(255, 255, 255, 100);
236  ImU32 shadeColor = IM_COL32(25, 51, 82, 200);
237  // owning object
238  SectorView &view;
239  // array
240  std::vector<std::unique_ptr<Label>> array;
241  };
242  Labels m_labels;
243  bool m_hideLabels = false;
244 };
245 
246 #endif /* _SECTORVIEW_H */
nlohmann::json Json
Definition: Json.h:8
Definition: DeleteEmitter.h:16
Definition: Factions.h:21
Definition: Galaxy.h:18
Definition: Game.h:38
Definition: Drawables.h:80
Definition: Drawables.h:114
Definition: PiGuiView.h:11
Definition: RefCounted.h:36
Definition: SectorView.h:23
void SetHyperspaceTarget(const SystemPath &path)
Definition: SectorView.cpp:817
~SectorView() override
Definition: SectorView.cpp:38
SectorView::InputBinding InputBindings
void GotoSystem(const SystemPath &path)
Definition: SectorView.cpp:838
sigc::signal< void > onHyperspaceTargetChanged
Definition: SectorView.h:50
double GetZoomLevel() const
Definition: SectorView.cpp:1680
void SetDrawRouteLines(bool value)
Definition: SectorView.h:81
void SetLabelsVisibility(bool hideLabels)
Definition: SectorView.h:70
const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector< SystemPath > &outRoute) const
Definition: SectorView.cpp:1040
void ZoomIn()
Definition: SectorView.cpp:1685
void SwitchToPath(const SystemPath &path)
Definition: SectorView.cpp:868
vector3f GetCenterSector()
Definition: SectorView.cpp:1703
void DrawPiGui() override
Definition: SectorView.cpp:738
std::vector< SystemPath > GetRoute()
Definition: SectorView.cpp:1035
double GetCenterDistance()
Definition: SectorView.cpp:1708
SectorView(Game *game)
Definition: SectorView.cpp:477
bool MoveRouteItemDown(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:996
void SetLabelParams(std::string fontName, int fontSize, float gap, Color highlight, Color shade)
Definition: SectorView.cpp:744
void OnSwitchFrom() override
Definition: SectorView.cpp:1506
const std::set< const Faction * > & GetVisibleFactions()
Definition: SectorView.h:62
void ResetHyperspaceTarget()
Definition: SectorView.cpp:823
void UpdateRouteItem(const std::vector< SystemPath >::size_type element, const SystemPath &path)
Definition: SectorView.cpp:1006
void ResetView()
Definition: SectorView.cpp:1775
void Update() override
Definition: SectorView.cpp:1511
void SaveToJson(Json &jsonObj) override
Definition: SectorView.cpp:628
void SetDrawVerticalLines(bool value)
Definition: SectorView.h:58
bool MoveRouteItemUp(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:986
SystemPath GetCurrent() const
Definition: SectorView.h:36
void AddToRoute(const SystemPath &path)
Definition: SectorView.cpp:1012
void SetAutomaticSystemSelection(bool value)
Definition: SectorView.h:60
vector3f GetPosition() const
Definition: SectorView.h:35
void GotoHyperspaceTarget()
Definition: SectorView.h:46
void OnSwitchTo() override
Definition: SectorView.cpp:1500
void GotoSelectedSystem()
Definition: SectorView.h:45
void GotoSector(const SystemPath &path)
Definition: SectorView.cpp:833
void GotoCurrentSystem()
Definition: SectorView.h:44
void SetDrawUninhabitedLabels(bool value)
Definition: SectorView.h:57
bool IsCenteredOn(const SystemPath &path)
Definition: SectorView.cpp:847
SystemPath GetSelected() const
Definition: SectorView.h:37
void ZoomOut()
Definition: SectorView.cpp:1694
std::vector< SystemPath > GetNearbyStarSystemsByName(std::string pattern)
Definition: SectorView.cpp:1718
void Draw3D() override
Definition: SectorView.cpp:658
const std::set< const Faction * > & GetHiddenFactions()
Definition: SectorView.h:63
void SetDrawOutRangeLabels(bool value)
Definition: SectorView.h:59
void SetFactionVisible(const Faction *faction, bool visible)
Definition: SectorView.cpp:1748
SystemPath GetHyperspaceTarget() const
Definition: SectorView.h:39
bool RemoveRouteItem(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:1018
void DrawLabels()
Definition: SectorView.cpp:754
void ClearRoute()
Definition: SectorView.cpp:1029
void SetRotateMode(bool enable)
Definition: SectorView.cpp:1766
void SetZoomMode(bool enable)
Definition: SectorView.cpp:1757
Definition: Sector.h:38
Definition: SystemPath.h:13
Definition: Color.h:66
Definition: ConnectionTicket.h:12
Definition: InputBindings.h:142
Definition: InputBindings.h:166
Definition: Input.h:46
Definition: SectorView.h:87
void RegisterBindings() override
Definition: SectorView.cpp:461
Axis * mapViewYaw
Definition: SectorView.h:98
Action * mapViewReset
Definition: SectorView.h:93
Axis * mapViewMoveForward
Definition: SectorView.h:95
Axis * mapViewMoveLeft
Definition: SectorView.h:96
Axis * mapViewPitch
Definition: SectorView.h:99
Action * mapWarpToSelected
Definition: SectorView.h:92
Axis * mapViewMoveUp
Definition: SectorView.h:97
Action * mapToggleSelectionFollowView
Definition: SectorView.h:90
Action * mapWarpToCurrent
Definition: SectorView.h:91
Axis * mapViewZoom
Definition: SectorView.h:100