Skip to content

Commit 0899ebc

Browse files
committed
When setting a tooltip, automatically switch mouse filter to PASS if it's IGNORE
1 parent fed4223 commit 0899ebc

File tree

3 files changed

+30
-81
lines changed

3 files changed

+30
-81
lines changed

extension/src/openvic-extension/classes/GUIHasTooltip.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
#include <godot_cpp/classes/control.hpp>
44
#include <godot_cpp/variant/string.hpp>
5-
#include <godot_cpp/variant/utility_functions.hpp>
6-
#include <godot_cpp/variant/vector2.hpp>
75

86
#include <openvic-simulation/utility/Getters.hpp>
97

108
#include "openvic-extension/singletons/MenuSingleton.hpp"
119
#include "openvic-extension/utility/ClassBindings.hpp"
12-
#include "openvic-extension/utility/Utilities.hpp"
1310

1411
/* To add tooltip functionality to a class:
1512
* - the class must be derived from Control.
@@ -40,7 +37,7 @@
4037
String const& new_tooltip_string, Dictionary const& new_tooltip_substitution_dict \
4138
) { \
4239
if (get_mouse_filter() == MOUSE_FILTER_IGNORE) { \
43-
UtilityFunctions::push_error("Tooltips won't work for \"", get_name(), "\" as it has MOUSE_FILTER_IGNORE"); \
40+
set_mouse_filter(MOUSE_FILTER_PASS); \
4441
} \
4542
if (tooltip_string != new_tooltip_string || tooltip_substitution_dict != new_tooltip_substitution_dict) { \
4643
tooltip_string = new_tooltip_string; \
@@ -52,7 +49,7 @@
5249
} \
5350
void CLASS::set_tooltip_string(String const& new_tooltip_string) { \
5451
if (get_mouse_filter() == MOUSE_FILTER_IGNORE) { \
55-
UtilityFunctions::push_error("Tooltips won't work for \"", get_name(), "\" as it has MOUSE_FILTER_IGNORE"); \
52+
set_mouse_filter(MOUSE_FILTER_PASS); \
5653
} \
5754
if (tooltip_string != new_tooltip_string) { \
5855
tooltip_string = new_tooltip_string; \
@@ -63,7 +60,7 @@
6360
} \
6461
void CLASS::set_tooltip_substitution_dict(Dictionary const& new_tooltip_substitution_dict) { \
6562
if (get_mouse_filter() == MOUSE_FILTER_IGNORE) { \
66-
UtilityFunctions::push_error("Tooltips won't work for \"", get_name(), "\" as it has MOUSE_FILTER_IGNORE"); \
63+
set_mouse_filter(MOUSE_FILTER_PASS); \
6764
} \
6865
if (tooltip_substitution_dict != new_tooltip_substitution_dict) { \
6966
tooltip_substitution_dict = new_tooltip_substitution_dict; \

game/src/Game/GameSession/NationManagementScreen/PopulationMenu.gd

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -317,41 +317,23 @@ func _setup_pop_list() -> void:
317317

318318
_pop_list_producing_icons.push_back(GUINode.get_gui_icon_from_node(pop_row_panel.get_node(^"./pop_producing_icon")))
319319

320-
var culture_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_nation"))
321-
_pop_list_culture_labels.push_back(culture_label)
322-
if culture_label:
323-
culture_label.set_mouse_filter(MOUSE_FILTER_PASS)
324-
325-
var religion_icon : GUIIcon = GUINode.get_gui_icon_from_node(pop_row_panel.get_node(^"./pop_religion"))
326-
_pop_list_religion_icons.push_back(religion_icon)
327-
if religion_icon:
328-
religion_icon.set_mouse_filter(MOUSE_FILTER_PASS)
329-
330-
var location_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_location"))
331-
_pop_list_location_labels.push_back(location_label)
332-
if location_label:
333-
location_label.set_mouse_filter(MOUSE_FILTER_PASS)
334-
335-
var militancy_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_mil"))
336-
_pop_list_militancy_labels.push_back(militancy_label)
337-
if militancy_label:
338-
militancy_label.set_mouse_filter(MOUSE_FILTER_PASS)
339-
340-
var consciousness_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_con"))
341-
_pop_list_consciousness_labels.push_back(consciousness_label)
342-
if consciousness_label:
343-
consciousness_label.set_mouse_filter(MOUSE_FILTER_PASS)
320+
_pop_list_culture_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_nation")))
321+
322+
_pop_list_religion_icons.push_back(GUINode.get_gui_icon_from_node(pop_row_panel.get_node(^"./pop_religion")))
323+
324+
_pop_list_location_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_location")))
325+
326+
_pop_list_militancy_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_mil")))
327+
328+
_pop_list_consciousness_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_con")))
344329

345330
_pop_list_ideology_charts.push_back(GUINode.get_gui_pie_chart_from_node(pop_row_panel.get_node(^"./pop_ideology")))
346331

347332
_pop_list_issues_charts.push_back(GUINode.get_gui_pie_chart_from_node(pop_row_panel.get_node(^"./pop_issues")))
348333

349334
_pop_list_unemployment_progressbars.push_back(GUINode.get_gui_progress_bar_from_node(pop_row_panel.get_node(^"./pop_unemployment_bar")))
350335

351-
var cash_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_cash"))
352-
_pop_list_cash_labels.push_back(cash_label)
353-
if cash_label:
354-
cash_label.set_mouse_filter(MOUSE_FILTER_PASS)
336+
_pop_list_cash_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_cash")))
355337

356338
var pop_list_life_needs_progressbar : GUIProgressBar = GUINode.get_gui_progress_bar_from_node(pop_row_panel.get_node(^"./lifeneed_progress"))
357339
_pop_list_life_needs_progressbars.push_back(pop_list_life_needs_progressbar)
@@ -373,15 +355,9 @@ func _setup_pop_list() -> void:
373355

374356
_pop_list_national_movement_flags.push_back(GUINode.get_gui_masked_flag_from_node(pop_row_panel.get_node(^"./pop_movement_flag")))
375357

376-
var size_change_icon : GUIIcon = GUINode.get_gui_icon_from_node(pop_row_panel.get_node(^"./growth_indicator"))
377-
_pop_list_size_change_icons.push_back(size_change_icon)
378-
if size_change_icon:
379-
size_change_icon.set_mouse_filter(MOUSE_FILTER_PASS)
358+
_pop_list_size_change_icons.push_back(GUINode.get_gui_icon_from_node(pop_row_panel.get_node(^"./growth_indicator")))
380359

381-
var literacy_label : GUILabel = GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_literacy"))
382-
_pop_list_literacy_labels.push_back(literacy_label)
383-
if literacy_label:
384-
literacy_label.set_mouse_filter(MOUSE_FILTER_PASS)
360+
_pop_list_literacy_labels.push_back(GUINode.get_gui_label_from_node(pop_row_panel.get_node(^"./pop_literacy")))
385361

386362
func _notification(what : int) -> void:
387363
match what:
@@ -536,10 +512,13 @@ func _update_distributions():
536512
var colour_icon : GUIIcon = GUINode.get_gui_icon_from_node(child.get_node(^"./legend_color"))
537513
if colour_icon:
538514
colour_icon.set_modulate(distribution_row[slice_colour_key])
539-
colour_icon.set_mouse_filter(MOUSE_FILTER_PASS)
540-
colour_icon.set_tooltip_string_and_substitution_dict("§Y$ID$§!: $PC$%", {
541-
"ID": distribution_row[slice_identifier_key], "PC": GUINode.float_to_string_dp(distribution_row[slice_weight_key] * 100.0, 2)
542-
})
515+
colour_icon.set_tooltip_string_and_substitution_dict(
516+
"§Y$ID$§!: $PC$%" + "\nTEST: colour_icon",
517+
{
518+
"ID": distribution_row[slice_identifier_key],
519+
"PC": GUINode.float_to_string_dp(distribution_row[slice_weight_key] * 100.0, 2)
520+
}
521+
)
543522

544523
var identifier_label : GUILabel = GUINode.get_gui_label_from_node(child.get_node(^"./legend_title"))
545524
if identifier_label:

game/src/Game/GameSession/Topbar.gd

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,13 @@ func _ready() -> void:
102102
_country_flag_overlay_icon = get_gui_icon_from_nodepath(^"./topbar/topbar_flag_overlay")
103103
_country_name_label = get_gui_label_from_nodepath(^"./topbar/CountryName")
104104
_country_rank_label = get_gui_label_from_nodepath(^"./topbar/nation_totalrank")
105-
if _country_rank_label:
106-
_country_rank_label.set_mouse_filter(MOUSE_FILTER_PASS)
107105
_country_prestige_label = get_gui_label_from_nodepath(^"./topbar/country_prestige")
108-
if _country_prestige_label:
109-
_country_prestige_label.set_mouse_filter(MOUSE_FILTER_PASS)
110106
_country_prestige_rank_label = get_gui_label_from_nodepath(^"./topbar/selected_prestige_rank")
111-
if _country_prestige_rank_label:
112-
_country_prestige_rank_label.set_mouse_filter(MOUSE_FILTER_PASS)
113107
_country_industrial_power_label = get_gui_label_from_nodepath(^"./topbar/country_economic")
114-
if _country_industrial_power_label:
115-
_country_industrial_power_label.set_mouse_filter(MOUSE_FILTER_PASS)
116108
_country_industrial_power_rank_label = get_gui_label_from_nodepath(^"./topbar/selected_industry_rank")
117-
if _country_industrial_power_rank_label:
118-
_country_industrial_power_rank_label.set_mouse_filter(MOUSE_FILTER_PASS)
119109
_country_military_power_label = get_gui_label_from_nodepath(^"./topbar/country_military")
120-
if _country_military_power_label:
121-
_country_military_power_label.set_mouse_filter(MOUSE_FILTER_PASS)
122110
_country_military_power_rank_label = get_gui_label_from_nodepath(^"./topbar/selected_military_rank")
123-
if _country_military_power_rank_label:
124-
_country_military_power_rank_label.set_mouse_filter(MOUSE_FILTER_PASS)
125111
_country_colonial_power_label = get_gui_label_from_nodepath(^"./topbar/country_colonial_power")
126-
if _country_colonial_power_label:
127-
_country_colonial_power_label.set_mouse_filter(MOUSE_FILTER_PASS)
128112

129113
# Time controls
130114
_speed_up_button = get_gui_icon_button_from_nodepath(^"./topbar/button_speedup")
@@ -184,20 +168,14 @@ func _ready() -> void:
184168
if _technology_progress_bar and tech_button:
185169
_technology_progress_bar.reparent(tech_button)
186170
_technology_current_research_label = get_gui_label_from_nodepath(^"./topbar/tech_current_research")
187-
if _technology_current_research_label:
188-
_technology_current_research_label.set_mouse_filter(MOUSE_FILTER_PASS)
189-
if tech_button:
190-
_technology_current_research_label.reparent(tech_button)
171+
if _technology_current_research_label and tech_button:
172+
_technology_current_research_label.reparent(tech_button)
191173
_technology_literacy_label = get_gui_label_from_nodepath(^"./topbar/tech_literacy_value")
192-
if _technology_literacy_label:
193-
_technology_literacy_label.set_mouse_filter(MOUSE_FILTER_PASS)
194-
if tech_button:
195-
_technology_literacy_label.reparent(tech_button)
174+
if _technology_literacy_label and tech_button:
175+
_technology_literacy_label.reparent(tech_button)
196176
_technology_research_points_label = get_gui_label_from_nodepath(^"./topbar/topbar_researchpoints_value")
197-
if _technology_research_points_label:
198-
_technology_research_points_label.set_mouse_filter(MOUSE_FILTER_PASS)
199-
if tech_button:
200-
_technology_research_points_label.reparent(tech_button)
177+
if _technology_research_points_label and tech_button:
178+
_technology_research_points_label.reparent(tech_button)
201179

202180
# Politics
203181
_politics_party_icon = get_gui_icon_from_nodepath(^"./topbar/politics_party_icon")
@@ -264,18 +242,11 @@ func _ready() -> void:
264242
# Military
265243
_military_army_size_label = get_gui_label_from_nodepath(^"./topbar/military_army_value")
266244
if _military_army_size_label:
267-
_military_army_size_label.set_mouse_filter(MOUSE_FILTER_PASS)
268245
_military_army_size_label.set_text("§Y$CURR$/$MAX$")
269246
_military_army_size_label.set_tooltip_string("TOPBAR_ARMY_TOOLTIP")
270247
_military_navy_size_label = get_gui_label_from_nodepath(^"./topbar/military_navy_value")
271-
if _military_navy_size_label:
272-
_military_navy_size_label.set_mouse_filter(MOUSE_FILTER_PASS)
273248
_military_mobilisation_size_label = get_gui_label_from_nodepath(^"./topbar/military_manpower_value")
274-
if _military_mobilisation_size_label:
275-
_military_mobilisation_size_label.set_mouse_filter(MOUSE_FILTER_PASS)
276249
_military_leadership_points_label = get_gui_label_from_nodepath(^"./topbar/military_leadership_value")
277-
if _military_leadership_points_label:
278-
_military_leadership_points_label.set_mouse_filter(MOUSE_FILTER_PASS)
279250

280251
_update_info()
281252
_update_speed_controls()
@@ -539,6 +510,7 @@ func _update_info() -> void:
539510

540511
if _military_navy_size_label:
541512
_military_navy_size_label.set_text("§Y%d/%d" % [0, 0])
513+
# TODO - navy size tooltip
542514

543515
const mobilised_key : StringName = &"mobilised"
544516
const mobilisation_regiments_key : StringName = &"mobilisation_regiments"
@@ -565,6 +537,7 @@ func _update_info() -> void:
565537

566538
if _military_leadership_points_label:
567539
_military_leadership_points_label.set_text("§Y%d" % 0)
540+
# TODO - leadership points tooltip
568541

569542
func _update_speed_controls() -> void:
570543
var paused : bool = MenuSingleton.is_paused()

0 commit comments

Comments
 (0)