Skip to content

Commit

Permalink
refactor(views): merge PiGuiView into View
Browse files Browse the repository at this point in the history
Merge the functionality from PiGuiView into the base-class View and
remove the now obsolete PiGuiView.

This is in preparation of refactoring the View names and simplifying how
the Lua side accesses Views.
  • Loading branch information
mwerle committed Nov 19, 2024
1 parent 0c3510c commit e7f216f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 63 deletions.
9 changes: 4 additions & 5 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "SystemView.h"
#include "WorldView.h"
#include "galaxy/GalaxyGenerator.h"
#include "pigui/PiGuiView.h"
#include "ship/PlayerShipController.h"

Game::Game(const SystemPath &path, const double startDateTime, const char *shipType) :
Expand Down Expand Up @@ -824,8 +823,8 @@ void Game::Views::Init(Game *game)
m_sectorView = new SectorView(game);
m_worldView = new WorldView(game);
m_systemView = new SystemView(game);
m_spaceStationView = new PiGuiView("StationView");
m_infoView = new PiGuiView("InfoView");
m_spaceStationView = new View("StationView");
m_infoView = new View("InfoView");
m_deathView = new DeathView(game);

#if WITH_OBJECTVIEWER
Expand All @@ -841,8 +840,8 @@ void Game::Views::LoadFromJson(const Json &jsonObj, Game *game)
m_worldView = new WorldView(jsonObj, game);

m_systemView = new SystemView(game);
m_spaceStationView = new PiGuiView("StationView");
m_infoView = new PiGuiView("InfoView");
m_spaceStationView = new View("StationView");
m_infoView = new View("InfoView");
m_deathView = new DeathView(game);

#if WITH_OBJECTVIEWER
Expand Down
4 changes: 2 additions & 2 deletions src/ObjectViewerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#if WITH_OBJECTVIEWER

ObjectViewerView::ObjectViewerView() :
PiGuiView("ObjectViewerView"),
View("ObjectViewerView"),
m_targetBody(nullptr),
m_systemBody(nullptr),
m_state{},
Expand Down Expand Up @@ -253,7 +253,7 @@ void ObjectViewerView::DrawPiGui()
DrawControlsWindow();
}

PiGuiView::DrawPiGui();
View::DrawPiGui();
}

static constexpr fixed dtofixed(double val, uint32_t denom = 1 << 16)
Expand Down
4 changes: 2 additions & 2 deletions src/ObjectViewerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#define _OBJECTVIEWERVIEW_H

#include "Camera.h"
#include "pigui/PiGuiView.h"
#include "View.h"

class Body;
class SystemBody;

class ObjectViewerView : public PiGuiView {
class ObjectViewerView : public View {
public:
ObjectViewerView();
virtual void Update() override;
Expand Down
4 changes: 2 additions & 2 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SectorMapContext SectorView::CreateMapContext()
}

SectorView::SectorView(Game *game) :
PiGuiView("sector-view"),
View("sector-view"),
InputBindings(Pi::input),
m_game(*game),
m_map(new SectorMap(CreateMapContext()))
Expand All @@ -145,7 +145,7 @@ SectorView::SectorView(Game *game) :
}

SectorView::SectorView(const Json &jsonObj, Game *game) :
PiGuiView("sector-view"),
View("sector-view"),
InputBindings(Pi::input),
m_game(*game)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SectorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "JsonFwd.h"

#include "galaxy/SystemPath.h"
#include "pigui/PiGuiView.h"
#include "View.h"

#include "vector3.h"
#include "matrix4x4.h"
Expand All @@ -20,7 +20,7 @@ class Galaxy;
class SectorMap;
struct SectorMapContext;

class SectorView : public PiGuiView, public DeleteEmitter {
class SectorView : public View, public DeleteEmitter {
public:
SectorView(Game *game);
SectorView(const Json &jsonObj, Game *game);
Expand Down
2 changes: 1 addition & 1 deletion src/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace {
// ─── System View ─────────────────────────────────────────────────────────────

SystemView::SystemView(Game *game) :
PiGuiView("system-view"),
View("system-view"),
m_game(game),
m_displayMode(Mode::Orrery),
m_systemSelectionMode(SystemSelectionMode::SELECTED_SYSTEM),
Expand Down
6 changes: 3 additions & 3 deletions src/SystemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "graphics/Drawables.h"
#include "graphics/Graphics.h"
#include "matrix4x4.h"
#include "pigui/PiGuiView.h"
#include "vector3.h"
#include "View.h"

#include <sigc++/signal.h>

Expand Down Expand Up @@ -155,13 +155,13 @@ struct AtlasBodyLayout {
class SystemMapViewport;

/**
* SystemView glues a SystemMapViewport to the PiGuiView framework and handles
* SystemView glues a SystemMapViewport to the View framework and handles
* most user interaction in the context of a running game.
*
* It is responsible for pushing ship contacts and managing the orbit planner
* interface.
*/
class SystemView : public PiGuiView, public DeleteEmitter {
class SystemView : public View, public DeleteEmitter {
public:
enum class Mode { // <enum name=SystemViewMode scope='SystemView::Mode' public>
Orrery = 0,
Expand Down
6 changes: 6 additions & 0 deletions src/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "View.h"
#include "Pi.h"
#include "pigui/LuaPiGui.h"

View::View() :
m_renderer(nullptr)
Expand All @@ -22,3 +23,8 @@ void View::Detach()
{
OnSwitchFrom();
}

void View::DrawPiGui()
{
PiGui::RunHandler(Pi::GetFrameTime(), m_handlerName);
}
10 changes: 5 additions & 5 deletions src/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class View {
public:
View();
virtual ~View();
virtual void Draw(){};
virtual void Draw() {};
// called before Gui::Draw will call widget ::Draw methods.
virtual void Draw3D() = 0;
virtual void Draw3D() {};
// for checking key states, mouse crud
virtual void Update() = 0;
virtual void Update() {};
// Called during the pigui frame to draw UI
virtual void DrawPiGui(){};
virtual void DrawPiGui();
virtual void SaveToJson(Json &jsonObj) {}
virtual void LoadFromJson(const Json &jsonObj) {}

Expand All @@ -37,7 +37,7 @@ class View {
void SetRenderer(Graphics::Renderer *r) { m_renderer = r; }

protected:
virtual void OnSwitchTo() = 0;
virtual void OnSwitchTo() {};
virtual void OnSwitchFrom() {}
Graphics::Renderer *m_renderer;
};
Expand Down
4 changes: 2 additions & 2 deletions src/WorldView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ void WorldView::InputBinding::RegisterBindings()
}

WorldView::WorldView(Game *game) :
PiGuiView("WorldView"),
View("WorldView"),
m_game(game),
InputBindings(Pi::input)
{
InitObject();
}

WorldView::WorldView(const Json &jsonObj, Game *game) :
PiGuiView("WorldView"),
View("WorldView"),
m_game(game),
InputBindings(Pi::input)
{
Expand Down
4 changes: 2 additions & 2 deletions src/WorldView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "ConnectionTicket.h"
#include "graphics/Drawables.h"
#include "pigui/PiGuiView.h"
#include "ship/ShipViewController.h"
#include "View.h"

class Body;
class Camera;
Expand All @@ -27,7 +27,7 @@ enum PlaneType {
PARENT
};

class WorldView : public PiGuiView {
class WorldView : public View {
public:
static void RegisterInputBindings();
friend class NavTunnelWidget;
Expand Down
11 changes: 0 additions & 11 deletions src/pigui/PiGuiView.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions src/pigui/PiGuiView.h

This file was deleted.

0 comments on commit e7f216f

Please sign in to comment.