Skip to content

Commit

Permalink
EE-185 split closing passport menu state
Browse files Browse the repository at this point in the history
  • Loading branch information
stohrendorf committed Mar 2, 2021
1 parent 91041a9 commit af959a7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ set( EDISONENGINE_SRCS
menu/menudisplay.cpp
menu/menuobject.cpp
menu/applyitemtransformmenustate.cpp
menu/closepassportmenustate.cpp
menu/deflateringmenustate.cpp
menu/deselectingmenustate.cpp
menu/donemenustate.cpp
Expand Down
10 changes: 6 additions & 4 deletions src/loader/file/datatypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ void Room::createSceneNode(const size_t roomId,
resMesh->getRenderState().setDepthTest(!isSkybox());
node->setRenderOrder(isSkybox() ? 0 : 1);

static gl::ShaderStorageBuffer<engine::Lighting::Light> emptyBuffer{"lights-buffer-empty"};
node->addBufferBinder("b_lights", [](const render::scene::Node&, gl::ShaderStorageBlock& shaderStorageBlock) {
shaderStorageBlock.bind(emptyBuffer);
});
node->addBufferBinder(
"b_lights",
[emptyBuffer = std::make_shared<gl::ShaderStorageBuffer<engine::Lighting::Light>>("lights-buffer-empty")](
const render::scene::Node&, gl::ShaderStorageBlock& shaderStorageBlock) {
shaderStorageBlock.bind(*emptyBuffer);
});

for(const RoomStaticMesh& sm : staticMeshes)
{
Expand Down
46 changes: 46 additions & 0 deletions src/menu/closepassportmenustate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "closepassportmenustate.h"

#include "engine/items_tr1.h"
#include "finishitemanimationmenustate.h"
#include "idleringmenustate.h"
#include "menuobject.h"
#include "passportmenustate.h"
#include "resetitemtransformmenustate.h"
#include "setitemtypemenustate.h"

namespace menu
{
ClosePassportMenuState::ClosePassportMenuState(const std::shared_ptr<MenuRingTransform>& ringTransform,
MenuObject& passport)
: MenuState{ringTransform}
{
Expects(passport.type == engine::TR1ItemId::PassportOpening);

const auto localFrame = passport.goalFrame - passport.openFrame;
auto page = localFrame / PassportMenuState::FramesPerPage;
if(page == PassportMenuState::ExitGamePage)
{
passport.goalFrame = passport.lastMeshAnimFrame - 1_frame;
passport.animDirection = 1_frame;
}
else
{
passport.goalFrame = 0_frame;
passport.animDirection = -1_frame;
}
}

std::unique_ptr<MenuState>
ClosePassportMenuState::onFrame(ui::Ui& /*ui*/, engine::World& /*world*/, MenuDisplay& /*display*/)
{
return create<FinishItemAnimationMenuState>(create<SetItemTypeMenuState>(
engine::TR1ItemId::PassportClosed, create<ResetItemTransformMenuState>(create<IdleRingMenuState>(false))));
}

void ClosePassportMenuState::handleObject(ui::Ui& /*ui*/,
engine::World& /*world*/,
MenuDisplay& /*display*/,
MenuObject& /*object*/)
{
}
} // namespace menu
15 changes: 15 additions & 0 deletions src/menu/closepassportmenustate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "menustate.h"

namespace menu
{
class ClosePassportMenuState : public MenuState
{
public:
explicit ClosePassportMenuState(const std::shared_ptr<MenuRingTransform>& ringTransform, MenuObject& passport);

void handleObject(ui::Ui& ui, engine::World& world, MenuDisplay& display, MenuObject& object) override;
std::unique_ptr<MenuState> onFrame(ui::Ui& ui, engine::World& world, MenuDisplay& display) override;
};
} // namespace menu
24 changes: 3 additions & 21 deletions src/menu/passportmenustate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "passportmenustate.h"

#include "closepassportmenustate.h"
#include "donemenustate.h"
#include "engine/audioengine.h"
#include "engine/engine.h"
Expand Down Expand Up @@ -206,11 +207,11 @@ std::unique_ptr<MenuState> PassportMenuState::onFrame(ui::Ui& ui, engine::World&
if(!m_allowExit && display.mode != InventoryMode::TitleMode)
return nullptr;

return close(display, page, passport);
return create<ClosePassportMenuState>(passport);
}
else if(world.getPresenter().getInputHandler().hasDebouncedAction(hid::Action::Action))
{
return close(display, page, passport);
return create<ClosePassportMenuState>(passport);
}

return nullptr;
Expand All @@ -227,23 +228,4 @@ PassportMenuState::PassportMenuState(const std::shared_ptr<MenuRingTransform>& r
: std::nullopt}
{
}

std::unique_ptr<MenuState> PassportMenuState::close(MenuDisplay& /*display*/, int page, MenuObject& passport)
{
m_passportText.reset();

if(page == ExitGamePage)
{
passport.goalFrame = passport.lastMeshAnimFrame - 1_frame;
passport.animDirection = 1_frame;
}
else
{
passport.goalFrame = 0_frame;
passport.animDirection = -1_frame;
}

return create<FinishItemAnimationMenuState>(create<SetItemTypeMenuState>(
engine::TR1ItemId::PassportClosed, create<ResetItemTransformMenuState>(create<IdleRingMenuState>(false))));
}
} // namespace menu
12 changes: 5 additions & 7 deletions src/menu/passportmenustate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ enum class InventoryMode;
class PassportMenuState : public MenuState
{
private:
static constexpr int LoadGamePage = 0;
static constexpr int SaveGamePage = 1;
static constexpr int ExitGamePage = 2;
static constexpr core::Frame FramesPerPage = 5_frame;

const bool m_allowExit;
const bool m_allowSave;
std::optional<int> m_forcePage;
std::unique_ptr<ui::Label> m_passportText;

std::unique_ptr<MenuState> close(MenuDisplay& display, int page, MenuObject& passport);

std::optional<std::unique_ptr<MenuState>> showLoadGamePage(engine::World& world, MenuDisplay& display);
std::optional<std::unique_ptr<MenuState>> showSaveGamePage(engine::World& world, MenuDisplay& display, bool isInGame);
void showExitGamePage(engine::World& world, MenuDisplay& display, bool returnToTitle);
void prevPage(const core::Frame& minFrame, MenuObject& passport, engine::World& world);
void nextPage(MenuObject& passport, engine::World& world);

public:
static constexpr int LoadGamePage = 0;
static constexpr int SaveGamePage = 1;
static constexpr int ExitGamePage = 2;
static constexpr core::Frame FramesPerPage = 5_frame;

explicit PassportMenuState(const std::shared_ptr<MenuRingTransform>& ringTransform,
InventoryMode mode,
bool allowSave);
Expand Down
2 changes: 2 additions & 0 deletions src/menu/savegamelistmenustate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ SavegameListMenuState::SavegameListMenuState(const std::shared_ptr<MenuRingTrans
std::unique_ptr<MenuState> SavegameListMenuState::onSelected(size_t idx, engine::World& world, MenuDisplay& display)
{
if(!m_loading)
{
// TODO confirm overwrite if necessary
world.save(idx);
}
else if(m_hasSavegame.at(idx))
{
display.requestLoad = idx;
Expand Down

0 comments on commit af959a7

Please sign in to comment.