Skip to content

Commit

Permalink
refs #232: gizmos working for PopochiuClickables. (#235)
Browse files Browse the repository at this point in the history
* refs #232: gizmos working for PopochiuClickables.

* refs #232: editor settings refactoring.

* refs #232: initialization and clean-up.

* refs #232: gizmo sub-plugin enable/disable.

* refs #232 #134: old node-based helpers removed.

* refs #232: updating documentation to reflect the new gizmos

* refs #232: interaction polygon button visibility follows node selection, updated look at point init code.

* refs #232: restored correct default values for baseline and walk_to_point for PopochiuProp. See: #235 (comment)

* refs #232: removed _exit_tree(). See: #235 (comment)

* refs #232: _try_grab_gizmo restricted to InputEventMouseButton. See: #235 (comment)

* refs #232: added/edited code regions. See: #235 (comment)

* refs #232: updated plugin.cfg. See: #235 (comment)

---------

Co-authored-by: Paolo Pustorino <[email protected]>
  • Loading branch information
drbbgh and stickgrinder authored May 24, 2024
1 parent 3ed7124 commit e009c9d
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func _ready() -> void:
_types_helper = load('res://addons/popochiu/editor/helpers/popochiu_types_helper.gd')

# Connect to child signals
btn_baseline.pressed.connect(_select_baseline)
btn_walk_point.pressed.connect(_select_walk_point)
btn_baseline.pressed.connect(_toggle_baseline_visibile)
btn_walk_point.pressed.connect(_toggle_walk_to_point_visibile)
btn_interaction_polygon.pressed.connect(_select_interaction_polygon)

# Connect to singleton signals
Expand All @@ -30,38 +30,14 @@ func _ready() -> void:
#endregion

#region Private ####################################################################################
func _select_walk_point() -> void:
btn_baseline.set_pressed_no_signal(false)
btn_interaction_polygon.set_pressed_no_signal(false)

EditorInterface.get_selection().clear()

var walk_point_helper: Marker2D = null

if _types_helper.is_prop(_selected_node)\
or _types_helper.is_hotspot(_selected_node):
walk_point_helper = _selected_node.get_node("WalkToHelper")
else:
walk_point_helper = _selected_node.get_node("../WalkToHelper")

EditorInterface.get_selection().add_node(walk_point_helper)
func _toggle_walk_to_point_visibile() -> void:
#TODO: gizmo visibility logic
pass


func _select_baseline() -> void:
btn_walk_point.set_pressed_no_signal(false)
btn_interaction_polygon.set_pressed_no_signal(false)

EditorInterface.get_selection().clear()

var baseline_helper: Line2D = null

if _types_helper.is_prop(_selected_node)\
or _types_helper.is_hotspot(_selected_node):
baseline_helper = _selected_node.get_node("BaselineHelper")
else:
baseline_helper = _selected_node.get_node("../BaselineHelper")

EditorInterface.get_selection().add_node(baseline_helper)
func _toggle_baseline_visibile() -> void:
#TODO: gizmo visibility logic
pass


func _select_interaction_polygon() -> void:
Expand Down Expand Up @@ -90,14 +66,14 @@ func _check_nodes() -> void:

if EditorInterface.get_selection().get_selected_nodes().is_empty():
deselect_helpers_buttons = true

# Deselect any BaselineHelper or WalkToPointHelper
if EditorInterface.get_selection().get_selected_nodes().size() > 1:
if EditorInterface.get_selection().get_selected_nodes().size() != 1:
for node in EditorInterface.get_selection().get_selected_nodes():
if node.name in ["BaselineHelper", "WalkToHelper", "InteractionPolygon"]:
if node.name in ["InteractionPolygon"]:
EditorInterface.get_selection().remove_node.call_deferred(node)
deselect_helpers_buttons = true

if deselect_helpers_buttons:
_deselect_buttons()

Expand All @@ -119,6 +95,8 @@ func _check_nodes() -> void:

if not is_instance_valid(_types_helper): return

hide()

if EditorInterface.get_selection().get_selected_nodes().size() == 1:
_selected_node = EditorInterface.get_selection().get_selected_nodes()[0]

Expand All @@ -131,8 +109,6 @@ func _check_nodes() -> void:
_deselect_buttons()

show()
else:
hide()


func _deselect_buttons() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
[ext_resource type="Texture2D" uid="uid://cesndtvbchw7v" path="res://addons/popochiu/icons/interaction_polygon.png" id="3_kma38"]

[node name="PopochiuCanvasEditorMenu" type="HBoxContainer"]
visible = false
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("1_vs7c6")

