Working on removing ui label

This commit is contained in:
2023-06-12 10:09:45 -07:00
parent dd1004257e
commit aab5548ae2
12 changed files with 97 additions and 261 deletions

View File

@ -15,86 +15,90 @@ VNTextboxScroller::VNTextboxScroller(SceneItem *item) :
}
void VNTextboxScroller::onStart() {
assertNotNull(label);
// assertNotNull(label);
std::function<void()> x = [&]{
this->lineCurrent = 0;
this->timeCharacter = 0;
this->label->startQuad = 0;
this->label->quadCount = 0;
this->readyToClose = false;
};
x();
// std::function<void()> x = [&]{
// this->lineCurrent = 0;
// this->timeCharacter = 0;
// this->label->startQuad = 0;
// this->label->quadCount = 0;
// this->readyToClose = false;
// };
// x();
useEvent(x, this->label->eventTextChanged);
// useEvent(x, this->label->eventTextChanged);
useEvent([&](float_t delta){
auto game = this->getGame();
// useEvent([&](float_t delta){
// auto game = this->getGame();
this->timeCharacter += delta;
if(this->hasRevealedAllCurrentCharacters()) {
if(this->hasRevealedAllCharacters()) {
if(!this->readyToClose) {
this->readyToClose = true;
this->eventReadyToClose.invoke();
}
} else {
if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
this->lineCurrent += this->getCountOfVisibleLines();
this->label->startQuad = 0;
for(int32_t i = 0; i < this->lineCurrent; i++) {
this->label->startQuad += this->label->measure.getQuadsOnLine(i);
}
this->label->quadCount = 0;
this->timeCharacter = 0.0f;
}
}
return;
}
// this->timeCharacter += delta;
// if(this->hasRevealedAllCurrentCharacters()) {
// if(this->hasRevealedAllCharacters()) {
// if(!this->readyToClose) {
// this->readyToClose = true;
// this->eventReadyToClose.invoke();
// }
// } else {
// if(game->inputManager.isPressed(INPUT_BIND_ACCEPT)) {
// this->lineCurrent += this->getCountOfVisibleLines();
// this->label->startQuad = 0;
// for(int32_t i = 0; i < this->lineCurrent; i++) {
// this->label->startQuad += this->label->measure.getQuadsOnLine(i);
// }
// this->label->quadCount = 0;
// this->timeCharacter = 0.0f;
// }
// }
// return;
// }
auto lastTimeCharacter = mathFloor<int32_t>(this->timeCharacter);
if(game->inputManager.isDown(INPUT_BIND_ACCEPT)) {
this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED_FASTER;
} else {
this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED;
}
// auto lastTimeCharacter = mathFloor<int32_t>(this->timeCharacter);
// if(game->inputManager.isDown(INPUT_BIND_ACCEPT)) {
// this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED_FASTER;
// } else {
// this->timeCharacter += game->timeManager.delta * VN_TEXTBOX_SPEED;
// }
auto newCount = mathFloor<int32_t>(this->timeCharacter);
if(newCount == this->label->quadCount) return;
this->label->quadCount = mathFloor<int32_t>(this->timeCharacter);
this->eventCharacterRevealed.invoke();
}, getScene()->eventSceneUpdate);
// auto newCount = mathFloor<int32_t>(this->timeCharacter);
// if(newCount == this->label->quadCount) return;
// this->label->quadCount = mathFloor<int32_t>(this->timeCharacter);
// this->eventCharacterRevealed.invoke();
// }, getScene()->eventSceneUpdate);
assertUnreachable();
}
size_t VNTextboxScroller::getCountOfVisibleLines() {
float_t y = this->label->getHeight();
size_t i = 1;
for(i = this->label->measure.getLineCount(); i > 0; --i) {
if(y >= this->label->measure.getHeightOfLineCount(i)) {
return i;
}
}
return this->label->measure.getLineCount();
// float_t y = this->label->getHeight();
// size_t i = 1;
// for(i = this->label->measure.getLineCount(); i > 0; --i) {
// if(y >= this->label->measure.getHeightOfLineCount(i)) {
// return i;
// }
// }
// return this->label->measure.getLineCount();
assertUnreachable();
}
bool_t VNTextboxScroller::hasRevealedAllCurrentCharacters() {
int32_t quadsTotal = 0;
for(
size_t i = this->lineCurrent;
i < mathMin<size_t>(
this->label->measure.getLineCount(),
this->lineCurrent + this->getCountOfVisibleLines()
);
i++
) {
quadsTotal += this->label->measure.getQuadsOnLine(i);
}
return mathFloor<int32_t>(this->timeCharacter) >= quadsTotal;
// int32_t quadsTotal = 0;
// for(
// size_t i = this->lineCurrent;
// i < mathMin<size_t>(
// this->label->measure.getLineCount(),
// this->lineCurrent + this->getCountOfVisibleLines()
// );
// i++
// ) {
// quadsTotal += this->label->measure.getQuadsOnLine(i);
// }
// return mathFloor<int32_t>(this->timeCharacter) >= quadsTotal;
assertUnreachable();
}
bool_t VNTextboxScroller::hasRevealedAllCharacters() {
return (
this->lineCurrent + this->getCountOfVisibleLines() >=
this->label->measure.getLineCount()
);
// return (
// this->lineCurrent + this->getCountOfVisibleLines() >=
// this->label->measure.getLineCount()
// );
assertUnreachable();
}

