diff --git a/CMakeLists.txt b/CMakeLists.txt index 2405a9ec22..36974bcc24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/data/lang/ui-core/en.json b/data/lang/ui-core/en.json index 92dacea984..5ef61b19d1 100644 --- a/data/lang/ui-core/en.json +++ b/data/lang/ui-core/en.json @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/data/libs/Player.lua b/data/libs/Player.lua index fea96a9f88..52a591bb47 100644 --- a/data/libs/Player.lua +++ b/data/libs/Player.lua @@ -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' @@ -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) diff --git a/data/meta/Constants.lua b/data/meta/Constants.lua index 52830a5291..343c4f81e8 100644 --- a/data/meta/Constants.lua +++ b/data/meta/Constants.lua @@ -221,6 +221,16 @@ local SystemViewMode = { ---@type SystemViewMode[] Constants.SystemViewMode = {} +-- A string +---@enum (key) SystemSelectionMode +local SystemSelectionMode = { + CURRENT_SYSTEM = 1, + SELECTED_SYSTEM = 2, +} + +---@type SystemSelectionMode[] +Constants.SystemSelectionMode = {} + -- A string ---@enum (key) SystemViewColorIndex local SystemViewColorIndex = { diff --git a/data/pigui/modules/settings-window.lua b/data/pigui/modules/settings-window.lua index 10f8d1bd6f..cafd582697 100644 --- a/data/pigui/modules/settings-window.lua +++ b/data/pigui/modules/settings-window.lua @@ -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) @@ -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 @@ -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() @@ -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() diff --git a/data/pigui/modules/system-view-ui.lua b/data/pigui/modules/system-view-ui.lua index 819a4b59b2..0cd8c94d59 100644 --- a/data/pigui/modules/system-view-ui.lua +++ b/data/pigui/modules/system-view-ui.lua @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 } diff --git a/data/pigui/views/map-sector-view.lua b/data/pigui/views/map-sector-view.lua index a685207994..b4d62089e5 100644 --- a/data/pigui/views/map-sector-view.lua +++ b/data/pigui/views/map-sector-view.lua @@ -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") @@ -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 @@ -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 @@ -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}) diff --git a/src/Player.cpp b/src/Player.cpp index de049923c3..e8b3f25976 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -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 diff --git a/src/SectorView.cpp b/src/SectorView.cpp index 22b0c084de..5d1768b613 100644 --- a/src/SectorView.cpp +++ b/src/SectorView.cpp @@ -282,6 +282,9 @@ void SectorView::DrawPiGui() void SectorView::SetHyperspaceTarget(const SystemPath &path) { + if (m_hyperspaceTarget.IsSameSystem(path)) { + return; + } m_hyperspaceTarget = path; onHyperspaceTargetChanged.emit(); } diff --git a/src/SystemView.cpp b/src/SystemView.cpp index f451fc12cf..8b0b855434 100644 --- a/src/SystemView.cpp +++ b/src/SystemView.cpp @@ -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) { @@ -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) @@ -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 system = m_map->GetCurrentSystem(); if (!system || (system->GetUnexplored() != m_unexplored || !system->GetPath().IsSameSystem(path))) { @@ -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() diff --git a/src/SystemView.h b/src/SystemView.h index 79a6cc37bf..560fdf99ad 100644 --- a/src/SystemView.h +++ b/src/SystemView.h @@ -168,6 +168,11 @@ class SystemView : public PiGuiView, public DeleteEmitter { Atlas = 1 }; + enum class SystemSelectionMode { // + CURRENT_SYSTEM = 0, + SELECTED_SYSTEM = 1, + }; + SystemView(Game *game); ~SystemView() override; void Update() override; @@ -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(); } @@ -199,6 +207,7 @@ class SystemView : public PiGuiView, public DeleteEmitter { std::list> m_contacts; Mode m_displayMode; + SystemSelectionMode m_systemSelectionMode; bool m_viewingCurrentSystem; bool m_unexplored; }; diff --git a/src/enum_table.cpp b/src/enum_table.cpp index aeeba11dfd..f77091e0d0 100644 --- a/src/enum_table.cpp +++ b/src/enum_table.cpp @@ -171,6 +171,12 @@ const struct EnumItem ENUM_SystemViewMode[] = { { 0, 0 }, }; +const struct EnumItem ENUM_SystemSelectionMode[] = { + { "CURRENT_SYSTEM", int(SystemView::SystemSelectionMode::CURRENT_SYSTEM) }, + { "SELECTED_SYSTEM", int(SystemView::SystemSelectionMode::SELECTED_SYSTEM) }, + { 0, 0 }, +}; + const struct EnumItem ENUM_SystemViewColorIndex[] = { { "GRID", int(SystemMapViewport::GRID) }, { "GRID_LEG", int(SystemMapViewport::GRID_LEG) }, @@ -353,6 +359,7 @@ const struct EnumTable ENUM_TABLES[] = { { "ProjectableTypes", ENUM_ProjectableTypes }, { "ProjectableBases", ENUM_ProjectableBases }, { "SystemViewMode", ENUM_SystemViewMode }, + { "SystemSelectionMode", ENUM_SystemSelectionMode }, { "SystemViewColorIndex", ENUM_SystemViewColorIndex }, { "PolitEcon", ENUM_PolitEcon }, { "PolitGovType", ENUM_PolitGovType }, @@ -384,6 +391,7 @@ const struct EnumTable ENUM_TABLES_PUBLIC[] = { { "ProjectableTypes", ENUM_ProjectableTypes }, { "ProjectableBases", ENUM_ProjectableBases }, { "SystemViewMode", ENUM_SystemViewMode }, + { "SystemSelectionMode", ENUM_SystemSelectionMode }, { "SystemViewColorIndex", ENUM_SystemViewColorIndex }, { "PolitEcon", ENUM_PolitEcon }, { "PolitGovType", ENUM_PolitGovType }, diff --git a/src/enum_table.h b/src/enum_table.h index fbdd8bd613..e65c7b5f20 100644 --- a/src/enum_table.h +++ b/src/enum_table.h @@ -30,6 +30,7 @@ extern const struct EnumItem ENUM_DockStage[]; extern const struct EnumItem ENUM_ProjectableTypes[]; extern const struct EnumItem ENUM_ProjectableBases[]; extern const struct EnumItem ENUM_SystemViewMode[]; +extern const struct EnumItem ENUM_SystemSelectionMode[]; extern const struct EnumItem ENUM_SystemViewColorIndex[]; extern const struct EnumItem ENUM_PolitEcon[]; extern const struct EnumItem ENUM_PolitGovType[]; diff --git a/src/lua/LuaEngine.cpp b/src/lua/LuaEngine.cpp index 92405ee75d..6a1fe6e9fe 100644 --- a/src/lua/LuaEngine.cpp +++ b/src/lua/LuaEngine.cpp @@ -580,6 +580,21 @@ static int l_engine_set_autosave_enabled(lua_State *l) Pi::config->Save(); return 0; } +static int l_engine_get_reset_view_on_hyperspace_exit(lua_State *l) +{ + lua_pushboolean(l, Pi::config->Int("ResetViewOnHyperspaceExit") != 0); + return 1; +} + +static int l_engine_set_reset_view_on_hyperspace_exit(lua_State *l) +{ + if (lua_isnone(l, 1)) + return luaL_error(l, "SetResetViewOnHyperspaceExit takes one boolean argument"); + const bool enabled = lua_toboolean(l, 1); + Pi::config->SetInt("ResetViewOnHyperspaceExit", (enabled ? 1 : 0)); + Pi::config->Save(); + return 0; +} static int l_engine_get_display_hud_trails(lua_State *l) { @@ -1104,6 +1119,9 @@ void LuaEngine::Register() { "GetAutosaveEnabled", l_engine_get_autosave_enabled }, { "SetAutosaveEnabled", l_engine_set_autosave_enabled }, + { "GetResetViewOnHyperspaceExit", l_engine_get_reset_view_on_hyperspace_exit }, + { "SetResetViewOnHyperspaceExit", l_engine_set_reset_view_on_hyperspace_exit }, + { "GetDisplayHudTrails", l_engine_get_display_hud_trails }, { "SetDisplayHudTrails", l_engine_set_display_hud_trails }, diff --git a/src/lua/LuaSystemView.cpp b/src/lua/LuaSystemView.cpp index 05e005b601..add1056971 100644 --- a/src/lua/LuaSystemView.cpp +++ b/src/lua/LuaSystemView.cpp @@ -296,6 +296,20 @@ static int l_systemview_set_display_mode(lua_State *l) return 1; } +static int l_systemview_get_system_selection_mode(lua_State *l) +{ + SystemView *sv = LuaObject::CheckFromLua(1); + LuaPush(l, EnumStrings::GetString("SystemSelectionMode", int(sv->GetSystemSelectionMode()))); + return 1; +} + +static int l_systemview_set_system_selection_mode(lua_State *l) +{ + SystemView *sv = LuaObject::CheckFromLua(1); + int mode = EnumStrings::GetValue("SystemSelectionMode", LuaPull(l, 2)); + sv->SetSystemSelectionMode(SystemView::SystemSelectionMode(mode)); + return 1; +} static int l_systemview_transfer_planner_get(lua_State *l) { SystemView *sv = LuaObject::CheckFromLua(1); @@ -392,6 +406,8 @@ void LuaObject::RegisterClass() { "SetZoomMode", l_systemview_set_zoom_mode }, { "GetDisplayMode", l_systemview_get_display_mode }, { "SetDisplayMode", l_systemview_set_display_mode }, + { "GetSystemSelectionMode", l_systemview_get_system_selection_mode }, + { "SetSystemSelectionMode", l_systemview_set_system_selection_mode }, { "GetZoom", l_systemview_get_zoom }, { "AtlasViewPlanetGap", l_systemview_atlas_view_planet_gap }, { "AtlasViewPixelPerUnit", l_systemview_atlas_view_pixel_per_unit },