CFrontEndUI work

This commit is contained in:
Jack Andersen 2016-12-29 20:37:01 -10:00
parent b3cae0d4d5
commit a93ca26ea1
29 changed files with 960 additions and 216 deletions

View File

@ -204,7 +204,8 @@ void CHintOptions::SetNextHintTime()
{ {
if (x10_nextHintIdx == -1) if (x10_nextHintIdx == -1)
return; return;
x0_hintStates[x10_nextHintIdx].x4_time = g_MemoryCardSys->GetHints()[x10_nextHintIdx].GetTime(); x0_hintStates[x10_nextHintIdx].x4_time =
g_MemoryCardSys->GetHints()[x10_nextHintIdx].GetTime() + 5.f;
} }
} }

View File

@ -141,7 +141,8 @@ CGameState::CGameState()
x228_25_deferPowerupInit = true; x228_25_deferPowerupInit = true;
} }
CGameState::CGameState(CBitStreamReader& stream) CGameState::CGameState(CBitStreamReader& stream, u32 saveIdx)
: x20c_saveFileIdx(saveIdx)
{ {
x228_25_deferPowerupInit = true; x228_25_deferPowerupInit = true;
@ -183,6 +184,11 @@ CGameState::CGameState(CBitStreamReader& stream)
} }
} }
void CGameState::ReadPersistentOptions(CBitStreamReader& r)
{
xa8_systemOptions = CPersistentOptions(r);
}
void CGameState::ImportPersistentOptions(const CPersistentOptions& opts) void CGameState::ImportPersistentOptions(const CPersistentOptions& opts)
{ {
if (opts.xd0_24_) if (opts.xd0_24_)

View File

@ -77,19 +77,20 @@ class CGameState
std::vector<CWorldState> x88_worldStates; std::vector<CWorldState> x88_worldStates;
std::shared_ptr<CPlayerState> x98_playerState; std::shared_ptr<CPlayerState> x98_playerState;
std::shared_ptr<CWorldTransManager> x9c_transManager; std::shared_ptr<CWorldTransManager> x9c_transManager;
double xa0_playTime; double xa0_playTime = 0.0;
CPersistentOptions xa8_systemOptions; CPersistentOptions xa8_systemOptions;
CGameOptions x17c_gameOptions; CGameOptions x17c_gameOptions;
CHintOptions x1f8_hintOptions; CHintOptions x1f8_hintOptions;
u64 x210_cardSerial; u32 x20c_saveFileIdx = 0;
u64 x210_cardSerial = 0;
std::vector<u8> x218_backupBuf; std::vector<u8> x218_backupBuf;
union union
{ {
struct struct
{ {
bool x228_24_hardMode; bool x228_24_hardMode : 1;
bool x228_25_deferPowerupInit; bool x228_25_deferPowerupInit : 1;
}; };
u8 _dummy = 0; u8 _dummy = 0;
}; };
@ -98,20 +99,24 @@ class CGameState
public: public:
CGameState(); CGameState();
CGameState(CBitStreamReader& stream); CGameState(CBitStreamReader& stream, u32 saveIdx);
void SetCurrentWorldId(ResId id); void SetCurrentWorldId(ResId id);
std::shared_ptr<CPlayerState> GetPlayerState() {return x98_playerState;} std::shared_ptr<CPlayerState> GetPlayerState() {return x98_playerState;}
std::shared_ptr<CWorldTransManager> GetWorldTransitionManager() {return x9c_transManager;} std::shared_ptr<CWorldTransManager> GetWorldTransitionManager() {return x9c_transManager;}
void SetTotalPlayTime(float time); void SetTotalPlayTime(float time);
CPersistentOptions& SystemOptions() { return xa8_systemOptions; } CPersistentOptions& SystemOptions() { return xa8_systemOptions; }
CGameOptions& GameOptions() { return x17c_gameOptions; } CGameOptions& GameOptions() { return x17c_gameOptions; }
CHintOptions& HintOptions() { return x1f8_hintOptions; }
CWorldState& StateForWorld(ResId mlvlId); CWorldState& StateForWorld(ResId mlvlId);
CWorldState& CurrentWorldState() { return StateForWorld(x84_mlvlId); } CWorldState& CurrentWorldState() { return StateForWorld(x84_mlvlId); }
ResId CurrentWorldAssetId() const { return x84_mlvlId; } ResId CurrentWorldAssetId() const { return x84_mlvlId; }
void SetHardMode(bool v) { x228_24_hardMode = v; } void SetHardMode(bool v) { x228_24_hardMode = v; }
void ReadPersistentOptions(CBitStreamReader& r);
void ImportPersistentOptions(const CPersistentOptions& opts); void ImportPersistentOptions(const CPersistentOptions& opts);
void ExportPersistentOptions(CPersistentOptions& opts) const; void ExportPersistentOptions(CPersistentOptions& opts) const;
void WriteBackupBuf(); void WriteBackupBuf();
u32 GetFileIdx() const { return x20c_saveFileIdx; }
void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; }
void SetCardSerial(u64 serial) { x210_cardSerial = serial; } void SetCardSerial(u64 serial) { x210_cardSerial = serial; }
void PutTo(CBitStreamWriter& writer) const; void PutTo(CBitStreamWriter& writer) const;
float GetHardModeDamageMultiplier() const; float GetHardModeDamageMultiplier() const;

View File

@ -19,14 +19,14 @@ zeus::CColor CFontRenderState::ConvertToTextureSpace(const CTextColor& col) cons
void CFontRenderState::PopState() void CFontRenderState::PopState()
{ {
static_cast<CSaveableState&>(*this) = xa4_pushedStates.back(); static_cast<CSaveableState&>(*this) = x10c_pushedStates.back();
xa4_pushedStates.pop_back(); x10c_pushedStates.pop_back();
RefreshPalette(); RefreshPalette();
} }
void CFontRenderState::PushState() void CFontRenderState::PushState()
{ {
xa4_pushedStates.push_back(*this); x10c_pushedStates.push_back(*this);
} }
void CFontRenderState::SetColor(EColorType tp, const CTextColor& col) void CFontRenderState::SetColor(EColorType tp, const CTextColor& col)

View File

@ -18,13 +18,15 @@ class CFontRenderState : public CSaveableState
friend class CImageInstruction; friend class CImageInstruction;
friend class CWordInstruction; friend class CWordInstruction;
CBlockInstruction* x54_curBlock = nullptr; CBlockInstruction* x88_curBlock = nullptr;
CDrawStringOptions x58_drawOpts; CDrawStringOptions x8c_drawOpts;
s32 x6c_curX = 0; s32 xd4_curX = 0;
s32 x70_curY; s32 xd8_curY = 0;
const CLineInstruction* x74_currentLineInst = nullptr; const CLineInstruction* xdc_currentLineInst = nullptr;
bool xa0_lineInitialized = true; std::vector<u32> xe8_;
std::vector<CSaveableState> xa4_pushedStates; std::vector<u8> xf8_;
bool x108_lineInitialized = true;
std::list<CSaveableState> x10c_pushedStates;
public: public:
CFontRenderState(); CFontRenderState();
zeus::CColor ConvertToTextureSpace(const CTextColor& col) const; zeus::CColor ConvertToTextureSpace(const CTextColor& col) const;

View File

@ -1,6 +1,7 @@
#include "CGuiCamera.hpp" #include "CGuiCamera.hpp"
#include "CGuiFrame.hpp" #include "CGuiFrame.hpp"
#include "Graphics/CGraphics.hpp" #include "Graphics/CGraphics.hpp"
#include "CGuiWidgetDrawParms.hpp"
namespace urde namespace urde
{ {
@ -41,7 +42,7 @@ void CGuiCamera::Draw(const CGuiWidgetDrawParms& parms) const
CGraphics::SetPerspective(xfc_fov, x100_aspect, x104_znear, x108_zfar); CGraphics::SetPerspective(xfc_fov, x100_aspect, x104_znear, x108_zfar);
else else
CGraphics::SetOrtho(xfc_left, x100_right, x104_top, x108_bottom, x10c_znear, x110_zfar); CGraphics::SetOrtho(xfc_left, x100_right, x104_top, x108_bottom, x10c_znear, x110_zfar);
CGraphics::SetViewPointMatrix(x34_worldXF); CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(parms.x4_cameraOffset) * x34_worldXF);
CGuiWidget::Draw(parms); CGuiWidget::Draw(parms);
} }

View File

