Skip to content

tooltip: Don't save style overrides to tooltip.tscn #138

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

Merged
merged 3 commits into from
Jul 16, 2024

Conversation

wjt
Copy link
Member

@wjt wjt commented Jul 16, 2024

Previously, if you opened tooltip.tscn in the editor and hit Save, its _ready() method would persist the style overrides we use to apply the editor theme's fonts to the label. This isn't necessary, or desirable.

Godot 4.3+ exposes Node.is_part_of_edited_scene() to GDScript, which is analogous to Engine.is_editor_hint() but determines whether the @tool script's node is itself being edited, as opposed to instantiated elsewhere in the editor.

Reimplement this function in GDScript and only apply the style overrides to the tooltip if it returns false.

https://phabricator.endlessm.com/T35540

@wjt wjt requested a review from wnbaum July 16, 2024 15:59
@wjt
Copy link
Member Author

wjt commented Jul 16, 2024

I pushed a couple more changes to apply the same fix to the scenes discussed on Slack.

@wjt wjt force-pushed the push-zpzlykxuttqu branch from 77ddebe to bfe465c Compare July 16, 2024 16:48
Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

Wow, nice find. I have often wondered why so much stuff is getting serialized into the scenes.

@@ -45,7 +47,7 @@ signal replace_block_code


func _ready():
if not _open_scene_button.icon:
if not Util.node_is_part_of_edited_scene(self) and not _open_scene_button.icon:
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick - optimize the logic by moving the simple null check first.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the null check is now redundant: it will always be null when _ready runs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I left the null check in, but swapped the condition around.

Copy link
Contributor

@wnbaum wnbaum left a comment

Choose a reason for hiding this comment

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

Looks good to me once you fix Dan's changes! This is a much more elegant solution than restoring the file every time :)

wjt added 3 commits July 16, 2024 22:48
Godot 4.3+ exposes `Node.is_part_of_edited_scene()` to GDScript, which is
analogous to `Engine.is_editor_hint()` but determines whether the `@tool`
script's node is itself being edited, as opposed to instantiated elsewhere in
the editor.

Reimplement this function in GDScript.

https://phabricator.endlessm.com/T35540

Move node_is_part_of_edited_scene to new Util module

This will allow it to be reused in other scenes which have the same problem as
tooltip did.
Previously, if you opened tooltip.tscn in the editor and hit Save, its
`_ready()` method would persist the style overrides we use to apply the editor
theme's fonts to the label. This isn't necessary, or desirable.

Don't apply the style overrides if the tooltip scene itself is being edited.

https://phabricator.endlessm.com/T35540
Previously, opening and saving parameter_block.tscn (for example) in the editor
would cause its StyleBoxFlat resource to be replaced by an identical
sub_resource with a new unique identifier. This is because its _ready()
function runs when the scene is being edited, and previously would
unconditionally re-set the stylebox.

This either causes needless diff churn, or requires extra work by the developer
to discard that hunk.

In each case, guard the change with `node_is_part_of_edited_scene`, and
remove it from the saved scene.
@wjt wjt force-pushed the push-zpzlykxuttqu branch from bfe465c to 1b6d64b Compare July 16, 2024 21:55
@wjt wjt requested a review from dbnicholson July 16, 2024 21:56
Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

Sweet

@dbnicholson dbnicholson merged commit 2516bd1 into main Jul 16, 2024
2 checks passed
@dbnicholson dbnicholson deleted the push-zpzlykxuttqu branch July 16, 2024 22:03
@manuq
Copy link
Contributor

manuq commented Jul 17, 2024

I'm late to the party, this is a fantastic improvement!

Copy link
Contributor

@wnbaum wnbaum left a comment

Choose a reason for hiding this comment

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

@wjt Did you remove the style boxes manually? Or did the scene resave without them? Because all of the parameter blocks and category color icons are now squares xD. My bad for not catching.


[ext_resource type="Script" path="res://addons/block_code/ui/blocks/parameter_block/parameter_block.gd" id="1_0hajy"]
[ext_resource type="PackedScene" uid="uid://c7puyxpqcq6xo" path="res://addons/block_code/ui/blocks/utilities/drag_drop_area/drag_drop_area.tscn" id="2_gy5co"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dbera"]
bg_color = Color(1, 1, 1, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait were these StyleBoxes removed manually? They are meant to be saved to the scene, somehow I missed this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I think I reset them to defaults in the editor on the basis that they will be instantiated every time the scene is actually used. I didn't see the square-icon issue... I can investigate tomorrow

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the default stylebox value is actually used as a template, only the color is set on it. Which is kind of weird, maybe we should just create a totally new stylebox at runtime.


[ext_resource type="Script" path="res://addons/block_code/ui/picker/categories/block_category_button.gd" id="1_pxxnl"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_eogpc"]
bg_color = Color(1, 0, 0, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too.

wjt added a commit that referenced this pull request Jul 18, 2024
This partially reverts commit 1b6d64b (“Don't
recreate resources when editing plugin scenes”).

I incorrectly believed that these were being fully recreated every time the
scene is instantiated based on another element's stylebox, but in fact they are
being used as a template and it is only the colour that is being adjusted.

See discussion at #138 (comment).
@wjt wjt mentioned this pull request Jul 18, 2024
wnbaum pushed a commit that referenced this pull request Jul 24, 2024
This partially reverts commit 1b6d64b (“Don't
recreate resources when editing plugin scenes”).

I incorrectly believed that these were being fully recreated every time the
scene is instantiated based on another element's stylebox, but in fact they are
being used as a template and it is only the colour that is being adjusted.

See discussion at #138 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants