aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-08-29 00:16:24 +0200
committer hop311 <hop3114@gmail.com>2024-08-29 23:04:30 +0200
commitbdc2ba527bc02e7cdf977f6040f2ca85aa4f9a94 (patch)
tree4627ad955ac60f5c66b94dfc3106bd8442b58302 /extension/src/openvic-extension/singletons
parent88acb31bd43f0e163522837bb1d0dd7da2977c4a (diff)
Add tooltips for buttons, labels, icons, pie charts, sliders, and progress barstooltip
Diffstat (limited to 'extension/src/openvic-extension/singletons')
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.cpp33
-rw-r--r--extension/src/openvic-extension/singletons/MenuSingleton.hpp14
2 files changed, 47 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
index b95bc15..367462b 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp
@@ -30,6 +30,10 @@ StringName const& MenuSingleton::_signal_search_cache_changed() {
static const StringName signal_search_cache_changed = "search_cache_changed";
return signal_search_cache_changed;
}
+StringName const& MenuSingleton::_signal_update_tooltip() {
+ static const StringName signal_update_tooltip = "update_tooltip";
+ return signal_update_tooltip;
+}
String MenuSingleton::get_state_name(State const& state) const {
StateSet const& state_set = state.get_state_set();
@@ -103,6 +107,16 @@ String MenuSingleton::get_country_adjective(CountryInstance const& country) cons
}
void MenuSingleton::_bind_methods() {
+ /* TOOLTIP */
+ OV_BIND_METHOD(MenuSingleton::show_tooltip, { "text", "substitution_dict", "position" });
+ OV_BIND_METHOD(MenuSingleton::show_control_tooltip, { "text", "substitution_dict", "control" });
+ OV_BIND_METHOD(MenuSingleton::hide_tooltip);
+
+ ADD_SIGNAL(MethodInfo(
+ _signal_update_tooltip(), PropertyInfo(Variant::STRING, "text"),
+ PropertyInfo(Variant::DICTIONARY, "substitution_dict"), PropertyInfo(Variant::VECTOR2, "position")
+ ));
+
/* PROVINCE OVERVIEW PANEL */
OV_BIND_METHOD(MenuSingleton::get_province_info_from_index, { "index" });
OV_BIND_METHOD(MenuSingleton::get_province_building_count);
@@ -205,6 +219,25 @@ MenuSingleton::~MenuSingleton() {
singleton = nullptr;
}
+/* TOOLTIP */
+
+void MenuSingleton::show_tooltip(String const& text, Dictionary const& substitution_dict, Vector2 const& position) {
+ emit_signal(_signal_update_tooltip(), text, substitution_dict, position);
+}
+
+void MenuSingleton::show_control_tooltip(String const& text, Dictionary const& substitution_dict, Control const* control) {
+ ERR_FAIL_NULL(control);
+
+ using namespace OpenVic::Utilities::literals;
+ static const Vector2 offset { 0.0_real, 64.0_real };
+
+ show_tooltip(text, substitution_dict, control->get_global_position() + offset);
+}
+
+void MenuSingleton::hide_tooltip() {
+ show_tooltip({}, {}, {});
+}
+
/* PROVINCE OVERVIEW PANEL */
static TypedArray<Dictionary> _make_buildings_dict_array(
diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.hpp b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
index 190e3ea..022bce5 100644
--- a/extension/src/openvic-extension/singletons/MenuSingleton.hpp
+++ b/extension/src/openvic-extension/singletons/MenuSingleton.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/image.hpp>
#include <openvic-simulation/pop/Pop.hpp>
@@ -95,6 +96,10 @@ namespace OpenVic {
static godot::StringName const& _signal_population_menu_pops_changed();
/* Emitted when the collection of possible search results changes. */
static godot::StringName const& _signal_search_cache_changed();
+ /* Emitted when the current tooltip changes. Arguments: text (godot::String), substitution_dict (godot::Dictionary),
+ * position (godot::Vector2). If text is empty then the tooltip will be hidden, otherwise the text will be shown at
+ * the given position. */
+ static godot::StringName const& _signal_update_tooltip();
godot::String get_state_name(State const& state) const;
godot::String get_country_name(CountryInstance const& country) const;
@@ -110,6 +115,15 @@ namespace OpenVic {
MenuSingleton();
~MenuSingleton();
+ /* TOOLTIP */
+ void show_tooltip(
+ godot::String const& text, godot::Dictionary const& substitution_dict, godot::Vector2 const& position
+ );
+ void show_control_tooltip(
+ godot::String const& text, godot::Dictionary const& substitution_dict, godot::Control const* control
+ );
+ void hide_tooltip();
+
/* PROVINCE OVERVIEW PANEL */
/* Get info to display in Province Overview Panel, packaged in a Dictionary using StringName constants as keys. */
godot::Dictionary get_province_info_from_index(int32_t index) const;