From e7f216f8fb76456135dabcc114346b739a75d59f Mon Sep 17 00:00:00 2001 From: Michael Werle Date: Tue, 19 Nov 2024 16:37:05 +0900 Subject: [PATCH] refactor(views): merge PiGuiView into View 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. --- src/Game.cpp | 9 ++++----- src/ObjectViewerView.cpp | 4 ++-- src/ObjectViewerView.h | 4 ++-- src/SectorView.cpp | 4 ++-- src/SectorView.h | 4 ++-- src/SystemView.cpp | 2 +- src/SystemView.h | 6 +++--- src/View.cpp | 6 ++++++ src/View.h | 10 +++++----- src/WorldView.cpp | 4 ++-- src/WorldView.h | 4 ++-- src/pigui/PiGuiView.cpp | 11 ----------- src/pigui/PiGuiView.h | 26 -------------------------- 13 files changed, 31 insertions(+), 63 deletions(-) delete mode 100644 src/pigui/PiGuiView.cpp delete mode 100644 src/pigui/PiGuiView.h diff --git a/src/Game.cpp b/src/Game.cpp index 8e5e634a9f6..73b421af1c4 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -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) : @@ -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 @@ -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 diff --git a/src/ObjectViewerView.cpp b/src/ObjectViewerView.cpp index 51439b5d25c..bb7a0183412 100644 --- a/src/ObjectViewerView.cpp +++ b/src/ObjectViewerView.cpp @@ -27,7 +27,7 @@ #if WITH_OBJECTVIEWER ObjectViewerView::ObjectViewerView() : - PiGuiView("ObjectViewerView"), + View("ObjectViewerView"), m_targetBody(nullptr), m_systemBody(nullptr), m_state{}, @@ -253,7 +253,7 @@ void ObjectViewerView::DrawPiGui() DrawControlsWindow(); } - PiGuiView::DrawPiGui(); + View::DrawPiGui(); } static constexpr fixed dtofixed(double val, uint32_t denom = 1 << 16) diff --git a/src/ObjectViewerView.h b/src/ObjectViewerView.h index c4ae4b1db06..3753ec14d03 100644 --- a/src/ObjectViewerView.h +++ b/src/ObjectViewerView.h @@ -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; diff --git a/src/SectorView.cpp b/src/SectorView.cpp index 3ed524e1610..2ca1926aa2b 100644 --- a/src/SectorView.cpp +++ b/src/SectorView.cpp @@ -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())) @@ -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) { diff --git a/src/SectorView.h b/src/SectorView.h index a75d0196993..bb3ffd6de27 100644 --- a/src/SectorView.h +++ b/src/SectorView.h @@ -10,7 +10,7 @@ #include "JsonFwd.h" #include "galaxy/SystemPath.h" -#include "pigui/PiGuiView.h" +#include "View.h" #include "vector3.h" #include "matrix4x4.h" @@ -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); diff --git a/src/SystemView.cpp b/src/SystemView.cpp index aa423dccec2..a08a4996bd3 100644 --- a/src/SystemView.cpp +++ b/src/SystemView.cpp @@ -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), diff --git a/src/SystemView.h b/src/SystemView.h index 49b67a8d7c0..331cdc59514 100644 --- a/src/SystemView.h +++ b/src/SystemView.h @@ -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 @@ -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 { // Orrery = 0, diff --git a/src/View.cpp b/src/View.cpp index c6f38203159..aafdbd4d8b3 100644 --- a/src/View.cpp +++ b/src/View.cpp @@ -3,6 +3,7 @@ #include "View.h" #include "Pi.h" +#include "pigui/LuaPiGui.h" View::View() : m_renderer(nullptr) @@ -22,3 +23,8 @@ void View::Detach() { OnSwitchFrom(); } + +void View::DrawPiGui() +{ + PiGui::RunHandler(Pi::GetFrameTime(), m_handlerName); +} diff --git a/src/View.h b/src/View.h index 63b836f0253..59478af2a97 100644 --- a/src/View.h +++ b/src/View.h @@ -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) {} @@ -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; }; diff --git a/src/WorldView.cpp b/src/WorldView.cpp index 83bf77b939c..e27c9a4a300 100644 --- a/src/WorldView.cpp +++ b/src/WorldView.cpp @@ -63,7 +63,7 @@ void WorldView::InputBinding::RegisterBindings() } WorldView::WorldView(Game *game) : - PiGuiView("WorldView"), + View("WorldView"), m_game(game), InputBindings(Pi::input) { @@ -71,7 +71,7 @@ WorldView::WorldView(Game *game) : } WorldView::WorldView(const Json &jsonObj, Game *game) : - PiGuiView("WorldView"), + View("WorldView"), m_game(game), InputBindings(Pi::input) { diff --git a/src/WorldView.h b/src/WorldView.h index 4bf31913059..e76f95a7eef 100644 --- a/src/WorldView.h +++ b/src/WorldView.h @@ -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; @@ -27,7 +27,7 @@ enum PlaneType { PARENT }; -class WorldView : public PiGuiView { +class WorldView : public View { public: static void RegisterInputBindings(); friend class NavTunnelWidget; diff --git a/src/pigui/PiGuiView.cpp b/src/pigui/PiGuiView.cpp deleted file mode 100644 index a20b0b603f2..00000000000 --- a/src/pigui/PiGuiView.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details -// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt - -#include "pigui/PiGuiView.h" -#include "LuaPiGui.h" -#include "Pi.h" - -void PiGuiView::DrawPiGui() -{ - PiGui::RunHandler(Pi::GetFrameTime(), m_handlerName); -} diff --git a/src/pigui/PiGuiView.h b/src/pigui/PiGuiView.h deleted file mode 100644 index 636e7895f9c..00000000000 --- a/src/pigui/PiGuiView.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details -// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt - -#pragma once - -#include "../View.h" - -// Replacement for UIView. This class dispatches to lua-registered pigui draw -// functions when DrawPiGui() is called. -// TODO: support rendering to a debug window during the Update() and Draw3D() methods. -class PiGuiView : public View { -public: - PiGuiView(const std::string &name) : - m_handlerName(name) {} - - virtual void Update() override {} - virtual void Draw3D() override {} - virtual void DrawPiGui() override; - - const std::string &GetViewName() { return m_handlerName; } - -private: - virtual void OnSwitchTo() override{}; - - std::string m_handlerName; -};