Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include <godot_cpp/classes/rendering_server.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

#include <openvic-simulation/utility/Typedefs.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"

using namespace OpenVic;
using namespace godot;
Expand Down Expand Up @@ -135,22 +138,17 @@ Error GFXButtonStateTexture::generate_state_image(
}

StringName const& GFXButtonStateTexture::button_state_to_name(ButtonState button_state) {
static const StringName name_hover = "hover";
static const StringName name_pressed = "pressed";
static const StringName name_disabled = "disabled";
static const StringName name_selected = "selected";
static const StringName name_error = "INVALID BUTTON STATE";
switch (button_state) {
case HOVER:
return name_hover;
return OV_SNAME(hover);
case PRESSED:
return name_pressed;
return OV_SNAME(pressed);
case DISABLED:
return name_disabled;
return OV_SNAME(disabled);
case SELECTED:
return name_selected;
return OV_SNAME(selected);
default:
return name_error;
unreachable();
}
}

Expand Down
13 changes: 5 additions & 8 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
#include <numbers>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/utility/UITools.hpp"

using namespace godot;
using namespace OpenVic;
using namespace OpenVic::Utilities::literals;

StringName const& GFXPieChartTexture::_slice_identifier_key() {
static const StringName slice_identifier_key = "identifier";
return slice_identifier_key;
return OV_SNAME(identifier);
}
StringName const& GFXPieChartTexture::_slice_tooltip_key() {
static const StringName slice_tooltip_key = "tooltip";
return slice_tooltip_key;
return OV_SNAME(tooltip);
}
StringName const& GFXPieChartTexture::_slice_colour_key() {
static const StringName slice_colour_key = "colour";
return slice_colour_key;
return OV_SNAME(colour);
}
StringName const& GFXPieChartTexture::_slice_weight_key() {
static const StringName slice_weight_key = "weight";
return slice_weight_key;
return OV_SNAME(weight);
}

