Skip to content

Commit

Permalink
Merge pull request #5612 from Gliese852/fix-new-game-menu-after-merge
Browse files Browse the repository at this point in the history
Some fixes after sector map refactoring and new start menu added
  • Loading branch information
Webster Sheets authored Aug 26, 2023
2 parents 422dbfe + 1cd0e02 commit 3f7e6ee
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
9 changes: 3 additions & 6 deletions data/pigui/modules/new-game-window/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ Widgets.alignLabel = function(label, layout, fnc)
-- calculate item's width
local before = ui.getCursorPos()
fnc()
local backup = ui.getCursorPos()
ui.sameLine(0)
local after = ui.getCursorPos()
local width = after.x - before.x
layout.itemWidth = layout.itemWidth or width
if width < layout.itemWidth then
ui.dummy(Vector2(layout.itemWidth - width, 1))
else

if not layout.itemWidth or width > layout.itemWidth then
layout.itemWidth = width
ui.setCursorPos(backup)
end
ui.dummy(Vector2(layout.itemWidth - width, 1))
end
end

Expand Down
14 changes: 7 additions & 7 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,15 +814,15 @@ void Game::Views::LoadFromJson(const Json &jsonObj, Game *game)
Game::Views::~Views()
{
#if WITH_OBJECTVIEWER
delete m_objectViewerView;
if (m_objectViewerView) delete m_objectViewerView;
#endif

delete m_deathView;
delete m_infoView;
delete m_spaceStationView;
delete m_systemView;
delete m_worldView;
delete m_sectorView;
if (m_deathView) delete m_deathView;
if (m_infoView) delete m_infoView;
if (m_spaceStationView) delete m_spaceStationView;
if (m_systemView) delete m_systemView;
if (m_worldView) delete m_worldView;
if (m_sectorView) delete m_sectorView;
}

// XXX this should be in some kind of central UI management class that
Expand Down
18 changes: 9 additions & 9 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ class Game {

void SetRenderer(Graphics::Renderer *r);

SectorView *m_sectorView;
SystemView *m_systemView;
WorldView *m_worldView;
DeathView *m_deathView;
View *m_spaceStationView;
View *m_infoView;
SectorView *m_sectorView = nullptr;
SystemView *m_systemView = nullptr;
WorldView *m_worldView = nullptr;
DeathView *m_deathView = nullptr;
View *m_spaceStationView = nullptr;
View *m_infoView = nullptr;

/* Only use #if WITH_OBJECTVIEWER */
ObjectViewerView *m_objectViewerView;
ObjectViewerView *m_objectViewerView = nullptr;
};

void CreateViews();
Expand All @@ -155,13 +155,13 @@ class Game {
void SwitchToHyperspace();
void SwitchToNormalSpace();

std::unique_ptr<Player> m_player;

RefCountedPtr<Galaxy> m_galaxy;
std::unique_ptr<Views> m_gameViews;
std::unique_ptr<Space> m_space;
double m_time;

std::unique_ptr<Player> m_player;

enum class State {
NORMAL,
HYPERSPACE,
Expand Down
4 changes: 4 additions & 0 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void SectorView::SaveToJson(Json &jsonObj)
m_current.ToJson(currentSystemObj);
sectorViewObj["current"] = currentSystemObj; // Add current system object to sector view object.

Json selectedSystemObj({}); // Create JSON object to contain selected system data.
m_selected.ToJson(selectedSystemObj);
sectorViewObj["selected"] = selectedSystemObj; // Add selected system object to sector view object.

Json hyperspaceSystemObj({}); // Create JSON object to contain hyperspace system data.
m_hyperspaceTarget.ToJson(hyperspaceSystemObj);
sectorViewObj["hyperspace"] = hyperspaceSystemObj; // Add hyperspace system object to sector view object.
Expand Down
6 changes: 6 additions & 0 deletions src/Space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ Space::~Space()
for (Body *body : m_bodies)
KillBody(body);
UpdateBodies();

// since the player is owned by the game, we cannot delete it, but it
// stores the id of the frame we are going to delete
auto player = m_game->GetPlayer();
if (player) player->SetFrame(FrameId::Invalid);

Frame::DeleteFrames();
}

Expand Down

0 comments on commit 3f7e6ee

Please sign in to comment.