aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-03-03 14:23:21 +0100
committer hop311 <hop3114@gmail.com>2024-03-03 14:29:30 +0100
commitd45d6270c8924f571b53d71ac8eb9ce5a7788255 (patch)
treea617e5ff1f417797330e9a81abb478700b602ec4
parent9e305db5e5090a1a24979c480d64eebfe2de65da (diff)
ProgressBar, StyleBoxTexture, Icon tweaks + current dir install check fix
m---------extension/deps/openvic-simulation0
-rw-r--r--extension/src/openvic-extension/classes/GUINode.cpp6
-rw-r--r--extension/src/openvic-extension/classes/GUINode.hpp1
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.cpp17
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.hpp6
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.cpp8
-rw-r--r--extension/src/openvic-extension/singletons/GameSingleton.hpp9
-rw-r--r--extension/src/openvic-extension/utility/UITools.cpp25
-rw-r--r--game/assets/localisation/locales/en_GB/menus.csv2
-rw-r--r--game/assets/localisation/locales/ru_RU/menus.csv2
-rw-r--r--game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn2
-rw-r--r--game/src/Game/GameSession/ProvinceOverviewPanel.gd5
-rw-r--r--game/src/Game/GameSession/Topbar.gd4
-rw-r--r--game/src/Game/GameStart.gd2
14 files changed, 49 insertions, 40 deletions
diff --git a/extension/deps/openvic-simulation b/extension/deps/openvic-simulation
-Subproject 164e76e367ff7dc5914f0d7105b5914fd3fba90
+Subproject 2c892c99a6647be15ef23cabf6cc40f08769283
diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp
index 5296ad7..ceff66e 100644
--- a/extension/src/openvic-extension/classes/GUINode.cpp
+++ b/extension/src/openvic-extension/classes/GUINode.cpp
@@ -48,6 +48,7 @@ void GUINode::_bind_methods() {
OV_BIND_SMETHOD(int_to_formatted_string, { "val" });
OV_BIND_SMETHOD(float_to_formatted_string, { "val", "decimal_places" });
+ OV_BIND_SMETHOD(format_province_name, { "province_identifier" });
}
GUINode::GUINode() {
@@ -189,3 +190,8 @@ String GUINode::int_to_formatted_string(int64_t val) {
String GUINode::float_to_formatted_string(float val, int32_t decimal_places) {
return Utilities::float_to_formatted_string(val, decimal_places);
}
+
+String GUINode::format_province_name(String const& province_identifier) {
+ static const String province_prefix = "PROV";
+ return province_prefix + province_identifier;
+}
diff --git a/extension/src/openvic-extension/classes/GUINode.hpp b/extension/src/openvic-extension/classes/GUINode.hpp
index f935683..dc7f665 100644
--- a/extension/src/openvic-extension/classes/GUINode.hpp
+++ b/extension/src/openvic-extension/classes/GUINode.hpp
@@ -69,5 +69,6 @@ namespace OpenVic {
static godot::String int_to_formatted_string(int64_t val);
static godot::String float_to_formatted_string(float val, int32_t decimal_places);
+ static godot::String format_province_name(godot::String const& province_identifier);
};
}
diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp
index 546dc9d..083d934 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.cpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.cpp
@@ -13,8 +13,8 @@ using OpenVic::Utilities::godot_to_std_string;
using OpenVic::Utilities::std_to_godot_string;
void AssetManager::_bind_methods() {
- OV_BIND_METHOD(AssetManager::get_image, { "path" });
- OV_BIND_METHOD(AssetManager::get_texture, { "path" });
+ OV_BIND_METHOD(AssetManager::get_image, { "path", "cache", "flip_y" }, DEFVAL(true), DEFVAL(false));
+ OV_BIND_METHOD(AssetManager::get_texture, { "path", "flip_y" }, DEFVAL(false));
OV_BIND_METHOD(AssetManager::get_font, { "name" });
}
@@ -45,19 +45,22 @@ Ref<Image> AssetManager::_load_image(StringName const& path) {
return image;
}
-AssetManager::image_asset_t* AssetManager::_get_image_asset(StringName const& path) {
+AssetManager::image_asset_t* AssetManager::_get_image_asset(StringName const& path, bool flip_y) {
image_asset_map_t::iterator it = image_assets.find(path);
if (it != image_assets.end()) {
return &it.value();
}
const Ref<Image> image = _load_image(path);
ERR_FAIL_NULL_V(image, nullptr);
+ if (flip_y) {
+ image->flip_y();
+ }
return &image_assets.emplace(std::move(path), AssetManager::image_asset_t { image, nullptr }).first.value();
}
-Ref<Image> AssetManager::get_image(StringName const& path, bool cache) {
+Ref<Image> AssetManager::get_image(StringName const& path, bool cache, bool flip_y) {
if (cache) {
- image_asset_t const* asset = _get_image_asset(path);
+ image_asset_t const* asset = _get_image_asset(path, flip_y);
ERR_FAIL_NULL_V(asset, nullptr);
return asset->image;
} else {
@@ -65,8 +68,8 @@ Ref<Image> AssetManager::get_image(StringName const& path, bool cache) {
}
}
-Ref<ImageTexture> AssetManager::get_texture(StringName const& path) {
- image_asset_t* asset = _get_image_asset(path);
+Ref<ImageTexture> AssetManager::get_texture(StringName const& path, bool flip_y) {
+ image_asset_t* asset = _get_image_asset(path, flip_y);
ERR_FAIL_NULL_V(asset, nullptr);
if (asset->texture.is_null()) {
asset->texture = ImageTexture::create_from_image(asset->image);
diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp
index 7f73e4c..0416e5b 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.hpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.hpp
@@ -25,7 +25,7 @@ namespace OpenVic {
font_map_t fonts;
static godot::Ref<godot::Image> _load_image(godot::StringName const& path);
- image_asset_t* _get_image_asset(godot::StringName const& path);
+ image_asset_t* _get_image_asset(godot::StringName const& path, bool flip_y);
protected:
static void _bind_methods();
@@ -38,12 +38,12 @@ namespace OpenVic {
/* Search for and load an image at the specified path relative to the game defines, first checking the AssetManager's
* image cache (if cache is true) in case it has already been loaded, and returning nullptr if image loading fails. */
- godot::Ref<godot::Image> get_image(godot::StringName const& path, bool cache = true);
+ godot::Ref<godot::Image> get_image(godot::StringName const& path, bool cache = true, bool flip_y = false);
/* Create a texture from an image found at the specified path relative to the game defines, fist checking
* AssetManager's texture cache in case it has already been loaded, and returning nullptr if image loading
* or texture creation fails. */
- godot::Ref<godot::ImageTexture> get_texture(godot::StringName const& path);
+ godot::Ref<godot::ImageTexture> get_texture(godot::StringName const& path, bool flip_y = false);
/* Search for and load a font with the specified name from the game defines' font directory, first checking the
* AssetManager's font cache in case it has already been loaded, and returning nullptr if font loading fails. */
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp
index 9b8abce..8893f75 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp
@@ -129,14 +129,6 @@ void GameSingleton::setup_logger() {
});
}
-GameManager const& GameSingleton::get_game_manager() const {
- return game_manager;
-}
-
-Dataloader const& GameSingleton::get_dataloader() const {
- return dataloader;
-}
-
Error GameSingleton::setup_game(int32_t bookmark_index) {
Bookmark const* bookmark = game_manager.get_history_manager().get_bookmark_manager().get_bookmark_by_index(bookmark_index);
ERR_FAIL_NULL_V_MSG(bookmark, FAILED, vformat("Failed to get bookmark with index: %d", bookmark_index));
diff --git a/extension/src/openvic-extension/singletons/GameSingleton.hpp b/extension/src/openvic-extension/singletons/GameSingleton.hpp
index 35f7437..a2b15cd 100644
--- a/extension/src/openvic-extension/singletons/GameSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/GameSingleton.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/image_texture.hpp>
#include <godot_cpp/classes/texture2d_array.hpp>
@@ -14,8 +13,8 @@ namespace OpenVic {
static inline GameSingleton* singleton = nullptr;
- GameManager game_manager;
- Dataloader dataloader;
+ GameManager PROPERTY(game_manager);
+ Dataloader PROPERTY(dataloader);
godot::Vector2i image_subdivisions;
godot::Ref<godot::Texture2DArray> province_shape_texture;
@@ -29,7 +28,6 @@ namespace OpenVic {
static godot::StringName const& _signal_province_selected();
static godot::StringName const& _signal_clock_state_changed();
- godot::Error _generate_terrain_texture_array();
godot::Error _load_map_images();
godot::Error _load_terrain_variants();
godot::Error _load_flag_images();
@@ -50,9 +48,6 @@ namespace OpenVic {
static void setup_logger();
- GameManager const& get_game_manager() const;
- Dataloader const& get_dataloader() const;
-
/* Load the game's defines in compatiblity mode from the filepath
* pointing to the defines folder. */
godot::Error load_defines_compatibility_mode(godot::PackedStringArray const& file_paths);
diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp
index 9cd5db0..3cc0d53 100644
--- a/extension/src/openvic-extension/utility/UITools.cpp
+++ b/extension/src/openvic-extension/utility/UITools.cpp
@@ -117,6 +117,11 @@ static bool add_theme_stylebox(Control* control, StringName const& theme_name, R
stylebox.instantiate();
ERR_FAIL_NULL_V(stylebox, false);
stylebox->set_texture(texture);
+
+ static const StringName changed_signal = "changed";
+ static const StringName emit_changed_func = "emit_changed";
+ texture->connect(changed_signal, Callable { *stylebox, emit_changed_func }, Object::CONNECT_PERSIST);
+
control->add_theme_stylebox_override(theme_name, stylebox);
return true;
};
@@ -145,6 +150,9 @@ static bool generate_icon(generate_gui_args_t&& args) {
ret = false;
}
+ const float scale = icon.get_scale();
+ godot_texture_rect->set_scale({ scale, scale });
+
args.result = godot_texture_rect;
} else if (icon.get_sprite()->is_type<GFX::MaskedFlag>()) {
TextureRect* godot_texture_rect = nullptr;
@@ -168,12 +176,15 @@ static bool generate_icon(generate_gui_args_t&& args) {
godot_progress_bar, false, vformat("Failed to create TextureProgressBar for GUI icon %s", icon_name)
);
+ godot_progress_bar->set_nine_patch_stretch(true);
+ godot_progress_bar->set_max(1.0);
+
GFX::ProgressBar const* progress_bar = icon.get_sprite()->cast_to<GFX::ProgressBar>();
Ref<ImageTexture> back_texture;
if (!progress_bar->get_back_texture_file().empty()) {
const StringName back_texture_file = std_view_to_godot_string_name(progress_bar->get_back_texture_file());
- back_texture = args.asset_manager.get_texture(back_texture_file);
+ back_texture = args.asset_manager.get_texture(back_texture_file, true);
if (back_texture.is_null()) {
UtilityFunctions::push_error(
"Failed to load progress bar sprite back texture ", back_texture_file, " for GUI icon ", icon_name
@@ -205,7 +216,7 @@ static bool generate_icon(generate_gui_args_t&& args) {
Ref<ImageTexture> progress_texture;
if (!progress_bar->get_progress_texture_file().empty()) {
const StringName progress_texture_file = std_view_to_godot_string_name(progress_bar->get_progress_texture_file());
- progress_texture = args.asset_manager.get_texture(progress_texture_file);
+ progress_texture = args.asset_manager.get_texture(progress_texture_file, true);
if (progress_texture.is_null()) {
UtilityFunctions::push_error(
"Failed to load progress bar sprite progress texture ", progress_texture_file, " for GUI icon ", icon_name
@@ -266,9 +277,13 @@ static bool generate_icon(generate_gui_args_t&& args) {
}
if (args.result != nullptr) {
- const float scale = icon.get_scale();
- args.result->set_scale({ scale, scale });
- // TODO - rotation (may have to translate as godot rotates around the top left corner)
+ const float rotation = icon.get_rotation();
+ if (rotation != 0.0f) {
+ args.result->set_position(
+ args.result->get_position() - args.result->get_custom_minimum_size().height * Vector2 { sin(rotation), cos(rotation) - 1.0f }
+ );
+ args.result->set_rotation(-rotation);
+ }
}
} else {
UtilityFunctions::push_error("Null sprite for GUI icon ", icon_name);
diff --git a/game/assets/localisation/locales/en_GB/menus.csv b/game/assets/localisation/locales/en_GB/menus.csv
index 67e3519..e488996 100644
--- a/game/assets/localisation/locales/en_GB/menus.csv
+++ b/game/assets/localisation/locales/en_GB/menus.csv
@@ -132,7 +132,7 @@ VIC2_DIR_DIALOG_SELECT;Select
VIC2_DIR_DIALOG_CANCEL;Cancel
;; Province Overview Panel
-province_MISSING;No Province
+PROV_MISSING;No Province
region_MISSING;No Region
LIFE_RATING_TOOLTIP;Liferating: {life_rating}
terrain_type_MISSING;No Terrain Type
diff --git a/game/assets/localisation/locales/ru_RU/menus.csv b/game/assets/localisation/locales/ru_RU/menus.csv
index 76605d3..4e96f82 100644
--- a/game/assets/localisation/locales/ru_RU/menus.csv
+++ b/game/assets/localisation/locales/ru_RU/menus.csv
@@ -108,7 +108,7 @@ DIALOG_SAVE_AND_RESIGN;Сохраниться и выйти в главное м
DIALOG_SAVE_AND_QUIT;Сохраниться и выйти из игры
;; Province Overview Panel
-province_MISSING;Нет провинции
+PROV_MISSING;Нет провинции
region_MISSING;Нет региона
LIFE_RATING_TOOLTIP;Уровень жизни: {life_rating}
rgo_MISSING;Нет ДП
diff --git a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn
index 2bb62f1..6731358 100644
--- a/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn
+++ b/game/src/Game/GameSession/MapControlPanel/MapControlPanel.tscn
@@ -40,7 +40,7 @@ alignment = 1
[node name="MapmodesGrid" type="GridContainer" parent="MapPanelMargin/MapPanelList/MapDisplayList"]
editor_description = "UI-750"
layout_mode = 2
-columns = 11
+columns = 7
[node name="Minimap" type="PanelContainer" parent="MapPanelMargin/MapPanelList/MapDisplayList"]
editor_description = "UI-549"
diff --git a/game/src/Game/GameSession/ProvinceOverviewPanel.gd b/game/src/Game/GameSession/ProvinceOverviewPanel.gd
index 32f9600..54591a3 100644
--- a/game/src/Game/GameSession/ProvinceOverviewPanel.gd
+++ b/game/src/Game/GameSession/ProvinceOverviewPanel.gd
@@ -251,8 +251,7 @@ func _update_info() -> void:
if _province_info:
# Header
if _province_name_label:
- _province_name_label.text = "PROV" + _province_info.get(_province_info_province_key,
- _province_info_province_key + _missing_suffix)
+ _province_name_label.text = GUINode.format_province_name(_province_info.get(_province_info_province_key, _missing_suffix))
if _region_name_label:
_region_name_label.text = _province_info.get(_province_info_region_key,
@@ -294,7 +293,7 @@ func _update_info() -> void:
push_error("Failed to set terrain type texture: ", terrain_type)
if _life_rating_bar:
- _life_rating_bar.value = _province_info.get(_province_info_life_rating_key, 0)
+ _life_rating_bar.value = _province_info.get(_province_info_life_rating_key, 0) / 100.0
if _controller_flag_texture:
_controller_flag_texture.set_flag_country_name(_province_info.get(_province_info_controller_key, ""))
diff --git a/game/src/Game/GameSession/Topbar.gd b/game/src/Game/GameSession/Topbar.gd
index e660c6a..82dd4d3 100644
--- a/game/src/Game/GameSession/Topbar.gd
+++ b/game/src/Game/GameSession/Topbar.gd
@@ -73,7 +73,7 @@ func _ready() -> void:
button.pressed.connect(
Events.NationManagementScreens.toggle_nation_management_screen.bind(screen)
)
- var icon : GFXSpriteTexture = get_gfx_sprite_texture_from_node(button)
+ var icon : GFXSpriteTexture = GUINode.get_gfx_sprite_texture_from_node(button)
if icon:
_nation_management_buttons[screen] = button
_nation_management_button_textures[screen] = icon
@@ -107,7 +107,6 @@ func _update_speed_controls() -> void:
if not GameSingleton.is_paused():
index += GameSingleton.get_speed() + 1
_speed_indicator_texture.set_icon_index(index)
- _speed_indicator_button.queue_redraw()
# REQUIREMENTS:
# * UIFUN-71
@@ -130,4 +129,3 @@ func _on_decrease_speed_button_pressed() -> void:
func _on_update_active_nation_management_screen(active_screen : NationManagement.Screen) -> void:
for screen in _nation_management_buttons:
_nation_management_button_textures[screen].set_icon_index(1 + int(screen == active_screen))
- _nation_management_buttons[screen].queue_redraw()
diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd
index 0aadbb9..6074df8 100644
--- a/game/src/Game/GameStart.gd
+++ b/game/src/Game/GameStart.gd
@@ -70,7 +70,7 @@ func _setup_compatibility_mode_paths() -> void:
else:
# Check if the program is being run from inside the install directory,
# and if not also search for a Steam install
- actual_base_path = GameSingleton.search_for_game_path("..")
+ actual_base_path = GameSingleton.search_for_game_path(".")
if not actual_base_path:
get_tree().paused = true
vic2_dir_dialog.popup_centered_ratio()