View File

@ -5,7 +5,7 @@
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "scene/components/ui/UILabel.hpp"
#include "scene/components/ui/text/UILabelNew.hpp"
#include "input/InputManager.hpp"
#define VN_TEXTBOX_SPEED 25.0f
@ -15,7 +15,7 @@ namespace Dawn {
class VNTextboxScroller : public SceneItemComponent {
public:
// @optional
StateProperty<UILabel*> label;
StateProperty<UILabelNew*> label;
StateEvent<> eventReadyToClose;
StateEvent<> eventCharacterRevealed;

View File

@ -20,7 +20,8 @@ namespace Dawn {
scroller = this->getScene()->findComponent<VNTextboxScroller>();
assertNotNull(scroller);
scroller->label->text = text;
assertUnreachable();
// scroller->label->text = text;
useEvent([&](inputbind_t bind){
if(bind != INPUT_BIND_ACCEPT) return;

View File

@ -18,6 +18,7 @@ void FPSLabelComponent::onStart() {
if(this->label == nullptr) return;
std::string strFps = std::to_string((int32_t)(1.0f / delta));
std::string strTick = std::to_string((int32_t)(delta * 1000.0f));
label->text = strFps + "FPS (" + strTick + "ms)";
assertUnreachable();// Needs updating to new UI Label
// label->text = strFps + "FPS (" + strTick + "ms)";
}, this->item->scene->eventSceneUnpausedUpdate);
}

View File

@ -4,13 +4,13 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/components/ui/UILabel.hpp"
#include "scene/components/ui/text/UILabelNew.hpp"
namespace Dawn {
class FPSLabelComponent : public SceneItemComponent {
public:
/* @optional */
UILabel *label = nullptr;
UILabelNew *label = nullptr;
FPSLabelComponent(SceneItem *item);
void onStart() override;

View File

@ -9,10 +9,9 @@ target_sources(${DAWN_TARGET_NAME}
UICanvas.cpp
UIComponent.cpp
UIComponentRenderable.cpp
UILabel.cpp
UIImage.cpp
UIBorder.cpp
UILabelNew.cpp
)
add_subdirectory(menu)
add_subdirectory(menu)
add_subdirectory(text)

View File

@ -1,121 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UILabel.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
UILabel::UILabel(SceneItem *item) :
UIComponentRenderable(item),
text(""),
fontSize(10.0f),
font(&item->scene->game->renderManager.defaultFont),
maxWidth(UI_LABEL_MAX_WIDTH_ALIGN),
startQuad(0),
quadCount(-1)
{
}
bool_t UILabel::hasText() {
return (
this->font != nullptr &&
this->font->isReady() &&
((std::string)this->text).size() > 0
);
}
void UILabel::updateMesh() {
if(!this->needsRebuffering) return;
if(!this->hasText()) return;
float_t width = this->maxWidth;
assertTrue(
width == UI_LABEL_MAX_WIDTH_NONE ||
width == UI_LABEL_MAX_WIDTH_ALIGN ||
width > 0
);
if(width == UI_LABEL_MAX_WIDTH_ALIGN) {
auto dimensional = this->getParentDimensional();
auto align = (glm::vec4)this->alignment;
float_t x;
UIComponent::calculateDimensions(
this->alignX,
this->alignUnitLeft,
this->alignUnitRight,
&x,
&width,
dimensional->getWidth(),
0,
glm::vec2(align[0], align[2])
);
}
this->font->buffer(
text,
fontSize,
width,
&this->mesh,
&this->measure
);
this->needsRebuffering = false;
this->eventFontRebuffered.invoke();
}
std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
if(!this->hasText()) return {};
this->updateMesh();
struct ShaderPassItem item;
auto shader = getGame()->renderManager.uiShader;
item.shader = shader;
item.colorValues[shader->paramColor] = textColor;
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
item.matrixValues[shader->paramModel] = this->transform->getWorldTransform();
item.textureSlots[0] = this->font->getTexture();
item.textureValues[shader->paramTexture] = 0;
item.start = this->startQuad * QUAD_INDICE_COUNT;
item.count = this->quadCount == -1 ? -1 : this->quadCount * QUAD_INDICE_COUNT;
item.w = this->transform->getWorldPosition().z;
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
item.mesh = &mesh;
return { item };
}
float_t UILabel::getContentWidth() {
if(!this->hasText()) return 0;
this->updateMesh();
return this->measure.getWidth();
}
float_t UILabel::getContentHeight() {
if(!this->hasText()) return 0;
this->updateMesh();
return this->measure.getHeight();
}
void UILabel::onStart() {
UIComponent::onStart();
useEffect([&]{
alignmentNeedsUpdating = true;
}, { &fontSize, &font, &text, &maxWidth, &startQuad, &quadCount });
useEffect([&]{
eventTextChanged.invoke();
}, text);
useEffect([&]{
needsRebuffering = true;
}, alignmentNeedsUpdating);
useEvent([&]{
needsRebuffering = true;
}, eventAlignmentUpdated);
}

View File

@ -1,59 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "UIComponentRenderable.hpp"
#include "display/font/Font.hpp"
#define UI_LABEL_MAX_WIDTH_NONE -1
#define UI_LABEL_MAX_WIDTH_ALIGN 0
namespace Dawn {
class UILabel : public UIComponentRenderable {
private:
bool_t needsRebuffering = true;
Mesh mesh;
/**
* Returns true if the label contains renderable text.
*
* @return True if the label has text, otherwise false.
*/
bool_t hasText();
/**
* Internally performs the mesh update.
*/
void updateMesh();
public:
//@optional
StateProperty<std::string> text;
// @optional
StateProperty<float_t> fontSize;
/* @optional */
StateProperty<Font*> font;
/* @optional */
StateProperty<float_t> maxWidth;
/* @optional */
struct Color textColor = COLOR_WHITE;
// @optional
StateProperty<int32_t> startQuad;
// @optional
StateProperty<int32_t> quadCount;
StateEvent<> eventFontRebuffered;
StateEvent<> eventTextChanged;
struct FontMeasure measure;
UILabel(SceneItem *item);
float_t getContentWidth() override;
float_t getContentHeight() override;
std::vector<struct ShaderPassItem> getUIRenderPasses() override;
void onStart() override;
};
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
UILabelNew.cpp
)

View File

@ -21,10 +21,11 @@ namespace Dawn {
std::string text;
struct UILabelStyle style;
// Part index
// Quad start
// position
// size
// Part index?
// Quad start?
// quad count?
// position?
// size?
// some kind of custom data e.g. wobble or shake?
usagelockid_t lockId = -1;

View File

@ -7,7 +7,7 @@
#include "scene/Scene.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "scene/components/display/Camera.hpp"
#include "scene/components/ui/UILabelNew.hpp"
#include "scene/components/ui/text/UILabelNew.hpp"
namespace Dawn {
class HelloWorldScene : public Scene {