aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp97
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp5
3 files changed, 101 insertions, 1 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 7a9206e3869fbb659d296b854c90f5c81755a5c
+Subproject 81e00e3291834dbae6e70224651bf66198ba154
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 <godot_cpp/variant/utility_functions.hpp>
#include <openvic-simulation/GameManager.hpp>
+#include <openvic-simulation/misc/Modifier.hpp>
#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();