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
7 changes: 4 additions & 3 deletions addons/flowkit/editor/Ui/base_unit_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
extends MarginContainer
class_name FKUnitUi

signal before_block_changed(node)
signal block_changed(node)
signal before_block_changed(node: FKUnitUi)
signal block_changed(node: FKUnitUi)
signal block_contents_changed()
signal selected(node)
signal selected(node: FKUnitUi)

## Call this when you want to have an FKUnitUi work properly as
## a non-preview instance. This func assumes this instance
Expand Down Expand Up @@ -44,6 +44,7 @@ func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_STOP
update_display.call_deferred()

## Returns the FKUnit this is representing.
func get_block() -> FKUnit:
return _block

Expand Down
14 changes: 10 additions & 4 deletions addons/flowkit/editor/Ui/comment_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ func _can_drop_data(at_position: Vector2, data) -> bool:
var parent = get_parent()
if parent and parent.has_method("_can_drop_data"):
var parent_pos = at_position + position
return parent._can_drop_data(parent_pos, data)
#print("[FKCommentUi] Delegating to parent's (" + parent.name + "'s) _can_drop_data")
var result: bool = parent._can_drop_data(parent_pos, data)
#print("Result: " + str(result))
return result

return false

Expand All @@ -197,15 +200,18 @@ func _drop_data(at_position: Vector2, data) -> void:
return

var drag_data = data as FKDragData

#print("[FKCommentUi] Drag data type given in _drop_data: " + drag_data.type)
# For event_row, comment, or group drags, forward to parent
if drag_data.type in [DragTarget.Type.EVENT_ROW, DragTarget.Type.COMMENT, \
DragTarget.Type.GROUP]:
if drag_data.type in _drag_targets:
var parent = get_parent()
if parent and parent.has_method("_drop_data"):
var parent_pos = at_position + position
#print("[FKCommentUi] Dropping at pos " + str(parent_pos))
parent._drop_data(parent_pos, data)

static var _drag_targets := [DragTarget.Type.EVENT_ROW, DragTarget.Type.COMMENT, \
DragTarget.Type.GROUP]

func _on_right_click(event: InputEventMouseButton):
_show_context_menu(event.global_position)
accept_event()
Expand Down
61 changes: 61 additions & 0 deletions addons/flowkit/editor/Ui/unit_ui_factory.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
extends Node
class_name FKUnitUiFactory

func _init(p_sheet_io: FKSheetIO) -> void:
sheet_io = p_sheet_io

var sheet_io : FKSheetIO
var registry: FKRegistry

##
## Currently only able to output these:
## FKEventRowUi
## FKCommentUi
#3 FKGroupUi
##
func unit_ui_from(unit: FKUnit, inputs: Dictionary = {}) -> FKUnitUi:
var result: FKUnitUi = null

if unit is FKEventBlock:
result = _create_event_row(unit)
elif unit is FKComment:
result = _create_comment_ui(unit)
elif unit is FKGroup:
result = _create_group_block(unit)

return result


func _create_event_row(data: FKEventBlock) -> FKEventRowUi:
"""Create event row node from data (GDevelop-style)."""
#print("[FKUnitUiFactory] Creating event row node")
var row: FKEventRowUi = EVENT_ROW_SCENE.instantiate()
var copy := sheet_io.copy_event_block(data)

row.legitimize(copy, registry)
return row

const EVENT_ROW_SCENE = preload("res://addons/flowkit/ui/workspace/event_row_ui.tscn")

func _create_comment_ui(data: FKComment) -> FKCommentUi:
"""Create comment block node from data."""
#print("[FKUnitUiFactory]: Creating comment block node")
var comment: FKCommentUi = COMMENT_SCENE.instantiate()
var copy := FKComment.new()
copy.text = data.text

comment.legitimize(copy, registry)
return comment

const COMMENT_SCENE = preload("res://addons/flowkit/ui/workspace/comment_ui.tscn")

func _create_group_block(data: FKGroup) -> FKGroupUi:
"""Create group block node from data."""
#print("[FKUnitUiFactory]: Creating group block node")
var group: FKGroupUi = GROUP_SCENE.instantiate()
var copy := data.copy_deep()
copy.normalize_children()
group.legitimize(copy, registry)
return group