GFXPieChartTexture::slice_t const* GFXPieChartTexture::get_slice(Vector2 const& position) const {
Expand Down
25 changes: 12 additions & 13 deletions extension/src/openvic-extension/classes/GUIButton.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "GUIButton.hpp"

#include <array>

#include <godot_cpp/variant/utility_functions.hpp>

#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/singletons/AssetManager.hpp"
#include "openvic-extension/utility/Utilities.hpp"

Expand Down Expand Up @@ -33,9 +32,7 @@ Error GUIButton::set_gfx_button_state_having_texture(Ref<GFXButtonStateHavingTex
Ref<StyleBoxTexture> stylebox = AssetManager::make_stylebox_texture(texture);

if (stylebox.is_valid()) {
static const StringName normal_theme = "normal";

add_theme_stylebox_override(normal_theme, stylebox);
add_theme_stylebox_override(OV_SNAME(normal), stylebox);
} else {
UtilityFunctions::push_error("Failed to make StyleBoxTexture for GUIButton ", get_name());

Expand Down Expand Up @@ -86,22 +83,24 @@ Error GUIButton::set_gfx_font(GFX::Font const* gfx_font) {
const Ref<Font> font = asset_manager->get_font(font_file);

if (font.is_valid()) {
static const StringName font_theme = "font";

add_theme_font_override(font_theme, font);
add_theme_font_override(OV_SNAME(font), font);
} else {
UtilityFunctions::push_error("Failed to load font \"", font_file, "\" for GUIButton ", get_name());

err = FAILED;
}

static const std::array<StringName, 5> button_font_themes {
"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());

for (StringName const& theme_name : button_font_themes) {
for (StringName const& theme_name :
{
OV_SNAME(font_color), //
OV_SNAME(font_hover_color), //
OV_SNAME(font_hover_pressed_color), //
OV_SNAME(font_pressed_color), //
OV_SNAME(font_disabled_color) //
} //
) {
add_theme_color_override(theme_name, colour);
}

Expand Down
10 changes: 3 additions & 7 deletions extension/src/openvic-extension/classes/GUIListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
#include <godot_cpp/variant/utility_functions.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/utility/UITools.hpp"
#include "openvic-extension/utility/Utilities.hpp"

using namespace OpenVic;
using namespace godot;
using namespace OpenVic::Utilities::literals;

/* StringNames cannot be constructed until Godot has called StringName::setup(),
* so we must use wrapper functions to delay their initialisation. */
StringName const& GUIListBox::_signal_scroll_index_changed() {
static const StringName signal_scroll_index_changed = "scroll_index_changed";
return signal_scroll_index_changed;
return OV_SNAME(scroll_index_changed);
}

Error GUIListBox::_calculate_max_scroll_index(bool signal) {
Expand Down Expand Up @@ -285,10 +283,8 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) {
scrollbar->set_position(position);
scrollbar->set_length_override(size.height);

static const StringName set_scroll_index_func_name = "set_scroll_index";

scrollbar->connect(
GUIScrollbar::signal_value_changed(), Callable { this, set_scroll_index_func_name }, CONNECT_PERSIST
GUIScrollbar::signal_value_changed(), Callable { this, OV_SNAME(set_scroll_index) }, CONNECT_PERSIST
);
} else {
UtilityFunctions::push_error(
Expand Down
10 changes: 5 additions & 5 deletions extension/src/openvic-extension/classes/GUINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <godot_cpp/variant/vector2i.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/utility/UITools.hpp"
#include "openvic-extension/utility/Utilities.hpp"

Expand Down Expand Up @@ -160,21 +161,20 @@ Ref<Texture2D> GUINode::get_texture_from_node(Node* node) {
ERR_FAIL_NULL_V_MSG(texture, nullptr, Utilities::format("Failed to get Texture2D from TextureRect %s", node->get_name()));
return texture;
} else if (GUIButton const* button = Object::cast_to<GUIButton>(node); button != nullptr) {
static const StringName theme_name_normal = "normal";
const Ref<StyleBox> stylebox = button->get_theme_stylebox(theme_name_normal);
const Ref<StyleBox> stylebox = button->get_theme_stylebox(OV_SNAME(normal));
ERR_FAIL_NULL_V_MSG(
stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", theme_name_normal, node->get_name())
stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", OV_SNAME(normal), node->get_name())
);
const Ref<StyleBoxTexture> stylebox_texture = stylebox;
ERR_FAIL_NULL_V_MSG(
stylebox_texture, nullptr, Utilities::format(
"Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", theme_name_normal, node->get_name()
"Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", OV_SNAME(normal), node->get_name()
)
);
const Ref<Texture2D> result = stylebox_texture->get_texture();
ERR_FAIL_NULL_V_MSG(
result, nullptr,
Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", theme_name_normal, node->get_name())
Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", OV_SNAME(normal), node->get_name())
);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <godot_cpp/variant/utility_functions.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/utility/UITools.hpp"
#include "openvic-extension/utility/Utilities.hpp"
#include "openvic-simulation/types/TextFormat.hpp"
Expand Down Expand Up @@ -121,13 +122,9 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) {
)
);

static const StringName set_z_index_func_name = "set_z_index";
static const StringName mouse_entered_signal_name = "mouse_entered";
static const StringName mouse_exited_signal_name = "mouse_exited";

/* Move the child element in front of its neighbours when moused-over. */
child->connect(mouse_entered_signal_name, Callable { child, set_z_index_func_name }.bind(1), CONNECT_PERSIST);
child->connect(mouse_exited_signal_name, Callable { child, set_z_index_func_name }.bind(0), CONNECT_PERSIST);
child->connect(OV_SNAME(mouse_entered), Callable { child, OV_SNAME(set_z_index) }.bind(1), CONNECT_PERSIST);
child->connect(OV_SNAME(mouse_exited), Callable { child, OV_SNAME(set_z_index) }.bind(0), CONNECT_PERSIST);

add_child(child);
child_count++;
Expand Down
4 changes: 2 additions & 2 deletions extension/src/openvic-extension/classes/GUIScrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <openvic-simulation/utility/Logger.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/utility/UITools.hpp"
#include "openvic-extension/utility/Utilities.hpp"

Expand All @@ -22,8 +23,7 @@ using namespace godot;
/* StringNames cannot be constructed until Godot has called StringName::setup(),
* so we must use wrapper functions to delay their initialisation. */
StringName const& GUIScrollbar::signal_value_changed() {
static const StringName signal_value_changed = "value_changed";
return signal_value_changed;
return OV_SNAME(value_changed);
}

GUI_TOOLTIP_IMPLEMENTATIONS(GUIScrollbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <godot_cpp/variant/utility_functions.hpp>

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/StaticString.hpp"

using namespace OpenVic;
using namespace godot;
Expand Down Expand Up @@ -40,7 +41,7 @@ void StyleBoxWithSound::_bind_methods() {
}

StyleBoxWithSound::StyleBoxWithSound() {
audio_bus = "Master";
audio_bus = OV_SNAME(Master);
}

Ref<StyleBox> StyleBoxWithSound::get_style_box() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fixed_point_t AdministrationBudget::calculate_budget_and_update_custom(
CountryInstance& country,
const fixed_point_t scaled_value
) {
static const godot::StringName administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s";
static const godot::String administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s";

const fixed_point_t administrative_efficiency_from_administrators = country.get_administrative_efficiency_from_administrators_untracked();
administrative_efficiency_label.set_text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openvic-extension/classes/GUILabel.hpp"
#include "openvic-extension/classes/GUINode.hpp"
#include "openvic-extension/classes/GUIScrollbar.hpp"
#include "openvic-extension/core/StaticString.hpp"
#include "openvic-extension/singletons/PlayerSingleton.hpp"
#include "openvic-extension/utility/Utilities.hpp"

Expand Down Expand Up @@ -37,7 +38,7 @@ StrataTaxBudget::StrataTaxBudget(
GUILabel::set_text_and_tooltip(
parent,
Utilities::format("./country_budget/tax_%d_desc", static_cast<uint64_t>(new_strata.get_index())),
generate_slider_tooltip_localisation_key(new_strata),
slider_tooltip_localisation_key,
Utilities::format(
"TAX_%s_DESC",
Utilities::std_to_godot_string(strata.get_identifier()).to_upper()
Expand Down Expand Up @@ -82,22 +83,19 @@ void StrataTaxBudget::update_slider_tooltip(
const fixed_point_t scaled_value
) {
//these use $VALUE$%
static const godot::StringName tax_efficiency_localisation_key = "BUDGET_TAX_EFFICIENCY";
static const godot::StringName effective_tax_rate_localisation_key = "BUDGET_TAX_EFFECT";

//this uses $VALUE$ only
static const godot::StringName tax_efficiency_from_tech_localisation_key = "BUDGET_TECH_TAX";

const godot::String localised_strata_tax = slider.tr(slider_tooltip_localisation_key);

const fixed_point_t tax_efficiency = country.get_tax_efficiency_untracked();
const godot::String tax_efficiency_text = slider.tr(tax_efficiency_localisation_key).replace(
const godot::String tax_efficiency_text = slider.tr(OV_INAME("BUDGET_TAX_EFFICIENCY")).replace(
Utilities::get_long_value_placeholder(),
Utilities::float_to_string_dp(100 * static_cast<float>(tax_efficiency), 2)
);

const fixed_point_t tax_efficiency_from_tech = country.get_modifier_effect_value(*modifier_effect_cache.get_tax_eff());
const godot::String tax_efficiency_from_tech_text = slider.tr(tax_efficiency_from_tech_localisation_key).replace(
const godot::String tax_efficiency_from_tech_text = slider.tr(OV_INAME("BUDGET_TECH_TAX")).replace(
Utilities::get_short_value_placeholder(),
Utilities::format(
"%s%%",
Expand All @@ -109,7 +107,7 @@ void StrataTaxBudget::update_slider_tooltip(
);

const fixed_point_t effective_tax_rate = tax_efficiency * scaled_value;
const godot::String effective_tax_rate_text = slider.tr(effective_tax_rate_localisation_key).replace(
const godot::String effective_tax_rate_text = slider.tr(OV_INAME("BUDGET_TAX_EFFECT")).replace(
Utilities::get_long_value_placeholder(),
Utilities::float_to_string_dp(100 * static_cast<float>(effective_tax_rate), 2)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ void TariffBudget::update_slider_tooltip(
CountryInstance& country,
const fixed_point_t scaled_value
) {
static const godot::StringName tooltip_template = "%s\n%s\n--------------\n%s\n%s";
static const godot::StringName green = "G";
static const godot::StringName red = "R";
static const godot::String tooltip_template = "%s\n%s\n--------------\n%s\n%s";
//Yes Victoria 2 overrides the colour specified in localisation...
godot::StringName const& prefix = scaled_value < 0
? red
: green;
godot::String prefix = scaled_value < 0 ? "R" : "G";

slider_tooltip_args[0] = slider.tr(slider_tooltip_localisation_key).replace(
"Y"+Utilities::get_short_value_placeholder(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ godot::String BudgetIncomeComponent::generate_income_summary_text(
}

godot::String BudgetIncomeComponent::generate_balance_income_summary_text(godot::Object const& translation_object) const {
static const godot::StringName green_plus = "G+";
const float income = static_cast<float>(get_income()); //TODO use yesterdays value
return translation_object.tr(income_summary_localisation_key).replace(
"Y$VAL$",
green_plus + Utilities::float_to_string_dp(income, income_summary_decimal_places)
"G+" + Utilities::float_to_string_dp(income, income_summary_decimal_places)
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "SliderBudgetComponent.hpp"

#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string_name.hpp>

#include <openvic-simulation/country/CountryInstance.hpp>

Expand All @@ -14,7 +15,7 @@ using namespace OpenVic;

SliderBudgetComponent::SliderBudgetComponent(
GUINode const& parent,
godot::String&& new_slider_tooltip_localisation_key,
godot::StringName&& new_slider_tooltip_localisation_key,
const BudgetType new_budget_type,
godot::NodePath const& slider_path,
godot::NodePath const& budget_label_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <godot_cpp/variant/node_path.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/string_name.hpp>

#include "openvic-extension/components/budget/abstract/BudgetComponent.hpp"

Expand All @@ -25,13 +26,13 @@ namespace OpenVic {
void _on_slider_value_changed();
void update_labels(CountryInstance& country, const fixed_point_t scaled_value);
protected:
const godot::String slider_tooltip_localisation_key;
const godot::StringName slider_tooltip_localisation_key;
GUIScrollbar& slider;
GUILabel* const budget_label;

SliderBudgetComponent(
GUINode const& parent,
godot::String&& new_slider_tooltip_localisation_key,
godot::StringName&& new_slider_tooltip_localisation_key,
const BudgetType new_budget_type,
godot::NodePath const& slider_path,
godot::NodePath const& budget_label_path = {},
Expand Down
Loading
Loading