From 31aed9a3e6e37df7409e83d0b1505c62f922fa83 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Mon, 16 Jun 2025 07:47:33 -0400 Subject: [PATCH] Add clang-format to pre-commit Add SConstruct and SCsub to ruff/ruff-format pre-commit Standardize header consistency: dependency headers should include with `<...>` local headers should include with `"..."` Standardize GDCLASS terminated with a semicolon Replace camelCase variable names with snake_case --- .pre-commit-config.yaml | 33 +- SConstruct | 28 +- extension/deps/SCsub | 3 + .../classes/GFXButtonStateTexture.cpp | 42 +- .../classes/GFXButtonStateTexture.hpp | 8 +- .../classes/GFXMaskedFlagTexture.cpp | 25 +- .../classes/GFXMaskedFlagTexture.hpp | 6 +- .../classes/GFXPieChartTexture.cpp | 13 +- .../classes/GFXPieChartTexture.hpp | 7 +- .../classes/GFXSpriteTexture.cpp | 5 +- .../classes/GFXSpriteTexture.hpp | 8 +- .../openvic-extension/classes/GUIButton.cpp | 2 +- .../openvic-extension/classes/GUIButton.hpp | 2 +- .../classes/GUIHasTooltip.hpp | 37 +- .../src/openvic-extension/classes/GUIIcon.hpp | 8 +- .../classes/GUIIconButton.hpp | 8 +- .../openvic-extension/classes/GUILabel.cpp | 59 +-- .../openvic-extension/classes/GUILabel.hpp | 20 +- .../classes/GUILineChart.cpp | 14 +- .../classes/GUILineChart.hpp | 2 +- .../openvic-extension/classes/GUIListBox.hpp | 2 +- .../classes/GUIMaskedFlag.hpp | 4 +- .../classes/GUIMaskedFlagButton.hpp | 4 +- .../src/openvic-extension/classes/GUINode.cpp | 9 +- .../src/openvic-extension/classes/GUINode.hpp | 10 +- .../classes/GUIOverlappingElementsBox.cpp | 46 +- .../classes/GUIOverlappingElementsBox.hpp | 4 +- .../openvic-extension/classes/GUIPieChart.hpp | 2 +- .../classes/GUIProgressBar.cpp | 28 +- .../classes/GUIProgressBar.hpp | 5 +- .../classes/GUIScrollbar.cpp | 151 +++---- .../classes/GUIScrollbar.hpp | 18 +- .../classes/GUITextureRect.hpp | 2 +- .../src/openvic-extension/classes/MapMesh.hpp | 2 +- .../classes/resources/StyleBoxWithSound.hpp | 2 +- .../singletons/AssetManager.cpp | 3 +- .../singletons/AssetManager.hpp | 20 +- .../openvic-extension/singletons/Checksum.hpp | 2 +- .../singletons/CursorSingleton.cpp | 421 ++++++++---------- .../singletons/CursorSingleton.hpp | 26 +- .../singletons/GameSingleton.cpp | 4 +- .../singletons/GameSingleton.hpp | 2 +- .../openvic-extension/singletons/GitInfo.hpp | 2 +- .../singletons/LoadLocalisation.cpp | 4 +- .../singletons/LoadLocalisation.hpp | 2 +- .../singletons/MapItemSingleton.cpp | 113 ++--- .../singletons/MapItemSingleton.hpp | 15 +- .../singletons/MenuSingleton.cpp | 410 ++++++++--------- .../singletons/MenuSingleton.hpp | 57 ++- .../singletons/MilitaryMenu.cpp | 217 ++++----- .../singletons/ModelSingleton.cpp | 54 +-- .../singletons/ModelSingleton.hpp | 4 +- .../singletons/PlayerSingleton.cpp | 29 +- .../singletons/PlayerSingleton.hpp | 2 +- .../singletons/PopulationMenu.cpp | 124 +++--- .../singletons/SoundSingleton.cpp | 26 +- .../singletons/SoundSingleton.hpp | 2 +- .../singletons/TradeMenu.cpp | 77 ++-- .../src/openvic-extension/utility/UITools.cpp | 68 ++- .../src/openvic-extension/utility/UITools.hpp | 4 +- .../openvic-extension/utility/Utilities.cpp | 16 +- .../openvic-extension/utility/Utilities.hpp | 6 +- 62 files changed, 1130 insertions(+), 1199 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c9bed878..29d25931 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,16 +2,16 @@ default_language_version: python: python3 repos: - # Waiting on Hop311 to approve clang-format - # - repo: https://github.com/pre-commit/mirrors-clang-format - # rev: v19.1.3 - # hooks: - # - id: clang-format - # files: \.(c|h|cpp|hpp|inc)$ - # types_or: [text] - # # exclude: | - # # (?x)^( - # # ) + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.3 + hooks: + - id: clang-format + files: \.(c|h|cpp|hpp|inc)$ + types_or: [text] + exclude: | + (?x)^( + extension/src/gen/.* + ) - repo: https://github.com/pocc/pre-commit-hooks rev: v1.3.5 @@ -25,19 +25,28 @@ repos: stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy` - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.3 + rev: v0.11.13 hooks: - id: ruff args: [--fix] + files: (\.py|SConstruct|SCsub)$ + exclude: | + (?x)^( + extension/doc_tools/make_rst.py| + extension/doc_tools/doc_status.py + ) + types_or: [text] - id: ruff-format + files: (\.py|SConstruct|SCsub)$ exclude: | (?x)^( extension/doc_tools/make_rst.py| extension/doc_tools/doc_status.py ) + types_or: [text] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.13.0 + rev: v1.14.1 hooks: - id: mypy files: \.py$ diff --git a/SConstruct b/SConstruct index 4d648f7c..1f694220 100644 --- a/SConstruct +++ b/SConstruct @@ -1,8 +1,6 @@ #!/usr/bin/env python import os -import platform -import sys import SCons @@ -21,7 +19,7 @@ env.FinalizeOptions() OLD_ARGS = SCons.Script.ARGUMENTS.copy() SCons.Script.ARGUMENTS["use_static_cpp"] = env["use_static_cpp"] SCons.Script.ARGUMENTS["disable_exceptions"] = env["disable_exceptions"] -SCons.Script.ARGUMENTS["compiledb_file"] = 'godot-cpp/compile_commands.json' +SCons.Script.ARGUMENTS["compiledb_file"] = "godot-cpp/compile_commands.json" godot_env = SConscript("godot-cpp/SConstruct") SCons.Script.ARGUMENTS = OLD_ARGS @@ -32,18 +30,21 @@ env.Prepend(LIBS=godot_env["LIBS"]) SConscript("extension/deps/SCsub", "env") + Default( env.CommandNoCache( "extension/src/gen/commit_info.gen.hpp", env.Value(env.get_git_info()), - env.Run(env.git_builder), name_prefix="game" + env.Run(env.git_builder), + name_prefix="game", ) ) Default( env.CommandNoCache( "extension/src/gen/license_info.gen.hpp", ["#COPYRIGHT", "#LICENSE.md"], - env.Run(env.license_builder), name_prefix="game" + env.Run(env.license_builder), + name_prefix="game", ) ) @@ -69,13 +70,15 @@ if env["target"] in ["editor", "template_debug"]: # Remove unassociated intermediate binary files if allowed, usually the result of a renamed or deleted source file if env["intermediate_delete"]: from glob import glob - def remove_extension(file : str): - if file.find(".") == -1: return file - return file[:file.rindex(".")] + + def remove_extension(file: str): + if file.find(".") == -1: + return file + return file[: file.rindex(".")] found_one = False for path in paths: - for obj_file in [file[:-len(".os")] for file in glob(path + "*.os", recursive=True)]: + for obj_file in [file[: -len(".os")] for file in glob(path + "*.os", recursive=True)]: found = False for source_file in sources: if remove_extension(str(source_file)) == obj_file: @@ -85,12 +88,13 @@ if env["intermediate_delete"]: if not found_one: found_one = True print("Unassociated intermediate files found...") - print("Removing "+obj_file+".os") - os.remove(obj_file+".os") + print("Removing " + obj_file + ".os") + os.remove(obj_file + ".os") if env["platform"] == "macos": library = env.SharedLibrary( - BINDIR + "/openvic/libopenvic.{}.{}.framework/libopenvic.{}.{}".format( + BINDIR + + "/openvic/libopenvic.{}.{}.framework/libopenvic.{}.{}".format( godot_env["platform"], godot_env["target"], godot_env["platform"], godot_env["target"] ), source=sources, diff --git a/extension/deps/SCsub b/extension/deps/SCsub index 6a7a48db..17797796 100644 --- a/extension/deps/SCsub +++ b/extension/deps/SCsub @@ -2,6 +2,7 @@ Import("env") + def build_openvic_simulation(env): ovsim_env = SConscript("openvic-simulation/SConstruct") env.Append(LIBPATH=ovsim_env.openvic_simulation["LIBPATH"]) @@ -9,11 +10,13 @@ def build_openvic_simulation(env): env.Append(CPPPATH=ovsim_env.openvic_simulation["INCPATH"]) env.openvic_simulation = ovsim_env.openvic_simulation + def build_gli(env): gli_includes = ["gli", "gli/external"] env.gli_loader = {} env.gli_loader["INCPATH"] = [env.Dir(p) for p in gli_includes] env.Append(CPPPATH=env.gli_loader["INCPATH"]) + build_openvic_simulation(env) build_gli(env) diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp index ab4d4b45..681aa1ec 100644 --- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp @@ -26,8 +26,7 @@ void GFXCorneredTileSupportingTexture::draw_rect_cornered(RID const& to_canvas_i if (rendering_server != nullptr) { const Size2 size = get_size(); rendering_server->canvas_item_add_nine_patch( - to_canvas_item, rect, { {}, size }, get_rid(), - cornered_tile_border_size, size - cornered_tile_border_size + to_canvas_item, rect, { {}, size }, get_rid(), cornered_tile_border_size, size - cornered_tile_border_size ); } } else { @@ -69,8 +68,7 @@ Ref GFXButtonStateTexture::make_gfx_button_state_texture( void GFXButtonStateTexture::set_button_state(ButtonState new_button_state) { ERR_FAIL_COND( - new_button_state != HOVER && new_button_state != PRESSED && - new_button_state != DISABLED && new_button_state != SELECTED + new_button_state != HOVER && new_button_state != PRESSED && new_button_state != DISABLED && new_button_state != SELECTED ); button_state = new_button_state; } @@ -82,9 +80,9 @@ Error GFXButtonStateTexture::generate_state_image( const Rect2i source_image_rect { {}, source_image->get_size() }; ERR_FAIL_COND_V(!region.has_area() || !source_image_rect.encloses(region), FAILED); /* Whether we've already set the ImageTexture to an image of the right dimensions and format, - * and so can update it without creating and setting a new image, or not. */ - bool can_update = state_image.is_valid() && state_image->get_size() == region.get_size() - && state_image->get_format() == source_image->get_format(); + * and so can update it without creating and setting a new image, or not. */ + bool can_update = state_image.is_valid() && state_image->get_size() == region.get_size() && + state_image->get_format() == source_image->get_format(); if (!can_update) { state_image = Image::create(region.size.width, region.size.height, false, source_image->get_format()); ERR_FAIL_NULL_V(state_image, FAILED); @@ -114,11 +112,14 @@ Error GFXButtonStateTexture::generate_state_image( return { std::max(colour.r - 0.3f, 0.0f), std::max(colour.g - 0.3f, 0.0f), std::max(colour.b - 0.3f, 0.0f), colour.a }; }; - const auto colour_func = - button_state == HOVER ? hover_colour : - button_state == PRESSED ? pressed_colour : - button_state == DISABLED ? disabled_colour : - selected_colour; + const auto colour_func = [&]() -> Color (*const)(const Color&) { + switch (button_state) { + case HOVER: return hover_colour; + case PRESSED: return pressed_colour; + case DISABLED: return disabled_colour; + default: return selected_colour; + } + }(); for (Vector2i point { 0, 0 }; point.y < state_image->get_height(); ++point.y) { for (point.x = 0; point.x < state_image->get_width(); ++point.x) { @@ -141,16 +142,11 @@ StringName const& GFXButtonStateTexture::button_state_to_name(ButtonState button static const StringName name_selected = "selected"; static const StringName name_error = "INVALID BUTTON STATE"; switch (button_state) { - case HOVER: - return name_hover; - case PRESSED: - return name_pressed; - case DISABLED: - return name_disabled; - case SELECTED: - return name_selected; - default: - return name_error; + case HOVER: return name_hover; + case PRESSED: return name_pressed; + case DISABLED: return name_disabled; + case SELECTED: return name_selected; + default: return name_error; } } @@ -181,7 +177,7 @@ void GFXButtonStateHavingTexture::_clear_button_states() { GFXButtonStateHavingTexture::GFXButtonStateHavingTexture() : button_state_textures {} {} -Ref GFXButtonStateHavingTexture::get_button_state_texture( +Ref GFXButtonStateHavingTexture::get_button_state_texture( // GFXButtonStateTexture::ButtonState button_state ) { const size_t button_state_index = button_state; diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp index 2a3a2841..0bb04cfa 100644 --- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.hpp @@ -7,7 +7,7 @@ namespace OpenVic { class GFXCorneredTileSupportingTexture : public godot::AtlasTexture { - GDCLASS(GFXCorneredTileSupportingTexture, godot::AtlasTexture) + GDCLASS(GFXCorneredTileSupportingTexture, godot::AtlasTexture); protected: godot::Vector2i PROPERTY_ACCESS(cornered_tile_border_size, protected); @@ -25,10 +25,10 @@ namespace OpenVic { }; class GFXButtonStateTexture : public GFXCorneredTileSupportingTexture { - GDCLASS(GFXButtonStateTexture, GFXCorneredTileSupportingTexture) + GDCLASS(GFXButtonStateTexture, GFXCorneredTileSupportingTexture); public: - enum ButtonState { + enum ButtonState { // HOVER, PRESSED, DISABLED, @@ -68,7 +68,7 @@ namespace OpenVic { }; class GFXButtonStateHavingTexture : public GFXCorneredTileSupportingTexture { - GDCLASS(GFXButtonStateHavingTexture, GFXCorneredTileSupportingTexture) + GDCLASS(GFXButtonStateHavingTexture, GFXCorneredTileSupportingTexture); std::array, GFXButtonStateTexture::BUTTON_STATE_COUNT> button_state_textures; diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp index b490a92a..ef54dd1c 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp @@ -13,12 +13,11 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { ERR_FAIL_NULL_V(overlay_image, FAILED); /* Whether we've already set the ImageTexture to an image of the right dimensions and format, * and so can update it without creating and setting a new image, or not. */ - bool can_update = button_image.is_valid() && button_image->get_size() == overlay_image->get_size() - && button_image->get_format() == overlay_image->get_format(); + bool can_update = button_image.is_valid() && button_image->get_size() == overlay_image->get_size() && + button_image->get_format() == overlay_image->get_format(); if (!can_update) { - button_image = Image::create( - overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format() - ); + button_image = + Image::create(overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format()); ERR_FAIL_NULL_V(button_image, FAILED); } @@ -33,10 +32,9 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { if (mask_image.is_valid() && flag_image.is_valid() && flag_image_rect.has_area()) { const Vector2i centre_translation = (mask_image->get_size() - button_image->get_size()) / 2; - for ( - Vector2i combined_image_point { 0, 0 }; - combined_image_point.y < button_image->get_height(); - ++combined_image_point.y + for (Vector2i combined_image_point { 0, 0 }; // + combined_image_point.y < button_image->get_height(); // + ++combined_image_point.y // ) { for (combined_image_point.x = 0; combined_image_point.x < button_image->get_width(); ++combined_image_point.x) { @@ -46,10 +44,8 @@ Error GFXMaskedFlagTexture::_generate_combined_image() { // Translate to mask_image coordinates, keeping the centres of each image aligned. const Vector2i mask_image_point = combined_image_point + centre_translation; - if ( - 0 <= mask_image_point.x && mask_image_point.x < mask_image->get_width() && - 0 <= mask_image_point.y && mask_image_point.y < mask_image->get_height() - ) { + if (0 <= mask_image_point.x && mask_image_point.x < mask_image->get_width() && 0 <= mask_image_point.y && + mask_image_point.y < mask_image->get_height()) { const Color mask_image_colour = mask_image->get_pixelv(mask_image_point); // Rescale from mask_image to flag_image coordinates. @@ -152,7 +148,8 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag_name(String const& gfx_masked_fl GFX::MaskedFlag const* new_masked_flag = sprite->cast_to(); ERR_FAIL_NULL_V_MSG( - new_masked_flag, FAILED, vformat( + new_masked_flag, FAILED, + vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_masked_flag_name, Utilities::std_to_godot_string(sprite->get_type()), Utilities::std_to_godot_string(GFX::MaskedFlag::get_type_static()) diff --git a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp index 2d5b4816..3c547ec0 100644 --- a/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXMaskedFlagTexture.hpp @@ -9,7 +9,7 @@ namespace OpenVic { struct CountryInstance; class GFXMaskedFlagTexture : public GFXButtonStateHavingTexture { - GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture) + GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture); GFX::MaskedFlag const* PROPERTY(gfx_masked_flag, nullptr); CountryDefinition const* PROPERTY(flag_country, nullptr); @@ -44,13 +44,13 @@ namespace OpenVic { godot::String get_gfx_masked_flag_name() const; /* Set flag_country and flag_type and update the combined image to use that flag, or no flag if it doesn't exist. */ - godot::Error set_flag_country_and_type( + godot::Error set_flag_country_and_type( // CountryDefinition const* new_flag_country, godot::StringName const& new_flag_type ); /* Look up the country with the specified identifier, then call set_flag_country_and_type with the country and * specified flag_type as arguments. */ - godot::Error set_flag_country_name_and_type( + godot::Error set_flag_country_name_and_type( // godot::String const& new_flag_country_name, godot::StringName const& new_flag_type ); diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp index 496145c9..72132471 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp @@ -68,8 +68,8 @@ Error GFXPieChartTexture::_generate_pie_chart_image() { /* Whether we've already set the ImageTexture to an image of the right dimensions, * and so can update it without creating and setting a new image, or not. */ - const bool can_update = pie_chart_image.is_valid() && pie_chart_image->get_width() == pie_chart_diameter - && pie_chart_image->get_height() == pie_chart_diameter; + const bool can_update = pie_chart_image.is_valid() && pie_chart_image->get_width() == pie_chart_diameter && + pie_chart_image->get_height() == pie_chart_diameter; if (!can_update) { pie_chart_image = Image::create(pie_chart_diameter, pie_chart_diameter, false, Image::FORMAT_RGBA8); @@ -99,7 +99,6 @@ Error GFXPieChartTexture::_generate_pie_chart_image() { } else { pie_chart_image->fill(background_colour); - } if (can_update) { @@ -123,7 +122,7 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli ); const slice_t slice { slice_dict[_slice_identifier_key()], slice_dict[_slice_tooltip_key()], slice_dict[_slice_colour_key()], - slice_dict[_slice_weight_key()] + slice_dict[_slice_weight_key()] // }; if (slice.weight > 0.0f) { total_weight += slice.weight; @@ -182,10 +181,10 @@ Error GFXPieChartTexture::set_gfx_pie_chart_name(String const& gfx_pie_chart_nam ERR_FAIL_NULL_V(sprite, FAILED); GFX::PieChart const* new_pie_chart = sprite->cast_to(); ERR_FAIL_NULL_V_MSG( - new_pie_chart, FAILED, vformat( + new_pie_chart, FAILED, + vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_pie_chart_name, - Utilities::std_to_godot_string(sprite->get_type()), - Utilities::std_to_godot_string(GFX::PieChart::get_type_static()) + Utilities::std_to_godot_string(sprite->get_type()), Utilities::std_to_godot_string(GFX::PieChart::get_type_static()) ) ); return set_gfx_pie_chart(new_pie_chart); diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp index 54058445..b05e99f2 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.hpp @@ -18,7 +18,7 @@ namespace OpenVic { && std::convertible_to; class GFXPieChartTexture : public godot::ImageTexture { - GDCLASS(GFXPieChartTexture, godot::ImageTexture) + GDCLASS(GFXPieChartTexture, godot::ImageTexture); public: using godot_pie_chart_data_t = godot::TypedArray; @@ -50,8 +50,9 @@ namespace OpenVic { Container const& distribution, NodeTools::Functor< // return tooltip; args: key const*, identifier, weight, total weight - godot::String, std::remove_pointer_t const*, godot::String const&, float, float - > auto make_tooltip, + godot::String, std::remove_pointer_t const*, godot::String const&, float, + float // + > auto make_tooltip, godot::String const& identifier_suffix = {} ) { using namespace godot; diff --git a/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp index 797d718a..9f33cdda 100644 --- a/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.cpp @@ -29,7 +29,7 @@ void GFXSpriteTexture::_bind_methods() { GFXSpriteTexture::GFXSpriteTexture() : icon_index { GFX::NO_FRAMES }, icon_count { GFX::NO_FRAMES } {} -Ref GFXSpriteTexture::make_gfx_sprite_texture( +Ref GFXSpriteTexture::make_gfx_sprite_texture( // GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon ) { Ref texture; @@ -96,7 +96,8 @@ Error GFXSpriteTexture::set_gfx_texture_sprite_name(String const& gfx_texture_sp ERR_FAIL_NULL_V(sprite, FAILED); GFX::TextureSprite const* new_texture_sprite = sprite->cast_to(); ERR_FAIL_NULL_V_MSG( - new_texture_sprite, FAILED, vformat( + new_texture_sprite, FAILED, + vformat( "Invalid type for GFX sprite %s: %s (expected %s)", gfx_texture_sprite_name, Utilities::std_to_godot_string(sprite->get_type()), Utilities::std_to_godot_string(GFX::TextureSprite::get_type_static()) diff --git a/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp index cd04113f..55a2ccbb 100644 --- a/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp +++ b/extension/src/openvic-extension/classes/GFXSpriteTexture.hpp @@ -8,7 +8,7 @@ namespace OpenVic { class GFXSpriteTexture : public GFXButtonStateHavingTexture { - GDCLASS(GFXSpriteTexture, GFXButtonStateHavingTexture) + GDCLASS(GFXSpriteTexture, GFXButtonStateHavingTexture); /* PROPERTY automatically defines getter functions: * - get_gfx_texture_sprite @@ -26,7 +26,7 @@ namespace OpenVic { /* Create a GFXSpriteTexture using the specified GFX::TextureSprite and icon index. Returns nullptr if * set_gfx_texture_sprite fails. */ - static godot::Ref make_gfx_sprite_texture( + static godot::Ref make_gfx_sprite_texture( // GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES ); @@ -35,13 +35,13 @@ namespace OpenVic { /* Set the GFX::TextureSprite, load its texture as an atlas, check if it is an IconTextureSprite, * and if so set its icon count and the current displayed icon. */ - godot::Error set_gfx_texture_sprite( + godot::Error set_gfx_texture_sprite( // GFX::TextureSprite const* new_gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES ); /* Search for a GFX::TextureSprite with the specified name and, * if successful, call set_gfx_texture_sprite to set it and its icon. */ - godot::Error set_gfx_texture_sprite_name( + godot::Error set_gfx_texture_sprite_name( // godot::String const& gfx_texture_sprite_name, GFX::frame_t icon = GFX::NO_FRAMES ); diff --git a/extension/src/openvic-extension/classes/GUIButton.cpp b/extension/src/openvic-extension/classes/GUIButton.cpp index e674e286..2fc590ff 100644 --- a/extension/src/openvic-extension/classes/GUIButton.cpp +++ b/extension/src/openvic-extension/classes/GUIButton.cpp @@ -96,7 +96,7 @@ Error GUIButton::set_gfx_font(GFX::Font const* gfx_font) { } static const std::array button_font_themes { - "font_color", "font_hover_color", "font_hover_pressed_color", "font_pressed_color", "font_disabled_color" + "font_color", "font_hover_color", "font_hover_pressed_color", "font_pressed_color", "font_disabled_color" // }; const Color colour = Utilities::to_godot_color(gfx_font->get_colour()); diff --git a/extension/src/openvic-extension/classes/GUIButton.hpp b/extension/src/openvic-extension/classes/GUIButton.hpp index 3873a4de..7eb0accc 100644 --- a/extension/src/openvic-extension/classes/GUIButton.hpp +++ b/extension/src/openvic-extension/classes/GUIButton.hpp @@ -9,7 +9,7 @@ namespace OpenVic { class GUIButton : public godot::Button { - GDCLASS(GUIButton, godot::Button) + GDCLASS(GUIButton, godot::Button); GUI_TOOLTIP_DEFINITIONS diff --git a/extension/src/openvic-extension/classes/GUIHasTooltip.hpp b/extension/src/openvic-extension/classes/GUIHasTooltip.hpp index 18bdb308..4ce2ba6e 100644 --- a/extension/src/openvic-extension/classes/GUIHasTooltip.hpp +++ b/extension/src/openvic-extension/classes/GUIHasTooltip.hpp @@ -17,20 +17,21 @@ * - initialise tooltip_active to false in the class' constructor. */ #define GUI_TOOLTIP_DEFINITIONS \ - public: \ - void set_tooltip_string_and_substitution_dict( \ - godot::String const& new_tooltip_string, godot::Dictionary const& new_tooltip_substitution_dict \ - ); \ - void set_tooltip_string(godot::String const& new_tooltip_string); \ - void set_tooltip_substitution_dict(godot::Dictionary const& new_tooltip_substitution_dict); \ - void clear_tooltip(); \ - private: \ - godot::String PROPERTY(tooltip_string); \ - godot::Dictionary PROPERTY(tooltip_substitution_dict); \ - bool PROPERTY_CUSTOM_PREFIX(tooltip_active, is, false); \ - void _tooltip_notification(int what); \ - void _set_tooltip_active(bool new_tooltip_active); \ - void _set_tooltip_visibility(bool visible); +public: \ + void set_tooltip_string_and_substitution_dict( \ + godot::String const& new_tooltip_string, godot::Dictionary const& new_tooltip_substitution_dict \ + ); \ + void set_tooltip_string(godot::String const& new_tooltip_string); \ + void set_tooltip_substitution_dict(godot::Dictionary const& new_tooltip_substitution_dict); \ + void clear_tooltip(); \ +\ +private: \ + godot::String PROPERTY(tooltip_string); \ + godot::Dictionary PROPERTY(tooltip_substitution_dict); \ + bool PROPERTY_CUSTOM_PREFIX(tooltip_active, is, false); \ + void _tooltip_notification(int what); \ + void _set_tooltip_active(bool new_tooltip_active); \ + void _set_tooltip_visibility(bool visible); #define GUI_TOOLTIP_IMPLEMENTATIONS(CLASS) \ void CLASS::set_tooltip_string_and_substitution_dict( \ @@ -108,11 +109,11 @@ OV_BIND_METHOD(CLASS::clear_tooltip); \ OV_BIND_METHOD(CLASS::is_tooltip_active); \ ADD_PROPERTY( \ - PropertyInfo(Variant::STRING, "tooltip_string", PROPERTY_HINT_MULTILINE_TEXT), \ - "set_tooltip_string", "get_tooltip_string" \ + PropertyInfo(Variant::STRING, "tooltip_string", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_string", \ + "get_tooltip_string" \ ); \ ADD_PROPERTY( \ - PropertyInfo(Variant::DICTIONARY, "tooltip_substitution_dict"), \ - "set_tooltip_substitution_dict", "get_tooltip_substitution_dict" \ + PropertyInfo(Variant::DICTIONARY, "tooltip_substitution_dict"), "set_tooltip_substitution_dict", \ + "get_tooltip_substitution_dict" \ ); \ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tooltip_active"), "", "is_tooltip_active"); diff --git a/extension/src/openvic-extension/classes/GUIIcon.hpp b/extension/src/openvic-extension/classes/GUIIcon.hpp index e8e3014a..2e8e5ed4 100644 --- a/extension/src/openvic-extension/classes/GUIIcon.hpp +++ b/extension/src/openvic-extension/classes/GUIIcon.hpp @@ -5,7 +5,7 @@ namespace OpenVic { class GUIIcon : public GUITextureRect { - GDCLASS(GUIIcon, GUITextureRect) + GDCLASS(GUIIcon, GUITextureRect); godot::Ref gfx_sprite_texture; @@ -13,13 +13,11 @@ namespace OpenVic { static void _bind_methods(); public: - godot::Error set_gfx_texture_sprite( - GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES - ); + godot::Error set_gfx_texture_sprite(GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES); godot::Ref get_gfx_sprite_texture() const; - godot::Error set_gfx_texture_sprite_name( + godot::Error set_gfx_texture_sprite_name( // godot::String const& gfx_texture_sprite_name, GFX::frame_t icon = GFX::NO_FRAMES ); diff --git a/extension/src/openvic-extension/classes/GUIIconButton.hpp b/extension/src/openvic-extension/classes/GUIIconButton.hpp index 10fc1791..3b35dc34 100644 --- a/extension/src/openvic-extension/classes/GUIIconButton.hpp +++ b/extension/src/openvic-extension/classes/GUIIconButton.hpp @@ -5,7 +5,7 @@ namespace OpenVic { class GUIIconButton : public GUIButton { - GDCLASS(GUIIconButton, GUIButton) + GDCLASS(GUIIconButton, GUIButton); godot::Ref gfx_sprite_texture; @@ -13,13 +13,11 @@ namespace OpenVic { static void _bind_methods(); public: - godot::Error set_gfx_texture_sprite( - GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES - ); + godot::Error set_gfx_texture_sprite(GFX::TextureSprite const* gfx_texture_sprite, GFX::frame_t icon = GFX::NO_FRAMES); godot::Ref get_gfx_sprite_texture() const; - godot::Error set_gfx_texture_sprite_name( + godot::Error set_gfx_texture_sprite_name( // godot::String const& gfx_texture_sprite_name, GFX::frame_t icon = GFX::NO_FRAMES ); diff --git a/extension/src/openvic-extension/classes/GUILabel.cpp b/extension/src/openvic-extension/classes/GUILabel.cpp index b5def5cb..39389fd0 100644 --- a/extension/src/openvic-extension/classes/GUILabel.cpp +++ b/extension/src/openvic-extension/classes/GUILabel.cpp @@ -5,11 +5,12 @@ #include #include +#include + #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" -#include "openvic-simulation/types/TextFormat.hpp" using namespace OpenVic; using namespace godot; @@ -102,9 +103,7 @@ void GUILabel::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR2, "border_size", PROPERTY_HINT_NONE, "suffix:px"), "set_border_size", "get_border_size" ); - ADD_PROPERTY( - PropertyInfo(Variant::RECT2, "adjusted_rect", PROPERTY_HINT_NONE, "suffix:px"), "", "get_adjusted_rect" - ); + ADD_PROPERTY(PropertyInfo(Variant::RECT2, "adjusted_rect", PROPERTY_HINT_NONE, "suffix:px"), "", "get_adjusted_rect"); ADD_PROPERTY( PropertyInfo(Variant::BOOL, "auto_adjust_to_content_size"), "set_auto_adjust_to_content_size", "will_auto_adjust_to_content_size" @@ -158,7 +157,7 @@ void GUILabel::_notification(int what) { position.x += adjusted_rect.size.width - 2 * border_size.width - line.width; } break; case HORIZONTAL_ALIGNMENT_LEFT: - default: + default: // break; } @@ -167,22 +166,18 @@ void GUILabel::_notification(int what) { for (segment_t const& segment : line.segments) { if (string_segment_t const* string_segment = std::get_if(&segment)) { font->draw_string( - ci, position, string_segment->text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, - string_segment->colour + ci, position, string_segment->text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, string_segment->colour ); position.x += string_segment->width; } else if (flag_segment_t const* flag_segment = std::get_if(&segment)) { - (*flag_segment)->draw_rect(ci, Rect2 { - position - Vector2 { 1.0_real, ascent - 4.0_real }, FLAG_DRAW_DIMS - }, false); + (*flag_segment) + ->draw_rect(ci, Rect2 { position - Vector2 { 1.0_real, ascent - 4.0_real }, FLAG_DRAW_DIMS }, false); position.x += FLAG_SEGMENT_WIDTH; } else if (currency_texture.is_valid()) { currency_texture->draw( - ci, position - Vector2 { - 1.0_real, static_cast(currency_texture->get_height()) * 0.75_real - } + ci, position - Vector2 { 1.0_real, static_cast(currency_texture->get_height()) * 0.75_real } ); position.x += currency_texture->get_width(); @@ -243,9 +238,9 @@ Error GUILabel::set_gui_text(GUI::Text const* new_gui_text, GFX::Font::colour_co using enum text_format_t; static const ordered_map format_map { - { left, HORIZONTAL_ALIGNMENT_LEFT }, + { left, HORIZONTAL_ALIGNMENT_LEFT }, // { centre, HORIZONTAL_ALIGNMENT_CENTER }, - { right, HORIZONTAL_ALIGNMENT_RIGHT } + { right, HORIZONTAL_ALIGNMENT_RIGHT } // }; const decltype(format_map)::const_iterator it = format_map.find(gui_text->get_format()); @@ -506,9 +501,8 @@ String GUILabel::generate_substituted_text(String const& base_text) const { while ((marker_start_pos = base_text.find(get_substitution_marker(), start_pos)) != -1) { result += base_text.substr(start_pos, marker_start_pos - start_pos); - int64_t marker_end_pos = base_text.find( - get_substitution_marker(), marker_start_pos + get_substitution_marker().length() - ); + int64_t marker_end_pos = + base_text.find(get_substitution_marker(), marker_start_pos + get_substitution_marker().length()); if (marker_end_pos == -1) { marker_end_pos = base_text.length(); } @@ -541,7 +535,7 @@ String GUILabel::generate_substituted_text(String const& base_text) const { return result; } -std::pair GUILabel::generate_display_text_and_colour_instructions( +std::pair GUILabel::generate_display_text_and_colour_instructions( // String const& substituted_text ) const { String result; @@ -571,7 +565,7 @@ std::pair GUILabel::generate_display_te return { std::move(result), std::move(colour_instructions) }; } -std::vector GUILabel::generate_lines_and_segments( +std::vector GUILabel::generate_lines_and_segments( // String const& display_text, colour_instructions_t const& colour_instructions ) const { static constexpr char RESET_COLOUR_CODE = '!'; @@ -602,9 +596,7 @@ std::vector GUILabel::generate_lines_and_segments( if (current_colour != new_colour) { if (section_start < idx) { - separate_lines( - display_text.substr(section_start, idx - section_start), current_colour, unwrapped_lines - ); + separate_lines(display_text.substr(section_start, idx - section_start), current_colour, unwrapped_lines); section_start = idx; } current_colour = new_colour; @@ -618,9 +610,7 @@ std::vector GUILabel::generate_lines_and_segments( return unwrapped_lines; } -void GUILabel::separate_lines( - String const& string, Color const& colour, std::vector& unwrapped_lines -) const { +void GUILabel::separate_lines(String const& string, Color const& colour, std::vector& unwrapped_lines) const { static const String NEWLINE_MARKER = "\n"; int64_t start_pos = 0; @@ -641,9 +631,7 @@ void GUILabel::separate_lines( } } -void GUILabel::separate_currency_segments( - String const& string, Color const& colour, line_t& line -) const { +void GUILabel::separate_currency_segments(String const& string, Color const& colour, line_t& line) const { int64_t start_pos = 0; int64_t marker_pos; @@ -722,9 +710,7 @@ GUILabel::flag_segment_t GUILabel::make_flag_segment(String const& identifier) { return flag_segment; } -void GUILabel::separate_flag_segments( - String const& string, Color const& colour, line_t& line -) const { +void GUILabel::separate_flag_segments(String const& string, Color const& colour, line_t& line) const { const auto push_string_segment = [this, &string, &colour, &line](int64_t start, int64_t end) -> void { String substring = string.substr(start, end - start); const real_t width = get_string_width(substring); @@ -819,7 +805,7 @@ std::vector GUILabel::wrap_lines(std::vector& unwrappe if (last_marker_pos != 0 || !current_line->segments.empty()) { if (!new_segment_string.is_empty()) { current_line->segments.emplace_back(string_segment_t { - std::move(new_segment_string), string_segment->colour, new_segment_width + std::move(new_segment_string), string_segment->colour, new_segment_width // }); current_line->width += new_segment_width; } @@ -832,7 +818,7 @@ std::vector GUILabel::wrap_lines(std::vector& unwrappe } } current_line->segments.emplace_back(string_segment_t { - std::move(whole_segment_string), string_segment->colour, whole_segment_width + std::move(whole_segment_string), string_segment->colour, whole_segment_width // }); current_line->width += whole_segment_width; break; @@ -849,8 +835,7 @@ std::vector GUILabel::wrap_lines(std::vector& unwrappe } const auto is_over_max_height = [this, &wrapped_lines, &max_content_size]() -> bool { - return wrapped_lines.size() > 1 - && wrapped_lines.size() * font->get_height(font_size) > max_content_size.height; + return wrapped_lines.size() > 1 && wrapped_lines.size() * font->get_height(font_size) > max_content_size.height; }; if (is_over_max_height()) { @@ -914,7 +899,7 @@ void GUILabel::adjust_to_content_size() { adjusted_rect.position.x = max_size.width - adjusted_rect.size.width; } break; case HORIZONTAL_ALIGNMENT_LEFT: - default: + default: // break; } } else { diff --git a/extension/src/openvic-extension/classes/GUILabel.hpp b/extension/src/openvic-extension/classes/GUILabel.hpp index 94422913..07611083 100644 --- a/extension/src/openvic-extension/classes/GUILabel.hpp +++ b/extension/src/openvic-extension/classes/GUILabel.hpp @@ -13,7 +13,7 @@ namespace OpenVic { class GUILabel : public godot::Control { - GDCLASS(GUILabel, godot::Control) + GDCLASS(GUILabel, godot::Control); GUI_TOOLTIP_DEFINITIONS @@ -76,7 +76,7 @@ namespace OpenVic { /* Return the name of the GUI::Text, or an empty String if it's null. */ godot::String get_gui_text_name() const; /* Set the GUI::Text. */ - godot::Error set_gui_text( + godot::Error set_gui_text( // GUI::Text const* new_gui_text, GFX::Font::colour_codes_t const* override_colour_codes = nullptr ); @@ -115,22 +115,16 @@ namespace OpenVic { void _update_lines(); godot::String generate_substituted_text(godot::String const& base_text) const; - std::pair generate_display_text_and_colour_instructions( + std::pair generate_display_text_and_colour_instructions( // godot::String const& substituted_text ) const; - std::vector generate_lines_and_segments( + std::vector generate_lines_and_segments( // godot::String const& display_text, colour_instructions_t const& colour_instructions ) const; - void separate_lines( - godot::String const& string, godot::Color const& colour, std::vector& lines - ) const; - void separate_currency_segments( - godot::String const& string, godot::Color const& colour, line_t& line - ) const; + void separate_lines(godot::String const& string, godot::Color const& colour, std::vector& lines) const; + void separate_currency_segments(godot::String const& string, godot::Color const& colour, line_t& line) const; static flag_segment_t make_flag_segment(godot::String const& identifier); - void separate_flag_segments( - godot::String const& string, godot::Color const& colour, line_t& line - ) const; + void separate_flag_segments(godot::String const& string, godot::Color const& colour, line_t& line) const; std::vector wrap_lines(std::vector& unwrapped_lines) const; void adjust_to_content_size(); }; diff --git a/extension/src/openvic-extension/classes/GUILineChart.cpp b/extension/src/openvic-extension/classes/GUILineChart.cpp index c0b5a020..e7e1c723 100644 --- a/extension/src/openvic-extension/classes/GUILineChart.cpp +++ b/extension/src/openvic-extension/classes/GUILineChart.cpp @@ -78,7 +78,8 @@ Error GUILineChart::set_gfx_line_chart_name(String const& new_gfx_line_chart_nam GFX::LineChart const* new_gfx_line_chart = sprite->cast_to(); ERR_FAIL_NULL_V_MSG( - new_gfx_line_chart, FAILED, vformat( + new_gfx_line_chart, FAILED, + vformat( "Invalid type for GFX sprite %s: %s (expected %s)", new_gfx_line_chart_name, Utilities::std_to_godot_string(sprite->get_type()), Utilities::std_to_godot_string(GFX::LineChart::get_type_static()) @@ -181,10 +182,13 @@ Error GUILineChart::add_coloured_line(PackedFloat32Array const& line_values, Col if (point_count <= 0) { point_count = line_values.size(); } else { - ERR_FAIL_COND_V_MSG(point_count != line_values.size(), FAILED, vformat( - "Mismatch between number of points in GUILineChart lines: new line %d != existing lines %d", - line_values.size(), point_count - )); + ERR_FAIL_COND_V_MSG( + point_count != line_values.size(), FAILED, + vformat( + "Mismatch between number of points in GUILineChart lines: new line %d != existing lines %d", line_values.size(), + point_count + ) + ); } Line2D* line = memnew(Line2D); diff --git a/extension/src/openvic-extension/classes/GUILineChart.hpp b/extension/src/openvic-extension/classes/GUILineChart.hpp index 10163d63..ce32e470 100644 --- a/extension/src/openvic-extension/classes/GUILineChart.hpp +++ b/extension/src/openvic-extension/classes/GUILineChart.hpp @@ -7,7 +7,7 @@ namespace OpenVic { class GUILineChart : public godot::Control { - GDCLASS(GUILineChart, godot::Control) + GDCLASS(GUILineChart, godot::Control); GFX::LineChart const* gfx_line_chart = nullptr; diff --git a/extension/src/openvic-extension/classes/GUIListBox.hpp b/extension/src/openvic-extension/classes/GUIListBox.hpp index 95f74607..b57fe9b6 100644 --- a/extension/src/openvic-extension/classes/GUIListBox.hpp +++ b/extension/src/openvic-extension/classes/GUIListBox.hpp @@ -8,7 +8,7 @@ namespace OpenVic { class GUIListBox : public godot::Container { - GDCLASS(GUIListBox, godot::Container) + GDCLASS(GUIListBox, godot::Container); GUI::ListBox const* PROPERTY(gui_listbox, nullptr); diff --git a/extension/src/openvic-extension/classes/GUIMaskedFlag.hpp b/extension/src/openvic-extension/classes/GUIMaskedFlag.hpp index 4bdc6c15..b6d4999c 100644 --- a/extension/src/openvic-extension/classes/GUIMaskedFlag.hpp +++ b/extension/src/openvic-extension/classes/GUIMaskedFlag.hpp @@ -5,7 +5,7 @@ namespace OpenVic { class GUIMaskedFlag : public GUITextureRect { - GDCLASS(GUIMaskedFlag, GUITextureRect) + GDCLASS(GUIMaskedFlag, GUITextureRect); godot::Ref gfx_masked_flag_texture; @@ -21,7 +21,7 @@ namespace OpenVic { godot::String get_gfx_masked_flag_name() const; - godot::Error set_flag_country_name_and_type( + godot::Error set_flag_country_name_and_type( // godot::String const& flag_country_name, godot::StringName const& flag_type ) const; diff --git a/extension/src/openvic-extension/classes/GUIMaskedFlagButton.hpp b/extension/src/openvic-extension/classes/GUIMaskedFlagButton.hpp index 131c93de..afb99600 100644 --- a/extension/src/openvic-extension/classes/GUIMaskedFlagButton.hpp +++ b/extension/src/openvic-extension/classes/GUIMaskedFlagButton.hpp @@ -5,7 +5,7 @@ namespace OpenVic { class GUIMaskedFlagButton : public GUIButton { - GDCLASS(GUIMaskedFlagButton, GUIButton) + GDCLASS(GUIMaskedFlagButton, GUIButton); godot::Ref gfx_masked_flag_texture; @@ -21,7 +21,7 @@ namespace OpenVic { godot::String get_gfx_masked_flag_name() const; - godot::Error set_flag_country_name_and_type( + godot::Error set_flag_country_name_and_type( // godot::String const& flag_country_name, godot::StringName const& flag_type ) const; diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp index 047320c8..ef6cdcd9 100644 --- a/extension/src/openvic-extension/classes/GUINode.cpp +++ b/extension/src/openvic-extension/classes/GUINode.cpp @@ -167,9 +167,8 @@ Ref GUINode::get_texture_from_node(Node* node) { ); const Ref stylebox_texture = stylebox; ERR_FAIL_NULL_V_MSG( - stylebox_texture, nullptr, vformat( - "Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", theme_name_normal, node->get_name() - ) + stylebox_texture, nullptr, + vformat("Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", theme_name_normal, node->get_name()) ); const Ref result = stylebox_texture->get_texture(); ERR_FAIL_NULL_V_MSG( @@ -179,9 +178,7 @@ Ref GUINode::get_texture_from_node(Node* node) { return result; } ERR_FAIL_V_MSG( - nullptr, vformat( - "Failed to cast node %s from type %s to TextureRect or GUIButton", node->get_name(), node->get_class() - ) + nullptr, vformat("Failed to cast node %s from type %s to TextureRect or GUIButton", node->get_name(), node->get_class()) ); } diff --git a/extension/src/openvic-extension/classes/GUINode.hpp b/extension/src/openvic-extension/classes/GUINode.hpp index 538749f9..9dd7e0a6 100644 --- a/extension/src/openvic-extension/classes/GUINode.hpp +++ b/extension/src/openvic-extension/classes/GUINode.hpp @@ -29,7 +29,7 @@ namespace OpenVic { class GUINode : public godot::Control { - GDCLASS(GUINode, godot::Control) + GDCLASS(GUINode, godot::Control); godot::Ref _click_mask; godot::Vector _mask_controls; @@ -42,11 +42,11 @@ namespace OpenVic { public: GUINode(); - static godot::Control* generate_gui_element( + static godot::Control* generate_gui_element( // godot::String const& gui_scene, godot::String const& gui_element, godot::String const& name = "" ); - godot::Error add_gui_element( + godot::Error add_gui_element( // godot::String const& gui_scene, godot::String const& gui_element, godot::String const& name = "" ); @@ -68,7 +68,7 @@ namespace OpenVic { // These expect a non-null node! static GUIIconButton* get_gui_icon_button_from_node_and_path(godot::Node* node, godot::NodePath const& path); - static GUIMaskedFlagButton* get_gui_masked_flag_button_from_node_and_path( + static GUIMaskedFlagButton* get_gui_masked_flag_button_from_node_and_path( // godot::Node* node, godot::NodePath const& path ); static GUILabel* get_gui_label_from_node_and_path(godot::Node* node, godot::NodePath const& path); @@ -77,7 +77,7 @@ namespace OpenVic { static GUIIcon* get_gui_icon_from_node_and_path(godot::Node* node, godot::NodePath const& path); static GUIMaskedFlag* get_gui_masked_flag_from_node_and_path(godot::Node* node, godot::NodePath const& path); static GUIPieChart* get_gui_pie_chart_from_node_and_path(godot::Node* node, godot::NodePath const& path); - static GUIOverlappingElementsBox* get_gui_overlapping_elements_box_from_node_and_path( + static GUIOverlappingElementsBox* get_gui_overlapping_elements_box_from_node_and_path( // godot::Node* node, godot::NodePath const& path ); static GUIScrollbar* get_gui_scrollbar_from_node_and_path(godot::Node* node, godot::NodePath const& path); diff --git a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp index c346b038..cb891816 100644 --- a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp +++ b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp @@ -2,10 +2,11 @@ #include +#include + #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" -#include "openvic-simulation/types/TextFormat.hpp" using namespace OpenVic; using namespace godot; @@ -17,7 +18,9 @@ Error GUIOverlappingElementsBox::_update_child_positions() { return OK; } - const auto _get_child = [this](int32_t index) -> Control* { return Object::cast_to(get_child(index)); }; + const auto _get_child = [this](int32_t index) -> Control* { + return Object::cast_to(get_child(index)); + }; const float box_width = get_size().x; const float child_width = _get_child(0)->get_size().x; @@ -33,20 +36,19 @@ Error GUIOverlappingElementsBox::_update_child_positions() { Error err = OK; using enum text_format_t; switch (gui_overlapping_elements_box->get_format()) { - case left: - break; - case centre: - starting_x = (box_width - total_width) / 2; - break; - case right: - starting_x = box_width - total_width; - break; - default: - UtilityFunctions::push_error( - "Invalid GUIOverlappingElementsBox alignment: ", - static_cast(gui_overlapping_elements_box->get_format()) - ); - err = FAILED; + case left: // + break; + case centre: // + starting_x = (box_width - total_width) / 2; + break; + case right: // + starting_x = box_width - total_width; + break; + default: + UtilityFunctions::push_error( + "Invalid GUIOverlappingElementsBox alignment: ", static_cast(gui_overlapping_elements_box->get_format()) + ); + err = FAILED; } for (int32_t index = 0; index < child_count; ++index) { @@ -101,7 +103,8 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) { return OK; } else { ERR_FAIL_NULL_V_MSG( - gui_child_element, FAILED, vformat( + gui_child_element, FAILED, + vformat( "GUIOverlappingElementsBox child element is null (child_count = %d, new_count = %d)", child_count, new_count ) ); @@ -115,9 +118,10 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) { err = FAILED; } ERR_FAIL_NULL_V_MSG( - child, FAILED, vformat( - "Failed to generate GUIOverlappingElementsBox child element %s (child_count = %d, new_count = %d)", - name, child_count, new_count + child, FAILED, + vformat( + "Failed to generate GUIOverlappingElementsBox child element %s (child_count = %d, new_count = %d)", name, + child_count, new_count ) ); @@ -153,7 +157,7 @@ Error GUIOverlappingElementsBox::set_gui_overlapping_elements_box( } String GUIOverlappingElementsBox::get_gui_overlapping_elements_box_name() const { - return gui_overlapping_elements_box != nullptr + return gui_overlapping_elements_box != nullptr // ? Utilities::std_to_godot_string(gui_overlapping_elements_box->get_name()) : String {}; } diff --git a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.hpp b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.hpp index b10c7d89..1c4d5418 100644 --- a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.hpp +++ b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.hpp @@ -6,7 +6,7 @@ namespace OpenVic { class GUIOverlappingElementsBox : public godot::Container { - GDCLASS(GUIOverlappingElementsBox, godot::Container) + GDCLASS(GUIOverlappingElementsBox, godot::Container); GUI::OverlappingElementsBox const* PROPERTY(gui_overlapping_elements_box, nullptr); GUI::Element const* PROPERTY(gui_child_element, nullptr); @@ -41,7 +41,7 @@ namespace OpenVic { /* Search for a GUI::Element with the specified name and, if successful, * set the child element to it using set_gui_child_element. */ - godot::Error set_gui_child_element_name( + godot::Error set_gui_child_element_name( // godot::String const& gui_child_element_file, godot::String const& gui_child_element_name ); diff --git a/extension/src/openvic-extension/classes/GUIPieChart.hpp b/extension/src/openvic-extension/classes/GUIPieChart.hpp index 32ca3505..6b23f2df 100644 --- a/extension/src/openvic-extension/classes/GUIPieChart.hpp +++ b/extension/src/openvic-extension/classes/GUIPieChart.hpp @@ -8,7 +8,7 @@ namespace OpenVic { class GUIPieChart : public godot::TextureRect { - GDCLASS(GUIPieChart, godot::TextureRect) + GDCLASS(GUIPieChart, godot::TextureRect); godot::Ref gfx_pie_chart_texture; diff --git a/extension/src/openvic-extension/classes/GUIProgressBar.cpp b/extension/src/openvic-extension/classes/GUIProgressBar.cpp index 35b449f8..6c680f6e 100644 --- a/extension/src/openvic-extension/classes/GUIProgressBar.cpp +++ b/extension/src/openvic-extension/classes/GUIProgressBar.cpp @@ -51,7 +51,7 @@ Error GUIProgressBar::set_gfx_progress_bar(GFX::ProgressBar const* progress_bar) } if (back_texture.is_null()) { const Color back_colour = Utilities::to_godot_color(progress_bar->get_back_colour()); - back_texture = Utilities::make_solid_colour_texture( + back_texture = Utilities::make_solid_colour_texture( // back_colour, progress_bar->get_size().x, progress_bar->get_size().y ); if (back_texture.is_null()) { @@ -64,34 +64,28 @@ Error GUIProgressBar::set_gfx_progress_bar(GFX::ProgressBar const* progress_bar) if (back_texture.is_valid()) { set_under_texture(back_texture); } else { - UtilityFunctions::push_error( - "Failed to create and set sprite back texture for GUIProgressBar ", get_name() - ); + UtilityFunctions::push_error("Failed to create and set sprite back texture for GUIProgressBar ", get_name()); err = FAILED; } Ref progress_texture; if (!progress_bar->get_progress_texture_file().empty()) { - const StringName progress_texture_file = - Utilities::std_to_godot_string(progress_bar->get_progress_texture_file()); + const StringName progress_texture_file = Utilities::std_to_godot_string(progress_bar->get_progress_texture_file()); progress_texture = asset_manager->get_texture(progress_texture_file, LOAD_FLAG_CACHE_TEXTURE | LOAD_FLAG_FLIP_Y); if (progress_texture.is_null()) { UtilityFunctions::push_error( - "Failed to load sprite progress texture ", progress_texture_file, " for GUIProgressBar ", - get_name() + "Failed to load sprite progress texture ", progress_texture_file, " for GUIProgressBar ", get_name() ); err = FAILED; } } if (progress_texture.is_null()) { const Color progress_colour = Utilities::to_godot_color(progress_bar->get_progress_colour()); - progress_texture = Utilities::make_solid_colour_texture( - progress_colour, progress_bar->get_size().x, progress_bar->get_size().y - ); + progress_texture = + Utilities::make_solid_colour_texture(progress_colour, progress_bar->get_size().x, progress_bar->get_size().y); if (progress_texture.is_null()) { UtilityFunctions::push_error( - "Failed to generate sprite ", progress_colour, " progress texture for GUIProgressBar ", - get_name() + "Failed to generate sprite ", progress_colour, " progress texture for GUIProgressBar ", get_name() ); err = FAILED; } @@ -99,16 +93,12 @@ Error GUIProgressBar::set_gfx_progress_bar(GFX::ProgressBar const* progress_bar) if (progress_texture.is_valid()) { set_progress_texture(progress_texture); } else { - UtilityFunctions::push_error( - "Failed to create and set sprite progress texture for GUIProgressBar ", get_name() - ); + UtilityFunctions::push_error("Failed to create and set sprite progress texture for GUIProgressBar ", get_name()); err = FAILED; } // TODO - work out why progress bar is missing bottom border pixel (e.g. province building expansion bar) - set_custom_minimum_size( - Utilities::to_godot_fvec2(static_cast(progress_bar->get_size())) - ); + set_custom_minimum_size(Utilities::to_godot_fvec2(static_cast(progress_bar->get_size()))); return err; } diff --git a/extension/src/openvic-extension/classes/GUIProgressBar.hpp b/extension/src/openvic-extension/classes/GUIProgressBar.hpp index 11b677ac..393fdbad 100644 --- a/extension/src/openvic-extension/classes/GUIProgressBar.hpp +++ b/extension/src/openvic-extension/classes/GUIProgressBar.hpp @@ -2,12 +2,13 @@ #include -#include "openvic-simulation/interface/GFXSprite.hpp" +#include + #include "openvic-extension/classes/GUIHasTooltip.hpp" namespace OpenVic { class GUIProgressBar : public godot::TextureProgressBar { - GDCLASS(GUIProgressBar, godot::TextureProgressBar) + GDCLASS(GUIProgressBar, godot::TextureProgressBar); GUI_TOOLTIP_DEFINITIONS diff --git a/extension/src/openvic-extension/classes/GUIScrollbar.cpp b/extension/src/openvic-extension/classes/GUIScrollbar.cpp index b18a8d12..4da53db2 100644 --- a/extension/src/openvic-extension/classes/GUIScrollbar.cpp +++ b/extension/src/openvic-extension/classes/GUIScrollbar.cpp @@ -1,14 +1,15 @@ #include "GUIScrollbar.hpp" #include +#include #include #include #include #include -#include #include +#include #include #include "openvic-extension/utility/ClassBindings.hpp" @@ -105,7 +106,7 @@ bool GUIScrollbar::_update_button_change() { } float GUIScrollbar::_value_to_ratio(int32_t val) const { - return step_count == 0 + return step_count == 0 // ? 0.0f : static_cast(val) / step_count; } @@ -192,8 +193,8 @@ void GUIScrollbar::_calculate_rects() { * They have a row of transparent pixels at the top to account for this, so we must also draw them * one pixel taller to avoid having a gap between the track and the more button. */ track_rect = { - { (average_button_width - track_width) / 2.0f, slider_start - 1.0f }, - { track_width, slider_distance + 1.0f } + { (average_button_width - track_width) / 2.0f, slider_start - 1.0f }, // + { track_width, slider_distance + 1.0f } // }; } else { track_rect = {}; @@ -204,7 +205,7 @@ void GUIScrollbar::_calculate_rects() { slider_rect = { { (average_button_width - slider_size.width) / 2.0f, 0.0f }, - slider_size + slider_size // }; slider_distance -= slider_rect.size.height; @@ -231,18 +232,14 @@ void GUIScrollbar::_constrain_value() { const int32_t upper_limit = upper_range_limit.value_or(step_count); // Special case to mimic SliderValue.hpp - if (lower_limit > upper_limit){ + if (lower_limit > upper_limit) { if (value > upper_limit) { value = lower_limit; } else { value = upper_limit; } } else { - value = std::clamp( - value, - lower_limit, - upper_limit - ); + value = std::clamp(value, lower_limit, upper_limit); } slider_rect.position[orientation == HORIZONTAL ? 0 : 1] = slider_start + slider_distance * get_value_as_ratio(); @@ -255,7 +252,7 @@ void GUIScrollbar::_constrain_range_limits() { lower_range_limit = upper_range_limit = {}; return; } - + if (lower_range_limit.has_value()) { lower_range_limit = std::clamp(lower_range_limit.value(), 0, step_count); } @@ -265,9 +262,8 @@ void GUIScrollbar::_constrain_range_limits() { const int axis = orientation == HORIZONTAL ? 0 : 1; range_limit_min_rect.position[axis] = slider_start + slider_distance * _value_to_ratio(lower_range_limit.value_or(0)); - range_limit_max_rect.position[axis] = slider_start - + slider_distance * _value_to_ratio(upper_range_limit.value_or(step_count)) - + slider_rect.size[axis] / 2.0f; + range_limit_max_rect.position[axis] = slider_start + + slider_distance * _value_to_ratio(upper_range_limit.value_or(step_count)) + slider_rect.size[axis] / 2.0f; return; } @@ -373,39 +369,52 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { length_override = 0.0f; range_limited = gui_scrollbar->is_range_limited(); - /* _Element is either GUI::Button or GUI::Icon, both of which have their own + /* element is either GUI::Button or GUI::Icon, both of which have their own * separately defined get_sprite(), hence the need for a template. */ - const auto set_texture = [&gui_scrollbar_name]( - String const& target, _Element const* element, Ref& texture - ) -> bool { - ERR_FAIL_NULL_V_MSG(element, false, vformat( - "Invalid %s element for GUIScrollbar %s - null!", target, gui_scrollbar_name - )); + const auto set_texture = // + [&gui_scrollbar_name]( + String const& target, Element const* element, Ref& texture + ) -> bool // + { + ERR_FAIL_NULL_V_MSG( + element, false, vformat("Invalid %s element for GUIScrollbar %s - null!", target, gui_scrollbar_name) + ); const String element_name = Utilities::std_to_godot_string(element->get_name()); /* Get Sprite, convert to TextureSprite, use to make a GFXSpriteTexture. */ GFX::Sprite const* sprite = element->get_sprite(); - ERR_FAIL_NULL_V_MSG(sprite, false, vformat( - "Invalid %s element %s for GUIScrollbar %s - sprite is null!", target, element_name, gui_scrollbar_name - )); + ERR_FAIL_NULL_V_MSG( + sprite, false, + vformat("Invalid %s element %s for GUIScrollbar %s - sprite is null!", target, element_name, gui_scrollbar_name) + ); GFX::TextureSprite const* texture_sprite = sprite->cast_to(); - ERR_FAIL_NULL_V_MSG(texture_sprite, false, vformat( - "Invalid %s element %s for GUIScrollbar %s - sprite type is %s with base type %s, expected base %s!", target, - element_name, gui_scrollbar_name, Utilities::std_to_godot_string(sprite->get_type()), - Utilities::std_to_godot_string(sprite->get_base_type()), - Utilities::std_to_godot_string(GFX::TextureSprite::get_type_static()) - )); + ERR_FAIL_NULL_V_MSG( + texture_sprite, false, + vformat( + "Invalid %s element %s for GUIScrollbar %s - sprite type is %s with base type %s, expected base %s!", target, + element_name, gui_scrollbar_name, Utilities::std_to_godot_string(sprite->get_type()), + Utilities::std_to_godot_string(sprite->get_base_type()), + Utilities::std_to_godot_string(GFX::TextureSprite::get_type_static()) + ) + ); texture = GFXSpriteTexture::make_gfx_sprite_texture(texture_sprite); - ERR_FAIL_NULL_V_MSG(texture, false, vformat( - "Failed to make GFXSpriteTexture from %s element %s for GUIScrollbar %s!", target, element_name, gui_scrollbar_name - )); - if constexpr (std::is_same_v<_Element, GUI::Button>) { + ERR_FAIL_NULL_V_MSG( + texture, false, + vformat( + "Failed to make GFXSpriteTexture from %s element %s for GUIScrollbar %s!", target, element_name, + gui_scrollbar_name + ) + ); + if constexpr (std::is_same_v) { using enum GFXButtonStateTexture::ButtonState; for (GFXButtonStateTexture::ButtonState state : { HOVER, PRESSED }) { - ERR_FAIL_NULL_V_MSG(texture->get_button_state_texture(state), false, vformat( - "Failed to generate %s texture for %s element %s for GUIScrollbar %s!", - GFXButtonStateTexture::button_state_to_name(state), target, element_name, gui_scrollbar_name - )); + ERR_FAIL_NULL_V_MSG( + texture->get_button_state_texture(state), false, + vformat( + "Failed to generate %s texture for %s element %s for GUIScrollbar %s!", + GFXButtonStateTexture::button_state_to_name(state), target, element_name, gui_scrollbar_name + ) + ); } } return true; @@ -432,28 +441,21 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { _calculate_rects(); - auto adjust_for_min_and_step_size = [ - min_value = gui_scrollbar->get_min_value(), - step_size = gui_scrollbar->get_step_size() - ](const int32_t val)->int32_t { + auto adjust_for_min_and_step_size // + = [min_value = gui_scrollbar->get_min_value(), + step_size = gui_scrollbar->get_step_size()](const int32_t val) -> int32_t { return (val - min_value) / step_size; }; const bool was_blocking_signals = is_blocking_signals(); if (!was_blocking_signals) { - set_block_signals(true); //only emit 1 signal via set_value + set_block_signals(true); // only emit 1 signal via set_value } - set_step_count( - adjust_for_min_and_step_size(gui_scrollbar->get_max_value()) - ); + set_step_count(adjust_for_min_and_step_size(gui_scrollbar->get_max_value())); + + set_scale(gui_scrollbar->get_min_value(), gui_scrollbar->get_step_size(), 1); - set_scale( - gui_scrollbar->get_min_value(), - gui_scrollbar->get_step_size(), - 1 - ); - set_range_limits( adjust_for_min_and_step_size(gui_scrollbar->get_range_limit_min()), adjust_for_min_and_step_size(gui_scrollbar->get_range_limit_max()) @@ -463,9 +465,7 @@ Error GUIScrollbar::set_gui_scrollbar(GUI::Scrollbar const* new_gui_scrollbar) { set_block_signals(false); } - set_value( - adjust_for_min_and_step_size(gui_scrollbar->get_start_value()) - ); + set_value(adjust_for_min_and_step_size(gui_scrollbar->get_start_value())); return ERR(ret); } @@ -474,9 +474,7 @@ Error GUIScrollbar::set_gui_scrollbar_name(String const& gui_scene, String const if (gui_scene.is_empty() && gui_scrollbar_name.is_empty()) { return set_gui_scrollbar(nullptr); } - ERR_FAIL_COND_V_MSG( - gui_scene.is_empty() || gui_scrollbar_name.is_empty(), FAILED, "GUI scene or scrollbar name is empty!" - ); + ERR_FAIL_COND_V_MSG(gui_scene.is_empty() || gui_scrollbar_name.is_empty(), FAILED, "GUI scene or scrollbar name is empty!"); GUI::Element const* gui_element = UITools::get_gui_element(gui_scene, gui_scrollbar_name); ERR_FAIL_NULL_V(gui_element, FAILED); @@ -532,7 +530,9 @@ float GUIScrollbar::get_value_scaled() const { void GUIScrollbar::set_step_count(const int32_t new_step_count) { if (new_step_count < 0) { - Logger::warning(fmt::format("Ignoring set_step_count to {} on GUIScrollbar {}", new_step_count, gui_scrollbar->get_name())); + Logger::warning( + fmt::format("Ignoring set_step_count to {} on GUIScrollbar {}", new_step_count, gui_scrollbar->get_name()) + ); return; } step_count = new_step_count; @@ -544,9 +544,7 @@ void GUIScrollbar::set_step_count(const int32_t new_step_count) { } } void GUIScrollbar::set_scale( - const fixed_point_t new_offset, - const int32_t new_scale_numerator, - const int32_t new_scale_denominator + const fixed_point_t new_offset, const int32_t new_scale_numerator, const int32_t new_scale_denominator ) { if (new_scale_numerator == 0) { Logger::warning(fmt::format("Ignoring set_scale with numerator 0 on GUIScrollbar {}", gui_scrollbar->get_name())); @@ -561,12 +559,14 @@ void GUIScrollbar::set_scale( scale_denominator = new_scale_denominator; emit_value_changed(); } + void GUIScrollbar::set_range_limits( - const std::optional new_lower_range_limit, - const std::optional new_upper_range_limit + const std::optional new_lower_range_limit, const std::optional new_upper_range_limit ) { if (!range_limited) { - Logger::warning(fmt::format("Ignoring set_range_limits of non-range-limited GUIScrollbar {}", gui_scrollbar->get_name())); + Logger::warning( // + fmt::format("Ignoring set_range_limits of non-range-limited GUIScrollbar {}", gui_scrollbar->get_name()) + ); return; } @@ -580,23 +580,16 @@ void GUIScrollbar::set_range_limits( } } void GUIScrollbar::set_range_limits_fp( - const std::optional new_lower_range_limit, - const std::optional new_upper_range_limit + const std::optional new_lower_range_limit, const std::optional new_upper_range_limit ) { set_range_limits( - new_lower_range_limit.has_value() - ? _fp_to_value(new_lower_range_limit.value()) - : std::optional{}, - new_upper_range_limit.has_value() - ? _fp_to_value(new_upper_range_limit.value()) - : std::optional{} + new_lower_range_limit.has_value() ? _fp_to_value(new_lower_range_limit.value()) : std::optional {}, + new_upper_range_limit.has_value() ? _fp_to_value(new_upper_range_limit.value()) : std::optional {} ); } + void GUIScrollbar::set_range_limits_and_value_from_slider_value(SliderValue const& slider_value) { - set_range_limits_fp( - slider_value.get_min(), - slider_value.get_max() - ); + set_range_limits_fp(slider_value.get_min(), slider_value.get_max()); set_scaled_value(slider_value.get_value()); } @@ -696,7 +689,7 @@ void GUIScrollbar::_notification(int what) { switch (what) { case NOTIFICATION_VISIBILITY_CHANGED: - case NOTIFICATION_MOUSE_EXIT: { + case NOTIFICATION_MOUSE_EXIT: { hover_slider = false; hover_track = false; hover_less = false; diff --git a/extension/src/openvic-extension/classes/GUIScrollbar.hpp b/extension/src/openvic-extension/classes/GUIScrollbar.hpp index d9ced3c4..f8f6b984 100644 --- a/extension/src/openvic-extension/classes/GUIScrollbar.hpp +++ b/extension/src/openvic-extension/classes/GUIScrollbar.hpp @@ -16,7 +16,7 @@ namespace OpenVic { struct SliderValue; class GUIScrollbar : public godot::Control { - GDCLASS(GUIScrollbar, godot::Control) + GDCLASS(GUIScrollbar, godot::Control); GUI_TOOLTIP_DEFINITIONS @@ -119,22 +119,14 @@ namespace OpenVic { float get_value_scaled() const; void set_step_count(const int32_t new_step_count); - void set_scale( - const fixed_point_t new_offset, - const int32_t new_scale_numerator, - const int32_t new_scale_denominator - ); + void set_scale(const fixed_point_t new_offset, const int32_t new_scale_numerator, const int32_t new_scale_denominator); void set_range_limits( - const std::optional new_lower_range_limit, - const std::optional new_upper_range_limit + const std::optional new_lower_range_limit, const std::optional new_upper_range_limit ); void set_range_limits_fp( - const std::optional new_lower_range_limit, - const std::optional new_upper_range_limit - ); - void set_range_limits_and_value_from_slider_value( - SliderValue const& slider_value + const std::optional new_lower_range_limit, const std::optional new_upper_range_limit ); + void set_range_limits_and_value_from_slider_value(SliderValue const& slider_value); /* Override the main dimension of gui_scollbar's size with the specified length. */ void set_length_override(real_t new_length_override); diff --git a/extension/src/openvic-extension/classes/GUITextureRect.hpp b/extension/src/openvic-extension/classes/GUITextureRect.hpp index 6fc81237..18ce74e4 100644 --- a/extension/src/openvic-extension/classes/GUITextureRect.hpp +++ b/extension/src/openvic-extension/classes/GUITextureRect.hpp @@ -6,7 +6,7 @@ namespace OpenVic { class GUITextureRect : public godot::TextureRect { - GDCLASS(GUITextureRect, godot::TextureRect) + GDCLASS(GUITextureRect, godot::TextureRect); GUI_TOOLTIP_DEFINITIONS diff --git a/extension/src/openvic-extension/classes/MapMesh.hpp b/extension/src/openvic-extension/classes/MapMesh.hpp index 092521e1..8ff64694 100644 --- a/extension/src/openvic-extension/classes/MapMesh.hpp +++ b/extension/src/openvic-extension/classes/MapMesh.hpp @@ -4,7 +4,7 @@ namespace OpenVic { class MapMesh : public godot::PrimitiveMesh { - GDCLASS(MapMesh, godot::PrimitiveMesh) + GDCLASS(MapMesh, godot::PrimitiveMesh); float aspect_ratio = 2.0f, repeat_proportion = 0.5f; int32_t subdivide_w = 0, subdivide_d = 0; diff --git a/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.hpp b/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.hpp index 91f00a1d..e697c974 100644 --- a/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.hpp +++ b/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.hpp @@ -11,7 +11,7 @@ namespace OpenVic { class StyleBoxWithSound : public godot::StyleBox { - GDCLASS(StyleBoxWithSound, godot::StyleBox) + GDCLASS(StyleBoxWithSound, godot::StyleBox); godot::Ref style_box; godot::StringName audio_bus; diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp index b24b3d1c..37c33c3f 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.cpp +++ b/extension/src/openvic-extension/singletons/AssetManager.cpp @@ -48,8 +48,7 @@ Ref AssetManager::_load_image(StringName const& path, bool flip_y) { const Ref image = Utilities::load_godot_image(lookedup_path); ERR_FAIL_COND_V_MSG( - image.is_null() || image->is_empty(), nullptr, - vformat("Failed to load image: %s (looked up: %s)", path, lookedup_path) + image.is_null() || image->is_empty(), nullptr, vformat("Failed to load image: %s (looked up: %s)", path, lookedup_path) ); if (image->detect_alpha() != Image::ALPHA_NONE) { image->fix_alpha_edges(); diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp index 3728bb11..a2af4c52 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.hpp +++ b/extension/src/openvic-extension/singletons/AssetManager.hpp @@ -13,16 +13,16 @@ namespace OpenVic { class AssetManager : public godot::Object { - GDCLASS(AssetManager, godot::Object) + GDCLASS(AssetManager, godot::Object); static inline AssetManager* _singleton = nullptr; public: enum LoadFlags { - LOAD_FLAG_NONE = 0, - LOAD_FLAG_CACHE_IMAGE = 1 << 0, + LOAD_FLAG_NONE = 0, + LOAD_FLAG_CACHE_IMAGE = 1 << 0, LOAD_FLAG_CACHE_TEXTURE = 1 << 1, - LOAD_FLAG_FLIP_Y = 1 << 2 + LOAD_FLAG_FLIP_Y = 1 << 2 }; private: @@ -53,7 +53,9 @@ namespace OpenVic { * load flag is set then the loaded image will be stored in the AssetManager's image cache for future access; if the * flip y load flag is set then the image will be flipped vertically before being returned (if the image is already * in the cache then no flipping will occur, regardless of whether it was originally flipped or not). */ - godot::Ref get_image(godot::StringName const& path, godot::BitField load_flags = LOAD_FLAG_CACHE_IMAGE); + godot::Ref get_image( // + godot::StringName const& path, godot::BitField load_flags = LOAD_FLAG_CACHE_IMAGE + ); /* Create a texture from an image found at the specified path relative to the game defines, fist checking the * AssetManager's texture cache in case it has already been loaded, and returning nullptr if image loading or texture @@ -62,11 +64,11 @@ namespace OpenVic { * AssetManager's texture cache for future access; if the flip y load flag is set then the image will be flipped * vertically before being used to create the texture (if the image is already in the cache then no flipping will * occur, regardless of whether it was originally flipped or not). */ - godot::Ref get_texture( + godot::Ref get_texture( // godot::StringName const& path, godot::BitField load_flags = LOAD_FLAG_CACHE_TEXTURE ); - static godot::Ref make_stylebox_texture( + static godot::Ref make_stylebox_texture( // godot::Ref const& texture, godot::Vector2 const& border = {} ); @@ -75,9 +77,9 @@ namespace OpenVic { godot::Ref get_font(godot::StringName const& name); private: - godot::Ref PROPERTY(currency_texture_big); // 32x32 + godot::Ref PROPERTY(currency_texture_big); // 32x32 godot::Ref PROPERTY(currency_texture_medium); // 24x24 - godot::Ref PROPERTY(currency_texture_small); // 16x16 + godot::Ref PROPERTY(currency_texture_small); // 16x16 godot::Ref PROPERTY(missing_leader_texture); diff --git a/extension/src/openvic-extension/singletons/Checksum.hpp b/extension/src/openvic-extension/singletons/Checksum.hpp index 532a50d5..9d64a9f7 100644 --- a/extension/src/openvic-extension/singletons/Checksum.hpp +++ b/extension/src/openvic-extension/singletons/Checksum.hpp @@ -6,7 +6,7 @@ namespace OpenVic { class Checksum : public godot::Object { - GDCLASS(Checksum, godot::Object) + GDCLASS(Checksum, godot::Object); static inline Checksum* _singleton = nullptr; diff --git a/extension/src/openvic-extension/singletons/CursorSingleton.cpp b/extension/src/openvic-extension/singletons/CursorSingleton.cpp index 3339df8c..d4af6906 100644 --- a/extension/src/openvic-extension/singletons/CursorSingleton.cpp +++ b/extension/src/openvic-extension/singletons/CursorSingleton.cpp @@ -4,39 +4,39 @@ #include #include +#include #include #include #include +#include #include #include #include #include -#include -#include #include -#include -#include + +#include "openvic-extension/utility/ClassBindings.hpp" +#include "openvic-extension/utility/Utilities.hpp" using namespace godot; using namespace OpenVic; void CursorSingleton::_bind_methods() { OV_BIND_METHOD(CursorSingleton::load_cursors); - OV_BIND_METHOD(CursorSingleton::get_frames, {"cursor_name","resolution_index"}, "normal", 0); - OV_BIND_METHOD(CursorSingleton::get_hotspots, {"cursor_name","resolution_index"}, "normal", 0); - OV_BIND_METHOD(CursorSingleton::get_animation_length, {"cursor_name"}, "normal"); - OV_BIND_METHOD(CursorSingleton::get_display_rates, {"cursor_name"}, "normal"); - OV_BIND_METHOD(CursorSingleton::get_sequence, {"cursor_name"}, "normal"); - OV_BIND_METHOD(CursorSingleton::get_resolutions, {"cursor_name"}, "normal"); - OV_BIND_METHOD(CursorSingleton::generate_resolution, {"cursor_name", "base_resolution_index", "target_resolution"}, "normal", 0, Vector2(64,64)); + OV_BIND_METHOD(CursorSingleton::get_frames, { "cursor_name", "resolution_index" }, "normal", 0); + OV_BIND_METHOD(CursorSingleton::get_hotspots, { "cursor_name", "resolution_index" }, "normal", 0); + OV_BIND_METHOD(CursorSingleton::get_animation_length, { "cursor_name" }, "normal"); + OV_BIND_METHOD(CursorSingleton::get_display_rates, { "cursor_name" }, "normal"); + OV_BIND_METHOD(CursorSingleton::get_sequence, { "cursor_name" }, "normal"); + OV_BIND_METHOD(CursorSingleton::get_resolutions, { "cursor_name" }, "normal"); + OV_BIND_METHOD( + CursorSingleton::generate_resolution, { "cursor_name", "base_resolution_index", "target_resolution" }, "normal", 0, + Vector2(64, 64) + ); OV_BIND_METHOD(CursorSingleton::get_cursor_names); - ADD_PROPERTY(PropertyInfo( - Variant::ARRAY, - "cursor_names", PROPERTY_HINT_ARRAY_TYPE, - "StringName"), - "", "get_cursor_names"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "cursor_names", PROPERTY_HINT_ARRAY_TYPE, "StringName"), "", "get_cursor_names"); } CursorSingleton* CursorSingleton::get_singleton() { @@ -72,7 +72,9 @@ PackedVector2Array CursorSingleton::get_hotspots(StringName const& name, int32_t ERR_FAIL_COND_V_MSG(it == cursors.end(), {}, vformat("Cursor \"%s\" not found", name)); std::vector const& hotspots = it->second.hotspots; - ERR_FAIL_INDEX_V_MSG(res_index, hotspots.size(), {}, vformat("Invalid hotspot index for cursor \"%s\": %d", name, res_index)); + ERR_FAIL_INDEX_V_MSG( + res_index, hotspots.size(), {}, vformat("Invalid hotspot index for cursor \"%s\": %d", name, res_index) + ); return hotspots[res_index]; } @@ -80,7 +82,7 @@ PackedVector2Array CursorSingleton::get_hotspots(StringName const& name, int32_t int32_t CursorSingleton::get_animation_length(StringName const& name) const { const cursor_map_t::const_iterator it = cursors.find(name); ERR_FAIL_COND_V_MSG(it == cursors.end(), {}, vformat("Cursor \"%s\" not found", name)); - + return it->second.animation_length; } @@ -149,42 +151,42 @@ Error CursorSingleton::load_cursors() { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V_MSG(game_singleton, FAILED, "Error retrieving GameSingleton"); - //there is also a png file in the folder we don't want to bother loading - //so don't just load everything in the directory + // there is also a png file in the folder we don't want to bother loading + // so don't just load everything in the directory + + // We need to load both ".cur" and ".CUR" files + Dataloader::path_vector_t cursor_files = + game_singleton->get_dataloader().lookup_files_in_dir_recursive(cursor_directory, ".cur"); - //We need to load both ".cur" and ".CUR" files - Dataloader::path_vector_t cursor_files = game_singleton->get_dataloader() - .lookup_files_in_dir_recursive(cursor_directory, ".cur"); + Dataloader::path_vector_t CURsor_files = + game_singleton->get_dataloader().lookup_files_in_dir_recursive(cursor_directory, ".CUR"); + cursor_files.insert(std::end(cursor_files), std::begin(CURsor_files), std::end(CURsor_files)); - Dataloader::path_vector_t CURsor_files = game_singleton->get_dataloader() - .lookup_files_in_dir_recursive(cursor_directory, ".CUR"); - cursor_files.insert(std::end(cursor_files),std::begin(CURsor_files),std::end(CURsor_files)); + Dataloader::path_vector_t animated_cursor_files = + game_singleton->get_dataloader().lookup_files_in_dir_recursive(cursor_directory, ".ani"); - Dataloader::path_vector_t animated_cursor_files = game_singleton->get_dataloader() - .lookup_files_in_dir_recursive(cursor_directory, ".ani"); - - if (cursor_files.empty() && animated_cursor_files.empty()){ + if (cursor_files.empty() && animated_cursor_files.empty()) { Logger::error("failed to load cursors: no files in cursors directory"); return FAILED; } Error ret = OK; - for(fs::path const& file_name : cursor_files) { + for (fs::path const& file_name : cursor_files) { String file = Utilities::std_to_godot_string(file_name.string()); StringName name = _to_define_file_name(file); - if (!_load_cursor_cur(name,file)){ + if (!_load_cursor_cur(name, file)) { Logger::error("failed to load normal cursor at path ", file_name); ret = FAILED; } } - for(fs::path const& file_name : animated_cursor_files) { + for (fs::path const& file_name : animated_cursor_files) { String file = Utilities::std_to_godot_string(file_name.string()); StringName name = _to_define_file_name(file); - if (!_load_cursor_ani(name,file)){ + if (!_load_cursor_ani(name, file)) { Logger::error("failed to load animated cursor at path ", file_name); ret = FAILED; } @@ -193,19 +195,16 @@ Error CursorSingleton::load_cursors() { return ret; } -static constexpr int32_t _reverser_lookup[] { - 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, - 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf -}; -static constexpr int32_t _reverse_bits(int32_t byte, int32_t bits_per_pixel=8) { +static constexpr int32_t _reverser_lookup[] { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf }; +static constexpr int32_t _reverse_bits(int32_t byte, int32_t bits_per_pixel = 8) { int32_t a = _reverser_lookup[(byte & 0b1111)] << 4; int32_t b = _reverser_lookup[byte >> 4]; int32_t c = b | a; - return c >> (8-bits_per_pixel); + return c >> (8 - bits_per_pixel); } -static constexpr int32_t _rotate_right(int32_t byte, int32_t size=8) { - return ((byte & 0b1) << (size-1)) | (byte >> 1); +static constexpr int32_t _rotate_right(int32_t byte, int32_t size = 8) { + return ((byte & 0b1) << (size - 1)) | (byte >> 1); } static int32_t _load_int_256(Ref const& file) { @@ -229,42 +228,42 @@ static constexpr int32_t _select_bits(uint8_t const* data, int32_t row_start, in Logger::error("Attempted to select bits outside of a byte."); return 0; } - int32_t byte = _reverse_bits(*(data+row_start+byte_index)); + int32_t byte = _reverse_bits(*(data + row_start + byte_index)); int32_t selected = (byte >> bit_in_byte_index) & ((1 << bit_count) - 1); - //TODO: questionable hack, nothing in the spec suggests we should need to do this - if (bit_count > 1 && selected != 0){ - return _rotate_right(selected,4); + // TODO: questionable hack, nothing in the spec suggests we should need to do this + if (bit_count > 1 && selected != 0) { + return _rotate_right(selected, 4); } return selected; } -static constexpr bool _read_AND_mask( - uint8_t const* data, int32_t pixel_x, int32_t pixel_y, int32_t x_dimension, int32_t offset) { - +static constexpr bool +_read_AND_mask(uint8_t const* data, int32_t pixel_x, int32_t pixel_y, int32_t x_dimension, int32_t offset) { int32_t row_start = _get_row_start(x_dimension, pixel_y, 1); - int32_t and_bit = _select_bits(data, row_start + offset,pixel_x, 1); + int32_t and_bit = _select_bits(data, row_start + offset, pixel_x, 1); return !and_bit; } static void _pixel_palette_lookup( - PackedByteArray const& data, PackedByteArray& pixel_data, uint32_t i, - PackedByteArray const& palette, int32_t coord_x, int32_t coord_y, int32_t x_dimension, - int32_t offset, bool transparent, int32_t bits_per_pixel) { - + PackedByteArray const& data, PackedByteArray& pixel_data, uint32_t i, PackedByteArray const& palette, int32_t coord_x, + int32_t coord_y, int32_t x_dimension, int32_t offset, bool transparent, int32_t bits_per_pixel +) { + int32_t row_start = _get_row_start(x_dimension, coord_y, bits_per_pixel); - int32_t pixel_bits = _select_bits(data.ptr(), row_start + offset, coord_x*bits_per_pixel, bits_per_pixel); - - if ((pixel_bits+1)*4 > palette.size()){ + int32_t pixel_bits = _select_bits(data.ptr(), row_start + offset, coord_x * bits_per_pixel, bits_per_pixel); + + if ((pixel_bits + 1) * 4 > palette.size()) { Logger::error("attempted to select invalid colour palette entry, ", pixel_bits); return; } - - //pixel bits serves as an index into the colour palette. We need to multiply the index by the number of bytes per colour (4) - pixel_data[(i*4) + 0] = palette[pixel_bits*4 + 0]; - pixel_data[(i*4) + 1] = palette[pixel_bits*4 + 1]; - pixel_data[(i*4) + 2] = palette[pixel_bits*4 + 2]; - pixel_data[(i*4) + 3] = 0xFF * transparent; //a + + // pixel bits serves as an index into the colour palette. We need to multiply the index by the number of bytes per colour + // (4) + pixel_data[(i * 4) + 0] = palette[pixel_bits * 4 + 0]; + pixel_data[(i * 4) + 1] = palette[pixel_bits * 4 + 1]; + pixel_data[(i * 4) + 2] = palette[pixel_bits * 4 + 2]; + pixel_data[(i * 4) + 3] = 0xFF * transparent; // a } /* @@ -273,37 +272,35 @@ the spec (per daubnet) says we should pad bytes to end things on 32bit boundarie but the singular example of a 24bit cursor found on the internet does things like this. So emit a warning when trying to load one of these */ -static void _read_24bit_pixel( - PackedByteArray const& image_data, PackedByteArray& pixel_data, - int32_t i, int32_t offset, bool opaque) { - - if((i+1)*3 > image_data.size()){ +static void _read_24bit_pixel( // + PackedByteArray const& image_data, PackedByteArray& pixel_data, int32_t i, int32_t offset, bool opaque +) { + if ((i + 1) * 3 > image_data.size()) { Logger::error("Pixel ", i, "tried to read from a pixel data array of max size ", pixel_data.size()); return; } - pixel_data[(i*4) + 0] = image_data[offset + (i*3) + 2]; //r - pixel_data[(i*4) + 1] = image_data[offset + (i*3) + 1]; //g - pixel_data[(i*4) + 2] = image_data[offset + (i*3) + 0]; //b - pixel_data[(i*4) + 3] = 0xFF * opaque; //a + pixel_data[(i * 4) + 0] = image_data[offset + (i * 3) + 2]; // r + pixel_data[(i * 4) + 1] = image_data[offset + (i * 3) + 1]; // g + pixel_data[(i * 4) + 2] = image_data[offset + (i * 3) + 0]; // b + pixel_data[(i * 4) + 3] = 0xFF * opaque; // a } -static void _read_32bit_pixel( - PackedByteArray const& image_data, PackedByteArray& pixel_data, - int32_t i, int32_t offset, bool opaque) { - - if((i+1)*4 > image_data.size()){ +static void _read_32bit_pixel( // + PackedByteArray const& image_data, PackedByteArray& pixel_data, int32_t i, int32_t offset, bool opaque +) { + if ((i + 1) * 4 > image_data.size()) { Logger::error("Pixel ", i, "tried to read from a pixel data array of max size ", pixel_data.size()); return; } - pixel_data[(i*4) + 0] = image_data[offset + (i*4) + 2]; //r - pixel_data[(i*4) + 1] = image_data[offset + (i*4) + 1]; //g - pixel_data[(i*4) + 2] = image_data[offset + (i*4) + 0]; //b - pixel_data[(i*4) + 3] = image_data[offset + (i*4) + 3] * opaque; //a + pixel_data[(i * 4) + 0] = image_data[offset + (i * 4) + 2]; // r + pixel_data[(i * 4) + 1] = image_data[offset + (i * 4) + 1]; // g + pixel_data[(i * 4) + 2] = image_data[offset + (i * 4) + 0]; // b + pixel_data[(i * 4) + 3] = image_data[offset + (i * 4) + 3] * opaque; // a } -//used to load a .cur file from a file (could be the a whole .cur file, or a .cur within a .ani file) +// used to load a .cur file from a file (could be the a whole .cur file, or a .cur within a .ani file) static CursorSingleton::image_hotspot_pair_asset_t _load_pair(Ref const& file) { CursorSingleton::image_hotspot_pair_asset_t pairs = {}; @@ -312,15 +309,15 @@ static CursorSingleton::image_hotspot_pair_asset_t _load_pair(Ref co //.cur header int32_t reserved = file->get_16(); - int32_t type = file->get_16(); //1=ico, 2=cur + int32_t type = file->get_16(); // 1=ico, 2=cur int32_t images_count = file->get_16(); - - //all the images - for(int32_t i=0; iget_8(); - file->get_8(); //int32_t img_reserved - + file->get_8(); // int32_t img_reserved + Vector2i hotspot = Vector2i(); hotspot.x = file->get_16(); hotspot.y = file->get_16(); @@ -328,125 +325,117 @@ static CursorSingleton::image_hotspot_pair_asset_t _load_pair(Ref co int32_t data_size = std::min(static_cast(file->get_32()), file->get_length() - file->get_position()); int32_t data_offset = file->get_32(); - //This image header information is sequential in the data, but the images aren't necessarily - // so save the current position, get the image data and return so we're ready for the next image header + // This image header information is sequential in the data, but the images aren't necessarily + // so save the current position, get the image data and return so we're ready for the next image header int32_t end_of_image_header = file->get_position(); - file->seek(data_offset+base_offset); + file->seek(data_offset + base_offset); PackedByteArray const& image_data = file->get_buffer(data_size); file->seek(end_of_image_header); Ref image = Ref(); image.instantiate(); - + // PNGs are stored in their entirety, so use Godot's internal loader - if (image_data.slice(1,4).get_string_from_ascii() == "PNG") { + if (image_data.slice(1, 4).get_string_from_ascii() == "PNG") { image->load_png_from_buffer(image_data); - } - else { //BMP based cursor, have to load this manually - //int32_t dib_header_size = image_data.decode_u32(0); + } else { // BMP based cursor, have to load this manually + // int32_t dib_header_size = image_data.decode_u32(0); - //this is the combined sized of the picture and the transparency bitmask - // (ex. 32x32 dimension image becomes 32x64 here) - //Vector2i combined_dimensions = Vector2i(image_data.decode_u32(4),image_data.decode_u32(8)); - //int32_t colour_planes = image_data.decode_u16(12); + // this is the combined sized of the picture and the transparency bitmask + // (ex. 32x32 dimension image becomes 32x64 here) + // Vector2i combined_dimensions = Vector2i(image_data.decode_u32(4),image_data.decode_u32(8)); + // int32_t colour_planes = image_data.decode_u16(12); int32_t bits_per_pixel = image_data.decode_u16(14); - if (bits_per_pixel <= 8 || bits_per_pixel == 24){ + if (bits_per_pixel <= 8 || bits_per_pixel == 24) { Logger::warning("Attempting to import ", bits_per_pixel, "bit cursor, this isn't guaranteed to work"); - } - else if (bits_per_pixel != 32){ - Logger::error("Invalid or Unsupported bits per pixel while loading cursor image, bpp: ", bits_per_pixel, "loading blank image instead"); + } else if (bits_per_pixel != 32) { + Logger::error( + "Invalid or Unsupported bits per pixel while loading cursor image, bpp: ", bits_per_pixel, + "loading blank image instead" + ); } int32_t size = image_data.decode_u32(20); - Vector2i resolution = Vector2i(image_data.decode_s32(24),image_data.decode_s32(28)); + Vector2i resolution = Vector2i(image_data.decode_s32(24), image_data.decode_s32(28)); int32_t palette_size = image_data.decode_u32(32); - if (palette_size == 0 && bits_per_pixel <= 8){ - palette_size = 1 << bits_per_pixel; + if (palette_size == 0 && bits_per_pixel <= 8) { + palette_size = 1 << bits_per_pixel; } - //int32_t important_colours = image_data.decode_u32(36); + // int32_t important_colours = image_data.decode_u32(36); - //for BMPs with 8 bits per pixel or less, the pixel data is actually a lookup to this table here - PackedByteArray const& palette = image_data.slice(40,40+(4*palette_size)); + // for BMPs with 8 bits per pixel or less, the pixel data is actually a lookup to this table here + PackedByteArray const& palette = image_data.slice(40, 40 + (4 * palette_size)); // this is where the image data starts - int32_t offset = 40 + palette_size*4; + int32_t offset = 40 + palette_size * 4; - //where the transparency AND mask starts - int32_t mask_offset = offset + _get_row_start(dimensions.x,dimensions.y,bits_per_pixel); + // where the transparency AND mask starts + int32_t mask_offset = offset + _get_row_start(dimensions.x, dimensions.y, bits_per_pixel); PackedByteArray pixel_data = PackedByteArray(); - pixel_data.resize(dimensions.x*dimensions.y*4); + pixel_data.resize(dimensions.x * dimensions.y * 4); pixel_data.fill(255); - int32_t i=0; - for(int32_t row=0; row < dimensions.y; row++) { - for(int32_t col=0; col < dimensions.x; col++) { - Vector2i coord = Vector2i(col,row); - bool transparent = _read_AND_mask( - image_data.ptr(),coord.x,coord.y,dimensions.x,mask_offset - ); - if (bits_per_pixel <= 8){ - //mostly legacy files, these ones all use a lookup into the colour palette + int32_t i = 0; + for (int32_t row = 0; row < dimensions.y; row++) { + for (int32_t col = 0; col < dimensions.x; col++) { + Vector2i coord = Vector2i(col, row); + bool transparent = _read_AND_mask(image_data.ptr(), coord.x, coord.y, dimensions.x, mask_offset); + if (bits_per_pixel <= 8) { + // mostly legacy files, these ones all use a lookup into the colour palette _pixel_palette_lookup( - image_data, pixel_data, i, palette, coord.x, coord.y, dimensions.x, offset, transparent, bits_per_pixel + image_data, pixel_data, i, palette, coord.x, coord.y, dimensions.x, offset, transparent, + bits_per_pixel ); - }/* - else if (bits_per_pixel == 16) { //TODO - //Unsupported, error - }*/ + } /* + else if (bits_per_pixel == 16) { //TODO + //Unsupported, error + }*/ else if (bits_per_pixel == 24) { - //Support Questionable, based on 1 example on the internet as opposed to the actual spec - _read_24bit_pixel( - image_data, pixel_data, i, offset, transparent - ); - } - else if (bits_per_pixel == 32) { - //What vic actually uses - _read_32bit_pixel( - image_data, pixel_data, i, offset, transparent - ); + // Support Questionable, based on 1 example on the internet as opposed to the actual spec + _read_24bit_pixel(image_data, pixel_data, i, offset, transparent); + } else if (bits_per_pixel == 32) { + // What vic actually uses + _read_32bit_pixel(image_data, pixel_data, i, offset, transparent); } i++; } } - - image = image->create_from_data(dimensions.x,dimensions.y,false, Image::FORMAT_RGBA8,pixel_data); - //bmp images are stored bottom to top + + image = image->create_from_data(dimensions.x, dimensions.y, false, Image::FORMAT_RGBA8, pixel_data); + // bmp images are stored bottom to top image->flip_y(); } Ref image_texture = Ref(); image_texture.instantiate(); image_texture = image_texture->create_from_image(image); - - if (image_texture.is_null()){ - Logger::error("Image Texture ",Utilities::godot_to_std_string(file->get_path())," was null!"); + + if (image_texture.is_null()) { + Logger::error("Image Texture ", Utilities::godot_to_std_string(file->get_path()), " was null!"); } pairs.hotspots.push_back(hotspot); pairs.images.push_back(image_texture); - } return pairs; - } bool CursorSingleton::_load_cursor_ani(StringName const& name, String const& path) { const Ref file = FileAccess::open(path, FileAccess::ModeFlags::READ); const Error err = FileAccess::get_open_error(); - ERR_FAIL_COND_V_MSG( - err != OK || file.is_null(), false, vformat("Failed to open ani file: \"%s\"", path) - ); + ERR_FAIL_COND_V_MSG(err != OK || file.is_null(), false, vformat("Failed to open ani file: \"%s\"", path)); - //read the RIFF container - Utilities::read_riff_str(file); //riff_id - const uint64_t riff_size = std::min(static_cast(file->get_32()), file->get_length());; - Utilities::read_riff_str(file); //form_type + // read the RIFF container + Utilities::read_riff_str(file); // riff_id + const uint64_t riff_size = std::min(static_cast(file->get_32()), file->get_length()); + ; + Utilities::read_riff_str(file); // form_type - //important variables + // important variables std::vector> frames_by_resolution; std::vector hotspots_by_resolution; @@ -454,50 +443,46 @@ bool CursorSingleton::_load_cursor_ani(StringName const& name, String const& pat PackedFloat32Array display_rates; PackedInt32Array sequence; - //ani header variables + // ani header variables int32_t num_frames = 1; int32_t num_steps = 1; - Vector2i dimensions = Vector2i(1,1); + Vector2i dimensions = Vector2i(1, 1); int32_t bit_count = 1; int32_t num_planes = 1; //??? - int32_t display_rate = 1; //how long each frame should last + int32_t display_rate = 1; // how long each frame should last int32_t flags = 0; bool icon_flag = false; bool sequence_flag = false; - - while(file->get_position() < riff_size){ + while (file->get_position() < riff_size) { String id = Utilities::read_riff_str(file); int32_t size = file->get_32(); - if (id == "LIST"){ + if (id == "LIST") { String list_type = Utilities::read_riff_str(file); - } - else if (id == "anih"){ - //hack for some files, there's likely a better way - if (size == 36){ - int32_t headerSize = file->get_32(); + } else if (id == "anih") { + // hack for some files, there's likely a better way + if (size == 36) { + int32_t header_size = file->get_32(); } num_frames = file->get_32(); num_steps = file->get_32(); - dimensions = Vector2i(file->get_32(),file->get_32()); + dimensions = Vector2i(file->get_32(), file->get_32()); bit_count = file->get_32(); num_planes = file->get_32(); display_rate = file->get_32(); flags = file->get_32(); icon_flag = flags & 0x1; sequence_flag = flags & 0x2; - } - else if (id == "icon"){ - + } else if (id == "icon") { int32_t file_access_offset = file->get_position(); image_hotspot_pair_asset_t pair = _load_pair(file); - //basically pushback an array + // basically pushback an array + + // only store the resolutions from one frame + if (resolutions.is_empty()) { + for (int32_t i = 0; i < pair.images.size(); i++) { - //only store the resolutions from one frame - if (resolutions.is_empty()){ - for(int32_t i=0;i images; images.push_back(pair.images[i]); @@ -505,94 +490,84 @@ bool CursorSingleton::_load_cursor_ani(StringName const& name, String const& pat frames_by_resolution.push_back(images); hotspots_by_resolution.push_back(hotspots); - resolutions.push_back(Vector2(pair.images[i]->get_width(),pair.images[i]->get_height())); + resolutions.push_back(Vector2(pair.images[i]->get_width(), pair.images[i]->get_height())); } - - } - else { - if (pair.images.size() != frames_by_resolution.size()){ + } else { + if (pair.images.size() != frames_by_resolution.size()) { Logger::error( - "Malformatted .ani cursor file ", - Utilities::godot_to_std_string(name), + "Malformatted .ani cursor file ", Utilities::godot_to_std_string(name), " had inconsistent number of images per cursor" ); } - for(int32_t i=0; iseek(file_access_offset + size); - - } - else if (id == "seq "){ - for(int32_t i=0; iget_32()); } - } - else if (id == "rate"){ - for(int32_t i=0;iget_32()/60.0); + } else if (id == "rate") { + for (int32_t i = 0; i < num_steps; i++) { + display_rates.push_back(file->get_32() / 60.0); } - } - else { - //Various junk (JUNK, metadata we don't care about, ...) + } else { + // Various junk (JUNK, metadata we don't care about, ...) file->get_buffer(size); } - //align to even bytes - if ((file->get_position() & 1) != 0){ + // align to even bytes + if ((file->get_position() & 1) != 0) { file->get_8(); } } - //not all ani files have the sequence and rate chunks, if not, fill out these properties - //manually - if (sequence.is_empty()){ - for(int32_t i=0; i(sequence.size()), - display_rates, - sequence + std::move(hotspots_by_resolution), // + std::move(frames_by_resolution), // + resolutions, // + static_cast(sequence.size()), // + display_rates, sequence // } ); cursor_names.append(name); - + return true; } bool CursorSingleton::_load_cursor_cur(StringName const& name, String const& path) { const Ref file = FileAccess::open(path, FileAccess::ModeFlags::READ); const Error err = FileAccess::get_open_error(); - ERR_FAIL_COND_V_MSG( - err != OK || file.is_null(), false, vformat("Failed to open cur file: \"%s\"", path) - ); + ERR_FAIL_COND_V_MSG(err != OK || file.is_null(), false, vformat("Failed to open cur file: \"%s\"", path)); image_hotspot_pair_asset_t pair = _load_pair(file); - + std::vector> frames_by_resolution; std::vector hotspots_by_resolution; PackedVector2Array resolutions; - for(int32_t i=0;iget_width(),pair.images[i]->get_height())); - + for (int32_t i = 0; i < pair.images.size(); i++) { + resolutions.push_back(Vector2(pair.images[i]->get_width(), pair.images[i]->get_height())); + TypedArray frames; frames.push_back(pair.images[i]); frames_by_resolution.push_back(frames); @@ -603,15 +578,9 @@ bool CursorSingleton::_load_cursor_cur(StringName const& name, String const& pat } cursors.emplace( - name, - cursor_asset_t { - std::move(hotspots_by_resolution), - std::move(frames_by_resolution), - resolutions, - 1 - } + name, cursor_asset_t { std::move(hotspots_by_resolution), std::move(frames_by_resolution), resolutions, 1 } ); cursor_names.append(name); return true; -} \ No newline at end of file +} diff --git a/extension/src/openvic-extension/singletons/CursorSingleton.hpp b/extension/src/openvic-extension/singletons/CursorSingleton.hpp index ac50db7f..bde13606 100644 --- a/extension/src/openvic-extension/singletons/CursorSingleton.hpp +++ b/extension/src/openvic-extension/singletons/CursorSingleton.hpp @@ -1,31 +1,31 @@ #pragma once -#include -#include #include #include #include +#include +#include #include #include #include #include #include -#include #include -#include #include +#include + +#include "openvic-extension/singletons/GameSingleton.hpp" namespace OpenVic { class CursorSingleton : public godot::Object { - GDCLASS(CursorSingleton, godot::Object); static inline CursorSingleton* _singleton = nullptr; public: - //An intermediate data type to help with loading cursors. - //The size of images/hotspots arrays corresponds to resolutionsPerCursor. + // An intermediate data type to help with loading cursors. + // The size of images/hotspots arrays corresponds to resolutions_per_cursor. struct image_hotspot_pair_asset_t { std::vector hotspots; std::vector> images; @@ -37,23 +37,23 @@ namespace OpenVic { std::vector hotspots; std::vector> images; godot::PackedVector2Array resolutions; - int32_t animation_length; //1 for static cursors + int32_t animation_length; // 1 for static cursors godot::PackedFloat32Array display_rates; godot::PackedInt32Array sequence; }; - //map of "subfolder/fileName.cur/.ani" -> cursor_asset. Subfolder comes after gfx/cursor + // map of "subfolder/fileName.cur/.ani" -> cursor_asset. Subfolder comes after gfx/cursor using cursor_map_t = deque_ordered_map; cursor_map_t cursors; godot::TypedArray cursor_names; - + public: CursorSingleton(); ~CursorSingleton(); static CursorSingleton* get_singleton(); - + protected: static void _bind_methods(); @@ -64,7 +64,7 @@ namespace OpenVic { public: godot::Error load_cursors(); godot::TypedArray get_cursor_names() const; - + godot::TypedArray get_frames(godot::StringName const& name, int32_t res_index = 0) const; godot::PackedVector2Array get_hotspots(godot::StringName const& name, int32_t res_index = 0) const; int32_t get_animation_length(godot::StringName const& name) const; @@ -75,4 +75,4 @@ namespace OpenVic { void generate_resolution(godot::StringName const& name, int32_t base_res_index, godot::Vector2 target_res); }; -} \ No newline at end of file +} diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 18abb2f0..141a4bc7 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -35,7 +35,9 @@ void GameSingleton::_bind_methods() { OV_BIND_SMETHOD(setup_logger); OV_BIND_METHOD(GameSingleton::load_defines_compatibility_mode); - OV_BIND_METHOD(GameSingleton::set_compatibility_mode_roots, { "file_paths", "replace_paths" }, DEFVAL(PackedStringArray{})); + OV_BIND_METHOD( + GameSingleton::set_compatibility_mode_roots, { "file_paths", "replace_paths" }, DEFVAL(PackedStringArray {}) + ); OV_BIND_SMETHOD(search_for_game_path, { "hint_path" }, DEFVAL(String {})); OV_BIND_METHOD(GameSingleton::lookup_file_path, { "path" }); diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp index 613458cc..97094ff3 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.hpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp @@ -9,7 +9,7 @@ namespace OpenVic { class GameSingleton : public godot::Object { - GDCLASS(GameSingleton, godot::Object) + GDCLASS(GameSingleton, godot::Object); static inline GameSingleton* singleton = nullptr; diff --git a/extension/src/openvic-extension/singletons/GitInfo.hpp b/extension/src/openvic-extension/singletons/GitInfo.hpp index 899c1a38..b0e02d4b 100644 --- a/extension/src/openvic-extension/singletons/GitInfo.hpp +++ b/extension/src/openvic-extension/singletons/GitInfo.hpp @@ -4,7 +4,7 @@ #include #include -#include "openvic-simulation/utility/Getters.hpp" +#include namespace OpenVic { class GitInfo : public godot::Object { diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp index 62b3a4af..bfff39bd 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp @@ -142,8 +142,8 @@ bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t lo const StringName old_localisation = translation->get_message(godot_key); if (!old_localisation.is_empty()) { UtilityFunctions::push_warning( - "Changing translation ", godot_key, " (", Dataloader::locale_names[locale], ") from \"", - old_localisation, "\" to \"", godot_localisation, "\"" + "Changing translation ", godot_key, " (", Dataloader::locale_names[locale], ") from \"", old_localisation, + "\" to \"", godot_localisation, "\"" ); } } diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp index 9e39746b..f57da174 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp @@ -6,7 +6,7 @@ namespace OpenVic { class LoadLocalisation : public godot::Object { - GDCLASS(LoadLocalisation, godot::Object) + GDCLASS(LoadLocalisation, godot::Object); static inline LoadLocalisation* _singleton = nullptr; diff --git a/extension/src/openvic-extension/singletons/MapItemSingleton.cpp b/extension/src/openvic-extension/singletons/MapItemSingleton.cpp index f9567f19..3b09cf98 100644 --- a/extension/src/openvic-extension/singletons/MapItemSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MapItemSingleton.cpp @@ -1,23 +1,26 @@ #include "MapItemSingleton.hpp" + #include -#include "godot_cpp/core/error_macros.hpp" -#include "godot_cpp/variant/packed_int32_array.hpp" -#include "godot_cpp/variant/packed_vector2_array.hpp" -#include "godot_cpp/variant/typed_array.hpp" -#include "godot_cpp/variant/vector2.hpp" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/ClassBindings.hpp" #include "openvic-extension/utility/Utilities.hpp" -#include "openvic-simulation/country/CountryDefinition.hpp" -#include "openvic-simulation/country/CountryInstance.hpp" -#include "openvic-simulation/DefinitionManager.hpp" -#include "openvic-simulation/economy/BuildingType.hpp" -#include "openvic-simulation/interface/GFXObject.hpp" -#include "openvic-simulation/map/ProvinceDefinition.hpp" -#include "openvic-simulation/map/ProvinceInstance.hpp" -#include "openvic-simulation/map/State.hpp" -#include "openvic-simulation/types/Vector.hpp" using namespace godot; using namespace OpenVic; @@ -32,10 +35,9 @@ void MapItemSingleton::_bind_methods() { OV_BIND_METHOD(MapItemSingleton::get_rgo_icons); OV_BIND_METHOD(MapItemSingleton::get_national_focus_icons); OV_BIND_METHOD(MapItemSingleton::get_projections); - OV_BIND_METHOD(MapItemSingleton::get_unit_position_by_province_index,{"index"}); - OV_BIND_METHOD(MapItemSingleton::get_port_position_by_province_index,{"index"}); - OV_BIND_METHOD(MapItemSingleton::get_clicked_port_province_index, {"position"}); - + OV_BIND_METHOD(MapItemSingleton::get_unit_position_by_province_index, { "index" }); + OV_BIND_METHOD(MapItemSingleton::get_port_position_by_province_index, { "index" }); + OV_BIND_METHOD(MapItemSingleton::get_clicked_port_province_index, { "position" }); } MapItemSingleton* MapItemSingleton::get_singleton() { @@ -54,27 +56,25 @@ MapItemSingleton::~MapItemSingleton() { // repackage the billboard object into a godot dictionary for the Billboard manager to work with void MapItemSingleton::add_billboard_dict(GFX::Billboard const& billboard, TypedArray& billboard_dict_array) const { - static const StringName name_key = "name"; static const StringName texture_key = "texture"; static const StringName scale_key = "scale"; - static const StringName noOfFrames_key = "noFrames"; + static const StringName no_frames_key = "noFrames"; Dictionary dict; dict[name_key] = Utilities::std_to_godot_string(billboard.get_name()); dict[texture_key] = Utilities::std_to_godot_string(billboard.get_texture_file()); dict[scale_key] = billboard.get_scale().to_float(); - dict[noOfFrames_key] = billboard.get_no_of_frames(); + dict[no_frames_key] = billboard.get_no_of_frames(); billboard_dict_array.push_back(dict); } -//get an array of all the billboard dictionaries +// get an array of all the billboard dictionaries TypedArray MapItemSingleton::get_billboards() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); - TypedArray ret; for (std::unique_ptr const& obj : game_singleton->get_definition_manager().get_ui_manager().get_objects()) { @@ -87,7 +87,9 @@ TypedArray MapItemSingleton::get_billboards() const { return ret; } -void MapItemSingleton::add_projection_dict(GFX::Projection const& projection, TypedArray& projection_dict_array) const { +void MapItemSingleton::add_projection_dict( // + GFX::Projection const& projection, TypedArray& projection_dict_array +) const { static const StringName name_key = "name"; static const StringName texture_key = "texture"; static const StringName size_key = "size"; @@ -146,9 +148,11 @@ PackedVector2Array MapItemSingleton::get_province_positions() const { return billboard_pos; } -//includes non-existent countries, used for setting the billboard buffer size +// includes non-existent countries, used for setting the billboard buffer size int32_t MapItemSingleton::get_max_capital_count() const { - return GameSingleton::get_singleton()->get_definition_manager().get_country_definition_manager().get_country_definition_count(); + CountryDefinitionManager const& def_manager = + GameSingleton::get_singleton()->get_definition_manager().get_country_definition_manager(); + return def_manager.get_country_definition_count(); } PackedVector2Array MapItemSingleton::get_capital_positions() const { @@ -166,7 +170,7 @@ PackedVector2Array MapItemSingleton::get_capital_positions() const { for (CountryInstance const& country : country_instance_manager.get_country_instances()) { if (!country.exists() || country.get_capital() == nullptr) { - //skip non-existent or capital-less countries + // skip non-existent or capital-less countries continue; } @@ -228,7 +232,6 @@ PackedByteArray MapItemSingleton::get_rgo_icons() const { } return icons; - } /* @@ -266,64 +269,70 @@ PackedByteArray MapItemSingleton::get_national_focus_icons() const { } -Vector2 MapItemSingleton::get_unit_position_by_province_index(int32_t province_index) const { +Vector2 MapItemSingleton::get_unit_position_by_province_index(int32_t province_index) const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); + MapDefinition const& map_definition = game_singleton->get_definition_manager().get_map_definition(); - ProvinceDefinition const* province = game_singleton->get_definition_manager().get_map_definition() - .get_province_definition_by_index(province_index); + ProvinceDefinition const* province = map_definition.get_province_definition_by_index(province_index); ERR_FAIL_NULL_V_MSG(province, {}, vformat("Cannot get unit position - invalid province index: %d", province_index)); return game_singleton->normalise_map_position(province->get_unit_position()); } -Vector2 MapItemSingleton::get_port_position_by_province_index(int32_t province_index) const { +Vector2 MapItemSingleton::get_port_position_by_province_index(int32_t province_index) const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); + DefinitionManager const& definition_manager = game_singleton->get_definition_manager(); + MapDefinition const& map_definition = definition_manager.get_map_definition(); - ProvinceDefinition const* province = game_singleton->get_definition_manager().get_map_definition() - .get_province_definition_by_index(province_index); + ProvinceDefinition const* province = map_definition.get_province_definition_by_index(province_index); ERR_FAIL_NULL_V_MSG(province, {}, vformat("Cannot get port position - invalid province index: %d", province_index)); - ERR_FAIL_COND_V_MSG(!province->has_port(), {},vformat("Cannot get port position, province has no port, index: %d", province_index) ); + ERR_FAIL_COND_V_MSG( + !province->has_port(), {}, vformat("Cannot get port position, province has no port, index: %d", province_index) + ); - BuildingType const* port_building_type = game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager().get_port_building_type(); + BuildingTypeManager const& building_type_manager = definition_manager.get_economy_manager().get_building_type_manager(); + BuildingType const* port_building_type = building_type_manager.get_port_building_type(); fvec2_t const* port_position = province->get_building_position(port_building_type); - //no null check because province->has_port() condition passed, already verifying that this isn't null + // no null check because province->has_port() condition passed, already verifying that this isn't null return game_singleton->normalise_map_position(*port_position); } -static constexpr real_t port_radius = 0.0006_real; //how close we have to click for a detection +static constexpr real_t port_radius = 0.0006_real; // how close we have to click for a detection -//Searches provinces near the one clicked and attempts to find a port within the port_radius of the click position +// Searches provinces near the one clicked and attempts to find a port within the port_radius of the click position int32_t MapItemSingleton::get_clicked_port_province_index(Vector2 click_position) const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); + DefinitionManager const& definition_manager = game_singleton->get_definition_manager(); + MapDefinition const& map_definition = definition_manager.get_map_definition(); int32_t initial_province_index = game_singleton->get_province_index_from_uv_coords(click_position); - ProvinceDefinition const* province = game_singleton->get_definition_manager().get_map_definition() - .get_province_definition_by_index(initial_province_index); + ProvinceDefinition const* province = map_definition.get_province_definition_by_index(initial_province_index); ERR_FAIL_NULL_V_MSG(province, {}, vformat("Cannot get port position - invalid province index: %d", initial_province_index)); - BuildingType const* port_building_type = game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager().get_port_building_type(); - - if(province->has_port()){ + BuildingTypeManager const& building_type_manager = definition_manager.get_economy_manager().get_building_type_manager(); + BuildingType const* port_building_type = building_type_manager.get_port_building_type(); + + if (province->has_port()) { Vector2 port_position = game_singleton->normalise_map_position(*province->get_building_position(port_building_type)); - if(click_position.distance_to(port_position) <= port_radius){ + if (click_position.distance_to(port_position) <= port_radius) { return province->get_index(); } - } - else if(province->is_water()){ + } else if (province->is_water()) { // search the adjacent provinces for ones with ports - for(ProvinceDefinition::adjacency_t const& adjacency : province->get_adjacencies()) { + for (ProvinceDefinition::adjacency_t const& adjacency : province->get_adjacencies()) { ProvinceDefinition const* adjacent_province = adjacency.get_to(); - if(!adjacent_province->has_port()) { + if (!adjacent_province->has_port()) { continue; // skip provinces without ports (ie. other water provinces) } - Vector2 port_position = game_singleton->normalise_map_position(*adjacent_province->get_building_position(port_building_type)); - if(click_position.distance_to(port_position) <= port_radius){ + Vector2 port_position = + game_singleton->normalise_map_position(*adjacent_province->get_building_position(port_building_type)); + if (click_position.distance_to(port_position) <= port_radius) { return adjacent_province->get_index(); } } } return 0; -} \ No newline at end of file +} diff --git a/extension/src/openvic-extension/singletons/MapItemSingleton.hpp b/extension/src/openvic-extension/singletons/MapItemSingleton.hpp index 58e1a2b1..16bb7d8f 100644 --- a/extension/src/openvic-extension/singletons/MapItemSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MapItemSingleton.hpp @@ -2,14 +2,15 @@ #include #include + #include #include -//billboards, projections, and progress bar (no progress bar yet) +// billboards, projections, and progress bar (no progress bar yet) namespace OpenVic { class MapItemSingleton : public godot::Object { - GDCLASS(MapItemSingleton, godot::Object) + GDCLASS(MapItemSingleton, godot::Object); static inline MapItemSingleton* singleton = nullptr; @@ -23,11 +24,15 @@ namespace OpenVic { ~MapItemSingleton(); private: - void add_billboard_dict(GFX::Billboard const& billboard, godot::TypedArray& billboard_dict_array) const; + void add_billboard_dict( // + GFX::Billboard const& billboard, godot::TypedArray& billboard_dict_array + ) const; godot::TypedArray get_billboards() const; - void add_projection_dict(GFX::Projection const& projection, godot::TypedArray& projection_dict_array) const; - godot::TypedArray get_projections() const; + void add_projection_dict( // + GFX::Projection const& projection, godot::TypedArray& projection_dict_array + ) const; + godot::TypedArray get_projections() const; godot::PackedVector2Array get_province_positions() const; int32_t get_max_capital_count() const; diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index d9afbeac..c73d5f6d 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -78,9 +78,9 @@ String MenuSingleton::_get_state_name(State const& state) const { String MenuSingleton::_get_country_name(CountryInstance const& country) const { if (country.get_government_type() != nullptr && !country.get_government_type()->get_identifier().empty()) { - const String government_name_key = Utilities::std_to_godot_string(StringUtils::append_string_views( - country.get_identifier(), "_", country.get_government_type()->get_identifier() - )); + const String government_name_key = Utilities::std_to_godot_string( + StringUtils::append_string_views(country.get_identifier(), "_", country.get_government_type()->get_identifier()) + ); String government_name = tr(government_name_key); @@ -123,8 +123,8 @@ String MenuSingleton::_make_modifier_effect_value( // Apply multiplier format part { - uint8_t multiplier_power = (format >> ModifierEffect::FORMAT_MULTIPLIER_BIT_OFFSET) & - ((1 << ModifierEffect::FORMAT_MULTIPLIER_BIT_COUNT) - 1); + uint8_t multiplier_power = + (format >> ModifierEffect::FORMAT_MULTIPLIER_BIT_OFFSET) & ((1 << ModifierEffect::FORMAT_MULTIPLIER_BIT_COUNT) - 1); while (multiplier_power-- > 0) { value *= 10; } @@ -179,9 +179,10 @@ String MenuSingleton::_make_modifier_effect_value_coloured( ) const { String result = GUILabel::get_colour_marker(); - const bool is_positive_green = ( - static_cast(format_effect.get_format()) & (1 << ModifierEffect::FORMAT_POS_NEG_BIT_OFFSET) - ) == static_cast(ModifierEffect::format_t::FORMAT_PART_POS); + const bool is_positive_green = ( // + static_cast(format_effect.get_format()) & // + (1 << ModifierEffect::FORMAT_POS_NEG_BIT_OFFSET) + ) == static_cast(ModifierEffect::format_t::FORMAT_PART_POS); if (value == 0) { result += "Y"; @@ -212,16 +213,16 @@ String MenuSingleton::_make_modifier_effects_tooltip(ModifierValue const& modifi template requires std::same_as || std::same_as String MenuSingleton::_make_modifier_effect_contributions_tooltip( - T const& modifier_sum, ModifierEffect const& effect, fixed_point_t* effect_value, - String const& prefix, String const& suffix + T const& modifier_sum, ModifierEffect const& effect, fixed_point_t* effect_value, String const& prefix, String const& suffix ) const { String result; modifier_sum.for_each_contributing_modifier( effect, - [this, &effect, effect_value, &prefix, &suffix, &result]( + [this, &effect, effect_value, &prefix, &suffix, &result]( // modifier_entry_t const& modifier_entry, fixed_point_t value - ) -> void { + ) -> void // + { using enum Modifier::modifier_type_t; if (effect_value != nullptr) { @@ -248,12 +249,14 @@ String MenuSingleton::_make_modifier_effect_contributions_tooltip( return result; } +// clang-format off template String OpenVic::MenuSingleton::_make_modifier_effect_contributions_tooltip( CountryInstance const&, ModifierEffect const&, fixed_point_t*, String const&, String const& ) const; template String OpenVic::MenuSingleton::_make_modifier_effect_contributions_tooltip( ProvinceInstance const&, ModifierEffect const&, fixed_point_t*, String const&, String const& ) const; +// clang-format on String MenuSingleton::_make_rules_tooltip(RuleSet const& rules) const { if (rules.empty()) { @@ -273,8 +276,8 @@ String MenuSingleton::_make_rules_tooltip(RuleSet const& rules) const { for (auto const& [rule_group, rule_map] : rules.get_rule_groups()) { for (auto const& [rule, enabled] : rule_map) { - result += "\n" + tr(Utilities::std_to_godot_string(rule->get_localisation_key())) - + (enabled ? enabled_text : disabled_text); + result += "\n" + tr(Utilities::std_to_godot_string(rule->get_localisation_key())) + + (enabled ? enabled_text : disabled_text); } } @@ -308,26 +311,22 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const { const String impact_string = Utilities::fixed_point_to_string_dp(country->get_mobilisation_impact() * 100, 1) + "%"; - return tr( - mobilisation_impact_tooltip_localisation_key - ).replace( - mobilisation_impact_tooltip_replace_impact_key, impact_string - ).replace( - mobilisation_impact_tooltip_replace_policy_key, tr( - war_policy_issue != nullptr - ? StringName { Utilities::std_to_godot_string(war_policy_issue->get_identifier()) } - : no_issue - ) - ).replace( - mobilisation_impact_tooltip_replace_units_key, - String::num_uint64(country->get_mobilisation_max_regiment_count()) - ) + "\n" + tr( - mobilisation_impact_tooltip2_localisation_key - ).replace( - mobilisation_impact_tooltip2_replace_curr_key, String::num_uint64(country->get_regiment_count()) - ).replace( - mobilisation_impact_tooltip2_replace_impact_key, impact_string - ); + return tr(mobilisation_impact_tooltip_localisation_key) + .replace(mobilisation_impact_tooltip_replace_impact_key, impact_string) + .replace( + mobilisation_impact_tooltip_replace_policy_key, + tr(war_policy_issue != nullptr + ? StringName { Utilities::std_to_godot_string(war_policy_issue->get_identifier()) } + : no_issue) + ) + .replace( + mobilisation_impact_tooltip_replace_units_key, + String::num_uint64(country->get_mobilisation_max_regiment_count()) + ) + + "\n" + + tr(mobilisation_impact_tooltip2_localisation_key) + .replace(mobilisation_impact_tooltip2_replace_curr_key, String::num_uint64(country->get_regiment_count())) + .replace(mobilisation_impact_tooltip2_replace_impact_key, impact_string); } void MenuSingleton::_bind_methods() { @@ -341,8 +340,8 @@ void MenuSingleton::_bind_methods() { OV_BIND_METHOD(MenuSingleton::hide_tooltip); ADD_SIGNAL(MethodInfo( - _signal_update_tooltip(), PropertyInfo(Variant::STRING, "text"), - PropertyInfo(Variant::DICTIONARY, "substitution_dict"), PropertyInfo(Variant::VECTOR2, "position") + _signal_update_tooltip(), PropertyInfo(Variant::STRING, "text"), PropertyInfo(Variant::DICTIONARY, "substitution_dict"), + PropertyInfo(Variant::VECTOR2, "position") )); /* PROVINCE OVERVIEW PANEL */ @@ -387,7 +386,7 @@ void MenuSingleton::_bind_methods() { OV_BIND_METHOD(MenuSingleton::get_population_menu_distribution_info); ADD_SIGNAL(MethodInfo(_signal_population_menu_province_list_changed())); - ADD_SIGNAL( + ADD_SIGNAL( // MethodInfo(_signal_population_menu_province_list_selected_changed(), PropertyInfo(Variant::INT, "scroll_index")) ); ADD_SIGNAL(MethodInfo(_signal_population_menu_pops_changed())); @@ -523,9 +522,7 @@ void MenuSingleton::hide_tooltip() { /* PROVINCE OVERVIEW PANEL */ -static TypedArray _make_buildings_dict_array( - ProvinceInstance const* province -) { +static TypedArray _make_buildings_dict_array(ProvinceInstance const* province) { std::vector const& buildings = province->get_buildings(); if (buildings.empty()) { @@ -557,8 +554,8 @@ static TypedArray _make_buildings_dict_array( } } else { UtilityFunctions::push_error( - "Failed to resize buildings array to the correct size (", static_cast(buildings.size()), - ") for province ", Utilities::std_to_godot_string(province->get_identifier()) + "Failed to resize buildings array to the correct size (", static_cast(buildings.size()), ") for province ", + Utilities::std_to_godot_string(province->get_identifier()) ); } @@ -626,8 +623,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_terrain_type_tooltip_key] = vformat( terrain_type_template_string, tr(terrain_type_localisation_key).replace(terrain_type_replace_key, tr(terrain_type_string)), - tr(movement_cost_localisation_key), - Utilities::fixed_point_to_string_dp(terrain_type->get_movement_cost(), 2), + tr(movement_cost_localisation_key), Utilities::fixed_point_to_string_dp(terrain_type->get_movement_cost(), 2), _make_modifier_effects_tooltip(*terrain_type) ); @@ -642,9 +638,8 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const StringName controller_localisation_key = "PV_CONTROLLER"; static const String controller_template_string = "%s %s"; - ret[province_info_controller_tooltip_key] = vformat( - controller_template_string, tr(controller_localisation_key), _get_country_name(*controller) - ); + ret[province_info_controller_tooltip_key] = + vformat(controller_template_string, tr(controller_localisation_key), _get_country_name(*controller)); } ResourceGatheringOperation const& rgo = province->get_rgo(); @@ -669,12 +664,11 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ModifierEffectCache const& modifier_effect_cache = game_singleton->get_definition_manager().get_modifier_manager().get_modifier_effect_cache(); - fixed_point_t output_from_workers = 1, throughput_from_workers = 0, - output_multiplier = 1, throughput_multiplier = 1; + fixed_point_t output_from_workers = 1, throughput_from_workers = 0, output_multiplier = 1, throughput_multiplier = 1; String size_string, output_string, throughput_string; - static const String employee_effect_template_string = "\n -%s: " + GUILabel::get_colour_marker() + "Y%s" + - GUILabel::get_colour_marker() + "!: %s"; + static const String employee_effect_template_string = + "\n -%s: " + GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!: %s"; using enum Job::effect_t; @@ -685,8 +679,10 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { if (unlikely(state == nullptr)) { Logger::error( - "Province \"", province->get_identifier(), "\" has no state, preventing calculation of state-wide " - "population proportion of RGO owner pop type \"", owner_pop_type.get_identifier(), "\"" + "Province \"", province->get_identifier(), + "\" has no state, preventing calculation of state-wide " + "population proportion of RGO owner pop type \"", + owner_pop_type.get_identifier(), "\"" ); } else { fixed_point_t effect_value = @@ -702,8 +698,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { case OUTPUT: output_multiplier += effect_value; output_string += vformat( - employee_effect_template_string, - tr(owners_localisation_key), + employee_effect_template_string, tr(owners_localisation_key), tr(Utilities::std_to_godot_string(owner_pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_output_country(), effect_value, true @@ -713,16 +708,14 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { case THROUGHPUT: throughput_multiplier += effect_value; throughput_string += vformat( - employee_effect_template_string, - tr(owners_localisation_key), + employee_effect_template_string, tr(owners_localisation_key), tr(Utilities::std_to_godot_string(owner_pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_country(), effect_value, true ) ); break; - default: - break; + default: break; } } } @@ -734,12 +727,11 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { continue; } - static const String amount_of_employees_by_pop_type_template_string = "\n -" + GUILabel::get_colour_marker() + - "Y%s" + GUILabel::get_colour_marker() + "!:%d"; + static const String amount_of_employees_by_pop_type_template_string = + "\n -" + GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!:%d"; amount_of_employees_by_pop_type += vformat( - amount_of_employees_by_pop_type_template_string, - tr(Utilities::std_to_godot_string(pop_type.get_identifier())), + amount_of_employees_by_pop_type_template_string, tr(Utilities::std_to_godot_string(pop_type.get_identifier())), employees_of_type ); @@ -757,30 +749,27 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const StringName workers_localisation_key = "PRODUCTION_FACTOR_WORKER"; switch (job.get_effect_type()) { - case OUTPUT: - output_from_workers += effect_value; - output_string += vformat( - employee_effect_template_string, - tr(workers_localisation_key), - tr(Utilities::std_to_godot_string(pop_type.get_identifier())), - _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_rgo_output_country(), effect_value, true - ) - ); - break; - case THROUGHPUT: - throughput_from_workers += effect_value; - throughput_string += vformat( - employee_effect_template_string, - tr(workers_localisation_key), - tr(Utilities::std_to_godot_string(pop_type.get_identifier())), - _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_rgo_throughput_country(), effect_value, true - ) - ); - break; - default: - break; + case OUTPUT: + output_from_workers += effect_value; + output_string += vformat( + employee_effect_template_string, tr(workers_localisation_key), + tr(Utilities::std_to_godot_string(pop_type.get_identifier())), + _make_modifier_effect_value_coloured( + *modifier_effect_cache.get_rgo_output_country(), effect_value, true + ) + ); + break; + case THROUGHPUT: + throughput_from_workers += effect_value; + throughput_string += vformat( + employee_effect_template_string, tr(workers_localisation_key), + tr(Utilities::std_to_godot_string(pop_type.get_identifier())), + _make_modifier_effect_value_coloured( + *modifier_effect_cache.get_rgo_throughput_country(), effect_value, true + ) + ); + break; + default: break; } } } @@ -857,8 +846,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const StringName rgo_size_localisation_key = "RGO_SIZE"; size_string += vformat( - size_modifier_template_string, - tr(rgo_size_localisation_key), + size_modifier_template_string, tr(rgo_size_localisation_key), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_farm_rgo_size_local(), size_from_province, false ) @@ -868,8 +856,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ModifierEffectCache::good_effects_t const& good_effects = modifier_effect_cache.get_good_effects()[production_type.get_output_good()]; - fixed_point_t output_from_tech = - province->get_modifier_effect_value(*modifier_effect_cache.get_rgo_output_tech()) + + fixed_point_t output_from_tech = province->get_modifier_effect_value(*modifier_effect_cache.get_rgo_output_tech()) + province->get_modifier_effect_value(*good_effects.get_rgo_goods_output()); fixed_point_t throughput_from_tech = province->get_modifier_effect_value(*modifier_effect_cache.get_rgo_throughput_tech()) + @@ -899,9 +886,10 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { if (size_from_tech != fixed_point_t::_0) { static const StringName from_technology_localisation_key = "employ_from_tech"; - size_string += tr(from_technology_localisation_key) + _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_farm_rgo_size_global(), size_from_tech, false - ); + size_string += tr(from_technology_localisation_key) + + _make_modifier_effect_value_coloured( + *modifier_effect_cache.get_farm_rgo_size_global(), size_from_tech, false + ); } static const String tech_modifier_template_string = modifier_effect_contributions_prefix + String { "%s: %s" }; @@ -912,11 +900,8 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const StringName rgo_output_tech_localisation_key = "RGO_OUTPUT_TECH"; output_string += vformat( - tech_modifier_template_string, - tr(rgo_output_tech_localisation_key), - _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_rgo_output_tech(), output_from_tech, true - ) + tech_modifier_template_string, tr(rgo_output_tech_localisation_key), + _make_modifier_effect_value_coloured(*modifier_effect_cache.get_rgo_output_tech(), output_from_tech, true) ); } @@ -926,8 +911,7 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const StringName rgo_throughput_tech_localisation_key = "RGO_THROUGHPUT_TECH"; throughput_string += vformat( - tech_modifier_template_string, - tr(rgo_throughput_tech_localisation_key), + tech_modifier_template_string, tr(rgo_throughput_tech_localisation_key), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_tech(), throughput_from_tech, true ) @@ -959,17 +943,15 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_rgo_production_tooltip_key] = vformat( rgo_production_template_string, - tr(rgo_production_localisation_key).replace( - rgo_good_replace_key, tr(Utilities::std_to_godot_string(rgo_good.get_identifier())) - ).replace(value_replace_key, Utilities::fixed_point_to_string_dp(rgo.get_revenue_yesterday(), 3)), + tr(rgo_production_localisation_key) + .replace(rgo_good_replace_key, tr(Utilities::std_to_godot_string(rgo_good.get_identifier()))) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(rgo.get_revenue_yesterday(), 3)), tr(max_output_localisation_key).replace(curr_replace_key, Utilities::fixed_point_to_string_dp(max_output, 2)), tr(output_explanation_localisation_key), tr(base_output_localisation_key).replace(base_replace_key, Utilities::fixed_point_to_string_dp(base_output, 2)), tr(output_efficiency_localisation_key), _make_modifier_effect_value_coloured(*modifier_effect_cache.get_rgo_output_country(), output_efficiency, false), - tr(base_localisation_key), - output_string, - tr(throughput_efficiency_localisation_key), + tr(base_localisation_key), output_string, tr(throughput_efficiency_localisation_key), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_country(), throughput_efficiency, false ), @@ -982,22 +964,16 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { static const String employee_max_replace_key = "$EMPLOYEE_MAX$"; static const StringName rgo_workforce_localisation_key = "BASE_RGO_SIZE"; static const StringName province_size_localisation_key = "FROM_PROV_SIZE"; - static const String rgo_employment_template_string = "%s" + get_tooltip_separator() + "%s%s\n%s%d\n%s\n%s" + - GUILabel::get_colour_marker() + "G%d"; + static const String rgo_employment_template_string = + "%s" + get_tooltip_separator() + "%s%s\n%s%d\n%s\n%s" + GUILabel::get_colour_marker() + "G%d"; ret[province_info_rgo_employment_tooltip_key] = vformat( - rgo_employment_template_string, - tr(employment_localisation_key).replace(value_replace_key, {}), - tr(employee_count_localisation_key).replace( - employee_replace_key, String::num_int64(rgo.get_total_employees_count_cache()) - ).replace( - employee_max_replace_key, String::num_int64(rgo.get_max_employee_count_cache()) - ), - amount_of_employees_by_pop_type, - tr(rgo_workforce_localisation_key), - production_type.get_base_workforce_size(), - size_string, - tr(province_size_localisation_key), + rgo_employment_template_string, tr(employment_localisation_key).replace(value_replace_key, {}), + tr(employee_count_localisation_key) + .replace(employee_replace_key, String::num_int64(rgo.get_total_employees_count_cache())) + .replace(employee_max_replace_key, String::num_int64(rgo.get_max_employee_count_cache())), + amount_of_employees_by_pop_type, tr(rgo_workforce_localisation_key), production_type.get_base_workforce_size(), + size_string, tr(province_size_localisation_key), static_cast(rgo.get_size_multiplier()) // TODO - remove cast once variable is an int32_t ); } @@ -1011,14 +987,11 @@ Dictionary MenuSingleton::get_province_info_from_index(int32_t index) const { ret[province_info_total_population_key] = province->get_total_population(); const auto make_pie_chart_tooltip = [this]( - HasGetIdentifierAndGetColour auto const* key, String const& identifier, float weight, float total_weight - ) -> String { + HasGetIdentifierAndGetColour auto const* key, String const& identifier, + float weight, float total_weight + ) -> String { static const String format_key = "%d%% %s"; - return vformat( - format_key, - static_cast(100.0f * weight / total_weight), - tr(identifier) - ); + return vformat(format_key, static_cast(100.0f * weight / total_weight), tr(identifier)); }; GFXPieChartTexture::godot_pie_chart_data_t pop_types = @@ -1067,16 +1040,20 @@ int32_t MenuSingleton::get_province_building_count() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, 0); - return game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager() - .get_province_building_types().size(); + return game_singleton->get_definition_manager() + .get_economy_manager() + .get_building_type_manager() + .get_province_building_types() + .size(); } String MenuSingleton::get_province_building_identifier(int32_t building_index) const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, {}); - std::vector const& province_building_types = game_singleton->get_definition_manager() - .get_economy_manager().get_building_type_manager().get_province_building_types(); + BuildingTypeManager const& building_type_manager = + game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager(); + std::vector const& province_building_types = building_type_manager.get_province_building_types(); ERR_FAIL_COND_V_MSG( building_index < 0 || building_index >= province_building_types.size(), {}, vformat("Invalid province building index: %d", building_index) @@ -1106,7 +1083,8 @@ int32_t MenuSingleton::get_rgo_owner_pop_icon_index() const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, 0); - const PopType::sprite_t sprite = game_singleton->get_definition_manager().get_economy_manager().get_production_type_manager().get_rgo_owner_sprite(); + const PopType::sprite_t sprite = + game_singleton->get_definition_manager().get_economy_manager().get_production_type_manager().get_rgo_owner_sprite(); ERR_FAIL_COND_V_MSG(sprite <= 0, 0, "RGO owner sprite unset!"); return sprite; } @@ -1156,7 +1134,7 @@ Dictionary MenuSingleton::get_topbar_info() const { industrial_power_states.emplace_back(_get_state_name(*state), power); } std::sort( - industrial_power_states.begin(), industrial_power_states.end(), + industrial_power_states.begin(), industrial_power_states.end(), // [](auto const& a, auto const& b) -> bool { // Sort by greatest power, then by state name alphabetically return a.second != b.second ? a.second > b.second : a.first < b.first; @@ -1166,11 +1144,8 @@ Dictionary MenuSingleton::get_topbar_info() const { static const String state_power_template_string = "\n%s: " + GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!"; - industrial_power_tooltip += vformat( - state_power_template_string, - state_name, - Utilities::fixed_point_to_string_dp(power, 3) - ); + industrial_power_tooltip += + vformat(state_power_template_string, state_name, Utilities::fixed_point_to_string_dp(power, 3)); } // Tuple: Country identifier / Country name / Power @@ -1188,13 +1163,11 @@ Dictionary MenuSingleton::get_topbar_info() const { } ); for (auto const& [country_identifier, country_name, power] : industrial_power_from_investments) { - static const String investment_power_template_string = "\n" + GUILabel::get_flag_marker() + "%s %s: " + - GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!"; + static const String investment_power_template_string = "\n" + GUILabel::get_flag_marker() + + "%s %s: " + GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!"; industrial_power_tooltip += vformat( - investment_power_template_string, - country_identifier, - country_name, + investment_power_template_string, country_identifier, country_name, Utilities::fixed_point_to_string_dp(power, 3) ); } @@ -1216,14 +1189,13 @@ Dictionary MenuSingleton::get_topbar_info() const { static const StringName military_power_from_leaders_key = "MIL_FROM_LEADERS"; for (auto const& [source, power] : { - std::pair - { military_power_from_land_key, country->get_military_power_from_land() }, - { military_power_from_sea_key, country->get_military_power_from_sea() }, - { military_power_from_leaders_key, country->get_military_power_from_leaders() } - }) { + std::pair { military_power_from_land_key, country->get_military_power_from_land() }, + { military_power_from_sea_key, country->get_military_power_from_sea() }, + { military_power_from_leaders_key, country->get_military_power_from_leaders() } // + }) { if (power != 0) { - military_power_tooltip += "\n" + tr(source) + ": " + GUILabel::get_colour_marker() + "Y" - + Utilities::fixed_point_to_string_dp(power, 3) + GUILabel::get_colour_marker() + "!"; + military_power_tooltip += "\n" + tr(source) + ": " + GUILabel::get_colour_marker() + "Y" + + Utilities::fixed_point_to_string_dp(power, 3) + GUILabel::get_colour_marker() + "!"; } } @@ -1263,13 +1235,17 @@ Dictionary MenuSingleton::get_topbar_info() const { String current_tech_localised = tr(Utilities::std_to_godot_string(current_research->get_identifier())); - ret[research_tooltip_key] = tr(research_localisation_key).replace( - tech_replace_key, current_tech_localised - ).replace( - date_replace_key, Utilities::date_to_formatted_string(country->get_expected_research_completion_date(), false) - ) + "\n" + tr(research_invested_localisation_key).replace( - invested_replace_key, String::num_uint64(country->get_invested_research_points().to_int64_t()) - ).replace(cost_replace_key, String::num_uint64(country->get_current_research_cost().to_int64_t())); + ret[research_tooltip_key] = + tr(research_localisation_key) + .replace(tech_replace_key, current_tech_localised) + .replace( + date_replace_key, + Utilities::date_to_formatted_string(country->get_expected_research_completion_date(), false) + ) + + "\n" + + tr(research_invested_localisation_key) + .replace(invested_replace_key, String::num_uint64(country->get_invested_research_points().to_int64_t())) + .replace(cost_replace_key, String::num_uint64(country->get_current_research_cost().to_int64_t())); ret[research_key] = std::move(current_tech_localised); @@ -1310,17 +1286,21 @@ Dictionary MenuSingleton::get_topbar_info() const { daily_base_research_points += research_points; - research_points_tooltip += tr(pop_type_research_localisation_key).replace( - pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier())) - ).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(research_points, 2) - ).replace( - fraction_replace_key, Utilities::fixed_point_to_string_dp( - 100 * country->get_pop_type_proportion(*pop_type) / country->get_total_population(), 2 - ) - ).replace( - optimal_replace_key, Utilities::fixed_point_to_string_dp(100 * pop_type->get_research_leadership_optimum(), 2) - ) + "\n"; + research_points_tooltip += + tr(pop_type_research_localisation_key) + .replace(pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier()))) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(research_points, 2)) + .replace( + fraction_replace_key, + Utilities::fixed_point_to_string_dp( + 100 * country->get_pop_type_proportion(*pop_type) / country->get_total_population(), 2 + ) + ) + .replace( + optimal_replace_key, + Utilities::fixed_point_to_string_dp(100 * pop_type->get_research_leadership_optimum(), 2) + ) + + "\n"; } // Empty prefix, "\n" suffix, fitting with the potential trailing "\n" from the pop type contributions and the upcoming @@ -1333,37 +1313,37 @@ Dictionary MenuSingleton::get_topbar_info() const { // so this line has no newline characters of its own. Instead, potential lines above finish with newlines and // potential (and some guaranteed) lines below start with them. static const StringName daily_base_research_points_localisation_key = "TECH_DAILY_RESEARCHPOINTS_BASE_TOOLTIP"; - research_points_tooltip += tr(daily_base_research_points_localisation_key).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(daily_base_research_points, 2) - ); + research_points_tooltip += + tr(daily_base_research_points_localisation_key) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(daily_base_research_points, 2)); - research_points_tooltip += _make_modifier_effect_contributions_tooltip( - *country, *modifier_effect_cache.get_research_points_modifier() - ); + research_points_tooltip += + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_research_points_modifier()); const fixed_point_t research_points_modifier_from_tech = country->get_modifier_effect_value(*modifier_effect_cache.get_increase_research()); if (research_points_modifier_from_tech != fixed_point_t::_0) { static const StringName from_technology_localisation_key = "FROM_TECHNOLOGY"; - research_points_tooltip += "\n" + tr(from_technology_localisation_key) + ": " + + research_points_tooltip += + "\n" + tr(from_technology_localisation_key) + ": " + _make_modifier_effect_value_coloured( *modifier_effect_cache.get_increase_research(), research_points_modifier_from_tech, true ); } static const StringName daily_research_points_localisation_key = "TECH_DAILY_RESEARCHPOINTS_TOTAL_TOOLTIP"; - research_points_tooltip += "\n" + tr(daily_research_points_localisation_key).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(country->get_daily_research_points(), 2) - ); + research_points_tooltip += "\n" + + tr(daily_research_points_localisation_key) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(country->get_daily_research_points(), 2)); // In the base game this section is only shown when no research is set, but it's useful to show it always research_points_tooltip += "\n" + get_tooltip_separator(); static const StringName accumulated_research_points_localisation_key = "RP_ACCUMULATED"; static const String val_replace_key = "$VAL$"; - research_points_tooltip += tr(accumulated_research_points_localisation_key).replace( - val_replace_key, Utilities::fixed_point_to_string_dp(country->get_research_point_stockpile(), 1) - ); + research_points_tooltip += + tr(accumulated_research_points_localisation_key) + .replace(val_replace_key, Utilities::fixed_point_to_string_dp(country->get_research_point_stockpile(), 1)); ret[research_points_tooltip_key] = std::move(research_points_tooltip); } @@ -1414,17 +1394,21 @@ Dictionary MenuSingleton::get_topbar_info() const { monthly_base_leadership_points += leadership_points; - leadership_tooltip += tr(pop_type_leadership_localisation_key).replace( - pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier())) - ).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(leadership_points, 2) - ).replace( - fraction_replace_key, Utilities::fixed_point_to_string_dp( - 100 * country->get_pop_type_proportion(*pop_type) / country->get_total_population(), 2 - ) - ).replace( - optimal_replace_key, Utilities::fixed_point_to_string_dp(100 * pop_type->get_research_leadership_optimum(), 2) - ) + "\n"; + leadership_tooltip += + tr(pop_type_leadership_localisation_key) + .replace(pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier()))) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(leadership_points, 2)) + .replace( + fraction_replace_key, + Utilities::fixed_point_to_string_dp( + 100 * country->get_pop_type_proportion(*pop_type) / country->get_total_population(), 2 + ) + ) + .replace( + optimal_replace_key, + Utilities::fixed_point_to_string_dp(100 * pop_type->get_research_leadership_optimum(), 2) + ) + + "\n"; } // Empty prefix, "\n" suffix, fitting with the potential trailing "\n" from the pop type contributions and the upcoming @@ -1437,18 +1421,17 @@ Dictionary MenuSingleton::get_topbar_info() const { // so this line has no newline characters of its own. Instead, potential lines above finish with newlines and // potential (and some guaranteed) lines below start with them. static const StringName monthly_base_leadership_localisation_key = "TECH_DAILY_LEADERSHIP_BASE_TOOLTIP"; - leadership_tooltip += tr(monthly_base_leadership_localisation_key).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(monthly_base_leadership_points, 2) - ); + leadership_tooltip += + tr(monthly_base_leadership_localisation_key) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(monthly_base_leadership_points, 2)); - leadership_tooltip += _make_modifier_effect_contributions_tooltip( - *country, *modifier_effect_cache.get_leadership_modifier() - ); + leadership_tooltip += + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_leadership_modifier()); static const StringName monthly_leadership_points_localisation_key = "TECH_DAILY_LEADERSHIP_TOTAL_TOOLTIP"; - leadership_tooltip += "\n" + tr(monthly_leadership_points_localisation_key).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(country->get_monthly_leadership_points(), 2) - ); + leadership_tooltip += "\n" + + tr(monthly_leadership_points_localisation_key) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(country->get_monthly_leadership_points(), 2)); const fixed_point_t max_leadership_point_stockpile = definition_manager.get_define_manager().get_military_defines().get_max_leadership_point_stockpile(); @@ -1457,9 +1440,10 @@ Dictionary MenuSingleton::get_topbar_info() const { static const StringName max_leadership_points_localisation_key = "TOPBAR_LEADERSHIP_MAX"; static const String max_replace_key = "$MAX$"; - leadership_tooltip += tr(max_leadership_points_localisation_key).trim_suffix("\n").replace( - max_replace_key, Utilities::fixed_point_to_string_dp(max_leadership_point_stockpile, 1) - ); + leadership_tooltip += + tr(max_leadership_points_localisation_key) + .trim_suffix("\n") + .replace(max_replace_key, Utilities::fixed_point_to_string_dp(max_leadership_point_stockpile, 1)); } ret[leadership_tooltip_key] = std::move(leadership_tooltip); @@ -1538,7 +1522,7 @@ Error MenuSingleton::generate_search_cache() { String search_name = display_name.to_lower(); search_panel.entry_cache.push_back({ - &province, std::move(display_name), std::move(search_name), identifier.to_lower() + &province, std::move(display_name), std::move(search_name), identifier.to_lower() // }); } @@ -1549,7 +1533,10 @@ Error MenuSingleton::generate_search_cache() { search_panel.entry_cache.push_back({ // TODO - include state identifier? (region and/or split?) - &state, std::move(display_name), std::move(search_name), {} + &state, + std::move(display_name), + std::move(search_name), + {} // }); } } @@ -1560,10 +1547,8 @@ Error MenuSingleton::generate_search_cache() { String display_name = _get_country_name(country); String search_name = display_name.to_lower(); - search_panel.entry_cache.push_back({ - &country, std::move(display_name), std::move(search_name), - Utilities::std_to_godot_string(country.get_identifier()).to_lower() - }); + search_panel.entry_cache.push_back({ &country, std::move(display_name), std::move(search_name), + Utilities::std_to_godot_string(country.get_identifier()).to_lower() }); } } @@ -1600,8 +1585,7 @@ PackedStringArray MenuSingleton::get_search_result_rows(int32_t start, int32_t c } ERR_FAIL_INDEX_V_MSG( - start, search_panel.result_indices.size(), {}, - vformat("Invalid start for search panel result rows: %d", start) + start, search_panel.result_indices.size(), {}, vformat("Invalid start for search panel result rows: %d", start) ); ERR_FAIL_COND_V_MSG(count <= 0, {}, vformat("Invalid count for search panel result rows: %d", count)); diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp index e7fa63af..9056f168 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp @@ -8,8 +8,8 @@ #include #include -#include #include +#include #include #include "openvic-extension/classes/GFXPieChartTexture.hpp" @@ -33,19 +33,38 @@ namespace OpenVic { struct GUIScrollbar; class MenuSingleton : public godot::Object { - GDCLASS(MenuSingleton, godot::Object) + GDCLASS(MenuSingleton, godot::Object); static inline MenuSingleton* singleton = nullptr; public: - enum ProvinceListEntry { - LIST_ENTRY_NONE, LIST_ENTRY_COUNTRY, LIST_ENTRY_STATE, LIST_ENTRY_PROVINCE + enum ProvinceListEntry { // + LIST_ENTRY_NONE, + LIST_ENTRY_COUNTRY, + LIST_ENTRY_STATE, + LIST_ENTRY_PROVINCE }; enum PopSortKey { - SORT_NONE, SORT_SIZE, SORT_TYPE, SORT_CULTURE, SORT_RELIGION, SORT_LOCATION, SORT_MILITANCY, SORT_CONSCIOUSNESS, - SORT_IDEOLOGY, SORT_ISSUES, SORT_UNEMPLOYMENT, SORT_CASH, SORT_LIFE_NEEDS, SORT_EVERYDAY_NEEDS, - SORT_LUXURY_NEEDS, SORT_REBEL_FACTION, SORT_SIZE_CHANGE, SORT_LITERACY, MAX_SORT_KEY + SORT_NONE, + SORT_SIZE, + SORT_TYPE, + SORT_CULTURE, + SORT_RELIGION, + SORT_LOCATION, + SORT_MILITANCY, + SORT_CONSCIOUSNESS, + SORT_IDEOLOGY, + SORT_ISSUES, + SORT_UNEMPLOYMENT, + SORT_CASH, + SORT_LIFE_NEEDS, + SORT_EVERYDAY_NEEDS, + SORT_LUXURY_NEEDS, + SORT_REBEL_FACTION, + SORT_SIZE_CHANGE, + SORT_LITERACY, + MAX_SORT_KEY }; struct population_menu_t { @@ -102,7 +121,10 @@ namespace OpenVic { }; enum TradeSettingBit { - TRADE_SETTING_NONE = 0, TRADE_SETTING_AUTOMATED = 1, TRADE_SETTING_BUYING = 2, TRADE_SETTING_SELLING = 4 + TRADE_SETTING_NONE = 0, + TRADE_SETTING_AUTOMATED = 1, + TRADE_SETTING_BUYING = 2, + TRADE_SETTING_SELLING = 4 }; ordered_map cached_leader_dicts; @@ -138,7 +160,7 @@ namespace OpenVic { godot::String _get_country_name(CountryInstance const& country) const; godot::String _get_country_adjective(CountryInstance const& country) const; - godot::String _make_modifier_effect_value( + godot::String _make_modifier_effect_value( // ModifierEffect const& format_effect, fixed_point_t value, bool plus_for_non_negative ) const; @@ -176,7 +198,7 @@ namespace OpenVic { godot::String get_country_adjective_from_identifier(godot::String const& country_identifier) const; /* TOOLTIP */ - void show_tooltip( + void show_tooltip( // godot::String const& text, godot::Dictionary const& substitution_dict, godot::Vector2 const& position ); void show_control_tooltip( @@ -238,29 +260,24 @@ namespace OpenVic { /* TRADE MENU */ godot::Dictionary get_trade_menu_good_categories_info() const; - godot::Dictionary get_trade_menu_trade_details_info( + godot::Dictionary get_trade_menu_trade_details_info( // int32_t trade_detail_good_index, GUIScrollbar* stockpile_cutoff_slider ) const; godot::Dictionary get_trade_menu_tables_info() const; static constexpr int32_t calculate_slider_value_from_trade_menu_stockpile_cutoff( - const fixed_point_t stockpile_cutoff, - const int32_t max_slider_value + const fixed_point_t stockpile_cutoff, const int32_t max_slider_value ) { // Math.log(2)/Math.log(Math.exp(Math.log(2001)/2000)) = 182.37... constexpr fixed_point_t DOUBLES_AFTER_STEPS = fixed_point_t::parse_raw(11952029); int32_t times_halved = 0; - fixed_point_t copy_plus_one = stockpile_cutoff+1; + fixed_point_t copy_plus_one = stockpile_cutoff + 1; while (copy_plus_one >= 2) { copy_plus_one /= 2; times_halved++; } - int32_t slider_value = times_halved * DOUBLES_AFTER_STEPS; //truncated - while ( - calculate_trade_menu_stockpile_cutoff_amount_fp( - slider_value - ) < stockpile_cutoff - ) { + int32_t slider_value = times_halved * DOUBLES_AFTER_STEPS; // truncated + while (calculate_trade_menu_stockpile_cutoff_amount_fp(slider_value) < stockpile_cutoff) { if (slider_value >= max_slider_value) { return max_slider_value; } diff --git a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp index 38ff0f3f..6da98825 100644 --- a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp +++ b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp @@ -1,5 +1,3 @@ -#include "MenuSingleton.hpp" - #include #include @@ -10,6 +8,8 @@ #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" +#include "MenuSingleton.hpp" + using namespace OpenVic; using namespace godot; @@ -69,8 +69,7 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { ProvinceInstance const* location = group->get_position(); if (location != nullptr) { - leader_dict[military_info_leader_location_key] = - Utilities::std_to_godot_string(location->get_identifier()); + leader_dict[military_info_leader_location_key] = Utilities::std_to_godot_string(location->get_identifier()); } } } @@ -121,9 +120,9 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { static const StringName prestige_localisation_key = "PRESTIGE_SCORE"; static const String value_replace_key = "$VAL$"; - String prestige_tooltip = tr(prestige_localisation_key).replace( - value_replace_key, Utilities::fixed_point_to_string_dp(prestige * 100, 2) + "%" - ); + String prestige_tooltip = // + tr(prestige_localisation_key) + .replace(value_replace_key, Utilities::fixed_point_to_string_dp(prestige * 100, 2) + "%"); tooltip += "\n" + prestige_tooltip; @@ -136,13 +135,20 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { static const StringName morale_localisation_key = "PRESTIGE_MORALE_BONUS"; static const StringName organisation_localisation_key = "PRESTIGE_MAX_ORG_BONUS"; - prestige_tooltip += "\n" + tr(morale_localisation_key).replace( - value_replace_key, - _make_modifier_effect_value_coloured(morale_effect, modifier_value.get_effect(morale_effect), true) - ) + "\n" + tr(organisation_localisation_key).replace( - value_replace_key, - _make_modifier_effect_value_coloured(organisation_effect, modifier_value.get_effect(organisation_effect), true) - ); + prestige_tooltip += "\n" + + tr(morale_localisation_key) + .replace( + value_replace_key, + _make_modifier_effect_value_coloured(morale_effect, modifier_value.get_effect(morale_effect), true) + ) + + "\n" + + tr(organisation_localisation_key) + .replace( + value_replace_key, + _make_modifier_effect_value_coloured( + organisation_effect, modifier_value.get_effect(organisation_effect), true + ) + ); leader_dict[military_info_leader_prestige_key] = prestige.to_float(); leader_dict[military_info_leader_prestige_tooltip_key] = std::move(prestige_tooltip); @@ -163,9 +169,7 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { static const StringName background_localisation_key = "MILITARY_BACKGROUND"; static const String background_replace_key = "$NAME$"; - tooltip += "\n" + tr(background_localisation_key).replace( - background_replace_key, background - ); + tooltip += "\n" + tr(background_localisation_key).replace(background_replace_key, background); leader_dict[military_info_leader_background_key] = std::move(background); } @@ -185,9 +189,7 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { static const StringName personality_localisation_key = "MILITARY_PERSONALITY"; static const String personality_replace_key = "$NAME$"; - tooltip += "\n" + tr(personality_localisation_key).replace( - personality_replace_key, personality - ); + tooltip += "\n" + tr(personality_localisation_key).replace(personality_replace_key, personality); leader_dict[military_info_leader_personality_key] = std::move(personality); } @@ -211,16 +213,16 @@ template Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched const& unit_group) { static const StringName military_info_unit_group_leader_picture_key = "unit_group_leader_picture"; static const StringName military_info_unit_group_leader_tooltip_key = "unit_group_leader_tooltip"; - static const StringName military_info_unit_group_name_key = "unit_group_name"; - static const StringName military_info_unit_group_location_key = "unit_group_location"; - static const StringName military_info_unit_group_unit_count_key = "unit_group_unit_count"; - static const StringName military_info_unit_group_men_count_key = "unit_group_men_count"; // armies only - static const StringName military_info_unit_group_max_men_count_key = "unit_group_max_men_count"; // armies only - static const StringName military_info_unit_group_organisation_key = "unit_group_organisation"; - static const StringName military_info_unit_group_strength_key = "unit_group_strength"; + static const StringName military_info_unit_group_name_key = "unit_group_name"; + static const StringName military_info_unit_group_location_key = "unit_group_location"; + static const StringName military_info_unit_group_unit_count_key = "unit_group_unit_count"; + static const StringName military_info_unit_group_men_count_key = "unit_group_men_count"; // armies only + static const StringName military_info_unit_group_max_men_count_key = "unit_group_max_men_count"; // armies only + static const StringName military_info_unit_group_organisation_key = "unit_group_organisation"; + static const StringName military_info_unit_group_strength_key = "unit_group_strength"; static const StringName military_info_unit_group_moving_tooltip_key = "unit_group_moving_tooltip"; - static const StringName military_info_unit_group_dig_in_tooltip_key = "unit_group_dig_in_tooltip"; // armies only - static const StringName military_info_unit_group_combat_key = "unit_group_combat"; + static const StringName military_info_unit_group_dig_in_tooltip_key = "unit_group_dig_in_tooltip"; // armies only + static const StringName military_info_unit_group_combat_key = "unit_group_combat"; using enum UnitType::branch_t; @@ -255,12 +257,16 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched ProvinceInstance const* destination = unit_group.get_movement_destination_province(); - unit_group_dict[military_info_unit_group_moving_tooltip_key] = tr(moving_localisation_key).replace( - moving_location_replace_key, - tr(GUINode::format_province_name( - destination != nullptr ? Utilities::std_to_godot_string(destination->get_identifier()) : String {}, false - )) - ).replace(moving_date_replace_key, Utilities::date_to_string(unit_group.get_movement_arrival_date())); + unit_group_dict[military_info_unit_group_moving_tooltip_key] = + tr(moving_localisation_key) + .replace( + moving_location_replace_key, + tr(GUINode::format_province_name( + destination != nullptr ? Utilities::std_to_godot_string(destination->get_identifier()) : String {}, + false + )) + ) + .replace(moving_date_replace_key, Utilities::date_to_string(unit_group.get_movement_arrival_date())); } if constexpr (Branch == LAND) { @@ -274,9 +280,8 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched static const StringName dig_in_localisation_key = "MILITARY_DIGIN_TOOLTIP"; static const String moving_days_replace_key = "$DAYS$"; - unit_group_dict[military_info_unit_group_dig_in_tooltip_key] = tr(dig_in_localisation_key).replace( - moving_days_replace_key, String::num_uint64(dig_in_level) - ); + unit_group_dict[military_info_unit_group_dig_in_tooltip_key] = + tr(dig_in_localisation_key).replace(moving_days_replace_key, String::num_uint64(dig_in_level)); } } @@ -308,16 +313,19 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { const ordered_map> required_goods { { good_definition_manager.get_good_definition_by_index(0), - { fixed_point_t::parse(1234) / 100, fixed_point_t::parse(1900) / 100 } - }, { + { fixed_point_t::parse(1234) / 100, fixed_point_t::parse(1900) / 100 } // + }, + { good_definition_manager.get_good_definition_by_index(1), - { fixed_point_t::parse(888) / 100, fixed_point_t::parse(1444) / 100 } - }, { + { fixed_point_t::parse(888) / 100, fixed_point_t::parse(1444) / 100 } // + }, + { good_definition_manager.get_good_definition_by_index(2), - { fixed_point_t::parse(1622) / 100, fixed_point_t::parse(1622) / 100 } - }, { + { fixed_point_t::parse(1622) / 100, fixed_point_t::parse(1622) / 100 } // + }, + { good_definition_manager.get_good_definition_by_index(3), - { fixed_point_t::parse(211) / 100, fixed_point_t::parse(805) / 100 } + { fixed_point_t::parse(211) / 100, fixed_point_t::parse(805) / 100 } // } }; @@ -391,9 +399,8 @@ Dictionary MenuSingleton::get_military_menu_info() { static const String war_exhaustion_template_string = "%s/%s"; const String war_exhaustion_string = Utilities::fixed_point_to_string_dp(country->get_war_exhaustion(), 2); const String max_war_exhaustion_string = Utilities::fixed_point_to_string_dp(country->get_war_exhaustion_max(), 2); - ret[military_info_war_exhaustion_key] = vformat( - war_exhaustion_template_string, war_exhaustion_string, max_war_exhaustion_string - ); + ret[military_info_war_exhaustion_key] = + vformat(war_exhaustion_template_string, war_exhaustion_string, max_war_exhaustion_string); static const StringName war_exhaution_localisation_key = "MILITARY_WAR_EXHAUSTION_TOOLTIP"; static const StringName max_war_exhaution_localisation_key = "MILITARY_MAX_WAR_EXHAUSTION_TOOLTIP"; @@ -426,13 +433,11 @@ Dictionary MenuSingleton::get_military_menu_info() { String organisation_regain_tooltip = base_value_percent_tooltip; const fixed_point_t morale = country->get_modifier_effect_value(*modifier_effect_cache.get_morale_global()); if (morale != fixed_point_t::_0) { - organisation_regain_tooltip += from_technology_tooltip + _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_morale_global(), morale, true - ); + organisation_regain_tooltip += from_technology_tooltip + + _make_modifier_effect_value_coloured(*modifier_effect_cache.get_morale_global(), morale, true); } - organisation_regain_tooltip += _make_modifier_effect_contributions_tooltip( - *country, *modifier_effect_cache.get_org_regain() - ); + organisation_regain_tooltip += + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_org_regain()); ret[military_info_organisation_regain_tooltip_key] = std::move(organisation_regain_tooltip); } @@ -449,18 +454,19 @@ Dictionary MenuSingleton::get_military_menu_info() { { static const StringName base_value_localisation_key = "MILITARY_BASEVALUE"; String unit_start_experience_tooltip = tr(base_value_localisation_key); - const fixed_point_t regular_experience_level = country->get_modifier_effect_value( - *modifier_effect_cache.get_regular_experience_level() - ); + const fixed_point_t regular_experience_level = + country->get_modifier_effect_value(*modifier_effect_cache.get_regular_experience_level()); if (regular_experience_level != fixed_point_t::_0) { - unit_start_experience_tooltip += from_technology_tooltip + _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_regular_experience_level(), regular_experience_level, true - ); + unit_start_experience_tooltip += + from_technology_tooltip + + _make_modifier_effect_value_coloured( + *modifier_effect_cache.get_regular_experience_level(), regular_experience_level, true + ); } - const String land_unit_start_experience_tooltip = _make_modifier_effect_contributions_tooltip( + const String land_unit_start_experience_tooltip = _make_modifier_effect_contributions_tooltip( // *country, *modifier_effect_cache.get_land_unit_start_experience() ); - const String naval_unit_start_experience_tooltip = _make_modifier_effect_contributions_tooltip( + const String naval_unit_start_experience_tooltip = _make_modifier_effect_contributions_tooltip( // *country, *modifier_effect_cache.get_naval_unit_start_experience() ); unit_start_experience_tooltip += land_unit_start_experience_tooltip; @@ -472,25 +478,25 @@ Dictionary MenuSingleton::get_military_menu_info() { } ret[military_info_recruit_time_key] = country->get_recruit_time().to_float(); - ret[military_info_recruit_time_tooltip_key] = base_value_percent_tooltip + _make_modifier_effect_contributions_tooltip( - *country, *modifier_effect_cache.get_unit_recruitment_time() - ); + ret[military_info_recruit_time_tooltip_key] = base_value_percent_tooltip + + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_unit_recruitment_time()); ret[military_info_combat_width_key] = country->get_combat_width(); { static const StringName base_value_combat_width_localisation_key = "COMWID_BASE"; static const String val_replace_key = "$VAL$"; - String combat_width_tooltip = tr(base_value_combat_width_localisation_key).replace( - val_replace_key, String::num_uint64( - definition_manager.get_define_manager().get_military_defines().get_base_combat_width() - ) - ); - const fixed_point_t combat_width = country->get_modifier_effect_value( + String combat_width_tooltip = + tr(base_value_combat_width_localisation_key) + .replace( + val_replace_key, + String::num_uint64(definition_manager.get_define_manager().get_military_defines().get_base_combat_width()) + ); + const fixed_point_t combat_width = country->get_modifier_effect_value( // *modifier_effect_cache.get_combat_width_additive() ); if (combat_width != fixed_point_t::_0) { - combat_width_tooltip += from_technology_tooltip + GUILabel::get_colour_marker() + "G" + - String::num_int64(combat_width.to_int64_t()); + combat_width_tooltip += + from_technology_tooltip + GUILabel::get_colour_marker() + "G" + String::num_int64(combat_width.to_int64_t()); } ret[military_info_combat_width_tooltip_key] = std::move(combat_width_tooltip); } @@ -517,30 +523,34 @@ Dictionary MenuSingleton::get_military_menu_info() { static const StringName mobilisation_size_tech_tooltip_localisation_key = "MOB_FROM_TECH"; static const String mobilisation_size_tooltip_replace_value_key = "$VALUE$"; - const fixed_point_t mobilisation_size_from_tech = country->get_modifier_effect_value( - *modifier_effect_cache.get_mobilisation_size_tech() - ); - - String military_info_mobilisation_size_tooltip = tr(mobilisation_size_tooltip_localisation_key).replace( - mobilisation_size_tooltip_replace_value_key, Utilities::fixed_point_to_string_dp( - ( - country->get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_size_country()) + - mobilisation_size_from_tech - ) * 100, 2 - ) - ); + const fixed_point_t mobilisation_size_from_tech = + country->get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_size_tech()); + + String military_info_mobilisation_size_tooltip = + tr(mobilisation_size_tooltip_localisation_key) + .replace( + mobilisation_size_tooltip_replace_value_key, + Utilities::fixed_point_to_string_dp( + (country->get_modifier_effect_value(*modifier_effect_cache.get_mobilisation_size_country()) + + mobilisation_size_from_tech) * + 100, + 2 + ) + ); if (mobilisation_size_from_tech != fixed_point_t::_0) { - military_info_mobilisation_size_tooltip += "\n" + tr(mobilisation_size_tech_tooltip_localisation_key).replace( - mobilisation_size_tooltip_replace_value_key, _make_modifier_effect_value_coloured( - *modifier_effect_cache.get_mobilisation_size_country(), mobilisation_size_from_tech, false - ) - ); + military_info_mobilisation_size_tooltip += "\n" + + tr(mobilisation_size_tech_tooltip_localisation_key) + .replace( + mobilisation_size_tooltip_replace_value_key, + _make_modifier_effect_value_coloured( + *modifier_effect_cache.get_mobilisation_size_country(), mobilisation_size_from_tech, false + ) + ); } - military_info_mobilisation_size_tooltip += _make_modifier_effect_contributions_tooltip( - *country, *modifier_effect_cache.get_mobilisation_size_country() - ); + military_info_mobilisation_size_tooltip += + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_mobilisation_size_country()); ret[military_info_mobilisation_size_tooltip_key] = std::move(military_info_mobilisation_size_tooltip); } @@ -556,7 +566,7 @@ Dictionary MenuSingleton::get_military_menu_info() { *country, *modifier_effect_cache.get_mobilisation_economy_impact_country() ); - const fixed_point_t research_contribution = country->get_modifier_effect_value( + const fixed_point_t research_contribution = country->get_modifier_effect_value( // *modifier_effect_cache.get_mobilisation_economy_impact_tech() ); @@ -565,15 +575,16 @@ Dictionary MenuSingleton::get_military_menu_info() { static const StringName research_contribution_positive_key = "MOB_ECO_PENALTY"; static const String replace_value_key = "$VALUE$"; - mobilisation_economy_impact_tooltip = tr( - research_contribution < fixed_point_t::_0 - ? research_contribution_negative_key - : research_contribution_positive_key - ).replace( - replace_value_key, _make_modifier_effect_value( - *modifier_effect_cache.get_mobilisation_economy_impact_tech(), research_contribution.abs(), false - ) - ) + mobilisation_economy_impact_tooltip; + mobilisation_economy_impact_tooltip = + tr(research_contribution < fixed_point_t::_0 ? research_contribution_negative_key + : research_contribution_positive_key) + .replace( + replace_value_key, + _make_modifier_effect_value( + *modifier_effect_cache.get_mobilisation_economy_impact_tech(), research_contribution.abs(), false + ) + ) + + mobilisation_economy_impact_tooltip; } else if (!mobilisation_economy_impact_tooltip.is_empty()) { // Remove leading newline mobilisation_economy_impact_tooltip = mobilisation_economy_impact_tooltip.substr(1); diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index 5b2fa8b8..b4cd483a 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -49,16 +49,17 @@ GFX::Actor const* ModelSingleton::get_actor(std::string_view name, bool error_on return actor; } -GFX::Actor const* ModelSingleton::get_cultural_actor( +GFX::Actor const* ModelSingleton::get_cultural_actor( // std::string_view culture, std::string_view name, std::string_view fallback_name ) const { GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, nullptr); ERR_FAIL_COND_V_MSG( - culture.empty() || name.empty(), nullptr, vformat( - "Failed to find actor \"%s\" for culture \"%s\" - neither can be empty", - Utilities::std_to_godot_string(name), Utilities::std_to_godot_string(culture) + culture.empty() || name.empty(), nullptr, + vformat( + "Failed to find actor \"%s\" for culture \"%s\" - neither can be empty", Utilities::std_to_godot_string(name), + Utilities::std_to_godot_string(culture) ) ); @@ -69,9 +70,10 @@ GFX::Actor const* ModelSingleton::get_cultural_actor( // Which should be tried first: "Generic***" or "***Infantry"? if (actor == nullptr) { + CultureManager const& culture_manager = + game_singleton->get_definition_manager().get_pop_manager().get_culture_manager(); /* If no Actor exists for the specified GraphicalCultureType then try the default instead. */ - GraphicalCultureType const* default_graphical_culture_type = game_singleton->get_definition_manager().get_pop_manager() - .get_culture_manager().get_default_graphical_culture_type(); + GraphicalCultureType const* default_graphical_culture_type = culture_manager.get_default_graphical_culture_type(); if (default_graphical_culture_type != nullptr && default_graphical_culture_type->get_identifier() != culture) { actor_name = StringUtils::append_string_views(default_graphical_culture_type->get_identifier(), name); @@ -85,7 +87,8 @@ GFX::Actor const* ModelSingleton::get_cultural_actor( } ERR_FAIL_NULL_V_MSG( - actor, nullptr, vformat( + actor, nullptr, + vformat( "Failed to find actor \"%s\" for culture \"%s\"", Utilities::std_to_godot_string(name), Utilities::std_to_godot_string(culture) ) @@ -158,7 +161,8 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { GFX::Actor const* attachment_actor = get_actor(attachment.get_actor_name()); ERR_CONTINUE_MSG( - attachment_actor == nullptr, vformat( + attachment_actor == nullptr, + vformat( "Failed to find \"%s\" attachment actor for actor \"%s\"", Utilities::std_to_godot_string(attachment.get_actor_name()), Utilities::std_to_godot_string(actor.get_name()) @@ -171,7 +175,6 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { attachment_dict[attachment_model_key] = get_model_dict(*attachment_actor); attachments_array[idx] = std::move(attachment_dict); - } if (!attachments_array.is_empty()) { @@ -229,9 +232,8 @@ bool ModelSingleton::add_unit_dict( GraphicalCultureType const& graphical_culture_type = country->get_graphical_culture(); UnitType const* display_unit_type = unit.get_display_unit_type(); ERR_FAIL_NULL_V_MSG( - display_unit_type, false, vformat( - "Failed to get display unit type for unit \"%s\"", Utilities::std_to_godot_string(unit.get_name()) - ) + display_unit_type, false, + vformat("Failed to get display unit type for unit \"%s\"", Utilities::std_to_godot_string(unit.get_name())) ); std::string_view actor_name = display_unit_type->get_sprite(); @@ -262,12 +264,12 @@ bool ModelSingleton::add_unit_dict( // TODO - default without requiring hardcoded name static constexpr std::string_view default_fallback_actor_name = "Infantry"; - GFX::Actor const* actor = get_cultural_actor( - graphical_culture_type.get_identifier(), actor_name, default_fallback_actor_name - ); + GFX::Actor const* actor = + get_cultural_actor(graphical_culture_type.get_identifier(), actor_name, default_fallback_actor_name); ERR_FAIL_NULL_V_MSG( - actor, false, vformat( + actor, false, + vformat( "Failed to find \"%s\" actor of graphical culture type \"%s\" for unit \"%s\"", Utilities::std_to_godot_string(display_unit_type->get_sprite()), Utilities::std_to_godot_string(graphical_culture_type.get_identifier()), @@ -396,10 +398,9 @@ bool ModelSingleton::add_building_dict( std::string suffix; - if ( - &building.get_building_type() == - game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager().get_port_building_type() - ) { + BuildingTypeManager const& building_type_manager = + game_singleton->get_definition_manager().get_economy_manager().get_building_type_manager(); + if (&building.get_building_type() == building_type_manager.get_port_building_type()) { /* Port */ if (!province_definition.has_port()) { return true; @@ -433,10 +434,10 @@ bool ModelSingleton::add_building_dict( GFX::Actor const* actor = get_actor(actor_name); ERR_FAIL_NULL_V_MSG( - actor, false, vformat( - "Failed to find \"%s\" actor for building \"%s\" in province \"%s\"", - Utilities::std_to_godot_string(actor_name), Utilities::std_to_godot_string(building.get_identifier()), - Utilities::std_to_godot_string(province.get_identifier()) + actor, false, + vformat( + "Failed to find \"%s\" actor for building \"%s\" in province \"%s\"", Utilities::std_to_godot_string(actor_name), + Utilities::std_to_godot_string(building.get_identifier()), Utilities::std_to_godot_string(province.get_identifier()) ) ); @@ -444,9 +445,8 @@ bool ModelSingleton::add_building_dict( dict[model_key] = get_model_dict(*actor); - dict[position_key] = game_singleton->normalise_map_position( - position_ptr != nullptr ? *position_ptr : province_definition.get_centre() - ); + dict[position_key] = + game_singleton->normalise_map_position(position_ptr != nullptr ? *position_ptr : province_definition.get_centre()); if (rotation != 0.0f) { dict[rotation_key] = rotation; diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.hpp b/extension/src/openvic-extension/singletons/ModelSingleton.hpp index ebec7504..3c372441 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.hpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.hpp @@ -10,7 +10,7 @@ namespace OpenVic { struct BuildingInstance; class ModelSingleton : public godot::Object { - GDCLASS(ModelSingleton, godot::Object) + GDCLASS(ModelSingleton, godot::Object); static inline ModelSingleton* singleton = nullptr; @@ -25,7 +25,7 @@ namespace OpenVic { private: GFX::Actor const* get_actor(std::string_view name, bool error_on_fail = true) const; - GFX::Actor const* get_cultural_actor( + GFX::Actor const* get_cultural_actor( // std::string_view culture, std::string_view name, std::string_view fallback_name ) const; diff --git a/extension/src/openvic-extension/singletons/PlayerSingleton.cpp b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp index c78962f1..33466813 100644 --- a/extension/src/openvic-extension/singletons/PlayerSingleton.cpp +++ b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp @@ -86,8 +86,7 @@ void PlayerSingleton::set_player_country(CountryInstance const* new_player_count if (player_country != nullptr) { instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_AI, - std::pair { player_country->get_index(), true } + game_action_type_t::GAME_ACTION_SET_AI, std::pair { player_country->get_index(), true } ); } @@ -95,8 +94,7 @@ void PlayerSingleton::set_player_country(CountryInstance const* new_player_count if (player_country != nullptr) { instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_AI, - std::pair { player_country->get_index(), false } + game_action_type_t::GAME_ACTION_SET_AI, std::pair { player_country->get_index(), false } ); } @@ -172,8 +170,7 @@ void PlayerSingleton::toggle_paused() const { ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_PAUSE, - !instance_manager->get_simulation_clock().is_paused() + game_action_type_t::GAME_ACTION_SET_PAUSE, !instance_manager->get_simulation_clock().is_paused() ); } @@ -182,8 +179,7 @@ void PlayerSingleton::increase_speed() const { ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_SPEED, - instance_manager->get_simulation_clock().get_simulation_speed() + 1 + game_action_type_t::GAME_ACTION_SET_SPEED, instance_manager->get_simulation_clock().get_simulation_speed() + 1 ); } @@ -192,8 +188,7 @@ void PlayerSingleton::decrease_speed() const { ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_SPEED, - instance_manager->get_simulation_clock().get_simulation_speed() - 1 + game_action_type_t::GAME_ACTION_SET_SPEED, instance_manager->get_simulation_clock().get_simulation_speed() - 1 ); } @@ -239,9 +234,10 @@ void PlayerSingleton::set_good_trade_order(int32_t good_index, bool is_selling, ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_GOOD_TRADE_ORDER, std::tuple { + game_action_type_t::GAME_ACTION_SET_GOOD_TRADE_ORDER, + std::tuple { player_country->get_index(), good_index, is_selling, - MenuSingleton::calculate_trade_menu_stockpile_cutoff_amount_fp(amount_slider->get_value_scaled_fp()) + MenuSingleton::calculate_trade_menu_stockpile_cutoff_amount_fp(amount_slider->get_value_scaled_fp()) // } ); } @@ -256,8 +252,7 @@ void PlayerSingleton::create_leader(bool is_general) const { ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_CREATE_LEADER, - std::pair { player_country->get_index(), is_general } + game_action_type_t::GAME_ACTION_CREATE_LEADER, std::pair { player_country->get_index(), is_general } ); } @@ -266,8 +261,7 @@ void PlayerSingleton::set_can_use_leader(uint64_t leader_id, bool can_use) const ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_USE_LEADER, - std::pair { leader_id, can_use } + game_action_type_t::GAME_ACTION_SET_USE_LEADER, std::pair { leader_id, can_use } ); } @@ -302,7 +296,6 @@ void PlayerSingleton::set_mobilise(bool value) const { ERR_FAIL_NULL(instance_manager); instance_manager->queue_game_action( - game_action_type_t::GAME_ACTION_SET_MOBILISE, - std::pair { player_country->get_index(), value } + game_action_type_t::GAME_ACTION_SET_MOBILISE, std::pair { player_country->get_index(), value } ); } diff --git a/extension/src/openvic-extension/singletons/PlayerSingleton.hpp b/extension/src/openvic-extension/singletons/PlayerSingleton.hpp index 2a407d18..0ce84b27 100644 --- a/extension/src/openvic-extension/singletons/PlayerSingleton.hpp +++ b/extension/src/openvic-extension/singletons/PlayerSingleton.hpp @@ -10,7 +10,7 @@ namespace OpenVic { struct GUIScrollbar; class PlayerSingleton : public godot::Object { - GDCLASS(PlayerSingleton, godot::Object) + GDCLASS(PlayerSingleton, godot::Object); static inline PlayerSingleton* singleton = nullptr; diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 8869d501..83324084 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -1,5 +1,3 @@ -#include "MenuSingleton.hpp" - #include #include @@ -11,6 +9,8 @@ #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" +#include "MenuSingleton.hpp" + using namespace godot; using namespace OpenVic; @@ -30,9 +30,9 @@ Error MenuSingleton::_population_menu_update_provinces() { ERR_FAIL_COND_V(!map_instance.province_instances_are_locked(), FAILED); for (CountryInstance const* country : { - // Example country - instance_manager->get_country_instance_manager().get_country_instance_by_identifier("ENG") - }) { + // Example country + instance_manager->get_country_instance_manager().get_country_instance_by_identifier("ENG") // + }) { ERR_CONTINUE(country == nullptr); population_menu.province_list_entries.emplace_back(population_menu_t::country_entry_t { *country }); @@ -165,8 +165,8 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int } } entry_visitor { *this, start, count }; - while (entry_visitor.index < population_menu.province_list_entries.size() - && std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) { + while (entry_visitor.index < population_menu.province_list_entries.size() && + std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) { entry_visitor.index++; } @@ -246,8 +246,7 @@ Error MenuSingleton::population_menu_select_province_list_entry(int32_t select_i } emit_signal( - _signal_population_menu_province_list_selected_changed(), - set_scroll_index ? entry_visitor.selected_visible_index : -1 + _signal_population_menu_province_list_selected_changed(), set_scroll_index ? entry_visitor.selected_visible_index : -1 ); return _population_menu_update_pops(); @@ -306,8 +305,8 @@ Error MenuSingleton::population_menu_select_province(int32_t province_index) { } entry_visitor { *this, province_index }; - while (entry_visitor.index < population_menu.province_list_entries.size() - && std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) { + while (entry_visitor.index < population_menu.province_list_entries.size() && + std::visit(entry_visitor, population_menu.province_list_entries[entry_visitor.index])) { entry_visitor.index++; } @@ -329,8 +328,8 @@ Error MenuSingleton::population_menu_toggle_expanded(int32_t toggle_index, bool int32_t provinces = 0; - while (++toggle_index < population_menu.province_list_entries.size() - && std::holds_alternative(population_menu.province_list_entries[toggle_index])) { + while (++toggle_index < population_menu.province_list_entries.size() && + std::holds_alternative(population_menu.province_list_entries[toggle_index])) { provinces++; } @@ -499,25 +498,27 @@ MenuSingleton::sort_func_t MenuSingleton::_get_population_menu_sort_func(PopSort }; default: UtilityFunctions::push_error("Invalid population menu sort key: ", sort_key); - return [](Pop const* a, Pop const* b) -> bool { return false; }; + return [](Pop const* a, Pop const* b) -> bool { + return false; + }; } } Error MenuSingleton::_population_menu_sort_pops() { if (population_menu.sort_key != SORT_NONE) { - if ( - !population_menu.pop_type_sort_cache.has_keys() || !population_menu.culture_sort_cache.has_keys() || + if (!population_menu.pop_type_sort_cache.has_keys() || !population_menu.culture_sort_cache.has_keys() || !population_menu.religion_sort_cache.has_keys() || !population_menu.province_sort_cache.has_keys() || - !population_menu.rebel_type_sort_cache.has_keys() - ) { + !population_menu.rebel_type_sort_cache.has_keys()) { ERR_FAIL_COND_V(population_menu_update_locale_sort_cache() != OK, FAILED); } const sort_func_t base_sort_func = _get_population_menu_sort_func(population_menu.sort_key); - const sort_func_t sort_func = population_menu.sort_descending + const sort_func_t sort_func = population_menu.sort_descending // ? base_sort_func - : [base_sort_func](Pop const* a, Pop const* b) { return base_sort_func(b, a); }; + : [base_sort_func](Pop const* a, Pop const* b) { + return base_sort_func(b, a); + }; std::sort(population_menu.filtered_pops.begin(), population_menu.filtered_pops.end(), sort_func); } @@ -536,36 +537,32 @@ Error MenuSingleton::population_menu_update_locale_sort_cache() { std::vector localised_items; std::vector sorted_items; - const auto generate_sort_cache = [this, &localised_items, &sorted_items]( - IndexedMap& cache, std::vector const& items - ) { - localised_items.resize(items.size()); - sorted_items.resize(items.size()); + const auto generate_sort_cache = + [this, &localised_items, &sorted_items](IndexedMap& cache, std::vector const& items) { + localised_items.resize(items.size()); + sorted_items.resize(items.size()); - for (size_t idx = 0; idx < items.size(); ++idx) { - String identifier = Utilities::std_to_godot_string(items[idx].get_identifier()); - if constexpr (std::is_same_v) { - identifier = GUINode::format_province_name(identifier); + for (size_t idx = 0; idx < items.size(); ++idx) { + String identifier = Utilities::std_to_godot_string(items[idx].get_identifier()); + if constexpr (std::is_same_v) { + identifier = GUINode::format_province_name(identifier); + } + localised_items[idx] = tr(identifier).to_lower(); + sorted_items[idx] = idx; } - localised_items[idx] = tr(identifier).to_lower(); - sorted_items[idx] = idx; - } - std::sort( - sorted_items.begin(), sorted_items.end(), [&localised_items](size_t a, size_t b) -> bool { + std::sort(sorted_items.begin(), sorted_items.end(), [&localised_items](size_t a, size_t b) -> bool { return localised_items[a] < localised_items[b]; - } - ); + }); - cache.set_keys(items); - for (size_t idx = 0; idx < sorted_items.size(); ++idx) { - cache[sorted_items[idx]] = idx; - } - }; + cache.set_keys(items); + for (size_t idx = 0; idx < sorted_items.size(); ++idx) { + cache[sorted_items[idx]] = idx; + } + }; generate_sort_cache( - population_menu.pop_type_sort_cache, - game_singleton->get_definition_manager().get_pop_manager().get_pop_types() + population_menu.pop_type_sort_cache, game_singleton->get_definition_manager().get_pop_manager().get_pop_types() ); generate_sort_cache( population_menu.culture_sort_cache, @@ -575,10 +572,7 @@ Error MenuSingleton::population_menu_update_locale_sort_cache() { population_menu.religion_sort_cache, game_singleton->get_definition_manager().get_pop_manager().get_religion_manager().get_religions() ); - generate_sort_cache( - population_menu.province_sort_cache, - instance_manager->get_map_instance().get_province_instances() - ); + generate_sort_cache(population_menu.province_sort_cache, instance_manager->get_map_instance().get_province_instances()); generate_sort_cache( population_menu.rebel_type_sort_cache, game_singleton->get_definition_manager().get_politics_manager().get_rebel_manager().get_rebel_types() @@ -621,8 +615,8 @@ GFXPieChartTexture::godot_pie_chart_data_t MenuSingleton::generate_population_me total_weight += static_cast(weight); } - static const String pie_chart_tooltip_format_key = "%s: " + GUILabel::get_colour_marker() + "Y%s%%" + - GUILabel::get_colour_marker() + "!"; + static const String pie_chart_tooltip_format_key = + "%s: " + GUILabel::get_colour_marker() + "Y%s%%" + GUILabel::get_colour_marker() + "!"; for (auto [key_ref_or_ptr, weight] : distribution) { if (weight > 0.0f) { @@ -633,8 +627,7 @@ GFXPieChartTexture::godot_pie_chart_data_t MenuSingleton::generate_population_me key_ptr = &key_ref_or_ptr; } String tooltip = vformat( - pie_chart_tooltip_format_key, - tr(Utilities::std_to_godot_string(key_ptr->get_identifier()) + identifier_suffix), + pie_chart_tooltip_format_key, tr(Utilities::std_to_godot_string(key_ptr->get_identifier()) + identifier_suffix), Utilities::float_to_string_dp(100.0f * static_cast(weight) / total_weight, 1) ); full_tooltip += "\n" + tooltip; @@ -734,9 +727,8 @@ TypedArray MenuSingleton::get_population_menu_pop_rows(int32_t start pop_dict[pop_militancy_key] = pop->get_militancy().to_float(); pop_dict[pop_consciousness_key] = pop->get_consciousness().to_float(); pop_dict[pop_ideology_key] = generate_population_menu_pop_row_pie_chart_data(pop->get_ideology_distribution()); - pop_dict[pop_issues_key] = generate_population_menu_pop_row_pie_chart_data( - pop->get_issue_distribution(), get_issue_identifier_suffix() - ); + pop_dict[pop_issues_key] = + generate_population_menu_pop_row_pie_chart_data(pop->get_issue_distribution(), get_issue_identifier_suffix()); pop_dict[pop_unemployment_key] = pop->get_unemployment_fraction().to_float(); pop_dict[pop_cash_key] = pop->get_cash().get_copy_of_value().to_float(); pop_dict[pop_daily_money_key] = pop->get_income().to_float(); @@ -857,12 +849,12 @@ Error MenuSingleton::population_menu_deselect_all_pop_filters() { PackedStringArray MenuSingleton::get_population_menu_distribution_setup_info() const { static const PackedStringArray distribution_names = []() -> PackedStringArray { constexpr std::array NAMES { - /* Workforce (PopType) */ "WORKFORCE_DISTTITLE", - /* Religion */ "RELIGION_DISTTITLE", - /* Ideology */ "IDEOLOGY_DISTTITLE", - /* Nationality (Culture) */ "NATIONALITY_DISTTITLE", + /* Workforce (PopType) */ "WORKFORCE_DISTTITLE", + /* Religion */ "RELIGION_DISTTITLE", + /* Ideology */ "IDEOLOGY_DISTTITLE", + /* Nationality (Culture) */ "NATIONALITY_DISTTITLE", /* Issues */ "DOMINANT_ISSUES_DISTTITLE", - /* Vote */ "ELECTORATE_DISTTITLE" + /* Vote */ "ELECTORATE_DISTTITLE" }; PackedStringArray array; @@ -882,16 +874,14 @@ TypedArray MenuSingleton::get_population_menu_distribution_info() const { TypedArray array; ERR_FAIL_COND_V(array.resize(population_menu_t::DISTRIBUTION_COUNT) != OK, {}); - const auto make_pie_chart_tooltip = [this]( - HasGetIdentifierAndGetColour auto const* key, String const& identifier, float weight, float total_weight - ) -> String { + const auto make_pie_chart_tooltip = // + [this]( + HasGetIdentifierAndGetColour auto const* key, String const& identifier, float weight, float total_weight + ) -> String // + { static const String format_key = GUILabel::get_colour_marker() + String { "Y%s" } + GUILabel::get_colour_marker() + "!: %s%%"; - return vformat( - format_key, - tr(identifier), - Utilities::float_to_string_dp(100.0f * weight / total_weight, 2) - ); + return vformat(format_key, tr(identifier), Utilities::float_to_string_dp(100.0f * weight / total_weight, 2)); }; array[0] = GFXPieChartTexture::distribution_to_slices_array(population_menu.workforce_distribution, make_pie_chart_tooltip); diff --git a/extension/src/openvic-extension/singletons/SoundSingleton.cpp b/extension/src/openvic-extension/singletons/SoundSingleton.cpp index f13e5a1b..b4187920 100644 --- a/extension/src/openvic-extension/singletons/SoundSingleton.cpp +++ b/extension/src/openvic-extension/singletons/SoundSingleton.cpp @@ -13,11 +13,11 @@ #include #include +#include -#include "openvic-simulation/utility/StringUtils.hpp" -#include -#include -#include +#include "openvic-extension/singletons/GameSingleton.hpp" +#include "openvic-extension/utility/ClassBindings.hpp" +#include "openvic-extension/utility/Utilities.hpp" using OpenVic::Utilities::godot_to_std_string; using OpenVic::Utilities::std_to_godot_string; @@ -110,7 +110,10 @@ bool SoundSingleton::load_title_theme() { String file_stem = to_define_file_name(file, music_folder); if (file_stem == title_theme_name.data()) { - ERR_BREAK_MSG(!get_song(file).is_valid(), vformat("Failed to load title theme song at path %s.", std_to_godot_string(file_name.string()))); + ERR_BREAK_MSG( + !get_song(file).is_valid(), + vformat("Failed to load title theme song at path %s.", std_to_godot_string(file_name.string())) + ); String name = to_define_file_name(file, music_folder); title_theme = name; @@ -185,7 +188,7 @@ Ref SoundSingleton::get_sound_stream(String const& path) { it == sfx_define.end(), nullptr, vformat("Attempted to retrieve sound stream at invalid index %s.", path) ); - return it.value().audioStream; + return it.value().audio_stream; } // get the base volume of a sound from its define name @@ -218,13 +221,18 @@ bool SoundSingleton::load_sounds() { // UI_Cavalry_Selected.wav doesn't exist (paradox mistake, UI_Cavalry_Select.wav does), just keep going // the define its associated with also isn't used in game if (full_path.empty()) { - WARN_PRINT(vformat("The sound define %s points to non-existent file.", std_to_godot_string(sound_inst.get_identifier()))); + WARN_PRINT( + vformat("The sound define %s points to non-existent file.", std_to_godot_string(sound_inst.get_identifier())) + ); continue; } Ref stream = get_sound(std_to_godot_string(full_path.string())); if (stream.is_null()) { - ERR_PRINT(vformat("Failed to load sound %s at path %s.", std_to_godot_string(sound_inst.get_identifier()), std_to_godot_string(full_path.string()))); + ERR_PRINT(vformat( + "Failed to load sound %s at path %s.", std_to_godot_string(sound_inst.get_identifier()), + std_to_godot_string(full_path.string()) + )); ret = false; continue; // don't try to append a null pointer to the list } @@ -232,7 +240,7 @@ bool SoundSingleton::load_sounds() { String name = to_define_file_name(std_to_godot_string(full_path.string()), sound_folder); StringName define_gd_name = std_to_godot_string(sound_inst.get_identifier()); - sfx_define[define_gd_name].audioStream = get_sound(name); + sfx_define[define_gd_name].audio_stream = get_sound(name); sfx_define[define_gd_name].volume = sound_inst.get_volume(); sound_list.append(define_gd_name); diff --git a/extension/src/openvic-extension/singletons/SoundSingleton.hpp b/extension/src/openvic-extension/singletons/SoundSingleton.hpp index b4804f10..47a880f1 100644 --- a/extension/src/openvic-extension/singletons/SoundSingleton.hpp +++ b/extension/src/openvic-extension/singletons/SoundSingleton.hpp @@ -32,7 +32,7 @@ namespace OpenVic { // define name, stream ref, volume for sound effects so we can get these properties with a simple call in godot struct sound_asset_t { - godot::Ref audioStream; + godot::Ref audio_stream; std::optional volume; }; using sfx_define_map_t = deque_ordered_map; diff --git a/extension/src/openvic-extension/singletons/TradeMenu.cpp b/extension/src/openvic-extension/singletons/TradeMenu.cpp index 8d6818a0..f2d5bbf9 100644 --- a/extension/src/openvic-extension/singletons/TradeMenu.cpp +++ b/extension/src/openvic-extension/singletons/TradeMenu.cpp @@ -1,5 +1,3 @@ -#include "MenuSingleton.hpp" - #include #include "openvic-extension/classes/GUILabel.hpp" @@ -8,6 +6,8 @@ #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" +#include "MenuSingleton.hpp" + using namespace OpenVic; using namespace godot; @@ -57,15 +57,18 @@ Dictionary MenuSingleton::get_trade_menu_good_categories_info() const { const fixed_point_t supply = good_instance.get_total_supply_yesterday(); const fixed_point_t demand = good_instance.get_total_demand_yesterday(); - good_dict[demand_tooltip_key] = tr( - demand > supply ? in_demand_localisation_key : not_in_demand_localisation_key - ) + get_tooltip_separator() + tr(supply_localisation_key).replace( - val_replace_key, Utilities::fixed_point_to_string_dp(supply, 3) - ) + "\n" + tr(demand_localisation_key).replace( - val_replace_key, Utilities::fixed_point_to_string_dp(demand, 3) - ) + "\n" + tr(actual_bought_localisation_key).replace( - val_replace_key, Utilities::fixed_point_to_string_dp(good_instance.get_quantity_traded_yesterday(), 3) - ); + good_dict[demand_tooltip_key] = + tr(demand > supply ? in_demand_localisation_key : not_in_demand_localisation_key) + + get_tooltip_separator() + + tr(supply_localisation_key).replace(val_replace_key, Utilities::fixed_point_to_string_dp(supply, 3)) + + "\n" + + tr(demand_localisation_key).replace(val_replace_key, Utilities::fixed_point_to_string_dp(demand, 3)) + + "\n" + + tr(actual_bought_localisation_key) + .replace( + val_replace_key, + Utilities::fixed_point_to_string_dp(good_instance.get_quantity_traded_yesterday(), 3) + ); } if (country != nullptr) { @@ -106,7 +109,7 @@ Dictionary MenuSingleton::get_trade_menu_good_categories_info() const { return ret; } -Dictionary MenuSingleton::get_trade_menu_trade_details_info( +Dictionary MenuSingleton::get_trade_menu_trade_details_info( // int32_t trade_detail_good_index, GUIScrollbar* stockpile_cutoff_slider ) const { static const StringName trade_detail_good_name_key = "trade_detail_good_name"; @@ -151,8 +154,8 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info( ret[trade_detail_price_history_key] = std::move(price_history); } else { UtilityFunctions::push_error( - "Failed to resize price history array to the correct size (", - static_cast(good_price_history.size()), ")" + "Failed to resize price history array to the correct size (", static_cast(good_price_history.size()), + ")" ); } } @@ -167,8 +170,7 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info( ret[trade_detail_is_selling_key] = good_data.is_selling; if (stockpile_cutoff_slider != nullptr) { const int32_t index = calculate_slider_value_from_trade_menu_stockpile_cutoff( - good_data.stockpile_cutoff, - stockpile_cutoff_slider->get_max_value_scaled() + good_data.stockpile_cutoff, stockpile_cutoff_slider->get_max_value_scaled() ); stockpile_cutoff_slider->set_scaled_value(index); } @@ -220,8 +222,7 @@ Dictionary MenuSingleton::get_trade_menu_tables_info() const { static const String top_producer_template_string = "\n" + GUILabel::get_flag_marker() + "%s %s: %s"; tooltip += vformat( - top_producer_template_string, - Utilities::std_to_godot_string(country->get_identifier()), + top_producer_template_string, Utilities::std_to_godot_string(country->get_identifier()), _get_country_name(*country), Utilities::fixed_point_to_string_dp(fixed_point_t::parse(1000) / static_cast(index + 1), 2) ); @@ -264,54 +265,38 @@ Dictionary MenuSingleton::get_trade_menu_tables_info() const { } good_trading_yesterday_tooltips.push_back( - tooltip.replace( - money_replace_key, Utilities::fixed_point_to_string_dp(stockpile_change_yesterday, 2) - ).replace( - units_replace_key, Utilities::fixed_point_to_string_dp(stockpile_change_yesterday * good.get_price(), 2) - ) + tooltip.replace(money_replace_key, Utilities::fixed_point_to_string_dp(stockpile_change_yesterday, 2)) + .replace( + units_replace_key, Utilities::fixed_point_to_string_dp(stockpile_change_yesterday * good.get_price(), 2) + ) ); const float good_index = good.get_good_definition().get_index(); if (good_data.government_needs != fixed_point_t::_0) { - government_needs.push_back({ - good_index, - good_data.government_needs.to_float() - }); + government_needs.push_back({ good_index, good_data.government_needs.to_float() }); } if (good_data.factory_demand != fixed_point_t::_0) { - factory_needs.push_back({ - good_index, - good_data.factory_demand.to_float() - }); + factory_needs.push_back({ good_index, good_data.factory_demand.to_float() }); } if (good_data.pop_demand != fixed_point_t::_0) { - pop_needs.push_back({ - good_index, good_data.pop_demand.to_float() - }); + pop_needs.push_back({ good_index, good_data.pop_demand.to_float() }); } market_activity.push_back({ - good_index, - good_data.exported_amount.abs().to_float(), - (good_data.exported_amount * good.get_price()).to_float() + good_index, good_data.exported_amount.abs().to_float(), + (good_data.exported_amount * good.get_price()).to_float() // }); stockpile.push_back({ - good_index, - good_data.stockpile_amount.to_float(), - good_data.stockpile_change_yesterday.to_float() + good_index, good_data.stockpile_amount.to_float(), + good_data.stockpile_change_yesterday.to_float() // }); // TODO - replace with actual common market data - common_market.push_back({ - good_index, - good_index * 100, - -good_index, - good_index * 10 - }); + common_market.push_back({ good_index, good_index * 100, -good_index, good_index * 10 }); } ret[good_trading_yesterday_tooltips_key] = std::move(good_trading_yesterday_tooltips); diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index aa5b49f8..c6e8372c 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include "openvic-extension/classes/GUIButton.hpp" #include "openvic-extension/classes/GUIIcon.hpp" #include "openvic-extension/classes/GUIIconButton.hpp" @@ -43,8 +45,6 @@ #include "openvic-extension/singletons/SoundSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" -#include "openvic-simulation/misc/SoundEffect.hpp" - using namespace godot; using namespace OpenVic; @@ -213,7 +213,8 @@ namespace OpenVic { constexpr generate_gui_args_t( GUI::Element const& new_element, String const& new_name, AssetManager& new_asset_manager, Control*& new_result - ) : element { new_element }, name { new_name }, asset_manager { new_asset_manager }, result { new_result } {} + ) + : element { new_element }, name { new_name }, asset_manager { new_asset_manager }, result { new_result } {} }; } @@ -225,8 +226,10 @@ static bool new_control(T*& node, GUI::Element const& element, String const& nam using enum GUI::Element::orientation_t; using enum Control::LayoutPreset; static const ordered_map orientation_map { - { UPPER_LEFT, PRESET_TOP_LEFT }, { LOWER_LEFT, PRESET_BOTTOM_LEFT }, - { LOWER_RIGHT, PRESET_BOTTOM_RIGHT }, { UPPER_RIGHT, PRESET_TOP_RIGHT }, + { UPPER_LEFT, PRESET_TOP_LEFT }, + { LOWER_LEFT, PRESET_BOTTOM_LEFT }, + { LOWER_RIGHT, PRESET_BOTTOM_RIGHT }, + { UPPER_RIGHT, PRESET_TOP_RIGHT }, { CENTER, PRESET_CENTER } }; @@ -268,9 +271,7 @@ static bool generate_icon(generate_gui_args_t&& args) { if (GFX::IconTextureSprite const* texture_sprite = icon.get_sprite()->cast_to()) { GUIIcon* gui_icon = nullptr; ret &= new_control(gui_icon, icon, args.name); - ERR_FAIL_NULL_V_MSG( - gui_icon, false, vformat("Failed to create GUIIcon for GUI icon %s", icon_name) - ); + ERR_FAIL_NULL_V_MSG(gui_icon, false, vformat("Failed to create GUIIcon for GUI icon %s", icon_name)); gui_icon->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); @@ -286,9 +287,7 @@ static bool generate_icon(generate_gui_args_t&& args) { } else if (GFX::MaskedFlag const* masked_flag = icon.get_sprite()->cast_to()) { GUIMaskedFlag* gui_masked_flag = nullptr; ret &= new_control(gui_masked_flag, icon, args.name); - ERR_FAIL_NULL_V_MSG( - gui_masked_flag, false, vformat("Failed to create GUIMaskedFlag for GUI icon %s", icon_name) - ); + ERR_FAIL_NULL_V_MSG(gui_masked_flag, false, vformat("Failed to create GUIMaskedFlag for GUI icon %s", icon_name)); if (gui_masked_flag->set_gfx_masked_flag(masked_flag) != OK) { UtilityFunctions::push_error("Error setting up GUIMaskedFlag for GUI icon ", icon_name); @@ -299,9 +298,7 @@ static bool generate_icon(generate_gui_args_t&& args) { } else if (GFX::ProgressBar const* progress_bar = icon.get_sprite()->cast_to()) { GUIProgressBar* gui_progress_bar = nullptr; ret &= new_control(gui_progress_bar, icon, args.name); - ERR_FAIL_NULL_V_MSG( - gui_progress_bar, false, vformat("Failed to create GUIProgressBar for GUI icon %s", icon_name) - ); + ERR_FAIL_NULL_V_MSG(gui_progress_bar, false, vformat("Failed to create GUIProgressBar for GUI icon %s", icon_name)); if (gui_progress_bar->set_gfx_progress_bar(progress_bar) != OK) { UtilityFunctions::push_error("Error setting up GUIProgressBar for GUI icon ", icon_name); @@ -312,9 +309,7 @@ static bool generate_icon(generate_gui_args_t&& args) { } else if (GFX::PieChart const* pie_chart = icon.get_sprite()->cast_to()) { GUIPieChart* gui_pie_chart = nullptr; ret &= new_control(gui_pie_chart, icon, args.name); - ERR_FAIL_NULL_V_MSG( - gui_pie_chart, false, vformat("Failed to create GUIPieChart for GUI icon %s", icon_name) - ); + ERR_FAIL_NULL_V_MSG(gui_pie_chart, false, vformat("Failed to create GUIPieChart for GUI icon %s", icon_name)); if (gui_pie_chart->set_gfx_pie_chart(pie_chart) == OK) { // For some reason pie charts are defined by their top-centre position, so we need to subtract @@ -331,9 +326,7 @@ static bool generate_icon(generate_gui_args_t&& args) { } else if (GFX::LineChart const* line_chart = icon.get_sprite()->cast_to()) { GUILineChart* gui_line_chart = nullptr; ret &= new_control(gui_line_chart, icon, args.name); - ERR_FAIL_NULL_V_MSG( - gui_line_chart, false, vformat("Failed to create GUILineChart for GUI icon %s", icon_name) - ); + ERR_FAIL_NULL_V_MSG(gui_line_chart, false, vformat("Failed to create GUILineChart for GUI icon %s", icon_name)); if (gui_line_chart->set_gfx_line_chart(line_chart) != OK) { UtilityFunctions::push_error("Error setting up GUILineChart for GUI icon ", icon_name); @@ -343,8 +336,8 @@ static bool generate_icon(generate_gui_args_t&& args) { args.result = gui_line_chart; } else { UtilityFunctions::push_error( - "Invalid sprite type ", Utilities::std_to_godot_string(icon.get_sprite()->get_type()), - " for GUI icon ", icon_name + "Invalid sprite type ", Utilities::std_to_godot_string(icon.get_sprite()->get_type()), " for GUI icon ", + icon_name ); ret = false; } @@ -353,9 +346,9 @@ static bool generate_icon(generate_gui_args_t&& args) { const real_t rotation = icon.get_rotation(); if (rotation != 0.0_real) { args.result->set_position( - args.result->get_position() - args.result->get_custom_minimum_size().height * Vector2 { - Math::sin(rotation), Math::cos(rotation) - 1.0_real - } + args.result->get_position() - + args.result->get_custom_minimum_size().height * + Vector2 { Math::sin(rotation), Math::cos(rotation) - 1.0_real } ); args.result->set_rotation(-rotation); } @@ -406,7 +399,8 @@ static bool generate_button(generate_gui_args_t&& args) { gui_button = gui_masked_flag_button; } else { ERR_FAIL_V_MSG( - false, vformat( + false, + vformat( "Invalid sprite type %s for GUI button %s", Utilities::std_to_godot_string(button.get_sprite()->get_type()), button_name ) @@ -474,7 +468,8 @@ static bool generate_checkbox(generate_gui_args_t&& args) { GFX::IconTextureSprite const* texture_sprite = checkbox.get_sprite()->cast_to(); ERR_FAIL_NULL_V_MSG( - texture_sprite, false, vformat( + texture_sprite, false, + vformat( "Invalid sprite type %s for GUI checkbox %s", Utilities::std_to_godot_string(checkbox.get_sprite()->get_type()), checkbox_name ) @@ -482,9 +477,7 @@ static bool generate_checkbox(generate_gui_args_t&& args) { GUIIconButton* gui_icon_button = nullptr; bool ret = new_control(gui_icon_button, checkbox, args.name); - ERR_FAIL_NULL_V_MSG( - gui_icon_button, false, vformat("Failed to create GUIIconButton for GUI checkbox %s", checkbox_name) - ); + ERR_FAIL_NULL_V_MSG(gui_icon_button, false, vformat("Failed to create GUIIconButton for GUI checkbox %s", checkbox_name)); gui_icon_button->set_toggle_mode(true); @@ -523,7 +516,8 @@ static bool generate_text(generate_gui_args_t&& args) { GameSingleton const* game_singleton = GameSingleton::get_singleton(); GFX::Font::colour_codes_t const* override_colour_codes = game_singleton != nullptr - ? &game_singleton->get_definition_manager().get_ui_manager().get_universal_colour_codes() : nullptr; + ? &game_singleton->get_definition_manager().get_ui_manager().get_universal_colour_codes() + : nullptr; if (gui_label->set_gui_text(&text, override_colour_codes) != OK) { UtilityFunctions::push_error("Error initializing GUILabel for GUI text ", text_name); @@ -713,9 +707,7 @@ static bool generate_window(generate_gui_args_t&& args) { godot_panel->add_child(node); } if (!element_ret) { - UtilityFunctions::push_error( - "Errors generating GUI element ", Utilities::std_to_godot_string(element->get_name()) - ); + UtilityFunctions::push_error("Errors generating GUI element ", Utilities::std_to_godot_string(element->get_name())); ret = false; } } @@ -745,17 +737,13 @@ static bool generate_element(GUI::Element const* element, String const& name, As return it->second({ *element, name, asset_manager, result }); } -bool UITools::generate_gui_element( - GUI::Element const* element, String const& name, Control*& result -) { +bool UITools::generate_gui_element(GUI::Element const* element, String const& name, Control*& result) { result = nullptr; AssetManager* asset_manager = AssetManager::get_singleton(); ERR_FAIL_NULL_V(asset_manager, false); return generate_element(element, name, *asset_manager, result); } -bool UITools::generate_gui_element( - String const& gui_scene, String const& gui_element, String const& name, Control*& result -) { +bool UITools::generate_gui_element(String const& gui_scene, String const& gui_element, String const& name, Control*& result) { return generate_gui_element(get_gui_element(gui_scene, gui_element), name, result); } diff --git a/extension/src/openvic-extension/utility/UITools.hpp b/extension/src/openvic-extension/utility/UITools.hpp index 566318a2..25a374bc 100644 --- a/extension/src/openvic-extension/utility/UITools.hpp +++ b/extension/src/openvic-extension/utility/UITools.hpp @@ -10,9 +10,7 @@ namespace OpenVic::UITools { GUI::Element const* get_gui_element(godot::String const& gui_scene, godot::String const& gui_element); GUI::Position const* get_gui_position(godot::String const& gui_scene, godot::String const& gui_position); - bool generate_gui_element( - GUI::Element const* element, godot::String const& name, godot::Control*& result - ); + bool generate_gui_element(GUI::Element const* element, godot::String const& name, godot::Control*& result); bool generate_gui_element( godot::String const& gui_scene, godot::String const& gui_element, godot::String const& name, godot::Control*& result ); diff --git a/extension/src/openvic-extension/utility/Utilities.cpp b/extension/src/openvic-extension/utility/Utilities.cpp index 89011927..5027398c 100644 --- a/extension/src/openvic-extension/utility/Utilities.cpp +++ b/extension/src/openvic-extension/utility/Utilities.cpp @@ -15,10 +15,10 @@ using namespace OpenVic; * or normal integer string if less than the smallest suffix. */ String Utilities::int_to_string_suffixed(int64_t val) { static const std::vector> suffixes { - { 1'000'000'000'000, "T" }, + { 1'000'000'000'000, "T" }, // { 1'000'000'000, "B" }, { 1'000'000, "M" }, - { 1'000, "k" } + { 1'000, "k" } // }; static constexpr int64_t decimal_places_multiplier = 100; const bool negative = val < 0; @@ -29,8 +29,8 @@ String Utilities::int_to_string_suffixed(int64_t val) { if (val >= suffix_val) { const int64_t whole = val / suffix_val; const int64_t frac = (val * decimal_places_multiplier / suffix_val) % decimal_places_multiplier; - return (negative ? "-" : "") + String::num_int64(whole) + "." + - (frac < 10 ? "0" : "") + String::num_int64(frac) + suffix_str; + return (negative ? "-" : "") + String::num_int64(whole) + "." + (frac < 10 ? "0" : "") + String::num_int64(frac) + + suffix_str; } } return (negative ? "-" : "") + String::num_int64(val); @@ -107,8 +107,8 @@ String Utilities::float_to_string_dp_dynamic(float val) { } String Utilities::date_to_string(Date date) { - static const String date_template_string = String { "%d" } + Date::SEPARATOR_CHARACTER + "%d" + - Date::SEPARATOR_CHARACTER + "%d"; + static const String date_template_string = + String { "%d" } + Date::SEPARATOR_CHARACTER + "%d" + Date::SEPARATOR_CHARACTER + "%d"; return vformat(date_template_string, date.get_year(), date.get_month(), date.get_day()); } @@ -197,7 +197,9 @@ Ref Utilities::make_solid_colour_image(Color const& colour, int32_t width return result; } -Ref Utilities::make_solid_colour_texture(Color const& colour, int32_t width, int32_t height, Image::Format format) { +Ref Utilities::make_solid_colour_texture( // + Color const& colour, int32_t width, int32_t height, Image::Format format +) { const Ref image = make_solid_colour_image(colour, width, height, format); ERR_FAIL_NULL_V(image, nullptr); const Ref result = ImageTexture::create_from_image(image); diff --git a/extension/src/openvic-extension/utility/Utilities.hpp b/extension/src/openvic-extension/utility/Utilities.hpp index 39e92426..4ecc483e 100644 --- a/extension/src/openvic-extension/utility/Utilities.hpp +++ b/extension/src/openvic-extension/utility/Utilities.hpp @@ -2,13 +2,13 @@ #include +#include #include #include #include #include #include -#include "godot_cpp/classes/file_access.hpp" #define ERR(x) ((x) ? OK : FAILED) @@ -85,6 +85,8 @@ namespace OpenVic::Utilities { ); namespace literals { - constexpr real_t operator""_real(long double val) { return to_real_t(val); } + constexpr real_t operator""_real(long double val) { + return to_real_t(val); + } } }