aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author BrickPi <ajmach6@gmail.com>2024-11-04 23:33:44 +0100
committer BrickPi <ajmach6@gmail.com>2024-11-04 23:33:51 +0100
commit05f564d918ea939e5844262c74154c005d279bed (patch)
tree3f3d60e6c408deb1c54bfb3a10ef47700e593fdd
parent7f7510cd3c3541b596d97eff8ade42e819d82c85 (diff)
tech schools
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp79
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp5
-rw-r--r--game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd23
3 files changed, 106 insertions, 1 deletions
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index 81582c2..f3b6d3d 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -1,4 +1,9 @@
#include "MenuSingleton.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <string>
+#include <string_view>
#include <godot_cpp/variant/utility_functions.hpp>
@@ -12,6 +17,12 @@
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/utility/ClassBindings.hpp"
#include "openvic-extension/utility/Utilities.hpp"
+#include "godot_cpp/variant/array.hpp"
+#include "godot_cpp/variant/dictionary.hpp"
+#include "godot_cpp/variant/string.hpp"
+#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/research/Technology.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
using namespace godot;
using namespace OpenVic;
@@ -296,6 +307,9 @@ void MenuSingleton::_bind_methods() {
OV_BIND_METHOD(MenuSingleton::get_search_result_position, { "result_index" });
ADD_SIGNAL(MethodInfo(_signal_search_cache_changed()));
+
+ /* TECHNOLOGY MENU */
+ OV_BIND_METHOD(MenuSingleton::get_technology_menu_info);
}
MenuSingleton* MenuSingleton::get_singleton() {
@@ -975,3 +989,68 @@ Vector2 MenuSingleton::get_search_result_position(int32_t result_index) const {
std::visit(entry_visitor, search_panel.entry_cache[search_panel.result_indices[result_index]].target)
);
}
+
+/* TECHNOLOGY MENU */
+godot::Dictionary MenuSingleton::get_technology_menu_info() const {
+ GameSingleton const* game_singleton = GameSingleton::get_singleton();
+ ERR_FAIL_NULL_V(game_singleton, {});
+
+ static const StringName tech_folders_key = "tech_folders";
+ static const StringName tech_school_key = "tech_school";
+ static const StringName tech_school_mod_names = "tech_school_mod_names";
+ static const StringName tech_school_mod_values = "tech_school_mod_values";
+ static const StringName tech_school_mod_icons = "tech_school_mod_icons";
+
+ Dictionary ret;
+
+ std::vector<std::string_view> tech_folder_identifiers = game_singleton->get_definition_manager().get_research_manager().get_technology_manager().get_technology_folder_identifiers();
+ Array tech_folders {};
+ for (auto folder : tech_folder_identifiers) {
+ tech_folders.push_back(Utilities::std_to_godot_string(folder));
+ }
+ ret[tech_folders_key] = tech_folders;
+
+ const CountryInstance* country = game_singleton->get_viewed_country();
+ if (country == nullptr) {
+ ret[tech_school_key] = String("traditional_academic");
+ ret[tech_school_mod_names] = Array {};
+ ret[tech_school_mod_values] = Array {};
+ return ret;
+ }
+ ret[tech_school_key] = Utilities::std_to_godot_string(country->get_tech_school() == nullptr ? "traditional_academic" : country->get_tech_school()->get_identifier());
+
+ static const auto bonus_suffix = "_research_bonus";
+ auto compareFolders = [&tech_folder_identifiers](std::pair<std::string_view, fixed_point_t> a, std::pair<std::string_view, fixed_point_t> b) -> bool {
+ std::string tempA{a.first.substr(0, a.first.find(bonus_suffix))};
+ std::string tempB{b.first.substr(0, b.first.find(bonus_suffix))};
+ return std::find(tech_folder_identifiers.begin(), tech_folder_identifiers.end(), tempA) < std::find(tech_folder_identifiers.begin(), tech_folder_identifiers.end(), tempB);
+ };
+
+ std::vector<std::pair<std::string_view, fixed_point_t>> school_modifiers;
+ if (country->get_tech_school() != nullptr) {
+ for (auto effect : country->get_tech_school()->get_values()) {
+ if (!effect.first->get_identifier().starts_with("unciv")) {
+ if (effect.second != 0) {
+ school_modifiers.push_back({effect.first->get_localisation_key(), effect.second});
+ }
+ }
+ }
+ }
+ std::sort(school_modifiers.begin(), school_modifiers.end(), compareFolders);
+
+ Array school_modifier_names {};
+ Array school_modifier_values {};
+ Array school_modifier_icons {};
+
+ for (auto modifier : school_modifiers) {
+ school_modifier_names.push_back(Utilities::std_to_godot_string(modifier.first));
+ school_modifier_values.push_back(modifier.second.to_float());
+ school_modifier_icons.push_back(1 + std::find(tech_folder_identifiers.begin(), tech_folder_identifiers.end(), modifier.first.substr(0, modifier.first.find(bonus_suffix))) - tech_folder_identifiers.begin());
+ }
+
+ ret[tech_school_mod_names] = school_modifier_names;
+ ret[tech_school_mod_values] = school_modifier_values;
+ ret[tech_school_mod_icons] = school_modifier_icons;
+
+ return ret;
+} \ No newline at end of file
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
index 0dcc8ff..198c900 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
@@ -1,11 +1,13 @@
#pragma once
+#include <cstdint>
#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/image.hpp>
#include <openvic-simulation/pop/Pop.hpp>
#include <openvic-simulation/types/IndexedMap.hpp>
#include <openvic-simulation/types/OrderedContainers.hpp>
+#include "godot_cpp/variant/dictionary.hpp"
namespace OpenVic {
struct CountryInstance;
@@ -191,6 +193,9 @@ namespace OpenVic {
/* Array of GFXPieChartTexture::godot_pie_chart_data_t. */
godot::TypedArray<godot::Array> get_population_menu_distribution_info() const;
+ /* TECHNOLOGY MENU */
+ godot::Dictionary get_technology_menu_info() const;
+
/* Find/Search Panel */
// TODO - update on country government type change and state creation/destruction
// (which automatically includes country creation/destruction)
diff --git a/game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd b/game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd
index 97c3390..3d2275b 100644
--- a/game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd
+++ b/game/src/Game/GameSession/NationManagementScreen/TechnologyMenu.gd
@@ -4,6 +4,9 @@ var _active : bool = false
const _screen : NationManagement.Screen = NationManagement.Screen.TECHNOLOGY
+var _tech_school : GUILabel
+var _tech_school_modifiers : GUIOverlappingElementsBox
+
func _ready() -> void:
GameSingleton.gamestate_updated.connect(_update_info)
@@ -11,6 +14,11 @@ func _ready() -> void:
add_gui_element("country_technology", "country_technology")
+ _tech_school = get_gui_label_from_nodepath(^"./country_technology/administration_type")
+ _tech_school_modifiers = get_gui_overlapping_elements_box_from_nodepath(^"./country_technology/school_bonus_icons")
+ if _tech_school_modifiers:
+ _tech_school_modifiers.set_gui_child_element_name("country_technology", "school_icon_window")
+
var close_button : GUIIconButton = get_gui_icon_button_from_nodepath(^"./country_technology/close_button")
if close_button:
close_button.pressed.connect(Events.NationManagementScreens.close_nation_management_screen.bind(_screen))
@@ -28,7 +36,20 @@ func _on_update_active_nation_management_screen(active_screen : NationManagement
func _update_info() -> void:
if _active:
- # TODO - update UI state
+ var info : Dictionary = MenuSingleton.get_technology_menu_info()
+ if _tech_school:
+ _tech_school.set_text(info.get("tech_school"))
+
+ if _tech_school_modifiers:
+ var mod_names : Array = info.get("tech_school_mod_names")
+ var mod_values : Array = info.get("tech_school_mod_values")
+ var mod_icons : Array = info.get("tech_school_mod_icons")
+ var mod_count = mod_names.size()
+ _tech_school_modifiers.set_child_count(mod_count)
+ for i in range(mod_count):
+ get_gui_icon_from_nodepath("./country_technology/school_bonus_icons/school_icon_window_{x}/main_icon".format({"x": i})).set_icon_index(mod_icons[i])
+ get_gui_icon_from_nodepath("./country_technology/school_bonus_icons/school_icon_window_{x}/plusminus_icon".format({"x": i})).set_icon_index(2 if mod_values[i] > 0 else 1)
+
show()
else:
hide()