Skip to content

Commit

Permalink
Merge pull request #367 from OpenVicProject/trade-menu
Browse files Browse the repository at this point in the history
Add trade menu control script
  • Loading branch information
Hop311 authored Feb 2, 2025
2 parents 0523104 + acf0edc commit 79a0f12
Show file tree
Hide file tree
Showing 12 changed files with 1,070 additions and 19 deletions.
10 changes: 10 additions & 0 deletions extension/doc_classes/GUILineChart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
<description>
</description>
</method>
<method name="get_max_value" qualifiers="const">
<return type="float" />
<description>
</description>
</method>
<method name="get_min_value" qualifiers="const">
<return type="float" />
<description>
</description>
</method>
<method name="scale_coloured_lines">
<return type="void" />
<description>
Expand Down
91 changes: 91 additions & 0 deletions extension/doc_classes/GUINode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
<description>
</description>
</method>
<method name="get_gui_icon_button_from_node_and_path" qualifiers="static">
<return type="GUIIconButton" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_icon_button_from_nodepath" qualifiers="const">
<return type="GUIIconButton" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -67,6 +74,13 @@
<description>
</description>
</method>
<method name="get_gui_icon_from_node_and_path" qualifiers="static">
<return type="GUIIcon" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_icon_from_nodepath" qualifiers="const">
<return type="GUIIcon" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -79,6 +93,13 @@
<description>
</description>
</method>
<method name="get_gui_label_from_node_and_path" qualifiers="static">
<return type="GUILabel" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_label_from_nodepath" qualifiers="const">
<return type="GUILabel" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -91,6 +112,13 @@
<description>
</description>
</method>
<method name="get_gui_line_chart_from_node_and_path" qualifiers="static">
<return type="GUILineChart" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_line_chart_from_nodepath" qualifiers="const">
<return type="GUILineChart" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -103,6 +131,13 @@
<description>
</description>
</method>
<method name="get_gui_listbox_from_node_and_path" qualifiers="static">
<return type="GUIListBox" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_listbox_from_nodepath" qualifiers="const">
<return type="GUIListBox" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -115,6 +150,13 @@
<description>
</description>
</method>
<method name="get_gui_masked_flag_button_from_node_and_path" qualifiers="static">
<return type="GUIMaskedFlagButton" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_masked_flag_button_from_nodepath" qualifiers="const">
<return type="GUIMaskedFlagButton" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -127,6 +169,13 @@
<description>
</description>
</method>
<method name="get_gui_masked_flag_from_node_and_path" qualifiers="static">
<return type="GUIMaskedFlag" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_masked_flag_from_nodepath" qualifiers="const">
<return type="GUIMaskedFlag" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -139,6 +188,13 @@
<description>
</description>
</method>
<method name="get_gui_overlapping_elements_box_from_node_and_path" qualifiers="static">
<return type="GUIOverlappingElementsBox" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_overlapping_elements_box_from_nodepath" qualifiers="const">
<return type="GUIOverlappingElementsBox" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -151,6 +207,13 @@
<description>
</description>
</method>
<method name="get_gui_pie_chart_from_node_and_path" qualifiers="static">
<return type="GUIPieChart" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_pie_chart_from_nodepath" qualifiers="const">
<return type="GUIPieChart" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -170,6 +233,13 @@
<description>
</description>
</method>
<method name="get_gui_progress_bar_from_node_and_path" qualifiers="static">
<return type="GUIProgressBar" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_progress_bar_from_nodepath" qualifiers="const">
<return type="GUIProgressBar" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -182,6 +252,13 @@
<description>
</description>
</method>
<method name="get_gui_scrollbar_from_node_and_path" qualifiers="static">
<return type="GUIScrollbar" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_gui_scrollbar_from_nodepath" qualifiers="const">
<return type="GUIScrollbar" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -194,6 +271,13 @@
<description>
</description>
</method>
<method name="get_line_edit_from_node_and_path" qualifiers="static">
<return type="LineEdit" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_line_edit_from_nodepath" qualifiers="const">
<return type="LineEdit" />
<param index="0" name="path" type="NodePath" />
Expand All @@ -206,6 +290,13 @@
<description>
</description>
</method>
<method name="get_panel_from_node_and_path" qualifiers="static">
<return type="Panel" />
<param index="0" name="node" type="Node" />
<param index="1" name="path" type="NodePath" />
<description>
</description>
</method>
<method name="get_panel_from_nodepath" qualifiers="const">
<return type="Panel" />
<param index="0" name="path" type="NodePath" />
Expand Down
24 changes: 24 additions & 0 deletions extension/doc_classes/MenuSingleton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@
<description>
</description>
</method>
<method name="get_trade_menu_good_categories_info" qualifiers="const">
<return type="Dictionary" />
<description>
</description>
</method>
<method name="get_trade_menu_tables_info" qualifiers="const">
<return type="Dictionary" />
<description>
</description>
</method>
<method name="get_trade_menu_trade_details_info" qualifiers="const">
<return type="Dictionary" />
<param index="0" name="trade_detail_good_index" type="int" />
<description>
</description>
</method>
<method name="hide_tooltip">
<return type="void" />
<description>
Expand Down Expand Up @@ -337,6 +353,14 @@
</constant>
<constant name="SORT_LITERACY" value="17" enum="PopSortKey">
</constant>
<constant name="TRADE_SETTING_NONE" value="0" enum="TradeSettingBit">
</constant>
<constant name="TRADE_SETTING_AUTOMATED" value="1" enum="TradeSettingBit">
</constant>
<constant name="TRADE_SETTING_BUYING" value="2" enum="TradeSettingBit">
</constant>
<constant name="TRADE_SETTING_SELLING" value="4" enum="TradeSettingBit">
</constant>
<constant name="LEADER_SORT_NONE" value="0" enum="LeaderSortKey">
</constant>
<constant name="LEADER_SORT_PRESTIGE" value="1" enum="LeaderSortKey">
Expand Down
6 changes: 6 additions & 0 deletions extension/src/openvic-extension/classes/GUILineChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ void GUILineChart::_bind_methods() {
OV_BIND_METHOD(GUILineChart::clear);
OV_BIND_METHOD(GUILineChart::clear_lines);

OV_BIND_METHOD(GUILineChart::get_min_value);
OV_BIND_METHOD(GUILineChart::get_max_value);

OV_BIND_METHOD(GUILineChart::set_gfx_line_chart_name, { "new_gfx_line_chart_name" });
OV_BIND_METHOD(GUILineChart::get_gfx_line_chart_name);

Expand Down Expand Up @@ -118,6 +121,9 @@ Error GUILineChart::set_gradient_line(PackedFloat32Array const& line_values, flo
}
}

