Updating a few more things to state events, will probably stop here for now and revist the trailing things later.

This commit is contained in:
2023-03-01 14:16:50 -08:00
parent 8cc122d97c
commit d1892c3617
15 changed files with 397 additions and 405 deletions

View File

@ -9,6 +9,7 @@
#include "util/array.hpp"
#include "util/mathutils.hpp"
#include "display/shader/Shader.hpp"
#include "state/State.hpp"
namespace Dawn {
enum UIComponentAlign {
@ -20,7 +21,7 @@ namespace Dawn {
class UIGrid;
class UIComponent {
class UIComponent : public StateOwner {
protected:
// Calculated (and cached) values
float_t width = 1;

View File

@ -9,9 +9,12 @@
using namespace Dawn;
UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
getGame()->localeManager.eventLanguageUpdated.addListener(
this, &UILabel::onLanguageUpdated
);
evtLangUpdated = useEvent([&]{
this->needsRebuffering = true;
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size() > 0) {
this->hasText = true;
}
}, getGame()->localeManager.eventLanguageUpdated);
}
void UILabel::updatePositions() {
@ -104,17 +107,4 @@ void UILabel::setTransform(
) {
this->needsRebuffering = true;
UIComponent::setTransform(xAlign, yAlign, alignment, z);
}
void UILabel::onLanguageUpdated() {
this->needsRebuffering = true;
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){
this->hasText = true;
}
}
UILabel::~UILabel() {
getGame()->localeManager.eventLanguageUpdated.removeListener(
this, &UILabel::onLanguageUpdated
);
}

View File

@ -17,12 +17,10 @@ namespace Dawn {
std::string key = "";
float_t fontSize = 10.0f;
bool_t hasText = false;
std::function<void()> evtLangUpdated;
void updatePositions() override;
/** Event for when the language strings are updated */
void onLanguageUpdated();
std::vector<struct ShaderPassItem> getSelfPassItems(
glm::mat4 projection,
glm::mat4 view,
@ -79,7 +77,5 @@ namespace Dawn {
* @return Font size of the label.
*/
float_t getFontSize();
~UILabel();
};
}