Skip to content
Open
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
24 changes: 10 additions & 14 deletions addons/beehave/debug/debugger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
extends EditorDebuggerPlugin

const DebuggerTab := preload("debugger_tab.gd")
const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd")

var debugger_tab := DebuggerTab.new()
# const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd")
var debugger_tab := BeehaveDebuggerTab.new()
var floating_window: Window
var session: EditorDebuggerSession


func _init(f: RefCounted) -> void:
debugger_tab.frame = f


func _has_capture(prefix: String) -> bool:
return prefix == "beehave"

Expand Down Expand Up @@ -51,25 +54,18 @@ func _setup_session(session_id: int) -> void:


func _on_make_floating() -> void:
var plugin := BeehaveUtils.get_plugin()
if not plugin:
return
if floating_window:
_on_window_close_requested()
return

var border_size := Vector2(4, 4) * BeehaveUtils.get_editor_scale()
var editor_interface: EditorInterface = plugin.get_editor_interface()
var editor_main_screen = editor_interface.get_editor_main_screen()
var border_size := Vector2(4, 4) * EditorInterface.get_editor_scale()
var editor_main_screen = EditorInterface.get_editor_main_screen()
debugger_tab.get_parent().remove_child(debugger_tab)

floating_window = Window.new()

var panel := Panel.new()
panel.add_theme_stylebox_override(
"panel",
editor_interface.get_base_control().get_theme_stylebox("PanelForeground", "EditorStyles")
)
panel.add_theme_stylebox_override("panel", EditorInterface.get_base_control().get_theme_stylebox("PanelForeground", "EditorStyles"))
panel.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
floating_window.add_child(panel)

Expand All @@ -89,7 +85,7 @@ func _on_make_floating() -> void:
floating_window.position = editor_main_screen.global_position
floating_window.transient = true
floating_window.close_requested.connect(_on_window_close_requested)
editor_interface.get_base_control().add_child(floating_window)
EditorInterface.get_base_control().add_child(floating_window)


func _on_window_close_requested() -> void:
Expand Down
46 changes: 23 additions & 23 deletions addons/beehave/debug/debugger_tab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
class_name BeehaveDebuggerTab
extends PanelContainer

const Utils = preload("res://addons/beehave/utils/utils.gd")
const TREE_ICON = preload("../icons/tree.svg")
const OldGraph = preload("old_graph_edit.gd")
const NewGraph = preload("new_graph_edit.gd")
# const Utils = preload("res://addons/beehave/utils/utils.gd")
const TREE_ICON = preload("../icons/tree.svg")
const OldGraph = preload("old_graph_edit.gd")
const NewGraph = preload("new_graph_edit.gd")
const Blackboard = preload("new_node_blackboard.gd")

signal make_floating
Expand All @@ -14,14 +14,15 @@ var session: EditorDebuggerSession
var first_run = true
var active_trees = {}
var active_tree_id = -1

# UI nodes
var container: HSplitContainer
var item_list: ItemList
var graph_container: HSplitContainer
var graph
var blackboard_vbox: VBoxContainer
var message: Label
static var frame: RefCounted


func _ready() -> void:
_build_ui()
Expand Down Expand Up @@ -62,17 +63,16 @@ func _build_ui() -> void:
message = Label.new()
message.text = "Run Project for debugging"
message.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
message.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
message.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
message.set_anchors_preset(Control.PRESET_CENTER)
add_child(message)


func _init_graph() -> void:
var frames = Utils.get_frames()
if Engine.get_version_info().minor >= 2:
graph = NewGraph.new(frames)
graph = NewGraph.new(frame)
else:
graph = OldGraph.new(frames)
graph = OldGraph.new(frame)

# Graph on the left, blackboard (index 1) on the right
graph.node_selected.connect(_on_graph_node_selected)
Expand All @@ -87,9 +87,7 @@ func _init_graph() -> void:
float_btn.flat = true
float_btn.focus_mode = Control.FOCUS_NONE
float_btn.icon = get_theme_icon("ExternalLink", "EditorIcons")
float_btn.pressed.connect(func():
emit_signal("make_floating")
)
float_btn.pressed.connect(func(): emit_signal("make_floating"))
graph.get_menu_container().add_child(float_btn)