@ -20,7 +20,7 @@ CGuiTextSupport::CGuiTextSupport(ResId fontId, const CGuiTextProperties& props,
x2cc_font = store->GetObj({SBIG('FONT'), fontId}); x2cc_font = store->GetObj({SBIG('FONT'), fontId});
} }
CTextRenderBuffer* CGuiTextSupport::GetCurrentLineRenderBuffer() const CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() const
{ {
if (x60_renderBuf && !x308_multipageFlag) if (x60_renderBuf && !x308_multipageFlag)
return const_cast<CTextRenderBuffer*>(&*x60_renderBuf); return const_cast<CTextRenderBuffer*>(&*x60_renderBuf);
@ -36,7 +36,7 @@ CTextRenderBuffer* CGuiTextSupport::GetCurrentLineRenderBuffer() const
float CGuiTextSupport::GetCurrentAnimationOverAge() const float CGuiTextSupport::GetCurrentAnimationOverAge() const
{ {
float ret = 0.f; float ret = 0.f;
if (CTextRenderBuffer* buf = GetCurrentLineRenderBuffer()) if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
{ {
if (x50_typeEnable) if (x50_typeEnable)
{ {
@ -56,7 +56,7 @@ float CGuiTextSupport::GetCurrentAnimationOverAge() const
float CGuiTextSupport::GetNumCharsPrinted() const float CGuiTextSupport::GetNumCharsPrinted() const
{ {
if (CTextRenderBuffer* buf = GetCurrentLineRenderBuffer()) if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
{ {
if (x50_typeEnable) if (x50_typeEnable)
{ {
@ -69,7 +69,7 @@ float CGuiTextSupport::GetNumCharsPrinted() const
float CGuiTextSupport::GetTotalAnimationTime() const float CGuiTextSupport::GetTotalAnimationTime() const
{ {
if (CTextRenderBuffer* buf = GetCurrentLineRenderBuffer()) if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
if (x50_typeEnable) if (x50_typeEnable)
return buf->GetPrimitiveCount() / x58_chRate; return buf->GetPrimitiveCount() / x58_chRate;
return 0.f; return 0.f;
@ -91,7 +91,7 @@ void CGuiTextSupport::Update(float dt)
{ {
if (x50_typeEnable) if (x50_typeEnable)
{ {
if (CTextRenderBuffer* buf = GetCurrentLineRenderBuffer()) if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
{ {
for (s32 i=0 ; i<buf->GetPrimitiveCount() ; ++i) for (s32 i=0 ; i<buf->GetPrimitiveCount() ; ++i)
{ {
@ -127,7 +127,7 @@ void CGuiTextSupport::ClearRenderBuffer()
x60_renderBuf = std::experimental::nullopt; x60_renderBuf = std::experimental::nullopt;
} }
void CGuiTextSupport::CheckAndRebuildTextRenderBuffer() void CGuiTextSupport::CheckAndRebuildTextBuffer()
{ {
g_TextExecuteBuf->Clear(); g_TextExecuteBuf->Clear();
g_TextExecuteBuf->x18_textState.x7c_enableWordWrap = x14_props.x0_wordWrap; g_TextExecuteBuf->x18_textState.x7c_enableWordWrap = x14_props.x0_wordWrap;
@ -146,9 +146,30 @@ void CGuiTextSupport::CheckAndRebuildTextRenderBuffer()
g_TextExecuteBuf->EndBlock(); g_TextExecuteBuf->EndBlock();
} }
bool CGuiTextSupport::CheckAndRebuildRenderBuffer()
{
if (x308_multipageFlag || x60_renderBuf)
{
if (!x308_multipageFlag || x300_)
return true;
}
CheckAndRebuildTextBuffer();
x2bc_assets = g_TextExecuteBuf->GetAssets();
if (!_GetIsTextSupportFinishedLoading())
return false;
CheckAndRebuildTextBuffer();
if (x308_multipageFlag)
{
zeus::CVector2i extent(x34_extentX, x38_extentY);
}
}
void CGuiTextSupport::Render() const void CGuiTextSupport::Render() const
{ {
if (CTextRenderBuffer* buf = GetCurrentLineRenderBuffer()) if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
{ {
zeus::CTransform oldModel = CGraphics::g_GXModelMatrix; zeus::CTransform oldModel = CGraphics::g_GXModelMatrix;
CGraphics::SetModelMatrix(oldModel * zeus::CTransform::Scale(1.f, 1.f, -1.f)); CGraphics::SetModelMatrix(oldModel * zeus::CTransform::Scale(1.f, 1.f, -1.f));
@ -210,15 +231,21 @@ void CGuiTextSupport::SetText(const std::string& str, bool multipage)
SetText(hecl::UTF8ToWide(str), multipage); SetText(hecl::UTF8ToWide(str), multipage);
} }
bool CGuiTextSupport::GetIsTextSupportFinishedLoading() const bool CGuiTextSupport::_GetIsTextSupportFinishedLoading() const
{ {
for (const CToken& tok : x2bc_assets) for (const CToken& tok : x2bc_assets)
{ {
((CToken&)tok).Lock(); const_cast<CToken&>(tok).Lock();
if (!tok.IsLoaded()) if (!tok.IsLoaded())
return false; return false;
} }
return x2cc_font.IsLoaded(); return x2cc_font.IsLoaded();
} }
bool CGuiTextSupport::GetIsTextSupportFinishedLoading() const
{
const_cast<CGuiTextSupport*>(this)->CheckAndRebuildRenderBuffer();
return _GetIsTextSupportFinishedLoading();
}
} }

View File

@ -13,6 +13,7 @@ namespace urde
class CSimplePool; class CSimplePool;
class CRasterFont; class CRasterFont;
class CTextRenderBuffer; class CTextRenderBuffer;
class CTextExecuteBuffer;
enum class EJustification enum class EJustification
{ {
@ -102,7 +103,8 @@ class CGuiTextSupport
u32 x304_pageCounter = 0; u32 x304_pageCounter = 0;
bool x308_multipageFlag = false; bool x308_multipageFlag = false;
CTextRenderBuffer* GetCurrentLineRenderBuffer() const; CTextRenderBuffer* GetCurrentPageRenderBuffer() const;
bool _GetIsTextSupportFinishedLoading() const;
public: public:
CGuiTextSupport(ResId fontId, const CGuiTextProperties& props, CGuiTextSupport(ResId fontId, const CGuiTextProperties& props,
@ -115,7 +117,9 @@ public:
void SetTypeWriteEffectOptions(bool enable, float chFadeTime, float chRate); void SetTypeWriteEffectOptions(bool enable, float chFadeTime, float chRate);
void Update(float dt); void Update(float dt);
void ClearRenderBuffer(); void ClearRenderBuffer();
void CheckAndRebuildTextRenderBuffer(); void CheckAndRebuildTextBuffer();
bool CheckAndRebuildRenderBuffer();
void Render() const; void Render() const;
void SetGeometryColor(const zeus::CColor& col); void SetGeometryColor(const zeus::CColor& col);
void SetOutlineColor(const zeus::CColor& col); void SetOutlineColor(const zeus::CColor& col);

View File

@ -1,16 +1,19 @@
#ifndef __URDE_CGUIWIDGETDRAWPARMS_HPP__ #ifndef __URDE_CGUIWIDGETDRAWPARMS_HPP__
#define __URDE_CGUIWIDGETDRAWPARMS_HPP__ #define __URDE_CGUIWIDGETDRAWPARMS_HPP__
#include "zeus/CVector3f.hpp"
namespace urde namespace urde
{ {
struct CGuiWidgetDrawParms struct CGuiWidgetDrawParms
{ {
float x0_alphaMod = 1.f; float x0_alphaMod = 1.f;
float x4_ = 0.f; zeus::CVector3f x4_cameraOffset;
float x8_ = 0.f;
float xc_ = 0.f;
CGuiWidgetDrawParms() = default;
CGuiWidgetDrawParms(float alphaMod, const zeus::CVector3f& cameraOff)
: x0_alphaMod(alphaMod), x4_cameraOffset(cameraOff) {}
static CGuiWidgetDrawParms Default; static CGuiWidgetDrawParms Default;
}; };

View File

@ -73,44 +73,44 @@ void CLineInstruction::InvokeLTR(CFontRenderState& state) const
case EJustification::Full: case EJustification::Full:
case EJustification::NLeft: case EJustification::NLeft:
case EJustification::Seven: case EJustification::Seven:
state.x6c_curX = state.x54_curBlock->x4_offsetX; state.xd4_curX = state.x88_curBlock->x4_offsetX;
break; break;
case EJustification::Center: case EJustification::Center:
case EJustification::Eight: case EJustification::Eight:
state.x6c_curX = state.x54_curBlock->x4_offsetX + state.xd4_curX = state.x88_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2; state.x88_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
break; break;
case EJustification::NCenter: case EJustification::NCenter:
if (x4_wordCount == 1) if (x4_wordCount == 1)
{ {
state.x6c_curX = state.x54_curBlock->x4_offsetX + state.xd4_curX = state.x88_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2; state.x88_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
} }
else else
{ {
state.x6c_curX = state.x54_curBlock->x4_offsetX + state.xd4_curX = state.x88_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockExtentX / 2 - state.x88_curBlock->xc_blockExtentX / 2 -
state.x54_curBlock->x2c_lineX / 2; state.x88_curBlock->x2c_lineX / 2;
} }
break; break;
case EJustification::Right: case EJustification::Right:
case EJustification::Nine: case EJustification::Nine:
state.x6c_curX = state.x54_curBlock->x4_offsetX + state.xd4_curX = state.x88_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockExtentX - x8_curX; state.x88_curBlock->xc_blockExtentX - x8_curX;
break; break;
case EJustification::NRight: case EJustification::NRight:
state.x6c_curX = state.x54_curBlock->x4_offsetX + state.xd4_curX = state.x88_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockExtentX - state.x88_curBlock->xc_blockExtentX -
state.x54_curBlock->x2c_lineX; state.x88_curBlock->x2c_lineX;
break; break;
default: break; default: break;
} }
if (state.x74_currentLineInst) if (state.xdc_currentLineInst)
{ {
const CLineInstruction& inst = *state.x74_currentLineInst; const CLineInstruction& inst = *state.xdc_currentLineInst;
s32 val = 0; s32 val = 0;
switch (state.x54_curBlock->x1c_vertJustification) switch (state.x88_curBlock->x1c_vertJustification)
{ {
case EVerticalJustification::Top: case EVerticalJustification::Top:
case EVerticalJustification::Center: case EVerticalJustification::Center:
@ -121,37 +121,37 @@ void CLineInstruction::InvokeLTR(CFontRenderState& state) const
val = inst.xc_curY; val = inst.xc_curY;
break; break;
case EVerticalJustification::Full: case EVerticalJustification::Full:
val = state.x54_curBlock->x10_blockExtentY - state.x54_curBlock->x30_lineY; val = state.x88_curBlock->x10_blockExtentY - state.x88_curBlock->x30_lineY;
if (state.x54_curBlock->x34_lineCount > 1) if (state.x88_curBlock->x34_lineCount > 1)
val /= state.x54_curBlock->x34_lineCount - 1; val /= state.x88_curBlock->x34_lineCount - 1;
else else
val = 0; val = 0;
val += inst.xc_curY; val += inst.xc_curY;
break; break;
case EVerticalJustification::Seven: case EVerticalJustification::Seven:
val = state.x54_curBlock->x24_largestMonoH; val = state.x88_curBlock->x24_largestMonoH;
break; break;
case EVerticalJustification::Eight: case EVerticalJustification::Eight:
val = (inst.xc_curY - state.x54_curBlock->x24_largestMonoH) / 2 + val = (inst.xc_curY - state.x88_curBlock->x24_largestMonoH) / 2 +
state.x54_curBlock->x24_largestMonoH; state.x88_curBlock->x24_largestMonoH;
break; break;
case EVerticalJustification::Nine: case EVerticalJustification::Nine:
val = state.x54_curBlock->x24_largestMonoH * 2 - inst.xc_curY; val = state.x88_curBlock->x24_largestMonoH * 2 - inst.xc_curY;
break; break;
} }
if (state.x54_curBlock->x1c_vertJustification != EVerticalJustification::Full) if (state.x88_curBlock->x1c_vertJustification != EVerticalJustification::Full)
val = val * state.x74_lineSpacing + state.x78_extraLineSpace; val = val * state.x74_lineSpacing + state.x78_extraLineSpace;
state.x70_curY += val; state.xd8_curY += val;
} }
} }
void CLineInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const void CLineInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
{ {
InvokeLTR(state); InvokeLTR(state);
state.xa0_lineInitialized = true; state.x108_lineInitialized = true;
state.x74_currentLineInst = this; state.xdc_currentLineInst = this;
} }
void CLineSpacingInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const void CLineSpacingInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
@ -178,17 +178,17 @@ void CImageInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf)
{ {
if (x4_image.IsLoaded() && x4_image.x4_texs.size()) if (x4_image.IsLoaded() && x4_image.x4_texs.size())
{ {
if (state.x54_curBlock->x14_direction == ETextDirection::Horizontal) if (state.x88_curBlock->x14_direction == ETextDirection::Horizontal)
{ {
const CTexture* tex = x4_image.x4_texs[0].GetObj(); const CTexture* tex = x4_image.x4_texs[0].GetObj();
if (buf) if (buf)
{ {
zeus::CVector2i coords(state.x6c_curX, zeus::CVector2i coords(state.xd4_curX,
state.x70_curY + state.x74_currentLineInst->x18_largestBaseline - state.xd8_curY + state.xdc_currentLineInst->x18_largestBaseline -
tex->GetHeight() * x4_image.x14_pointsPerTexel.y * 2 / 3); tex->GetHeight() * x4_image.x14_pointsPerTexel.y * 2 / 3);
buf->AddImage(coords, x4_image); buf->AddImage(coords, x4_image);
} }
state.x6c_curX += tex->GetWidth() * x4_image.x14_pointsPerTexel.x; state.xd4_curX += tex->GetWidth() * x4_image.x14_pointsPerTexel.x;
} }
} }
} }
@ -196,10 +196,10 @@ void CImageInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf)
void CTextInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const void CTextInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
{ {
int xOut, yOut; int xOut, yOut;
state.x48_font.GetObj()->DrawString(state.x0_drawStrOpts, state.x6c_curX, state.x48_font.GetObj()->DrawString(state.x0_drawStrOpts, state.xd4_curX,
state.x74_currentLineInst->x18_largestBaseline + state.x70_curY, state.xdc_currentLineInst->x18_largestBaseline + state.xd8_curY,
xOut, yOut, buf, x4_str.c_str(), x4_str.size()); xOut, yOut, buf, x4_str.c_str(), x4_str.size());
state.x6c_curX = xOut; state.xd4_curX = xOut;
} }
void CBlockInstruction::TestLargestFont(s32 monoW, s32 monoH, s32 baseline) void CBlockInstruction::TestLargestFont(s32 monoW, s32 monoH, s32 baseline)
@ -225,21 +225,21 @@ void CBlockInstruction::SetupPositionLTR(CFontRenderState& state) const
case EVerticalJustification::Full: case EVerticalJustification::Full:
case EVerticalJustification::NTop: case EVerticalJustification::NTop:
case EVerticalJustification::Seven: case EVerticalJustification::Seven:
state.x70_curY = x8_offsetY; state.xd8_curY = x8_offsetY;
break; break;
case EVerticalJustification::Center: case EVerticalJustification::Center:
case EVerticalJustification::NCenter: case EVerticalJustification::NCenter:
state.x70_curY = x8_offsetY + (x10_blockExtentY - x30_lineY) / 2; state.xd8_curY = x8_offsetY + (x10_blockExtentY - x30_lineY) / 2;
break; break;
case EVerticalJustification::Eight: case EVerticalJustification::Eight:
state.x70_curY = x8_offsetY + (x10_blockExtentY - x34_lineCount * x24_largestMonoH) / 2; state.xd8_curY = x8_offsetY + (x10_blockExtentY - x34_lineCount * x24_largestMonoH) / 2;
break; break;
case EVerticalJustification::Bottom: case EVerticalJustification::Bottom:
case EVerticalJustification::NBottom: case EVerticalJustification::NBottom:
state.x70_curY = x8_offsetY + x10_blockExtentY - x30_lineY; state.xd8_curY = x8_offsetY + x10_blockExtentY - x30_lineY;
break; break;
case EVerticalJustification::Nine: case EVerticalJustification::Nine:
state.x70_curY = x8_offsetY + x10_blockExtentY - x34_lineCount * x24_largestMonoH; state.xd8_curY = x8_offsetY + x10_blockExtentY - x34_lineCount * x24_largestMonoH;
break; break;
} }
} }
@ -247,7 +247,7 @@ void CBlockInstruction::SetupPositionLTR(CFontRenderState& state) const
void CBlockInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const void CBlockInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
{ {
state.x0_drawStrOpts.x0_direction = x14_direction; state.x0_drawStrOpts.x0_direction = x14_direction;
state.x54_curBlock = (CBlockInstruction*)this; state.x88_curBlock = (CBlockInstruction*)this;
if (x14_direction == ETextDirection::Horizontal) if (x14_direction == ETextDirection::Horizontal)
SetupPositionLTR(state); SetupPositionLTR(state);
} }
@ -259,31 +259,31 @@ void CWordInstruction::InvokeLTR(CFontRenderState& state) const
int w, h; int w, h;
font->GetSize(state.x0_drawStrOpts, w, h, &space, 1); font->GetSize(state.x0_drawStrOpts, w, h, &space, 1);
const CLineInstruction& inst = *state.x74_currentLineInst; const CLineInstruction& inst = *state.xdc_currentLineInst;
switch (state.x54_curBlock->x18_justification) switch (state.x88_curBlock->x18_justification)
{ {
case EJustification::Full: case EJustification::Full:
w += (state.x54_curBlock->xc_blockExtentX - inst.x8_curX) / (inst.x4_wordCount - 1); w += (state.x88_curBlock->xc_blockExtentX - inst.x8_curX) / (inst.x4_wordCount - 1);
break; break;
case EJustification::NLeft: case EJustification::NLeft:
case EJustification::NCenter: case EJustification::NCenter:
case EJustification::NRight: case EJustification::NRight:
w += (state.x54_curBlock->x2c_lineX - inst.x8_curX) / (inst.x4_wordCount - 1); w += (state.x88_curBlock->x2c_lineX - inst.x8_curX) / (inst.x4_wordCount - 1);
break; break;
default: break; default: break;
} }
int wOut = state.x6c_curX; int wOut = state.xd4_curX;
font->DrawSpace(state.x0_drawStrOpts, wOut, font->DrawSpace(state.x0_drawStrOpts, wOut,
inst.xc_curY - font->GetMonoHeight() + state.x70_curY, wOut, h, w); inst.xc_curY - font->GetMonoHeight() + state.xd8_curY, wOut, h, w);
state.x6c_curX = wOut; state.xd4_curX = wOut;
} }
void CWordInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const void CWordInstruction::Invoke(CFontRenderState& state, CTextRenderBuffer* buf) const
{ {
if (state.xa0_lineInitialized) if (state.x108_lineInitialized)
{ {
state.xa0_lineInitialized = false; state.x108_lineInitialized = false;
return; return;
} }

View File

@ -16,6 +16,7 @@ class CLineInstruction;
class CTextExecuteBuffer class CTextExecuteBuffer
{ {
friend class CGuiTextSupport; friend class CGuiTextSupport;
friend class CTextRenderBufferPages;
std::list<std::shared_ptr<CInstruction>> x0_instList; std::list<std::shared_ptr<CInstruction>> x0_instList;
u32 x14_ = 0; u32 x14_ = 0;

View File

@ -4,6 +4,9 @@
#include "Graphics/CGraphics.hpp" #include "Graphics/CGraphics.hpp"
#include "CRasterFont.hpp" #include "CRasterFont.hpp"
#include "Graphics/CTexture.hpp" #include "Graphics/CTexture.hpp"
#include "CTextExecuteBuffer.hpp"
#include "CFontRenderState.hpp"
#include "CInstruction.hpp"
namespace urde namespace urde
{ {
@ -230,4 +233,41 @@ void CTextRenderBuffer::AddFontChange(const TToken<CRasterFont>& font)
m_fontCharacters.push_back({font}); m_fontCharacters.push_back({font});
} }
CTextRenderBufferPages::CTextRenderBufferPages(CTextExecuteBuffer& buf, const zeus::CVector2i& extent)
{
for (auto it = buf.x0_instList.begin() ; it != buf.x0_instList.end() ;)
{
std::shared_ptr<CInstruction>& inst = *it;
CTextRenderBuffer rbuf(CTextRenderBuffer::EMode::AllocTally);
{
CFontRenderState rstate;
for (auto it2 = buf.x0_instList.begin() ; it2 != buf.x0_instList.end() ;)
{
std::shared_ptr<CInstruction>& inst2 = *it2;
inst2->Invoke(rstate, &rbuf);
}
}
rbuf.SetMode(CTextRenderBuffer::EMode::BufferFill);
/* TODO: Finish */
{
CFontRenderState rstate;
for (auto it2 = buf.x0_instList.begin() ; it2 != buf.x0_instList.end() ;)
{
std::shared_ptr<CInstruction>& inst2 = *it2;
if (it2 != it)
{
}
else
{
}
}
}
}
}
} }

View File

@ -16,6 +16,7 @@ namespace urde
class CGraphicsPalette; class CGraphicsPalette;
class CRasterFont; class CRasterFont;
class CGlyph; class CGlyph;
class CTextExecuteBuffer;
using CTextColor = zeus::CColor; using CTextColor = zeus::CColor;
@ -154,6 +155,12 @@ public:
void AddFontChange(const TToken<CRasterFont>& font); void AddFontChange(const TToken<CRasterFont>& font);
}; };
class CTextRenderBufferPages
{
public:
CTextRenderBufferPages(CTextExecuteBuffer&, const zeus::CVector2i&);
};
} }
#endif // __URDE_CTEXTRENDERBUFFER_HPP__ #endif // __URDE_CTEXTRENDERBUFFER_HPP__

View File

@ -34,7 +34,7 @@ public:
virtual void RegisterResourceTweaks() {} virtual void RegisterResourceTweaks() {}
virtual void ResetGameState()=0; virtual void ResetGameState()=0;
virtual void StreamNewGameState(CInputStream&) {} virtual void StreamNewGameState(CBitStreamReader&, u32 idx) {}
virtual void CheckTweakManagerDebugOptions() {} virtual void CheckTweakManagerDebugOptions() {}
virtual void Init(const hecl::Runtime::FileStoreManager& storeMgr, virtual void Init(const hecl::Runtime::FileStoreManager& storeMgr,
boo::IAudioVoiceEngine* voiceEngine, boo::IAudioVoiceEngine* voiceEngine,

View File

@ -17,7 +17,9 @@
#include "CGameState.hpp" #include "CGameState.hpp"
#include "CDependencyGroup.hpp" #include "CDependencyGroup.hpp"
#include "Audio/CAudioGroupSet.hpp" #include "Audio/CAudioGroupSet.hpp"
#include "GuiSys/CGuiWidgetDrawParms.hpp"
#include "CNESEmulator.hpp" #include "CNESEmulator.hpp"
#include "CQuitScreen.hpp"
namespace urde namespace urde
{ {
@ -118,7 +120,8 @@ void CFrontEndUI::SNewFileSelectFrame::FinishedLoading()
for (int i=0 ; i<3 ; ++i) for (int i=0 ; i<3 ; ++i)
x64_fileSelections[i] = FindFileSelectOption(x1c_loadedFrame, i); x64_fileSelections[i] = FindFileSelectOption(x1c_loadedFrame, i);
x104_rowPitch = (x64_fileSelections[1].x0_base->GetLocalPosition() - x64_fileSelections[0].x0_base->GetLocalPosition()).z; x104_rowPitch = (x64_fileSelections[1].x0_base->GetLocalPosition() -
x64_fileSelections[0].x0_base->GetLocalPosition()).z;
} }
bool CFrontEndUI::SNewFileSelectFrame::PumpLoad() bool CFrontEndUI::SNewFileSelectFrame::PumpLoad()
@ -150,7 +153,7 @@ bool CFrontEndUI::SNewFileSelectFrame::IsTextDoneAnimating() const
return x38_textpane_gba.x0_panes[0]->GetTextSupport()->IsAnimationDone(); return x38_textpane_gba.x0_panes[0]->GetTextSupport()->IsAnimationDone();
} }
CFrontEndUI::SNewFileSelectFrame::EPhase CFrontEndUI::SNewFileSelectFrame::EAction
CFrontEndUI::SNewFileSelectFrame::ProcessUserInput(const CFinalInput& input) CFrontEndUI::SNewFileSelectFrame::ProcessUserInput(const CFinalInput& input)
{ {
if (x8_subMenu != ESubMenu::Two) if (x8_subMenu != ESubMenu::Two)
@ -160,7 +163,7 @@ CFrontEndUI::SNewFileSelectFrame::ProcessUserInput(const CFinalInput& input)
x108_curTime = std::min(0.5f, x108_curTime + input.DeltaTime()); x108_curTime = std::min(0.5f, x108_curTime + input.DeltaTime());
if (x108_curTime < 0.5f) if (x108_curTime < 0.5f)
return xc_phase; return xc_action;
if (x10c_inputEnable) if (x10c_inputEnable)
x1c_loadedFrame->ProcessUserInput(input); x1c_loadedFrame->ProcessUserInput(input);
@ -183,7 +186,7 @@ CFrontEndUI::SNewFileSelectFrame::ProcessUserInput(const CFinalInput& input)
x10e_needsNewToggle = false; x10e_needsNewToggle = false;
} }
return xc_phase; return xc_action;
} }
void CFrontEndUI::SNewFileSelectFrame::Draw() const void CFrontEndUI::SNewFileSelectFrame::Draw() const
@ -419,7 +422,7 @@ void CFrontEndUI::SNewFileSelectFrame::DoPopupAdvance(CGuiTableGroup* caller)
if (x40_tablegroup_popup->GetUserSelection() == 1) if (x40_tablegroup_popup->GetUserSelection() == 1)
{ {
PlayAdvanceSfx(); PlayAdvanceSfx();
xc_phase = EPhase::One; xc_action = EAction::One;
return; return;
} }
g_GameState->SetHardMode(x20_tablegroup_fileselect->GetUserSelection()); g_GameState->SetHardMode(x20_tablegroup_fileselect->GetUserSelection());
@ -430,7 +433,7 @@ void CFrontEndUI::SNewFileSelectFrame::DoPopupAdvance(CGuiTableGroup* caller)
if (x40_tablegroup_popup->GetUserSelection() == 1) if (x40_tablegroup_popup->GetUserSelection() == 1)
{ {
PlayAdvanceSfx(); PlayAdvanceSfx();
xc_phase = EPhase::One; xc_action = EAction::One;
return; return;
} }
x4_saveUI->StartGame(x40_tablegroup_popup->GetUserSelection()); x4_saveUI->StartGame(x40_tablegroup_popup->GetUserSelection());
@ -540,7 +543,8 @@ void CFrontEndUI::SGBASupportFrame::SetTableColors(CGuiTableGroup* tbgp) const
zeus::CColor{0.627450f, 0.627450f, 0.627450f, 0.784313f}); zeus::CColor{0.627450f, 0.627450f, 0.627450f, 0.784313f});
} }
void CFrontEndUI::SGBASupportFrame::ProcessUserInput(const CFinalInput& input, CSaveUI* sui) CFrontEndUI::SGBASupportFrame::EAction
CFrontEndUI::SGBASupportFrame::ProcessUserInput(const CFinalInput& input, CSaveUI* sui)
{ {
} }
@ -630,14 +634,17 @@ bool CFrontEndUI::SFrontEndFrame::PumpLoad()
return false; return false;
} }
void CFrontEndUI::SFrontEndFrame::ProcessUserInput(const CFinalInput& input) CFrontEndUI::SFrontEndFrame::EAction
CFrontEndUI::SFrontEndFrame::ProcessUserInput(const CFinalInput& input)
{ {
x4_action = EAction::Zero;
x14_loadedFrme->ProcessUserInput(input);
return x4_action;
} }
void CFrontEndUI::SFrontEndFrame::Draw() const void CFrontEndUI::SFrontEndFrame::Draw() const
{ {
x14_loadedFrme->Draw(CGuiWidgetDrawParms::Default);
} }
void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller) void CFrontEndUI::SFrontEndFrame::DoCancel(CGuiTableGroup* caller)
@ -661,7 +668,7 @@ CFrontEndUI::SFrontEndFrame::SFrontEndFrame(u32 rnd)
x8_frme = g_SimplePool->GetObj("FRME_FrontEndPL"); x8_frme = g_SimplePool->GetObj("FRME_FrontEndPL");
} }
CFrontEndUI::SFusionBonusFrame::SFusionBonusFrame() CFrontEndUI::SNesEmulatorFrame::SNesEmulatorFrame()
{ {
x4_nesEmu = std::make_unique<CNESEmulator>(); x4_nesEmu = std::make_unique<CNESEmulator>();
@ -674,9 +681,56 @@ CFrontEndUI::SFusionBonusFrame::SFusionBonusFrame()
0, 0, g_SimplePool); 0, 0, g_SimplePool);
} }
bool CFrontEndUI::SFusionBonusFrame::DoUpdateWithSaveUI(float dt, CSaveUI* saveUi) void CFrontEndUI::SNesEmulatorFrame::SetMode(EMode mode)
{ {
bool flag = (saveUi && saveUi->GetUIType() != CSaveUI::UIType::SaveProgress) ? false : true; switch (mode)
{
case EMode::Emulator:
x8_quitScreen.reset();
break;
case EMode::QuitNESMetroid:
x8_quitScreen = std::make_unique<CQuitScreen>(EQuitType::QuitNESMetroid);
break;
case EMode::ContinuePlaying:
x8_quitScreen = std::make_unique<CQuitScreen>(EQuitType::ContinuePlaying);
break;
case EMode::SaveProgress:
x8_quitScreen = std::make_unique<CQuitScreen>(EQuitType::SaveProgress);
break;
default: break;
}
x0_mode = mode;
}
void CFrontEndUI::SNesEmulatorFrame::ProcessUserInput(const CFinalInput& input, CSaveUI* sui)
{
bool processInput = true;
if (sui && sui->GetUIType() != CSaveUI::EUIType::SaveProgress)
processInput = false;
if (sui)
sui->ProcessUserInput(input);
if (!processInput)
return;
switch (x0_mode)
{
case EMode::Emulator:
x4_nesEmu->ProcessUserInput(input, 4);
if (input.ControllerIdx() == 0 && input.PL())
SetMode(EMode::SaveProgress);
break;
case EMode::QuitNESMetroid:
case EMode::ContinuePlaying:
case EMode::SaveProgress:
x8_quitScreen->ProcessUserInput(input);
break;
default: break;
}
}
bool CFrontEndUI::SNesEmulatorFrame::DoUpdateWithSaveUI(float dt, CSaveUI* saveUi)
{
bool flag = (saveUi && saveUi->GetUIType() != CSaveUI::EUIType::SaveProgress) ? false : true;
x10_remTime = std::max(x10_remTime - dt, 0.f); x10_remTime = std::max(x10_remTime - dt, 0.f);
zeus::CColor geomCol(zeus::CColor::skWhite); zeus::CColor geomCol(zeus::CColor::skWhite);
@ -689,7 +743,7 @@ bool CFrontEndUI::SFusionBonusFrame::DoUpdateWithSaveUI(float dt, CSaveUI* saveU
return false; return false;
} }
void CFrontEndUI::SFusionBonusFrame::Draw(CSaveUI* saveUi) const void CFrontEndUI::SNesEmulatorFrame::Draw(CSaveUI* saveUi) const
{ {
} }
@ -700,7 +754,7 @@ CFrontEndUI::SOptionsFrontEndFrame::SOptionsFrontEndFrame()
x10_pauseScreen = g_SimplePool->GetObj("STRG_PauseScreen"); x10_pauseScreen = g_SimplePool->GetObj("STRG_PauseScreen");
} }
void CFrontEndUI::SOptionsFrontEndFrame::ProcessUserInput(const CFinalInput& input, CSaveUI* sui) bool CFrontEndUI::SOptionsFrontEndFrame::ProcessUserInput(const CFinalInput& input, CSaveUI* sui)
{ {
} }
@ -893,8 +947,8 @@ void CFrontEndUI::Draw() const
if (x14_phase < EPhase::Four) if (x14_phase < EPhase::Four)
return; return;
if (xec_fusionFrme) if (xec_emuFrme)
xec_fusionFrme->Draw(xdc_saveUI.get()); xec_emuFrme->Draw(xdc_saveUI.get());
else else
{ {
//g_Renderer->SetDepthReadWrite(false, false); //g_Renderer->SetDepthReadWrite(false, false);
@ -970,8 +1024,6 @@ void CFrontEndUI::Draw() const
xdc_saveUI->Draw(); xdc_saveUI->Draw();
} }
} }
} }
void CFrontEndUI::UpdateMovies(float dt) void CFrontEndUI::UpdateMovies(float dt)
@ -1033,6 +1085,119 @@ bool CFrontEndUI::PumpMovieLoad()
void CFrontEndUI::ProcessUserInput(const CFinalInput& input, CArchitectureQueue& queue) void CFrontEndUI::ProcessUserInput(const CFinalInput& input, CArchitectureQueue& queue)
{ {
if (static_cast<CMain*>(g_Main)->GetBardBusy())
return;
if (input.ControllerIdx() > 1)
return;
if (xec_emuFrme)
{
xec_emuFrme->ProcessUserInput(input, xdc_saveUI.get());
return;
}
if (x14_phase != EPhase::Four || input.ControllerIdx() != 0)
return;
if (x50_curScreen != x54_nextScreen)
{
if (x54_nextScreen == EScreen::Two && (input.PStart() || input.PA()))
{
SetMovieSeconds(std::min(1.f, x58_movieSeconds));
PlayAdvanceSfx();
return;
}
if (input.PA() || input.PStart())
{
if (x50_curScreen == EScreen::Zero && x54_nextScreen == EScreen::One &&
x58_movieSeconds > 1.f)
{
xd0_ = true;
SetMovieSeconds(1.f);
return;
}
}
}
else
{
if (x50_curScreen == EScreen::One)
{
if (input.PStart() || input.PA())
{
if (x58_movieSeconds < 30.f - g_tweakGame->GetPressStartDelay())
{
CSfxManager::SfxStart(FETransitionBackSFX[x18_rndA][0], 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
CSfxManager::SfxStart(FETransitionBackSFX[x18_rndA][1], 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
StartStateTransition(EScreen::Three);
return;
}
}
}
else if (x50_curScreen == EScreen::Three && x54_nextScreen == EScreen::Three)
{
if (xf0_optionsFrme)
{
if (xf0_optionsFrme->ProcessUserInput(input, xdc_saveUI.get()))
return;
xf0_optionsFrme.reset();
return;
}
else if (xe0_newFileSel)
{
switch (xe0_newFileSel->ProcessUserInput(input))
{
case SNewFileSelectFrame::EAction::Two:
StartStateTransition(EScreen::Four);
return;
case SNewFileSelectFrame::EAction::One:
xf0_optionsFrme = std::make_unique<SOptionsFrontEndFrame>();
return;
case SNewFileSelectFrame::EAction::Three:
xd2_ = true;
StartSlideShow(queue);
return;
default: return;
}
}
else
{
switch (xe8_frontendFrme->ProcessUserInput(input))
{
case SFrontEndFrame::EAction::Two:
StartStateTransition(EScreen::Four);
return;
case SFrontEndFrame::EAction::Three:
xf0_optionsFrme = std::make_unique<SOptionsFrontEndFrame>();
return;
case SFrontEndFrame::EAction::One:
TransitionToFive();
return;
case SFrontEndFrame::EAction::Four:
xd2_ = true;
StartSlideShow(queue);
return;
default: return;
}
}
}
else if (x50_curScreen == EScreen::Four && x54_nextScreen == EScreen::Four)
{
switch (xe4_gbaSupportFrme->ProcessUserInput(input, xdc_saveUI.get()))
{
case SGBASupportFrame::EAction::One:
StartStateTransition(EScreen::Three);
return;
case SGBASupportFrame::EAction::Two:
xf4_curAudio->StopMixing();
xec_emuFrme = std::make_unique<SNesEmulatorFrame>();
if (xdc_saveUI)
xdc_saveUI->SetInGame(true);
return;
default: return;
}
}
}
} }
void CFrontEndUI::TransitionToFive() void CFrontEndUI::TransitionToFive()
@ -1139,11 +1304,11 @@ CIOWin::EMessageReturn CFrontEndUI::Update(float dt, CArchitectureQueue& queue)
case EPhase::Four: case EPhase::Four:
case EPhase::Five: case EPhase::Five:
if (xec_fusionFrme) if (xec_emuFrme)
{ {
if (xec_fusionFrme->DoUpdateWithSaveUI(dt, xdc_saveUI.get())) if (xec_emuFrme->DoUpdateWithSaveUI(dt, xdc_saveUI.get()))
{ {
xec_fusionFrme.reset(); xec_emuFrme.reset();
xf4_curAudio->StartMixing(); xf4_curAudio->StartMixing();
} }
break; break;

View File

@ -34,6 +34,7 @@ namespace MP1
{ {
class CNESEmulator; class CNESEmulator;
class CSaveUI; class CSaveUI;
class CQuitScreen;
class CFrontEndUI : public CIOWin class CFrontEndUI : public CIOWin
{ {
@ -108,17 +109,18 @@ public:
Three Three
}; };
enum class EPhase enum class EAction
{ {
Zero, Zero,
One, One,
Two Two,
Three
}; };
u32 x0_rnd; u32 x0_rnd;
CSaveUI* x4_saveUI; CSaveUI* x4_saveUI;
ESubMenu x8_subMenu = ESubMenu::Zero; ESubMenu x8_subMenu = ESubMenu::Zero;
EPhase xc_phase = EPhase::Zero; EAction xc_action = EAction::Zero;
TLockedToken<CGuiFrame> x10_frme; TLockedToken<CGuiFrame> x10_frme;
CGuiFrame* x1c_loadedFrame = nullptr; CGuiFrame* x1c_loadedFrame = nullptr;
CGuiTableGroup* x20_tablegroup_fileselect = nullptr; CGuiTableGroup* x20_tablegroup_fileselect = nullptr;
@ -144,7 +146,7 @@ public:
void FinishedLoading(); void FinishedLoading();
bool PumpLoad(); bool PumpLoad();
bool IsTextDoneAnimating() const; bool IsTextDoneAnimating() const;
EPhase ProcessUserInput(const CFinalInput& input); EAction ProcessUserInput(const CFinalInput& input);
void Draw() const; void Draw() const;
void HandleActiveChange(CGuiTableGroup* active); void HandleActiveChange(CGuiTableGroup* active);
@ -169,6 +171,13 @@ public:
struct SGBASupportFrame struct SGBASupportFrame
{ {
enum class EAction
{
Zero,
One,
Two
};
u32 x0_ = 0; u32 x0_ = 0;
std::unique_ptr<CGBASupport> x4_gbaSupport; std::unique_ptr<CGBASupport> x4_gbaSupport;
TLockedToken<CGuiFrame> xc_gbaScreen; TLockedToken<CGuiFrame> xc_gbaScreen;
@ -185,7 +194,7 @@ public:
void FinishedLoading(); void FinishedLoading();
bool PumpLoad(); bool PumpLoad();
void SetTableColors(CGuiTableGroup* tbgp) const; void SetTableColors(CGuiTableGroup* tbgp) const;
void ProcessUserInput(const CFinalInput& input, CSaveUI* sui); EAction ProcessUserInput(const CFinalInput& input, CSaveUI* sui);
void Draw() const; void Draw() const;
void DoOptionsCancel(CGuiTableGroup* caller); void DoOptionsCancel(CGuiTableGroup* caller);
@ -195,7 +204,17 @@ public:
struct SFrontEndFrame struct SFrontEndFrame
{ {
enum class EAction
{
Zero,
One,
Two,
Three,
Four
};
u32 x0_rnd; u32 x0_rnd;
EAction x4_action;
TLockedToken<CGuiFrame> x8_frme; TLockedToken<CGuiFrame> x8_frme;
CGuiFrame* x14_loadedFrme = nullptr; CGuiFrame* x14_loadedFrme = nullptr;
CGuiTableGroup* x18_tablegroup_mainmenu = nullptr; CGuiTableGroup* x18_tablegroup_mainmenu = nullptr;
@ -204,7 +223,7 @@ public:
SFrontEndFrame(u32 rnd); SFrontEndFrame(u32 rnd);
void FinishedLoading(); void FinishedLoading();
bool PumpLoad(); bool PumpLoad();
void ProcessUserInput(const CFinalInput& input); EAction ProcessUserInput(const CFinalInput& input);
void Draw() const; void Draw() const;
void DoCancel(CGuiTableGroup* caller); void DoCancel(CGuiTableGroup* caller);
@ -212,16 +231,26 @@ public:
void DoAdvance(CGuiTableGroup* caller); void DoAdvance(CGuiTableGroup* caller);
}; };
struct SFusionBonusFrame struct SNesEmulatorFrame
{ {
u32 x0_ = 0; enum class EMode
{
Emulator,
QuitNESMetroid,
ContinuePlaying,
SaveProgress
};
EMode x0_mode = EMode::Emulator;
std::unique_ptr<CNESEmulator> x4_nesEmu; std::unique_ptr<CNESEmulator> x4_nesEmu;
std::unique_ptr<CQuitScreen> x8_quitScreen;
std::unique_ptr<CGuiTextSupport> xc_textSupport; std::unique_ptr<CGuiTextSupport> xc_textSupport;
float x10_remTime = 8.f; float x10_remTime = 8.f;
bool x14_ = false; bool x14_ = false;
bool x15_ = true; bool x15_ = true;
SFusionBonusFrame(); SNesEmulatorFrame();
void SetMode(EMode mode);
void ProcessUserInput(const CFinalInput& input, CSaveUI* sui); void ProcessUserInput(const CFinalInput& input, CSaveUI* sui);
bool DoUpdateWithSaveUI(float dt, CSaveUI* saveUi); bool DoUpdateWithSaveUI(float dt, CSaveUI* saveUi);
void Draw(CSaveUI* saveUi) const; void Draw(CSaveUI* saveUi) const;
@ -252,7 +281,7 @@ public:
}; };
}; };
SOptionsFrontEndFrame(); SOptionsFrontEndFrame();
void ProcessUserInput(const CFinalInput& input, CSaveUI* sui); bool ProcessUserInput(const CFinalInput& input, CSaveUI* sui);
void Draw() const; void Draw() const;
}; };
@ -296,7 +325,7 @@ private:
std::unique_ptr<SNewFileSelectFrame> xe0_newFileSel; std::unique_ptr<SNewFileSelectFrame> xe0_newFileSel;
std::unique_ptr<SGBASupportFrame> xe4_gbaSupportFrme; std::unique_ptr<SGBASupportFrame> xe4_gbaSupportFrme;
std::unique_ptr<SFrontEndFrame> xe8_frontendFrme; std::unique_ptr<SFrontEndFrame> xe8_frontendFrme;
std::unique_ptr<SFusionBonusFrame> xec_fusionFrme; std::unique_ptr<SNesEmulatorFrame> xec_emuFrme;
std::unique_ptr<SOptionsFrontEndFrame> xf0_optionsFrme; std::unique_ptr<SOptionsFrontEndFrame> xf0_optionsFrme;
CStaticAudioPlayer* xf4_curAudio = nullptr; CStaticAudioPlayer* xf4_curAudio = nullptr;

View File

@ -19,6 +19,7 @@ set(MP1_SOURCES
CBabygoth.hpp CBabygoth.cpp CBabygoth.hpp CBabygoth.cpp
CSaveUI.hpp CSaveUI.cpp CSaveUI.hpp CSaveUI.cpp
CMemoryCardDriver.hpp CMemoryCardDriver.cpp CMemoryCardDriver.hpp CMemoryCardDriver.cpp
CQuitScreen.hpp CQuitScreen.cpp
MP1.hpp MP1.cpp) MP1.hpp MP1.cpp)
runtime_add_list(MP1 MP1_SOURCES) runtime_add_list(MP1 MP1_SOURCES)

View File

@ -138,13 +138,19 @@ void CMemoryCardDriver::SGameFileSlot::InitializeFromGameState()
x944_fileInfo = CGameState::LoadGameFileState(x0_saveBuffer); x944_fileInfo = CGameState::LoadGameFileState(x0_saveBuffer);
} }
void CMemoryCardDriver::SGameFileSlot::LoadGameState(u32 idx)
{
CBitStreamReader r(x0_saveBuffer, 940);
static_cast<MP1::CMain*>(g_Main)->StreamNewGameState(r, idx);
}
CMemoryCardDriver::SFileInfo::SFileInfo(kabufuda::ECardSlot port, const std::string& name) CMemoryCardDriver::SFileInfo::SFileInfo(kabufuda::ECardSlot port, const std::string& name)
: x0_fileInfo(port), x14_name(name) {} : x0_fileInfo(port), x14_name(name) {}
CMemoryCardDriver::CMemoryCardDriver(kabufuda::ECardSlot cardPort, ResId saveBanner, CMemoryCardDriver::CMemoryCardDriver(kabufuda::ECardSlot cardPort, ResId saveBanner,
ResId saveIcon0, ResId saveIcon1, bool importPersistent) ResId saveIcon0, ResId saveIcon1, bool inGame)
: x0_cardPort(cardPort), x4_saveBanner(saveBanner), : x0_cardPort(cardPort), x4_saveBanner(saveBanner),
x8_saveIcon0(saveIcon0), xc_saveIcon1(saveIcon1), x19d_doImportPersistent(importPersistent) x8_saveIcon0(saveIcon0), xc_saveIcon1(saveIcon1), x19d_inGame(inGame)
{ {
x100_mcFileInfos.reserve(2); x100_mcFileInfos.reserve(2);
x100_mcFileInfos.emplace_back(EFileState::Unknown, SFileInfo(x0_cardPort, SaveFileNames[0])); x100_mcFileInfos.emplace_back(EFileState::Unknown, SFileInfo(x0_cardPort, SaveFileNames[0]));
@ -157,7 +163,7 @@ void CMemoryCardDriver::NoCardFound()
static_cast<CMain*>(g_Main)->SetCardBusy(false); static_cast<CMain*>(g_Main)->SetCardBusy(false);
} }
CGameState::GameFileStateInfo* CMemoryCardDriver::GetGameFileStateInfo(int idx) const CGameState::GameFileStateInfo* CMemoryCardDriver::GetGameFileStateInfo(int idx)
{ {
SGameFileSlot* slot = xe4_fileSlots[idx].get(); SGameFileSlot* slot = xe4_fileSlots[idx].get();
if (!slot) if (!slot)
@ -197,7 +203,7 @@ void CMemoryCardDriver::ReadFinished()
for (int i=0 ; i<3 ; ++i) for (int i=0 ; i<3 ; ++i)
xe4_fileSlots[i] = LoadSaveFile(r); xe4_fileSlots[i] = LoadSaveFile(r);
if (x19d_doImportPersistent) if (x19d_inGame)
ImportPersistentOptions(); ImportPersistentOptions();
} }
@ -745,6 +751,37 @@ void CMemoryCardDriver::UpdateCardFormat(ECardResult result)
HandleCardError(result, EState::CardFormatFailed); HandleCardError(result, EState::CardFormatFailed);
} }
void CMemoryCardDriver::BuildNewFileSlot(u32 saveIdx)
{
g_GameState->SetFileIdx(saveIdx);
bool fusionBackup = g_GameState->SystemOptions().GetPlayerHasFusion();
std::unique_ptr<SGameFileSlot>& slot = xe4_fileSlots[saveIdx];
if (!slot)
slot = std::make_unique<SGameFileSlot>();
slot->LoadGameState(saveIdx);
CBitStreamReader r(x30_systemData, 174);
g_GameState->ReadPersistentOptions(r);
ImportPersistentOptions();
g_GameState->SetCardSerial(x28_cardSerial);
g_GameState->SystemOptions().SetPlayerHasFusion(fusionBackup);
}
void CMemoryCardDriver::BuildExistingFileSlot(u32 saveIdx)
{
g_GameState->SetFileIdx(saveIdx);
std::unique_ptr<SGameFileSlot>& slot = xe4_fileSlots[saveIdx];
if (!slot)
slot = std::make_unique<SGameFileSlot>();
else
slot->InitializeFromGameState();
CBitStreamWriter w(x30_systemData, 174);
g_GameState->PutTo(w);
}
void CMemoryCardDriver::InitializeFileInfo() void CMemoryCardDriver::InitializeFileInfo()
{ {
ExportPersistentOptions(); ExportPersistentOptions();

View File

@ -107,6 +107,7 @@ private:
SGameFileSlot(); SGameFileSlot();
SGameFileSlot(CMemoryInStream& in); SGameFileSlot(CMemoryInStream& in);
void InitializeFromGameState(); void InitializeFromGameState();
void LoadGameState(u32 idx);
void DoPut(CMemoryOutStream& w) const void DoPut(CMemoryOutStream& w) const
{ {
w.writeBytes(x0_saveBuffer, 940); w.writeBytes(x0_saveBuffer, 940);
@ -137,14 +138,14 @@ private:
u32 x194_fileIdx = -1; u32 x194_fileIdx = -1;
std::unique_ptr<CMemoryCardSys::CCardFileInfo> x198_fileInfo; std::unique_ptr<CMemoryCardSys::CCardFileInfo> x198_fileInfo;
bool x19c_ = false; bool x19c_ = false;
bool x19d_doImportPersistent; bool x19d_inGame;
public: public:
CMemoryCardDriver(kabufuda::ECardSlot cardPort, ResId saveBanner, CMemoryCardDriver(kabufuda::ECardSlot cardPort, ResId saveBanner,
ResId saveIcon0, ResId saveIcon1, bool importPersistent); ResId saveIcon0, ResId saveIcon1, bool inGame);
void NoCardFound(); void NoCardFound();
CGameState::GameFileStateInfo* GetGameFileStateInfo(int idx); const CGameState::GameFileStateInfo* GetGameFileStateInfo(int idx);
static SSaveHeader LoadSaveHeader(CMemoryInStream& in); static SSaveHeader LoadSaveHeader(CMemoryInStream& in);
static std::unique_ptr<SGameFileSlot> LoadSaveFile(CMemoryInStream& in); static std::unique_ptr<SGameFileSlot> LoadSaveFile(CMemoryInStream& in);
void ReadFinished(); void ReadFinished();
@ -182,6 +183,8 @@ public:
void UpdateCardFormat(kabufuda::ECardResult result); // 37 void UpdateCardFormat(kabufuda::ECardResult result); // 37
void ClearFileInfo() { x198_fileInfo.reset(); } void ClearFileInfo() { x198_fileInfo.reset(); }
void BuildNewFileSlot(u32 saveIdx);
void BuildExistingFileSlot(u32 saveIdx);
void InitializeFileInfo(); void InitializeFileInfo();
void WriteBackupBuf(); void WriteBackupBuf();
bool GetCardFreeBytes(); bool GetCardFreeBytes();

View File

@ -0,0 +1,14 @@
#include "CNESEmulator.hpp"
namespace urde
{
namespace MP1
{
void CNESEmulator::ProcessUserInput(const CFinalInput& input, int)
{
}
}
}

View File

@ -3,12 +3,15 @@
namespace urde namespace urde
{ {
class CFinalInput;
namespace MP1 namespace MP1
{ {
class CNESEmulator class CNESEmulator
{ {
public:
void ProcessUserInput(const CFinalInput& input, int);
}; };
} }

120
Runtime/MP1/CQuitScreen.cpp Normal file
View File

@ -0,0 +1,120 @@
#include "CQuitScreen.hpp"
#include "Input/CFinalInput.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "GuiSys/CGuiFrame.hpp"
#include "GuiSys/CGuiTableGroup.hpp"
#include "GuiSys/CGuiTextPane.hpp"
#include "GuiSys/CStringTable.hpp"
#include "GuiSys/CGuiWidgetDrawParms.hpp"
#include "Audio/CSfxManager.hpp"
namespace urde
{
namespace MP1
{
static const int Titles[] =
{
24, 25, 26, 27, 28
};
static const int DefaultSelections[] =
{
1, 0, 1, 1, 0
};
static const float VerticalOffsets[] =
{
0.f, 1.6f, 1.f, 0.f, 1.f
};
void CQuitScreen::SetColors()
{
x14_tablegroup_quitgame->SetColors(zeus::CColor{0.784313f, 0.784313f, 0.784313f, 1.f},
zeus::CColor{0.196078f, 0.196078f, 0.196078f, 1.f});
}
void CQuitScreen::FinishedLoading()
{
x10_loadedFrame = x4_frame.GetObj();
x14_tablegroup_quitgame = static_cast<CGuiTableGroup*>(
x10_loadedFrame->FindWidget("tablegroup_quitgame"));
x14_tablegroup_quitgame->SetMenuAdvanceCallback(
std::bind(&CQuitScreen::DoAdvance, this, std::placeholders::_1));
x14_tablegroup_quitgame->SetMenuSelectionChangeCallback(
std::bind(&CQuitScreen::DoSelectionChange, this, std::placeholders::_1));
static_cast<CGuiTextPane*>(x10_loadedFrame->FindWidget("textpane_title"))->TextSupport()->
SetText(g_MainStringTable->GetString(Titles[int(x0_type)]));
static_cast<CGuiTextPane*>(x10_loadedFrame->FindWidget("textpane_yes"))->TextSupport()->
SetText(g_MainStringTable->GetString(22));
static_cast<CGuiTextPane*>(x10_loadedFrame->FindWidget("textpane_no"))->TextSupport()->
SetText(g_MainStringTable->GetString(23));
x14_tablegroup_quitgame->SetUserSelection(DefaultSelections[int(x0_type)]);
SetColors();
}
void CQuitScreen::DoSelectionChange(CGuiTableGroup* caller)
{
SetColors();
CSfxManager::SfxStart(1424, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
}
void CQuitScreen::DoAdvance(CGuiTableGroup* caller)
{
if (caller->GetUserSelection() == 0)
{
/* Yes */
CSfxManager::SfxStart(1432, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
x18_action = EQuitAction::Yes;
}
else
{
/* No */
CSfxManager::SfxStart(1431, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
x18_action = EQuitAction::No;
}
}
EQuitAction CQuitScreen::Update()
{
if (!x10_loadedFrame && x4_frame.IsLoaded())
FinishedLoading();
return x18_action;
}
void CQuitScreen::Draw()
{
if (x0_type == EQuitType::QuitGame)
m_blackScreen->draw(zeus::CColor::skBlack);
if (x10_loadedFrame)
x10_loadedFrame->Draw(CGuiWidgetDrawParms{1.f,
zeus::CVector3f{0.f, 0.f, VerticalOffsets[int(x0_type)]}});
}
void CQuitScreen::ProcessUserInput(const CFinalInput& input)
{
if (input.ControllerIdx() != 0)
return;
if (!x10_loadedFrame)
return;
x10_loadedFrame->ProcessUserInput(input);
if (input.PB() && x0_type != EQuitType::ContinueFromLastSave)
x18_action = EQuitAction::No;
}
CQuitScreen::CQuitScreen(EQuitType tp)
: x0_type(tp)
{
x4_frame = g_SimplePool->GetObj("FRME_QuitScreen");
if (tp == EQuitType::QuitGame)
m_blackScreen.emplace(CCameraFilterPass::EFilterType::Blend);
}
}
}

View File

@ -0,0 +1,56 @@
#ifndef __URDE_CQUITSCREEN_HPP__
#define __URDE_CQUITSCREEN_HPP__
#include "RetroTypes.hpp"
#include "CToken.hpp"
#include "Graphics/Shaders/CColoredQuadFilter.hpp"
namespace urde
{
class CFinalInput;
class CGuiFrame;
class CGuiTableGroup;
class CGuiTextPane;
namespace MP1
{
enum class EQuitType
{
QuitGame,
ContinueFromLastSave,
SaveProgress,
QuitNESMetroid,
ContinuePlaying
};
enum class EQuitAction
{
None,
Yes,
No
};
class CQuitScreen
{
EQuitType x0_type;
TLockedToken<CGuiFrame> x4_frame;
CGuiFrame* x10_loadedFrame = nullptr;
CGuiTableGroup* x14_tablegroup_quitgame = nullptr;
EQuitAction x18_action = EQuitAction::None;
std::experimental::optional<CColoredQuadFilter> m_blackScreen;
void SetColors();
public:
void FinishedLoading();
void DoSelectionChange(CGuiTableGroup* caller);
void DoAdvance(CGuiTableGroup* caller);
EQuitAction Update();
void Draw();
void ProcessUserInput(const CFinalInput& input);
CQuitScreen(EQuitType pos);
};
}
}
#endif // __URDE_CQUITSCREEN_HPP__

View File

@ -7,6 +7,7 @@
#include "GuiSys/CGuiTextPane.hpp" #include "GuiSys/CGuiTextPane.hpp"
#include "GuiSys/CGuiWidgetDrawParms.hpp" #include "GuiSys/CGuiWidgetDrawParms.hpp"
#include "Audio/CSfxManager.hpp" #include "Audio/CSfxManager.hpp"
#include "MP1/MP1.hpp"
namespace urde namespace urde
{ {
@ -20,10 +21,10 @@ void CSaveUI::ResetCardDriver()
{ {
x92_ = false; x92_ = false;
x6c_cardDriver.reset(); x6c_cardDriver.reset();
bool importState = (x0_instIdx == 0 && !x90_needsDriverReset); bool importState = (x0_saveCtx == ESaveContext::FrontEnd && !x90_needsDriverReset);
x6c_cardDriver = ConstructCardDriver(importState); x6c_cardDriver = ConstructCardDriver(importState);
x6c_cardDriver->StartCardProbe(); x6c_cardDriver->StartCardProbe();
x10_uiType = UIType::Empty; x10_uiType = EUIType::Empty;
SetUIText(); SetUIText();
} }
@ -45,13 +46,13 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
else else
x80_iowRet = CIOWin::EMessageReturn::Exit; x80_iowRet = CIOWin::EMessageReturn::Exit;
} }
else if (x6c_cardDriver->x10_state == EState::CardCheckDone && x10_uiType != UIType::NotOriginalCard) else if (x6c_cardDriver->x10_state == EState::CardCheckDone && x10_uiType != EUIType::NotOriginalCard)
{ {
if (x6c_cardDriver->x28_cardSerial != x8_serial) if (x6c_cardDriver->x28_cardSerial != x8_serial)
{ {
if (x93_secondaryInst) if (x93_inGame)
{ {
x10_uiType = UIType::NotOriginalCard; x10_uiType = EUIType::NotOriginalCard;
x91_uiTextDirty = true; x91_uiTextDirty = true;
} }
else else
@ -70,7 +71,7 @@ CIOWin::EMessageReturn CSaveUI::Update(float dt)
if (x80_iowRet != CIOWin::EMessageReturn::Normal) if (x80_iowRet != CIOWin::EMessageReturn::Normal)
return x80_iowRet; return x80_iowRet;
UIType oldTp = x10_uiType; EUIType oldTp = x10_uiType;
x10_uiType = SelectUIType(); x10_uiType = SelectUIType();
if (oldTp != x10_uiType || x91_uiTextDirty) if (oldTp != x10_uiType || x91_uiTextDirty)
SetUIText(); SetUIText();
@ -126,7 +127,7 @@ bool CSaveUI::PumpLoad()
x58_tablegroup_choices->SetMenuSelectionChangeCallback( x58_tablegroup_choices->SetMenuSelectionChangeCallback(
std::bind(&CSaveUI::DoSelectionChange, this, std::placeholders::_1)); std::bind(&CSaveUI::DoSelectionChange, this, std::placeholders::_1));
if (x0_instIdx == 1) if (x0_saveCtx == ESaveContext::InGame)
x6c_cardDriver->StartCardProbe(); x6c_cardDriver->StartCardProbe();
x10_uiType = SelectUIType(); x10_uiType = SelectUIType();
@ -134,16 +135,16 @@ bool CSaveUI::PumpLoad()
return true; return true;
} }
CSaveUI::UIType CSaveUI::SelectUIType() const CSaveUI::EUIType CSaveUI::SelectUIType() const
{ {
if (x6c_cardDriver->x10_state == EState::NoCard) if (x6c_cardDriver->x10_state == EState::NoCard)
return UIType::NoCardFound; return EUIType::NoCardFound;
switch (x10_uiType) switch (x10_uiType)
{ {
case UIType::ProgressWillBeLost: case EUIType::ProgressWillBeLost:
case UIType::NotOriginalCard: case EUIType::NotOriginalCard:
case UIType::AllDataWillBeLost: case EUIType::AllDataWillBeLost:
return x10_uiType; return x10_uiType;
default: break; default: break;
} }
@ -151,43 +152,43 @@ CSaveUI::UIType CSaveUI::SelectUIType() const
if (CMemoryCardDriver::IsCardBusy(x6c_cardDriver->x10_state)) if (CMemoryCardDriver::IsCardBusy(x6c_cardDriver->x10_state))
{ {
if (CMemoryCardDriver::IsCardWriting(x6c_cardDriver->x10_state)) if (CMemoryCardDriver::IsCardWriting(x6c_cardDriver->x10_state))
return UIType::BusyWriting; return EUIType::BusyWriting;
return UIType::BusyReading; return EUIType::BusyReading;
} }
if (x6c_cardDriver->x10_state == EState::Ready) if (x6c_cardDriver->x10_state == EState::Ready)
{ {
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardStillFull) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardStillFull)
return UIType::StillInsufficientSpace; return EUIType::StillInsufficientSpace;
return UIType::SaveProgress; return EUIType::SaveProgress;
} }
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardBroken) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardBroken)
return UIType::NeedsFormatBroken; return EUIType::NeedsFormatBroken;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongCharacterSet) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongCharacterSet)
return UIType::NeedsFormatEncoding; return EUIType::NeedsFormatEncoding;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongDevice) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardWrongDevice)
return UIType::WrongDevice; return EUIType::WrongDevice;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardFull) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardFull)
{ {
if (x6c_cardDriver->x10_state == EState::CardCheckFailed) if (x6c_cardDriver->x10_state == EState::CardCheckFailed)
return UIType::InsufficientSpaceBadCheck; return EUIType::InsufficientSpaceBadCheck;
return UIType::InsufficientSpaceOKCheck; return EUIType::InsufficientSpaceOKCheck;
} }
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardNon8KSectors) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardNon8KSectors)
return UIType::IncompatibleCard; return EUIType::IncompatibleCard;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::FileCorrupted) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::FileCorrupted)
return UIType::SaveCorrupt; return EUIType::SaveCorrupt;
if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardIOError) if (x6c_cardDriver->x14_error == CMemoryCardDriver::EError::CardIOError)
return UIType::CardDamaged; return EUIType::CardDamaged;
return UIType::Empty; return EUIType::Empty;
} }
void CSaveUI::SetUIText() void CSaveUI::SetUIText()
@ -202,64 +203,64 @@ void CSaveUI::SetUIText()
switch (x10_uiType) switch (x10_uiType)
{ {
case UIType::BusyReading: case EUIType::BusyReading:
msgB = 24; // Reading msgB = 24; // Reading
break; break;
case UIType::BusyWriting: case EUIType::BusyWriting:
msgB = 25; // Writing msgB = 25; // Writing
break; break;
case UIType::NoCardFound: case EUIType::NoCardFound:
msgB = 0; // No card found msgB = 0; // No card found
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
break; break;
case UIType::NeedsFormatBroken: case EUIType::NeedsFormatBroken:
msgB = 1; // Needs format (card broken) msgB = 1; // Needs format (card broken)
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
opt2 = 20; // Format opt2 = 20; // Format
break; break;
case UIType::NeedsFormatEncoding: case EUIType::NeedsFormatEncoding:
msgB = 2; // Needs format (wrong char set) msgB = 2; // Needs format (wrong char set)
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
opt2 = 20; // Format opt2 = 20; // Format
break; break;
case UIType::CardDamaged: case EUIType::CardDamaged:
msgB = 3; // Damaged msgB = 3; // Damaged
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
break; break;
case UIType::WrongDevice: case EUIType::WrongDevice:
msgB = 5; // Invalid device msgB = 5; // Invalid device
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
break; break;
case UIType::InsufficientSpaceOKCheck: case EUIType::InsufficientSpaceOKCheck:
msgB = 6; // Insufficient space (completely filled) msgB = 6; // Insufficient space (completely filled)
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
opt2 = 19; // Manage memory card opt2 = 19; // Manage memory card
break; break;
case UIType::InsufficientSpaceBadCheck: case EUIType::InsufficientSpaceBadCheck:
msgB = bool(x0_instIdx) + 9; // Insufficient space A or B msgB = bool(x0_saveCtx) + 9; // Insufficient space A or B
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
opt2 = 19; // Manage memory card opt2 = 19; // Manage memory card
break; break;
case UIType::IncompatibleCard: case EUIType::IncompatibleCard:
msgB = 7; // Incompatible card msgB = 7; // Incompatible card
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
opt1 = 18; // Retry opt1 = 18; // Retry
break; break;
case UIType::SaveCorrupt: case EUIType::SaveCorrupt:
msgB = 4; // Save corrupt msgB = 4; // Save corrupt
opt0 = 22; // Delete corrupt file opt0 = 22; // Delete corrupt file
opt1 = 17; // Continue without saving opt1 = 17; // Continue without saving
opt2 = 18; // Retry opt2 = 18; // Retry
break; break;
case UIType::StillInsufficientSpace: case EUIType::StillInsufficientSpace:
if (x0_instIdx == 1) if (x0_saveCtx == ESaveContext::InGame)
{ {
msgB = 10; // Insufficient space B msgB = 10; // Insufficient space B
opt0 = 17; // Continue without saving opt0 = 17; // Continue without saving
@ -274,26 +275,26 @@ void CSaveUI::SetUIText()
opt2 = 19; // Manage memory card opt2 = 19; // Manage memory card
} }
break; break;
case UIType::ProgressWillBeLost: case EUIType::ProgressWillBeLost:
msgA = 28; // Warning msgA = 28; // Warning
msgB = 11; // Progress will be lost msgB = 11; // Progress will be lost
opt0 = 21; // Cancel opt0 = 21; // Cancel
opt1 = 16; // Continue opt1 = 16; // Continue
break; break;
case UIType::NotOriginalCard: case EUIType::NotOriginalCard:
msgA = 28; // Warning msgA = 28; // Warning
msgB = 12; // Not the original card msgB = 12; // Not the original card
opt0 = x0_instIdx == 1 ? 21 : 17; // Cancel : continue without saving opt0 = x0_saveCtx == ESaveContext::InGame ? 21 : 17; // Cancel : continue without saving
opt1 = 16; // Continue opt1 = 16; // Continue
break; break;
case UIType::AllDataWillBeLost: case EUIType::AllDataWillBeLost:
msgA = 28; // Warning msgA = 28; // Warning
msgB = 13; // All card data will be erased msgB = 13; // All card data will be erased
opt0 = 16; // Continue opt0 = 16; // Continue
opt1 = 21; // Cancel opt1 = 21; // Cancel
break; break;
case UIType::SaveProgress: case EUIType::SaveProgress:
if (x0_instIdx == 1) if (x0_saveCtx == ESaveContext::InGame)
{ {
msgB = 8; // Save progress? msgB = 8; // Save progress?
opt0 = 14; // Yes opt0 = 14; // Yes
@ -359,18 +360,18 @@ void CSaveUI::ContinueWithoutSaving()
void CSaveUI::DoAdvance(CGuiTableGroup* caller) void CSaveUI::DoAdvance(CGuiTableGroup* caller)
{ {
int userSel = x58_tablegroup_choices->GetUserSelection(); int userSel = x58_tablegroup_choices->GetUserSelection();
s32 sfx = -1; int sfx = -1;
switch (x10_uiType) switch (x10_uiType)
{ {
case UIType::NoCardFound: case EUIType::NoCardFound:
case UIType::CardDamaged: case EUIType::CardDamaged:
case UIType::WrongDevice: case EUIType::WrongDevice:
case UIType::IncompatibleCard: case EUIType::IncompatibleCard:
if (userSel == 0) if (userSel == 0)
{ {
/* Continue without saving */ /* Continue without saving */
if (x0_instIdx == 1) if (x0_saveCtx == ESaveContext::InGame)
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit; x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
else else
ContinueWithoutSaving(); ContinueWithoutSaving();
@ -384,22 +385,205 @@ void CSaveUI::DoAdvance(CGuiTableGroup* caller)
} }
break; break;
case UIType::NeedsFormatBroken: case EUIType::NeedsFormatBroken:
case UIType::NeedsFormatEncoding: case EUIType::NeedsFormatEncoding:
if (userSel == 0)
{
/* Continue without saving */
if (x0_saveCtx == ESaveContext::InGame)
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
else
ContinueWithoutSaving();
sfx = x8c_navBackSfx;
}
else if (userSel == 1)
{
/* Retry */
ResetCardDriver();
sfx = x84_navConfirmSfx;
}
else if (userSel == 2)
{
/* Format */
x10_uiType = EUIType::AllDataWillBeLost;
x91_uiTextDirty = true;
sfx = x84_navConfirmSfx;
}
break;
case UIType::InsufficientSpaceBadCheck: case EUIType::InsufficientSpaceBadCheck:
case UIType::InsufficientSpaceOKCheck: case EUIType::InsufficientSpaceOKCheck:
if (userSel == 0)
{
/* Continue without saving */
if (x0_saveCtx == ESaveContext::InGame)
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
else
ContinueWithoutSaving();
sfx = x8c_navBackSfx;
}
else if (userSel == 1)
{
/* Retry */
ResetCardDriver();
sfx = x84_navConfirmSfx;
}
else if (userSel == 2)
{
/* Manage memory card */
if (x0_saveCtx == ESaveContext::InGame)
{
x10_uiType = EUIType::ProgressWillBeLost;
x91_uiTextDirty = true;
sfx = x84_navConfirmSfx;
}
else
static_cast<MP1::CMain*>(g_Main)->SetManageCard(true);
}
break;
case UIType::SaveCorrupt: case EUIType::SaveCorrupt:
if (userSel == 0)
{
/* Delete corrupt file */
x6c_cardDriver->StartFileDeleteBad();
sfx = x84_navConfirmSfx;
}
else if (userSel == 1)
{
/* Continue without saving */
if (x0_saveCtx == ESaveContext::InGame)
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
else
ContinueWithoutSaving();
sfx = x8c_navBackSfx;
}
else if (userSel == 2)
{
/* Retry */
ResetCardDriver();
sfx = x84_navConfirmSfx;
}
break;
case UIType::StillInsufficientSpace: case EUIType::StillInsufficientSpace:
if (x0_saveCtx == ESaveContext::InGame)
{
if (userSel == 0)
{
/* Continue without saving */
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
sfx = x8c_navBackSfx;
}
else if (userSel == 1)
{
/* Retry */
ResetCardDriver();
sfx = x84_navConfirmSfx;
}
else if (userSel == 2)
{
/* Manage memory card */
x10_uiType = EUIType::ProgressWillBeLost;
x91_uiTextDirty = true;
sfx = x84_navConfirmSfx;
}
}
else
{
if (userSel == 0)
{
/* Continue without saving */
if (x93_inGame)
{
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
sfx = x8c_navBackSfx;
}
else
{
x6c_cardDriver->ClearError();
x92_ = true;
sfx = x84_navConfirmSfx;
}
}
else if (userSel == 1)
{
/* Retry */
ResetCardDriver();
sfx = x84_navConfirmSfx;
}
else if (userSel == 2)
{
/* Manage memory card */
static_cast<MP1::CMain*>(g_Main)->SetManageCard(true);
}
}
break;
case UIType::NotOriginalCard: case EUIType::ProgressWillBeLost:
if (userSel == 1)
{
/* Continue */
static_cast<MP1::CMain*>(g_Main)->SetManageCard(true);
}
else if (userSel == 0)
{
/* Cancel */
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
sfx = x8c_navBackSfx;
}
break;
case UIType::AllDataWillBeLost: case EUIType::NotOriginalCard:
if (userSel == 1)
{
/* Continue */
x8_serial = x6c_cardDriver->x28_cardSerial;
x10_uiType = EUIType::Empty;
x6c_cardDriver->IndexFiles();
sfx = x84_navConfirmSfx;
}
else if (userSel == 0)
{
/* Cancel */
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
sfx = x8c_navBackSfx;
}
break;
case UIType::SaveProgress: case EUIType::AllDataWillBeLost:
if (userSel == 0)
{
/* Continue */
x6c_cardDriver->StartCardFormat();
x10_uiType = EUIType::Empty;
sfx = x84_navConfirmSfx;
}
else if (userSel == 1)
{
/* Cancel */
ResetCardDriver();
sfx = x8c_navBackSfx;
}
break;
case EUIType::SaveProgress:
if (x0_saveCtx == ESaveContext::InGame)
{
if (userSel == 0)
{
/* Yes */
x6c_cardDriver->BuildExistingFileSlot(g_GameState->GetFileIdx());
x6c_cardDriver->StartFileCreateTransactional();
sfx = x84_navConfirmSfx;
}
else if (userSel == 1)
{
/* No */
x80_iowRet = CIOWin::EMessageReturn::RemoveIOWinAndExit;
sfx = x8c_navBackSfx;
}
}
default: break; default: break;
} }
@ -410,30 +594,44 @@ void CSaveUI::DoAdvance(CGuiTableGroup* caller)
void CSaveUI::DoSelectionChange(CGuiTableGroup* caller) void CSaveUI::DoSelectionChange(CGuiTableGroup* caller)
{ {
SetUIColors();
CSfxManager::SfxStart(x88_navMoveSfx, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
} }
void CSaveUI::ProcessUserInput(const CFinalInput& input) void CSaveUI::ProcessUserInput(const CFinalInput& input)
{ {
if (x50_loadedFrame)
x50_loadedFrame->ProcessUserInput(input);
} }
void CSaveUI::StartGame(int idx) void CSaveUI::StartGame(int idx)
{ {
const CGameState::GameFileStateInfo* info = x6c_cardDriver->GetGameFileStateInfo(idx);
x6c_cardDriver->ExportPersistentOptions();
x6c_cardDriver->BuildNewFileSlot(idx);
if (info)
x6c_cardDriver->StartFileCreateTransactional();
else
x80_iowRet = CIOWin::EMessageReturn::Exit;
} }
void CSaveUI::EraseGame(int idx) void CSaveUI::EraseGame(int idx)
{ {
if (!x92_)
{
x90_needsDriverReset = true;
x8_serial = x6c_cardDriver->x28_cardSerial;
x6c_cardDriver->StartFileCreateTransactional();
}
} }
void* CSaveUI::GetGameData(int idx) const const CGameState::GameFileStateInfo* CSaveUI::GetGameData(int idx) const
{ {
return nullptr; return x6c_cardDriver->GetGameFileStateInfo(idx);
} }
CSaveUI::CSaveUI(u32 instIdx, u64 serial) CSaveUI::CSaveUI(ESaveContext saveCtx, u64 serial)
: x0_instIdx(instIdx), x8_serial(serial) : x0_saveCtx(saveCtx), x8_serial(serial)
{ {
x14_txtrSaveBanner = g_SimplePool->GetObj("TXTR_SaveBanner"); x14_txtrSaveBanner = g_SimplePool->GetObj("TXTR_SaveBanner");
x20_txtrSaveIcon0 = g_SimplePool->GetObj("TXTR_SaveIcon0"); x20_txtrSaveIcon0 = g_SimplePool->GetObj("TXTR_SaveIcon0");
@ -441,15 +639,15 @@ CSaveUI::CSaveUI(u32 instIdx, u64 serial)
x38_strgMemoryCard = g_SimplePool->GetObj("STRG_MemoryCard"); x38_strgMemoryCard = g_SimplePool->GetObj("STRG_MemoryCard");
x44_frmeGenericMenu = g_SimplePool->GetObj("FRME_GenericMenu"); x44_frmeGenericMenu = g_SimplePool->GetObj("FRME_GenericMenu");
x6c_cardDriver = ConstructCardDriver(x0_instIdx); x6c_cardDriver = ConstructCardDriver(bool(x0_saveCtx));
if (instIdx == 1) if (saveCtx == ESaveContext::InGame)
{ {
x84_navConfirmSfx = 1432; x84_navConfirmSfx = 1432;
x88_navMoveSfx = 1436; x88_navMoveSfx = 1436;
x8c_navBackSfx = 1431; x8c_navBackSfx = 1431;
} }
x93_secondaryInst = instIdx; x93_inGame = bool(saveCtx);
x70_saveWorlds.reserve(g_MemoryCardSys->GetMemoryWorlds().size()); x70_saveWorlds.reserve(g_MemoryCardSys->GetMemoryWorlds().size());
for (const std::pair<ResId, CSaveWorldMemory>& wld : g_MemoryCardSys->GetMemoryWorlds()) for (const std::pair<ResId, CSaveWorldMemory>& wld : g_MemoryCardSys->GetMemoryWorlds())
@ -459,12 +657,12 @@ CSaveUI::CSaveUI(u32 instIdx, u64 serial)
} }
} }
std::unique_ptr<CMemoryCardDriver> CSaveUI::ConstructCardDriver(bool importState) std::unique_ptr<CMemoryCardDriver> CSaveUI::ConstructCardDriver(bool inGame)
{ {
return std::make_unique<CMemoryCardDriver>(kabufuda::ECardSlot::SlotA, return std::make_unique<CMemoryCardDriver>(kabufuda::ECardSlot::SlotA,
g_ResFactory->GetResourceIdByName("TXTR_SaveBanner")->id, g_ResFactory->GetResourceIdByName("TXTR_SaveBanner")->id,
g_ResFactory->GetResourceIdByName("TXTR_SaveIcon0")->id, g_ResFactory->GetResourceIdByName("TXTR_SaveIcon0")->id,
g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, importState); g_ResFactory->GetResourceIdByName("TXTR_SaveIcon1")->id, inGame);
} }
} }

View File

@ -19,10 +19,16 @@ class CGuiTableGroup;
namespace MP1 namespace MP1
{ {
enum class ESaveContext
{
FrontEnd,
InGame
};
class CSaveUI class CSaveUI
{ {
public: public:
enum class UIType enum class EUIType
{ {
Empty = 0, Empty = 0,
BusyReading = 1, BusyReading = 1,
@ -47,10 +53,10 @@ public:
{ {
switch (x10_uiType) switch (x10_uiType)
{ {
case UIType::SaveProgress: case EUIType::SaveProgress:
case UIType::Empty: case EUIType::Empty:
case UIType::BusyReading: case EUIType::BusyReading:
case UIType::BusyWriting: case EUIType::BusyWriting:
return false; return false;
default: default:
return true; return true;
@ -58,9 +64,9 @@ public:
} }
private: private:
u32 x0_instIdx; ESaveContext x0_saveCtx;
u64 x8_serial; u64 x8_serial;
UIType x10_uiType = UIType::Empty; EUIType x10_uiType = EUIType::Empty;
TLockedToken<CTexture> x14_txtrSaveBanner; TLockedToken<CTexture> x14_txtrSaveBanner;
TLockedToken<CTexture> x20_txtrSaveIcon0; TLockedToken<CTexture> x20_txtrSaveIcon0;
TLockedToken<CTexture> x2c_txtrSaveIcon1; TLockedToken<CTexture> x2c_txtrSaveIcon1;
@ -82,16 +88,17 @@ private:
bool x90_needsDriverReset = false; bool x90_needsDriverReset = false;
bool x91_uiTextDirty = false; bool x91_uiTextDirty = false;
bool x92_ = false; bool x92_ = false;
bool x93_secondaryInst; bool x93_inGame;
void ResetCardDriver(); void ResetCardDriver();
void ContinueWithoutSaving(); void ContinueWithoutSaving();
public: public:
static std::unique_ptr<CMemoryCardDriver> ConstructCardDriver(bool importState); static std::unique_ptr<CMemoryCardDriver> ConstructCardDriver(bool inGame);
CIOWin::EMessageReturn Update(float dt); CIOWin::EMessageReturn Update(float dt);
void SetInGame(bool v) { x93_inGame = v; }
bool PumpLoad(); bool PumpLoad();
UIType SelectUIType() const; EUIType SelectUIType() const;
void SetUIText(); void SetUIText();
void SetUIColors(); void SetUIColors();
void Draw() const; void Draw() const;
@ -102,9 +109,9 @@ public:
void ProcessUserInput(const CFinalInput& input); void ProcessUserInput(const CFinalInput& input);
void StartGame(int idx); void StartGame(int idx);
void EraseGame(int idx); void EraseGame(int idx);
void* GetGameData(int idx) const; const CGameState::GameFileStateInfo* GetGameData(int idx) const;
UIType GetUIType() const { return x10_uiType; } EUIType GetUIType() const { return x10_uiType; }
CSaveUI(u32 inst, u64 serial); CSaveUI(ESaveContext saveCtx, u64 serial);
}; };
} }

View File

@ -142,6 +142,16 @@ void CMain::LoadAudio()
{ {
} }
void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx)
{
bool fusionBackup = g_GameState->SystemOptions().GetPlayerHasFusion();
x128_globalObjects.x134_gameState = CGameState(r, idx);
g_GameState = &x128_globalObjects.x134_gameState;
g_GameState->SystemOptions().SetPlayerHasFusion(fusionBackup);
g_GameState->GetPlayerState()->SetFusion(fusionBackup);
g_GameState->HintOptions().SetNextHintTime();
}
void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr,
boo::IAudioVoiceEngine* voiceEngine, boo::IAudioVoiceEngine* voiceEngine,
amuse::IBackendVoiceAllocator& backend) amuse::IBackendVoiceAllocator& backend)

View File

@ -48,6 +48,8 @@ class CMain;
class CGameGlobalObjects class CGameGlobalObjects
{ {
friend class CMain;
std::unique_ptr<CMemoryCardSys> x0_memoryCardSys; std::unique_ptr<CMemoryCardSys> x0_memoryCardSys;
IFactory& x4_resFactory; IFactory& x4_resFactory;
CSimplePool& xcc_simplePool; CSimplePool& xcc_simplePool;
@ -210,7 +212,7 @@ private:
bool x160_25_ : 1; bool x160_25_ : 1;
bool x160_26_ : 1; bool x160_26_ : 1;
bool x160_27_ : 1; bool x160_27_ : 1;
bool x160_28_ : 1; bool x160_28_manageCard : 1;
bool x160_29_ : 1; bool x160_29_ : 1;
bool x160_30_ : 1; bool x160_30_ : 1;
bool x160_31_cardBusy : 1; bool x160_31_cardBusy : 1;
@ -230,7 +232,7 @@ public:
boo::ITextureR* spareTex); boo::ITextureR* spareTex);
void RegisterResourceTweaks(); void RegisterResourceTweaks();
void ResetGameState(); void ResetGameState();
void StreamNewGameState(CInputStream&) {} void StreamNewGameState(CBitStreamReader&, u32 idx);
void CheckTweakManagerDebugOptions() {} void CheckTweakManagerDebugOptions() {}
//int RsMain(int argc, const boo::SystemChar* argv[]); //int RsMain(int argc, const boo::SystemChar* argv[]);
@ -242,15 +244,17 @@ public:
void Shutdown(); void Shutdown();
bool CheckReset() { return false; } bool CheckReset() { return false; }
bool CheckTerminate() {return false;} bool CheckTerminate() { return false; }
void DrawDebugMetrics(double, CStopWatch&) {} void DrawDebugMetrics(double, CStopWatch&) {}
void DoPredrawMetrics() {} void DoPredrawMetrics() {}
void FillInAssetIDs(); void FillInAssetIDs();
void LoadAudio(); void LoadAudio();
void ShutdownSubsystems() {} void ShutdownSubsystems() {}
EGameplayResult GetGameplayResult() const {return xe4_gameplayResult;} EGameplayResult GetGameplayResult() const { return xe4_gameplayResult; }
void SetGameplayResult(EGameplayResult wl) {xe4_gameplayResult = wl;} void SetGameplayResult(EGameplayResult wl) { xe4_gameplayResult = wl; }
void SetCardBusy(bool v) {x160_31_cardBusy = v;} void SetManageCard(bool v) { x160_28_manageCard = v; }
bool GetBardBusy() const { return x160_31_cardBusy; }
void SetCardBusy(bool v) { x160_31_cardBusy = v; }
EFlowState GetFlowState() const { return x12c_flowState; } EFlowState GetFlowState() const { return x12c_flowState; }
}; };

2
amuse

@ -1 +1 @@
Subproject commit df167556fbded7d8bcdf72306921a6594374121c Subproject commit 2836e738127b3a315977f1b9c51b30c6cfdf5dd2

2
nod

@ -1 +1 @@
Subproject commit 512a8a122d51c3bea20d0e2572c0d2dd6d6f1dce Subproject commit 31a06ea7266abace21473488d5191cea8e6554d2