tooltip: Don't save style overrides to tooltip.tscn#138
Conversation
|
I pushed a couple more changes to apply the same fix to the scenes discussed on Slack. |
dbnicholson
left a comment
There was a problem hiding this comment.
Wow, nice find. I have often wondered why so much stuff is getting serialized into the scenes.
|
|
||
| func _ready(): | ||
| if not _open_scene_button.icon: | ||
| if not Util.node_is_part_of_edited_scene(self) and not _open_scene_button.icon: |
There was a problem hiding this comment.
Nitpick - optimize the logic by moving the simple null check first.
There was a problem hiding this comment.
I think the null check is now redundant: it will always be null when _ready runs.
There was a problem hiding this comment.
I left the null check in, but swapped the condition around.
wnbaum
left a comment
There was a problem hiding this comment.
Looks good to me once you fix Dan's changes! This is a much more elegant solution than restoring the file every time :)
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.
|
I'm late to the party, this is a fantastic improvement! |
| [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) |
There was a problem hiding this comment.
Wait were these StyleBoxes removed manually? They are meant to be saved to the scene, somehow I missed this.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
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).
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).
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 toEngine.is_editor_hint()but determines whether the@toolscript'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