-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* state-machine * another iteration * remove state machine utils
- Loading branch information
1 parent
e828a88
commit 17d4a1f
Showing
14 changed files
with
724 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
public static class DecembristSettings | ||
namespace Decembrist | ||
{ | ||
public const string ConfigClass = "decembrist_plugin/commons/config_class"; | ||
public const string EventBusEnabled = "decembrist_plugin/commons/event_bus_enabled"; | ||
public const string LanEventsEnabled = "decembrist_plugin/commons/lan_events_enabled"; | ||
public static class DecembristSettings | ||
{ | ||
public const string ConfigClass = "decembrist_plugin/commons/config_class"; | ||
public const string EventBusEnabled = "decembrist_plugin/commons/event_bus_enabled"; | ||
public const string LanEventsEnabled = "decembrist_plugin/commons/lan_events_enabled"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,151 @@ | ||
using System; | ||
using Decembrist.Utils.Callback; | ||
using Godot; | ||
using VoidFunc = System.Action; | ||
|
||
namespace Decembrist.Utils | ||
{ | ||
public static class Controls | ||
{ | ||
public static AbstractCallback OnPointerEnter(this Control control, Action callback) | ||
public const string FocusEnteredSignal = "focus_entered"; | ||
public const string FocusExitedSignal = "focus_exited"; | ||
public const string GuiInputSignal = "gui_input"; | ||
public const string MinimumSizeChangedSignal = "minimum_size_changed"; | ||
public const string ModalClosedSignal = "modal_closed"; | ||
public const string MouseEnteredSignal = "mouse_entered"; | ||
public const string MouseExitedSignal = "mouse_exited"; | ||
public const string ResizedSignal = "resized"; | ||
public const string SizeFlagsChangedSignal = "size_flags_changed"; | ||
|
||
/// <summary> | ||
/// Emitted when the node gains keyboard focus. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnFocusEntered(this Control control, VoidFunc action) | ||
{ | ||
return control.Subscribe("mouse_entered", callback); | ||
var callback = control.Subscribe(FocusEnteredSignal, action); | ||
return () => control.Unsubscribe(FocusEnteredSignal, callback); | ||
} | ||
|
||
public static AbstractCallback OnPointerExit(this Control control, Action callback) | ||
|
||
/// <summary> | ||
/// Emitted when the node loses keyboard focus. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnFocusExited(this Control control, VoidFunc action) | ||
{ | ||
return control.Subscribe("mouse_exited", callback); | ||
var callback = control.Subscribe(FocusExitedSignal, action); | ||
return () => control.Unsubscribe(FocusExitedSignal, callback); | ||
} | ||
|
||
public static AbstractCallback OnGuiInput(this Control control, Action<InputEvent> callback) | ||
|
||
/// <summary> | ||
/// Emitted when the node receives an InputEvent. | ||
/// </summary> | ||
/// <param name="control">This control</param> | ||
/// <param name="action">action ( InputEvent event )</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnGuiInput(this Control control, Action<InputEvent> action) | ||
{ | ||
return control.Subscribe("gui_input", callback); | ||
var callback = control.Subscribe(GuiInputSignal, action); | ||
return () => control.Unsubscribe(GuiInputSignal, callback); | ||
} | ||
|
||
public static AbstractCallback OnGuiInput( | ||
/// <summary> | ||
/// Emitted when the node receives an InputEvent. | ||
/// </summary> | ||
/// <param name="control">This control</param> | ||
/// <param name="inputPredicate">Invokes only if the event satisfies the predicate</param> | ||
/// <param name="action">action ( InputEvent event )</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnGuiInput( | ||
this Control control, | ||
Func<InputEvent, bool> eventPredicate, | ||
Action<InputEvent> callback) | ||
Func<InputEvent, bool> inputPredicate, | ||
Action<InputEvent> action) | ||
{ | ||
return control.Subscribe("gui_input", (InputEvent @event) => | ||
var callback = control.Subscribe(GuiInputSignal, (InputEvent @event) => | ||
{ | ||
if (eventPredicate(@event)) | ||
if (inputPredicate(@event)) | ||
{ | ||
callback(@event); | ||
action(@event); | ||
} | ||
}); | ||
return () => control.Unsubscribe(GuiInputSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when the node receives an mouse InputEvent. | ||
/// </summary> | ||
/// <param name="control">This control</param> | ||
/// <param name="action">action ( InputEventMouseButton event )</param> | ||
/// <param name="inputPredicate">Invokes only if the event satisfies the predicate</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnMouseInput( | ||
this Control control, | ||
Action<InputEventMouseButton> action, | ||
Func<InputEventMouseButton, bool> inputPredicate = null) => control.OnGuiInput( | ||
@event => @event is InputEventMouseButton mouseEvent | ||
&& (inputPredicate == null || inputPredicate(mouseEvent)), | ||
@event => action(@event as InputEventMouseButton) | ||
); | ||
|
||
|
||
/// <summary> | ||
/// Emitted when the node's minimum size changes. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnMinimumSizeChanged(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(MinimumSizeChangedSignal, action); | ||
return () => control.Unsubscribe(MinimumSizeChangedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when a modal Control is closed. See show_modal. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnModalClosed(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(ModalClosedSignal, action); | ||
return () => control.Unsubscribe(ModalClosedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when the mouse enters the control's Rect area, provided its mouse_filter lets the event reach it. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnMouseEntered(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(MouseEnteredSignal, action); | ||
return () => control.Unsubscribe(MouseEnteredSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when the mouse leaves the control's Rect area, provided its mouse_filter lets the event reach it. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnMouseExited(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(MouseExitedSignal, action); | ||
return () => control.Unsubscribe(MouseExitedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when the control changes size. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnResized(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(ResizedSignal, action); | ||
return () => control.Unsubscribe(ResizedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when one of the size flags changes. See size_flags_horizontal and size_flags_vertical. | ||
/// </summary> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnSizeFlagsChanged(this Control control, Action action) | ||
{ | ||
var callback = control.Subscribe(SizeFlagsChangedSignal, action); | ||
return () => control.Unsubscribe(SizeFlagsChangedSignal, callback); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using Decembrist.Utils.Callback; | ||
using Godot; | ||
using VoidFunc = System.Action; | ||
|
||
namespace Decembrist.Utils | ||
{ | ||
public static class EditorPlugins | ||
{ | ||
public const string MainScreenChangedSignal = "main_screen_changed"; | ||
public const string ResourceSavedSignal = "resource_saved"; | ||
public const string SceneChangedSignal = "scene_changed"; | ||
public const string SceneClosedSignal = "scene_closed"; | ||
|
||
/// <summary> | ||
/// Emitted when user changes the workspace (2D, 3D, Script, AssetLib). Also works with custom screens defined by plugins. | ||
/// </summary> | ||
/// <param name="plugin">EditorPlugin object</param> | ||
/// <param name="action">action(String screen_name)</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnMainScreenChanged(this EditorPlugin plugin, Action<string> action) | ||
{ | ||
var callback = plugin.Subscribe(MainScreenChangedSignal, action); | ||
return () => plugin.Unsubscribe(MainScreenChangedSignal, callback); | ||
} | ||
|
||
/// <param name="plugin">EditorPlugin object</param> | ||
/// <param name="action">action( Resource resource )</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnResourceSaved(this EditorPlugin plugin, Action<Resource> action) | ||
{ | ||
var callback = plugin.Subscribe(ResourceSavedSignal, action); | ||
return () => plugin.Unsubscribe(ResourceSavedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when the scene is changed in the editor. The argument will return the root node of the scene that | ||
/// has just become active. If this scene is new and empty, the argument will be null. | ||
/// </summary> | ||
/// <param name="plugin">EditorPlugin object</param> | ||
/// <param name="action">action( Node scene_root )</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnSceneChanged(this EditorPlugin plugin, Action<Node> action) | ||
{ | ||
var callback = plugin.Subscribe(SceneChangedSignal, action); | ||
return () => plugin.Unsubscribe(SceneChangedSignal, callback); | ||
} | ||
|
||
/// <summary> | ||
/// Emitted when user closes a scene. The argument is file path to a closed scene. | ||
/// </summary> | ||
/// <param name="plugin">EditorPlugin object</param> | ||
/// <param name="action">action( String filepath )</param> | ||
/// <returns>Unsubscribe callback</returns> | ||
public static VoidFunc OnSceneClosed(this EditorPlugin plugin, Action<Node> action) | ||
{ | ||
var callback = plugin.Subscribe(SceneClosedSignal, action); | ||
return () => plugin.Unsubscribe(SceneClosedSignal, callback); | ||
} | ||
} | ||
} |
Oops, something went wrong.