Skip to content

Commit

Permalink
Fix #109
Browse files Browse the repository at this point in the history
Create script to be used by classes used in the Editor to replace the
use of PopochiuUtils.
Update the plugin version to show the proper name for Alpha 6.
Minor UI improvement in node with buttons to select the BaselineHelper
and WalkToPointHelper.
Added comments to methods in PopochiuUtils.
  • Loading branch information
mapedorr committed Dec 16, 2023
1 parent 69f59ac commit 0276de2
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func _parse_walkable_area(object: Object) -> void:
func _find_polygon_instance(object: Object) -> void:
if not object is PopochiuWalkableArea: return
var children = object.get_children()
PopochiuUtils.select_node(children[0])
PopochiuEditorHelper.select_node(children[0])


func _parse_navigation_polygon_instance(object: Object) -> void:
Expand Down Expand Up @@ -78,4 +78,4 @@ func _parse_navigation_polygon_instance(object: Object) -> void:

func _back_to_walkable_area(object: Object) -> void:
if not object.get_parent() is PopochiuWalkableArea: return
PopochiuUtils.select_node(object.get_parent())
PopochiuEditorHelper.select_node(object.get_parent())
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func _menu_item_pressed(id: int) -> void:
prop.set_script(script)

main_dock.ei.save_scene()
PopochiuUtils.select_node(prop)
PopochiuEditorHelper.select_node(prop)
main_dock.ei.select_file(script_path)

# Update this row properties and state
Expand Down
4 changes: 2 additions & 2 deletions addons/popochiu/editor/main_dock/tab_room.gd
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func _select_in_tree(por: PopochiuObjectRow) -> void:
var node := opened_room.get_node('%s/%s'\
% [_types[por.type].parent, por.node_path])

PopochiuUtils.select_node(node)
PopochiuEditorHelper.select_node(node)

_last_selected = por

Expand Down Expand Up @@ -336,7 +336,7 @@ func _on_character_seleced(id: int) -> void:
instance.owner = opened_room

main_dock.ei.save_scene()
PopochiuUtils.select_node(instance)
PopochiuEditorHelper.select_node(instance)


func _create_row_in_dock(type_id: int, child: Node) -> PopochiuObjectRow:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func _create() -> void:
# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Abrir las propiedades del hotspot creado en el Inspector
await get_tree().create_timer(0.1).timeout
PopochiuUtils.select_node(hotspot)
PopochiuEditorHelper.select_node(hotspot)

# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Fin
Expand Down
2 changes: 1 addition & 1 deletion addons/popochiu/editor/popups/create_prop/create_prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func _create() -> void:
# Abrir las propiedades de la prop creada en el Inspector
_main_dock.fs.scan()
await get_tree().create_timer(0.1).timeout
PopochiuUtils.select_node(prop_instance)
PopochiuEditorHelper.select_node(prop_instance)
_main_dock.ei.select_file(_new_prop_path + '.tscn')

# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func _create() -> void:
# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Abrir las propiedades de la región creada en el Inspector
await get_tree().create_timer(0.1).timeout
PopochiuUtils.select_node(region)
PopochiuEditorHelper.select_node(region)

# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Fin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func _create() -> void:
# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Abrir las propiedades de la walkable area creada en el Inspector
await get_tree().create_timer(0.1).timeout
PopochiuUtils.select_node(walkable_area)
PopochiuEditorHelper.select_node(walkable_area)

# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Fin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ extends RichTextLabel
# Show a text in the form of GUI. Can be used to show game (or narrator)
# messages.
# ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# warning-ignore-all:unused_signal
# warning-ignore-all:return_value_discarded

signal shown

Expand Down Expand Up @@ -44,9 +42,11 @@ func _show_box(msg := '') -> void:
rt.append_text(msg)
lbl.text = rt.text
add_child(lbl)
var size := lbl.size
if size.x > get_meta(DFLT_SIZE).x:
size.x = get_meta(DFLT_SIZE).x - 16.0

var lbl_size := lbl.size
if lbl_size.x > get_meta(DFLT_SIZE).x:
lbl_size.x = get_meta(DFLT_SIZE).x - 16.0

lbl.free()
rt.free()
# ===================================== Calculate the width of the node ====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ theme_override_styles/disabled = SubResource("StyleBoxEmpty_pcw4k")
theme_override_styles/focus = SubResource("StyleBoxEmpty_scpl3")

[node name="History" parent="." instance=ExtResource("7")]
visible = false

[node name="SaveLoad" parent="." instance=ExtResource("8")]
visible = false
Expand Down
23 changes: 12 additions & 11 deletions addons/popochiu/engine/others/popochiu_utils.gd
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
# Utility functions for Popochiu.
@tool
extends Node
class_name PopochiuUtils

static var ei: EditorInterface = null
extends Node
## Utility functions for Popochiu.


## Used by the graphic interface to get the position of a `node` in the scene
## in the transform space of the CanvasLayer where it is is rendered.
static func get_screen_coords_for(node: Node) -> Vector2:
return node.get_viewport().canvas_transform * node.get_global_position()


# Gets a random element from an Array
## Gets a random element from an Array.
static func get_random_array_element(arr: Array):
randomize()
var idx := randi() % arr.size()

return arr[idx]


# Gets a random index from an Array
## Gets a random index from an Array.
static func get_random_array_idx(arr: Array) -> int:
randomize()
var idx := randi() % arr.size()

return idx


## Compares the name of two files `a` and `b` to check which one comes first in
## alphabetical order.
static func sort_by_file_name(a: String, b: String) -> bool:
if a.get_file() < b.get_file():
return true
return false


## Overrides the font with `font_name` in a Control `node` with the Font received
## in `font`.
static func override_font(node: Control, font_name: String, font: Font) -> void:
node.add_theme_font_override(font_name, font)