[node name="BtnBaseline" type="Button" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2
tooltip_text = "Baseline"
toggle_mode = true
icon = ExtResource("1_8j5rt")

[node name="BtnWalkPoint" type="Button" parent="."]
unique_name_in_owner = true
visible = false
layout_mode = 2
tooltip_text = "Walk point"
toggle_mode = true
Expand Down
62 changes: 49 additions & 13 deletions addons/popochiu/editor/config/editor_config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,51 @@ const ASEPRITE_IMPORTER_ENABLED = "popochiu/import/aseprite/enable_aseprite_impo
const ASEPRITE_COMMAND_PATH = "popochiu/import/aseprite/command_path"
const ASEPRITE_REMOVE_JSON_FILE = "popochiu/import/aseprite/remove_json_file"

# GIZMOS -------------------------------------------------------------------------------------------
const GIZMOS_FONT_SIZE = "popochiu/gizmos/font_size"
const GIZMOS_BASELINE_COLOR = "popochiu/gizmos/baseline_color"
const GIZMOS_WALK_TO_POINT_COLOR = "popochiu/gizmos/walk_to_point_color"
const GIZMOS_LOOK_AT_POINT_COLOR = "popochiu/gizmos/look_at_point_color"
const GIZMOS_HANDLER_SIZE = "popochiu/gizmos/handler_size"
const GIZMOS_SHOW_CONNECTORS = "popochiu/gizmos/show_connectors"
const GIZMOS_SHOW_OUTLINE = "popochiu/gizmos/show_handler_outline"
const GIZMOS_SHOW_NODE_NAME = "popochiu/gizmos/show_node_name"

# Settings default values
static var defaults := {
ASEPRITE_IMPORTER_ENABLED: false,
ASEPRITE_COMMAND_PATH: _default_command(),
ASEPRITE_REMOVE_JSON_FILE: true,
GIZMOS_FONT_SIZE: EditorInterface.get_editor_theme().default_font_size,
GIZMOS_BASELINE_COLOR: Color.CYAN,
GIZMOS_WALK_TO_POINT_COLOR: Color.GREEN,
GIZMOS_LOOK_AT_POINT_COLOR: Color.RED,
GIZMOS_HANDLER_SIZE: 32,
GIZMOS_SHOW_CONNECTORS: true,
GIZMOS_SHOW_OUTLINE: true,
GIZMOS_SHOW_NODE_NAME: true,
}

static var editor_settings: EditorSettings


#region Public #####################################################################################
static func initialize_editor_settings():
editor_settings = EditorInterface.get_editor_settings()

_initialize_editor_setting(ASEPRITE_IMPORTER_ENABLED, false, TYPE_BOOL)
_initialize_editor_setting(ASEPRITE_COMMAND_PATH, _default_command(), TYPE_STRING)
_initialize_editor_setting(ASEPRITE_REMOVE_JSON_FILE, true, TYPE_BOOL)

# Aseprite importer
_initialize_editor_setting(ASEPRITE_IMPORTER_ENABLED, TYPE_BOOL)
_initialize_editor_setting(ASEPRITE_COMMAND_PATH, TYPE_STRING)
_initialize_editor_setting(ASEPRITE_REMOVE_JSON_FILE, TYPE_BOOL)
# Gizmos
_initialize_editor_setting(GIZMOS_BASELINE_COLOR, TYPE_COLOR)
_initialize_editor_setting(GIZMOS_WALK_TO_POINT_COLOR, TYPE_COLOR)
_initialize_editor_setting(GIZMOS_LOOK_AT_POINT_COLOR, TYPE_COLOR)
_initialize_editor_setting(GIZMOS_HANDLER_SIZE, TYPE_INT, PROPERTY_HINT_RANGE, "4,64")
_initialize_editor_setting(GIZMOS_FONT_SIZE, TYPE_INT, PROPERTY_HINT_RANGE, "4,64")
_initialize_editor_setting(GIZMOS_SHOW_CONNECTORS, TYPE_BOOL)
_initialize_editor_setting(GIZMOS_SHOW_OUTLINE, TYPE_BOOL)
_initialize_editor_setting(GIZMOS_SHOW_NODE_NAME, TYPE_BOOL)


static func get_icon(icon: Icons) -> Texture2D:
Expand All @@ -37,41 +72,42 @@ static func get_icon(icon: Icons) -> Texture2D:

# ASEPRITE IMPORTER --------------------------------------------------------------------------------
static func aseprite_importer_enabled() -> bool:
return _get_editor_setting(ASEPRITE_IMPORTER_ENABLED, false)
return _get_editor_setting(ASEPRITE_IMPORTER_ENABLED)


static func get_command() -> String:
return _get_editor_setting(ASEPRITE_COMMAND_PATH, _default_command())
return _get_editor_setting(ASEPRITE_COMMAND_PATH)


static func should_remove_source_files() -> bool:
return _get_editor_setting(ASEPRITE_REMOVE_JSON_FILE, true)

return _get_editor_setting(ASEPRITE_REMOVE_JSON_FILE)

#endregion


#region Private ####################################################################################
static func _default_command() -> String:
return 'aseprite'


static func _initialize_editor_setting(
key: String, default_value, type: int, hint: int = PROPERTY_HINT_NONE
key: String, type: int, hint: int = PROPERTY_HINT_NONE, hint_string : String = ""
) -> void:
if editor_settings.has_setting(key): return

editor_settings.set_setting(key, default_value)
editor_settings.set_initial_value(key, default_value, false)
editor_settings.set_setting(key, defaults[key])
editor_settings.set_initial_value(key, defaults[key], false)
editor_settings.add_property_info({
"name": key,
"type": type,
"hint": hint,
"hint_string": hint_string
})


static func _get_editor_setting(key: String, default_value):
static func _get_editor_setting(key: String):
var e = editor_settings.get_setting(key)
return e if e != null else default_value
return e if e != null else defaults[e]


#endregion
Loading

0 comments on commit e009c9d

Please sign in to comment.