Skip to content
Merged
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: 18 additions & 0 deletions extension/doc_classes/GUILineChart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<description>
</description>
</method>
<method name="clear_tooltip">
<return type="void" />
<description>
</description>
</method>
<method name="get_gfx_line_chart_name" qualifiers="const">
<return type="String" />
<description>
Expand Down Expand Up @@ -58,9 +63,22 @@
<description>
</description>
</method>
<method name="set_tooltip_string_and_substitution_dict">
<return type="void" />
<param index="0" name="new_tooltip_string" type="String" />
<param index="1" name="new_tooltip_substitution_dict" type="Dictionary" />
<description>
</description>
</method>
</methods>
<members>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="mouse_filter" type="int" setter="set_mouse_filter" getter="get_mouse_filter" overrides="Control" enum="Control.MouseFilter" default="2" />
<member name="tooltip_active" type="bool" setter="" getter="is_tooltip_active" default="false">
</member>
<member name="tooltip_string" type="String" setter="set_tooltip_string" getter="get_tooltip_string" default="&quot;&quot;">
</member>
<member name="tooltip_substitution_dict" type="Dictionary" setter="set_tooltip_substitution_dict" getter="get_tooltip_substitution_dict" default="{}">
</member>
</members>
</class>
11 changes: 11 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@
<description>
</description>
</method>
<method name="link_top_bar_to_cpp">
<return type="void" />
<param index="0" name="godot_top_bar" type="GUINode" />
<description>
</description>
</method>
<method name="population_menu_deselect_all_pop_filters">
<return type="int" enum="Error" />
<description>
Expand Down Expand Up @@ -260,6 +266,11 @@
<description>
</description>
</method>
<method name="unlink_top_bar_from_cpp">
<return type="void" />
<description>
</description>
</method>
<method name="update_search_results">
<return type="void" />
<param index="0" name="text" type="String" />
Expand Down
7 changes: 7 additions & 0 deletions extension/src/openvic-extension/classes/GUILineChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ using namespace OpenVic;
using namespace OpenVic::Utilities::literals;
using namespace godot;

GUI_TOOLTIP_IMPLEMENTATIONS(GUILineChart)

