Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Technology Menu #334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Implement Technology Menu #334

wants to merge 1 commit into from

Conversation

BrickPi
Copy link
Contributor

@BrickPi BrickPi commented Dec 21, 2024

  • Implements the Technology Menu
  • Adds _make_modifier_effect_tooltip for single modifiers

@Spartan322 Spartan322 added the enhancement New feature or request label Dec 21, 2024
@BrickPi BrickPi requested a review from Hop311 December 21, 2024 21:17
@BrickPi BrickPi force-pushed the topbar-tech branch 2 times, most recently from 891c6c1 to 0f67b06 Compare February 1, 2025 22:07
@BrickPi BrickPi changed the title Implement Technology Schools and Technology Folders Implement Technology Menu Feb 1, 2025
@BrickPi BrickPi force-pushed the topbar-tech branch 2 times, most recently from cae21ea to 6b9a012 Compare February 2, 2025 22:44

PackedStringArray tech_folder_identifiers {};
TypedArray<PackedStringArray> tech_area_identifiers {};
Array tech_identifiers {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Array tech_identifiers {};
TypedArray<PackedStringArray> tech_identifiers {};

This can be a typed array

return ret;
}

TechnologySchool const* tech_school = country->get_tech_school();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TechnologySchool const* tech_school = country->get_tech_school();
TechnologySchool const* tech_school = country->get_tech_school();

Extra tab

_current_research_progressbar = get_gui_progress_bar_from_nodepath(^"./country_technology/research_progress")

# FOLDERS, AREAS, TECHNOLOGIES
_tech_folders = _tech_defines.get("tech_folders", [] as PackedStringArray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_tech_folders = _tech_defines.get("tech_folders", [] as PackedStringArray)
_tech_folders = _tech_defines.get(&"tech_folders", [] as PackedStringArray)

All these get calls should be using StringNames rather than Strings (GDScript: "string literal" vs &"string name literal")

pos.x += folder_node.get_size().x * i
folder_node.set_position(pos)

var icon : GUIIcon = GUINode.get_gui_icon_from_node(folder_node.get_node(^"./folder_icon"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var icon : GUIIcon = GUINode.get_gui_icon_from_node(folder_node.get_node(^"./folder_icon"))
var icon : GUIIcon = GUINode.get_gui_icon_from_node_and_path(folder_node, ^"./folder_icon")

I've recently added another kind of helper function which does the get_node lookup for you, useful in similar cases throughout this file

if _technologies.size() > 0 and _technologies[0].size() > 0 and _technologies[0][0].size() > 0 and _technologies[0][0][0]:
_selected_technology = _technologies[0][0][0]
_selected_technology_info = MenuSingleton.get_specific_technology_info(_selected_technology)
_folder_tech_counts = _tech_defines.get("folder_tech_count", 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_folder_tech_counts = _tech_defines.get("folder_tech_count", 0)
_folder_tech_counts = _tech_defines.get("folder_tech_count", [] as PackedInt32Array)

Fallback types need to match the variable type otherwise they'll cause a crash when they're fallen back to. Could you check that there aren't any other mismatches in this file?

Comment on lines +116 to +120
add_gui_element("country_technology", "tech_group")

var area_node : Node = get_node(^"./tech_group")

area_node.reparent(root_node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than generating at the top level and reparenting, you can use GUINode.generate_gui_element, store the result in a variable, and then add_child it to the desired parent if it's not null (applies to similar cases throughout this file)

if i != 0:
area_node.set_visible(false)

pos = GUINode.get_gui_position("country_technology", "tech_group_offset")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be gotten once at the beginning of the _ready function and re-used without multiple lookups

Comment on lines +209 to +210
main_icon.mouse_filter = Control.MOUSE_FILTER_PASS
main_icon.set_tooltip_string(mod_tooltips[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_tooltip_string automatically changes mouse filter to PASS if it's currently IGNORE, so the change above isn't necessary unless you're changing it from something other than IGNORE

Comment on lines +226 to +237
_current_research_progressbar.set_tooltip_string_and_substitution_dict(
tr("TECHNOLOGYVIEW_RESEARCH_TOOLTIP") + "\n" +
tr("TECHNOLOGYVIEW_RESEARCH_INVESTED_TOOLTIP") +
MenuSingleton.get_tooltip_separator() +
info.get("current_research_effect_tt", ""),
{
"TECH": tr(current_research),
"DATE": info.get("current_research_finish_date", "1836.1.1"),
"INVESTED": info.get("current_research_invested", 0),
"COST": info.get("current_research_cost", 0)
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already generate the top half of this tooltip here, so you could separate out that code into a helper function under MenuSingleton then store its result in the info dictionary rather than passing up all the constituent parts

if _start_research_button:
if current_research == _selected_technology:
_start_research_button.disabled = true
_start_research_button.set_tooltip_string_and_substitution_dict(tr("TECHNOLOGYVIEW_UNDER_RESEARCH_TOOLTIP"), { "TECH": tr(_selected_technology) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cases like this you don't have to manually translate the tooltip string, it'll get auto translated by the tooltip node. The only common reason for manually translating is when you need to modify the result somehow, e.g. combine multiple seaprate localised keys together or manually substitute something inside it, but when you're using the substitution dict functionality that's all taken care of by the tooltip node.

@Hop311
Copy link
Contributor

Hop311 commented Feb 3, 2025

Also you'll probably have to rebase onto master to account for the submodule already being updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants