aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons/MenuSingleton.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-09-19 00:12:41 +0200
committer hop311 <hop3114@gmail.com>2024-09-19 00:12:41 +0200
commit258bcc535da4ae040da63006b4b95cf113dca9ed (patch)
treeb782ee665bf6fd6e054415f4a9c3360db331b829 /extension/src/openvic-extension/singletons/MenuSingleton.cpp
parentc26247464feabe0fbb9d6a8527b242d667faa066 (diff)
Add RuleSet and ModifierValue tooltip making functions
Diffstat (limited to 'extension/src/openvic-extension/singletons/MenuSingleton.cpp')
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 5074507..c4b704d 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,92 @@ 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";
+ }
+
+ result += tr(Utilities::std_to_godot_string(effect->get_localisation_key()));
+
+ 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";
+ }
+
+ result += tr(Utilities::std_to_godot_string(rule->get_localisation_key()))
+ + (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" });