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:
@ -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;
|
||||
|
@ -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
|
||||
);
|
||||
}
|
@ -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();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user