2016-03-19 00:07:31 +00:00
|
|
|
#include "CGuiTextSupport.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
2016-03-21 05:02:56 +00:00
|
|
|
#include "CFontImageDef.hpp"
|
2016-03-21 22:01:19 +00:00
|
|
|
#include "CGuiSys.hpp"
|
|
|
|
#include "CTextExecuteBuffer.hpp"
|
|
|
|
#include "CTextParser.hpp"
|
2016-03-21 05:02:56 +00:00
|
|
|
#include "Graphics/CGraphicsPalette.hpp"
|
2016-03-21 22:01:19 +00:00
|
|
|
#include "Graphics/CGraphics.hpp"
|
2016-03-22 18:35:52 +00:00
|
|
|
#include "GuiSys/CRasterFont.hpp"
|
2016-03-19 00:07:31 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CGuiTextSupport::CGuiTextSupport(TResId fontId, const CGuiTextProperties& props,
|
2016-03-22 02:27:46 +00:00
|
|
|
const zeus::CColor& fontCol, const zeus::CColor& outlineCol,
|
|
|
|
const zeus::CColor& geomCol, s32 padX, s32 padY, CSimplePool* store)
|
|
|
|
: x10_props(props), x1c_fontColor(fontCol), x20_outlineColor(outlineCol),
|
|
|
|
x24_geometryColor(geomCol), x28_extentX(padX), x2c_extentY(padY)
|
2016-03-21 05:02:56 +00:00
|
|
|
{
|
|
|
|
x2c0_font = store->GetObj({SBIG('FONT'), fontId});
|
|
|
|
}
|
|
|
|
|
2016-03-21 22:01:19 +00:00
|
|
|
float CGuiTextSupport::GetCurrentAnimationOverAge() const
|
2016-03-21 05:02:56 +00:00
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (!x2ac_active || !x44_typeEnable)
|
|
|
|
return 0.f;
|
2016-03-21 05:02:56 +00:00
|
|
|
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x34_primStartTimes.size())
|
|
|
|
{
|
2016-03-22 08:15:00 +00:00
|
|
|
float val = (x54_renderBuf->GetPrimitiveCount() - x34_primStartTimes.back().second) /
|
2016-03-21 22:01:19 +00:00
|
|
|
x4c_chRate + x34_primStartTimes.back().first;
|
|
|
|
return std::max(0.f, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-22 08:15:00 +00:00
|
|
|
float val = x54_renderBuf->GetPrimitiveCount() / x4c_chRate;
|
2016-03-21 22:01:19 +00:00
|
|
|
return std::max(0.f, val);
|
|
|
|
}
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 22:01:19 +00:00
|
|
|
float CGuiTextSupport::GetNumCharsPrinted() const
|
2016-03-21 05:02:56 +00:00
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x2ac_active)
|
2016-03-22 08:15:00 +00:00
|
|
|
return std::min(x30_curTime * x4c_chRate, float(x54_renderBuf->GetPrimitiveCount()));
|
2016-03-21 22:01:19 +00:00
|
|
|
return 0.f;
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 22:01:19 +00:00
|
|
|
float CGuiTextSupport::GetTotalAnimationTime() const
|
2016-03-21 05:02:56 +00:00
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (!x2ac_active || !x44_typeEnable)
|
|
|
|
return 0.f;
|
|
|
|
|
2016-03-22 08:15:00 +00:00
|
|
|
return x54_renderBuf->GetPrimitiveCount() / x4c_chRate;
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 22:01:19 +00:00
|
|
|
void CGuiTextSupport::SetTypeWriteEffectOptions(bool enable, float chFadeTime, float chRate)
|
2016-03-21 05:02:56 +00:00
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
x44_typeEnable = enable;
|
|
|
|
x48_chFadeTime = std::max(chFadeTime, 0.0001f);
|
|
|
|
x4c_chRate = std::max(chRate, 1.f);
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::Update(float dt)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (!x2ac_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x44_typeEnable)
|
|
|
|
{
|
2016-03-22 08:15:00 +00:00
|
|
|
for (int i=0 ; i<x54_renderBuf->GetPrimitiveCount() ; ++i)
|
2016-03-21 22:01:19 +00:00
|
|
|
{
|
|
|
|
float chStartTime = 0.f;
|
|
|
|
for (const std::pair<float, int>& p : x34_primStartTimes)
|
|
|
|
{
|
|
|
|
if (p.second < i)
|
|
|
|
continue;
|
|
|
|
if (p.second != i)
|
|
|
|
break;
|
|
|
|
chStartTime = p.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-22 08:15:00 +00:00
|
|
|
#if 0
|
2016-03-21 22:01:19 +00:00
|
|
|
CTextRenderBuffer::Primitive prim = x54_renderBuf->GetPrimitive(i);
|
|
|
|
prim.x0_color1.a = std::min(std::max(0.f, (x30_curTime - chStartTime) / x48_chFadeTime), 1.f);
|
|
|
|
x54_renderBuf->SetPrimitive(prim, i);
|
2016-03-22 08:15:00 +00:00
|
|
|
#else
|
|
|
|
x54_renderBuf->SetPrimitiveOpacity(i,
|
|
|
|
std::min(std::max(0.f, (x30_curTime - chStartTime) / x48_chFadeTime), 1.f));
|
|
|
|
#endif
|
2016-03-21 22:01:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x30_curTime += dt;
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::ClearBuffer()
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
x54_renderBuf = std::experimental::nullopt;
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::CheckAndRebuildTextRenderBuffer()
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x2ac_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_TextExecuteBuf->Clear();
|
|
|
|
g_TextExecuteBuf->x18_textState.x48_enableWordWrap = x10_props.x0_wordWrap;
|
2016-03-22 02:27:46 +00:00
|
|
|
g_TextExecuteBuf->BeginBlock(0, 0, x28_extentX, x2c_extentY, ETextDirection(x10_props.x1_vertical),
|
2016-03-21 22:01:19 +00:00
|
|
|
x10_props.x4_justification, x10_props.x8_vertJustification);
|
|
|
|
g_TextExecuteBuf->AddColor(EColorType::Main, x1c_fontColor);
|
|
|
|
g_TextExecuteBuf->AddColor(EColorType::Outline, x20_outlineColor);
|
|
|
|
|
|
|
|
std::wstring initStr;
|
|
|
|
if ((x50_fontId & 0xffff) != 0xffff)
|
|
|
|
initStr = hecl::WideFormat(L"&font=%08X;", u32(x50_fontId));
|
|
|
|
initStr += x0_string;
|
|
|
|
|
|
|
|
g_TextParser->ParseText(*g_TextExecuteBuf, initStr.c_str(), initStr.size());
|
|
|
|
|
|
|
|
g_TextExecuteBuf->EndBlock();
|
|
|
|
x2b0_assets = g_TextExecuteBuf->GetAssets();
|
|
|
|
|
|
|
|
if (GetIsTextSupportFinishedLoading())
|
|
|
|
{
|
|
|
|
x54_renderBuf = g_TextExecuteBuf->CreateTextRenderBuffer();
|
|
|
|
g_TextExecuteBuf->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Update(0.f);
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::Render() const
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x2ac_active)
|
|
|
|
{
|
|
|
|
zeus::CTransform oldModel = CGraphics::g_GXModelMatrix;
|
|
|
|
CGraphics::SetModelMatrix(oldModel * zeus::CTransform::Scale(1.f, 1.f, -1.f));
|
|
|
|
x54_renderBuf->Render(x24_geometryColor, x30_curTime);
|
|
|
|
CGraphics::SetModelMatrix(oldModel);
|
|
|
|
}
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::SetGeometryColor(const zeus::CColor& col)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
x24_geometryColor = col;
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::SetOutlineColor(const zeus::CColor& col)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (col != x20_outlineColor)
|
|
|
|
{
|
|
|
|
ClearBuffer();
|
|
|
|
x20_outlineColor = col;
|
|
|
|
}
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::SetFontColor(const zeus::CColor& col)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (col != x1c_fontColor)
|
|
|
|
{
|
|
|
|
ClearBuffer();
|
|
|
|
x1c_fontColor = col;
|
|
|
|
}
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::AddText(const std::wstring& str)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x2ac_active)
|
|
|
|
{
|
|
|
|
float t = GetCurrentAnimationOverAge();
|
|
|
|
x34_primStartTimes.push_back(std::make_pair(std::max(t, x30_curTime),
|
2016-03-22 08:15:00 +00:00
|
|
|
x54_renderBuf->GetPrimitiveCount()));
|
2016-03-21 22:01:19 +00:00
|
|
|
}
|
|
|
|
x0_string += str;
|
|
|
|
ClearBuffer();
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::SetText(const std::wstring& str)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
if (x0_string.compare(str))
|
|
|
|
{
|
|
|
|
x34_primStartTimes.clear();
|
|
|
|
x30_curTime = 0.f;
|
|
|
|
x0_string = str;
|
|
|
|
ClearBuffer();
|
|
|
|
}
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiTextSupport::SetText(const std::string& str)
|
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
SetText(hecl::UTF8ToWide(str));
|
2016-03-21 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGuiTextSupport::GetIsTextSupportFinishedLoading() const
|
2016-03-19 00:07:31 +00:00
|
|
|
{
|
2016-03-21 22:01:19 +00:00
|
|
|
for (const CToken& tok : x2b0_assets)
|
|
|
|
{
|
|
|
|
((CToken&)tok).Lock();
|
|
|
|
if (!tok.IsLoaded())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return x2c0_font.IsLoaded();
|
2016-03-19 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|