Working on messenger in portrait mode
This commit is contained in:
1 parent
0b4df8ab2d
commit
8c42179576
10 files changed
+498
-65
No files matched your search
+42
-25
@@ -854,6 +854,22 @@ namespace ZL {
|
||||
mesh.RefreshVBO();
|
||||
}
|
||||
|
||||
float UiChatBubble::computeWidthPortrait() const {
|
||||
if (!textRenderer) return P_MAX_WIDTH;
|
||||
const float measuredTextW = textRenderer->measureTextWidth(text, 1.0f);
|
||||
const float required = measuredTextW + P_CORNER_SIZE * 2.0f + P_PAD_X * 2.0f;
|
||||
return min(required, P_MAX_WIDTH);
|
||||
}
|
||||
|
||||
float UiChatBubble::computeHeightPortrait() const {
|
||||
if (!textRenderer) return P_CORNER_SIZE * 2 + P_PAD_Y * 2 + static_cast<float>(fontSize);
|
||||
const float textW = computeWidthPortrait() - P_CORNER_SIZE * 2.0f - P_PAD_X * 2.0f;
|
||||
const std::string wrapped = wrapTextByPixels(text, *textRenderer, textW, 1.0f);
|
||||
int lines = 1;
|
||||
for (char c : wrapped) if (c == '\n') ++lines;
|
||||
return P_CORNER_SIZE * 2.0f + P_PAD_Y * 2.0f + lines * static_cast<float>(fontSize) * 1.25f;
|
||||
}
|
||||
|
||||
float UiChatBubble::computeWidth() const {
|
||||
if (!textRenderer) return MAX_WIDTH;
|
||||
const float measuredTextW = textRenderer->measureTextWidth(text, 1.0f);
|
||||
@@ -892,7 +908,7 @@ namespace ZL {
|
||||
buildQuadMesh(meshCornerRB, x + w - cs, y, x + w, y + cs);
|
||||
}
|
||||
|
||||
void UiChatBubble::draw(Renderer& renderer, float nodeScaleX, float nodeScaleY) const {
|
||||
void UiChatBubble::draw(Renderer& renderer, float nodeScaleX, float nodeScaleY, float projW, float projH) const {
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
|
||||
@@ -936,7 +952,7 @@ namespace ZL {
|
||||
const float tx = cx + (tx0 - cx) * nodeScaleX;
|
||||
const float ty = cy + (ty0 - cy) * nodeScaleY;
|
||||
|
||||
textRenderer->drawText(wrapped, tx, ty, nodeScaleX, false, { 1.f, 1.f, 1.f, 1.f });
|
||||
textRenderer->drawText(wrapped, tx, ty, nodeScaleX, false, { 1.f, 1.f, 1.f, 1.f }, projW, projH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1456,8 +1472,10 @@ namespace ZL {
|
||||
return static_cast<int>(menuStack.size());
|
||||
}
|
||||
|
||||
void UiManager::draw(Renderer& renderer) {
|
||||
renderer.PushProjectionMatrix(Environment::projectionWidth, Environment::projectionHeight, -1, 1);
|
||||
void UiManager::draw(Renderer& renderer, float projW, float projH) {
|
||||
if (projW <= 0.0f) projW = Environment::projectionWidth;
|
||||
if (projH <= 0.0f) projH = Environment::projectionHeight;
|
||||
renderer.PushProjectionMatrix(projW, projH, -1, 1);
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
renderer.RenderUniform1f("uAlpha", 1.0f); // ensure alpha is fully opaque unless a widget overrides it
|
||||
@@ -1481,7 +1499,7 @@ namespace ZL {
|
||||
|
||||
// 1b. Chat bubble (composite widget)
|
||||
if (node->chatBubble) {
|
||||
node->chatBubble->draw(renderer, node->scaleX, node->scaleY);
|
||||
node->chatBubble->draw(renderer, node->scaleX, node->scaleY, projW, projH);
|
||||
}
|
||||
|
||||
// 2. Потом кнопки
|
||||
@@ -2136,6 +2154,7 @@ namespace ZL {
|
||||
std::shared_ptr<Texture> texLT, std::shared_ptr<Texture> texLB,
|
||||
std::shared_ptr<Texture> texRT, std::shared_ptr<Texture> texRB,
|
||||
Renderer& renderer, const std::string& fontPath, int fontSize,
|
||||
bool isPortrait,
|
||||
const std::string& zipFile)
|
||||
{
|
||||
if (!root) return "";
|
||||
@@ -2168,39 +2187,37 @@ namespace ZL {
|
||||
// Build the UiNode
|
||||
auto node = std::make_shared<UiNode>();
|
||||
node->name = nodeName;
|
||||
node->width = bubble->computeWidth();
|
||||
node->height = bubble->computeHeight();
|
||||
node->width = isPortrait? bubble->computeWidthPortrait() : bubble->computeWidth();
|
||||
node->height = isPortrait? bubble->computeHeightPortrait() : bubble->computeHeight();
|
||||
|
||||
if (incoming) {
|
||||
node->localX = -node->width * 0.5+110 - (UiChatBubble::MAX_WIDTH - node->width);// +(425.f - node->width);
|
||||
|
||||
if (isPortrait)
|
||||
{
|
||||
if (incoming) {
|
||||
node->localX = -300 + node->width * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
node->localX = 300 - node->width * 0.5;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*if (node->width == UiChatBubble::MAX_WIDTH)
|
||||
{
|
||||
node->localX = node->width * 0.5 - 110 - (UiChatBubble::MAX_WIDTH - node->width);// -(425.f - node->width);
|
||||
if (incoming) {
|
||||
node->localX = -210 + node->width * 0.5;
|
||||
}
|
||||
else
|
||||
{*/
|
||||
//node->localX = node->width * 0.5 - 110;
|
||||
//node->localX = - 110 +x;
|
||||
node->localX = 210 - node->width * 0.5;
|
||||
//}
|
||||
{
|
||||
node->localX = 210 - node->width * 0.5;
|
||||
}
|
||||
}
|
||||
//430
|
||||
//1280
|
||||
|
||||
node->localY = 0.0f;
|
||||
node->visible = true;
|
||||
node->chatBubble = bubble;
|
||||
|
||||
node->layoutSettings.hGravity = HorizontalGravity::Center;
|
||||
/*
|
||||
if (incoming) {
|
||||
node->layoutSettings.hGravity = HorizontalGravity::Left;
|
||||
} else {
|
||||
node->layoutSettings.hGravity = HorizontalGravity::Right;
|
||||
}*/
|
||||
|
||||
// Bottom gravity means localY is used as-is for screenRect.y (no parentH transform).
|
||||
// The original static chat nodes all had "vertical_gravity": "bottom" for the same reason.
|
||||
node->layoutSettings.vGravity = VerticalGravity::Bottom;
|
||||
|
||||
Reference in new issue
Block a user