# "Toggle Panel" button
Expand All @@ -98,26 +96,27 @@ func _init_graph() -> void:
toggle_btn.flat = true
toggle_btn.focus_mode = Control.FOCUS_NONE
toggle_btn.icon = get_theme_icon("Back", "EditorIcons")
toggle_btn.pressed.connect(func():
item_list.visible = not item_list.visible
var icon_name = "Back" if item_list.visible else "Forward"
toggle_btn.icon = get_theme_icon(icon_name, "EditorIcons")
toggle_btn.pressed.connect(
func():
item_list.visible = not item_list.visible
var icon_name = "Back" if item_list.visible else "Forward"
toggle_btn.icon = get_theme_icon(icon_name, "EditorIcons")
)
graph.get_menu_container().add_child(toggle_btn)
graph.get_menu_container().move_child(toggle_btn, 0)


func start() -> void:
container.visible = true
message.visible = false
message.visible = false

if first_run:
first_run = false
for delay in [0.0, 0.1, 0.5]:
get_tree().create_timer(delay).timeout.connect(_notify_state)
else:
_notify_state()

# Auto-detach if enabled in project settings - check every time
if ProjectSettings.get_setting("beehave/debugger/start_detached", false):
emit_signal("make_floating")
Expand All @@ -133,7 +132,7 @@ func _notify_state() -> void:

func stop() -> void:
container.visible = false
message.visible = true
message.visible = true
active_trees.clear()
item_list.clear()
graph.beehave_tree = {}
Expand Down Expand Up @@ -172,9 +171,10 @@ func _select_item_by_id(id_str: String) -> void:
if item_list.get_item_metadata(i) == id_str:
item_list.select(i)
break
get_tree().create_timer(0.2).timeout.connect(func():
if item_list.is_inside_tree() and not item_list.get_selected_items().is_empty():
_on_item_selected(item_list.get_selected_items()[0])
get_tree().create_timer(0.2).timeout.connect(
func():
if item_list.is_inside_tree() and not item_list.get_selected_items().is_empty():
_on_item_selected(item_list.get_selected_items()[0])
)


Expand All @@ -201,7 +201,7 @@ func _on_graph_node_selected(node: GraphNode) -> void:
for child in blackboard_vbox.get_children():
child.free()
blackboard_vbox.show()
blackboard_vbox.add_child(Blackboard.new(Utils.get_frames(), node))
blackboard_vbox.add_child(Blackboard.new(frame, node))


func _on_graph_node_deselected(node: GraphNode) -> void:
Expand Down
41 changes: 8 additions & 33 deletions addons/beehave/debug/new_frames.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
@tool
extends RefCounted


const BeehaveUtils := preload("res://addons/beehave/utils/utils.gd")


const SUCCESS_COLOR := Color("#07783a")
const NORMAL_COLOR := Color("#15181e")
const FAILURE_COLOR := Color("#82010b")
Expand All @@ -22,48 +20,25 @@ var titlebar_running: StyleBoxFlat


func _init() -> void:
var plugin := BeehaveUtils.get_plugin()
if not plugin:
return


titlebar_normal = (
plugin
.get_editor_interface()
.get_base_control()
.get_theme_stylebox(&"titlebar", &"GraphNode")\
.duplicate()
)

titlebar_normal = (EditorInterface.get_base_control().get_theme_stylebox(&"titlebar", &"GraphNode").duplicate())
titlebar_success = titlebar_normal.duplicate()
titlebar_failure = titlebar_normal.duplicate()
titlebar_running = titlebar_normal.duplicate()

titlebar_success.bg_color = SUCCESS_COLOR
titlebar_failure.bg_color = FAILURE_COLOR
titlebar_running.bg_color = RUNNING_COLOR

titlebar_success.border_color = SUCCESS_COLOR
titlebar_failure.border_color = FAILURE_COLOR
titlebar_running.border_color = RUNNING_COLOR


panel_normal = (
plugin
.get_editor_interface()
.get_base_control()
.get_theme_stylebox(&"panel", &"GraphNode")
.duplicate()
)
panel_success = (
plugin
.get_editor_interface()
.get_base_control()
.get_theme_stylebox(&"panel_selected", &"GraphNode")
.duplicate()
)

panel_normal = (EditorInterface.get_base_control().get_theme_stylebox(&"panel", &"GraphNode").duplicate())
panel_success = (EditorInterface.get_base_control().get_theme_stylebox(&"panel_selected", &"GraphNode").duplicate())
panel_failure = panel_success.duplicate()
panel_running = panel_success.duplicate()

panel_success.border_color = SUCCESS_COLOR
panel_failure.border_color = FAILURE_COLOR
panel_running.border_color = RUNNING_COLOR
4 changes: 2 additions & 2 deletions addons/beehave/debug/new_graph_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func _init(frames:RefCounted, horizontal: bool = false) -> void:


func _ready() -> void:
custom_minimum_size = Vector2(50, 50) * BeehaveUtils.get_editor_scale()
custom_minimum_size = Vector2(50, 50) * EditorInterface.get_editor_scale()
draggable = false

add_theme_color_override("close_color", Color.TRANSPARENT)
Expand Down Expand Up @@ -189,4 +189,4 @@ func _set_stylebox_overrides(panel_stylebox: StyleBox, titlebar_stylebox: StyleB


func _on_size_changed():
add_theme_constant_override("port_offset", 12 * BeehaveUtils.get_editor_scale() if horizontal else round(size.x))
add_theme_constant_override("port_offset", 12 * EditorInterface.get_editor_scale() if horizontal else round(size.x))
24 changes: 4 additions & 20 deletions addons/beehave/debug/old_frames.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,13 @@ var running: StyleBoxFlat


func _init() -> void:
var plugin := BeehaveUtils.get_plugin()
if not plugin:
return

var editor_scale := BeehaveUtils.get_editor_scale()
var editor_scale := EditorInterface.get_editor_scale()

empty = StyleBoxEmpty.new()

normal = (
plugin
. get_editor_interface()
. get_base_control()
. get_theme_stylebox(&"frame", &"GraphNode")
. duplicate()
)

success = (
plugin
. get_editor_interface()
. get_base_control()
. get_theme_stylebox(&"selected_frame", &"GraphNode")
. duplicate()
)
normal = (EditorInterface.get_base_control().get_theme_stylebox(&"frame", &"GraphNode").duplicate())

success = (EditorInterface.get_base_control().get_theme_stylebox(&"selected_frame", &"GraphNode").duplicate())
failure = success.duplicate()
running = success.duplicate()

Expand Down
8 changes: 4 additions & 4 deletions addons/beehave/debug/old_graph_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func _init(frames: RefCounted, horizontal: bool = false) -> void:


func _ready() -> void:
custom_minimum_size = Vector2(50, 50) * BeehaveUtils.get_editor_scale()
custom_minimum_size = Vector2(50, 50) * EditorInterface.get_editor_scale()
draggable = false

add_theme_stylebox_override("frame", frames.empty if frames != null else null)
Expand All @@ -67,10 +67,10 @@ func _ready() -> void:
var vbox_container := VBoxContainer.new()
panel.add_child(vbox_container)

var title_size := 24 * BeehaveUtils.get_editor_scale()
var title_size := 24 * EditorInterface.get_editor_scale()
var margin_container := MarginContainer.new()
margin_container.add_theme_constant_override(
"margin_top", -title_size - 2 * BeehaveUtils.get_editor_scale()
"margin_top", -title_size - 2 * EditorInterface.get_editor_scale()
)
margin_container.mouse_filter = Control.MOUSE_FILTER_PASS
vbox_container.add_child(margin_container)
Expand Down Expand Up @@ -162,5 +162,5 @@ func set_output_color(color: Color) -> void:

func _on_size_changed():
add_theme_constant_override(
"port_offset", 12 * BeehaveUtils.get_editor_scale() if horizontal else round(size.x / 2.0)
"port_offset", 12 * EditorInterface.get_editor_scale() if horizontal else round(size.x / 2.0)
)
4 changes: 2 additions & 2 deletions addons/beehave/debug/tree_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func _calculate_x(node: TreeNode, offset: int) -> void:
sibling = sibling.get_next_sibling()

for child in node.children:
_calculate_x(child, max_size + offset + LEVEL_DISTANCE * BeehaveUtils.get_editor_scale())
_calculate_x(child, max_size + offset + LEVEL_DISTANCE * EditorInterface.get_editor_scale())


func _calculate_y(node: TreeNode, offset: int) -> void:
Expand All @@ -272,4 +272,4 @@ func _calculate_y(node: TreeNode, offset: int) -> void:
sibling = sibling.get_next_sibling()

for child in node.children:
_calculate_y(child, max_size + offset + LEVEL_DISTANCE * BeehaveUtils.get_editor_scale())
_calculate_y(child, max_size + offset + LEVEL_DISTANCE * EditorInterface.get_editor_scale())
18 changes: 8 additions & 10 deletions addons/beehave/nodes/beehave_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ signal tree_disabled
@export_node_path var actor_node_path: NodePath:
set(anp):
actor_node_path = anp
if is_inside_tree():
_resolve_actor()
if actor_node_path != null and str(actor_node_path) != "..":
actor = get_node(actor_node_path.get_as_property_path())
else:
actor = get_parent()
if Engine.is_editor_hint():
update_configuration_warnings()

Expand Down Expand Up @@ -112,7 +114,10 @@ func _ready() -> void:
process_thread = ProcessThread.PHYSICS

if not actor:
_resolve_actor()
if actor_node_path:
actor = get_node(actor_node_path)
else:
actor = get_parent()

if not blackboard:
# invoke setter to auto-initialise the blackboard.
Expand All @@ -139,13 +144,6 @@ func _ready() -> void:
BeehaveDebuggerMessages.register_tree(_get_debugger_data(self))


func _resolve_actor() -> void:
if actor_node_path.is_empty():
actor = get_parent()
else:
actor = get_node_or_null(actor_node_path)


func _on_scene_tree_node_added_removed(node: Node, is_added: bool) -> void:
if Engine.is_editor_hint():
return
Expand Down
2 changes: 1 addition & 1 deletion addons/beehave/nodes/composites/simple_parallel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func _get_configuration_warnings() -> PackedStringArray:
return warnings


func tick(actor: Node, blackboard: Blackboard) -> int:
func tick(actor, blackboard: Blackboard):
for c in get_children():
var node_index: int = c.get_index()
if node_index == 0 and not main_task_finished:
Expand Down
Loading