Trigger API Reference DCEI Events Input0 - funovus/editor-wiki GitHub Wiki
Table of Contents
- [Trigger API Reference\DCEI Events\Input](#trigger-api-referencedcei-eventsinput)
* [void TriggerAddMouseDownEvent(int mouseButtonId, TypedCallback trigger)](#void-triggeraddmousedowneventint-mousebuttonid-typedcallbackfloat2-unit-trigger)
* [void TriggerAddMouseUpEvent(int mouseButtonId, TypedCallback trigger)](#void-triggeraddmouseupeventint-mousebuttonid-typedcallbackfloat2-unit-trigger)
* [void TriggerAddSwipeTouchDownEvent(TypedCallback trigger)](#void-triggeraddswipetouchdowneventtypedcallbackfloat2-trigger)
* [void TriggerAddSwipeTouchUpEvent(TypedCallback trigger)](#void-triggeraddswipetouchupeventtypedcallbackfloat2-trigger)
* [void TriggerAddTouchDownEvent(TypedCallback trigger)](#void-triggeraddtouchdowneventtypedcallbackfloat2-unit-trigger)
* [void TriggerAddTouchUpEvent(TypedCallback trigger)](#void-triggeraddtouchupeventtypedcallbackfloat2-unit-trigger)
* [void TriggerAddJoystickEvent(TypedCallback trigger)](#void-triggeraddjoystickeventtypedcallback-trigger)
* [void TriggerAddJoystickEventWithJoystickOptions(TypedCallback trigger, JoystickOptions options)](#void-triggeraddjoystickeventwithjoystickoptionstypedcallback-trigger-joystickoptions-options)
* [void TriggerAddJoystickTapEvent(TypedCallback trigger, int joystickId, float validDuration, float validRadius)](#void-triggeraddjoysticktapeventtypedcallback-trigger-int-joystickid-float-validduration-float-validradius)
* [void TriggerAddJoystickSwipeEvent(TypedCallback trigger, int joystickId, float validDuration)](#void-triggeraddjoystickswipeeventtypedcallback-trigger-int-joystickid-float-validduration)
* [void TriggerAddJoystickReleaseEvent(TypedCallback trigger)](#void-triggeraddjoystickreleaseeventtypedcallback-trigger)
* [void TriggerAddJoystickReleaseEventWithId(TypedCallback trigger, int joystickId)](#void-triggeraddjoystickreleaseeventwithidtypedcallback-trigger-int-joystickid)
* [void TriggerAddTextCommandEvent(TypedCallback trigger)](#void-triggeraddtextcommandeventtypedcallbackstring-trigger)
* [void TriggerAddJoystickButtonEvent(int buttonId, TypedCallback trigger, JoystickButtonOptions options)](#void-triggeraddjoystickbuttoneventint-buttonid-typedcallback-trigger-joystickbuttonoptions-options)
* [void TriggerAddMappedKeyDownEvent(string keyEventName, TypedCallback trigger)](#void-triggeraddmappedkeydowneventstring-keyeventname-typedcallbackstring-trigger)
* [void TriggerAddMappedKeyUpEvent(string keyEventName, TypedCallback trigger)](#void-triggeraddmappedkeyupeventstring-keyeventname-typedcallbackstring-trigger)
* [void TriggerAddOnMouseTrackingEvent(TypedCallback trigger)](#void-triggeraddonmousetrackingeventtypedcallbackint-float2-trigger)
* [void StartMouseTracking(int playerId)](#void-startmousetrackingint-playerid)
* [void StopMouseTracking(int playerId)](#void-stopmousetrackingint-playerid)
* [void SetBackButton(TypedCallback callback)](#void-setbackbuttontypedcallback-callback)
* [void SetOnDownCallback(Transform ui, object callback)](#void-setondowncallbacktransform-ui-object-callback)
* [void SetOnUpCallback(Transform ui, object callback)](#void-setonupcallbacktransform-ui-object-callback)
* [void SetOnClickCallback(Transform ui, object callback)](#void-setonclickcallbacktransform-ui-object-callback)
* [void SetPauseMenuCallback(TypedCallback callback)](#void-setpausemenucallbacktypedcallbackbool-callback)
|
Trigger API Reference\DCEI Events\Input {Trigger-API-ReferenceDCEI-EventsInput}
void TriggerAddMouseDownEvent(int mouseButtonId, TypedCallback<Float2, unit> trigger) {void-TriggerAddMouseDownEventint-mouseButtonId-TypedCallbackFloat2-unit-trigger}
void TriggerAddMouseDownEvent(int mouseButtonId, TypedCallback<Float2, unit> trigger)
This event triggers when the specified mouse button down occurs. Using this event will disable unit selection as well as all other built-in mouse functions tied to the given mouse button id including any TriggerAddMouseUpEvent(). This function can also pass the mouse cursor position as a parameter to the callback function.
-
int
mouseButtonId
the mouse button; mouseButtonId 0: left mouse, mouseButtonId 1: right mouse. -
object
trigger
the callback function that is run when the event is triggered.
-
Float2
position
-
Unit
target_unit
DCEI.TriggerAddMouseDownEvent(0, OnMouseDown)
function OnMouseDown(cursor_pos)
DCEI.LogMessage("LMB Down")
end
void TriggerAddMouseUpEvent(int mouseButtonId, TypedCallback<Float2, unit> trigger) {void-TriggerAddMouseUpEventint-mouseButtonId-TypedCallbackFloat2-unit-trigger}
void TriggerAddMouseUpEvent(int mouseButtonId, TypedCallback<Float2, unit> trigger)
This event triggers when the specified mouse button up occurs. Using this event will disable unit commands as well as all other built-in mouse functions tied to the given mouse button id including any TriggerAddMouseDownEvent().
-
int
mouseButtonId
the mouse button; mouseButtonId 0: left mouse, mouseButtonId 1: right mouse. -
object
trigger
the callback function that is run when the event is triggered.
-
Float2
position
-
Unit
target_unit
DCEI.TriggerAddMouseUpEvent(1, OnMouseUp)
function OnMouseUp()
DCEI.LogMessage("RMB Up")
end
void TriggerAddSwipeTouchDownEvent(TypedCallback<Float2> trigger) {void-TriggerAddSwipeTouchDownEventTypedCallbackFloat2-trigger}
void TriggerAddSwipeTouchDownEvent(TypedCallback<Float2> trigger)
This event triggers when the start of a screen swipe input has been detected. Only works on mobile. Using this event will disable camera pan as well as all other built-in touch functions including TriggerAddTouchUpEvent.
-
function
trigger
the trigger to run when this event occurs. Parameterpoint
denotes the point in screenspace (not worldspace), where the Swipe input was started.
-
Float2
position
DCEI.TriggerAddSwipeTouchDownEvent(function(point)
DCEI.LogMessage("Swipe down happens on screen point: " .. point.x .. ", " .. point.y)
end)
void TriggerAddSwipeTouchUpEvent(TypedCallback<Float2> trigger) {void-TriggerAddSwipeTouchUpEventTypedCallbackFloat2-trigger}
void TriggerAddSwipeTouchUpEvent(TypedCallback<Float2> trigger)
This event triggers when the end of a screen swipe input has been detected. Only works on mobile. Using this event will disable camera pan as well as all other built-in touch functions including TriggerAddTouchUpEvent.
-
function
trigger
the trigger to run when this event occurs. Parameterpoint
denotes the point in screenspace (not worldspace), where the Swipe input has ended.
-
Float2
position
DCEI.TriggerAddSwipeTouchUpEvent(function(point)
DCEI.LogMessage("Swipe up happens on screen point: " .. point.x .. ", " .. point.y)
end)
void TriggerAddTouchDownEvent(TypedCallback<Float2, unit> trigger) {void-TriggerAddTouchDownEventTypedCallbackFloat2-unit-trigger}
void TriggerAddTouchDownEvent(TypedCallback<Float2, unit> trigger)
This event triggers when the start of a touch input is detected. Only works on mobile. Using this event will disable unit selection as well as all other built-in touch functions including TriggerAddSwipeTouchDownEvent.
-
function
trigger
the trigger to run when this event occurs. Parameterpoint
denotes the point in screenspace (not worldspace), where the Touch input occurred.
-
Float2
position
-
Unit
target_unit
DCEI.TriggerAddTouchDownEvent(function(point)
DCEI.LogMessage("Touch down happens on screen point: " .. point.x .. ", " .. point.y)
end)
void TriggerAddTouchUpEvent(TypedCallback<Float2, unit> trigger) {void-TriggerAddTouchUpEventTypedCallbackFloat2-unit-trigger}
void TriggerAddTouchUpEvent(TypedCallback<Float2, unit> trigger)
This event triggers when the end of a touch input is detected. Only works on mobile. Using this event will disable unit selection as well as all other built-in touch functions including TriggerAddSwipeTouchDownEvent.
-
function
trigger
the trigger to run when this event occurs. Parameterpoint
denotes the point in screenspace (not worldspace), where the Touch input occurred.
-
Float2
position
-
Unit
target_unit
DCEI.TriggerAddTouchUpEvent(function(point)
DCEI.LogMessage("Touch up happens on screen point: " .. point.x .. ", " .. point.y)
end)
void TriggerAddJoystickEvent(TypedCallback trigger) {void-TriggerAddJoystickEventTypedCallback-trigger}
void TriggerAddJoystickEvent(TypedCallback trigger)
Creates an on-screen joystick and that triggers this event when moved. Uses default JoystickOptions.
function OnJoystickMove()
local axes = DCEI.TriggeringJoystickAxes
DCEI.DirectionalMove(unit, axes.x, axes.y)
end
DCEI.TriggerAddJoystickEvent(OnJoystickMove)
void TriggerAddJoystickEventWithJoystickOptions(TypedCallback trigger, JoystickOptions options) {void-TriggerAddJoystickEventWithJoystickOptionsTypedCallback-trigger-JoystickOptions-options}
void TriggerAddJoystickEventWithJoystickOptions(TypedCallback trigger, JoystickOptions options)
Creates an on-screen joystick and that triggers this event when moved. Uses default JoystickOptions.
By default, the joystick can be used with WASD, arrow keys, or by click-dragging the joystick button.
function OnJoystickMove()
local axes = DCEI.TriggeringJoystickAxes
DCEI.DirectionalMove(unit, axes.x, axes.y)
end
DCEI.TriggerAddJoystickEvent(OnJoystickMove)
void TriggerAddJoystickTapEvent(TypedCallback trigger, int joystickId, float validDuration, float validRadius) {void-TriggerAddJoystickTapEventTypedCallback-trigger-int-joystickId-float-validDuration-float-validRadius}
void TriggerAddJoystickTapEvent(TypedCallback trigger, int joystickId, float validDuration, float validRadius)
This event triggers when a joystick is tapped.
-
object
trigger
the trigger to run when this event occurs. -
int
joystickId
the ID of the joystick to register the event for. -
float
validDuration
the time window where interacting with the joystick will register as a tap. This is also the time window before the joystick will accept input regularly. If the joystick tap location exits the deadzone given in the next parameter, this duration will immediately end. -
float
validRadius
the deadzone where interacting with the joystick will register as a tap. Accepted values are from 0-1, corresponding to the radius of the joystick (measured from the center). Tapping the joystick outside this deadzone will not trigger the event.
function OnJoystickTap()
DCEI.LogMessage("Joystick Tapped: " .. DCEI.TriggeringJoystickId)
end
DCEI.TriggerAddJoystickEventWithJoystickOptions(OnJoystickMove, joystickOptions)
DCEI.TriggerAddJoystickTapEvent(OnJoystickTap, 0, 0.25, 0.5)
void TriggerAddJoystickSwipeEvent(TypedCallback trigger, int joystickId, float validDuration) {void-TriggerAddJoystickSwipeEventTypedCallback-trigger-int-joystickId-float-validDuration}
void TriggerAddJoystickSwipeEvent(TypedCallback trigger, int joystickId, float validDuration)
This event triggers when a joystick is swiped.
-
object
trigger
the trigger to run when this event occurs. -
int
joystickId
the ID of the joystick to register the event for. -
float
validDuration
the time window where interacting with the joystick will register as a swipe. This time window starts counting when the joystick is interacted with, even if it is within the deadzone of a TriggerAddJoystickTapEvent().
function OnJoystickTap()
DCEI.LogMessage("Joystick Tapped: " .. DCEI.TriggeringJoystickId)
end
DCEI.TriggerAddJoystickEventWithJoystickOptions(OnJoystickMove, joystickOptions)
DCEI.TriggerAddJoystickSwipeEvent(OnJoystickSwipe, 0, 1)
void TriggerAddJoystickReleaseEvent(TypedCallback trigger) {void-TriggerAddJoystickReleaseEventTypedCallback-trigger}
void TriggerAddJoystickReleaseEvent(TypedCallback trigger)
This event triggers when a joystick is released.
function OnJoystickRelease()
DCEI.LogMessage("Joystick Released: " .. DCEI.TriggeringJoystickId)
end
DCEI.TriggerAddJoystickReleaseEvent(OnJoystickRelease)
void TriggerAddJoystickReleaseEventWithId(TypedCallback trigger, int joystickId) {void-TriggerAddJoystickReleaseEventWithIdTypedCallback-trigger-int-joystickId}
void TriggerAddJoystickReleaseEventWithId(TypedCallback trigger, int joystickId)
This event triggers when the given joystick is released.
-
object
trigger
the trigger to run when this event occurs. -
int
joystickId
the ID of the joystick to register the event for.
DCEI.TriggerAddJoystickReleaseEventWithId(OnJoystickRelease, 0)
function OnJoystickRelease()
DCEI.LogMessage("Joystick Released: " .. DCEI.TriggeringJoystickId)
end
void TriggerAddTextCommandEvent(TypedCallback<string> trigger) {void-TriggerAddTextCommandEventTypedCallbackstring-trigger}
void TriggerAddTextCommandEvent(TypedCallback<string> trigger)
This event triggers when a text command is entered.
-
object
trigger
the callback function for the chat command. Parametertext_command
is the text command entered.
-
String
command
DCEI.TriggerAddTextCommandEvent(OnTextCommand)
function OnTextCommand(text_command)
DCEI.ShowFeedbackMessage(text_command)
end
void TriggerAddJoystickButtonEvent(int buttonId, TypedCallback trigger, JoystickButtonOptions options) {void-TriggerAddJoystickButtonEventint-buttonId-TypedCallback-trigger-JoystickButtonOptions-options}
void TriggerAddJoystickButtonEvent(int buttonId, TypedCallback trigger, JoystickButtonOptions options)
Creates an on-screen button corresponding to the given buttonId.
-
int
buttonId
which joystick button index to use. Accepted values:[0, 3]
(see below). -
function
trigger
the callback function for when the joystick button is used. -
table
options
accepted values:-
string
icon
the icon to use for the joystick button. -
bool
hide
if true, hides the joystick button.
-
string
Button Ids
-------------------
| |
| (3) |
| (2) |
| (1) (0) |
|-----------------|
function OnJoystickButton()
local button_id = DCEI.TriggeringJoystickButtonId
local button_event = DCEI.TriggeringJoystickButtonEventType
-- button event 0 is for ButtonDown, event 1 is for ButtonUp
if button_id == 0 and button_event == 0 then
-- currently does not support targeted abilities
-- movement commands will interrupt ability prep time / finish time, unless ability has "can cast while moving" flag checked
DCEI.CastAbility(HERO_SLASH, HERO, HERO)
end
end
DCEI.TriggerAddJoystickButtonEvent(0, OnJoystickButton, {icon = "icon_ingame_towerslot_barracks"})
void TriggerAddMappedKeyDownEvent(string keyEventName, TypedCallback<string> trigger) {void-TriggerAddMappedKeyDownEventstring-keyEventName-TypedCallbackstring-trigger}
void TriggerAddMappedKeyDownEvent(string keyEventName, TypedCallback<string> trigger)
This event triggers when the corresponding key is pressed. Key mappings are defined in input settings.
-
string
keyEventName
the mapped key event that will trigger this event. -
function
trigger
the trigger to run when this event occurs.
-
String
key event name
function OnPressKeyShoot()
-- shoot a projectile
end
-- for a key mapped to the name "Shoot"
DCEI.TriggerAddMappedKeyDownEvent("Shoot", OnPressKeyShoot)
void TriggerAddMappedKeyUpEvent(string keyEventName, TypedCallback<string> trigger) {void-TriggerAddMappedKeyUpEventstring-keyEventName-TypedCallbackstring-trigger}
void TriggerAddMappedKeyUpEvent(string keyEventName, TypedCallback<string> trigger)
This event triggers when the corresponding key is released. Key mappings are defined in input settings.
-
string
keyEventName
the mapped key event that will trigger this event. -
function
trigger
the trigger to run when this event occurs.
-
String
key event name
function OnReleaseKeyShoot()
-- shoot a projectile
end
-- for a key mapped to the name "Shoot"
DCEI.TriggerAddMappedKeyUpEvent("Shoot", OnReleaseKeyShoot)
void TriggerAddOnMouseTrackingEvent(TypedCallback<int, Float2> trigger) {void-TriggerAddOnMouseTrackingEventTypedCallbackint-Float2-trigger}
void TriggerAddOnMouseTrackingEvent(TypedCallback<int, Float2> trigger)
Tracks mouse position every frame when StartMouseTracking is called. StopMouseTracking will end it.
-
Int32
player_id
-
Float2
mouse_position
function OnMouseTracking(player_id, mouse_position)
local current_mouse_position = mouse_position --current mouse position
end
TriggerAddOnMouseTrackingEvent(OnMouseTracking)
void StartMouseTracking(int playerId)
Start tracking mouse. Notice this is very costy especially in multiplayer mode. So only use it for short time (follow mouse laser for example)
void StopMouseTracking(int playerId)
Stop mouse tracking for certain player.
void SetBackButton(TypedCallback callback)
This event triggers when the back button on mobile devices is used.
function OnBackButton()
DCEI.LogMessage("Back Button pressed.")
end
DCEI.SetBackButton(OnBackButton)
void SetOnDownCallback(Transform ui, object callback) {void-SetOnDownCallbackTransform-ui-object-callback}
void SetOnDownCallback(Transform ui, object callback)
This event triggers when the given button is pressed down. This can feel more responsive than DCEI.SetOnUpCallback().
-
Transform
ui
the button that triggers the event. -
object
callback
the callback function that is called when the event is triggered.
local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnDownCallback(
button,
function()
DCEI.LogMessage("Button is pressed down")
end
)
void SetOnUpCallback(Transform ui, object callback) {void-SetOnUpCallbackTransform-ui-object-callback}
void SetOnUpCallback(Transform ui, object callback)
This event triggers when the given button press is released. This is functionally similar to DCEI.SetOnClickCallback() but the event will fire regardless of input position when the button is released.
This can be combined with DCEI.SetOnDownCallback to make something happen when a button is held down.
-
Transform
ui
the button that triggers the event. -
object
callback
the callback function that is called when the event is triggered.
local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnUpCallback(
button,
function()
DCEI.LogMessage("Button is released")
end
)
void SetOnClickCallback(Transform ui, object callback) {void-SetOnClickCallbackTransform-ui-object-callback}
void SetOnClickCallback(Transform ui, object callback)
This event triggers when the specified UI button frame is clicked. This is functionally similar to DCEI.SetOnUpCallback() with one key difference--this event will only fire if the input position is still over the button when released.
-
Transform
ui
the button that triggers the event. -
object
callback
the callback function that is called when the event is triggered.
local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnClickCallback(
button,
function()
DCEI.LogMessage("Button is clicked")
end
)
void SetPauseMenuCallback(TypedCallback<bool> callback) {void-SetPauseMenuCallbackTypedCallbackbool-callback}
void SetPauseMenuCallback(TypedCallback<bool> callback)
This event is triggered when a custom pause menu is opened or closed. Setting this callback will overwrite the default pause menu functionality of stopping game time, so you will need to re-add that in your own implementation if desired.
-- create a custom pause menu
local menu = DCEI.NewFrame(DCEI.GetUiRoot())
DCEI.SetSize(menu, 400, 600)
DCEI.SetBackgroundImage(menu, "frame01_purple")
DCEI.SetPauseMenu(menu)
-- the pause menu is inactive by default but we can update it safely with UpdateUi
DCEI.UpdateUi(
menu,
function()
local resume_button = DCEI.NewButton(menu)
DCEI.SetSize(resume_button, 200, 100)
DCEI.SetOnClickCallback(
resume_button,
function()
DCEI.HidePauseMenu(menu)
end
)
end
)
-- create a custom pause menu button
local pause_button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetBackgroundImage(pause_button, "btn_red")
DCEI.SetTopAlignmentInParent(pause_button)
DCEI.SetLeftAlignmentInParent(pause_button)
DCEI.SetSize(pause_button, 200, 200)
-- hookup the pause menu button callback
DCEI.SetOnClickCallback(
pause_button,
function()
DCEI.ShowPauseMenu(menu)
end
)
-- add custom pause menu callback
DCEI.SetPauseMenuCallback(
function(pause)
if pause then
core.SetGameSpeed(0)
else
core.SetGameSpeed(1)
end
end
)