From 71cda1b644bd8b4e3c41e65e006cf842b2f03b6e Mon Sep 17 00:00:00 2001 From: hop311 Date: Fri, 13 Sep 2024 00:14:01 +0100 Subject: Modifier and rule set tooltips (WIP) --- extension/deps/openvic-simulation | 2 +- .../openvic-extension/singletons/MenuSingleton.cpp | 97 +++++++++++++++++++++- .../openvic-extension/singletons/MenuSingleton.hpp | 5 ++ 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation index 7a9206e..81e00e3 160000 --- a/extension/deps/openvic-simulation +++ b/extension/deps/openvic-simulation @@ -1 +1 @@ -Subproject commit 7a9206e3869fbb659d296b854c90f5c81755a5ca +Subproject commit 81e00e3291834dbae6e70224651bf66198ba154e diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index 5074507..1aee163 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUINode.hpp" @@ -106,6 +107,98 @@ String MenuSingleton::get_country_adjective(CountryInstance const& country) cons return tr(Utilities::std_to_godot_string(StringUtils::append_string_views(country.get_identifier(), adjective))); } +String MenuSingleton::make_modifier_effects_tooltip(ModifierValue const& modifier) const { + if (modifier.empty()) { + return {}; + } + + String result; + + for (auto const& [effect, value] : modifier.get_values()) { + if (!result.is_empty()) { + result += "\n"; + } + + // TODO - handle special modifier effects (e.g. unit type scoped effects) + + static const String modifier_prefix = "MODIFIER_"; + + result += tr(modifier_prefix + Utilities::std_to_godot_string(effect->get_identifier()).to_upper()); + + static const String post_name_text = ": " + GUILabel::get_colour_marker(); + result += post_name_text; + + if (value == 0) { + result += "Y"; + } else if (effect->is_positive_good() == value > 0) { + result += "G"; + } else { + result += "R"; + } + + if (value >= 0) { + result += "+"; + } + + static constexpr int32_t DECIMAL_PLACES = 2; + + using enum ModifierEffect::format_t; + + switch (effect->get_format()) { + case PROPORTION_DECIMAL: + result += GUINode::float_to_string_dp((value * 100).to_float(), DECIMAL_PLACES) + "%"; + break; + case PERCENTAGE_DECIMAL: + result += GUINode::float_to_string_dp(value.to_float(), DECIMAL_PLACES) + "%"; + break; + case INT: + result += String::num_int64(value.to_int64_t()); + break; + case RAW_DECIMAL: [[fallthrough]]; + default: // Use raw decimal as fallback format + result += GUINode::float_to_string_dp(value.to_float(), DECIMAL_PLACES); + break; + } + + static const String end_text = GUILabel::get_colour_marker() + String { "!" }; + result += end_text; + } + + return result; +} + +String MenuSingleton::make_rules_tooltip(RuleSet const& rules) const { + if (rules.empty()) { + return {}; + } + + static const StringName yes_key = "YES"; + static const StringName no_key = "NO"; + + static const String start_text = ": " + GUILabel::get_colour_marker(); + static const String end_text = GUILabel::get_colour_marker() + String { "!" }; + + const String enabled_text = start_text + String { "G" } + tr(yes_key) + end_text; + const String disabled_text = start_text + String { "R" } + tr(no_key) + end_text; + + String result; + + for (auto const& [rule_group, rule_map] : rules.get_rule_groups()) { + for (auto const& [rule, enabled] : rule_map) { + if (!result.is_empty()) { + result += "\n"; + } + + static const String rule_prefix = "RULE_"; + + result += tr(rule_prefix + Utilities::std_to_godot_string(rule->get_identifier()).to_upper()) + + (enabled ? enabled_text : disabled_text); + } + } + + return result; +} + void MenuSingleton::_bind_methods() { OV_BIND_SMETHOD(get_tooltip_separator); OV_BIND_METHOD(MenuSingleton::get_country_name_from_identifier, { "country_identifier" }); @@ -611,7 +704,9 @@ Dictionary MenuSingleton::get_topbar_info() const { // TODO - colonial power info ret[colonial_power_available_key] = 0; ret[colonial_power_max_key] = 0; - ret[colonial_power_tooltip_key] = String {}; + ret[colonial_power_tooltip_key] = + make_rules_tooltip(country->get_rule_set()) + get_tooltip_separator() + + make_modifier_effects_tooltip(country->get_base_modifier_sum()); // Production diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 3f07583..97a6956 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -11,6 +11,8 @@ namespace OpenVic { struct CountryInstance; struct State; struct ProvinceInstance; + struct ModifierValue; + struct RuleSet; class MenuSingleton : public godot::Object { GDCLASS(MenuSingleton, godot::Object) @@ -105,6 +107,9 @@ namespace OpenVic { godot::String get_country_name(CountryInstance const& country) const; godot::String get_country_adjective(CountryInstance const& country) const; + godot::String make_modifier_effects_tooltip(ModifierValue const& modifier) const; + godot::String make_rules_tooltip(RuleSet const& rules) const; + protected: static void _bind_methods(); -- cgit v1.2.3-56-ga3b1