Fixing UI bugs, updating web UI
This commit is contained in:
1 parent
dee9615483
commit
7031a21922
28 files changed
+216
-48
No files matched your search
+132
-3
@@ -48,18 +48,24 @@ namespace ZL
|
||||
#ifdef EMSCRIPTEN
|
||||
Game* Game::s_instance = nullptr;
|
||||
|
||||
void Game::onResourcesZipLoaded(const char* /*filename*/) {
|
||||
void Game::onResourcesZipLoaded(unsigned /*handle*/, void* /*userData*/, const char* /*filename*/) {
|
||||
std::cout << "Resources.zip loaded successfully" << std::endl;
|
||||
if (s_instance) {
|
||||
s_instance->resourcesDownloadProgress = 1.0f;
|
||||
s_instance->mainThreadHandler.EnqueueMainThreadTask([&]() {
|
||||
s_instance->setupPart2();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Game::onResourcesZipError(const char* /*filename*/) {
|
||||
void Game::onResourcesZipError(unsigned /*handle*/, void* /*userData*/, int /*httpStatus*/) {
|
||||
std::cout << "Failed to download resources.zip" << std::endl;
|
||||
}
|
||||
|
||||
void Game::onResourcesZipProgress(unsigned /*handle*/, void* /*userData*/, int percentComplete) {
|
||||
if (s_instance)
|
||||
s_instance->resourcesDownloadProgress = percentComplete / 100.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
Game::Game()
|
||||
@@ -98,6 +104,12 @@ namespace ZL
|
||||
#endif
|
||||
loadingTexture = renderer.textureManager.LoadFromPng("resources/loading.png", "");
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
loadingProgressBarFrameTexture = renderer.textureManager.LoadFromPng(
|
||||
"resources/loadingProgressBarFrame.png", "", true);
|
||||
loadingProgressBarTexture = renderer.textureManager.LoadFromPng(
|
||||
"resources/loadingProgressBar.png", "", true);
|
||||
#endif
|
||||
float minDimension;
|
||||
float width = Environment::projectionWidth;
|
||||
float height = Environment::projectionHeight;
|
||||
@@ -119,7 +131,8 @@ namespace ZL
|
||||
// The loading screen stays visible until the download finishes.
|
||||
s_instance = this;
|
||||
std::cout << "Load resurces step 1" << std::endl;
|
||||
emscripten_async_wget("resources.zip", "resources.zip", onResourcesZipLoaded, onResourcesZipError);
|
||||
emscripten_async_wget2("resources.zip", "resources.zip", "GET", nullptr, nullptr,
|
||||
onResourcesZipLoaded, onResourcesZipError, onResourcesZipProgress);
|
||||
#else
|
||||
mainThreadHandler.EnqueueMainThreadTask([this]() {
|
||||
std::cout << "Load resurces step 2" << std::endl;
|
||||
@@ -451,6 +464,9 @@ namespace ZL
|
||||
renderer.textureManager.LoadFromPng("resources/w/ui/img/toast/item_received001.png", CONST_ZIP_FILE, true);
|
||||
renderer.textureManager.LoadFromPng("resources/w/ui/img/toast/item_removed001.png", CONST_ZIP_FILE, true);
|
||||
|
||||
mobileRotateTexture = renderer.textureManager.LoadFromPng(
|
||||
"resources/rotateYourDevice.png", CONST_ZIP_FILE, true);
|
||||
|
||||
|
||||
|
||||
// Wire inventory callbacks: tutorial tracking + toast notifications.
|
||||
@@ -608,6 +624,9 @@ namespace ZL
|
||||
if (!loadingCompleted) {
|
||||
drawLoading();
|
||||
}
|
||||
else if (Environment::width < Environment::height) {
|
||||
drawMobilePortraitOverlay();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentLocation)
|
||||
@@ -643,6 +662,37 @@ namespace ZL
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
void Game::drawMobilePortraitOverlay()
|
||||
{
|
||||
if (!mobileRotateTexture) return;
|
||||
|
||||
const float W = Environment::projectionWidth;
|
||||
const float H = Environment::projectionHeight;
|
||||
|
||||
if (W != mobileRotateMeshLastW || H != mobileRotateMeshLastH) {
|
||||
mobileRotateMeshLastW = W;
|
||||
mobileRotateMeshLastH = H;
|
||||
const float minDim = min(W, H);
|
||||
mobileRotateMesh.data = CreateRect2D({ 0.f, 0.f }, { minDim * 0.5f, minDim * 0.5f }, 3.f);
|
||||
mobileRotateMesh.RefreshVBO();
|
||||
}
|
||||
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||
renderer.PushProjectionMatrix(-W * 0.5f, W * 0.5f, -H * 0.5f, H * 0.5f, -10, 10);
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, mobileRotateTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(mobileRotateMesh);
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.shaderManager.PopShader();
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
void Game::drawLoading()
|
||||
{
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
@@ -669,6 +719,81 @@ namespace ZL
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
if (loadingProgressBarFrameTexture && loadingProgressBarTexture) {
|
||||
const float W = Environment::projectionWidth;
|
||||
const float H = Environment::projectionHeight;
|
||||
static constexpr float kBarW = 400.0f;
|
||||
static constexpr float kBarH = 40.0f;
|
||||
const float barCenterY = -(H * 0.4f - 60.0f);
|
||||
const float barLeft = -kBarW * 0.5f;
|
||||
const float barBottom = barCenterY - kBarH * 0.5f;
|
||||
const float barTop = barCenterY + kBarH * 0.5f;
|
||||
|
||||
|
||||
// Rebuild frame mesh when projection dimensions change
|
||||
if (W != loadingBarLastW || H != loadingBarLastH) {
|
||||
loadingBarLastW = W;
|
||||
loadingBarLastH = H;
|
||||
VertexDataStruct frameData;
|
||||
frameData.PositionData = {
|
||||
{barLeft, barBottom, 4.f}, {barLeft, barTop, 4.f}, {barLeft+kBarW, barTop, 4.f},
|
||||
{barLeft+kBarW, barTop, 4.f}, {barLeft+kBarW, barBottom, 4.f}, {barLeft, barBottom, 4.f}
|
||||
};
|
||||
frameData.TexCoordData = {
|
||||
{0.f,0.f},{0.f,1.f},{1.f,1.f},
|
||||
{1.f,1.f},{1.f,0.f},{0.f,0.f}
|
||||
};
|
||||
loadingProgressBarFrameMesh.data = std::move(frameData);
|
||||
loadingProgressBarFrameMesh.RefreshVBO();
|
||||
loadingBarLastRenderedProgress = -1.0f; // force fill rebuild too
|
||||
}
|
||||
|
||||
// Rebuild fill mesh when progress changes
|
||||
const float p = std::min(resourcesDownloadProgress, 1.0f);
|
||||
if (p != loadingBarLastRenderedProgress) {
|
||||
loadingBarLastRenderedProgress = p;
|
||||
if (p > 0.001f) {
|
||||
const float fillRight = barLeft + kBarW * p;
|
||||
VertexDataStruct fillData;
|
||||
fillData.PositionData = {
|
||||
{barLeft, barBottom, 4.f}, {barLeft, barTop, 4.f}, {fillRight, barTop, 4.f},
|
||||
{fillRight, barTop, 4.f}, {fillRight, barBottom, 4.f}, {barLeft, barBottom, 4.f}
|
||||
};
|
||||
fillData.TexCoordData = {
|
||||
{0.f,0.f},{0.f,1.f},{p,1.f},
|
||||
{p,1.f},{p,0.f},{0.f,0.f}
|
||||
};
|
||||
loadingProgressBarFillMesh.data = std::move(fillData);
|
||||
loadingProgressBarFillMesh.RefreshVBO();
|
||||
}
|
||||
}
|
||||
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||
renderer.PushProjectionMatrix(-W*0.5f, W*0.5f, -H*0.5f, H*0.5f, -10, 10);
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, loadingProgressBarFrameTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(loadingProgressBarFrameMesh);
|
||||
|
||||
if (p > 0.001f) {
|
||||
glBindTexture(GL_TEXTURE_2D, loadingProgressBarTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(loadingProgressBarFillMesh);
|
||||
}
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.shaderManager.PopShader();
|
||||
}
|
||||
#endif
|
||||
|
||||
CheckGlError(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
@@ -729,6 +854,7 @@ namespace ZL
|
||||
|
||||
void Game::update() {
|
||||
SDL_Event event;
|
||||
const bool mobileIsPortrait = loadingCompleted && (Environment::width < Environment::height);
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
Environment::exitGameLoop = true;
|
||||
@@ -746,6 +872,9 @@ namespace ZL
|
||||
//space.clearTextRendererCache();
|
||||
}
|
||||
|
||||
// Suppress all input while portrait overlay is shown
|
||||
if (mobileIsPortrait) continue;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
Environment::exitGameLoop = true;
|
||||
|
||||
Reference in new issue
Block a user