Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/view event and names #5974

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/libs/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions data/modules/MusicPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data/pigui/modules/autopilot-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions data/pigui/modules/equipment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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 = {}
Expand Down
36 changes: 18 additions & 18 deletions data/pigui/modules/fx-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -79,21 +79,21 @@ 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

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
Expand Down
6 changes: 3 additions & 3 deletions data/pigui/modules/master-alarm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/pigui/modules/planetary-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions data/pigui/modules/radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions data/pigui/modules/ship-internals-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions data/pigui/modules/system-view-ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {}
6 changes: 3 additions & 3 deletions data/pigui/views/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ 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
end

ui.radialMenu("game")
callModules("game")
elseif Game.CurrentView() == "world" then
elseif Game.CurrentView() == "WorldView" then
displayScreenshotInfo()
end
end)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions data/pigui/views/info-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions data/pigui/views/map-sector-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions data/pigui/views/station-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
1 change: 0 additions & 1 deletion src/CityOnPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/DeathView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "profiler/Profiler.h"

DeathView::DeathView(Game *game) :
View(),
View("DeathView"),
m_game(game)
{
float znear;
Expand Down
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
Loading