const GROUP_SCENE = preload("res://addons/flowkit/ui/workspace/group_ui.tscn")
1 change: 1 addition & 0 deletions addons/flowkit/editor/Ui/unit_ui_factory.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dpobeetfqwbo1
2 changes: 1 addition & 1 deletion addons/flowkit/editor/editor_globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const CONDITION_ITEM_SCENE := preload("res://addons/flowkit/ui/workspace/conditi
const ACTION_ITEM_SCENE := preload("res://addons/flowkit/ui/workspace/action_unit_ui.tscn")

const BRANCH_ITEM_SCENE_PATH := "res://addons/flowkit/ui/workspace/branch_unit_ui.tscn"
const BRANCH_ITEM_SCENE := preload(BRANCH_ITEM_SCENE_PATH)
const BRANCH_ITEM_SCENE := preload(BRANCH_ITEM_SCENE_PATH)
2 changes: 1 addition & 1 deletion addons/flowkit/editor/main_editor_input_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func initialize(main_ed: FKMainEditor):

var _editor: FKMainEditor
var clipboard: FKClipboardManager
var block_container: BlockContainerUi
var block_container: FKBlockContainerUi

func handle_input(event: InputEvent):
var is_left_click: bool = event is InputEventMouseButton and event.pressed and \
Expand Down
1 change: 1 addition & 0 deletions addons/flowkit/editor/sheet_io.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func load_sheet(scene_uid: int) -> FKEventSheet:
func save_sheet(scene_uid: int, sheet: FKEventSheet) -> int:
var sheet_path := get_sheet_path(scene_uid)
if sheet_path == "":
print("[SheetIo] Returning err invalid param")
return ERR_INVALID_PARAMETER

DirAccess.make_dir_recursive_absolute(SHEET_DIR)
Expand Down
72 changes: 72 additions & 0 deletions addons/flowkit/resources/event_sheet.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@tool
extends Resource
class_name FKEventSheet
## The main event sheet resource that stores all events, comments, and groups for a scene.
Expand All @@ -14,6 +15,35 @@ class_name FKEventSheet
## Stores the display order: [{"type": "event"|"comment"|"group", "index": int}, ...]
@export var item_order: Array[Dictionary] = []

## Returns an array of the top-level FKUnits in the order they were
## appended to this sheet.
var ordered_items: Array[FKUnit]:
get:
if _ordered_items.size() != item_order.size():
_refresh_ordered_items()

return _ordered_items

func _refresh_ordered_items():
_ordered_items.clear()

for item in item_order:
var item_type = item.get("type", "")
var item_index: int = item.get("index", 0)
var to_add: FKUnit = null

if item_type == "event" and item_index < events.size():
to_add = events[item_index]
elif item_type == "comment" and item_index < comments.size():
to_add = comments[item_index]
elif item_type == "group" and item_index < groups.size():
to_add = groups[item_index]

if to_add:
_ordered_items.append(to_add)

var _ordered_items: Array[FKUnit] = []

func get_all_events() -> Array:
var events := []
events.append_array(self.events)
Expand Down Expand Up @@ -67,7 +97,49 @@ func get_ordered_items() -> Array:

return items

static func from_units(units: Array[FKUnit]) -> FKEventSheet:
var sheet := FKEventSheet.new()
for elem in units:
sheet.append_copy_of(elem)
return sheet

## Updates the item order as well.
func append_copy_of(unit: FKUnit):
var copy := unit.duplicate_block()

var where_copy_goes: Array = _array_for(copy)
where_copy_goes.append(copy)

var order_to_append: Dictionary = \
{
"type": copy.block_type,
"index": where_copy_goes.size() - 1
}
item_order.append(order_to_append)

## Returns the array in this sheet that the passed unit is able to go into
func _array_for(unit: FKUnit) -> Array:
var result: Array = []

if unit is FKEventBlock:
result = events
#print("[FKEventSheet] chosen arr: events")
elif unit is FKComment:
result = comments
#print("[FKEventSheet] chosen arr: comments")
elif unit is FKGroup:
result = groups
#print("[FKEventSheet] chosen arr: groups")
elif unit is FKConditionUnit:
# Seems you can't have a top-level FKConditionUnit, but just in
# case for the future...
result = standalone_conditions
#print("[FKEventSheet] chosen arr: standalone_conditions")
else:
print("[FKEventSheet] Unknown block type we can't register: " + unit.block_type)

return result

func rebuild_order_from_items(ordered_items: Array) -> void:
"""Rebuild the events, comments, groups arrays and item_order from an ordered list."""
events = [] as Array[FKEventBlock]
Expand Down
1 change: 1 addition & 0 deletions addons/flowkit/runtime/Units/condition_unit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func duplicate_block() -> FKUnit:
result.target_node = str(target_node)
result.inputs = inputs.duplicate()
result.negated = negated
result.actions = [] as Array[FKActionUnit]

return result

Expand Down
Loading