Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Event class #871

Merged
merged 1 commit into from
Apr 23, 2022
Merged
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
133 changes: 133 additions & 0 deletions addons/dialogic/resources/event_class.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

# This file is part of EventSystem, distributed under MIT license
# and modified to work with Dialogic.
# You can see the license of this file here
# https://github.com/AnidemDex/Godot-EventSystem/blob/main/LICENSE

tool
extends Resource

# Class name not exposed since original event were not exposed either
#class_name Event

##
## Base class for all events.
##
## @desc:
## Every event relies on this class.
## If you want to do your own event, you should [code]extend[/code] this class.
##

## Emmited when the event starts.
## The signal is emmited with the event resource [code]event_resource[/code]
signal event_started(event_resource)

## Emmited when the event finish.
## The signal is emmited with the event resource [code]event_resource[/code]
signal event_finished(event_resource)

##########
# Default Event Properties
##########

## Determines if the event will go to next event inmediatly or not.
## If value is true, the next event will be executed when event ends.
export(bool) var continue_at_end:bool = true setget _set_continue

var event_node_path:NodePath setget _set_event_node_path

##########
# Event Editor Properties
##########

## The event icon that'll be displayed in the editor
var event_icon:Texture = load("res://addons/dialogic/Images/Event Icons/warning.svg")

## The event color that event node will take in the editor
var event_color:Color = Color("FBB13C")

## The event name that'll be displayed in the editor.
## If the resource name is different from the event name, resource_name is returned instead.
var event_name:String = "Event" setget ,get_event_name

## The event preview string that will be displayed next to the event name in the editor.
## You can use String formats to parse variables from the script:
## [codeblock] event_preview_string = "{resource_name}" [/codeblock]
## Will display the resource's name instead of [code]{resource_name}[/code].
var event_preview_string:String = ""

## The event hint that'll be displayed when you hover the event button in the editor.
var event_hint:String = ""

var event_category:String = "Custom"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnidemDex veo que esto es una string ahora pero me preocupa porque no sería fácil de traducir en un futuro. Tienes pensado algo en particular para las categorías?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es un String cualquiera. Hay un nodo (CategoryManager) quien es quien crea las categorías y los botones. Así que esa cadena puede traducirse antes de crear la categoría



var _event_manager:Node
var _event_node_fallback:Node

## Executes the event behaviour.
func execute() -> void:
emit_signal("event_started", self)

call_deferred("_execute")


## Ends the event behaviour.
func finish() -> void:
emit_signal("event_finished", self)


func _execute() -> void:
finish()


func get_event_name() -> String:
if event_name != resource_name and resource_name != "":
return resource_name
return event_name


func get_event_manager_node() -> Node:
return _event_manager


func get_event_node() -> Node:
var event_node:Node
if event_node_path != NodePath():
event_node = get_event_manager_node().get_tree().current_scene.get_node(event_node_path)

if not is_instance_valid(event_node):
event_node = _event_node_fallback

return event_node


func _set_continue(value:bool) -> void:
continue_at_end = value
property_list_changed_notify()
emit_changed()


func _set_event_node_path(value:NodePath) -> void:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnidemDex por que haces el setget en este tipo de propiedades?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Los recursos necesitan notificar de alguna forma a los objetos que les usan que fueron modificados. Implemento los setter para hacer la notificación

event_node_path = value
property_list_changed_notify()
emit_changed()


func property_can_revert(property:String) -> bool:
if property == "event_node_path":
return true
return false


func property_get_revert(property:String):
if property == "event_node_path":
return NodePath()


func _to_string() -> String:
return "[{event_name}:{id}]".format({"event_name":event_name, "id":get_instance_id()})


func _hide_script_from_inspector():
return true