min_value = central_value - min_value_range;
max_value = central_value + min_value_range;

if (min_value_range == 0.0f) {
min_value_range = 1.0f;
} else {
Expand Down
3 changes: 2 additions & 1 deletion extension/src/openvic-extension/classes/GUILineChart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace OpenVic {
GFX::LineChart const* gfx_line_chart = nullptr;

int32_t point_count = 0;
float min_value = 0.0f, max_value = 0.0f;
float PROPERTY(min_value, 0.0f);
float PROPERTY(max_value, 0.0f);

protected:
static void _bind_methods();
Expand Down
4 changes: 4 additions & 0 deletions extension/src/openvic-extension/classes/GUINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void GUINode::_bind_methods() {

#define GET_BINDINGS(type, name) \
OV_BIND_SMETHOD(get_##name##_from_node, { "node" }); \
OV_BIND_SMETHOD(get_##name##_from_node_and_path, { "node", "path" }); \
OV_BIND_METHOD(GUINode::get_##name##_from_nodepath, { "path" });

APPLY_TO_CHILD_TYPES(GET_BINDINGS)
Expand Down Expand Up @@ -139,6 +140,9 @@ static T* _cast_node(Node* node) {
type* GUINode::get_##name##_from_node(Node* node) { \
return _cast_node<type>(node); \
} \
type* GUINode::get_##name##_from_node_and_path(Node* node, NodePath const& path) { \
return _cast_node<type>(node->get_node_internal(path)); \
} \
type* GUINode::get_##name##_from_nodepath(NodePath const& path) const { \
return _cast_node<type>(get_node_internal(path)); \
}
Expand Down
19 changes: 19 additions & 0 deletions extension/src/openvic-extension/classes/GUINode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ namespace OpenVic {
static godot::LineEdit* get_line_edit_from_node(godot::Node* node);
static GUILineChart* get_gui_line_chart_from_node(godot::Node* node);

// 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(
godot::Node* node, godot::NodePath const& path
);
static GUILabel* get_gui_label_from_node_and_path(godot::Node* node, godot::NodePath const& path);
static godot::Panel* get_panel_from_node_and_path(godot::Node* node, godot::NodePath const& path);
static GUIProgressBar* get_gui_progress_bar_from_node_and_path(godot::Node* node, godot::NodePath const& path);
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(
godot::Node* node, godot::NodePath const& path
);
static GUIScrollbar* get_gui_scrollbar_from_node_and_path(godot::Node* node, godot::NodePath const& path);
static GUIListBox* get_gui_listbox_from_node_and_path(godot::Node* node, godot::NodePath const& path);
static godot::LineEdit* get_line_edit_from_node_and_path(godot::Node* node, godot::NodePath const& path);
static GUILineChart* get_gui_line_chart_from_node_and_path(godot::Node* node, godot::NodePath const& path);

GUIIconButton* get_gui_icon_button_from_nodepath(godot::NodePath const& path) const;
GUIMaskedFlagButton* get_gui_masked_flag_button_from_nodepath(godot::NodePath const& path) const;
GUILabel* get_gui_label_from_nodepath(godot::NodePath const& path) const;
Expand Down
10 changes: 10 additions & 0 deletions extension/src/openvic-extension/singletons/MenuSingleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ void MenuSingleton::_bind_methods() {
BIND_ENUM_CONSTANT(SORT_SIZE_CHANGE);
BIND_ENUM_CONSTANT(SORT_LITERACY);

/* TRADE MENU */
OV_BIND_METHOD(MenuSingleton::get_trade_menu_good_categories_info);
OV_BIND_METHOD(MenuSingleton::get_trade_menu_trade_details_info, { "trade_detail_good_index" });
OV_BIND_METHOD(MenuSingleton::get_trade_menu_tables_info);

BIND_ENUM_CONSTANT(TRADE_SETTING_NONE);
BIND_ENUM_CONSTANT(TRADE_SETTING_AUTOMATED);
BIND_ENUM_CONSTANT(TRADE_SETTING_BUYING);
BIND_ENUM_CONSTANT(TRADE_SETTING_SELLING);

/* MILITARY MENU */
OV_BIND_METHOD(MenuSingleton::get_military_menu_info, {
"leader_sort_key", "sort_leaders_descending",
Expand Down
10 changes: 10 additions & 0 deletions extension/src/openvic-extension/singletons/MenuSingleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ namespace OpenVic {
std::vector<Pop const*> pops, filtered_pops;
};

enum TradeSettingBit {
TRADE_SETTING_NONE = 0, TRADE_SETTING_AUTOMATED = 1, TRADE_SETTING_BUYING = 2, TRADE_SETTING_SELLING = 4
};

enum LeaderSortKey {
LEADER_SORT_NONE, LEADER_SORT_PRESTIGE, LEADER_SORT_TYPE, LEADER_SORT_NAME, LEADER_SORT_ASSIGNMENT,
MAX_LEADER_SORT_KEY
Expand Down Expand Up @@ -233,6 +237,11 @@ namespace OpenVic {
/* Array of GFXPieChartTexture::godot_pie_chart_data_t. */
godot::TypedArray<godot::Array> get_population_menu_distribution_info() const;

/* TRADE MENU */
godot::Dictionary get_trade_menu_good_categories_info() const;
godot::Dictionary get_trade_menu_trade_details_info(int32_t trade_detail_good_index) const;
godot::Dictionary get_trade_menu_tables_info() const;

/* MILITARY MENU */
godot::Dictionary make_leader_dict(LeaderBase const& leader);
template<UnitType::branch_t Branch>
Expand All @@ -257,5 +266,6 @@ namespace OpenVic {

VARIANT_ENUM_CAST(OpenVic::MenuSingleton::ProvinceListEntry);
VARIANT_ENUM_CAST(OpenVic::MenuSingleton::PopSortKey);
VARIANT_ENUM_CAST(OpenVic::MenuSingleton::TradeSettingBit);
VARIANT_ENUM_CAST(OpenVic::MenuSingleton::LeaderSortKey);
VARIANT_ENUM_CAST(OpenVic::MenuSingleton::UnitGroupSortKey);
Loading

0 comments on commit 79a0f12

Please sign in to comment.