void GUILineChart::_bind_methods() {
GUI_TOOLTIP_BIND_METHODS(GUILineChart)
OV_BIND_METHOD(GUILineChart::clear);
OV_BIND_METHOD(GUILineChart::clear_lines);

Expand All @@ -27,6 +30,10 @@ void GUILineChart::_bind_methods() {
OV_BIND_METHOD(GUILineChart::scale_coloured_lines);
}

void GUILineChart::_notification(int what) {
_tooltip_notification(what);
}

GUILineChart::GUILineChart() {
set_clip_contents(true);
set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
Expand Down
5 changes: 5 additions & 0 deletions extension/src/openvic-extension/classes/GUILineChart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
#include <godot_cpp/classes/line2d.hpp>

#include <openvic-simulation/interface/GFXSprite.hpp>
#include "openvic-extension/classes/GUIHasTooltip.hpp"

namespace OpenVic {
class GUILineChart : public godot::Control {
GDCLASS(GUILineChart, godot::Control)

GUI_TOOLTIP_DEFINITIONS

GFX::LineChart const* gfx_line_chart = nullptr;

int32_t point_count = 0;
Expand All @@ -18,6 +21,8 @@ namespace OpenVic {
protected:
static void _bind_methods();

void _notification(int what);

public:
GUILineChart();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Error GUIMaskedFlagButton::set_flag_country_name(String const& flag_country_name

return gfx_masked_flag_texture->set_flag_country_name(flag_country_name);
}
Error GUIMaskedFlagButton::set_flag_country(CountryInstance* flag_country) const {
return gfx_masked_flag_texture->set_flag_country(flag_country);
}

String GUIMaskedFlagButton::get_flag_country_name() const {
ERR_FAIL_NULL_V(gfx_masked_flag_texture, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "openvic-extension/classes/GUIButton.hpp"

namespace OpenVic {
struct CountryInstance;

class GUIMaskedFlagButton : public GUIButton {
GDCLASS(GUIMaskedFlagButton, GUIButton)

Expand All @@ -26,6 +28,7 @@ namespace OpenVic {
) const;

godot::Error set_flag_country_name(godot::String const& flag_country_name) const;
godot::Error set_flag_country(CountryInstance* flag_country) const;

godot::String get_flag_country_name() const;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "BudgetOverview.hpp"

#include <openvic-simulation/types/fixed_point/FixedPoint.hpp>

#include "openvic-extension/classes/GUILabel.hpp"
#include "openvic-extension/classes/GUILineChart.hpp"
#include "openvic-extension/classes/GUINode.hpp"
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/singletons/PlayerSingleton.hpp"

using namespace OpenVic;

BudgetOverview::BudgetOverview(GUINode const& parent):
funds_label{*parent.get_gui_label_from_nodepath("./topbar/budget_funds")},
history_chart{*parent.get_gui_line_chart_from_nodepath("./topbar/budget_linechart")}
{}

void BudgetOverview::update() {
GameSingleton& game_singleton = *GameSingleton::get_singleton();
CountryInstance* country_ptr = PlayerSingleton::get_singleton()->get_player_country();
if (country_ptr == nullptr) {
return;
}
CountryInstance& country = *country_ptr;

const fixed_point_t cash = country.get_cash_stockpile();
ValueHistory<fixed_point_t> const& balance_history = country.get_balance_history();
fixed_point_t last_balance;
fixed_point_t maximum_balance;
fixed_point_t minimum_balance;
if (balance_history.empty()) {
last_balance = maximum_balance = minimum_balance = fixed_point_t::_0;
} else {
maximum_balance = fixed_point_t::min;
minimum_balance = fixed_point_t::max;
for (fixed_point_t const& balance : balance_history) {
if (balance > maximum_balance) {
maximum_balance = balance;
}
if (balance < minimum_balance) {
minimum_balance = balance;
}
}
last_balance = balance_history.back();
godot::PackedFloat32Array line_values;
line_values.resize(balance_history.capacity());
size_t index = line_values.size();
for (auto it = balance_history.rbegin(); it != balance_history.rend(); ++it) {
line_values[--index] = *it;
}
history_chart.set_gradient_line(line_values);
}

funds_label.set_text(
Utilities::format(
godot::String::utf8("§Y%s§W (§%s%s§W)"),
Utilities::cash_to_string_dp_dynamic(cash),
Utilities::get_colour_and_sign(last_balance),
Utilities::cash_to_string_dp_dynamic(last_balance)
)
);
funds_label.set_tooltip_string(
funds_label.tr("TOPBAR_FUNDS")
.replace("$YESTERDAY$", Utilities::format(
godot::String::utf8("§%s%s§W"),
Utilities::get_colour_and_sign(last_balance),
Utilities::cash_to_string_dp_dynamic(last_balance)
))
.replace("$CASH$", Utilities::format(
godot::String::utf8("§Y%s§W"),
Utilities::cash_to_string_dp_dynamic(cash)
))
);
history_chart.set_tooltip_string(
history_chart.tr("TOPBAR_HISTORICAL_INCOME")
.replace("$DAYS$", godot::String::num_int64(balance_history.size()))
.replace("$MAX$", Utilities::format(
godot::String::utf8("§%s%s§W"),
Utilities::get_colour_and_sign(maximum_balance),
Utilities::cash_to_string_dp_dynamic(maximum_balance)
))
.replace("$MIN$", Utilities::format(
godot::String::utf8("§%s%s§W"),
Utilities::get_colour_and_sign(minimum_balance),
Utilities::cash_to_string_dp_dynamic(minimum_balance)
))
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

namespace OpenVic {
struct GUILabel;
struct GUILineChart;
struct GUINode;

struct BudgetOverview {
private:
GUILabel& funds_label;
GUILineChart& history_chart;
public:
BudgetOverview(GUINode const& parent);
void update();
};
}
Loading
Loading