Pioneer
SectorView.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 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 "DeleteEmitter.h"
8 #include "Input.h"
9 #include "galaxy/Sector.h"
10 #include "galaxy/SystemPath.h"
11 #include "graphics/Drawables.h"
12 #include "gui/Gui.h"
13 #include "pigui/PiGuiView.h"
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 class Game;
19 class Galaxy;
20 
21 namespace Graphics {
22  class RenderState;
23 }
24 
25 class SectorView : public PiGuiView, public DeleteEmitter {
26 public:
27  SectorView(Game *game);
28  SectorView(const Json &jsonObj, Game *game);
29  ~SectorView() override;
30 
31  void Update() override;
32  void ShowAll() override;
33  void Draw3D() override;
34  vector3f GetPosition() const { return m_pos; }
35  SystemPath GetCurrent() const { return m_current; }
36  SystemPath GetSelected() const { return m_selected; }
37  void SwitchToPath(const SystemPath &path);
38  SystemPath GetHyperspaceTarget() const { return m_hyperspaceTarget; }
39  void SetHyperspaceTarget(const SystemPath &path);
40  void ResetHyperspaceTarget();
41  void GotoSector(const SystemPath &path);
42  void GotoSystem(const SystemPath &path);
43  void GotoCurrentSystem() { GotoSystem(m_current); }
44  void GotoSelectedSystem() { GotoSystem(m_selected); }
45  void GotoHyperspaceTarget() { GotoSystem(m_hyperspaceTarget); }
46  bool IsCenteredOn(const SystemPath &path);
47  void SaveToJson(Json &jsonObj) override;
48 
49  sigc::signal<void> onHyperspaceTargetChanged;
50 
51  double GetZoomLevel() const;
52  void ZoomIn();
53  void ZoomOut();
55  double GetCenterDistance();
56  void SetDrawUninhabitedLabels(bool value) { m_drawUninhabitedLabels = value; }
57  void SetDrawVerticalLines(bool value) { m_drawVerticalLines = value; }
58  void SetDrawOutRangeLabels(bool value) { m_drawOutRangeLabels = value; }
59  void SetAutomaticSystemSelection(bool value) { m_automaticSystemSelection = value; }
60  std::vector<SystemPath> GetNearbyStarSystemsByName(std::string pattern);
61  const std::set<const Faction *> &GetVisibleFactions() { return m_visibleFactions; }
62  const std::set<const Faction *> &GetHiddenFactions() { return m_hiddenFactions; }
63  void SetFactionVisible(const Faction *faction, bool visible);
64  void SetZoomMode(bool enable);
65  void SetRotateMode(bool enable);
66  void ResetView();
67 
68  // HyperJump Route Planner
69  bool MoveRouteItemUp(const std::vector<SystemPath>::size_type element);
70  bool MoveRouteItemDown(const std::vector<SystemPath>::size_type element);
71  void UpdateRouteItem(const std::vector<SystemPath>::size_type element, const SystemPath &path);
72  void AddToRoute(const SystemPath &path);
73  bool RemoveRouteItem(const std::vector<SystemPath>::size_type element);
74  void ClearRoute();
75  std::vector<SystemPath> GetRoute();
76  const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const;
77  void SetDrawRouteLines(bool value) { m_drawRouteLines = value; }
78 
79 protected:
80  void OnSwitchTo() override;
81  void OnSwitchFrom() override;
82 
83  struct InputBinding : public Input::InputFrame {
84  using InputFrame::InputFrame;
85 
90 
97 
98  void RegisterBindings() override;
100 
101 private:
102  void InitDefaults();
103  void InitObject();
104 
105  struct DistanceIndicator {
106  Gui::Label *label;
108  Color okayColor;
109  Color unsuffFuelColor;
110  Color outOfRangeColor;
111  };
112 
113  struct SystemLabels {
114  Gui::Label *systemName;
115  Gui::Label *sector;
116  DistanceIndicator distance;
117  Gui::Label *starType;
118  Gui::Label *shortDesc;
119  };
120 
121  void DrawNearSectors(const matrix4x4f &modelview);
122  void DrawNearSector(const int sx, const int sy, const int sz, const matrix4x4f &trans);
123  void PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius);
124 
125  void DrawFarSectors(const matrix4x4f &modelview);
126  void BuildFarSector(RefCountedPtr<Sector> sec, const vector3f &origin, std::vector<vector3f> &points, std::vector<Color> &colors);
127  void PutFactionLabels(const vector3f &secPos);
128  void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);
129 
130  void OnClickSystem(const SystemPath &path);
131  const SystemPath &CheckPathInRoute(const SystemPath &path);
132 
133  RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
134  void ShrinkCache();
135  void SetSelected(const SystemPath &path);
136 
137  void MouseWheel(bool up);
138 
139  RefCountedPtr<Galaxy> m_galaxy;
140 
141  bool m_inSystem;
142 
143  SystemPath m_current;
144  SystemPath m_selected;
145 
146  vector3f m_pos;
147  vector3f m_posMovingTo;
148 
149  float m_rotXDefault, m_rotZDefault, m_zoomDefault;
150 
151  float m_rotX, m_rotZ;
152  float m_rotXMovingTo, m_rotZMovingTo;
153 
154  float m_zoom;
155  float m_zoomClamped;
156  float m_zoomMovingTo;
157 
158  bool m_rotateWithMouseButton = false;
159  bool m_rotateView = false;
160  bool m_zoomView = false;
161  bool m_manualMove = false;
162 
163  SystemPath m_hyperspaceTarget;
164  bool m_automaticSystemSelection;
165 
166  bool m_drawUninhabitedLabels;
167  bool m_drawOutRangeLabels;
168  bool m_drawVerticalLines;
169 
170  std::unique_ptr<Graphics::Drawables::Disk> m_disk;
171 
172  Gui::LabelSet *m_clickableLabels;
173 
174  std::set<const Faction *> m_visibleFactions;
175  std::set<const Faction *> m_hiddenFactions;
176 
177  Uint8 m_detailBoxVisible;
178 
179  void OnToggleFaction(Gui::ToggleButton *button, bool pressed, const Faction *faction);
180 
181  sigc::connection m_onMouseWheelCon;
182  sigc::connection m_onToggleSelectionFollowView;
183  sigc::connection m_onWarpToCurrent;
184  sigc::connection m_onWarpToSelected;
185  sigc::connection m_onViewReset;
186 
187  RefCountedPtr<SectorCache::Slave> m_sectorCache;
188  std::string m_previousSearch;
189 
190  float m_playerHyperspaceRange;
191  Graphics::Drawables::Line3D m_selectedLine;
192  Graphics::Drawables::Line3D m_secondLine;
193  Graphics::Drawables::Line3D m_jumpLine;
194 
195  // HyperJump Route Planner Stuff
196  std::vector<SystemPath> m_route;
197  Graphics::Drawables::Lines m_routeLines;
198  bool m_drawRouteLines;
199  bool m_setupRouteLines;
200  void DrawRouteLines(const matrix4x4f &trans);
201  void SetupRouteLines(const vector3f &playerAbsPos);
202  void GetPlayerPosAndStarSize(vector3f &playerPosOut, float &currentStarSizeOut);
203 
204  Graphics::RenderState *m_solidState;
205  Graphics::RenderState *m_alphaBlendState;
206  Graphics::RenderState *m_jumpSphereState;
207  RefCountedPtr<Graphics::Material> m_material; //flat colour
208  RefCountedPtr<Graphics::Material> m_starMaterial;
209 
210  std::vector<vector3f> m_farstars;
211  std::vector<Color> m_farstarsColor;
212 
213  vector3f m_secPosFar;
214  int m_radiusFar;
215  bool m_toggledFaction;
216 
217  int m_cacheXMin;
218  int m_cacheXMax;
219  int m_cacheYMin;
220  int m_cacheYMax;
221  int m_cacheZMin;
222  int m_cacheZMax;
223 
224  std::unique_ptr<Graphics::VertexArray> m_lineVerts;
225  std::unique_ptr<Graphics::VertexArray> m_secLineVerts;
227  std::unique_ptr<Graphics::Drawables::Sphere3D> m_jumpSphere;
228  std::unique_ptr<Graphics::VertexArray> m_starVerts;
229 
231  Graphics::Drawables::Lines m_sectorlines;
232  Graphics::Drawables::Points m_farstarsPoints;
233 };
234 
235 #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:39
Definition: Drawables.h:56
Definition: Drawables.h:79
Definition: Drawables.h:114
Definition: RenderState.h:25
Definition: GuiLabelSet.h:15
Definition: GuiLabel.h:17
Definition: GuiToggleButton.h:11
Definition: PiGuiView.h:11
Definition: RefCounted.h:36
Definition: SectorView.h:25
void SetHyperspaceTarget(const SystemPath &path)
Definition: SectorView.cpp:509
~SectorView() override
Definition: SectorView.cpp:386
SectorView::InputBinding InputBindings
void GotoSystem(const SystemPath &path)
Definition: SectorView.cpp:535
sigc::signal< void > onHyperspaceTargetChanged
Definition: SectorView.h:49
double GetZoomLevel() const
Definition: SectorView.cpp:1467
void SetDrawRouteLines(bool value)
Definition: SectorView.h:77
const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector< SystemPath > &outRoute) const
Definition: SectorView.cpp:819
void ZoomIn()
Definition: SectorView.cpp:1472
void SwitchToPath(const SystemPath &path)
Definition: SectorView.cpp:570
vector3f GetCenterSector()
Definition: SectorView.cpp:1490
std::vector< SystemPath > GetRoute()
Definition: SectorView.cpp:814
double GetCenterDistance()
Definition: SectorView.cpp:1495
SectorView(Game *game)
Definition: SectorView.cpp:233
bool MoveRouteItemDown(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:775
void OnSwitchFrom() override
Definition: SectorView.cpp:1286
void ShowAll() override
Definition: SectorView.cpp:1416
const std::set< const Faction * > & GetVisibleFactions()
Definition: SectorView.h:61
void ResetHyperspaceTarget()
Definition: SectorView.cpp:515
void UpdateRouteItem(const std::vector< SystemPath >::size_type element, const SystemPath &path)
Definition: SectorView.cpp:785
void ResetView()
Definition: SectorView.cpp:1562
void Update() override
Definition: SectorView.cpp:1291
void SaveToJson(Json &jsonObj) override
Definition: SectorView.cpp:395
void SetDrawVerticalLines(bool value)
Definition: SectorView.h:57
bool MoveRouteItemUp(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:765
SystemPath GetCurrent() const
Definition: SectorView.h:35
void AddToRoute(const SystemPath &path)
Definition: SectorView.cpp:791
void SetAutomaticSystemSelection(bool value)
Definition: SectorView.h:59
vector3f GetPosition() const
Definition: SectorView.h:34
void GotoHyperspaceTarget()
Definition: SectorView.h:45
void OnSwitchTo() override
Definition: SectorView.cpp:1279
void GotoSelectedSystem()
Definition: SectorView.h:44
void GotoSector(const SystemPath &path)
Definition: SectorView.cpp:525
void GotoCurrentSystem()
Definition: SectorView.h:43
void SetDrawUninhabitedLabels(bool value)
Definition: SectorView.h:56
bool IsCenteredOn(const SystemPath &path)
Definition: SectorView.cpp:549
SystemPath GetSelected() const
Definition: SectorView.h:36
void ZoomOut()
Definition: SectorView.cpp:1481
std::vector< SystemPath > GetNearbyStarSystemsByName(std::string pattern)
Definition: SectorView.cpp:1505
void Draw3D() override
Definition: SectorView.cpp:425
const std::set< const Faction * > & GetHiddenFactions()
Definition: SectorView.h:62
void SetDrawOutRangeLabels(bool value)
Definition: SectorView.h:58
void SetFactionVisible(const Faction *faction, bool visible)
Definition: SectorView.cpp:1535
SystemPath GetHyperspaceTarget() const
Definition: SectorView.h:38
bool RemoveRouteItem(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:797
void ClearRoute()
Definition: SectorView.cpp:808
void SetRotateMode(bool enable)
Definition: SectorView.cpp:1553
void SetZoomMode(bool enable)
Definition: SectorView.cpp:1544
Definition: SystemPath.h:13
Definition: Background.h:13
Definition: Color.h:66
Definition: InputBindings.h:142
Definition: InputBindings.h:168
Definition: Input.h:45
Definition: SectorView.h:83
void RegisterBindings() override
Definition: SectorView.cpp:217
Axis * mapViewYaw
Definition: SectorView.h:94
Action * mapViewReset
Definition: SectorView.h:89
Axis * mapViewMoveForward
Definition: SectorView.h:91
Axis * mapViewMoveLeft
Definition: SectorView.h:92
Axis * mapViewPitch
Definition: SectorView.h:95
Action * mapWarpToSelected
Definition: SectorView.h:88
Axis * mapViewMoveUp
Definition: SectorView.h:93
Action * mapToggleSelectionFollowView
Definition: SectorView.h:86
Action * mapWarpToCurrent
Definition: SectorView.h:87
Axis * mapViewZoom
Definition: SectorView.h:96