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 
162  SystemPath m_hyperspaceTarget;
163  bool m_automaticSystemSelection;
164 
165  bool m_drawUninhabitedLabels;
166  bool m_drawOutRangeLabels;
167  bool m_drawVerticalLines;
168 
169  std::unique_ptr<Graphics::Drawables::Disk> m_disk;
170 
171  Gui::LabelSet *m_clickableLabels;
172 
173  std::set<const Faction *> m_visibleFactions;
174  std::set<const Faction *> m_hiddenFactions;
175 
176  Uint8 m_detailBoxVisible;
177 
178  void OnToggleFaction(Gui::ToggleButton *button, bool pressed, const Faction *faction);
179 
180  sigc::connection m_onMouseWheelCon;
181  sigc::connection m_onToggleSelectionFollowView;
182  sigc::connection m_onWarpToCurrent;
183  sigc::connection m_onWarpToSelected;
184  sigc::connection m_onViewReset;
185 
186  RefCountedPtr<SectorCache::Slave> m_sectorCache;
187  std::string m_previousSearch;
188 
189  float m_playerHyperspaceRange;
190  Graphics::Drawables::Line3D m_selectedLine;
191  Graphics::Drawables::Line3D m_secondLine;
192  Graphics::Drawables::Line3D m_jumpLine;
193 
194  // HyperJump Route Planner Stuff
195  std::vector<SystemPath> m_route;
196  Graphics::Drawables::Lines m_routeLines;
197  bool m_drawRouteLines;
198  bool m_setupRouteLines;
199  void DrawRouteLines(const matrix4x4f &trans);
200  void SetupRouteLines(const vector3f &playerAbsPos);
201  void GetPlayerPosAndStarSize(vector3f &playerPosOut, float &currentStarSizeOut);
202 
203  Graphics::RenderState *m_solidState;
204  Graphics::RenderState *m_alphaBlendState;
205  Graphics::RenderState *m_jumpSphereState;
206  RefCountedPtr<Graphics::Material> m_material; //flat colour
207  RefCountedPtr<Graphics::Material> m_starMaterial;
208 
209  std::vector<vector3f> m_farstars;
210  std::vector<Color> m_farstarsColor;
211 
212  vector3f m_secPosFar;
213  int m_radiusFar;
214  bool m_toggledFaction;
215 
216  int m_cacheXMin;
217  int m_cacheXMax;
218  int m_cacheYMin;
219  int m_cacheYMax;
220  int m_cacheZMin;
221  int m_cacheZMax;
222 
223  std::unique_ptr<Graphics::VertexArray> m_lineVerts;
224  std::unique_ptr<Graphics::VertexArray> m_secLineVerts;
226  std::unique_ptr<Graphics::Drawables::Sphere3D> m_jumpSphere;
227  std::unique_ptr<Graphics::VertexArray> m_starVerts;
228 
230  Graphics::Drawables::Lines m_sectorlines;
231  Graphics::Drawables::Points m_farstarsPoints;
232 };
233 
234 #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:375
~SectorView() override
Definition: SectorView.cpp:250
SectorView::InputBinding InputBindings
void GotoSystem(const SystemPath &path)
Definition: SectorView.cpp:401
sigc::signal< void > onHyperspaceTargetChanged
Definition: SectorView.h:49
double GetZoomLevel() const
Definition: SectorView.cpp:1353
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:685
void ZoomIn()
Definition: SectorView.cpp:1358
void SwitchToPath(const SystemPath &path)
Definition: SectorView.cpp:436
vector3f GetCenterSector()
Definition: SectorView.cpp:1376
std::vector< SystemPath > GetRoute()
Definition: SectorView.cpp:680
double GetCenterDistance()
Definition: SectorView.cpp:1381
SectorView(Game *game)
Definition: SectorView.cpp:97
bool MoveRouteItemDown(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:641
void OnSwitchFrom() override
Definition: SectorView.cpp:1152
void ShowAll() override
Definition: SectorView.cpp:1302
const std::set< const Faction * > & GetVisibleFactions()
Definition: SectorView.h:61
void ResetHyperspaceTarget()
Definition: SectorView.cpp:381
void UpdateRouteItem(const std::vector< SystemPath >::size_type element, const SystemPath &path)
Definition: SectorView.cpp:651
void ResetView()
Definition: SectorView.cpp:1448
void Update() override
Definition: SectorView.cpp:1157
void SaveToJson(Json &jsonObj) override
Definition: SectorView.cpp:259
void SetDrawVerticalLines(bool value)
Definition: SectorView.h:57
bool MoveRouteItemUp(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:631
SystemPath GetCurrent() const
Definition: SectorView.h:35
void AddToRoute(const SystemPath &path)
Definition: SectorView.cpp:657
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:1145
void GotoSelectedSystem()
Definition: SectorView.h:44
void GotoSector(const SystemPath &path)
Definition: SectorView.cpp:391
void GotoCurrentSystem()
Definition: SectorView.h:43
void SetDrawUninhabitedLabels(bool value)
Definition: SectorView.h:56
bool IsCenteredOn(const SystemPath &path)
Definition: SectorView.cpp:415
SystemPath GetSelected() const
Definition: SectorView.h:36
void ZoomOut()
Definition: SectorView.cpp:1367
std::vector< SystemPath > GetNearbyStarSystemsByName(std::string pattern)
Definition: SectorView.cpp:1391
void Draw3D() override
Definition: SectorView.cpp:291
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:1421
SystemPath GetHyperspaceTarget() const
Definition: SectorView.h:38
bool RemoveRouteItem(const std::vector< SystemPath >::size_type element)
Definition: SectorView.cpp:663
void ClearRoute()
Definition: SectorView.cpp:674
void SetRotateMode(bool enable)
Definition: SectorView.cpp:1439
void SetZoomMode(bool enable)
Definition: SectorView.cpp:1430
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:81
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