Skip to content

Commit

Permalink
refs #37: InteractionPolygons for props and hotspots have been moved …
Browse files Browse the repository at this point in the history
…in the scene and an edit button has been exposed in the toolbar to edit them.
  • Loading branch information
stickgrinder committed Dec 3, 2023
1 parent 33c6e40 commit 6a3d97b
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 16 deletions.
6 changes: 0 additions & 6 deletions addons/popochiu/editor/factories/factory_popochiu_hostspot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ func create(obj_name: String, room: PopochiuRoom) -> int:
# Save the hostspot scene (.tscn) and put it into _scene class property
result_code = _save_obj_scene(new_obj)
if result_code != ResultCodes.SUCCESS: return result_code

# Create a collision polygon as a child in the room scene
var collision := CollisionPolygon2D.new()
collision.name = 'InteractionPolygon'
collision.modulate = Color.BLUE
_add_visible_child(collision)
# ▓▓▓ END OF LOCAL CODE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

# Add the object to its room
Expand Down
6 changes: 0 additions & 6 deletions addons/popochiu/editor/factories/factory_popochiu_prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ func create(obj_name: String, room: PopochiuRoom, is_interactive:bool = false, i
# Save the scene (.tscn) and put it into _scene class property
result_code = _save_obj_scene(new_obj)
if result_code != ResultCodes.SUCCESS: return result_code

# Create a collision polygon as a child in the room scene
var collision := CollisionPolygon2D.new()
collision.name = 'InteractionPolygon'
_add_visible_child(collision)

# ▓▓▓ END OF LOCAL CODE ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

# Add the object to its room
Expand Down
2 changes: 1 addition & 1 deletion addons/popochiu/editor/helpers/popochiu_types_helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ static func is_walkable_area(node: Node) -> bool:

## TODO: If and when #67 is ready, add static facade metods to create items
## so we can just pass this object as entry point for all operations
## on Popochiu objects
## on Popochiu objects
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ func _on_item_used(item: PopochiuInventoryItem) -> void:
func hide_helpers() -> void:
$BaselineHelper.hide()
$WalkToHelper.hide()
$InteractionPolygon.hide()


func show_helpers() -> void:
$BaselineHelper.show()
$WalkToHelper.show()
$InteractionPolygon.show()


func disable() -> Callable:
Expand Down
5 changes: 4 additions & 1 deletion addons/popochiu/engine/objects/hotspot/popochiu_hotspot.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

[node name="Hotspot" type="Area2D"]
script = ExtResource("1")
walk_to_point = Vector2(0, 0)
cursor = 1

[node name="BaselineHelper" type="Line2D" parent="."]
Expand All @@ -19,3 +18,7 @@ offset_top = -2.5
offset_right = 2.5
offset_bottom = 2.5
color = Color(0, 1, 1, 1)

[node name="InteractionPolygon" type="CollisionPolygon2D" parent="."]
modulate = Color(0, 0, 1, 1)
polygon = PackedVector2Array(-12, -12, 12, -12, 12, 12, -12, 12)
3 changes: 3 additions & 0 deletions addons/popochiu/engine/objects/prop/popochiu_prop.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ offset_right = 2.5
offset_bottom = 2.5
color = Color(0, 1, 1, 1)

[node name="InteractionPolygon" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(-12, -12, 12, -12, 12, 12, -12, 12)

[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1

Expand Down
Binary file added addons/popochiu/icons/interaction_polygon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/popochiu/icons/interaction_polygon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cesndtvbchw7v"
path="res://.godot/imported/interaction_polygon.png-28f3d05312276a3121232981bf4f2bee.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/popochiu/icons/interaction_polygon.png"
dest_files=["res://.godot/imported/interaction_polygon.png-28f3d05312276a3121232981bf4f2bee.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
30 changes: 28 additions & 2 deletions addons/popochiu/popochiu_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var _selected_node: Node = null
var _vsep := VSeparator.new()
var _btn_baseline := Button.new()
var _btn_walk_to := Button.new()
var _btn_interaction_polygon := Button.new()
var _types_helper: Resource = null
var _tool_btn_stylebox :=\
_editor_interface.get_base_control().get_theme_stylebox("normal", "Button")
Expand Down Expand Up @@ -341,9 +342,11 @@ func _check_nodes() -> void:

_btn_baseline.show()
_btn_walk_to.show()
_btn_interaction_polygon.show()
else:
_btn_baseline.hide()
_btn_walk_to.hide()
_btn_interaction_polygon.hide()


func _on_files_moved(old_file: String, new_file: String) -> void:
Expand Down Expand Up @@ -374,17 +377,25 @@ func _create_container_buttons() -> void:
_btn_walk_to.add_theme_stylebox_override('hover', _tool_btn_stylebox)
_btn_walk_to.pressed.connect(_select_walk_to)

_btn_interaction_polygon.icon = preload('res://addons/popochiu/icons/interaction_polygon.png')
_btn_interaction_polygon.tooltip_text = 'Interaction Polygon'
_btn_interaction_polygon.toggle_mode = true
_btn_interaction_polygon.add_theme_stylebox_override('normal', _tool_btn_stylebox)
_btn_interaction_polygon.add_theme_stylebox_override('hover', _tool_btn_stylebox)
_btn_interaction_polygon.pressed.connect(_select_interaction_polygon)

hbox.add_child(_vsep)
hbox.add_child(_btn_baseline)
hbox.add_child(_btn_walk_to)
hbox.add_child(_btn_interaction_polygon)

panl.add_child(hbox)

add_control_to_container(
EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU,
panl
)

_vsep.hide()
_btn_baseline.hide()
_btn_walk_to.hide()
Expand All @@ -393,6 +404,7 @@ func _create_container_buttons() -> void:
func _select_walk_to() -> void:
_btn_walk_to.set_pressed_no_signal(true)
_btn_baseline.set_pressed_no_signal(false)
_btn_interaction_polygon.set_pressed_no_signal(false)
_vsep.hide()

if _types_helper.is_prop(_selected_node)\
Expand All @@ -403,8 +415,9 @@ func _select_walk_to() -> void:


func _select_baseline() -> void:
_btn_baseline.set_pressed_no_signal(true)
_btn_walk_to.set_pressed_no_signal(false)
_btn_baseline.set_pressed_no_signal(true)
_btn_interaction_polygon.set_pressed_no_signal(false)
_vsep.show()

if _types_helper.is_prop(_selected_node)\
Expand All @@ -414,6 +427,19 @@ func _select_baseline() -> void:
_editor_interface.edit_node(_selected_node.get_node('../BaselineHelper'))


func _select_interaction_polygon() -> void:
_btn_walk_to.set_pressed_no_signal(false)
_btn_baseline.set_pressed_no_signal(false)
_btn_interaction_polygon.set_pressed_no_signal(true)
_vsep.hide()

if _types_helper.is_prop(_selected_node)\
or _types_helper.is_hotspot(_selected_node):
_editor_interface.edit_node(_selected_node.get_node('InteractionPolygon'))
else:
_editor_interface.edit_node(_selected_node.get_node('../InteractionPolygon'))


func _move_to_project(id: int) -> void:
# Move files and folders so developer can overwrite them
if id == PopochiuResources.GI:
Expand Down
Binary file added popochiu/sources/aseprite/room_exterior.aseprite
Binary file not shown.

0 comments on commit 6a3d97b

Please sign in to comment.