static func select_node(node: Node) -> void:
ei.get_selection().clear()
ei.get_selection().add_node(node)


## Prints the text in `msg` with the error style for Popochiu.
static func print_error(msg: String) -> void:
print_rich("[bgcolor=c46c71][color=ffffff][b][Popochiu][/b] %s[/color][/bgcolor]" % msg)


## Prints the text in `msg` with the warning style for Popochiu.
static func print_warning(msg: String) -> void:
print_rich("[bgcolor=edf171][color=4a4a4a][b][Popochiu][/b] %s[/color][/bgcolor]" % msg)
2 changes: 1 addition & 1 deletion addons/popochiu/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ name="Popochiu"
description="[en] Point n' click games engine for Godot.
[es] Motor para crear juegos de aventura gráfica en Godot."
author="carenalga (@mapedorr) \\(|:3)/"
version="2.0-alpha_5"
version="2.0-alpha_6"
script="popochiu_plugin.gd"
13 changes: 8 additions & 5 deletions addons/popochiu/popochiu_export_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ func _export_begin(features: PackedStringArray, is_debug: bool, path: String, fl

file.close()

# Logic for Aseprite Importer
# This code removes importer's metadata from nodes before exporting them
# Thanks to Vinicius Gerevini and his Aseprite Wizard plugin for that!
# TODO: may be moved to another file so we keep things separated

## Logic for Aseprite Importer
## This code removes importer's metadata from nodes before exporting them
## Thanks to Vinicius Gerevini and his Aseprite Wizard plugin for that!
## TODO: may be moved to another file so we keep things separated
func _export_file(path: String, type: String, features: PackedStringArray) -> void:
if type != "PackedScene": return

var scene : PackedScene = ResourceLoader.load(path, type, 0)
var scene_changed := false
var root_node: Node = scene.instance(PackedScene.GEN_EDIT_STATE_INSTANCE)
var root_node: Node = scene.instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
var nodes := [root_node]

#remove metadata from scene
Expand All @@ -44,6 +45,7 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo

root_node.free()


func _remove_meta(node:Node, path: String) -> bool:
if node.has_meta(LOCAL_OBJ_CONFIG.LOCAL_OBJ_CONFIG_META_NAME):
node.remove_meta(LOCAL_OBJ_CONFIG.LOCAL_OBJ_CONFIG_META_NAME)
Expand All @@ -52,6 +54,7 @@ func _remove_meta(node:Node, path: String) -> bool:

return false


func _get_scene_content(path:String, scene:PackedScene) -> PackedByteArray:
var tmp_path = OS.get_cache_dir() + "tmp_scene." + path.get_extension()
ResourceSaver.save(scene, tmp_path)
Expand Down
27 changes: 8 additions & 19 deletions addons/popochiu/popochiu_plugin.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Plugin setup.
#
# Some icons that might be useful: godot\editor\editor_themes.cpp
@tool
extends EditorPlugin
## Plugin setup.
##
## Some icons that might be useful: godot\editor\editor_themes.cpp

const ES :=\
"[es] Estás usando Popochiu, un plugin para crear juegos point n' click"
Expand All @@ -25,7 +25,6 @@ var _shown_helpers := []
var _export_plugin: EditorExportPlugin = null
var _inspector_plugins := []
var _selected_node: Node = null
var _vsep := VSeparator.new()
var _btn_baseline := Button.new()
var _btn_walk_to := Button.new()
var _types_helper: Resource = null
Expand Down Expand Up @@ -94,7 +93,7 @@ func _enter_tree() -> void:
main_dock.ei = _editor_interface
main_dock.fs = _editor_file_system
main_dock.focus_mode = Control.FOCUS_ALL
PopochiuUtils.ei = _editor_interface
PopochiuEditorHelper.ei = _editor_interface

add_control_to_dock(DOCK_SLOT_RIGHT_BL, main_dock)

Expand Down Expand Up @@ -361,11 +360,9 @@ func _check_nodes() -> void:
_btn_baseline.set_pressed_no_signal(false)
_btn_walk_to.set_pressed_no_signal(false)

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


func _on_files_moved(old_file: String, new_file: String) -> void:
Expand All @@ -379,7 +376,6 @@ func _on_file_removed(file: String) -> void:


func _create_container_buttons() -> void:
var panl := Panel.new()
var hbox := HBoxContainer.new()

_btn_baseline.icon = preload('res://addons/popochiu/icons/baseline.png')
Expand All @@ -396,26 +392,20 @@ func _create_container_buttons() -> void:
_btn_walk_to.add_theme_stylebox_override('hover', _tool_btn_stylebox)
_btn_walk_to.pressed.connect(_select_walk_to)

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

panl.add_child(hbox)

add_control_to_container(
EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU,
panl
hbox
)

_vsep.hide()
_btn_baseline.hide()
_btn_walk_to.hide()
hbox.hide()


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

_editor_interface.get_selection().clear()

Expand All @@ -433,7 +423,6 @@ func _select_walk_to() -> void:
func _select_baseline() -> void:
_btn_baseline.set_pressed_no_signal(true)
_btn_walk_to.set_pressed_no_signal(false)
_vsep.show()

_editor_interface.get_selection().clear()

Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config/name="popochiu 2.0"
config/description="Make 2D point n' click games with a smooth workflow (like in Adventure Game Studio or PowerQuest)."
config/tags=PackedStringArray("4.1.x")
run/main_scene="res://popochiu/rooms/house/room_house.tscn"
config/features=PackedStringArray("4.1")
config/features=PackedStringArray("4.2")
config/icon="res://icon_v2.png"
config/windows_native_icon="res://popochiu_v2.ico"

Expand Down

0 comments on commit 0276de2

Please sign in to comment.