pioneer/src/SectorView.h

235 lines
7.0 KiB
C
Raw Normal View History

2020-12-31 07:32:16 -08:00
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2012-09-15 17:59:15 -07:00
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
2012-09-12 04:38:30 -07:00
#ifndef _SECTORVIEW_H
#define _SECTORVIEW_H
2020-11-22 16:15:30 -08:00
#include "DeleteEmitter.h"
#include "Input.h"
#include "galaxy/Sector.h"
#include "galaxy/SystemPath.h"
#include "graphics/Drawables.h"
#include "gui/Gui.h"
2020-11-22 16:15:30 -08:00
#include "pigui/PiGuiView.h"
2014-01-26 17:26:44 -08:00
#include <set>
#include <string>
#include <vector>
2014-09-15 11:30:54 -07:00
class Game;
class Galaxy;
2014-09-15 11:30:54 -07:00
namespace Graphics {
class RenderState;
}
2020-11-22 16:15:30 -08:00
class SectorView : public PiGuiView, public DeleteEmitter {
public:
SectorView(Game *game);
SectorView(const Json &jsonObj, Game *game);
~SectorView() override;
void Update() override;
void ShowAll() override;
void Draw3D() override;
vector3f GetPosition() const { return m_pos; }
2017-09-02 03:44:54 -07:00
SystemPath GetCurrent() const { return m_current; }
SystemPath GetSelected() const { return m_selected; }
void SwitchToPath(const SystemPath &path);
2011-06-27 23:49:59 -07:00
SystemPath GetHyperspaceTarget() const { return m_hyperspaceTarget; }
void SetHyperspaceTarget(const SystemPath &path);
void ResetHyperspaceTarget();
void GotoSector(const SystemPath &path);
void GotoSystem(const SystemPath &path);
2011-08-10 04:07:08 -07:00
void GotoCurrentSystem() { GotoSystem(m_current); }
void GotoSelectedSystem() { GotoSystem(m_selected); }
void GotoHyperspaceTarget() { GotoSystem(m_hyperspaceTarget); }
bool IsCenteredOn(const SystemPath &path);
void SaveToJson(Json &jsonObj) override;
sigc::signal<void> onHyperspaceTargetChanged;
2017-09-02 03:44:54 -07:00
double GetZoomLevel() const;
void ZoomIn();
void ZoomOut();
vector3f GetCenterSector();
double GetCenterDistance();
void SetDrawUninhabitedLabels(bool value) { m_drawUninhabitedLabels = value; }
void SetDrawVerticalLines(bool value) { m_drawVerticalLines = value; }
void SetDrawOutRangeLabels(bool value) { m_drawOutRangeLabels = value; }
void SetAutomaticSystemSelection(bool value) { m_automaticSystemSelection = value; }
std::vector<SystemPath> GetNearbyStarSystemsByName(std::string pattern);
const std::set<const Faction *> &GetVisibleFactions() { return m_visibleFactions; }
const std::set<const Faction *> &GetHiddenFactions() { return m_hiddenFactions; }
void SetFactionVisible(const Faction *faction, bool visible);
void SetZoomMode(bool enable);
void SetRotateMode(bool enable);
void ResetView();
// HyperJump Route Planner
bool MoveRouteItemUp(const std::vector<SystemPath>::size_type element);
bool MoveRouteItemDown(const std::vector<SystemPath>::size_type element);
void UpdateRouteItem(const std::vector<SystemPath>::size_type element, const SystemPath &path);
void AddToRoute(const SystemPath &path);
bool RemoveRouteItem(const std::vector<SystemPath>::size_type element);
void ClearRoute();
std::vector<SystemPath> GetRoute();
const std::string AutoRoute(const SystemPath &start, const SystemPath &target, std::vector<SystemPath> &outRoute) const;
void SetDrawRouteLines(bool value) { m_drawRouteLines = value; }
Refactor to InputFrame 2.0 Significantly refactored the Input class, added Input::Manager to handle most duties of the Input system. Replaced the legacy KeyBindings system with the new InputBindings (namespace subject to change) system for handling key state and key chords - among other improvements, there is no longer a hardcoded dependency on Pi::input anymore, as well as storing the binding state in the binding itself, completely decoupling InputBindings from the input system that handles input events and significantly reducing the complexity of the binding system. Input::Manager now is totally responsible for generating binding events, removing the need for WorldView::HandleSDLEvent and its ilk - interested parties can simply bind to the onPressed event and they will only be notified when the binding in question is part of an active input frame and nothing else has grabbed the input event, vastly simplifying control flow. Among other effects, this almost totally eradicates the need for Pi::IsConsoleActive(). The lua Console widget is slightly broken as a result of this change, it doesn't handle activation/deactivation state changes properly. The solution to this seems to simply be a direct rewrite in PiGui, which I don't expect to cause too many issues. I've added a CMake option to use LLD to speed up incremental build link times; this seems to be somewhat platform dependent and is not implemented for windows at this time. Serialization of key bindings to the config file is totally completed, although support for a graphical method of binding multi-key chords is not anticipated for this pull request.
2020-04-18 14:58:00 -07:00
protected:
void OnSwitchTo() override;
void OnSwitchFrom() override;
struct InputBinding : public Input::InputFrame {
using InputFrame::InputFrame;
Action *mapToggleSelectionFollowView;
Action *mapWarpToCurrent;
Action *mapWarpToSelected;
Action *mapViewReset;
Axis *mapViewMoveForward;
Axis *mapViewMoveLeft;
Axis *mapViewMoveUp;
Axis *mapViewYaw;
Axis *mapViewPitch;
Axis *mapViewZoom;
2020-11-24 23:35:33 -08:00
void RegisterBindings() override;
} InputBindings;
private:
void InitDefaults();
void InitObject();
struct DistanceIndicator {
Gui::Label *label;
Graphics::Drawables::Line3D *line;
Color okayColor;
Color unsuffFuelColor;
Color outOfRangeColor;
};
struct SystemLabels {
Gui::Label *systemName;
Gui::Label *sector;
DistanceIndicator distance;
Gui::Label *starType;
Gui::Label *shortDesc;
};
void DrawNearSectors(const matrix4x4f &modelview);
void DrawNearSector(const int sx, const int sy, const int sz, const matrix4x4f &trans);
void PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius);
2011-08-12 00:10:58 -07:00
void DrawFarSectors(const matrix4x4f &modelview);
void BuildFarSector(RefCountedPtr<Sector> sec, const vector3f &origin, std::vector<vector3f> &points, std::vector<Color> &colors);
void PutFactionLabels(const vector3f &secPos);
void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);
void OnClickSystem(const SystemPath &path);
const SystemPath &CheckPathInRoute(const SystemPath &path);
2011-07-03 23:18:18 -07:00
RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
void ShrinkCache();
void SetSelected(const SystemPath &path);
void MouseWheel(bool up);
2011-08-19 01:58:35 -07:00
RefCountedPtr<Galaxy> m_galaxy;
2014-09-15 11:30:54 -07:00
bool m_inSystem;
2011-08-10 04:07:08 -07:00
SystemPath m_current;
SystemPath m_selected;
2011-07-18 06:27:00 -07:00
vector3f m_pos;
vector3f m_posMovingTo;
float m_rotXDefault, m_rotZDefault, m_zoomDefault;
float m_rotX, m_rotZ;
float m_rotXMovingTo, m_rotZMovingTo;
2011-08-15 14:49:19 -07:00
float m_zoom;
float m_zoomClamped;
2011-08-15 14:49:19 -07:00
float m_zoomMovingTo;
bool m_rotateWithMouseButton = false;
bool m_rotateView = false;
bool m_zoomView = false;
2011-06-27 23:49:59 -07:00
SystemPath m_hyperspaceTarget;
bool m_automaticSystemSelection;
2011-08-12 00:10:58 -07:00
2017-09-02 03:44:54 -07:00
bool m_drawUninhabitedLabels;
bool m_drawOutRangeLabels;
bool m_drawVerticalLines;
std::unique_ptr<Graphics::Drawables::Disk> m_disk;
Gui::LabelSet *m_clickableLabels;
2011-07-03 23:18:18 -07:00
std::set<const Faction *> m_visibleFactions;
std::set<const Faction *> m_hiddenFactions;
Uint8 m_detailBoxVisible;
void OnToggleFaction(Gui::ToggleButton *button, bool pressed, const Faction *faction);
sigc::connection m_onMouseWheelCon;
sigc::connection m_onToggleSelectionFollowView;
sigc::connection m_onWarpToCurrent;
sigc::connection m_onWarpToSelected;
sigc::connection m_onViewReset;
RefCountedPtr<SectorCache::Slave> m_sectorCache;
std::string m_previousSearch;
float m_playerHyperspaceRange;
Graphics::Drawables::Line3D m_selectedLine;
Graphics::Drawables::Line3D m_secondLine;
Graphics::Drawables::Line3D m_jumpLine;
// HyperJump Route Planner Stuff
std::vector<SystemPath> m_route;
Graphics::Drawables::Lines m_routeLines;
bool m_drawRouteLines;
bool m_setupRouteLines;
void DrawRouteLines(const matrix4x4f &trans);
void SetupRouteLines(const vector3f &playerAbsPos);
void GetPlayerPosAndStarSize(vector3f &playerPosOut, float &currentStarSizeOut);
2014-01-26 17:26:44 -08:00
Graphics::RenderState *m_solidState;
Graphics::RenderState *m_alphaBlendState;
Graphics::RenderState *m_jumpSphereState;
RefCountedPtr<Graphics::Material> m_material; //flat colour
RefCountedPtr<Graphics::Material> m_starMaterial;
2012-11-26 11:42:58 -08:00
std::vector<vector3f> m_farstars;
std::vector<Color> m_farstarsColor;
vector3f m_secPosFar;
int m_radiusFar;
bool m_toggledFaction;
int m_cacheXMin;
int m_cacheXMax;
int m_cacheYMin;
int m_cacheYMax;
int m_cacheZMin;
int m_cacheZMax;
std::unique_ptr<Graphics::VertexArray> m_lineVerts;
std::unique_ptr<Graphics::VertexArray> m_secLineVerts;
RefCountedPtr<Graphics::Material> m_fresnelMat;
std::unique_ptr<Graphics::Drawables::Sphere3D> m_jumpSphere;
std::unique_ptr<Graphics::VertexArray> m_starVerts;
Graphics::Drawables::Lines m_lines;
Graphics::Drawables::Lines m_sectorlines;
Graphics::Drawables::Points m_farstarsPoints;
};
#endif /* _SECTORVIEW_H */