feat(parity): implement EterBase CTimer, image/slot cooldown geometry rendering (pass32)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "PythonWindow.h"
|
||||
#include "PythonWindowManager.h"
|
||||
#include "src/eter_image/GrpDevice.h"
|
||||
#include "eter_base/Timer.h"
|
||||
#include "eter_render/CRenderTarget.h"
|
||||
#include "shared/common/CRC32.h"
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -847,7 +848,12 @@ namespace UI
|
||||
if (!m_pImageInstance)
|
||||
return;
|
||||
if (IsShow())
|
||||
m_pImageInstance->Render();
|
||||
{
|
||||
if (m_fCoolTime == 0.0f)
|
||||
m_pImageInstance->Render();
|
||||
else
|
||||
m_pImageInstance->RenderCoolTime((CTimer::Instance().GetCurrentSecond() - m_fCoolTimeStart) / m_fCoolTime);
|
||||
}
|
||||
}
|
||||
|
||||
void CImageBox::OnChangePosition()
|
||||
@@ -988,8 +994,15 @@ namespace UI
|
||||
|
||||
void CExpandedImageBox::OnRender()
|
||||
{
|
||||
if (m_pImageInstance && IsShow())
|
||||
m_pImageInstance->Render();
|
||||
if (!m_pImageInstance)
|
||||
return;
|
||||
if (IsShow())
|
||||
{
|
||||
if (m_fCoolTime == 0.0f)
|
||||
m_pImageInstance->Render();
|
||||
else
|
||||
((CGraphicExpandedImageInstance*)m_pImageInstance)->RenderCoolTime((CTimer::Instance().GetCurrentSecond() - m_fCoolTimeStart) / m_fCoolTime);
|
||||
}
|
||||
}
|
||||
|
||||
// CAniImageBox
|
||||
@@ -1573,7 +1586,7 @@ namespace UI
|
||||
// Render cooltime overlay & countdown text
|
||||
CGraphicDevice* pDevice = CGraphicDevice::InstancePtr();
|
||||
SDL_Renderer* ren = pDevice ? pDevice->GetRenderer() : nullptr;
|
||||
float curTime = SDL_GetTicks() / 1000.0f;
|
||||
float curTime = CTimer::Instance().GetCurrentSecond();
|
||||
|
||||
for (auto& pair : m_slotMap) {
|
||||
SSlot& slot = pair.second;
|
||||
@@ -1581,16 +1594,65 @@ namespace UI
|
||||
float elapsed = curTime - slot.fStartCoolTime;
|
||||
if (elapsed < slot.fCoolTime) {
|
||||
if (ren) {
|
||||
float percent = std::max(0.0f, std::min(1.0f, (slot.fCoolTime - elapsed) / slot.fCoolTime));
|
||||
SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(ren, 15, 15, 15, 175);
|
||||
SDL_FRect shadeRect{
|
||||
static_cast<float>(m_rect.left + slot.ixPosition),
|
||||
static_cast<float>(m_rect.top + slot.iyPosition + slot.iyCellSize * (1.0f - percent)),
|
||||
static_cast<float>(slot.ixCellSize),
|
||||
static_cast<float>(slot.iyCellSize * percent)
|
||||
};
|
||||
SDL_RenderFillRect(ren, &shadeRect);
|
||||
float percent = (curTime - slot.fStartCoolTime) / slot.fCoolTime;
|
||||
float fRadius = slot.ixCellSize * 0.5f;
|
||||
float fxCenter = m_rect.left + slot.ixPosition + fRadius;
|
||||
float fyCenter = m_rect.top + slot.iyPosition + fRadius;
|
||||
|
||||
if (percent < 1.0f) {
|
||||
if (percent < 0.0f) percent = 0.0f;
|
||||
const int c_iTriangleCountPerBox = 8;
|
||||
static const SDL_FPoint s_v2BoxPos[c_iTriangleCountPerBox] = {
|
||||
{ -1.0f, -1.0f },
|
||||
{ -1.0f, 0.0f },
|
||||
{ -1.0f, +1.0f },
|
||||
{ 0.0f, +1.0f },
|
||||
{ +1.0f, +1.0f },
|
||||
{ +1.0f, 0.0f },
|
||||
{ +1.0f, -1.0f },
|
||||
{ 0.0f, -1.0f },
|
||||
};
|
||||
int iTriCount = static_cast<int>(8.0f - 8.0f * percent);
|
||||
float fLastPercentage = (8.0f - 8.0f * percent) - iTriCount;
|
||||
|
||||
std::vector<SDL_Vertex> vertices;
|
||||
SDL_FColor color{ 0.0f, 0.0f, 0.0f, 0.55f };
|
||||
vertices.push_back({ { fxCenter, fyCenter }, color, { 0.0f, 0.0f } });
|
||||
vertices.push_back({ { fxCenter, fyCenter - fRadius }, color, { 0.0f, 0.0f } });
|
||||
|
||||
for (int j = 0; j < iTriCount; ++j) {
|
||||
vertices.push_back({
|
||||
{ fxCenter + s_v2BoxPos[j].x * fRadius, fyCenter + s_v2BoxPos[j].y * fRadius },
|
||||
color,
|
||||
{ 0.0f, 0.0f }
|
||||
});
|
||||
}
|
||||
|
||||
if (fLastPercentage > 0.0f) {
|
||||
const SDL_FPoint* pv2LastPos = &s_v2BoxPos[(iTriCount - 1 + 8) % 8];
|
||||
const SDL_FPoint* pv2Pos = &s_v2BoxPos[(iTriCount + 8) % 8];
|
||||
float lx = (pv2Pos->x - pv2LastPos->x) * fLastPercentage + pv2LastPos->x;
|
||||
float ly = (pv2Pos->y - pv2LastPos->y) * fLastPercentage + pv2LastPos->y;
|
||||
vertices.push_back({
|
||||
{ fxCenter + lx * fRadius, fyCenter + ly * fRadius },
|
||||
color,
|
||||
{ 0.0f, 0.0f }
|
||||
});
|
||||
++iTriCount;
|
||||
}
|
||||
|
||||
if (vertices.size() >= 3 && iTriCount > 0) {
|
||||
std::vector<int> indices;
|
||||
indices.reserve(iTriCount * 3);
|
||||
for (int k = 0; k < iTriCount; ++k) {
|
||||
indices.push_back(0);
|
||||
indices.push_back(k + 1);
|
||||
indices.push_back(k + 2);
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
SDL_RenderGeometry(ren, nullptr, vertices.data(), static_cast<int>(vertices.size()), indices.data(), static_cast<int>(indices.size()));
|
||||
}
|
||||
}
|
||||
|
||||
int remainSec = static_cast<int>(std::ceil(slot.fCoolTime - elapsed));
|
||||
if (remainSec > 0 && slot.ixCellSize >= 24) {
|
||||
@@ -1603,6 +1665,9 @@ namespace UI
|
||||
SDL_RenderDebugText(ren, tx, ty, buf);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
slot.fCoolTime = 0.0f;
|
||||
slot.fStartCoolTime = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user