diff options
Diffstat (limited to 'extension')
6 files changed, 61 insertions, 26 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation -Subproject 8defcd5daa1acd2c61aa1cd0a26478d472fed9b +Subproject 7e84f23fe0690e6883ad9894b88a31951398122 diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index f258fe1..553d17c 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -33,6 +33,10 @@ StringName const& GameSingleton::_signal_clock_state_changed() { static const StringName signal_clock_state_changed = "clock_state_changed"; return signal_clock_state_changed; } +StringName const& GameSingleton::_signal_mapmode_changed() { + static const StringName signal_mapmode_changed = "mapmode_changed"; + return signal_mapmode_changed; +} void GameSingleton::_bind_methods() { OV_BIND_SMETHOD(setup_logger); @@ -63,7 +67,9 @@ void GameSingleton::_bind_methods() { OV_BIND_METHOD(GameSingleton::get_mapmode_count); OV_BIND_METHOD(GameSingleton::get_mapmode_identifier); - OV_BIND_METHOD(GameSingleton::set_mapmode, { "identifier" }); + OV_BIND_METHOD(GameSingleton::get_mapmode_localisation_key); + OV_BIND_METHOD(GameSingleton::get_current_mapmode_index); + OV_BIND_METHOD(GameSingleton::set_mapmode, { "index" }); OV_BIND_METHOD(GameSingleton::is_parchment_mapmode_allowed); OV_BIND_METHOD(GameSingleton::get_selected_province_index); OV_BIND_METHOD(GameSingleton::set_selected_province, { "index" }); @@ -76,6 +82,7 @@ void GameSingleton::_bind_methods() { ADD_SIGNAL(MethodInfo(_signal_gamestate_updated())); ADD_SIGNAL(MethodInfo(_signal_province_selected(), PropertyInfo(Variant::INT, "index"))); ADD_SIGNAL(MethodInfo(_signal_clock_state_changed())); + ADD_SIGNAL(MethodInfo(_signal_mapmode_changed(), PropertyInfo(Variant::INT, "index"))); } GameSingleton* GameSingleton::get_singleton() { @@ -95,9 +102,11 @@ void GameSingleton::_on_clock_state_changed() { * MAP-21, MAP-23, MAP-25, MAP-32, MAP-33, MAP-34 */ GameSingleton::GameSingleton() - : game_manager { + : game_manager { std::bind(&GameSingleton::_on_gamestate_updated, this), std::bind(&GameSingleton::_on_clock_state_changed, this) - }, viewed_country { nullptr } { + }, + viewed_country { nullptr }, + mapmode { &Mapmode::ERROR_MAPMODE } { ERR_FAIL_COND(singleton != nullptr); singleton = this; } @@ -249,7 +258,7 @@ Error GameSingleton::_update_colour_image() { InstanceManager const* instance_manager = get_instance_manager(); if (instance_manager != nullptr && !get_definition_manager().get_mapmode_manager().generate_mapmode_colours( - instance_manager->get_map_instance(), mapmode_index, colour_data_array.ptrw() + instance_manager->get_map_instance(), mapmode, colour_data_array.ptrw() )) { err = FAILED; } @@ -311,28 +320,37 @@ int32_t GameSingleton::get_mapmode_count() const { } String GameSingleton::get_mapmode_identifier(int32_t index) const { - Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); - if (mapmode != nullptr) { - return Utilities::std_to_godot_string(mapmode->get_identifier()); + Mapmode const* identifier_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + if (identifier_mapmode != nullptr) { + return Utilities::std_to_godot_string(identifier_mapmode->get_identifier()); + } + return String {}; +} + +String GameSingleton::get_mapmode_localisation_key(int32_t index) const { + Mapmode const* localisation_key_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + if (localisation_key_mapmode != nullptr) { + return Utilities::std_to_godot_string(localisation_key_mapmode->get_localisation_key()); } return String {}; } -Error GameSingleton::set_mapmode(String const& identifier) { - Mapmode const* mapmode = - get_definition_manager().get_mapmode_manager().get_mapmode_by_identifier(Utilities::godot_to_std_string(identifier)); - ERR_FAIL_NULL_V_MSG(mapmode, FAILED, vformat("Failed to find mapmode with identifier: %s", identifier)); - mapmode_index = mapmode->get_index(); - return _update_colour_image(); +int32_t GameSingleton::get_current_mapmode_index() const { + return mapmode->get_index(); +} + +Error GameSingleton::set_mapmode(int32_t index) { + Mapmode const* new_mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(index); + ERR_FAIL_NULL_V_MSG(new_mapmode, FAILED, vformat("Failed to find mapmode with index: %d", index)); + mapmode = new_mapmode; + const Error err = _update_colour_image(); + emit_signal(_signal_mapmode_changed(), mapmode->get_index()); + return err; } bool GameSingleton::is_parchment_mapmode_allowed() const { - // TODO - parchment bool per mapmode? - // TODO - move mapmode index to SIM/Map? - /* Disallows parchment mapmode for the cosmetic terrain mapmode */ - static constexpr std::string_view cosmetic_terrain_mapmode = "mapmode_terrain"; - Mapmode const* mapmode = get_definition_manager().get_mapmode_manager().get_mapmode_by_index(mapmode_index); - return mapmode != nullptr && mapmode->get_identifier() != cosmetic_terrain_mapmode; + /* Disallows parchment mapmode, e.g. for the cosmetic terrain mapmode */ + return mapmode->is_parchment_mapmode_allowed(); } int32_t GameSingleton::get_selected_province_index() const { diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index e737643..aa80141 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -21,7 +21,7 @@ namespace OpenVic { godot::Ref<godot::Texture2DArray> province_shape_texture; godot::Ref<godot::Image> province_colour_image; godot::Ref<godot::ImageTexture> province_colour_texture; - Mapmode::index_t mapmode_index = 0; + Mapmode const* mapmode; // This should never be null, if no mapmode is set then it'll point to Mapmode::ERROR_MAPMODE godot::Ref<godot::Texture2DArray> terrain_texture; static const godot::Vector2i PROPERTY(flag_dims); /* The size in pixels of an individual flag. */ @@ -34,6 +34,7 @@ namespace OpenVic { static godot::StringName const& _signal_gamestate_updated(); static godot::StringName const& _signal_province_selected(); static godot::StringName const& _signal_clock_state_changed(); + static godot::StringName const& _signal_mapmode_changed(); godot::Error _load_map_images(); godot::Error _load_terrain_variants(); @@ -120,7 +121,9 @@ namespace OpenVic { int32_t get_mapmode_count() const; godot::String get_mapmode_identifier(int32_t index) const; - godot::Error set_mapmode(godot::String const& identifier); + godot::String get_mapmode_localisation_key(int32_t index) const; + int32_t get_current_mapmode_index() const; + godot::Error set_mapmode(int32_t index); bool is_parchment_mapmode_allowed() const; int32_t get_selected_province_index() const; void set_selected_province(int32_t index); diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index 81582c2..e5554c3 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -482,7 +482,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_rgo_output_quantity_yesterday_key] = rgo.get_output_quantity_yesterday().to_float(); ret[province_info_rgo_revenue_yesterday_key] = rgo.get_revenue_yesterday().to_float(); ret[province_info_rgo_total_employees_key] = rgo.get_total_employees_count_cache(); - const Pop::pop_size_t max_employee_count = rgo.get_max_employee_count_cache(); + const pop_size_t max_employee_count = rgo.get_max_employee_count_cache(); if (max_employee_count == 0) { ret[province_info_rgo_employment_percentage_key] = 100.0f; } else { diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index 0dcc8ff..169d519 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -1,16 +1,26 @@ #pragma once +#include <variant> + #include <godot_cpp/classes/control.hpp> #include <godot_cpp/classes/image.hpp> -#include <openvic-simulation/pop/Pop.hpp> #include <openvic-simulation/types/IndexedMap.hpp> +#include <openvic-simulation/types/PopSize.hpp> #include <openvic-simulation/types/OrderedContainers.hpp> namespace OpenVic { struct CountryInstance; struct State; struct ProvinceInstance; + struct Pop; + struct PopType; + struct Religion; + struct Ideology; + struct Culture; + struct Issue; + struct CountryParty; + struct RebelType; struct ModifierValue; struct RuleSet; @@ -46,7 +56,7 @@ namespace OpenVic { int32_t visible_province_list_entries = 0; struct pop_filter_t { - Pop::pop_size_t count, promotion_demotion_change; + pop_size_t count, promotion_demotion_change; bool selected; }; ordered_map<PopType const*, pop_filter_t> pop_filters; diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 4bd537d..ecb35a8 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -482,14 +482,18 @@ static bool generate_window(generate_gui_args_t&& args) { GUI::Window const& window = static_cast<GUI::Window const&>(args.element); - // TODO - moveable, fullscreen, dontRender (disable visibility?) + // TODO - moveable, dontRender (disable visibility?) const String window_name = Utilities::std_to_godot_string(window.get_name()); Panel* godot_panel = nullptr; bool ret = new_control(godot_panel, window, args.name); ERR_FAIL_NULL_V_MSG(godot_panel, false, vformat("Failed to create Panel for GUI window %s", window_name)); - godot_panel->set_custom_minimum_size(Utilities::to_godot_fvec2(window.get_size())); + if (window.get_fullscreen()) { + godot_panel->set_anchors_preset(godot::Control::PRESET_FULL_RECT); + } else { + godot_panel->set_custom_minimum_size(Utilities::to_godot_fvec2(window.get_size())); + } Ref<StyleBoxEmpty> stylebox_empty; stylebox_empty.instantiate(); |