diff --git a/data/libs/Player.lua b/data/libs/Player.lua index ad5e8be0a4..2a19e7ad45 100644 --- a/data/libs/Player.lua +++ b/data/libs/Player.lua @@ -434,8 +434,8 @@ end local onEnterSystem = function (ship) if not ship.IsPlayer() then return end -- Return to game view when we exit hyperspace - if Engine.GetResetViewOnHyperspaceExit() and Game.CurrentView() ~= "world" then - Game.SetView("world") + if Engine.GetResetViewOnHyperspaceExit() and Game.CurrentView() ~= "WorldView" then + Game.SetView("WorldView") end end diff --git a/data/modules/MusicPlayer.lua b/data/modules/MusicPlayer.lua index 4c81f1e394..17979ace1d 100644 --- a/data/modules/MusicPlayer.lua +++ b/data/modules/MusicPlayer.lua @@ -147,7 +147,7 @@ Event.Register("onSongFinished", function () else playAmbient() end - elseif Game.CurrentView() == "sector" or Game.CurrentView() == "system_info" or Game.CurrentView() == "system" then + elseif Game.CurrentView() == "SectorView" or Game.CurrentView() == "SystemView" then if Game.system and Game.system:DistanceTo(SystemPath.New(0, 0, 0, 0, 0)) < 1000 then -- farther than where ambient music switches if music["map-core"] then MusicPlayer.playRandomSongFromCategory("map-core") @@ -238,7 +238,7 @@ end) -- view has changed, so player might have left the map view Event.Register("onViewChanged", function() - if inMapView and Game.CurrentView() == "world" then + if inMapView and Game.CurrentView() == "WorldView" then playAmbient() inMapView = false end diff --git a/data/pigui/modules/autopilot-window.lua b/data/pigui/modules/autopilot-window.lua index 9d99cd1cad..78b9f97de6 100644 --- a/data/pigui/modules/autopilot-window.lua +++ b/data/pigui/modules/autopilot-window.lua @@ -258,12 +258,12 @@ local function displayAutoPilotWindow() ui.setNextWindowPos(Vector2(window_posx, window_posy) , "Always") ui.window("AutoPilot", {"NoTitleBar", "NoResize", "NoFocusOnAppearing", "NoBringToFrontOnFocus", "NoSavedSettings", "AlwaysAutoResize"}, function() - if current_view == "world" then + if current_view == "WorldView" then ui.addCursorPos(Vector2(0, shift)) if button_hyperspace() then ui.sameLine() end if button_undock() then ui.sameLine() end speed_limiter.show() - end -- current_view == "world" + end -- current_view == "WorldView" end) end diff --git a/data/pigui/modules/equipment.lua b/data/pigui/modules/equipment.lua index 83691e34a4..5b4d8312de 100644 --- a/data/pigui/modules/equipment.lua +++ b/data/pigui/modules/equipment.lua @@ -59,7 +59,7 @@ end local function displayECM(uiPos) player = Game.player local current_view = Game.CurrentView() - if current_view == "world" then + if current_view == "WorldView" then local ecms = player:GetComponent("EquipSet"):GetInstalledOfType("utility.ecm") for i,ecm in ipairs(ecms) do local size, clicked = iconEqButton(uiPos, icons[ecm.ecm_type], false, mainIconSize, "ECM", not player:IsECMReady(), mainBackgroundColor, mainForegroundColor, mainHoverColor, mainPressedColor, lec[ecm.hover_message]) @@ -93,7 +93,7 @@ local function displayMissiles(uiPos) player = Game.player local current_view = Game.CurrentView() - if current_view == "world" then + if current_view == "WorldView" then local missiles = player:GetComponent("EquipSet"):GetInstalledOfType("missile") local count = {} diff --git a/data/pigui/modules/fx-window.lua b/data/pigui/modules/fx-window.lua index 57d8a050d9..e7f6dd290e 100644 --- a/data/pigui/modules/fx-window.lua +++ b/data/pigui/modules/fx-window.lua @@ -17,9 +17,9 @@ local cam_tooltip = { internal = lui.HUD_BUTTON_INTERNAL_VIEW, external = lui.HU local function button_world(current_view) local camtype = Game.GetWorldCamType() local view_icon = camtype and "view_" .. camtype or "view_internal" - if current_view ~= "world" then + if current_view ~= "WorldView" then if ui.mainMenuButton(icons[view_icon], lui.HUD_BUTTON_SWITCH_TO_WORLD_VIEW) or (ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f1)) then - Game.SetView("world") + Game.SetView("WorldView") ui.playBoinkNoise() end else @@ -34,43 +34,43 @@ local function button_world(current_view) end end -local current_map_view = "sector" +local current_map_view = "SectorView" local function buttons_map(current_view) - local onmap = current_view == "sector" or current_view == "system" + local onmap = current_view == "SectorView" or current_view == "SystemView" ui.sameLine() - local active = current_view == "sector" + local active = current_view == "SectorView" if ui.mainMenuButton(icons.sector_map, lui.HUD_BUTTON_SWITCH_TO_SECTOR_MAP, active) or (onmap and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f5)) then if not active then - Game.SetView("sector") - current_map_view = "sector" + Game.SetView("SectorView") + current_map_view = "SectorView" end end ui.sameLine() local isOrrery = Game.systemView:GetDisplayMode() == "Orrery" - active = current_view == "system" and isOrrery + active = current_view == "SystemView" and isOrrery if ui.mainMenuButton(icons.system_map, lui.HUD_BUTTON_SWITCH_TO_SYSTEM_MAP, active) or (onmap and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f6)) then if not active then Game.systemView:SetDisplayMode('Orrery') - Game.SetView("system") - current_map_view = "system" + Game.SetView("SystemView") + current_map_view = "SystemView" end end ui.sameLine() - active = current_view == "system" and not isOrrery + active = current_view == "SystemView" and not isOrrery if ui.mainMenuButton(icons.system_overview, lui.HUD_BUTTON_SWITCH_TO_SYSTEM_OVERVIEW, active) or (onmap and ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f7)) then if not active then Game.systemView:SetDisplayMode('Atlas') - Game.SetView("system") - current_map_view = "system" + Game.SetView("SystemView") + current_map_view = "SystemView" end end if ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f2) then if onmap then - Game.SetView("world") + Game.SetView("WorldView") else Game.SetView(current_map_view) end @@ -79,10 +79,10 @@ end local function button_info(current_view) ui.sameLine() - local active = current_view == "info" + local active = current_view == "InfoView" if ui.mainMenuButton(icons.personal_info, lui.HUD_BUTTON_SHOW_PERSONAL_INFO, active) or (ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f3)) then if not active then - Game.SetView("info") + Game.SetView("InfoView") end end end @@ -90,10 +90,10 @@ end local function button_comms(current_view) if player:IsDocked() then ui.sameLine() - local active = current_view == "space_station" + local active = current_view == "StationView" if ui.mainMenuButton(icons.comms, lui.HUD_BUTTON_SHOW_COMMS, active) or (ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f4)) then if not active then - Game.SetView("space_station") + Game.SetView("StationView") end end end diff --git a/data/pigui/modules/master-alarm.lua b/data/pigui/modules/master-alarm.lua index 97efac0803..a29744918e 100644 --- a/data/pigui/modules/master-alarm.lua +++ b/data/pigui/modules/master-alarm.lua @@ -98,7 +98,7 @@ local function alarm () --player is closer to the body than the altitude calculated via evasion_factor if approach_speed < -25 and periapsis_radius < body_radius and (altitude - recover_distance) / ((approach_speed^2 + 2*surface_gravity*recover_distance)^(1/2)) < response_time_factor and body_radius/altitude > evasion_factor and Game.player:GetCurrentAICommand() ~= "CMD_DOCK" then alreadyAlertedImpact = false - if Game.CurrentView() == "world" then + if Game.CurrentView() == "WorldView" then ui.addStyledText(uiTextPos, ui.anchor.center, ui.anchor.top, lui.HUD_WARNING_DESCENT_RATE, colors.alertRed, pionillium.large, nil, colors.lightBlackBackground) end if not alreadyAlertedDescent then @@ -112,7 +112,7 @@ local function alarm () --player is still far enough away from the body elseif approach_speed < -25 and recover_distance > altitude and periapsis_radius < body_radius and body_radius/altitude <= evasion_factor and (periapsis_radius + (1/2)*max_accel*(altitude / -approach_speed)^2) >= body_radius then alreadyAlertedDescent = false - if Game.CurrentView() == "world" then + if Game.CurrentView() == "WorldView" then ui.addIcon(uiPos, icons.impact_warning, colors.alertYellow, iconSize, ui.anchor.center, ui.anchor.center, lui.HUD_WARNING_IMPACT) end if not alreadyAlertedImpact then @@ -123,7 +123,7 @@ local function alarm () --with the following formula, alert triggers if --player ship's acceleration rate would not allow them to avoid a collision by simply accelerating sideways --exact calculations require complex integrals, this alert is accurate enough but just a tiny bit on the pessimistic side for extra safety measures - elseif approach_speed < -25 and recover_distance > altitude and periapsis_radius < body_radius and body_radius/altitude <= evasion_factor and (periapsis_radius + (1/2)*max_accel*(altitude / -approach_speed)^2) < body_radius and Game.CurrentView() == "world" then + elseif approach_speed < -25 and recover_distance > altitude and periapsis_radius < body_radius and body_radius/altitude <= evasion_factor and (periapsis_radius + (1/2)*max_accel*(altitude / -approach_speed)^2) < body_radius and Game.CurrentView() == "WorldView" then ui.addIcon(uiPos, icons.impact_warning, colors.alertRed, iconSize, ui.anchor.center, ui.anchor.center, lui.HUD_WARNING_IMPACT_IMMINENT) else -- clean up warning status so we can warn the player the next time they are in danger alreadyAlertedImpact = false diff --git a/data/pigui/modules/planetary-info.lua b/data/pigui/modules/planetary-info.lua index 7cdbc3ccd4..f423013f52 100644 --- a/data/pigui/modules/planetary-info.lua +++ b/data/pigui/modules/planetary-info.lua @@ -18,7 +18,7 @@ local height = math.max(iconSize.y, font.size) * 2 + ui.getItemSpacing().y + ui. local function displayPlanetaryInfo() local player = Game.player local current_view = Game.CurrentView() - if current_view == "world" then + if current_view == "WorldView" then local alt, vspd, latitude, longitude = player:GetGPS() if latitude and longitude and alt and vspd then ui.setNextWindowSize(Vector2(width, height), "Always") diff --git a/data/pigui/modules/radar.lua b/data/pigui/modules/radar.lua index d93669ad59..8fb7c0ed6d 100644 --- a/data/pigui/modules/radar.lua +++ b/data/pigui/modules/radar.lua @@ -275,7 +275,7 @@ local click_on_radar = false -- display either the 3D or the 2D radar, show a popup on right click to select local function displayRadar() - if ui.optionsWindow.isOpen or Game.CurrentView() ~= "world" then return end + if ui.optionsWindow.isOpen or Game.CurrentView() ~= "WorldView" then return end player = player or Game.player -- only display if there actually *is* a radar installed @@ -377,10 +377,10 @@ local function displayRadar() end -- function displayRadar() -- view has changed, update input frame -Event.Register("onViewChanged", function() - if Game.CurrentView() == "world" then +Event.Register("onViewChanged", function(newView, previousView) + if newView == "WorldView" then input_frame:AddToStack() - else + elseif previousView == "WorldView" then input_frame:RemoveFromStack() end end) diff --git a/data/pigui/modules/ship-internals-window.lua b/data/pigui/modules/ship-internals-window.lua index fc3b57168d..fe6486a33c 100644 --- a/data/pigui/modules/ship-internals-window.lua +++ b/data/pigui/modules/ship-internals-window.lua @@ -110,7 +110,7 @@ local function displayShipFunctionWindow() local window_posy = ui.screenHeight - window_height ui.setNextWindowPos(Vector2(window_posx, window_posy), "Always") ui.window("ShipFunctions", windowFlags, function() - if current_view == "world" then + if current_view == "WorldView" then local shift = Vector2(0.0, thrust_widget_size.y - mainButtonSize.y) ui.addCursorPos(shift) button_wheelstate() @@ -124,7 +124,7 @@ local function displayShipFunctionWindow() if ui.noModifierHeld() and ui.isKeyReleased(ui.keys.f8) then show_thrust_slider = not show_thrust_slider end - end -- current_view == "world" + end -- current_view == "WorldView" end) end diff --git a/data/pigui/modules/system-view-ui.lua b/data/pigui/modules/system-view-ui.lua index b4d4212769..97211aba85 100644 --- a/data/pigui/modules/system-view-ui.lua +++ b/data/pigui/modules/system-view-ui.lua @@ -902,7 +902,7 @@ local function displaySystemViewUI() if not ui.shouldDrawUI() then return end player = Game.player - if Game.CurrentView() == "system" then + if Game.CurrentView() == "SystemView" then if ui.isKeyReleased(ui.keys.tab) then systemViewLayout.enabled = not systemViewLayout.enabled end @@ -915,7 +915,7 @@ local function displaySystemViewUI() displayOnScreenObjects() if ui.escapeKeyReleased() then - Game.SetView("sector") + Game.SetView("SectorView") end if ui.ctrlHeld() and ui.isKeyReleased(ui.keys.delete) then @@ -928,6 +928,6 @@ end Event.Register("onGameStart", onGameStart) Event.Register("onEnterSystem", onEnterSystem) -ui.registerHandler("system-view", ui.makeFullScreenHandler("system-view", displaySystemViewUI)) +ui.registerHandler("SystemView", ui.makeFullScreenHandler("SystemView", displaySystemViewUI)) return {} diff --git a/data/pigui/views/game.lua b/data/pigui/views/game.lua index cb2efa7408..a08ad4b1c8 100644 --- a/data/pigui/views/game.lua +++ b/data/pigui/views/game.lua @@ -240,7 +240,7 @@ end local drawHUD = ui.makeFullScreenHandler("HUD", function() if ui.shouldDrawUI() then - if Game.CurrentView() == "world" then + if Game.CurrentView() == "WorldView" then gameView:draw() else gameView.shouldRefresh = true @@ -248,7 +248,7 @@ local drawHUD = ui.makeFullScreenHandler("HUD", function() ui.radialMenu("game") callModules("game") - elseif Game.CurrentView() == "world" then + elseif Game.CurrentView() == "WorldView" then displayScreenshotInfo() end end) @@ -295,7 +295,7 @@ ui.registerHandler('game', function(delta_t) end) -- TODO: dispatch escape key to views and let them handle it - if currentView == "world" and ui.escapeKeyReleased(true) then + if currentView == "WorldView" and ui.escapeKeyReleased(true) then ui.optionsWindow:changeState() end diff --git a/data/pigui/views/info-view.lua b/data/pigui/views/info-view.lua index e9093199ba..4cf71e5d1e 100644 --- a/data/pigui/views/info-view.lua +++ b/data/pigui/views/info-view.lua @@ -5,13 +5,13 @@ local Game = require 'Game' local ui = require 'pigui' local TabView = require 'pigui.views.tab-view' -local infoView = TabView.New("info") +local infoView = TabView.New("InfoView") infoView.windowPadding = ui.rescaleUI(Vector2(18, 18)) ui.registerModule("game", function() infoView:renderTabView() if infoView.isActive and ui.escapeKeyReleased() then - Game.SetView("world") + Game.SetView("WorldView") end end) diff --git a/data/pigui/views/map-sector-view.lua b/data/pigui/views/map-sector-view.lua index 46396d5e6e..ca85ffe439 100644 --- a/data/pigui/views/map-sector-view.lua +++ b/data/pigui/views/map-sector-view.lua @@ -457,7 +457,7 @@ end ui.registerModule("game", { id = 'map-sector-view', draw = function() player = Game.player - if Game.CurrentView() == "sector" then + if Game.CurrentView() == "SectorView" then sectorViewLayout:display() if ui.isKeyReleased(ui.keys.tab) then @@ -466,7 +466,7 @@ ui.registerModule("game", { id = 'map-sector-view', draw = function() end if ui.escapeKeyReleased() then - Game.SetView("world") + Game.SetView("WorldView") end if ui.ctrlHeld() and ui.isKeyReleased(ui.keys.delete) then diff --git a/data/pigui/views/station-view.lua b/data/pigui/views/station-view.lua index 74ad0b1d51..7e5f17531f 100644 --- a/data/pigui/views/station-view.lua +++ b/data/pigui/views/station-view.lua @@ -17,7 +17,7 @@ local TabView = require 'pigui.views.tab-view' local stationView if not stationView then - stationView = TabView.New("space_station") + stationView = TabView.New("StationView") -- stationView.windowPadding = ui.rescaleUI(Vector2(18, 18)) stationView.style = ui.rescaleUI({ windowPadding = Vector2(18, 18), @@ -84,7 +84,7 @@ if not stationView then ui.registerModule("game", function() stationView:renderTabView() if stationView.isActive and ui.escapeKeyReleased() then - Game.SetView("world") + Game.SetView("WorldView") end end) end diff --git a/src/Camera.cpp b/src/Camera.cpp index 10242ee5fc..60c6675215 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -35,11 +35,11 @@ CameraContext::CameraContext(float width, float height, float fovAng, float zNea m_zNear(zNear), m_zFar(zFar), m_frustum(m_width, m_height, m_fovAng, m_zNear, m_zFar), + m_projMatrix(matrix4x4f::InfinitePerspectiveMatrix(DEG2RAD(m_fovAng), m_width / m_height, m_zNear)), m_frame(FrameId::Invalid), m_pos(0.0), m_orient(matrix3x3d::Identity()), - m_camFrame(FrameId::Invalid), - m_projMatrix(matrix4x4f::InfinitePerspectiveMatrix(DEG2RAD(m_fovAng), m_width / m_height, m_zNear)) + m_camFrame(FrameId::Invalid) { } diff --git a/src/CityOnPlanet.cpp b/src/CityOnPlanet.cpp index f22d0eafa9..85294fcb92 100644 --- a/src/CityOnPlanet.cpp +++ b/src/CityOnPlanet.cpp @@ -675,7 +675,6 @@ void CityOnPlanet::Render(Graphics::Renderer *r, const CameraContext *camera, co return; // Early frustum test of whole city. - const vector3d stationOrigin = station->GetPosition(); const vector3d stationPos = viewTransform * (station->GetPosition() + m_realCentre); if (!camera->GetFrustum().TestPoint(stationPos, m_clipRadius)) diff --git a/src/DeathView.cpp b/src/DeathView.cpp index 602bb93aae..d514c8d125 100644 --- a/src/DeathView.cpp +++ b/src/DeathView.cpp @@ -14,7 +14,7 @@ #include "profiler/Profiler.h" DeathView::DeathView(Game *game) : - View(), + View("DeathView"), m_game(game) { float znear; diff --git a/src/Game.cpp b/src/Game.cpp index 8e5e634a9f..73b421af1c 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 51439b5d25..bb7a018341 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 c4ae4b1db0..3753ec14d0 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/Pi.cpp b/src/Pi.cpp index f3fbfc5deb..1430cd5b1d 100644 --- a/src/Pi.cpp +++ b/src/Pi.cpp @@ -39,6 +39,7 @@ #include "SpaceStation.h" #include "Star.h" #include "StringF.h" +#include "SystemView.h" #include "Tombstone.h" #include "TransferPlanner.h" #include "WorldView.h" @@ -1217,10 +1218,35 @@ void Pi::RequestQuit() void Pi::SetView(View *v) { // TODO: Should it be an error or warning to switch the view to itself? + View *previousView = currentView; + if (currentView) currentView->Detach(); currentView = v; if (currentView) currentView->Attach(); - LuaEvent::Queue("onViewChanged"); + LuaEvent::Queue("onViewChanged", + currentView? currentView->GetViewName().c_str() : "", + previousView? previousView->GetViewName().c_str() : ""); + +} + +bool Pi::SetView(const std::string& target) +{ + if (!target.compare("WorldView")) { + Pi::SetView(Pi::game->GetWorldView()); + } else if (!target.compare("StationView")) { + Pi::SetView(Pi::game->GetSpaceStationView()); + } else if (!target.compare("InfoView")) { + Pi::SetView(Pi::game->GetInfoView()); + } else if (!target.compare("DeathView")) { + Pi::SetView(Pi::game->GetDeathView()); + } else if (!target.compare("SectorView")) { + Pi::SetView(Pi::game->GetSectorView()); + } else if (!target.compare("SystemView")) { + Pi::SetView(Pi::game->GetSystemView()); + } else { + return false; + } + return true; } void Pi::OnChangeDetailLevel() diff --git a/src/Pi.h b/src/Pi.h index e623070c60..4734c2a921 100644 --- a/src/Pi.h +++ b/src/Pi.h @@ -168,6 +168,7 @@ class Pi { static int statNumPatches; static void SetView(View *v); + static bool SetView(const std::string& view_name); static View *GetView() { return currentView; } static void SetAmountBackgroundStars(const float pc) diff --git a/src/SectorView.cpp b/src/SectorView.cpp index 3ed524e161..0d3cc55938 100644 --- a/src/SectorView.cpp +++ b/src/SectorView.cpp @@ -121,7 +121,7 @@ SectorMapContext SectorView::CreateMapContext() } SectorView::SectorView(Game *game) : - PiGuiView("sector-view"), + View("SectorView"), 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("SectorView"), InputBindings(Pi::input), m_game(*game) { diff --git a/src/SectorView.h b/src/SectorView.h index a75d019699..bb3ffd6de2 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 aa423dccec..ae05f71d55 100644 --- a/src/SystemView.cpp +++ b/src/SystemView.cpp @@ -64,7 +64,7 @@ namespace { // ─── System View ───────────────────────────────────────────────────────────── SystemView::SystemView(Game *game) : - PiGuiView("system-view"), + View("SystemView"), m_game(game), m_displayMode(Mode::Orrery), m_systemSelectionMode(SystemSelectionMode::SELECTED_SYSTEM), diff --git a/src/SystemView.h b/src/SystemView.h index 49b67a8d7c..331cdc5951 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 c6f3820315..eeaf889e74 100644 --- a/src/View.cpp +++ b/src/View.cpp @@ -3,9 +3,11 @@ #include "View.h" #include "Pi.h" +#include "pigui/LuaPiGui.h" -View::View() : - m_renderer(nullptr) +View::View(const std::string &name) : + m_renderer(nullptr), + m_handlerName(name) { } @@ -22,3 +24,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 63b836f025..80e01f4dd2 100644 --- a/src/View.h +++ b/src/View.h @@ -19,15 +19,15 @@ namespace Graphics { */ class View { public: - View(); + View(const std::string &name); 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) {} @@ -36,10 +36,12 @@ class View { void SetRenderer(Graphics::Renderer *r) { m_renderer = r; } + const std::string &GetViewName() const { return m_handlerName; } protected: - virtual void OnSwitchTo() = 0; + virtual void OnSwitchTo() {}; virtual void OnSwitchFrom() {} Graphics::Renderer *m_renderer; + std::string m_handlerName; }; #endif /* _VIEW_H */ diff --git a/src/WorldView.cpp b/src/WorldView.cpp index 83bf77b939..e27c9a4a30 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 4bf3191305..e76f95a7ee 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/lua/LuaGame.cpp b/src/lua/LuaGame.cpp index be4a6d88f4..8fa353221d 100644 --- a/src/lua/LuaGame.cpp +++ b/src/lua/LuaGame.cpp @@ -571,7 +571,7 @@ static int l_game_in_hyperspace(lua_State *l) * * Return: * - * view - a string describing the game view: "world", "space_station", "info", "sector", "system", "death", "settings" + * view - a string describing the game view: "WorldView", "StationView", "InfoView", "SectorView", "SystemView", "DeathView" * * Availability: * @@ -585,20 +585,11 @@ static int l_game_in_hyperspace(lua_State *l) static int l_game_current_view(lua_State *l) { const View *view = Pi::GetView(); - if (view == Pi::game->GetWorldView()) - LuaPush(l, "world"); - else if (view == Pi::game->GetSpaceStationView()) - LuaPush(l, "space_station"); - else if (view == Pi::game->GetInfoView()) - LuaPush(l, "info"); - else if (view == Pi::game->GetSectorView()) - LuaPush(l, "sector"); - else if (view == Pi::game->GetSystemView()) - LuaPush(l, "system"); - else if (view == Pi::game->GetDeathView()) - LuaPush(l, "death"); - else + if( view != nullptr) { + LuaPush(l, view->GetViewName()); + } else { lua_pushnil(l); + } return 1; } @@ -685,22 +676,11 @@ static int l_game_get_date_time(lua_State *l) static int l_game_set_view(lua_State *l) { - if (!Pi::game) + if (!Pi::game) { return luaL_error(l, "can't set view when no game is running"); + } const std::string target = luaL_checkstring(l, 1); - if (!target.compare("world")) { - Pi::SetView(Pi::game->GetWorldView()); - } else if (!target.compare("space_station")) { - Pi::SetView(Pi::game->GetSpaceStationView()); - } else if (!target.compare("info")) { - Pi::SetView(Pi::game->GetInfoView()); - } else if (!target.compare("death")) { - Pi::SetView(Pi::game->GetDeathView()); - } else if (!target.compare("sector")) { - Pi::SetView(Pi::game->GetSectorView()); - } else if (!target.compare("system")) { - Pi::SetView(Pi::game->GetSystemView()); - } else { + if (!Pi::SetView(target)) { return luaL_error(l, "Unknown view %s", target.c_str()); } return 0; diff --git a/src/pigui/PiGuiView.cpp b/src/pigui/PiGuiView.cpp deleted file mode 100644 index a20b0b603f..0000000000 --- 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 636e7895f9..0000000000 --- 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; -}; diff --git a/src/scenegraph/Model.cpp b/src/scenegraph/Model.cpp index 67d6a09a33..a7a12862d1 100644 --- a/src/scenegraph/Model.cpp +++ b/src/scenegraph/Model.cpp @@ -706,7 +706,7 @@ namespace SceneGraph { const auto& start = bound.startTag->GetGlobalTransform().GetTranslate(); const auto& end = bound.endTag->GetGlobalTransform().GetTranslate(); - float dist; + float dist = 0.0; if(bound.boundDef.type == BoundDefinition::CAPSULE) { // Point-line distance (this naturally results in a rounded end-cap)