aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/interface
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/interface')
-rw-r--r--src/openvic-simulation/interface/GFXSprite.cpp4
-rw-r--r--src/openvic-simulation/interface/GFXSprite.hpp7
-rw-r--r--src/openvic-simulation/interface/GUI.cpp6
-rw-r--r--src/openvic-simulation/interface/GUI.hpp3
-rw-r--r--src/openvic-simulation/interface/UI.cpp34
-rw-r--r--src/openvic-simulation/interface/UI.hpp3
6 files changed, 43 insertions, 14 deletions
diff --git a/src/openvic-simulation/interface/GFXSprite.cpp b/src/openvic-simulation/interface/GFXSprite.cpp
index 992a1ff..8acb8d4 100644
--- a/src/openvic-simulation/interface/GFXSprite.cpp
+++ b/src/openvic-simulation/interface/GFXSprite.cpp
@@ -6,9 +6,9 @@ using namespace OpenVic::NodeTools;
Font::Font(
std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname, std::string_view new_charset,
- uint32_t new_height
+ uint32_t new_height, colour_codes_t&& new_colour_codes
) : HasIdentifierAndAlphaColour { new_identifier, new_colour, false }, fontname { new_fontname }, charset { new_charset },
- height { new_height } {}
+ height { new_height }, colour_codes { std::move(new_colour_codes) } {}
node_callback_t Sprite::expect_sprites(length_callback_t length_callback, callback_t<std::unique_ptr<Sprite>&&> callback) {
return expect_dictionary_keys_and_length(
diff --git a/src/openvic-simulation/interface/GFXSprite.hpp b/src/openvic-simulation/interface/GFXSprite.hpp
index 49691c1..cee8c42 100644
--- a/src/openvic-simulation/interface/GFXSprite.hpp
+++ b/src/openvic-simulation/interface/GFXSprite.hpp
@@ -11,16 +11,19 @@ namespace OpenVic::GFX {
struct Font : HasIdentifierAndAlphaColour {
friend class OpenVic::UIManager;
+ using colour_codes_t = ordered_map<char, colour_t>;
+
private:
std::string PROPERTY(fontname);
std::string PROPERTY(charset);
uint32_t PROPERTY(height);
+ colour_codes_t PROPERTY(colour_codes);
- // TODO - colorcodes, effect
+ // TODO - effect
Font(
std::string_view new_identifier, colour_argb_t new_colour, std::string_view new_fontname,
- std::string_view new_charset, uint32_t new_height
+ std::string_view new_charset, uint32_t new_height, colour_codes_t&& new_colour_codes
);
public:
diff --git a/src/openvic-simulation/interface/GUI.cpp b/src/openvic-simulation/interface/GUI.cpp
index 87e3624..4f42b86 100644
--- a/src/openvic-simulation/interface/GUI.cpp
+++ b/src/openvic-simulation/interface/GUI.cpp
@@ -184,12 +184,10 @@ bool Text::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map, UIManag
"maxWidth", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.x)),
"maxHeight", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(max_size.y)),
"borderSize", ZERO_OR_ONE, expect_fvec2(assign_variable_callback(border_size)),
+ "textureFile", ZERO_OR_ONE, expect_string(assign_variable_callback_string(texture_file), true),
"fixedsize", ZERO_OR_ONE, success_callback,
- "allwaystransparent", ZERO_OR_ONE, success_callback,
-
- // Add warning about redundant key?
- "textureFile", ZERO_OR_ONE, success_callback
+ "allwaystransparent", ZERO_OR_ONE, success_callback
);
return ret;
}
diff --git a/src/openvic-simulation/interface/GUI.hpp b/src/openvic-simulation/interface/GUI.hpp
index 4e1b062..a86d432 100644
--- a/src/openvic-simulation/interface/GUI.hpp
+++ b/src/openvic-simulation/interface/GUI.hpp
@@ -203,8 +203,9 @@ namespace OpenVic::GUI {
GFX::Font const* PROPERTY(font);
fvec2_t PROPERTY(max_size); /* Defines keys: maxWidth, maxHeight */
fvec2_t PROPERTY(border_size);
+ std::string PROPERTY(texture_file);
- // TODO - fixedsize, textureFile
+ // TODO - fixedsize
protected:
Text();
diff --git a/src/openvic-simulation/interface/UI.cpp b/src/openvic-simulation/interface/UI.cpp
index ea871de..03166b1 100644
--- a/src/openvic-simulation/interface/UI.cpp
+++ b/src/openvic-simulation/interface/UI.cpp
@@ -8,7 +8,8 @@ using namespace OpenVic::GFX;
using namespace OpenVic::GUI;
bool UIManager::add_font(
- std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, uint32_t height
+ std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset, uint32_t height,
+ Font::colour_codes_t&& colour_codes
) {
if (identifier.empty()) {
Logger::error("Invalid font identifier - empty!");
@@ -22,23 +23,48 @@ bool UIManager::add_font(
Logger::error("Invalid fontname for font ", identifier, " - empty!");
return false;
}
- return fonts.add_item({ identifier, colour, fontname, charset, height }, duplicate_warning_callback);
+ const bool ret = fonts.add_item(
+ { identifier, colour, fontname, charset, height, std::move(colour_codes) },
+ duplicate_warning_callback
+ );
+
+ if (universal_colour_codes.empty() && ret) {
+ GFX::Font::colour_codes_t const& loaded_colour_codes = get_fonts().back().get_colour_codes();
+ if (!loaded_colour_codes.empty()) {
+ universal_colour_codes = loaded_colour_codes;
+ Logger::info("Loaded universal colour codes from font: \"", identifier, "\"");
+ }
+ }
+
+ return ret;
}
bool UIManager::_load_font(ast::NodeCPtr node) {
std::string_view identifier, fontname, charset;
colour_argb_t colour = colour_argb_t::null();
uint32_t height = 0;
+ Font::colour_codes_t colour_codes;
+
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,
+ "colorcodes", ZERO_OR_ONE, expect_dictionary(
+ [&colour_codes](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key.size() != 1) {
+ Logger::error("Invalid colour code key: \"", key, "\" (expected single character)");
+ return false;
+ }
+ return expect_colour(map_callback(colour_codes, key.front()))(value);
+ }
+ ),
"effect", ZERO_OR_ONE, success_callback
)(node);
- ret &= add_font(identifier, colour, fontname, charset, height);
+
+ ret &= add_font(identifier, colour, fontname, charset, height, std::move(colour_codes));
+
return ret;
}
diff --git a/src/openvic-simulation/interface/UI.hpp b/src/openvic-simulation/interface/UI.hpp
index 9aec96c..8ba7745 100644
--- a/src/openvic-simulation/interface/UI.hpp
+++ b/src/openvic-simulation/interface/UI.hpp
@@ -8,6 +8,7 @@ namespace OpenVic {
class UIManager {
NamedInstanceRegistry<GFX::Sprite> IDENTIFIER_REGISTRY(sprite);
IdentifierRegistry<GFX::Font> IDENTIFIER_REGISTRY(font);
+ GFX::Font::colour_codes_t PROPERTY(universal_colour_codes);
NamedInstanceRegistry<GFX::Object> IDENTIFIER_REGISTRY(object);
NamedInstanceRegistry<GUI::Scene, UIManager const&> IDENTIFIER_REGISTRY(scene);
@@ -18,7 +19,7 @@ namespace OpenVic {
public:
bool add_font(
std::string_view identifier, colour_argb_t colour, std::string_view fontname, std::string_view charset,
- uint32_t height
+ uint32_t height, GFX::Font::colour_codes_t&& colour_codes
);
void lock_gfx_registries();