Make localization parameters better, and add a single frame animation helper
This commit is contained in:
+6
-15
@@ -68,40 +68,30 @@ struct EText : Element {
|
||||
Localization::Key key;
|
||||
uint64_t font_id = UINT64_MAX;
|
||||
Color color = {255, 255, 255};
|
||||
mrb_value params = mrb_nil_value();
|
||||
std::unordered_map<std::string, std::string> params;
|
||||
|
||||
~EText() {
|
||||
if (text_id != UINT64_MAX)
|
||||
text_pool.release(text_id);
|
||||
if (font_id != UINT64_MAX)
|
||||
font_pool.release(font_id);
|
||||
if (!mrb_nil_p(params))
|
||||
mrb_gc_unregister(Ruby::mrb, params);
|
||||
}
|
||||
|
||||
EText(Localization::Key key, uint64_t font_id, Color color, mrb_value params)
|
||||
: Element(Type::TEXT), key(key), font_id(font_id), color(color), params(params) {
|
||||
mrb_gc_register(Ruby::mrb, params);
|
||||
font_pool.use(font_id);
|
||||
}
|
||||
|
||||
void reload_params() {
|
||||
// Force re-render by resetting last_key (without affecting this frame)
|
||||
// this can be changed to use a dirty flag or version counter if needed
|
||||
last_key = UINT16_MAX;
|
||||
}
|
||||
EText(Localization::Key key, uint64_t font_id, Color color, std::unordered_map<std::string, std::string> params)
|
||||
: Element(Type::TEXT), key(key), font_id(font_id), color(color), params(params) {}
|
||||
|
||||
Vec2<float> size() override {
|
||||
if (text_id == UINT64_MAX)
|
||||
return {0, 0};
|
||||
return window.get_text_size(text_id);
|
||||
};
|
||||
}
|
||||
|
||||
void render(Window &window, uint64_t) override {
|
||||
if (
|
||||
last_language != Localization::current_language
|
||||
|| last_key != key || text_id == UINT64_MAX
|
||||
|| last_color != color
|
||||
|| params_changed
|
||||
) {
|
||||
std::string localized_str = Localization::get(Ruby::mrb, key, params);
|
||||
if (text_id != UINT64_MAX)
|
||||
@@ -119,6 +109,7 @@ private:
|
||||
Color last_color = color;
|
||||
Localization::LanguageCode last_language = UINT32_MAX;
|
||||
Localization::Key last_key = UINT16_MAX;
|
||||
bool params_changed = true;
|
||||
};
|
||||
|
||||
struct ERect : Element {
|
||||
|
||||
Reference in New Issue
Block a user