aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons/MenuSingleton.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-06-08 16:54:37 +0200
committer GitHub <noreply@github.com>2024-06-08 16:54:37 +0200
commit3dd525092e3a6027f20f0a1afdf8e871a9eecd34 (patch)
treeaea64483ffb003d74c0671f9f2a4db878a3b8cb3 /extension/src/openvic-extension/singletons/MenuSingleton.cpp
parentfb74bc86d194b50cb3277c7f367a5e5a0316c948 (diff)
parent0ba36e6762615d17605a573a036aff5bf84dfc95 (diff)
Merge pull request #232 from OpenVicProject/province-const-mutable
Province const/mutable + proper State names
Diffstat (limited to 'extension/src/openvic-extension/singletons/MenuSingleton.cpp')
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 993549c..b304b69 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -5,6 +5,7 @@
#include <openvic-simulation/GameManager.hpp>
#include "openvic-extension/classes/GFXPieChartTexture.hpp"
+#include "openvic-extension/classes/GUINode.hpp"
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/utility/ClassBindings.hpp"
#include "openvic-extension/utility/Utilities.hpp"
@@ -28,6 +29,44 @@ StringName const& MenuSingleton::_signal_population_menu_pops_changed() {
return signal_population_menu_pops_changed;
}
+String MenuSingleton::get_state_name(State const& state) const {
+ StateSet const& state_set = state.get_state_set();
+
+ const String region_identifier = std_view_to_godot_string(state_set.get_region().get_identifier());
+
+ String name = tr(region_identifier);
+
+ const bool named = name != region_identifier;
+ const bool owned = state.get_owner() != nullptr;
+ const bool split = state_set.get_state_count() > 1;
+
+ if (!named) {
+ // Capital province name
+ name = tr(GUINode::format_province_name(std_view_to_godot_string(state.get_capital()->get_identifier())));
+
+ if (!owned) {
+ static const StringName region_key = "REGION_NAME";
+ static const String name_key = "$NAME$";
+
+ String region = tr(region_key);
+
+ if (region != region_key) {
+ // CAPITAL Region
+ return region.replace(name_key, name);
+ }
+ }
+ }
+
+ if (owned && split) {
+ // COUNTRY STATE/CAPITAL
+ return tr(std_view_to_godot_string(StringUtils::append_string_views(state.get_owner()->get_identifier(), "_ADJ")))
+ + " " + name;
+ }
+
+ // STATE/CAPITAL
+ return name;
+}
+
void MenuSingleton::_bind_methods() {
/* PROVINCE OVERVIEW PANEL */
OV_BIND_METHOD(MenuSingleton::get_province_info_from_index, { "index" });
@@ -132,7 +171,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
ERR_FAIL_NULL_V(game_manager, {});
static const StringName province_info_province_key = "province";
- static const StringName province_info_region_key = "region";
+ static const StringName province_info_state_key = "state";
static const StringName province_info_slave_status_key = "slave_status";
static const StringName province_info_colony_status_key = "colony_status";
static const StringName province_info_terrain_type_key = "terrain_type";
@@ -149,7 +188,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
static const StringName province_info_cores_key = "cores";
static const StringName province_info_buildings_key = "buildings";
- Province const* province = game_manager->get_map().get_province_by_index(index);
+ ProvinceInstance const* province = game_manager->get_map().get_province_instance_by_index(index);
if (province == nullptr) {
return {};
}
@@ -157,9 +196,9 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const {
ret[province_info_province_key] = std_view_to_godot_string(province->get_identifier());
- Region const* region = province->get_region();
- if (region != nullptr) {
- ret[province_info_region_key] = std_view_to_godot_string(region->get_identifier());
+ State const* state = province->get_state();
+ if (state != nullptr) {
+ ret[province_info_state_key] = get_state_name(*state);
}
ret[province_info_slave_status_key] = province->get_slave();