Trigger API Reference DCEI Events Input0 - BLKTower/TestWiki GitHub Wiki

Table of Contents

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)

Description

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.

Parameters

  • 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.

Callback Parameters

  • Float2 position
  • Unit target_unit

Example Usage

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)

Description

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().

Parameters

  • 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.

Callback Parameters

  • Float2 position
  • Unit target_unit

Example Usage

DCEI.TriggerAddMouseUpEvent(1, OnMouseUp)

function OnMouseUp()
    DCEI.LogMessage("RMB Up")
end

void TriggerAddSwipeTouchDownEvent(TypedCallback<Float2> trigger) {void-TriggerAddSwipeTouchDownEventTypedCallbackFloat2-trigger}

void TriggerAddSwipeTouchDownEvent(TypedCallback<Float2> trigger)

Description

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.

Parameters

  • function trigger the trigger to run when this event occurs. Parameter point denotes the point in screenspace (not worldspace), where the Swipe input was started.

Callback Parameters

  • Float2 position

Example Usage

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)

Description

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.

Parameters

  • function trigger the trigger to run when this event occurs. Parameter point denotes the point in screenspace (not worldspace), where the Swipe input has ended.

Callback Parameters

  • Float2 position

Example Usage

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)

Description

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.

Parameters

  • function trigger the trigger to run when this event occurs. Parameter point denotes the point in screenspace (not worldspace), where the Touch input occurred.

Callback Parameters

  • Float2 position
  • Unit target_unit

Example Usage

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)

Description

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.

Parameters

  • function trigger the trigger to run when this event occurs. Parameter point denotes the point in screenspace (not worldspace), where the Touch input occurred.

Callback Parameters

  • Float2 position
  • Unit target_unit

Example Usage

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)

Description

Parameters

Example Usage

void TriggerAddJoystickEventWithJoystickOptions(TypedCallback trigger, JoystickOptions options) {void-TriggerAddJoystickEventWithJoystickOptionsTypedCallback-trigger-JoystickOptions-options}

void TriggerAddJoystickEventWithJoystickOptions(TypedCallback trigger, JoystickOptions options)

Description

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.

Parameters

  • object trigger the trigger to run when this event occurs.

Example Usage

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)

Description

This event triggers when a joystick is tapped.

Parameters

  • 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.

Example Usage

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)

Description

This event triggers when a joystick is swiped.

Parameters

  • 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().

Example Usage

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)

Description

This event triggers when a joystick is released.

Parameters

  • object trigger the trigger to run when this event occurs.

Example Usage

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)

Description

This event triggers when the given joystick is released.

Parameters

  • object trigger the trigger to run when this event occurs.
  • int joystickId the ID of the joystick to register the event for.

Example Usage

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)

Description

This event triggers when a text command is entered.

Parameters

  • object trigger the callback function for the chat command. Parameter text_command is the text command entered.

Callback Parameters

  • String command

Example Usage

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)

Description

Creates an on-screen button corresponding to the given buttonId.

Parameters

  • 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.
Button Ids
-------------------
|                 |
|             (3) |
|          (2)    |
|       (1)   (0) |
|-----------------|

Example Usage

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)

Description

This event triggers when the corresponding key is pressed. Key mappings are defined in input settings.

Parameters

  • string keyEventName the mapped key event that will trigger this event.
  • function trigger the trigger to run when this event occurs.

Callback Parameters

  • String key event name

Example Usage

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)

Description

This event triggers when the corresponding key is released. Key mappings are defined in input settings.

Parameters

  • string keyEventName the mapped key event that will trigger this event.
  • function trigger the trigger to run when this event occurs.

Callback Parameters

  • String key event name

Example Usage

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)

Description

Tracks mouse position every frame when StartMouseTracking is called. StopMouseTracking will end it.

Parameters

Callback Parameters

  • Int32 player_id
  • Float2 mouse_position

Example Usage

function OnMouseTracking(player_id, mouse_position)
    local current_mouse_position = mouse_position --current mouse position
end
TriggerAddOnMouseTrackingEvent(OnMouseTracking)

void StartMouseTracking(int playerId) {void-StartMouseTrackingint-playerId}

void StartMouseTracking(int playerId)

Description

Start tracking mouse. Notice this is very costy especially in multiplayer mode. So only use it for short time (follow mouse laser for example)

Parameters

  • Int32 player_id

Example Usage

void StopMouseTracking(int playerId) {void-StopMouseTrackingint-playerId}

void StopMouseTracking(int playerId)

Description

Stop mouse tracking for certain player.

Parameters

  • Int32 player_id

Example Usage

void SetBackButton(TypedCallback callback) {void-SetBackButtonTypedCallback-callback}

void SetBackButton(TypedCallback callback)

Description

This event triggers when the back button on mobile devices is used.

Parameters

  • object trigger the trigger to run when this event occurs.

Example Usage

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)

Description

This event triggers when the given button is pressed down. This can feel more responsive than DCEI.SetOnUpCallback().

Parameters

  • Transform ui the button that triggers the event.
  • object callback the callback function that is called when the event is triggered.

Example Usage

local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnDownCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is pressed down")
    end
)

Related

void SetOnUpCallback(Transform ui, object callback) {void-SetOnUpCallbackTransform-ui-object-callback}

void SetOnUpCallback(Transform ui, object callback)

Description

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.

Parameters

  • Transform ui the button that triggers the event.
  • object callback the callback function that is called when the event is triggered.

Example Usage

local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnUpCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is released")
    end
)

Related

void SetOnClickCallback(Transform ui, object callback) {void-SetOnClickCallbackTransform-ui-object-callback}

void SetOnClickCallback(Transform ui, object callback)

Description

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.

Parameters

  • Transform ui the button that triggers the event.
  • object callback the callback function that is called when the event is triggered.

Example Usage

local button = DCEI.NewButton(DCEI.GetUiRoot())
DCEI.SetSize(button, 100, 100)
DCEI.SetOnClickCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is clicked")
    end
)

Related

void SetPauseMenuCallback(TypedCallback<bool> callback) {void-SetPauseMenuCallbackTypedCallbackbool-callback}

void SetPauseMenuCallback(TypedCallback<bool> callback)

Description

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.

Parameters

  • object callback the callback function that is called when the pause menu is opened or closed.

Example Usage

-- 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
)

Related

⚠️ **GitHub.com Fallback** ⚠️