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/reset view on hyperspace exit #5922

Merged
merged 7 commits into from
Oct 8, 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
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,14 @@ if (NATURALDOCS)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif()

find_program(PYTHON NAMES python)
if (PYTHON)
find_package(Python2 COMPONENTS Interpreter)
if (Python2_Interpreter_FOUND)
add_custom_target(enums
COMMAND scripts/scan_enums.py -o src/enum_table.cpp --pattern='*.h' -r src
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
COMMAND "${Python2_EXECUTABLE}" scripts/scan_enums.py -o src/enum_table.cpp --pattern='*.h' -r src
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
else()
message(WARNING, "Python 2 not found; enums will not be scanned.")
endif()

target_link_libraries(pioneer-lib PUBLIC lz4 fmt::fmt)
Expand Down
20 changes: 20 additions & 0 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@
"description": "",
"message": "Full screen"
},
"GAME_OPTIONS": {
"description": "GameOptions - tooltip for the Game Options tab in the Settings Window",
"message": "Game Options"
},
"GAME_TIME": {
"description": "",
"message": "Game time"
Expand Down Expand Up @@ -963,6 +967,10 @@
"description": "Tooltip: Sidereal camera view",
"message": "Sidereal view"
},
"HUD_BUTTON_SWITCH_TO_CURRENT_SYSTEM": {
"description": "Tooltip: Switch to current system",
"message": "Switch to current system"
},
"HUD_BUTTON_SWITCH_TO_GALAXY_MAP": {
"description": "Tooltip: Switch to galaxy map",
"message": "Switch to galaxy map"
Expand All @@ -971,6 +979,10 @@
"description": "Tooltip: Switch to sector map",
"message": "Switch to sector map"
},
"HUD_BUTTON_SWITCH_TO_SELECTED_SYSTEM": {
"description": "Tooltip: Switch to selected system",
"message": "Switch to selected system"
},
"HUD_BUTTON_SWITCH_TO_SYSTEM_MAP": {
"description": "Tooltip: Switch to system map",
"message": "Switch to system map"
Expand Down Expand Up @@ -2027,6 +2039,14 @@
"description": "Paintshop button",
"message": "Reset Preview"
},
"RESET_VIEW_ON_HYPERSPACE_EXIT": {
"description": "Reset View on Hyperspace Exit option",
"message": "Reset View on Hyperspace Exit"
},
"RESET_VIEW_ON_HYPERSPACE_EXIT_DESC": {
"description": "The tooltip of Reset View on Hyperspace Exit in the settings menu",
"message": "Reset view to main game view when exiting from hyperspace"
},
"RETURN_TO_GAME": {
"description": "",
"message": "Return to game"
Expand Down
9 changes: 9 additions & 0 deletions data/libs/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
local Player = package.core["Player"]

local Serializer = require 'Serializer'
local Engine = require 'Engine'
local Event = require 'Event'
local Game = require 'Game'
local utils = require 'utils'
Expand Down Expand Up @@ -430,8 +431,16 @@ local onGameEnd = function ()
-- clean up for next game:
end

local onEnterSystem = function ()
-- Return to game view when we exit hyperspace
if Engine.GetResetViewOnHyperspaceExit() and Game.CurrentView() ~= "world" then
Game.SetView("world")
end
end

Event.Register("onGameEnd", onGameEnd)
Event.Register("onGameStart", onGameStart)
Event.Register("onEnterSystem", onEnterSystem)
Serializer:RegisterClass("CrimeRecord", CrimeRecord)
Serializer:Register("Player", serialize, unserialize)

Expand Down
10 changes: 10 additions & 0 deletions data/meta/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ local SystemViewMode = {
---@type SystemViewMode[]
Constants.SystemViewMode = {}

-- A <Constants.SystemSelectionMode> string
---@enum (key) SystemSelectionMode
local SystemSelectionMode = {
CURRENT_SYSTEM = 1,
SELECTED_SYSTEM = 2,
}

---@type SystemSelectionMode[]
Constants.SystemSelectionMode = {}

-- A <Constants.SystemViewColorIndex> string
---@enum (key) SystemViewColorIndex
local SystemViewColorIndex = {
Expand Down
28 changes: 21 additions & 7 deletions data/pigui/modules/settings-window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ local function showVideoOptions()
local displaySpeedLines = Engine.GetDisplaySpeedLines()
local displayHudTrails = Engine.GetDisplayHudTrails()
local enableCockpit = Engine.GetCockpitEnabled()
local enableAutoSave = Engine.GetAutosaveEnabled()

local c
ui.text(lui.VIDEO_CONFIGURATION_RESTART_GAME_TO_APPLY)
Expand Down Expand Up @@ -258,11 +257,6 @@ local function showVideoOptions()
Engine.SetCockpitEnabled(enableCockpit)
end

c,enableAutoSave = checkbox(lui.ENABLE_AUTOSAVE, enableAutoSave, lui.ENABLE_AUTOSAVE_DESC)
if c then
Engine.SetAutosaveEnabled(enableAutoSave)
end

c,starDensity = slider(lui.STAR_FIELD_DENSITY, starDensity, 0, 100)
if c then
needBackgroundStarRefresh = true
Expand Down Expand Up @@ -637,11 +631,28 @@ local function showControlsOptions()
end
end

local function showGameOptions()
local enableAutoSave = Engine.GetAutosaveEnabled()
local resetViewOnHyperspaceExit = Engine.GetResetViewOnHyperspaceExit()
local c

c,enableAutoSave = checkbox(lui.ENABLE_AUTOSAVE, enableAutoSave, lui.ENABLE_AUTOSAVE_DESC)
if c then
Engine.SetAutosaveEnabled(enableAutoSave)
end

c,resetViewOnHyperspaceExit = checkbox(lui.RESET_VIEW_ON_HYPERSPACE_EXIT, resetViewOnHyperspaceExit, lui.RESET_VIEW_ON_HYPERSPACE_EXIT_DESC)
if c then
Engine.SetResetViewOnHyperspaceExit(resetViewOnHyperspaceExit)
end
end

local optionsTabs = {
["video"]=showVideoOptions,
["sound"]=showSoundOptions,
["language"]=showLanguageOptions,
["controls"]=showControlsOptions
["controls"]=showControlsOptions,
["game"]=showGameOptions
}

ui.optionsWindow = ModalWindow.New("Options", function()
Expand All @@ -661,6 +672,9 @@ ui.optionsWindow = ModalWindow.New("Options", function()
mainButton(icons.controls, lui.CONTROLS, showTab=='controls', function()
showTab = 'controls'
end)
mainButton(icons.settings, lui.GAME_OPTIONS, showTab=='game', function()
showTab = 'game'
end)
end)

ui.separator()
Expand Down
33 changes: 20 additions & 13 deletions data/pigui/modules/system-view-ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ end

function Windows.edgeButtons.Show()
local isOrrery = systemView:GetDisplayMode() == "Orrery"
-- view control buttons
local isCurrent = systemView:GetSystemSelectionMode() == "CURRENT_SYSTEM"

if ui.mainMenuButton(icons.reset_view, luc.RESET_ORIENTATION_AND_ZOOM) then
systemView:SetVisibility("RESET_VIEW")
end
Expand All @@ -279,13 +280,19 @@ function Windows.edgeButtons.Show()
ui.mainMenuButton(icons.search_lens, luc.ZOOM)
systemView:SetZoomMode(ui.isItemActive())

if isOrrery and ui.mainMenuButton(icons.system_overview, luc.HUD_BUTTON_SWITCH_TO_SYSTEM_OVERVIEW) then
systemView:SetDisplayMode('Atlas')
ui.newLine()

drawWindowControlButton(Windows.objectInfo, icons.info, lc.OBJECT_INFO)

-- view control buttons
if not isCurrent and ui.mainMenuButton(icons.planet_grid, luc.HUD_BUTTON_SWITCH_TO_CURRENT_SYSTEM) then
systemView:SetSystemSelectionMode("CURRENT_SYSTEM")
end
if not isOrrery and ui.mainMenuButton(icons.system_map, luc.HUD_BUTTON_SWITCH_TO_SYSTEM_MAP) then
systemView:SetDisplayMode('Orrery')

if isCurrent and ui.mainMenuButton(icons.galaxy_map, luc.HUD_BUTTON_SWITCH_TO_SELECTED_SYSTEM) then
systemView:SetSystemSelectionMode("SELECTED_SYSTEM")
end
ui.newLine()

-- visibility control buttons
if isOrrery then
if ui.mainMenuButton(buttonState[ship_drawing].icon, lc.SHIPS_DISPLAY_MODE_TOGGLE, buttonState[ship_drawing].state) then
Expand All @@ -300,11 +307,6 @@ function Windows.edgeButtons.Show()
show_grid = nextShowGrid[show_grid]
systemView:SetVisibility(show_grid)
end
ui.newLine()
end

drawWindowControlButton(Windows.objectInfo, icons.info, lc.OBJECT_INFO)
if isOrrery then
drawWindowControlButton(Windows.orbitPlanner, icons.semi_major_axis, lc.ORBIT_PLANNER)
end
end
Expand Down Expand Up @@ -413,7 +415,12 @@ local function getColor(obj)
end

function Windows.systemName.Show()
local path = Game.sectorView:GetSelectedSystemPath()
local path
if systemView:GetSystemSelectionMode() == "SELECTED_SYSTEM" then
path = Game.sectorView:GetSelectedSystemPath()
else
path = systemView:GetSystem().path
end
ui.text(ui.Format.SystemPath(path))
end

Expand Down Expand Up @@ -867,7 +874,7 @@ end

function systemViewLayout:onUpdateWindowPivots(w)
w.systemName.anchors = { ui.anchor.center, ui.anchor.top }
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.center }
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.top }
w.timeButtons.anchors = { ui.anchor.right, ui.anchor.bottom }
w.orbitPlanner.anchors = { ui.anchor.right, ui.anchor.bottom }
w.objectInfo.anchors = { ui.anchor.right, ui.anchor.bottom }
Expand Down
10 changes: 6 additions & 4 deletions data/pigui/views/map-sector-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ function Windows.edgeButtons.Show()
ui.mainMenuButton(icons.search_lens, lui.ZOOM)
sectorView:GetMap():SetZoomMode(ui.isItemActive())
ui.text("")

if ui.mainMenuButton(icons.info, lc.OBJECT_INFO, buttonState[Windows.systemInfo.visible]) then
Windows.systemInfo.visible = not Windows.systemInfo.visible
end
-- settings buttons
if ui.mainMenuButton(icons.settings, lui.SETTINGS) then
ui.openPopup("sectorViewLabelSettings")
Expand All @@ -310,9 +314,6 @@ function Windows.edgeButtons.Show()
if ui.mainMenuButton(icons.shield_other, lui.FACTIONS, buttonState[Windows.factions.visible]) then
Windows.factions.visible = not Windows.factions.visible
end
if ui.mainMenuButton(icons.info, lc.OBJECT_INFO, buttonState[Windows.systemInfo.visible]) then
Windows.systemInfo.visible = not Windows.systemInfo.visible
end
if ui.mainMenuButton(icons.route, lui.HYPERJUMP_ROUTE, buttonState[Windows.hjPlanner.visible]) then
Windows.hjPlanner.visible = not Windows.hjPlanner.visible
end
Expand Down Expand Up @@ -424,7 +425,7 @@ Windows.hjPlanner.Dummy = hyperJumpPlanner.Dummy
function sectorViewLayout:onUpdateWindowPivots(w)
w.hjPlanner.anchors = { ui.anchor.right, ui.anchor.bottom }
w.systemInfo.anchors = { ui.anchor.right, ui.anchor.bottom }
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.center }
w.edgeButtons.anchors = { ui.anchor.right, ui.anchor.top }
w.factions.anchors = { ui.anchor.right, ui.anchor.top }
end

Expand Down Expand Up @@ -465,6 +466,7 @@ ui.registerModule("game", { id = 'map-sector-view', draw = function()

if ui.ctrlHeld() and ui.isKeyReleased(ui.keys.delete) then
systemEconView = package.reimport('pigui.modules.system-econ-view').New()
package.reimport()
end
end
end})
Expand Down
2 changes: 0 additions & 2 deletions src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ void Player::OnEnterHyperspace()
void Player::OnEnterSystem()
{
m_controller->SetFlightControlState(CONTROL_MANUAL);
//XXX don't call sectorview from here, use signals instead
Pi::game->GetSectorView()->ResetHyperspaceTarget();
}

//temporary targeting stuff
Expand Down
3 changes: 3 additions & 0 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ void SectorView::DrawPiGui()

void SectorView::SetHyperspaceTarget(const SystemPath &path)
{
if (m_hyperspaceTarget.IsSameSystem(path)) {
return;
}
m_hyperspaceTarget = path;
onHyperspaceTargetChanged.emit();
}
Expand Down
35 changes: 28 additions & 7 deletions src/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ SystemView::SystemView(Game *game) :
PiGuiView("system-view"),
m_game(game),
m_displayMode(Mode::Orrery),
m_systemSelectionMode(SystemSelectionMode::SELECTED_SYSTEM),
m_viewingCurrentSystem(false),
m_unexplored(true)
{
Expand Down Expand Up @@ -118,12 +119,14 @@ void SystemView::CalculateFramePositionAtTime(FrameId frameId, double t, vector3

double SystemView::CalculateStarportHeight(const SystemBody *body)
{
if (m_viewingCurrentSystem)
// if we look at the current system, the relief is known, we take the height from the physical body
// if we look at the current system, the relief is known, we take the height from the physical body
if (m_viewingCurrentSystem && m_game->IsNormalSpace()) {
assert(body != NULL);
return m_game->GetSpace()->FindBodyForPath(&(body->GetPath()))->GetPosition().Length();
else
// if the remote system - take the radius of the planet
return body->GetParent()->GetRadius();
}

// if the remote system - take the radius of the planet
return body->GetParent()->GetRadius();
}

void SystemView::RefreshShips(void)
Expand Down Expand Up @@ -167,8 +170,19 @@ void SystemView::Update()
const float ft = Pi::GetFrameTime();
m_map->SetReferenceTime(m_game->GetTime());

SystemPath path = m_game->GetSectorView()->GetSelected().SystemOnly();
m_viewingCurrentSystem = m_game->IsNormalSpace() && m_game->GetSpace()->GetStarSystem()->GetPath().IsSameSystem(path);
SystemPath path;
if (m_systemSelectionMode == SystemSelectionMode::CURRENT_SYSTEM) {
if (m_game->IsNormalSpace()) {
path = m_game->GetSpace()->GetStarSystem()->GetPath();
} else {
//path = m_game->GetSectorView()->GetCurrent();
path = m_game->GetHyperspaceSource();
}
m_viewingCurrentSystem = true;
} else {
path = m_game->GetSectorView()->GetSelected().SystemOnly();
m_viewingCurrentSystem = m_game->IsNormalSpace() && m_game->GetSpace()->GetStarSystem()->GetPath().IsSameSystem(path);
}

RefCountedPtr<StarSystem> system = m_map->GetCurrentSystem();
if (!system || (system->GetUnexplored() != m_unexplored || !system->GetPath().IsSameSystem(path))) {
Expand Down Expand Up @@ -269,6 +283,13 @@ void SystemView::OnSwitchFrom()
// m_projected.clear();
}

void SystemView::SetSystemSelectionMode(SystemSelectionMode systemMode)
{
if (m_systemSelectionMode != systemMode) {
m_systemSelectionMode = systemMode;
}
}

// ─── System Map Input ────────────────────────────────────────────────────────

void SystemMapViewport::InputBindings::RegisterBindings()
Expand Down
9 changes: 9 additions & 0 deletions src/SystemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class SystemView : public PiGuiView, public DeleteEmitter {
Atlas = 1
};

enum class SystemSelectionMode { // <enum name=SystemSelectionMode scope='SystemView::SystemSelectionMode' public>
CURRENT_SYSTEM = 0,
SELECTED_SYSTEM = 1,
};

SystemView(Game *game);
~SystemView() override;
void Update() override;
Expand All @@ -177,6 +182,9 @@ class SystemView : public PiGuiView, public DeleteEmitter {
Mode GetDisplayMode() { return m_displayMode; }
void SetDisplayMode(Mode displayMode) { m_displayMode = displayMode; }

SystemSelectionMode GetSystemSelectionMode() { return m_systemSelectionMode; }
void SetSystemSelectionMode(SystemSelectionMode systemMode);

TransferPlanner *GetTransferPlanner() const { return m_planner; }
double GetOrbitPlannerStartTime() const { return m_planner->GetStartTime(); }

Expand All @@ -199,6 +207,7 @@ class SystemView : public PiGuiView, public DeleteEmitter {
std::list<std::pair<Ship *, Orbit>> m_contacts;

Mode m_displayMode;
SystemSelectionMode m_systemSelectionMode;
bool m_viewingCurrentSystem;
bool m_unexplored;
};
Expand Down
Loading