Trigger API Reference\DCEI Events\Input

void TriggerAddMouseDownEvent(int mouseButtonId, TypedCallback<Float2, 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

Callback Parameters

Example Usage

DCEI.TriggerAddMouseDownEvent(0, OnMouseDown)

function OnMouseDown(cursor_pos)
    DCEI.LogMessage("LMB Down")
end

void TriggerAddMouseUpEvent(int mouseButtonId, TypedCallback<Float2, 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

Callback Parameters

Example Usage

DCEI.TriggerAddMouseUpEvent(1, OnMouseUp)

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

void TriggerAddSwipeTouchDownEvent(TypedCallback<Float2> 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

Callback Parameters

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

Callback Parameters

Example Usage

DCEI.TriggerAddSwipeTouchUpEvent(function(point)
  DCEI.LogMessage("Swipe up happens on screen point: " .. point.x .. ", " .. point.y)
end)

int RegisterControllerMap(int playerId, int categoryId, int layoutId, ControllerMapEntry controllerMap)

int RegisterControllerMap(int playerId, int categoryId, int layoutId, ControllerMapEntry controllerMap)

Description


This API is under development and may change without notice.

Parameters

Example Usage


This API is under development and may change without notice.

void RegisterControllerMapMode(string tag, int categoryId1, int layoutId1, int categoryId2 = -1, int layoutId2 = -1, int categoryId3 = -1, int layoutId3 = -1)

void RegisterControllerMapMode(string tag, int categoryId1, int layoutId1, int categoryId2 = -1, int layoutId2 = -1, int categoryId3 = -1, int layoutId3 = -1)

Description


This API is under development and may change without notice.

Parameters

Example Usage


This API is under development and may change without notice.

void ActivateControllerMapMode(string tag)

void ActivateControllerMapMode(string tag)

Description


This API is under development and may change without notice.

Parameters

Example Usage


This API is under development and may change without notice.

void SetUiNavigationExplicit(InGameUILayoutComponent ui, InGameUILayoutComponent up, InGameUILayoutComponent down, InGameUILayoutComponent left, InGameUILayoutComponent right)

void SetUiNavigationExplicit(InGameUILayoutComponent ui, InGameUILayoutComponent up, InGameUILayoutComponent down, InGameUILayoutComponent left, InGameUILayoutComponent right)

Description

Parameters

Example Usage

void SetUiControllerInputActionTrigger(InGameUILayoutComponent ui, int actionId)

void SetUiControllerInputActionTrigger(InGameUILayoutComponent ui, int actionId)

Description

Parameters

Example Usage

void TriggerAddInputActionEvent(TypedCallback trigger, int actionId)

void TriggerAddInputActionEvent(TypedCallback trigger, int actionId)

Description


This API is under development and may change without notice.

Parameters

Example Usage


This API is under development and may change without notice.

void TriggerAddTouchDownEvent(TypedCallback<Float2, 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

Callback Parameters

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

Callback Parameters

Example Usage

DCEI.TriggerAddTouchUpEvent(function(point)
  DCEI.LogMessage("Touch up happens on screen point: " .. point.x .. ", " .. point.y)
end)

void TriggerAddJoystickEvent(TypedCallback trigger)

void TriggerAddJoystickEvent(TypedCallback trigger)

Description


Creates an on-screen joystick and that triggers this event when moved. Uses default JoystickOptions.

Parameters

Example Usage

function OnJoystickMove()
    local axes = DCEI.TriggeringJoystickAxes
    DCEI.DirectionalMove(unit, axes.x, axes.y)
end

DCEI.TriggerAddJoystickEvent(OnJoystickMove)

void TriggerAddJoystickEventWithJoystickOptions(TypedCallback 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

Example Usage

local unit = DCEI.CreateUnit(1, 1, "Standard MeleeUnit", 15, 15)

local function OnJoystickMove()
    local axes = DCEI.TriggeringJoystickAxes
    DCEI.DirectionalMove(unit, axes.x, axes.y)
end

local function CreateJoystick()
    local frame = DCEI.CreateFrame(DCEI.GetUiRootFrame())

    DCEI.SetFrameWidth(frame, 1500)
    DCEI.SetFrameHeight(frame, 1500)

    local joystick_options = {
        anchor = { x = 0, y = 0 },
        offset = { x = 0, y = 0 },
        disable_wasd = true,
        disable_arrow_keys = true,
        joystick_id = 1,
        dynamic_position = true,
        always_show = true,
        radius = 150,
        active_area_offset = {
            left = 500,
            right = 50,
            top = 500,
            bottom = 50,
            debug_draw_color = { r = 0, g = 1, b = 0, a = 0.5 },
        },
        handle_icon = DCEI.Texture("icon_arrow"),
        handle_icon_color = { r = 1, g = 0, b = 0, a = 0.5 },
        background_icon = DCEI.Texture("general_icon_wildsky_mall_light_circle"),
        background_icon_color = { r = 1, g = 0, b = 0, a = 0.5 },
        handle_rotation = true,
        parent = frame,
    }

    DCEI.TriggerAddJoystickEventWithJoystickOptions(OnJoystickMove, joystick_options)
end

CreateJoystick()

void TriggerAddJoystickTapEvent(TypedCallback 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

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 TriggerAddJoystickSwipeEvent(TypedCallback trigger, int joystickId, float validDuration)

Description


This event triggers when a joystick is swiped.

Parameters

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 TriggerAddJoystickReleaseEvent(TypedCallback trigger)

Description


This event triggers when a joystick is released.

Parameters

Example Usage

function OnJoystickRelease()
    DCEI.LogMessage("Joystick Released: " .. DCEI.TriggeringJoystickId)
end
DCEI.TriggerAddJoystickReleaseEvent(OnJoystickRelease)

void TriggerAddJoystickReleaseEventWithId(TypedCallback trigger, int joystickId)

void TriggerAddJoystickReleaseEventWithId(TypedCallback trigger, int joystickId)

Description


This event triggers when the given joystick is released.

Parameters

Example Usage

DCEI.TriggerAddJoystickReleaseEventWithId(OnJoystickRelease, 0)

function OnJoystickRelease()
    DCEI.LogMessage("Joystick Released: " .. DCEI.TriggeringJoystickId)
end

void TriggerAddTextCommandEvent(TypedCallback<string> trigger)

void TriggerAddTextCommandEvent(TypedCallback<string> trigger)

Description


This event triggers when a text command is entered.

Parameters

Callback Parameters

Example Usage

DCEI.TriggerAddTextCommandEvent(OnTextCommand)

function OnTextCommand(text_command)
    DCEI.ShowFeedbackMessage(text_command)
end

void TriggerAddMappedKeyDownEvent(string keyEventName, TypedCallback<string> 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

Callback Parameters

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 TriggerAddMappedKeyUpEvent(string keyEventName, TypedCallback<string> trigger)

Description


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

Parameters

Callback Parameters

Example Usage

function OnReleaseKeyShoot()
  -- shoot a projectile
end

-- for a key mapped to the name "Shoot"
DCEI.TriggerAddMappedKeyUpEvent("Shoot", OnReleaseKeyShoot)

TriggerHandle TriggerAddOnMouseWorldPositionTrackingEvent(TypedCallback<int, Float2> trigger)

TriggerHandle TriggerAddOnMouseWorldPositionTrackingEvent(TypedCallback<int, Float2> trigger)

Description


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

Parameters

Callback Parameters

Example Usage

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

void StartMouseTracking(int 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

Example Usage

DCEI.StartMouseTracking(1)
DCEI.TriggerAddOnMouseTrackingEvent(MouseTrack)

function MouseTrack(player_id, position)
    if game.mouse_down then
        game.player_mouse_pos = position or DCEI.GetMousePosition2D()
    end
end

void StopMouseTracking(int playerId)

void StopMouseTracking(int playerId)

Description


Stop mouse tracking for certain player.

Parameters

Example Usage

DCEI.StartMouseTracking(1)
DCEI.TriggerAddOnMouseTrackingEvent(MouseTrack)

function MouseTrack(player_id, position)
    if game.mouse_down then
        game.player_mouse_pos = position or DCEI.GetMousePosition2D()
    end
end

DCEI.Wait(10)

DCEI.StopMouseTracking(1)

void SetBackButton(TypedCallback callback)

void SetBackButton(TypedCallback callback)

Description


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

Parameters

Example Usage

function OnBackButton()
    DCEI.LogMessage("Back Button pressed.")
end

DCEI.SetBackButton(OnBackButton)

void SetOnMouseEnterCallback(InGameUILayoutComponent ui, TypedCallback trigger)

void SetOnMouseEnterCallback(InGameUILayoutComponent ui, TypedCallback trigger)

Description


Register a callback to occur when the player's mouse hovers over a UI frame.

Parameters

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnMouseEnterCallback(button, function()
    DCEI.LogMessage("Mouse has entered button")
end)

void SetOnMouseExitCallback(InGameUILayoutComponent ui, TypedCallback trigger)

void SetOnMouseExitCallback(InGameUILayoutComponent ui, TypedCallback trigger)

Description


Register a callback to occur when the player's mouse leaves a UI frame.

Parameters

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnMouseExitCallback(button, function()
    DCEI.LogMessage("Mouse has left button")
end)

void SetOnDownCallback(InGameUILayoutComponent ui, object callback)

void SetOnDownCallback(InGameUILayoutComponent ui, object callback)

Description


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

Parameters

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnDownCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is pressed down")
    end
)

void SetOnUpCallback(InGameUILayoutComponent ui, object callback)

void SetOnUpCallback(InGameUILayoutComponent ui, object callback)

Description


This event triggers when the given button press is released. This is functionally similar to SetOnClickCallback but the event will fire regardless of input position when the button is released.

This can be combined with SetOnDownCallback to make something happen when a button is held down.

Parameters

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnUpCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is released")
    end
)

void SetOnClickCallback(InGameUILayoutComponent ui, object callback)

void SetOnClickCallback(InGameUILayoutComponent 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

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnClickCallback(
    button, 
    function()    
        DCEI.LogMessage("Button is clicked")
    end
)

void SetTextLinkOnClickCallback(InGameUILayoutComponent ui, string linkId, object callback)

void SetTextLinkOnClickCallback(InGameUILayoutComponent ui, string linkId, object callback)

Description

Parameters

Example Usage

void SetOnClickOutsideCallback(InGameUILayoutComponent ui, object callback)

void SetOnClickOutsideCallback(InGameUILayoutComponent ui, object callback)

Description


Registers a callback to run when a click/touch happens outside of the specified UI frame while the frame is active. Unlike DCEI.SetOnClickCallback(), this API works on any frame type. You can enable "Custom UI Inspector" in the in-game dev panel to check what UI frames are under the current mouse position to better understand what's considered outside of a frame by the engine.

Parameters

Example Usage

local button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(button, 100, 100)
DCEI.SetOnClickOutsideCallback(
    button, 
    function()    
        DCEI.LogMessage("Somewhere besides the button has been clicked")
    end
)

void SetPauseMenuCallback(TypedCallback<bool> 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

Callback Parameters

Example Usage

-- create a custom pause menu
local menu = DCEI.CreateFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameSize(menu, 400, 600)
DCEI.SetFrameImage(menu, DCEI.Texture("frame01_purple"))
DCEI.SetPauseMenuFrame(menu)

-- the pause menu is inactive by default but we can update it safely with UpdateFrame
DCEI.UpdateFrame(
    menu,
    function()
        local resume_button = DCEI.CreateButtonFrame(menu)
        DCEI.SetFrameSize(resume_button, 200, 100)
        DCEI.SetOnClickCallback(
            resume_button, 
            function()
                DCEI.HidePauseMenuFrame(menu)
            end
        )
    end
)

-- create a custom pause menu button
local pause_button = DCEI.CreateButtonFrame(DCEI.GetUiRootFrame())
DCEI.SetFrameImage(pause_button, DCEI.Texture("btn_red"))
DCEI.SetFrameTopAlignmentInParent(pause_button)
DCEI.SetFrameLeftAlignmentInParent(pause_button)
DCEI.SetFrameSize(pause_button, 200, 200)

-- hookup the pause menu button callback
DCEI.SetOnClickCallback(
    pause_button,
    function()
        DCEI.ShowPauseMenuFrame(menu)
    end
)

-- add custom pause menu callback
DCEI.SetPauseMenuCallback(
    function(pause)
        if pause then
            Core.GameSpeed.Set(0)
        else
            Core.GameSpeed.Set(1)
        end
    end
)