diff options
author | Hop311 <Hop3114@gmail.com> | 2024-02-05 20:38:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-05 20:38:23 +0100 |
commit | 6489da997cddb20667db0455fa4f38319dc7c883 (patch) | |
tree | 4e343f81b13f166ad4a478962348d4734ea7e11b /src/openvic-simulation/interface/UI.cpp | |
parent | 068c13ede817d17df599ca3481261bf17ed95604 (diff) | |
parent | 87fa1c74281a651b23089079c4c1621d4fb66d73 (diff) |
Merge pull request #145 from OpenVicProject/gui-loading
Added support for loading all gui files
Diffstat (limited to 'src/openvic-simulation/interface/UI.cpp')
-rw-r--r-- | src/openvic-simulation/interface/UI.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp index b977406..2646bb7 100644 --- a/src/openvic-simulation/interface/UI.cpp +++ b/src/openvic-simulation/interface/UI.cpp @@ -7,7 +7,9 @@ using namespace OpenVic::NodeTools; using namespace OpenVic::GFX; using namespace OpenVic::GUI; -bool UIManager::add_font(std::string_view identifier, colour_argb_t colour, std::string_view fontname) { +bool UIManager::add_font( + std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, uint32_t height +) { if (identifier.empty()) { Logger::error("Invalid font identifier - empty!"); return false; @@ -20,23 +22,39 @@ bool UIManager::add_font(std::string_view identifier, colour_argb_t colour, std: Logger::error("Invalid fontname for font ", identifier, " - empty!"); return false; } - return fonts.add_item({ identifier, colour, fontname }, duplicate_warning_callback); + return fonts.add_item({ identifier, colour, fontname, charset, height }, duplicate_warning_callback); } bool UIManager::_load_font(ast::NodeCPtr node) { - std::string_view identifier, fontname; + std::string_view identifier, fontname, charset; colour_argb_t colour = colour_argb_t::null(); + uint32_t height = 0; bool ret = expect_dictionary_keys( "name", ONE_EXACTLY, expect_string(assign_variable_callback(identifier)), "fontname", ONE_EXACTLY, expect_string(assign_variable_callback(fontname)), "color", ONE_EXACTLY, expect_colour_hex(assign_variable_callback(colour)), + "charset", ZERO_OR_ONE, expect_string(assign_variable_callback(charset)), + "height", ZERO_OR_ONE, expect_uint(assign_variable_callback(height)), "colorcodes", ZERO_OR_ONE, success_callback, "effect", ZERO_OR_ONE, success_callback )(node); - ret &= add_font(identifier, colour, fontname); + ret &= add_font(identifier, colour, fontname, charset, height); return ret; } +NodeCallback auto UIManager::_load_fonts(std::string_view font_key) { + return expect_dictionary_reserve_length( + fonts, + [this, font_key](std::string_view key, ast::NodeCPtr node) -> bool { + if (key != font_key) { + Logger::error("Invalid key: \"", key, "\" (expected ", font_key, ")"); + return false; + } + return _load_font(node); + } + ); +} + bool UIManager::load_gfx_file(ast::NodeCPtr root) { return expect_dictionary_keys( "spriteTypes", ZERO_OR_ONE, Sprite::expect_sprites( @@ -65,19 +83,10 @@ bool UIManager::load_gfx_file(ast::NodeCPtr root) { return sprites.add_item(std::move(sprite), duplicate_warning_callback); } ), - "bitmapfonts", ZERO_OR_ONE, expect_dictionary_reserve_length( - fonts, - [this](std::string_view key, ast::NodeCPtr node) -> bool { - if (key != "bitmapfont") { - Logger::error("Invalid bitmapfonts key: ", key); - return false; - } - return _load_font(node); - } - ), + "bitmapfonts", ZERO_OR_ONE, _load_fonts("bitmapfont"), + "fonts", ZERO_OR_ONE, _load_fonts("font"), "objectTypes", ZERO_OR_ONE, success_callback, - "lightTypes", ZERO_OR_ONE, success_callback, - "fonts", ZERO_OR_ONE, success_callback + "lightTypes", ZERO_OR_ONE, success_callback )(root); } |