Working on removing ui label

This commit is contained in:
2023-06-12 10:09:45 -07:00
parent c7d5377b9c
commit 29bb22b5d0
14 changed files with 102 additions and 86 deletions

View File

@ -14,7 +14,7 @@
/> />
<child ref="test123"> <child ref="test123">
<UILabel <!-- <UILabel
text="This is the text box." text="This is the text box."
font="font_main" font="font_main"
fontSize="48" fontSize="48"
@ -22,8 +22,8 @@
alignX="UI_COMPONENT_ALIGN_MIDDLE" alignX="UI_COMPONENT_ALIGN_MIDDLE"
alignY="UI_COMPONENT_ALIGN_MIDDLE" alignY="UI_COMPONENT_ALIGN_MIDDLE"
ref="uiLabel" ref="uiLabel"
/> /> -->
</child> </child>
<VNTextboxScroller ref="textboxScroller" label="uiLabel" /> <!-- <VNTextboxScroller ref="textboxScroller" label="uiLabel" /> -->
</prefab> </prefab>

View File

@ -1,4 +1,4 @@
<prefab name="FPSLabel" type="ui/debug"> <prefab name="FPSLabel" type="ui/debug">
<UILabel ref="label" text="Hello World" /> <!-- <UILabel ref="label" text="Hello World" /> -->
<FPSLabelComponent label="label" /> <!-- <FPSLabelComponent label="label" /> -->
</prefab> </prefab>

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@ void FPSLabelComponent::onStart() {
if(this->label == nullptr) return; if(this->label == nullptr) return;
std::string strFps = std::to_string((int32_t)(1.0f / delta)); std::string strFps = std::to_string((int32_t)(1.0f / delta));
std::string strTick = std::to_string((int32_t)(delta * 1000.0f)); 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); }, this->item->scene->eventSceneUnpausedUpdate);
} }

View File

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

View File

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

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; std::string text;
struct UILabelStyle style; struct UILabelStyle style;
// Part index // Part index?
// Quad start // Quad start?
// position // quad count?
// size // position?
// size?
// some kind of custom data e.g. wobble or shake? // some kind of custom data e.g. wobble or shake?
usagelockid_t lockId = -1; usagelockid_t lockId = -1;

View File

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