diff options
author | hop311 <hop3114@gmail.com> | 2024-06-04 00:54:38 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-06-06 21:30:56 +0200 |
commit | 0ba36e6762615d17605a573a036aff5bf84dfc95 (patch) | |
tree | aea64483ffb003d74c0671f9f2a4db878a3b8cb3 | |
parent | fb74bc86d194b50cb3277c7f367a5e5a0316c948 (diff) |
Province const/mutable + proper State namesprovince-const-mutable
10 files changed, 101 insertions, 46 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject e286cfef29d7c431ba33cd77283e838e6fba05d +Subproject f5d173e88a49a1a9556860063aef1aa287925cf diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 9f080b5..7576d0c 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -124,10 +124,11 @@ Error GameSingleton::setup_game(int32_t bookmark_index) { ERR_FAIL_NULL_V_MSG(bookmark, FAILED, vformat("Failed to get bookmark with index: %d", bookmark_index)); bool ret = game_manager.load_bookmark(bookmark); - for (Province& province : game_manager.get_map().get_provinces()) { + for (ProvinceInstance& province : game_manager.get_map().get_province_instances()) { province.set_crime( game_manager.get_crime_manager().get_crime_modifier_by_index( - (province.get_index() - 1) % game_manager.get_crime_manager().get_crime_modifier_count() + (province.get_province_definition().get_index() - 1) + % game_manager.get_crime_manager().get_crime_modifier_count() ) ); } @@ -215,15 +216,15 @@ Ref<ImageTexture> GameSingleton::get_province_colour_texture() const { Error GameSingleton::_update_colour_image() { Map const& map = game_manager.get_map(); ERR_FAIL_COND_V_MSG( - !map.provinces_are_locked(), FAILED, "Cannot generate province colour image before provinces are locked!" + !map.province_definitions_are_locked(), FAILED, "Cannot generate province colour image before provinces are locked!" ); /* We reshape the list of colours into a square, as each texture dimensions cannot exceed 16384. */ - static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(Province::index_t) * CHAR_BIT / 2); + static constexpr int32_t PROVINCE_INDEX_SQRT = 1 << (sizeof(ProvinceDefinition::index_t) * CHAR_BIT / 2); static constexpr int32_t colour_image_width = PROVINCE_INDEX_SQRT * sizeof(Mapmode::base_stripe_t) / sizeof(colour_argb_t); /* Province count + null province, rounded up to next multiple of PROVINCE_INDEX_SQRT. * Rearranged from: (map.get_province_count() + 1) + (PROVINCE_INDEX_SQRT - 1) */ - const int32_t colour_image_height = (map.get_province_count() + PROVINCE_INDEX_SQRT) / PROVINCE_INDEX_SQRT; + const int32_t colour_image_height = (map.get_province_definition_count() + PROVINCE_INDEX_SQRT) / PROVINCE_INDEX_SQRT; static PackedByteArray colour_data_array; const int64_t colour_data_array_size = colour_image_width * colour_image_height * sizeof(colour_argb_t); @@ -258,10 +259,10 @@ TypedArray<Dictionary> GameSingleton::get_province_names() const { static const StringName scale_key = "scale"; TypedArray<Dictionary> ret; - ERR_FAIL_COND_V(ret.resize(game_manager.get_map().get_province_count()) != OK, {}); + ERR_FAIL_COND_V(ret.resize(game_manager.get_map().get_province_definition_count()) != OK, {}); - for (int32_t index = 0; index < game_manager.get_map().get_province_count(); ++index) { - Province const& province = game_manager.get_map().get_provinces()[index]; + for (int32_t index = 0; index < game_manager.get_map().get_province_definition_count(); ++index) { + ProvinceDefinition const& province = game_manager.get_map().get_province_definitions()[index]; Dictionary province_dict; @@ -323,7 +324,7 @@ void GameSingleton::set_selected_province(int32_t index) { } void GameSingleton::unset_selected_province() { - set_selected_province(Province::NULL_INDEX); + set_selected_province(ProvinceDefinition::NULL_INDEX); } void GameSingleton::try_tick() { 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(); diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index fd1b6c5..efce81f 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -7,7 +7,7 @@ namespace OpenVic { struct GameManager; - struct Region; + struct State; class MenuSingleton : public godot::Object { GDCLASS(MenuSingleton, godot::Object) @@ -28,13 +28,12 @@ namespace OpenVic { }; struct state_entry_t { - // TODO - change to State - Region const& state; + State const& state; bool selected = true, expanded = false; }; struct province_entry_t { - Province const& province; + ProvinceInstance const& province; bool selected = true; }; @@ -80,6 +79,8 @@ namespace OpenVic { /* Emitted when the selected/filtered collection of pops changes. */ static godot::StringName const& _signal_population_menu_pops_changed(); + godot::String get_state_name(State const& state) const; + protected: static void _bind_methods(); diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index 88a69c9..152a7f4 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -288,7 +288,8 @@ bool ModelSingleton::add_unit_dict(ordered_set<T*> const& units, TypedArray<Dict dict[flag_floating_key] = true; } - dict[position_key] = game_singleton->map_position_to_world_coords(unit.get_position()->get_unit_position()); + dict[position_key] = + game_singleton->map_position_to_world_coords(unit.get_position()->get_province_definition().get_unit_position()); if (display_unit_type->get_unit_category() != UnitType::unit_category_t::INFANTRY) { dict[rotation_key] = -0.25f * std::numbers::pi_v<float>; @@ -310,8 +311,8 @@ TypedArray<Dictionary> ModelSingleton::get_units() const { TypedArray<Dictionary> ret; - for (Province const& province : game_singleton->get_game_manager().get_map().get_provinces()) { - if (province.is_water()) { + for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map().get_province_instances()) { + if (province.get_province_definition().is_water()) { if (!add_unit_dict(province.get_navies(), ret)) { UtilityFunctions::push_error( "Error adding navy to province \"", std_view_to_godot_string(province.get_identifier()), "\"" @@ -363,8 +364,10 @@ Dictionary ModelSingleton::get_flag_model(bool floating) const { } bool ModelSingleton::add_building_dict( - BuildingInstance const& building, Province const& province, TypedArray<Dictionary>& building_array + BuildingInstance const& building, ProvinceInstance const& province, TypedArray<Dictionary>& building_array ) const { + ProvinceDefinition const& province_definition = province.get_province_definition(); + GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, false); @@ -379,7 +382,7 @@ bool ModelSingleton::add_building_dict( game_singleton->get_game_manager().get_economy_manager().get_building_type_manager().get_port_building_type() ) { /* Port */ - if (!province.has_port()) { + if (!province_definition.has_port()) { return true; } @@ -404,8 +407,8 @@ bool ModelSingleton::add_building_dict( return true; } - fvec2_t const* position_ptr = province.get_building_position(&building.get_building_type()); - const float rotation = province.get_building_rotation(&building.get_building_type()); + fvec2_t const* position_ptr = province_definition.get_building_position(&building.get_building_type()); + const float rotation = province_definition.get_building_rotation(&building.get_building_type()); const std::string actor_name = StringUtils::append_string_views("building_", building.get_identifier(), suffix); @@ -422,8 +425,9 @@ bool ModelSingleton::add_building_dict( dict[model_key] = make_model_dict(*actor); - dict[position_key] = - game_singleton->map_position_to_world_coords(position_ptr != nullptr ? *position_ptr : province.get_centre()); + dict[position_key] = game_singleton->map_position_to_world_coords( + position_ptr != nullptr ? *position_ptr : province_definition.get_centre() + ); if (rotation != 0.0f) { dict[rotation_key] = rotation; @@ -441,8 +445,8 @@ TypedArray<Dictionary> ModelSingleton::get_buildings() const { TypedArray<Dictionary> ret; - for (Province const& province : game_singleton->get_game_manager().get_map().get_provinces()) { - if (!province.is_water()) { + for (ProvinceInstance const& province : game_singleton->get_game_manager().get_map().get_province_instances()) { + if (!province.get_province_definition().is_water()) { for (BuildingInstance const& building : province.get_buildings()) { if (!add_building_dict(building, province, ret)) { UtilityFunctions::push_error( diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.hpp b/extension/src/openvic-extension/singletons/ModelSingleton.hpp index 17c2dd0..ad1a6d8 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.hpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.hpp @@ -6,6 +6,8 @@ #include <openvic-simulation/military/UnitInstance.hpp> namespace OpenVic { + struct BuildingInstance; + class ModelSingleton : public godot::Object { GDCLASS(ModelSingleton, godot::Object) @@ -33,7 +35,8 @@ namespace OpenVic { bool add_unit_dict(ordered_set<T*> const& units, godot::TypedArray<godot::Dictionary>& unit_array) const; bool add_building_dict( - BuildingInstance const& building, Province const& province, godot::TypedArray<godot::Dictionary>& building_array + BuildingInstance const& building, ProvinceInstance const& province, + godot::TypedArray<godot::Dictionary>& building_array ) const; public: diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 609142a..4aeedae 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -20,6 +20,9 @@ void MenuSingleton::_population_menu_update_provinces() { population_menu.province_list_entries.clear(); population_menu.visible_province_list_entries = 0; + Map const& map = game_manager->get_map(); + ERR_FAIL_COND(!map.province_instances_are_locked()); + for (Country const* country : { // Example country game_manager->get_country_manager().get_country_by_identifier("ENG") @@ -29,14 +32,15 @@ void MenuSingleton::_population_menu_update_provinces() { population_menu.province_list_entries.emplace_back(population_menu_t::country_entry_t { *country }); population_menu.visible_province_list_entries++; - // TODO - change to State - for (Region const& state : game_manager->get_map().get_regions()) { + for (StateSet const& state_set : map.get_state_manager().get_state_sets()) { + for (State const& state : state_set.get_states()) { - population_menu.province_list_entries.emplace_back(population_menu_t::state_entry_t { state }); - population_menu.visible_province_list_entries++; + population_menu.province_list_entries.emplace_back(population_menu_t::state_entry_t { state }); + population_menu.visible_province_list_entries++; - for (Province const* province : state.get_provinces()) { - population_menu.province_list_entries.emplace_back(population_menu_t::province_entry_t { *province }); + for (ProvinceInstance const* province : state.get_provinces()) { + population_menu.province_list_entries.emplace_back(population_menu_t::province_entry_t { *province }); + } } } } @@ -81,6 +85,8 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int struct entry_visitor_t { + MenuSingleton const& menu_singleton; + int32_t& start_counter; int32_t& count_counter; @@ -124,8 +130,8 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int state_dict[type_key] = population_menu_t::LIST_ENTRY_STATE; state_dict[index_key] = index; - state_dict[name_key] = std_view_to_godot_string(state_entry.state.get_identifier()); - state_dict[size_key] = state_entry.state.calculate_total_population(); + state_dict[name_key] = menu_singleton.get_state_name(state_entry.state); + state_dict[size_key] = state_entry.state.get_total_population(); state_dict[change_key] = 0; state_dict[selected_key] = state_entry.selected; state_dict[expanded_key] = state_entry.expanded; @@ -157,7 +163,7 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int return true; } - } entry_visitor { start, count, game_manager->get_map().get_total_map_population() }; + } entry_visitor { *this, start, count, game_manager->get_map().get_total_map_population() }; while (entry_visitor.index < population_menu.province_list_entries.size() && std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) { @@ -170,7 +176,7 @@ TypedArray<Dictionary> MenuSingleton::get_population_menu_province_list_rows(int Error MenuSingleton::population_menu_select_province_list_entry(int32_t select_index, bool set_scroll_index) { ERR_FAIL_INDEX_V(select_index, population_menu.province_list_entries.size(), FAILED); - struct entry_visitor { + struct entry_visitor_t { const int32_t _select_index; @@ -253,7 +259,7 @@ Error MenuSingleton::population_menu_select_province_list_entry(int32_t select_i Error MenuSingleton::population_menu_select_province(int32_t province_index) { ERR_FAIL_NULL_V(game_manager, FAILED); - ERR_FAIL_COND_V(province_index <= 0 || province_index > game_manager->get_map().get_province_count(), FAILED); + ERR_FAIL_COND_V(province_index <= 0 || province_index > game_manager->get_map().get_province_instance_count(), FAILED); struct entry_visitor_t { @@ -283,7 +289,7 @@ Error MenuSingleton::population_menu_select_province(int32_t province_index) { } bool operator()(population_menu_t::province_entry_t& province_entry) { - if (province_entry.province.get_index() == _province_index) { + if (province_entry.province.get_province_definition().get_index() == _province_index) { if (state_entry_to_expand >= 0) { ret &= menu_singleton.population_menu_toggle_expanded(state_entry_to_expand, false) == OK; diff --git a/game/assets/localisation/locales/en_GB/menus.csv b/game/assets/localisation/locales/en_GB/menus.csv index e488996..d5db730 100644 --- a/game/assets/localisation/locales/en_GB/menus.csv +++ b/game/assets/localisation/locales/en_GB/menus.csv @@ -133,7 +133,7 @@ VIC2_DIR_DIALOG_CANCEL;Cancel ;; Province Overview Panel PROV_MISSING;No Province -region_MISSING;No Region +state_MISSING;No State LIFE_RATING_TOOLTIP;Liferating: {life_rating} terrain_type_MISSING;No Terrain Type total_population_MISSING;No Population diff --git a/game/src/Game/GameSession/NationManagementScreen/PopulationMenu.gd b/game/src/Game/GameSession/NationManagementScreen/PopulationMenu.gd index 15f8dca..c3e091e 100644 --- a/game/src/Game/GameSession/NationManagementScreen/PopulationMenu.gd +++ b/game/src/Game/GameSession/NationManagementScreen/PopulationMenu.gd @@ -458,6 +458,7 @@ func _update_province_list(scroll_index : int = -1) -> void: GUINode.format_province_name(province_list_info[name_key]) if type == MenuSingleton.LIST_ENTRY_PROVINCE else province_list_info[name_key] ) + _province_list_name_labels[index].set_text_overrun_behavior(TextServer.OVERRUN_TRIM_ELLIPSIS) if _province_list_size_labels[index]: _province_list_size_labels[index].set_text(GUINode.int_to_string_suffixed(province_list_info[size_key])) diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel.gd index 7482673..5616927 100644 --- a/game/src/Game/GameSession/ProvinceOverviewPanel.gd +++ b/game/src/Game/GameSession/ProvinceOverviewPanel.gd @@ -242,7 +242,7 @@ func _set_core_flag(core_index : int, country : String) -> void: func _update_info() -> void: const _province_info_province_key : StringName = &"province" - const _province_info_region_key : StringName = &"region" + const _province_info_state_key : StringName = &"state" const _province_info_slave_status_key : StringName = &"slave_status" const _province_info_colony_status_key : StringName = &"colony_status" const _province_info_terrain_type_key : StringName = &"terrain_type" @@ -268,8 +268,8 @@ func _update_info() -> void: _province_name_label.text = GUINode.format_province_name(_province_info.get(_province_info_province_key, _missing_suffix)) if _region_name_label: - _region_name_label.text = _province_info.get(_province_info_region_key, - _province_info_region_key + _missing_suffix) + _region_name_label.text = _province_info.get(_province_info_state_key, + _province_info_state_key + _missing_suffix) if _slave_status_icon: _slave_status_icon.visible = _province_info.get(_province_info_slave_status_key, false) |