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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class_name BlockCanvas
extends MarginContainer

const Util = preload("res://addons/block_code/ui/util.gd")

const EXTEND_MARGIN: float = 800
const BLOCK_AUTO_PLACE_MARGIN: Vector2 = Vector2(25, 8)
const DEFAULT_WINDOW_MARGIN: Vector2 = Vector2(25, 25)
Expand Down Expand Up @@ -45,7 +47,7 @@ signal replace_block_code


func _ready():
if not _open_scene_button.icon:
if not _open_scene_button.icon and not Util.node_is_part_of_edited_scene(self):
_open_scene_button.icon = _open_scene_icon
_populate_block_scenes_by_class()

Expand Down
15 changes: 1 addition & 14 deletions addons/block_code/ui/block_canvas/block_canvas.tscn
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://c6vumewgnfquy"]
[gd_scene load_steps=3 format=3 uid="uid://c6vumewgnfquy"]

[ext_resource type="Script" path="res://addons/block_code/ui/block_canvas/block_canvas.gd" id="1_tk8h2"]
[ext_resource type="Texture2D" uid="uid://cmusxj1ppspnp" path="res://addons/block_code/block_code_node/block_code_node.svg" id="2_710vn"]

[sub_resource type="Image" id="Image_1nubg"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
"height": 16,
"mipmaps": false,
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_jgo72"]
image = SubResource("Image_1nubg")

[node name="BlockCanvas" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
Expand Down Expand Up @@ -142,7 +130,6 @@ layout_mode = 2
size_flags_horizontal = 4
theme_type_variation = &"InspectorActionButton"
text = "Open in Editor"
icon = SubResource("ImageTexture_jgo72")

[node name="ReplaceBlockCodeButton" type="Button" parent="SelectedNodeWithBlockCodeBox/ButtonsBox"]
unique_name_in_owner = true
Expand Down
11 changes: 7 additions & 4 deletions addons/block_code/ui/blocks/parameter_block/parameter_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class_name ParameterBlock
extends Block

const Util = preload("res://addons/block_code/ui/util.gd")

@export var block_format: String = ""
@export var statement: String = ""
@export var variant_type: Variant.Type
Expand All @@ -19,10 +21,11 @@ func _ready():
super()

block_type = Types.BlockType.VALUE
var new_panel = _panel.get_theme_stylebox("panel").duplicate()
new_panel.bg_color = color
new_panel.border_color = color.darkened(0.2)
_panel.add_theme_stylebox_override("panel", new_panel)
if not Util.node_is_part_of_edited_scene(self):
var new_panel = _panel.get_theme_stylebox("panel").duplicate()
new_panel.bg_color = color
new_panel.border_color = color.darkened(0.2)
_panel.add_theme_stylebox_override("panel", new_panel)

format()

Expand Down
14 changes: 1 addition & 13 deletions addons/block_code/ui/blocks/parameter_block/parameter_block.tscn
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://clipm2dd28jde"]
[gd_scene load_steps=3 format=3 uid="uid://clipm2dd28jde"]

[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.

border_width_left = 3
border_width_top = 3
border_width_right = 3
border_width_bottom = 3
corner_radius_top_left = 16
corner_radius_top_right = 16
corner_radius_bottom_right = 16
corner_radius_bottom_left = 16

[node name="ParameterBlock" type="MarginContainer"]
offset_right = 16.0
offset_bottom = 8.0
Expand All @@ -27,7 +16,6 @@ block_type = 3
[node name="Panel" type="Panel" parent="."]
unique_name_in_owner = true
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_dbera")

[node name="DragDropArea" parent="." instance=ExtResource("2_gy5co")]
layout_mode = 2
Expand Down
10 changes: 6 additions & 4 deletions addons/block_code/ui/picker/categories/block_category_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class_name BlockCategoryButton
extends MarginContainer

const Util = preload("res://addons/block_code/ui/util.gd")

signal selected

var category: BlockCategory
Expand All @@ -14,10 +16,10 @@ func _ready():
if not category:
category = BlockCategory.new("Example", Color.RED)

var new_stylebox: StyleBoxFlat = _panel.get_theme_stylebox("panel").duplicate()
new_stylebox.bg_color = category.color

_panel.add_theme_stylebox_override("panel", new_stylebox)
if not Util.node_is_part_of_edited_scene(self):
var new_stylebox: StyleBoxFlat = _panel.get_theme_stylebox("panel").duplicate()
new_stylebox.bg_color = category.color
_panel.add_theme_stylebox_override("panel", new_stylebox)

_label.text = category.name

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
[gd_scene load_steps=7 format=3 uid="uid://bdtetj0gs45hv"]
[gd_scene load_steps=6 format=3 uid="uid://bdtetj0gs45hv"]

[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.

corner_radius_top_left = 100
corner_radius_top_right = 100
corner_radius_bottom_right = 100
corner_radius_bottom_left = 100

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ousiv"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fyk0j"]
Expand Down Expand Up @@ -39,7 +32,6 @@ theme_override_constants/margin_bottom = 8
[node name="Panel" type="Panel" parent="HBoxContainer/MarginContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_eogpc")

[node name="Label" type="Label" parent="HBoxContainer"]
unique_name_in_owner = true
Expand Down
9 changes: 8 additions & 1 deletion addons/block_code/ui/tooltip/tooltip.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ class_name Tooltip
extends RichTextLabel
## Rich-text control for block tooltips that matches the built-in inspector's tooltips' font styles

const Util = preload("res://addons/block_code/ui/util.gd")


func override_font(font_name: StringName, editor_font_name: StringName) -> Font:
var font = get_theme_font(editor_font_name, &"EditorFonts")
add_theme_font_override(font_name, font)
return font


func _ready():
func override_fonts():
# Set fonts to match documentation tooltips in inspector
override_font(&"normal_font", &"doc")
override_font(&"mono_font", &"doc_source")
Expand All @@ -22,3 +24,8 @@ func _ready():
bold_italics.set_base_font(italics)
bold_italics.set_variation_embolden(1.2)
add_theme_font_override(&"bold_italics_font", bold_italics)


func _ready():
if not Util.node_is_part_of_edited_scene(self):
override_fonts()
6 changes: 6 additions & 0 deletions addons/block_code/ui/util.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Object


## Polyfill of Node.is_part_of_edited_scene(), available to GDScript in Godot 4.3+.
static func node_is_part_of_edited_scene(node: Node) -> bool:
return Engine.is_editor_hint() && node.is_inside_tree() && node.get_tree().edited_scene_root && node.get_tree().edited_scene_root.get_parent().is_ancestor_of(node)