Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,99 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ButtonAnimation =
{
Properties =
{
IdleAnimName = {default = ""},
HoverAnimName = {default = ""},
ExitAnimName = {default = ""},
Button = {default = EntityId()},
},
Exiting = false,
}
function ButtonAnimation:OnActivate()
self.interactableHandler = UiInteractableNotificationBus.Connect(self, self.Properties.Button)
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.Properties.Button)
self.tickBusHandler = TickBus.Connect(self)
self.hovering = false
end
function ButtonAnimation:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
self.animHandler = UiAnimationNotificationBus.Connect(self, self.canvas)
-- Start the button sequence
if (self.hovering) then
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.HoverAnimName)
else
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.IdleAnimName)
end
end
function ButtonAnimation:OnDeactivate()
self.interactableHandler:Disconnect()
self.buttonHandler:Disconnect()
self.animHandler:Disconnect()
end
function ButtonAnimation:OnHoverStart()
self.hovering = true
if (self.Exiting == false and self.canvas ~= nil) then
UiAnimationBus.Event.StopSequence(self.canvas, self.Properties.IdleAnimName)
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.HoverAnimName)
end
end
function ButtonAnimation:OnHoverEnd()
self.hovering = false
if (self.Exiting == false and self.canvas ~= nil) then
UiAnimationBus.Event.StopSequence(self.canvas, self.Properties.HoverAnimName)
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.IdleAnimName)
end
end
function ButtonAnimation:OnButtonClick()
if (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.Button) then
UiAnimationBus.Event.StopSequence(self.canvas, self.Properties.HoverAnimName)
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.ExitAnimName)
self.Exiting = true
end
end
function ButtonAnimation:OnUiAnimationEvent(eventType, sequenceName)
if (eventType == eUiAnimationEvent_Stopped) then
if (sequenceName == self.Properties.ExitAnimName) then
UiAnimationBus.Event.ResetSequence(self.canvas, self.Properties.ExitAnimName)
if (self.hovering) then
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.HoverAnimName)
else
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.IdleAnimName)
end
self.Exiting = false
end
end
end
return ButtonAnimation
@@ -0,0 +1,42 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MultipleSequences =
{
Properties =
{
},
}
function MultipleSequences:OnActivate()
self.tickBusHandler = TickBus.Connect(self);
end
function MultipleSequences:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiAnimationBus.Event.StartSequence(canvas, "Progress")
UiAnimationBus.Event.StartSequence(canvas, "Pulse")
UiAnimationBus.Event.StartSequence(canvas, "Progress2")
UiAnimationBus.Event.StartSequence(canvas, "Pulse2")
end
function MultipleSequences:OnDeactivate()
end
return MultipleSequences
@@ -0,0 +1,143 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SequenceStates =
{
Properties =
{
SequenceName = {default = ""},
StateText = {default = EntityId()},
StartButton = {default = EntityId()},
PauseButton = {default = EntityId()},
ResumeButton = {default = EntityId()},
StopButton = {default = EntityId()},
AbortButton = {default = EntityId()},
ResetButton = {default = EntityId()},
},
}
function SequenceStates:OnActivate()
self.tickBusHandler = TickBus.Connect(self);
end
function SequenceStates:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, self.canvas)
self.animHandler = UiAnimationNotificationBus.Connect(self, self.canvas)
-- Initialize button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, false)
end
function SequenceStates:OnDeactivate()
self.canvasNotificationBusHandler:Disconnect()
self.animHandler:Disconnect()
end
function SequenceStates:OnAction(entityId, actionName)
if actionName == "StartPressed" then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, false)
-- Start sequence
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.SequenceName)
elseif actionName == "PausePressed" then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, false)
-- Pause sequence
UiAnimationBus.Event.PauseSequence(self.canvas, self.Properties.SequenceName)
elseif actionName == "ResumePressed" then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, false)
-- Resume sequence
UiAnimationBus.Event.ResumeSequence(self.canvas, self.Properties.SequenceName)
elseif actionName == "StopPressed" then
-- Stop sequence. Button states are updated in the animation handler
UiAnimationBus.Event.StopSequence(self.canvas, self.Properties.SequenceName)
elseif actionName == "AbortPressed" then
-- Abort sequence. Buttons states are updated in the animation handler
UiAnimationBus.Event.AbortSequence(self.canvas, self.Properties.SequenceName)
elseif actionName == "ResetPressed" then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, false)
-- Reset sequence
UiAnimationBus.Event.ResetSequence(self.canvas, self.Properties.SequenceName)
end
end
function SequenceStates:OnUiAnimationEvent(eventType, sequenceName)
if (eventType == eUiAnimationEvent_Started) then
-- Update state text
UiTextBus.Event.SetText(self.Properties.StateText, "Sequence Started")
elseif (eventType == eUiAnimationEvent_Stopped) then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, true)
-- Update state text
UiTextBus.Event.SetText(self.Properties.StateText, "Sequence Stopped")
elseif (eventType == eUiAnimationEvent_Aborted) then
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.PauseButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResumeButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AbortButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ResetButton, true)
-- Update state text
UiTextBus.Event.SetText(self.Properties.StateText, "Sequence Aborted")
elseif (eventType == eUiAnimationEvent_Updated) then
-- Update state text
UiTextBus.Event.SetText(self.Properties.StateText, "Sequence Playing")
end
end
return SequenceStates
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local LoadCppCanvas =
{
Properties =
{
},
}
function LoadCppCanvas:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function LoadCppCanvas:OnButtonClick()
LyShineExamplesCppExampleBus.Broadcast.CreateCanvas()
end
function LoadCppCanvas:OnDeactivate()
self.buttonHandler:Disconnect()
LyShineExamplesCppExampleBus.Broadcast.DestroyCanvas()
end
return LoadCppCanvas
@@ -0,0 +1,32 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DisplayMouseCursor =
{
Properties =
{
},
}
function DisplayMouseCursor:OnActivate()
-- Display the mouse cursor
LyShineLua.ShowMouseCursor(true)
end
function DisplayMouseCursor:OnDeactivate()
-- Hide the mouse cursor
LyShineLua.ShowMouseCursor(false)
end
return DisplayMouseCursor
@@ -0,0 +1,46 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DropTargetLayoutDraggableChild =
{
Properties =
{
},
}
function DropTargetLayoutDraggableChild:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function DropTargetLayoutDraggableChild:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function DropTargetLayoutDraggableChild:OnDropHoverStart(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
end
function DropTargetLayoutDraggableChild:OnDropHoverEnd(draggable)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
end
function DropTargetLayoutDraggableChild:OnDrop(draggable)
local parentDraggable = UiElementBus.Event.GetParent(self.entityId)
local parentLayout = UiElementBus.Event.GetParent(parentDraggable)
UiElementBus.Event.Reparent(draggable, parentLayout, parentDraggable)
end
return DropTargetLayoutDraggableChild
@@ -0,0 +1,61 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ChildDropTargets_Draggable =
{
Properties =
{
DragParent = {default = EntityId()},
},
}
function ChildDropTargets_Draggable:OnActivate()
self.draggableHandler = UiDraggableNotificationBus.Connect(self, self.entityId)
end
function ChildDropTargets_Draggable:OnDeactivate()
self.draggableHandler:Disconnect()
end
function ChildDropTargets_Draggable:OnDragStart(position)
self.originalPosition = UiTransformBus.Event.GetCanvasPosition(self.entityId)
self.originalParent = UiElementBus.Event.GetParent(self.entityId)
local index = UiElementBus.Event.GetIndexOfChildByEntityId(self.originalParent, self.entityId)
self.originalBefore = EntityId()
if (UiElementBus.Event.GetNumChildElements(self.originalParent) > index+1) then
self.originalBefore = UiElementBus.Event.GetChild(self.originalParent, index+1)
end
UiElementBus.Event.Reparent(self.entityId, self.Properties.DragParent, EntityId())
-- after reparenting the other drop targets will have moved since we removed an element
-- from the layout. So force an immediate recompute of their positions and redo the drag
-- which will redo the search for drop targets at the given position. This is important
-- when using keyboard/gamepad.
local canvasEntityId = UiElementBus.Event.GetCanvas(self.entityId)
UiCanvasBus.Event.RecomputeChangedLayouts(canvasEntityId)
UiDraggableBus.Event.RedoDrag(self.entityId, position)
UiTransformBus.Event.SetCanvasPosition(self.entityId, position)
end
function ChildDropTargets_Draggable:OnDrag(position)
UiTransformBus.Event.SetCanvasPosition(self.entityId, position)
end
function ChildDropTargets_Draggable:OnDragEnd(position)
UiElementBus.Event.Reparent(self.entityId, self.originalParent, self.originalBefore)
UiTransformBus.Event.SetCanvasPosition(self.entityId, self.originalPosition)
end
return ChildDropTargets_Draggable
@@ -0,0 +1,46 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ChildDropTargets_EndDropTarget =
{
Properties =
{
},
}
function ChildDropTargets_EndDropTarget:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function ChildDropTargets_EndDropTarget:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function ChildDropTargets_EndDropTarget:OnDropHoverStart(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
end
function ChildDropTargets_EndDropTarget:OnDropHoverEnd(draggable)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
end
function ChildDropTargets_EndDropTarget:OnDrop(draggable)
local parentLayout = UiElementBus.Event.GetParent(self.entityId)
-- add before this end marker
UiElementBus.Event.Reparent(draggable, parentLayout, self.entityId)
end
return ChildDropTargets_EndDropTarget
@@ -0,0 +1,46 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ChildDropTargets_LayoutDropTarget =
{
Properties =
{
EndDropTarget = {default = EntityId()},
},
}
function ChildDropTargets_LayoutDropTarget:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function ChildDropTargets_LayoutDropTarget:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function ChildDropTargets_LayoutDropTarget:OnDropHoverStart(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
end
function ChildDropTargets_LayoutDropTarget:OnDropHoverEnd(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
end
function ChildDropTargets_LayoutDropTarget:OnDrop(draggable)
-- insert before the invisible end drop target
UiElementBus.Event.Reparent(draggable, self.entityId, self.Properties.EndDropTarget)
end
return ChildDropTargets_LayoutDropTarget
@@ -0,0 +1,116 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- DraggableCrossCanvasElement - script for a draggable element that can be dropped on drop targets
-- on other canvases.
--
-- This makes use of some of the more advanced feature of the UiDraggableBus, such as the proxy
-- features.
--
-- Note that the element with this script on will get cloned to make a proxy draggable element.
-- So this same script runs on both the original and the proxy.
----------------------------------------------------------------------------------------------------
local DraggableCrossCanvasElement =
{
Properties =
{
},
}
function DraggableCrossCanvasElement:OnActivate()
self.draggableHandler = UiDraggableNotificationBus.Connect(self, self.entityId)
self.dragCanvas = EntityId()
self.clonedElement = EntityId()
self.originalParent = EntityId()
end
function DraggableCrossCanvasElement:OnDeactivate()
self.draggableHandler:Disconnect()
end
function DraggableCrossCanvasElement:OnDragStart(position)
self.isProxy = UiDraggableBus.Event.IsProxy(self.entityId)
-- Since we want to support dropping on a drop target on any canvas we set this flag
-- we want both the original and the proxy to set this flag, we turn it off on the drag end
UiDraggableBus.Event.SetCanDropOnAnyCanvas(self.entityId, true)
if (not self.isProxy) then
-- this is the original, we need to make a new canvas in front of all the other canvases
-- to move the proxy on
-- If no changes have been made to canvas draw orders then the new canvas will draw in
-- front of everything else. Otherwise, we would have to set the draw order to a high
-- number here.
self.dragCanvas = UiCanvasManagerBus.Broadcast.CreateCanvas()
if (self.dragCanvas:IsValid()) then
-- clone the original draggable making it a child of the root element on the new canvas
self.clonedElement = UiCanvasBus.Event.CloneElement(self.dragCanvas, self.entityId, EntityId(), EntityId())
if (self.clonedElement:IsValid()) then
-- set the new cloned draggable element to act as a proxy for the original element
UiDraggableBus.Event.SetAsProxy(self.clonedElement, self.entityId, position)
-- hide the original element by reparenting it and disabling it so that we can drop
-- the proxy at the original location if we want to
self.originalParent = UiElementBus.Event.GetParent(self.entityId)
UiElementBus.Event.Reparent(self.entityId, EntityId(), EntityId())
UiElementBus.Event.SetIsEnabled(self.entityId, false)
end
end
else
-- This is the proxy, it gets an OnDragStart after SetAsProxy is called, at that point we
-- to move it to where the cursor is
UiTransformBus.Event.SetViewportPosition(self.entityId, position)
end
end
function DraggableCrossCanvasElement:OnDrag(position)
if (self.isProxy) then
-- we do not move the original during the drag - just the proxy
UiTransformBus.Event.SetViewportPosition(self.entityId, position)
end
end
function DraggableCrossCanvasElement:OnDragEnd(position)
if (self.isProxy) then
-- this is the proxy, it gets OnDragEnd before the original, calling
-- ProxyDragEnd will result in OnDragEnd being called on the original
UiDraggableBus.Event.ProxyDragEnd(self.entityId, position)
else
-- this is the original
if (self.dragCanvas:IsValid()) then
if (self.clonedElement:IsValid()) then
-- unhide the original and put it back under its original parent
UiElementBus.Event.SetIsEnabled(self.entityId, true)
UiElementBus.Event.Reparent(self.entityId, self.originalParent, EntityId())
-- clean up by destroying the proxy element and the temporary canvas
UiElementBus.Event.DestroyElement(self.clonedElement)
end
UiCanvasManagerBus.Broadcast.UnloadCanvas(self.dragCanvas)
end
end
-- turn off the "Drop on any canvas flag" just for good measure
UiDraggableBus.Event.SetCanDropOnAnyCanvas(self.entityId, false)
end
return DraggableCrossCanvasElement
@@ -0,0 +1,46 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DraggableElement =
{
Properties =
{
DragParent = {default = EntityId()},
},
}
function DraggableElement:OnActivate()
self.draggableHandler = UiDraggableNotificationBus.Connect(self, self.entityId)
end
function DraggableElement:OnDeactivate()
self.draggableHandler:Disconnect()
end
function DraggableElement:OnDragStart(position)
self.originalPosition = UiTransformBus.Event.GetViewportPosition(self.entityId)
self.originalParent = UiElementBus.Event.GetParent(self.entityId)
UiElementBus.Event.Reparent(self.entityId, self.Properties.DragParent, EntityId())
end
function DraggableElement:OnDrag(position)
UiTransformBus.Event.SetViewportPosition(self.entityId, position)
end
function DraggableElement:OnDragEnd(position)
UiElementBus.Event.Reparent(self.entityId, self.originalParent, EntityId())
UiTransformBus.Event.SetViewportPosition(self.entityId, self.originalPosition)
end
return DraggableElement
@@ -0,0 +1,78 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DraggableStackingElement =
{
Properties =
{
DragParent = {default = EntityId()},
},
}
function DraggableStackingElement:OnActivate()
self.draggableHandler = UiDraggableNotificationBus.Connect(self, self.entityId)
end
function DraggableStackingElement:OnDeactivate()
self.draggableHandler:Disconnect()
end
function DraggableStackingElement:OnDragStart(position)
local draggableImage = UiElementBus.Event.GetChild(self.entityId, 0)
self.draggableCounterBox = UiElementBus.Event.GetChild(draggableImage, 0)
self.draggableCounterText = UiElementBus.Event.GetChild(self.draggableCounterBox, 0)
local textString = UiTextBus.Event.GetText(self.draggableCounterText)
local inventoryCount = tonumber(textString)
self.originalPosition = UiTransformBus.Event.GetViewportPosition(self.entityId)
self.originalParent = UiElementBus.Event.GetParent(self.entityId)
if (inventoryCount > 1) then
self.canvasEntity = UiElementBus.Event.GetCanvas(self.entityId)
self.clonedElement = UiCanvasBus.Event.CloneElement(self.canvasEntity, self.entityId, self.originalParent, EntityId())
inventoryCount = inventoryCount - 1
local clonedImage = UiElementBus.Event.GetChild(self.clonedElement, 0)
local clonedCounterBox = UiElementBus.Event.GetChild(clonedImage, 0)
local clonedCounterText = UiElementBus.Event.GetChild(clonedCounterBox, 0)
UiTextBus.Event.SetText(clonedCounterText, inventoryCount)
else
self.clonedElement = nil
end
-- hide the count
UiElementBus.Event.SetIsEnabled(self.draggableCounterBox, false)
UiElementBus.Event.Reparent(self.entityId, self.Properties.DragParent, EntityId())
UiTransformBus.Event.SetViewportPosition(self.entityId, position)
end
function DraggableStackingElement:OnDrag(position)
UiTransformBus.Event.SetViewportPosition(self.entityId, position)
end
function DraggableStackingElement:OnDragEnd(position)
if (self.clonedElement) then
UiElementBus.Event.DestroyElement(self.clonedElement)
end
UiElementBus.Event.Reparent(self.entityId, self.originalParent, EntityId())
UiTransformBus.Event.SetViewportPosition(self.entityId, self.originalPosition)
-- show the count
UiElementBus.Event.SetIsEnabled(self.draggableCounterBox, true)
end
return DraggableStackingElement
@@ -0,0 +1,51 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DropTarget =
{
Properties =
{
},
}
function DropTarget:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function DropTarget:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function DropTarget:OnDropHoverStart(draggable)
if (UiElementBus.Event.GetNumChildElements(self.entityId) <= 0) then
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
else
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Invalid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Invalid)
end
end
function DropTarget:OnDropHoverEnd(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
end
function DropTarget:OnDrop(draggable)
if (UiElementBus.Event.GetNumChildElements(self.entityId) <= 0) then
UiElementBus.Event.Reparent(draggable, self.entityId, EntityId())
end
end
return DropTarget
@@ -0,0 +1,72 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- DropTargetCrossCanvas - script for a drop target element that can be dropped on from other
-- canvases. This script is designed to be used with DraggableCrossCanvasElement
----------------------------------------------------------------------------------------------------
local DropTargetCrossCanvas =
{
Properties =
{
},
}
function DropTargetCrossCanvas:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function DropTargetCrossCanvas:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function DropTargetCrossCanvas:OnDropHoverStart(draggable)
if (UiDraggableBus.Event.IsProxy(draggable)) then
if (UiElementBus.Event.GetNumChildElements(self.entityId) <= 0) then
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
else
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Invalid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Invalid)
end
end
end
function DropTargetCrossCanvas:OnDropHoverEnd(draggable)
if (UiDraggableBus.Event.IsProxy(draggable)) then
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
else
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
end
end
function DropTargetCrossCanvas:OnDrop(draggable)
if (not UiDraggableBus.Event.IsProxy(draggable)) then
if (UiElementBus.Event.GetNumChildElements(self.entityId) <= 0) then
local myCanvasEntity = UiElementBus.Event.GetCanvas(self.entityId)
local draggableCanvasEntity = UiElementBus.Event.GetCanvas(draggable)
if (myCanvasEntity == draggableCanvasEntity) then
UiElementBus.Event.Reparent(draggable, self.entityId, EntityId())
else
-- clone the draggable and remove it from its original canvas
UiCanvasBus.Event.CloneElement(myCanvasEntity, draggable, self.entityId, EntityId())
UiElementBus.Event.DestroyElement(draggable)
end
end
end
end
return DropTargetCrossCanvas
@@ -0,0 +1,129 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DropTargetStacking =
{
Properties =
{
},
}
function DropTargetStacking:IsValidDrop(draggable, dropTarget)
local sourceDraggableImage = UiElementBus.Event.GetChild(draggable, 0)
local sourceType = UiImageBus.Event.GetSpritePathname(sourceDraggableImage)
local destType = ""
if (UiElementBus.Event.GetNumChildElements(dropTarget) > 0) then
local destDraggable = UiElementBus.Event.GetChild(dropTarget, 0)
local destDraggableImage = UiElementBus.Event.GetChild(destDraggable, 0)
destType = UiImageBus.Event.GetSpritePathname(destDraggableImage)
end
if (destType == "" or sourceType == destType) then
return true
else
return false
end
end
function DropTargetStacking:OnActivate()
self.dropTargetHandler = UiDropTargetNotificationBus.Connect(self, self.entityId)
end
function DropTargetStacking:OnDeactivate()
self.dropTargetHandler:Disconnect()
end
function DropTargetStacking:OnDropHoverStart(draggable)
if (self:IsValidDrop(draggable, self.entityId)) then
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Valid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Valid)
else
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Invalid)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Invalid)
end
end
function DropTargetStacking:OnDropHoverEnd(draggable)
UiDraggableBus.Event.SetDragState(draggable, eUiDragState_Normal)
UiDropTargetBus.Event.SetDropState(self.entityId, eUiDropState_Normal)
end
function DropTargetStacking:OnDrop(draggable)
if (not self:IsValidDrop(draggable, self.entityId)) then
return
end
-- get the source inventory count
local sourceInventoryCount = 0
local draggableImage = UiElementBus.Event.GetChild(draggable, 0)
local draggableCounterBox = UiElementBus.Event.GetChild(draggableImage, 0)
local draggableCounterText = UiElementBus.Event.GetChild(draggableCounterBox, 0)
local textString = UiTextBus.Event.GetText(draggableCounterText)
sourceInventoryCount = tonumber(textString)
-- get the dest inventory count
local destInventoryCount = 0
local destChildCount = UiElementBus.Event.GetNumChildElements(self.entityId)
local destDraggable = EntityId()
local destDraggableCounterText = EntityId()
local destTextString = ""
if (destChildCount > 0) then
destDraggable = UiElementBus.Event.GetChild(self.entityId, 0)
if (destDraggable == draggable) then
-- draggable was dropped on its original (current) slot - do nothing
return
end
local destDraggableImage = UiElementBus.Event.GetChild(destDraggable, 0)
local destDraggableCounterBox = UiElementBus.Event.GetChild(destDraggableImage, 0)
destDraggableCounterText = UiElementBus.Event.GetChild(destDraggableCounterBox, 0)
destTextString = UiTextBus.Event.GetText(destDraggableCounterText)
destInventoryCount = tonumber(destTextString)
end
if (destInventoryCount == 0 and sourceInventoryCount == 1) then
UiElementBus.Event.Reparent(draggable, self.entityId, EntityId())
else
if (destInventoryCount == 0) then
local canvasEntity = UiElementBus.Event.GetCanvas(self.entityId)
local clonedElement = UiCanvasBus.Event.CloneElement(canvasEntity, draggable, self.entityId, EntityId())
-- set the count on the cloned element to one
local clonedImage = UiElementBus.Event.GetChild(clonedElement, 0)
local clonedCounterBox = UiElementBus.Event.GetChild(clonedImage, 0)
local clonedCounterText = UiElementBus.Event.GetChild(clonedCounterBox, 0)
UiTextBus.Event.SetText(clonedCounterText, "1")
-- if using keyboard/gamepad make the we want to make sure the hover moves
UiCanvasBus.Event.ForceHoverInteractable(canvasEntity, clonedElement)
else
-- increment dest
destInventoryCount = destInventoryCount + 1
destTextString = destInventoryCount
UiTextBus.Event.SetText(destDraggableCounterText, destTextString)
-- if using keyboard/gamepad make the we want to make sure the hover moves
local canvasEntity = UiElementBus.Event.GetCanvas(self.entityId)
UiCanvasBus.Event.ForceHoverInteractable(canvasEntity, destDraggable)
end
if (sourceInventoryCount == 1) then
UiElementBus.Event.DestroyElement(draggable)
else
-- decrement source
sourceInventoryCount = sourceInventoryCount - 1
textString = sourceInventoryCount
UiTextBus.Event.SetText(draggableCounterText, textString)
end
end
end
return DropTargetStacking
@@ -0,0 +1,36 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ColorBall =
{
Properties =
{
Ball = {default = EntityId()},
Color = {default = Color(1,1,1)},
},
}
function ColorBall:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function ColorBall:OnButtonClick()
UiImageBus.Event.SetColor(self.Properties.Ball, self.Properties.Color)
end
function ColorBall:OnDeactivate()
self.buttonHandler:Disconnect()
end
return ColorBall
@@ -0,0 +1,57 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local CreateBall =
{
Properties =
{
Ball = {default = EntityId()},
OtherButtons = {default = {EntityId()}},
},
}
function CreateBall:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.tickHandler = TickBus.Connect(self)
end
function CreateBall:OnTick()
self.tickHandler:Disconnect()
UiElementBus.Event.SetIsEnabled(self.Properties.Ball, false)
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, UiElementBus.Event.GetCanvas(self.entityId))
end
function CreateBall:OnAction(entityId, actionName)
if (actionName == "BallDestroyed") then
for i = 0, #self.Properties.OtherButtons do
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.OtherButtons[i], false)
end
end
end
function CreateBall:OnButtonClick()
UiElementBus.Event.SetIsEnabled(self.Properties.Ball, true)
for i = 0, #self.Properties.OtherButtons do
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.OtherButtons[i], true)
end
end
function CreateBall:OnDeactivate()
self.buttonHandler:Disconnect()
end
return CreateBall
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DestroyBall =
{
Properties =
{
Ball = {default = EntityId()},
},
}
function DestroyBall:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function DestroyBall:OnButtonClick()
UiElementBus.Event.SetIsEnabled(self.Properties.Ball, false)
end
function DestroyBall:OnDeactivate()
self.buttonHandler:Disconnect()
end
return DestroyBall
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MoveBallDown =
{
Properties =
{
Ball = {default = EntityId()},
MinOffset = {default = 0},
},
}
function MoveBallDown:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function MoveBallDown:OnButtonClick()
local offsets = UiTransform2dBus.Event.GetOffsets(self.Properties.Ball)
local height = offsets.bottom - offsets.top
offsets.top = offsets.top + 50
offsets.bottom = offsets.bottom + 50
if (offsets.bottom > self.Properties.MinOffset) then
offsets.bottom = self.Properties.MinOffset
offsets.top = offsets.bottom - height
end
UiTransform2dBus.Event.SetOffsets(self.Properties.Ball, offsets)
end
function MoveBallDown:OnDeactivate()
self.buttonHandler:Disconnect()
end
return MoveBallDown
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MoveBallUp =
{
Properties =
{
Ball = {default = EntityId()},
MaxOffset = {default = 0},
},
}
function MoveBallUp:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function MoveBallUp:OnButtonClick()
local offsets = UiTransform2dBus.Event.GetOffsets(self.Properties.Ball)
local height = offsets.bottom - offsets.top
offsets.top = offsets.top - 50
offsets.bottom = offsets.bottom - 50
if (offsets.top < self.Properties.MaxOffset) then
offsets.top = self.Properties.MaxOffset
offsets.bottom = offsets.top + height
end
UiTransform2dBus.Event.SetOffsets(self.Properties.Ball, offsets)
end
function MoveBallUp:OnDeactivate()
self.buttonHandler:Disconnect()
end
return MoveBallUp
@@ -0,0 +1,49 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ResetBall =
{
Properties =
{
Ball = {default = EntityId()},
},
}
function ResetBall:OnActivate()
self.tickHandler = TickBus.Connect(self)
end
function ResetBall:OnTick()
self.tickHandler:Disconnect()
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, UiElementBus.Event.GetCanvas(self.entityId))
-- Save the default properties of the ball
self.defaultOffsets = UiTransform2dBus.Event.GetOffsets(self.Properties.Ball)
self.defaultColor = UiImageBus.Event.GetColor(self.Properties.Ball)
end
function ResetBall:OnAction(entityId, actionName)
-- This action is sent when the create button is clicked and when the reset button is clicked
if (actionName == "ResetBall") then
UiTransform2dBus.Event.SetOffsets(self.Properties.Ball, self.defaultOffsets)
UiImageBus.Event.SetColor(self.Properties.Ball, self.defaultColor)
end
end
function ResetBall:OnDeactivate()
self.canvasNotificationBusHandler:Disconnect()
end
return ResetBall
@@ -0,0 +1,47 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MultiSelectionDropdown =
{
Properties =
{
Content = {default = EntityId()},
Options = {default = {""}},
},
}
function MultiSelectionDropdown:OnActivate()
self.tickHandler = TickBus.Connect(self)
end
function MultiSelectionDropdown:OnTick()
self.tickHandler:Disconnect()
local numChildren = table.getn(self.Properties.Options)
UiDynamicLayoutBus.Event.SetNumChildElements(self.Properties.Content, numChildren)
for i=0,numChildren-1 do
-- Get child of the layout
local child = UiElementBus.Event.GetChild(self.Properties.Content, i)
-- Get the text element of the child and set its text
local textElement = UiElementBus.Event.FindChildByName(child, "Text")
UiTextBus.Event.SetText(textElement, self.Properties.Options[i+1])
end
end
function MultiSelectionDropdown:OnDeactivate()
end
return MultiSelectionDropdown
@@ -0,0 +1,49 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SelectionDropdownOption =
{
Properties =
{
DropdownContent = {default = EntityId()},
OptionsDisplay = {default = EntityId()},
},
}
function SelectionDropdownOption:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function SelectionDropdownOption:OnButtonClick()
-- Add a new child to the selected options list
local numChildren = UiElementBus.Event.GetNumChildElements(self.Properties.OptionsDisplay)
UiDynamicLayoutBus.Event.SetNumChildElements(self.Properties.OptionsDisplay, numChildren + 1)
-- Get the text that corresponds to our option
local textChild = UiElementBus.Event.FindChildByName(self.entityId, "Text")
local text = UiTextBus.Event.GetText(textChild)
-- Get the child that was last added (index = numChildren)
local newChild = UiElementBus.Event.GetChild(self.Properties.OptionsDisplay, numChildren)
UiTextBus.Event.SetText(newChild, text)
-- Remove this option from the dropdown
UiElementBus.Event.DestroyElement(self.entityId)
end
function SelectionDropdownOption:OnDeactivate()
self.buttonHandler:Disconnect()
end
return SelectionDropdownOption
@@ -0,0 +1,50 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SelectionDropdownSelectedOption =
{
Properties =
{
DropdownContent = {default = EntityId()},
OptionsDisplay = {default = EntityId()},
},
}
function SelectionDropdownSelectedOption:OnActivate()
local deleteButton = UiElementBus.Event.FindChildByName(self.entityId, "Delete")
self.buttonHandler = UiButtonNotificationBus.Connect(self, deleteButton)
end
function SelectionDropdownSelectedOption:OnButtonClick()
-- Add a new child to the dropdown content list
local numChildren = UiElementBus.Event.GetNumChildElements(self.Properties.DropdownContent)
UiDynamicLayoutBus.Event.SetNumChildElements(self.Properties.DropdownContent, numChildren + 1)
-- Get the text that corresponds to our option
local text = UiTextBus.Event.GetText(self.entityId)
-- Get the child that was last added (index = numChildren)
local newChild = UiElementBus.Event.GetChild(self.Properties.DropdownContent, numChildren)
local textChild = UiElementBus.Event.FindChildByName(newChild, "Text")
UiTextBus.Event.SetText(textChild, text)
-- Remove this option from the options display
UiElementBus.Event.DestroyElement(self.entityId)
end
function SelectionDropdownSelectedOption:OnDeactivate()
self.buttonHandler:Disconnect()
end
return SelectionDropdownSelectedOption
@@ -0,0 +1,101 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DynamicLayoutColumn =
{
Properties =
{
ScrollBox = {default = EntityId()},
DynamicLayout = {default = EntityId()},
AddColorsButton = {default = EntityId()},
ColorImage = {default = EntityId()},
},
}
function DynamicLayoutColumn:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.Properties.AddColorsButton)
self.tickBusHandler = TickBus.Connect(self);
end
function DynamicLayoutColumn:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, canvas)
self:InitContent("StaticData/LyShineExamples/uiTestFreeColors.json")
end
function DynamicLayoutColumn:OnDeactivate()
self.buttonHandler:Disconnect()
self.canvasNotificationBusHandler:Disconnect()
end
function DynamicLayoutColumn:OnAction(entityId, actionName)
if actionName == "ColorClicked" then
-- Get the index of the child that was pressed
index = UiElementBus.Event.GetIndexOfChildByEntityId(self.Properties.DynamicLayout, entityId)
-- Get the color at the specified index and set it on the image
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Free, index)
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
end
end
function DynamicLayoutColumn:OnButtonClick()
if (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.AddColorsButton) then
self:InitContent("StaticData/LyShineExamples/uiTestMoreFreeColors.json")
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AddColorsButton, false)
end
end
function DynamicLayoutColumn:InitContent(jsonFilepath)
-- Refresh the dynamic content database with the specified json file
UiDynamicContentDatabaseBus.Broadcast.Refresh(eUiDynamicContentDBColorType_Free, jsonFilepath)
-- Set the number of children for the layout element based on the number of colors in the dynamic content database
local numColors = UiDynamicContentDatabaseBus.Broadcast.GetNumColors(eUiDynamicContentDBColorType_Free)
UiDynamicLayoutBus.Event.SetNumChildElements(self.Properties.DynamicLayout, numColors)
for i=0,numColors-1 do
-- Get child of the layout
local child = UiElementBus.Event.GetChild(self.Properties.DynamicLayout, i)
-- Get the image of the child and set the color
local image = UiElementBus.Event.FindChildByName(child, "Color")
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Free, i)
UiImageBus.Event.SetColor(image, color)
-- Get the text of the child and set the name
local text = UiElementBus.Event.FindChildByName(child, "Name")
local name = UiDynamicContentDatabaseBus.Broadcast.GetColorName(eUiDynamicContentDBColorType_Free, i)
UiTextBus.Event.SetText(text, name)
end
-- Force the hover interactable to be the scroll box.
-- The scroll box is set to auto-activate, but it could still have the hover
-- since it starts out having no children. Now that it may contain children,
-- force it to be the hover in order to auto-activate it and pass the hover to its child.
-- Ensure that the layouts of the newly added children are up to date by forcing an
-- immediate recompute. This is necessary for the scroll box to correctly determine
-- which of its children should get the hover
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiCanvasBus.Event.RecomputeChangedLayouts(canvas)
UiCanvasBus.Event.ForceHoverInteractable(canvas, self.Properties.ScrollBox)
end
return DynamicLayoutColumn
@@ -0,0 +1,75 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DynamicLayoutGrid =
{
Properties =
{
FirstScrollBox = {default = EntityId()},
AddColorsButton = {default = EntityId()},
DynamicLayouts = { default = { EntityId(), EntityId() } },
},
}
function DynamicLayoutGrid:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.Properties.AddColorsButton)
self.tickBusHandler = TickBus.Connect(self);
end
function DynamicLayoutGrid:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self:InitContent("StaticData/LyShineExamples/uiTestFreeColors.json")
end
function DynamicLayoutGrid:OnDeactivate()
self.buttonHandler:Disconnect()
end
function DynamicLayoutGrid:OnButtonClick()
if (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.AddColorsButton) then
self:InitContent("StaticData/LyShineExamples/uiTestMoreFreeColors.json")
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AddColorsButton, false)
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiCanvasBus.Event.ForceHoverInteractable(canvas, self.Properties.FirstScrollBox)
end
end
function DynamicLayoutGrid:InitContent(jsonFilepath)
-- Refresh the dynamic content database with the specified json file
UiDynamicContentDatabaseBus.Broadcast.Refresh(eUiDynamicContentDBColorType_Free, jsonFilepath)
-- Get the number of colors in the dynamic content database
local numColors = UiDynamicContentDatabaseBus.Broadcast.GetNumColors(eUiDynamicContentDBColorType_Free)
for i=0,#self.Properties.DynamicLayouts do
-- Set the number of children for the layout element
UiDynamicLayoutBus.Event.SetNumChildElements(self.Properties.DynamicLayouts[i], numColors)
for j=0,numColors-1 do
-- Get child of the layout
local child = UiElementBus.Event.GetChild(self.Properties.DynamicLayouts[i], j)
-- Set the color
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Free, j)
UiImageBus.Event.SetColor(child, color)
end
end
end
return DynamicLayoutGrid
@@ -0,0 +1,170 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DynamicScrollBox =
{
Properties =
{
DynamicScrollBox = {default = EntityId()},
ScrollBar = {default = EntityId()},
AddCheckBox = {default = EntityId()},
ScrollToEndButton = {default = EntityId()},
},
addDelay = 1,
numElementsToAdd = 1,
keepAtEndIfAtEnd = true,
tickTimer = 0,
firstTick = true,
addEnabled = true
}
function DynamicScrollBox:OnActivate()
self.dynamicSBoxDataHandler = UiDynamicScrollBoxDataBus.Connect(self, self.Properties.DynamicScrollBox)
self.dynamicSBoxElementHandler = UiDynamicScrollBoxElementNotificationBus.Connect(self, self.Properties.DynamicScrollBox)
self.scrollBarHandler = UiScrollerNotificationBus.Connect(self, self.Properties.ScrollBar)
self.addCheckBoxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.AddCheckBox)
self.scrollButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.ScrollToEndButton)
self.tickBusHandler = TickBus.Connect(self);
end
function DynamicScrollBox:OnTick(deltaTime, timePoint)
if self.firstTick == true then
self:InitContent("StaticData/LyShineExamples/uiTestMorePaidColors.json")
self.firstTick = false
else
if self.addEnabled == true then
self.tickTimer = self.tickTimer + deltaTime
if self.tickTimer >= self.addDelay then
UiDynamicScrollBoxBus.Event.AddElementsToEnd(self.Properties.DynamicScrollBox, self.numElementsToAdd, self.keepAtEndIfAtEnd)
self.tickTimer = 0
end
end
end
end
function DynamicScrollBox:OnDeactivate()
self.dynamicSBoxDataHandler:Disconnect()
self.dynamicSBoxElementHandler:Disconnect()
self.scrollBarHandler:Disconnect()
self.addCheckBoxHandler:Disconnect()
self.scrollButtonHandler:Disconnect()
self.tickBusHandler:Disconnect()
end
function DynamicScrollBox:InitContent(jsonFilepath)
-- Refresh the dynamic content database with the specified json file
UiDynamicContentDatabaseBus.Broadcast.Refresh(eUiDynamicContentDBColorType_Paid, jsonFilepath)
-- Refresh the dynamic scrollbox. This will trigger events from the
-- UiDynamicScrollBoxDataBus and the UiDynamicScrollBoxElementNotificationBus
UiDynamicScrollBoxBus.Event.RefreshContent(self.Properties.DynamicScrollBox)
end
function DynamicScrollBox:GetMessageFromIndex(index)
local formattedValue
local i = index % 5
if i == 0 then
formattedValue = "This list contains elements of varying height"
elseif i == 1 then
formattedValue = "The auto calculate flag is on, so element heights are automatically calculated by the Dynamic Scroll Box component using layout methods"
elseif i == 2 then
formattedValue = "An estimated element height has not been provided, so all element heights are calculated up front. When an estimated element height is provided, sizes are only calculated when elements come into view. This is useful for lists that contain many elements"
elseif i == 3 then
formattedValue = "An element is added to this list every second. If the list is scrolled all the way to the bottom, it will remain scrolled to the bottom when elements are added"
elseif i == 4 then
formattedValue = "All features can also be applied to horizontal lists"
end
return formattedValue
end
-- Dynamic ScrollBox handlers
function DynamicScrollBox:GetNumElements()
return 1
end
function DynamicScrollBox:OnPrepareElementForSizeCalculation(entityId, index)
-- set message body
local messageField = UiElementBus.Event.FindDescendantByName(entityId, "ChatText")
local formattedValue = self:GetMessageFromIndex(index)
UiTextBus.Event.SetText(messageField, formattedValue)
end
function DynamicScrollBox:OnElementBecomingVisible(entityId, index)
local formattedValue
-- set player name
local playerName = UiElementBus.Event.FindDescendantByName(entityId, "PlayerName")
formattedValue = string.format("Player%d", index)
UiTextBus.Event.SetText(playerName, formattedValue)
-- set player image color
local numColors = UiDynamicContentDatabaseBus.Broadcast.GetNumColors(eUiDynamicContentDBColorType_Paid)
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Paid, index % numColors)
local playerImage = UiElementBus.Event.FindDescendantByName(entityId, "PlayerBackground")
UiImageBus.Event.SetColor(playerImage, color)
-- set message body
local messageField = UiElementBus.Event.FindDescendantByName(entityId, "ChatText")
formattedValue = self:GetMessageFromIndex(index)
UiTextBus.Event.SetText(messageField, formattedValue)
-- set background color
local background = UiElementBus.Event.FindDescendantByName(entityId, "Background")
local color
if index % 2 == 0 then
color = Color(167/255, 217/255, 232/255)
else
color = Color(245/255, 255/255, 255/255)
end
UiImageBus.Event.SetColor(background, color)
end
-- CheckBox handlers
function DynamicScrollBox:OnCheckboxStateChange(checked)
self.addEnabled = checked
if self.addEnabled then
self.tickTimer = self.addDelay
end
end
-- Button handlers
function DynamicScrollBox:OnButtonClick()
UiDynamicScrollBoxBus.Event.ScrollToEnd(self.Properties.DynamicScrollBox)
self.tickTimer = 0
end
-- Scroller handlers
function DynamicScrollBox:OnScrollerValueChanging(value)
self:OnScrollerValueChanged(value)
end
function DynamicScrollBox:OnScrollerValueChanged(value)
local enabled
if Math.IsClose(value, 1.0, 0.01) then
enabled = false
else
enabled = true
end
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.ScrollToEndButton, enabled)
end
return DynamicScrollBox
@@ -0,0 +1,133 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DynamicScrollBox =
{
Properties =
{
DynamicScrollBox = {default = EntityId()},
},
}
function DynamicScrollBox:OnActivate()
self.dynamicSBoxDataHandler = UiDynamicScrollBoxDataBus.Connect(self, self.Properties.DynamicScrollBox)
self.dynamicSBoxElementHandler = UiDynamicScrollBoxElementNotificationBus.Connect(self, self.Properties.DynamicScrollBox)
self.tickBusHandler = TickBus.Connect(self);
end
function DynamicScrollBox:OnDeactivate()
self.dynamicSBoxDataHandler:Disconnect()
self.dynamicSBoxElementHandler:Disconnect()
end
function DynamicScrollBox:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self:InitContent("StaticData/LyShineExamples/uiTestMorePaidColors.json")
end
function DynamicScrollBox:InitContent(jsonFilepath)
-- Refresh the dynamic content database with the specified json file
UiDynamicContentDatabaseBus.Broadcast.Refresh(eUiDynamicContentDBColorType_Paid, jsonFilepath)
-- Refresh the dynamic scrollbox. This will trigger events from the
-- UiDynamicScrollBoxDataBus and the UiDynamicScrollBoxElementNotificationBus
UiDynamicScrollBoxBus.Event.RefreshContent(self.Properties.DynamicScrollBox)
end
function DynamicScrollBox:GetElementIndex(sectionIndex, index)
local absoluteIndex
if sectionIndex == 0 then
absoluteIndex = index
else
absoluteIndex = ((sectionIndex * (sectionIndex + 1)) / 2) + index
end
return absoluteIndex
end
function DynamicScrollBox:GetMessageFromIndex(sectionIndex, index)
local formattedValue
local i = self:GetElementIndex(sectionIndex, index) % 5
if i == 0 then
formattedValue = "This list contains elements and headers that vary in height"
elseif i == 1 then
formattedValue = "The element heights are automatically calculated by the Dynamic Scroll Box component using layout methods"
elseif i == 2 then
formattedValue = "The header heights are not set to automatically calculate, so their sizes are provided via the UiDynamicScrollBoxDataBus. In this case, each header is a few pixels taller than the one before it"
elseif i == 3 then
formattedValue = "An estimated element height has been provided, so sizes are only calculated when an element comes into view. This is useful when the list contains many elements"
elseif i == 4 then
formattedValue = "All features can also be applied to horizontal lists"
end
return formattedValue
end
function DynamicScrollBox:GetHeaderMessageFromIndex(sectionIndex)
local formattedValue = string.format("Header %d", sectionIndex)
return formattedValue
end
-- Dynamic ScrollBox handlers
function DynamicScrollBox:GetNumSections()
return 10
end
function DynamicScrollBox:GetNumElementsInSection(sectionIndex)
return (sectionIndex + 1) * 1
end
function DynamicScrollBox:OnPrepareElementInSectionForSizeCalculation(entityId, sectionIndex, index)
-- set message body
local messageField = UiElementBus.Event.FindDescendantByName(entityId, "ChatText")
local formattedValue = self:GetMessageFromIndex(sectionIndex, index)
UiTextBus.Event.SetText(messageField, formattedValue)
end
function DynamicScrollBox:OnElementInSectionBecomingVisible(entityId, sectionIndex, index)
local formattedValue
-- set player name
local playerName = UiElementBus.Event.FindDescendantByName(entityId, "PlayerName")
formattedValue = string.format("Player%d.%d", sectionIndex, index)
UiTextBus.Event.SetText(playerName, formattedValue)
-- set player image color
local numColors = UiDynamicContentDatabaseBus.Broadcast.GetNumColors(eUiDynamicContentDBColorType_Paid)
local colorIndex = self:GetElementIndex(sectionIndex, index) % numColors
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Paid, colorIndex)
local playerImage = UiElementBus.Event.FindDescendantByName(entityId, "PlayerBackground")
UiImageBus.Event.SetColor(playerImage, color)
-- set message body
local messageField = UiElementBus.Event.FindDescendantByName(entityId, "ChatText")
formattedValue = self:GetMessageFromIndex(sectionIndex, index)
UiTextBus.Event.SetText(messageField, formattedValue)
end
function DynamicScrollBox:GetSectionHeaderHeight(sectionIndex)
local height = 40 + (sectionIndex * 5)
return height
end
function DynamicScrollBox:OnSectionHeaderBecomingVisible(entityId, sectionIndex)
-- set header title
local headerTitle = UiElementBus.Event.FindDescendantByName(entityId, "HeaderTitle")
local formattedValue = self:GetHeaderMessageFromIndex(sectionIndex)
UiTextBus.Event.SetText(headerTitle, formattedValue)
end
return DynamicScrollBox
@@ -0,0 +1,110 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DynamicScrollBox =
{
Properties =
{
DynamicScrollBox = {default = EntityId()},
AddColorsButton = {default = EntityId()},
ColorImage = {default = EntityId()},
ColorIndexText = {default = EntityId()},
},
}
function DynamicScrollBox:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.Properties.AddColorsButton)
self.dynamicSBoxDataHandler = UiDynamicScrollBoxDataBus.Connect(self, self.Properties.DynamicScrollBox)
self.dynamicSBoxElementHandler = UiDynamicScrollBoxElementNotificationBus.Connect(self, self.Properties.DynamicScrollBox)
self.tickBusHandler = TickBus.Connect(self);
end
function DynamicScrollBox:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, canvas)
self:InitContent("StaticData/LyShineExamples/uiTestPaidColors.json")
end
function DynamicScrollBox:OnDeactivate()
self.buttonHandler:Disconnect()
self.canvasNotificationBusHandler:Disconnect()
self.dynamicSBoxDataHandler:Disconnect()
self.dynamicSBoxElementHandler:Disconnect()
end
function DynamicScrollBox:GetNumElements()
local numColors = UiDynamicContentDatabaseBus.Broadcast.GetNumColors(eUiDynamicContentDBColorType_Paid)
return numColors
end
function DynamicScrollBox:OnElementBecomingVisible(entityId, index)
-- Get the image of the child and set the color
local image = UiElementBus.Event.FindChildByName(entityId, "Icon")
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Paid, index)
UiImageBus.Event.SetColor(image, color)
-- Get the name text of the child and set the name
local nameText = UiElementBus.Event.FindChildByName(entityId, "Name")
local name = UiDynamicContentDatabaseBus.Broadcast.GetColorName(eUiDynamicContentDBColorType_Paid, index)
UiTextBus.Event.SetText(nameText, name)
-- Get the price text of the child and set the price
local priceText = UiElementBus.Event.FindChildByName(entityId, "Price")
local price = UiDynamicContentDatabaseBus.Broadcast.GetColorPrice(eUiDynamicContentDBColorType_Paid, index)
UiTextBus.Event.SetText(priceText, price)
end
function DynamicScrollBox:OnAction(entityId, actionName)
if actionName == "IconClicked" then
-- Set selected color
index = UiDynamicScrollBoxBus.Event.GetLocationIndexOfChild(self.Properties.DynamicScrollBox, entityId)
local color = UiDynamicContentDatabaseBus.Broadcast.GetColor(eUiDynamicContentDBColorType_Paid, index)
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
-- Set selected index
UiTextBus.Event.SetText(self.Properties.ColorIndexText, index)
end
end
function DynamicScrollBox:OnButtonClick()
if (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.AddColorsButton) then
self:InitContent("StaticData/LyShineExamples/uiTestMorePaidColors.json")
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.AddColorsButton, false)
end
end
function DynamicScrollBox:InitContent(jsonFilepath)
-- Refresh the dynamic content database with the specified json file
UiDynamicContentDatabaseBus.Broadcast.Refresh(eUiDynamicContentDBColorType_Paid, jsonFilepath)
-- Refresh the dynamic scrollbox. This will trigger events from the
-- UiDynamicScrollBoxDataBus and the UiDynamicScrollBoxElementNotificationBus
UiDynamicScrollBoxBus.Event.RefreshContent(self.Properties.DynamicScrollBox)
-- Force the hover interactable to be the scroll box.
-- The scroll box is set to auto-activate, but it could still have the hover
-- since it starts out having no children. Now that it may contain children,
-- force it to be the hover in order to auto-activate it and pass the hover to its child
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiCanvasBus.Event.ForceHoverInteractable(canvas, self.Properties.DynamicScrollBox)
end
return DynamicScrollBox
@@ -0,0 +1,82 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local FadeButton =
{
Properties =
{
FaderEntity = {default = EntityId()},
FadeValueSlider = {default = EntityId()},
FadeSpeedMinusButton = {default = EntityId()},
FadeSpeedPlusButton = {default = EntityId()},
FadeSpeedText = {default = EntityId()},
},
}
function FadeButton:OnActivate()
-- Connect to the button notification bus on our entity to know when to start the animation
self.animButtonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
-- Connect to the slider notification bus to know what fade value to give to the animation
self.sliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.FadeValueSlider)
-- Connect to the button notification buses of the minus and plus buttons to know when to change the fade speed
self.minusButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.FadeSpeedMinusButton)
self.plusButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.FadeSpeedPlusButton)
-- Initialize the fade value (needs to be the same as the start fade value slider value)
self.fadeValue = 0
-- Initialize the fade speed (needs to be the same as the start fade speed text)
self.fadeSpeed = 5
end
function FadeButton:OnDeactivate()
-- Disconnect from all our buses
self.animButtonHandler:Disconnect()
self.sliderHandler:Disconnect()
self.minusButtonHandler:Disconnect()
self.plusButtonHandler:Disconnect()
end
function FadeButton:OnSliderValueChanging(percent)
-- Set the fade value to the slider value
self.fadeValue = percent / 100
end
function FadeButton:OnSliderValueChanged(percent)
-- Set the fade value to the slider value
self.fadeValue = percent / 100
end
function FadeButton:OnButtonClick()
-- If the animation button was clicked
if (UiButtonNotificationBus.GetCurrentBusId() == self.entityId) then
-- Start the fade animation
UiFaderBus.Event.Fade(self.Properties.FaderEntity, self.fadeValue, self.fadeSpeed)
-- Else if the minus button was clicked
elseif (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.FadeSpeedMinusButton) then
-- Decrement the animation speed (min = 1)
self.fadeSpeed = math.max(1, self.fadeSpeed - 1)
-- And update the text
UiTextBus.Event.SetText(self.Properties.FadeSpeedText, self.fadeSpeed)
-- Else the plus button was clicked
else
-- Decrement the animation speed (max = 10)
self.fadeSpeed = math.min(self.fadeSpeed + 1, 10)
-- And update the text
UiTextBus.Event.SetText(self.Properties.FadeSpeedText, self.fadeSpeed)
end
end
return FadeButton
@@ -0,0 +1,45 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local FadeSlider =
{
Properties =
{
FaderEntity = {default = EntityId()},
},
}
function FadeSlider:OnActivate()
-- Connect to the slider notification bus
self.sliderHandler = UiSliderNotificationBus.Connect(self, self.entityId)
end
function FadeSlider:OnDeactivate()
-- Deactivate from the slider notification bus only if we managed to connect
if (self.sliderHandler ~= nil) then
self.sliderHandler:Disconnect()
end
end
function FadeSlider:OnSliderValueChanging(percent)
-- Set the fade value to the slider value
UiFaderBus.Event.SetFadeValue(self.Properties.FaderEntity, percent / 100)
end
function FadeSlider:OnSliderValueChanged(percent)
-- Set the fade value to the slider value
UiFaderBus.Event.SetFadeValue(self.Properties.FaderEntity, percent / 100)
end
return FadeSlider
@@ -0,0 +1,197 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SequenceStates =
{
Properties =
{
FlipbookContentSpriteSheet = {default = EntityId()},
FlipbookContentImageSequence = {default = EntityId()},
StateText = {default = EntityId()},
PlayStateText = {default = EntityId()},
PlayStateImage = {default = EntityId()},
StartButton = {default = EntityId()},
StopButton = {default = EntityId()},
LoopTypeDropdown = {default = EntityId()},
ImageTypeDropdown = {default = EntityId()},
ImageTypeDropdownSpritesheetOption = {default = EntityId()},
ImageTypeDropdownImageSequenceOption = {default = EntityId()},
ImageDescription = {default = EntityId()},
},
}
function SequenceStates:OnActivate()
self.requiresInit = true
self.tickBusHandler = TickBus.Connect(self);
-- By default, we'll use sprite-sheets for flipbooks. The user can switch
-- to the image sequence version of the flipbook via dropdown.
self.currentImage = self.Properties.FlipbookContentSpriteSheet
end
function SequenceStates:PrintImageDescription()
local currentFrame = UiFlipbookAnimationBus.Event.GetCurrentFrame(self.currentImage, 0)
local zeroPaddedFrameString = string.format("%02d", currentFrame)
if self.currentImage == self.Properties.FlipbookContentSpriteSheet then
UiTextBus.Event.SetText(self.Properties.ImageDescription, "flipbook_walking.tif (index " .. zeroPaddedFrameString .. ")")
else
UiTextBus.Event.SetText(self.Properties.ImageDescription, "flipbook_walking_" .. zeroPaddedFrameString .. ".png")
end
end
function SequenceStates:OnTick(deltaTime, timePoint)
if self.requiresInit == true then
self.requiresInit = false
self.numLoops = 0
self.sequenceStartedString = "Sequence Started"
UiElementBus.Event.SetIsEnabled(self.currentImage, true)
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
-- Handler for OnAction callbacks
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, self.canvas)
-- Handler for flipbook animation start/stop callbacks
self.flipbookNotificationBusHandler = UiFlipbookAnimationNotificationsBus.Connect(self, self.currentImage)
-- Initialize button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
self:PrintImageDescription()
-- Disconnect here because we want to change the value of the image-type dropdown value
-- but we don't want to be notified of the change. The first time this logic gets
-- executed the handler will be nil, however, so we have to guard against that
if self.imageTypeDropdownNotificationBusHandler ~= nil then
self.imageTypeDropdownNotificationBusHandler:Disconnect()
end
if self.currentImage == self.Properties.FlipbookContentSpriteSheet then
UiDropdownBus.Event.SetValue(self.Properties.ImageTypeDropdown, self.Properties.ImageTypeDropdownSpritesheetOption)
else
UiDropdownBus.Event.SetValue(self.Properties.ImageTypeDropdown, self.Properties.ImageTypeDropdownImageSequenceOption)
end
-- Handler for dropd-down callbacks
self.loopTypeDropdownNotificationBusHandler = UiDropdownNotificationBus.Connect(self, self.Properties.LoopTypeDropdown)
self.imageTypeDropdownNotificationBusHandler = UiDropdownNotificationBus.Connect(self, self.Properties.ImageTypeDropdown)
else
local isPlaying = UiFlipbookAnimationBus.Event.IsPlaying(self.currentImage)
if isPlaying == true then
UiImageBus.Event.SetColor(self.Properties.PlayStateImage, Color(0, 255, 0))
UiTextBus.Event.SetColor(self.Properties.PlayStateText, Color(0, 255, 0))
self:PrintImageDescription()
else
UiImageBus.Event.SetColor(self.Properties.PlayStateImage, Color(255, 0, 0))
UiTextBus.Event.SetColor(self.Properties.PlayStateText, Color(255, 0, 0))
end
end
end
function SequenceStates:OnDeactivate()
self.tickBusHandler:Disconnect()
self.canvasNotificationBusHandler:Disconnect()
self.flipbookNotificationBusHandler:Disconnect()
self.loopTypeDropdownNotificationBusHandler:Disconnect()
self.imageTypeDropdownNotificationBusHandler:Disconnect()
end
function SequenceStates:OnAction(entityId, actionName)
if actionName == "StartPressed" then
UiFlipbookAnimationBus.Event.Start(self.currentImage)
elseif actionName == "StopPressed" then
UiFlipbookAnimationBus.Event.Stop(self.currentImage)
end
end
function SequenceStates:OnAnimationStarted()
-- Setup button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, true)
-- Set sequence state text
UiTextBus.Event.SetText(self.Properties.StateText, self.sequenceStartedString)
self.numLoops = 0
end
function SequenceStates:OnAnimationStopped()
-- Update button states
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StartButton, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.StopButton, false)
-- Set sequence state text
UiTextBus.Event.SetText(self.Properties.StateText, "Sequence Stopped")
end
function SequenceStates:OnLoopSequenceCompleted()
self.numLoops = self.numLoops + 1
local pluralString = ""
if self.numLoops > 1 then
pluralString = "s"
end
UiTextBus.Event.SetText(self.Properties.StateText, self.sequenceStartedString .. " (" .. tostring(self.numLoops) .. " loop" .. pluralString .. ")")
end
function SequenceStates:OnDropdownValueChanged(optionEntityId)
-- Note: both the loop and image type dropdowns will execute this function
local dropdownText = UiDropdownOptionBus.Event.GetTextElement(optionEntityId)
local textValue = UiTextBus.Event.GetText(dropdownText)
-- If the image type changes, we need to re-initialize based on the new
-- image content entity (either sprite-sheet or image sequence)
local currentLoopType = nil
if UiDropdownNotificationBus.GetCurrentBusId() == self.Properties.ImageTypeDropdown then
if (UiFlipbookAnimationBus.Event.IsPlaying(self.currentImage)) then
UiFlipbookAnimationBus.Event.Stop(self.currentImage)
end
self.requiresInit = true
self.flipbookNotificationBusHandler:Disconnect(self, self.currentImage)
currentLoopType = UiFlipbookAnimationBus.Event.GetLoopType(self.currentImage)
end
if textValue == "None" then
UiFlipbookAnimationBus.Event.SetLoopType(self.currentImage, eUiFlipbookAnimationLoopType_None)
elseif textValue == "Linear" then
UiFlipbookAnimationBus.Event.SetLoopType(self.currentImage, eUiFlipbookAnimationLoopType_Linear)
elseif textValue =="PingPong" then
UiFlipbookAnimationBus.Event.SetLoopType(self.currentImage, eUiFlipbookAnimationLoopType_PingPong)
elseif textValue =="Sprite sheet" then
UiElementBus.Event.SetIsEnabled(self.currentImage, false)
self.currentImage = self.Properties.FlipbookContentSpriteSheet
elseif textValue =="Image sequence" then
UiElementBus.Event.SetIsEnabled(self.currentImage, false)
self.currentImage = self.Properties.FlipbookContentImageSequence
end
-- If changing image type, restore the current loop type to the new image
-- content entity and reset the frame.
if UiDropdownNotificationBus.GetCurrentBusId() == self.Properties.ImageTypeDropdown then
UiFlipbookAnimationBus.Event.SetLoopType(self.currentImage, currentLoopType)
UiFlipbookAnimationBus.Event.SetCurrentFrame(self.currentImage, 0)
self:PrintImageDescription()
end
end
return SequenceStates
@@ -0,0 +1,37 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local HideThisElementButton =
{
Properties =
{
},
}
function HideThisElementButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
UiElementBus.Event.SetIsEnabled(self.entityId, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.entityId, false)
end
function HideThisElementButton:OnDeactivate()
self.buttonHandler:Disconnect()
end
function HideThisElementButton:OnButtonClick()
UiElementBus.Event.SetIsEnabled(self.entityId, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.entityId, false)
end
return HideThisElementButton
@@ -0,0 +1,153 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ImageFillTypes =
{
Properties =
{
FilledImages = { default = { EntityId(), EntityId(), EntityId(), EntityId() } },
Dropdowns = { default = { EntityId(), EntityId(), EntityId(), EntityId() } },
RadialStartAngleSlider = { default = EntityId() },
SpriteRadioButtonGroup = { default = EntityId() },
},
}
function ImageFillTypes:OnActivate()
self.tickBusHandler = TickBus.Connect(self)
self.totalTime = 0
self.timeOverride = 0
self.dropdownHandlers = {}
for i = 0, #self.Properties.Dropdowns do
self.dropdownHandlers[i] = UiDropdownNotificationBus.Connect(self, self.Properties.Dropdowns[i])
end
self.radialStartAngleSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.RadialStartAngleSlider)
self.spriteRadioButtonGroupHandler = UiRadioButtonGroupNotificationBus.Connect(self, self.Properties.SpriteRadioButtonGroup)
self:InitAutomatedTestEvents()
end
function ImageFillTypes:OnTick(deltaTime, timePoint)
self.totalTime = self.totalTime + deltaTime
-- [Automated Testing] Overrides the fill value
if self.timeOverride > 0 then
self.totalTime = self.timeOverride
end
for i = 0, #self.Properties.FilledImages do
fillAmount = 1.0-((math.cos(self.totalTime)*0.5)+0.5) -- Scale cos output to the range [0,1]
UiImageBus.Event.SetFillAmount(self.Properties.FilledImages[i], fillAmount)
end
end
function ImageFillTypes:OnDeactivate()
self.tickBusHandler:Disconnect()
for i = 0, #self.Properties.Dropdowns do
self.dropdownHandlers[i]:Disconnect()
end
self.radialStartAngleSliderHandler:Disconnect()
self.spriteRadioButtonGroupHandler:Disconnect()
self:DeInitAutomatedTestEvents()
end
function ImageFillTypes:OnDropdownValueChanged(entityId)
local dropdown = UiDropdownNotificationBus.GetCurrentBusId()
local parent = UiElementBus.Event.GetParent(entityId)
local selectedIndex = UiElementBus.Event.GetIndexOfChildByEntityId(parent, entityId)
if dropdown == self.Properties.Dropdowns[0] then
-- Linear
UiImageBus.Event.SetEdgeFillOrigin(self.Properties.FilledImages[0], selectedIndex)
elseif dropdown == self.Properties.Dropdowns[2] then
-- Radial corner
UiImageBus.Event.SetCornerFillOrigin(self.Properties.FilledImages[2], selectedIndex)
elseif dropdown == self.Properties.Dropdowns[3] then
-- Radial edge
UiImageBus.Event.SetEdgeFillOrigin(self.Properties.FilledImages[3], selectedIndex)
end
self.totalTime = 0
self:OnTick(0, 0)
end
function ImageFillTypes:OnSliderValueChanged(value)
-- Radial
local slider = UiSliderNotificationBus.GetCurrentBusId()
if slider == self.Properties.RadialStartAngleSlider then
UiImageBus.Event.SetRadialFillStartAngle(self.Properties.FilledImages[1], value)
end
self.totalTime = 0
self:OnTick(0, 0)
end
function ImageFillTypes:OnRadioButtonGroupStateChange(entityId)
local selectedIndex = UiElementBus.Event.GetIndexOfChildByEntityId(self.Properties.SpriteRadioButtonGroup, entityId)
if selectedIndex == 0 then
-- No sprite
for i = 0, #self.Properties.FilledImages do
UiImageBus.Event.SetSpritePathname(self.Properties.FilledImages[i], "")
end
elseif selectedIndex == 1 then
-- Sprite
for i = 0, #self.Properties.FilledImages do
UiImageBus.Event.SetImageType(self.Properties.FilledImages[i], eUiImageType_StretchedToFit)
UiImageBus.Event.SetSpritePathname(self.Properties.FilledImages[i], "ui/textures/lyshineexamples/scroll_box_icon_5.tif")
end
elseif selectedIndex == 2 then
-- Sliced sprite
for i = 0, #self.Properties.FilledImages do
UiImageBus.Event.SetImageType(self.Properties.FilledImages[i], eUiImageType_Sliced)
UiImageBus.Event.SetSpritePathname(self.Properties.FilledImages[i], "ui/textures/lyshineexamples/button.tif")
UiImageBus.Event.SetFillCenter(self.Properties.FilledImages[i], true)
end
elseif selectedIndex == 3 then
-- Sliced sprite, no center
for i = 0, #self.Properties.FilledImages do
UiImageBus.Event.SetImageType(self.Properties.FilledImages[i], eUiImageType_Sliced)
UiImageBus.Event.SetSpritePathname(self.Properties.FilledImages[i], "ui/textures/lyshineexamples/button.tif")
UiImageBus.Event.SetFillCenter(self.Properties.FilledImages[i], false)
end
end
end
-- [Automated Testing] setup
function ImageFillTypes:InitAutomatedTestEvents()
self.automatedTestSetFillValueId = GameplayNotificationId(EntityId(), "AutomatedTestSetFillValue", "float");
self.automatedTestSetFillValueHandler = GameplayNotificationBus.Connect(self, self.automatedTestSetFillValueId);
end
-- [Automated Testing] event handling
function ImageFillTypes:OnEventBegin(value)
if (GameplayNotificationBus.GetCurrentBusId() == self.automatedTestSetFillValueId) then
self.timeOverride = value
end
end
-- [Automated Testing] teardown
function ImageFillTypes:DeInitAutomatedTestEvents()
if (self.automatedTestSetFillValueHandler ~= nil) then
self.automatedTestSetFillValueHandler:Disconnect();
self.automatedTestSetFillValueHandler = nil;
end
end
return ImageFillTypes
@@ -0,0 +1,53 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ImageTypes =
{
Properties =
{
ShowOutlinesCheckbox = {default = EntityId()},
Outlines = { default = { EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId() } },
},
}
function ImageTypes:OnActivate()
self.showOutlinesCBHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.ShowOutlinesCheckbox)
self.tickBusHandler = TickBus.Connect(self);
end
function ImageTypes:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
-- Initialize outlines
self:ShowOutlines(false)
end
function ImageTypes:OnDeactivate()
self.showOutlinesCBHandler:Disconnect()
end
function ImageTypes:OnCheckboxStateChange(isChecked)
if (UiCheckboxNotificationBus.GetCurrentBusId() == self.Properties.ShowOutlinesCheckbox) then
self:ShowOutlines(isChecked)
end
end
function ImageTypes:ShowOutlines(show)
for i = 0, #self.Properties.Outlines do
UiElementBus.Event.SetIsEnabled(self.Properties.Outlines[i], show)
end
end
return ImageTypes
@@ -0,0 +1,56 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local Spritesheet =
{
Properties =
{
ButtonText = {default = EntityId()},
MainPanel = {default = EntityId()},
SpritesheetSourcePanel = {default = EntityId()}
},
}
function Spritesheet:OnActivate()
self.tickBusHandler = TickBus.Connect(self)
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.showSpritesheet = false
end
function Spritesheet:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
UiElementBus.Event.SetIsEnabled(self.Properties.SpritesheetSourcePanel, self.showSpritesheet)
end
function Spritesheet:OnButtonClick()
if (self.showSpritesheet) then
self.showSpritesheet = false
UiTextBus.Event.SetText(self.Properties.ButtonText, "Show Spritesheet")
else
self.showSpritesheet = true
UiTextBus.Event.SetText(self.Properties.ButtonText, "Hide Spritesheet")
end
UiElementBus.Event.SetIsEnabled(self.Properties.SpritesheetSourcePanel, self.showSpritesheet)
UiElementBus.Event.SetIsEnabled(self.Properties.MainPanel, not self.showSpritesheet)
end
function Spritesheet:OnDeactivate()
self.buttonHandler:Disconnect()
end
return Spritesheet
@@ -0,0 +1,74 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ResetSizes =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ResetSizes:OnActivate()
self.tickHandler = TickBus.Connect(self)
end
function ResetSizes:OnTick()
self.tickHandler:Disconnect()
-- Initialize table that will hold the base offsets for every element in the content
self.offsets = {}
-- Save the base offsets for every element
self:SaveElementSizeRecursive(self.Properties.ContainerElement)
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function ResetSizes:SaveElementSizeRecursive(element)
-- Save the offsets for that element
self.offsets[element] = UiTransform2dBus.Event.GetOffsets(element)
-- Iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
self:SaveElementSizeRecursive(children[i])
end
end
function ResetSizes:OnDeactivate()
self.buttonHandler:Disconnect()
end
function ResetSizes:OnButtonClick()
-- Reset the offsets for every element
for element, offsets in pairs(self.offsets) do
local isHorizontalFit = UiLayoutFitterBus.Event.GetHorizontalFit(element)
local isVerticalFit = UiLayoutFitterBus.Event.GetVerticalFit(element)
local newOffsets = UiTransform2dBus.Event.GetOffsets(element)
if (isHorizontalFit == false) then
newOffsets.left = offsets.left
newOffsets.right = offsets.right
end
if (isVerticalFit == false) then
newOffsets.top = offsets.top
newOffsets.bottom = offsets.bottom
end
UiTransform2dBus.Event.SetOffsets(element, newOffsets)
end
end
return ResetSizes
@@ -0,0 +1,36 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ScaletoTarget =
{
Properties =
{
Target = {default = EntityId()},
},
}
function ScaletoTarget:OnActivate()
self.tickHandler = TickBus.Connect(self)
end
function ScaletoTarget:OnTick()
local targetOffsets = UiTransform2dBus.Event.GetOffsets(self.Properties.Target)
UiTransform2dBus.Event.SetOffsets(self.entityId, targetOffsets)
end
function ScaletoTarget:OnDeactivate()
self.tickHandler:Disconnect()
end
return ScaletoTarget
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ToggleHorizontalFitRecursive =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ToggleHorizontalFitRecursive:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function ToggleHorizontalFitRecursive:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetHorizontalFitRecursive(element, horizontalFit)
UiLayoutFitterBus.Event.SetHorizontalFit(element, horizontalFit)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetHorizontalFitRecursive(children[i], horizontalFit)
end
end
function ToggleHorizontalFitRecursive:OnCheckboxStateChange(isChecked)
SetHorizontalFitRecursive(self.Properties.ContainerElement, isChecked)
end
return ToggleHorizontalFitRecursive
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ToggleVerticalFitRecursive =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ToggleVerticalFitRecursive:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function ToggleVerticalFitRecursive:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetVerticalFitRecursive(element, verticalFit)
UiLayoutFitterBus.Event.SetVerticalFit(element, verticalFit)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetVerticalFitRecursive(children[i], verticalFit)
end
end
function ToggleVerticalFitRecursive:OnCheckboxStateChange(isChecked)
SetVerticalFitRecursive(self.Properties.ContainerElement, isChecked)
end
return ToggleVerticalFitRecursive
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local LoadCanvasButton =
{
Properties =
{
canvasName = ""
},
}
function LoadCanvasButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function LoadCanvasButton:OnDeactivate()
self.buttonHandler:Disconnect()
end
function LoadCanvasButton:OnButtonClick()
UiCanvasManagerBus.Broadcast.LoadCanvas(self.Properties.canvasName)
end
return LoadCanvasButton
@@ -0,0 +1,45 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local LoadUnloadCanvasButton =
{
Properties =
{
canvasName = ""
},
}
function LoadUnloadCanvasButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.canvasId = EntityId()
end
function LoadUnloadCanvasButton:OnDeactivate()
self.buttonHandler:Disconnect()
if (self.canvasId:IsValid()) then
UiCanvasManagerBus.Broadcast.UnloadCanvas(self.canvasId)
self.canvasId = EntityId()
end
end
function LoadUnloadCanvasButton:OnButtonClick()
if (self.canvasId:IsValid()) then
UiCanvasManagerBus.Broadcast.UnloadCanvas(self.canvasId)
self.canvasId = EntityId()
else
self.canvasId = UiCanvasManagerBus.Broadcast.LoadCanvas(self.Properties.canvasName)
end
end
return LoadUnloadCanvasButton
@@ -0,0 +1,88 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ScrollingScrollBox =
{
Properties =
{
toggleButton = {default = EntityId()},
scrollSpeed = 75.0,
},
}
function ScrollingScrollBox:OnActivate()
-- Connect to the toggle button to know when to toggle the scrolling on/off
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.Properties.toggleButton)
-- Connect to the tick bus to be able to scroll
self.tickHandler = TickBus.Connect(self, 0)
self:InitAutomatedTestEvents()
end
function ScrollingScrollBox:OnDeactivate()
-- Deactivate from the button bus
self.buttonHandler:Disconnect()
-- Deactivate from the tick bus only if we were still connected
if (self.tickHandler ~= nil) then
self.tickHandler:Disconnect()
end
self:DeInitAutomatedTestEvents()
end
function ScrollingScrollBox:OnTick(dt)
-- Scroll down according to speed and dt
local scrollOffset = UiScrollBoxBus.Event.GetScrollOffset(self.entityId)
scrollOffset.y = scrollOffset.y - self.Properties.scrollSpeed * dt
UiScrollBoxBus.Event.SetScrollOffset(self.entityId, scrollOffset)
end
function ScrollingScrollBox:OnButtonClick()
-- If we are currently connected to the tick bus
if (self.tickHandler ~= nil) then
-- Disconnect from the tick bus to toggle the scrolling off
self.tickHandler:Disconnect()
self.tickHandler = nil
-- Else if we are not currently connected to the tick bus
else
-- Connect to the tick bus to toggle the scrolling on
self.tickHandler = TickBus.Connect(self, self.entityId)
end
end
-- [Automated Testing] setup
function ScrollingScrollBox:InitAutomatedTestEvents()
self.automatedTestSetScrollValueId = GameplayNotificationId(EntityId(), "AutomatedTestScrollValue", "float");
self.automatedTestSetScrollHandler = GameplayNotificationBus.Connect(self, self.automatedTestSetScrollValueId);
end
-- [Automated Testing] event handling
function ScrollingScrollBox:OnEventBegin(value)
if (GameplayNotificationBus.GetCurrentBusId() == self.automatedTestSetScrollValueId) then
-- Toggle scrolling off first, then you can set the scroll amount
local scrollOffset = UiScrollBoxBus.Event.GetScrollOffset(self.entityId)
scrollOffset.y = value
UiScrollBoxBus.Event.SetScrollOffset(self.entityId, scrollOffset)
end
end
-- [Automated Testing] teardown
function ScrollingScrollBox:DeInitAutomatedTestEvents()
if (self.automatedTestSetScrollHandler ~= nil) then
self.automatedTestSetScrollHandler:Disconnect();
self.automatedTestSetScrollHandler = nil;
end
end
return ScrollingScrollBox
@@ -0,0 +1,64 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ChildMaskElement =
{
Properties =
{
},
}
function ChildMaskElement:OnActivate()
self.tickBusHandler = TickBus.Connect(self);
self:InitAutomatedTestEvents()
end
function ChildMaskElement:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiAnimationBus.Event.StartSequence(canvas, "Animate")
end
function ChildMaskElement:OnDeactivate()
self:DeInitAutomatedTestEvents()
end
-- [Automated Testing] setup
function ChildMaskElement:InitAutomatedTestEvents()
self.automatedTestStopMaskAnimateId = GameplayNotificationId(EntityId(), "AutomatedTestStopMaskAnimate", "float");
self.automatedTestStopMaskAnimateHandler = GameplayNotificationBus.Connect(self, self.automatedTestStopMaskAnimateId);
end
-- [Automated Testing] event handling
function ChildMaskElement:OnEventBegin(value)
if (GameplayNotificationBus.GetCurrentBusId() == self.automatedTestStopMaskAnimateId) then
local canvas = UiElementBus.Event.GetCanvas(self.entityId)
UiAnimationBus.Event.StopSequence(canvas, "Animate")
UiAnimationBus.Event.ResetSequence(canvas, "Animate")
end
end
-- [Automated Testing] teardown
function ChildMaskElement:DeInitAutomatedTestEvents()
if (self.automatedTestStopMaskAnimateHandler ~= nil) then
self.automatedTestStopMaskAnimateHandler:Disconnect();
self.automatedTestStopMaskAnimateHandler = nil;
end
end
return ChildMaskElement
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SetElementEnabledCheckbox =
{
Properties =
{
Element = {default = EntityId()},
},
}
function SetElementEnabledCheckbox:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function SetElementEnabledCheckbox:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetElementEnabledCheckbox:OnCheckboxStateChange(isChecked)
UiElementBus.Event.SetIsEnabled(self.Properties.Element, isChecked)
end
return SetElementEnabledCheckbox
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SetUseAlphaGradientCheckbox =
{
Properties =
{
Element = {default = EntityId()},
},
}
function SetUseAlphaGradientCheckbox:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function SetUseAlphaGradientCheckbox:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetUseAlphaGradientCheckbox:OnCheckboxStateChange(isChecked)
UiMaskBus.Event.SetUseRenderToTexture(self.Properties.Element, isChecked)
end
return SetUseAlphaGradientCheckbox
@@ -0,0 +1,41 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local NextCanvasButton =
{
Properties =
{
canvasName = ""
},
}
function NextCanvasButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function NextCanvasButton:OnDeactivate()
self.buttonHandler:Disconnect()
end
function NextCanvasButton:OnButtonClick()
-- Load the next canvas
UiCanvasManagerBus.Broadcast.LoadCanvas(self.Properties.canvasName)
-- Unload the current canvas
canvasId = UiElementBus.Event.GetCanvas(self.entityId)
if (canvasId:IsValid()) then
UiCanvasManagerBus.Broadcast.UnloadCanvas(canvasId)
end
end
return NextCanvasButton
@@ -0,0 +1,62 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ParticleTrailButton =
{
Properties =
{
SequenceName = {default = ""},
ButtonParticlesRoot = {default = EntityId()},
},
}
function ParticleTrailButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.tickBusHandler = TickBus.Connect(self);
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
end
function ParticleTrailButton:OnUiAnimationEvent(eventType, sequenceName)
if (eventType == eUiAnimationEvent_Stopped) then
UiInteractableBus.Event.SetIsHandlingEvents(self.entityId, true)
end
end
function ParticleTrailButton:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
self.canvasNotificationBusHandler = UiCanvasNotificationBus.Connect(self, self.canvas)
self.animHandler = UiAnimationNotificationBus.Connect(self, self.canvas)
end
function ParticleTrailButton:OnDeactivate()
self.buttonHandler:Disconnect()
self.canvasNotificationBusHandler:Disconnect()
self.animHandler:Disconnect()
end
function ParticleTrailButton:OnButtonClick()
-- Animate particle trails
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.SequenceName)
local children = UiElementBus.Event.GetChildren(self.Properties.ButtonParticlesRoot)
for i = 1,#children do
UiParticleEmitterBus.Event.SetIsEmitting(children[i], true)
end
UiInteractableBus.Event.SetIsHandlingEvents(self.entityId, false)
end
return ParticleTrailButton
@@ -0,0 +1,337 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DrawCalls =
{
Properties =
{
CanvasCheckbox = {default = EntityId()},
MaskCheckbox = {default = EntityId()},
GradientMaskCheckbox = {default = EntityId()},
RtFaderCheckbox = {default = EntityId()},
RtOuterFaderCheckbox = {default = EntityId()},
BlendModeCheckbox = {default = EntityId()},
SrgbCheckbox = {default = EntityId()},
ExceedMaxTexturesCheckbox = {default = EntityId()},
ExceedMaxVertsCheckbox = {default = EntityId()},
AnimatePosCheckbox = {default = EntityId()},
AnimateScaleCheckbox = {default = EntityId()},
AnimateRotationCheckbox = {default = EntityId()},
ParticlesCheckbox = {default = EntityId()},
InnerFaderSlider = {default = EntityId()},
OuterFaderSlider = {default = EntityId()},
DebugDisplayDropdown = {default = EntityId()},
ReportDrawCallsButton = {default = EntityId()},
},
}
function DrawCalls:OnActivate()
self.initializationHandler = UiInitializationBus.Connect(self, self.entityId);
end
function DrawCalls:InGamePostActivate()
self.initializationHandler:Disconnect()
self.initializationHandler = nil
self:SetIsCanvasLoaded(true)
-- Handlers for checkboxes
self.CanvasCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.CanvasCheckbox)
self.MaskCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.MaskCheckbox)
self.GradientMaskCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.GradientMaskCheckbox)
self.RtFaderCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.RtFaderCheckbox)
self.RtOuterFaderCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.RtOuterFaderCheckbox)
self.BlendModeCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.BlendModeCheckbox)
self.SrgbCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.SrgbCheckbox)
self.ExceedMaxTexturesCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.ExceedMaxTexturesCheckbox)
self.ExceedMaxVertsCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.ExceedMaxVertsCheckbox)
self.AnimatePosCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.AnimatePosCheckbox)
self.AnimateScaleCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.AnimateScaleCheckbox)
self.AnimateRotationCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.AnimateRotationCheckbox)
self.ParticlesCheckboxHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.ParticlesCheckbox)
self.InnerFaderSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.InnerFaderSlider)
self.OuterFaderSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.OuterFaderSlider)
self.DebugDisplayDropdownHandler = UiDropdownNotificationBus.Connect(self, self.Properties.DebugDisplayDropdown)
self.ReportDrawCallsButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.ReportDrawCallsButton)
end
function DrawCalls:OnDeactivate()
self.CanvasCheckboxHandler:Disconnect()
self.MaskCheckboxHandler:Disconnect()
self.GradientMaskCheckboxHandler:Disconnect()
self.RtFaderCheckboxHandler:Disconnect()
self.RtOuterFaderCheckboxHandler:Disconnect()
self.BlendModeCheckboxHandler:Disconnect()
self.SrgbCheckboxHandler:Disconnect()
self.ExceedMaxTexturesCheckboxHandler:Disconnect()
self.ExceedMaxVertsCheckboxHandler:Disconnect()
self.AnimatePosCheckboxHandler:Disconnect()
self.AnimateScaleCheckboxHandler:Disconnect()
self.AnimateRotationCheckboxHandler:Disconnect()
self.ParticlesCheckboxHandler:Disconnect()
self.InnerFaderSliderHandler:Disconnect()
self.OuterFaderSliderHandler:Disconnect()
self.DebugDisplayDropdownHandler:Disconnect()
self.ReportDrawCallsButtonHandler:Disconnect()
end
function DrawCalls:OnCheckboxStateChange(isChecked)
local element = UiCheckboxNotificationBus.GetCurrentBusId()
if (element == self.Properties.CanvasCheckbox) then
self:SetIsCanvasLoaded(isChecked)
elseif (not (self.exampleCanvas == nil)) then
if (element == self.Properties.MaskCheckbox) then
SetIsMaskEnabledRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.GradientMaskCheckbox) then
SetIsGradientMaskEnabledRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.RtFaderCheckbox) then
SetIsRtFaderEnabledRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.RtOuterFaderCheckbox) then
SetIsRtOuterFaderEnabled(self.exampleCanvasBackground, isChecked)
elseif (element == self.Properties.BlendModeCheckbox) then
EnableBlendModeAddRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.SrgbCheckbox) then
EnableSrgbRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.ExceedMaxTexturesCheckbox) then
EnableExtraTexturesRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.ExceedMaxVertsCheckbox) then
EnableExtraSlicesRecursive(self.performanceElements, isChecked)
elseif (element == self.Properties.AnimatePosCheckbox) then
EnableAnimatePos(self.exampleCanvas, isChecked)
elseif (element == self.Properties.AnimateScaleCheckbox) then
EnableAnimateScale(self.exampleCanvas, isChecked)
elseif (element == self.Properties.AnimateRotationCheckbox) then
EnableAnimateRotation(self.exampleCanvas, isChecked)
elseif (element == self.Properties.ParticlesCheckbox) then
EnableParticlesRecursive(self.performanceElements, isChecked)
end
end
end
function DrawCalls:OnSliderValueChanging(value)
if (not (self.exampleCanvas == nil)) then
local element = UiSliderNotificationBus.GetCurrentBusId()
if (element == self.Properties.InnerFaderSlider) then
SetInnerFaderValueRecursive(self.performanceElements, value)
elseif (element == self.Properties.OuterFaderSlider) then
SetOuterFaderValue(self.exampleCanvasBackground, value)
end
end
end
function DrawCalls:OnDropdownValueChanged(value)
local dropdownElement = UiDropdownNotificationBus.GetCurrentBusId()
if (dropdownElement == self.Properties.DebugDisplayDropdown) then
local contentElement = UiElementBus.Event.FindDescendantByName(dropdownElement, "Content")
local index = UiElementBus.Event.GetIndexOfChildByEntityId(contentElement, value)
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayDrawCallData 0")
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayTextureData 0")
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayCanvasData 0")
if (index == 0) then
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayDrawCallData 1")
elseif (index == 1) then
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayTextureData 1")
elseif (index == 2) then
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_DisplayCanvasData 1")
end
end
end
function DrawCalls:OnButtonClick()
local element = UiButtonNotificationBus.GetCurrentBusId()
if (element == self.Properties.ReportDrawCallsButton) then
ConsoleRequestBus.Broadcast.ExecuteConsoleCommand("ui_ReportDrawCalls")
end
end
function DrawCalls:SetIsCanvasLoaded(enabled)
if (enabled) then
if (self.exampleCanvas == nil) then
self.exampleCanvas = UiCanvasManagerBus.Broadcast.LoadCanvas("UI/Canvases/LyShineExamples/Performance/DrawCallsExample.uicanvas")
self.exampleCanvasBackground = UiCanvasBus.Event.FindElementByName(self.exampleCanvas, "Background");
self.performanceElements = UiCanvasBus.Event.FindElementByName(self.exampleCanvas, "PerformanceElements");
SetIsMaskEnabledRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.MaskCheckbox))
SetIsGradientMaskEnabledRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.GradientMaskCheckbox))
SetIsRtFaderEnabledRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.RtFaderCheckbox))
SetIsRtOuterFaderEnabled(self.exampleCanvasBackground, UiCheckboxBus.Event.GetState(self.Properties.RtOuterFaderCheckbox))
EnableBlendModeAddRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.BlendModeCheckbox))
EnableSrgbRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.SrgbCheckbox))
EnableExtraTexturesRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.ExceedMaxTexturesCheckbox))
EnableExtraSlicesRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.ExceedMaxVertsCheckbox))
EnableAnimatePos(self.exampleCanvas, UiCheckboxBus.Event.GetState(self.Properties.AnimatePosCheckbox))
EnableAnimateScale(self.exampleCanvas, UiCheckboxBus.Event.GetState(self.Properties.AnimateScaleCheckbox))
EnableParticlesRecursive(self.performanceElements, UiCheckboxBus.Event.GetState(self.Properties.ParticlesCheckbox))
SetInnerFaderValueRecursive(self.performanceElements, UiSliderBus.Event.GetValue(self.Properties.InnerFaderSlider))
SetOuterFaderValue(self.exampleCanvasBackground, UiSliderBus.Event.GetValue(self.Properties.OuterFaderSlider))
end
else
if (not (self.exampleCanvas == nil)) then
UiCanvasManagerBus.Broadcast.UnloadCanvas(self.exampleCanvas)
self.exampleCanvas = nil
self.exampleCanvasBackground = nil
self.performanceElements = nil
end
end
end
function SetIsMaskEnabledRecursive(element, enabled)
UiMaskBus.Event.SetIsMaskingEnabled(element, enabled)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsMaskEnabledRecursive(children[i], enabled)
end
end
function SetIsGradientMaskEnabledRecursive(element, enabled)
UiMaskBus.Event.SetUseRenderToTexture(element, enabled)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsGradientMaskEnabledRecursive(children[i], enabled)
end
end
function SetIsRtFaderEnabledRecursive(element, enabled)
UiFaderBus.Event.SetUseRenderToTexture(element, enabled)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsRtFaderEnabledRecursive(children[i], enabled)
end
end
function SetIsRtOuterFaderEnabled(element, enabled)
UiFaderBus.Event.SetUseRenderToTexture(element, enabled)
end
function EnableBlendModeAddRecursive(element, enabled)
local name = UiElementBus.Event.GetName(element)
if (name == "BlendModeNormal") then
UiElementBus.Event.SetIsEnabled(element, not enabled)
elseif (name == "BlendModeAdd") then
UiElementBus.Event.SetIsEnabled(element, enabled)
end
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
EnableBlendModeAddRecursive(children[i], enabled)
end
end
function EnableSrgbRecursive(element, enabled)
local name = UiElementBus.Event.GetName(element)
if (name == "RttImage") then
UiImageBus.Event.SetIsRenderTargetSRGB(element, enabled)
end
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
EnableSrgbRecursive(children[i], enabled)
end
end
function EnableExtraTexturesRecursive(element, enabled)
local name = UiElementBus.Event.GetName(element)
if (name == "ImageTexture17" or name == "ImageTexture18") then
UiElementBus.Event.SetIsEnabled(element, enabled)
end
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
EnableExtraTexturesRecursive(children[i], enabled)
end
end
function EnableExtraSlicesRecursive(element, enabled)
local name = UiElementBus.Event.GetName(element)
if (name == "AdditionalPerformanceRows") then
UiElementBus.Event.SetIsEnabled(element, enabled)
end
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
EnableExtraSlicesRecursive(children[i], enabled)
end
end
function EnableAnimatePos(canvas, enabled)
if (enabled) then
UiAnimationBus.Event.StartSequence(canvas, "AnimatePos")
else
UiAnimationBus.Event.StopSequence(canvas, "AnimatePos")
end
end
function EnableAnimateScale(canvas, enabled)
if (enabled) then
UiAnimationBus.Event.StartSequence(canvas, "AnimateScale")
else
UiAnimationBus.Event.StopSequence(canvas, "AnimateScale")
end
end
function EnableAnimateRotation(canvas, enabled)
if (enabled) then
UiAnimationBus.Event.StartSequence(canvas, "AnimateRot")
else
UiAnimationBus.Event.StopSequence(canvas, "AnimateRot")
end
end
function EnableParticlesRecursive(element, enabled)
local name = UiElementBus.Event.GetName(element)
if (name == "ParticleEmitter") then
UiElementBus.Event.SetIsEnabled(element, enabled)
end
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
EnableParticlesRecursive(children[i], enabled)
end
end
function SetInnerFaderValueRecursive(element, value)
UiFaderBus.Event.SetFadeValue(element, value)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetInnerFaderValueRecursive(children[i], value)
end
end
function SetOuterFaderValue(element, value)
UiFaderBus.Event.SetFadeValue(element, value)
end
return DrawCalls
@@ -0,0 +1,49 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SwitchGroup =
{
Properties =
{
LeftGroup = {default = EntityId()},
RightGroup = {default = EntityId()},
SwitchButton = {default = EntityId()},
SwitchButtonText = {default = EntityId()},
},
}
function SwitchGroup:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.isInLeft = true
end
function SwitchGroup:OnButtonClick()
if (self.isInLeft) then
UiRadioButtonGroupBus.Event.RemoveRadioButton(self.Properties.LeftGroup, self.Properties.SwitchButton)
UiRadioButtonGroupBus.Event.AddRadioButton(self.Properties.RightGroup, self.Properties.SwitchButton)
UiTextBus.Event.SetColor(self.Properties.SwitchButtonText, Color(0, 0, 1))
self.isInLeft = false
else
UiRadioButtonGroupBus.Event.RemoveRadioButton(self.Properties.RightGroup, self.Properties.SwitchButton)
UiRadioButtonGroupBus.Event.AddRadioButton(self.Properties.LeftGroup, self.Properties.SwitchButton)
UiTextBus.Event.SetColor(self.Properties.SwitchButtonText, Color(1, 0, 0))
self.isInLeft = true
end
end
function SwitchGroup:OnDeactivate()
self.buttonHandler:Disconnect()
end
return SwitchGroup
@@ -0,0 +1,42 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ChangeValues =
{
Properties =
{
CurrentValue = {default = EntityId()},
ChangedValue = {default = EntityId()},
},
}
function ChangeValues:OnActivate()
self.scrollBarHandler = UiScrollerNotificationBus.Connect(self, self.entityId)
end
function ChangeValues:OnDeactivate()
self.scrollBarHandler:Disconnect()
end
function ChangeValues:OnScrollerValueChanged(value)
local formattedValue = string.format("%.2f", value)
UiTextBus.Event.SetText(self.Properties.ChangedValue, formattedValue)
end
function ChangeValues:OnScrollerValueChanging(value)
local formattedValue = string.format("%.2f", value)
UiTextBus.Event.SetText(self.Properties.CurrentValue, formattedValue)
end
return ChangeValues
@@ -0,0 +1,107 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ZoomSlider =
{
Properties =
{
ScrollBox = {default = EntityId()},
Content = {default = EntityId()},
MaxZoomMultiplier = {default = 2, min = 1, description = "How much the map can be zoomed in at its maximum zoom (multiplier)."},
MinZoomMultiplier = {default = 0.5, min = 0.1, max = 1, description = "How much the map can be zoomed out at its minimum zoom (multiplier)."},
},
}
function ZoomSlider:OnActivate()
-- Connect to the slider notification bus
self.sliderHandler = UiSliderNotificationBus.Connect(self, self.entityId)
-- Initialize first zoom
self.currentZoom = 1.0
end
function ZoomSlider:OnDeactivate()
-- Deactivate from the slider notification bus only if we managed to connect
if (self.sliderHandler ~= nil) then
self.sliderHandler:Disconnect()
end
end
-- Multiply an offset by a number
function MultiplyOffset(offset, multiplier)
local newOffset = UiOffsets()
newOffset.bottom = offset.bottom * multiplier
newOffset.left = offset.left * multiplier
newOffset.right = offset.right * multiplier
newOffset.top = offset.top * multiplier
return newOffset
end
-- Multiply a Vector2 by a number
function MultiplyVec2(vector, multiplier)
local newVector = Vector2(0, 0)
newVector.x = vector.x * multiplier
newVector.y = vector.y * multiplier
return newVector
end
function ZoomSlider:OnSliderValueChanging(percent)
-- Recompute the base offsets and scrollOffsets based on our current zoom (offsets change both the position and the scale)
local baseOffsets = UiTransform2dBus.Event.GetOffsets(self.Properties.Content)
baseOffsets = MultiplyOffset(baseOffsets, 1 / self.currentZoom) -- current zoom will never be 0 due to property min
local baseScrollOffsets = UiScrollBoxBus.Event.GetScrollOffset(self.Properties.ScrollBox)
baseScrollOffsets = MultiplyVec2(baseScrollOffsets, 1 / self.currentZoom)
-- Then recompute min and max offsets based on new base offsets
local minOffsets = MultiplyOffset(baseOffsets, self.Properties.MinZoomMultiplier)
local maxOffsets = MultiplyOffset(baseOffsets, self.Properties.MaxZoomMultiplier)
local minScrollOffsets = MultiplyVec2(baseScrollOffsets, self.Properties.MinZoomMultiplier)
local maxScrollOffsets = MultiplyVec2(baseScrollOffsets, self.Properties.MaxZoomMultiplier)
-- Calculate new offsets based on percentage of slider ( x = (max - min) * percentage + min )
-- Content offsets
-- (max - min)
local newOffset = UiOffsets()
newOffset.bottom = maxOffsets.bottom - minOffsets.bottom
newOffset.left = maxOffsets.left - minOffsets.left
newOffset.right = maxOffsets.right - minOffsets.right
newOffset.top = maxOffsets.top - minOffsets.top
-- * percentage
newOffset = MultiplyOffset(newOffset, percent / 100)
-- + min
newOffset.bottom = newOffset.bottom + minOffsets.bottom
newOffset.left = newOffset.left + minOffsets.left
newOffset.right = newOffset.right + minOffsets.right
newOffset.top = newOffset.top + minOffsets.top
-- Scroll offsets
-- (max - min)
local newScrollOffset = Vector2(0, 0)
newScrollOffset.x = maxScrollOffsets.x - minScrollOffsets.x
newScrollOffset.y = maxScrollOffsets.y - minScrollOffsets.y
-- * percentage
newScrollOffset = MultiplyVec2(newScrollOffset, percent / 100)
-- + min
newScrollOffset.x = newScrollOffset.x + minScrollOffsets.x
newScrollOffset.y = newScrollOffset.y + minScrollOffsets.y
-- Set the map offsets to the newly calculated offsets
UiTransform2dBus.Event.SetOffsets(self.Properties.Content, newOffset)
-- Set the scrollbox offsets to the newly calculated scroll offsets
UiScrollBoxBus.Event.SetScrollOffset(self.Properties.ScrollBox, newScrollOffset)
-- Update the zoom level
self.currentZoom = (self.Properties.MaxZoomMultiplier - self.Properties.MinZoomMultiplier) * percent / 100 + self.Properties.MinZoomMultiplier
end
return ZoomSlider
@@ -0,0 +1,36 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SetTextFromInput =
{
Properties =
{
TextToSet = {default = EntityId()},
},
}
function SetTextFromInput:OnActivate()
self.textInputHandler = UiTextInputNotificationBus.Connect(self, self.entityId)
end
function SetTextFromInput:OnDeactivate()
self.textInputHandler:Disconnect()
end
function SetTextFromInput:OnTextInputEndEdit(textString)
UiTextBus.Event.SetText(self.Properties.TextToSet, textString)
UiTextInputBus.Event.SetText(self.entityId, "")
end
return SetTextFromInput
@@ -0,0 +1,41 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ShowAndInputEnableElementButton =
{
Properties =
{
HelpElement = {default = EntityId()},
},
}
function ShowAndInputEnableElementButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function ShowAndInputEnableElementButton:OnDeactivate()
self.buttonHandler:Disconnect()
end
function ShowAndInputEnableElementButton:OnButtonClick()
if UiElementBus.Event.IsEnabled(self.Properties.HelpElement) then
UiElementBus.Event.SetIsEnabled(self.Properties.HelpElement, false)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.HelpElement, false)
else
UiElementBus.Event.SetIsEnabled(self.Properties.HelpElement, true)
UiInteractableBus.Event.SetIsHandlingEvents(self.Properties.HelpElement, true)
end
end
return ShowAndInputEnableElementButton
@@ -0,0 +1,50 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SliderWithButtons =
{
Properties =
{
MinusButton = {default = EntityId()},
PlusButton = {default = EntityId()},
Slider = {default = EntityId()},
},
}
function SliderWithButtons:OnActivate()
self.minusButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.MinusButton)
self.plusButtonHandler = UiButtonNotificationBus.Connect(self, self.Properties.PlusButton)
end
function SliderWithButtons:OnDeactivate()
self.minusButtonHandler:Disconnect()
self.plusButtonHandler:Disconnect()
end
function SliderWithButtons:OnButtonClick()
local curValue = UiSliderBus.Event.GetValue(self.Properties.Slider)
local stepValue = UiSliderBus.Event.GetStepValue(self.Properties.Slider)
if (stepValue <= 0) then
stepValue = 10
end
if (UiButtonNotificationBus.GetCurrentBusId() == self.Properties.MinusButton) then
UiSliderBus.Event.SetValue(self.Properties.Slider, curValue - stepValue)
else
UiSliderBus.Event.SetValue(self.Properties.Slider, curValue + stepValue)
end
end
return SliderWithButtons
@@ -0,0 +1,40 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local DeleteElements =
{
Properties =
{
ParentElement = {default = EntityId()},
},
}
function DeleteElements:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function DeleteElements:OnDeactivate()
self.buttonHandler:Disconnect()
end
function DeleteElements:OnButtonClick()
local children = UiElementBus.Event.GetChildren(self.Properties.ParentElement)
if children then
for i = 1,#children do
UiElementBus.Event.DestroyElement(children[i])
end
end
end
return DeleteElements
@@ -0,0 +1,156 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local RadioButtonSpawner =
{
Properties =
{
SpawnerElement = {default = EntityId()},
ColorsButton = {default = EntityId()},
ShapesButton = {default = EntityId()},
PatternsButton = {default = EntityId()},
},
}
function RadioButtonSpawner:OnActivate()
self.interactableHandler = UiRadioButtonGroupNotificationBus.Connect(self, self.entityId)
self.spawnsPending = 0
-- connect to the tickbus in order to set the right badio button group correctly for the
-- starting selection on the left radio button group. We do this on the next frame after everything
-- has been activated.
self.tickBusHandler = TickBus.Connect(self)
end
function RadioButtonSpawner:OnDeactivate()
self.interactableHandler:Disconnect()
end
function RadioButtonSpawner:OnTick()
local activeButton = UiRadioButtonGroupBus.Event.GetState(self.entityId)
self:SpawnRadioButtons(activeButton)
self.tickBusHandler:Disconnect()
end
function RadioButtonSpawner:OnRadioButtonGroupStateChange(activeButton)
self:SpawnRadioButtons(activeButton)
end
function RadioButtonSpawner:OnTopLevelEntitiesSpawned(ticket, ids)
-- we could do this in OnSpawnEnd but this is a convenient way to add each top-level element
-- spawned to be part of the radio button group. There is only one top-level element in the
-- dynamic slice and we know it is the radio button
for i = 1,#ids do
local parent = UiElementBus.Event.GetParent(ids[i])
if parent == self.Properties.SpawnerElement then
UiRadioButtonGroupBus.Event.AddRadioButton(self.Properties.SpawnerElement, ids[i])
end
end
end
function RadioButtonSpawner:OnSpawnEnd(ticket)
self.spawnsPending = self.spawnsPending - 1
if self.spawnsPending == 0 then
self.spawnerHandler:Disconnect()
-- The spawns are completed
local activeButton = UiRadioButtonGroupBus.Event.GetState(self.entityId)
-- get the children that were spawned
local children = UiElementBus.Event.GetChildren(self.Properties.SpawnerElement)
if activeButton == self.Properties.ColorsButton then
if #children == 4 then
self:SetRadioButtonText(children[1], "Red")
self:SetRadioButtonText(children[2], "Green")
self:SetRadioButtonText(children[3], "Blue")
self:SetRadioButtonText(children[4], "Yellow")
end
elseif activeButton == self.Properties.ShapesButton then
if #children == 3 then
self:SetRadioButtonText(children[1], "Circle")
self:SetRadioButtonText(children[2], "Triangle")
self:SetRadioButtonText(children[3], "Square")
end
elseif activeButton == self.Properties.PatternsButton then
if #children == 2 then
self:SetRadioButtonText(children[1], "Stripes")
self:SetRadioButtonText(children[2], "Crosshatch")
end
end
-- set the first one in the group to be active
if #children > 0 then
UiRadioButtonGroupBus.Event.SetState(self.Properties.SpawnerElement, children[1], true)
end
end
end
function RadioButtonSpawner:OnSpawnFailed(ticket)
self.spawnsPending = self.spawnsPending - 1
if self.spawnsPending == 0 then
self.spawnerHandler:Disconnect()
end
end
function RadioButtonSpawner:SpawnRadioButtons(activeButton)
if self.spawnsPending == 0 then
-- remove the existing children of the SpawnerElement (the right radio button group)
local children = UiElementBus.Event.GetChildren(self.Properties.SpawnerElement)
if children then
for i = 1,#children do
UiElementBus.Event.DestroyElement(children[i])
end
end
-- depending on which button is active in the left radio button group, we spawn the required
-- number of radio buttons. They will automatically become children of the SpawnerElement
-- (the right radio button group) but not automatically part of the radio button group.
local numButtonsToSpawn = 0
if activeButton == self.Properties.ColorsButton then
numButtonsToSpawn = 4
elseif activeButton == self.Properties.ShapesButton then
numButtonsToSpawn = 3
elseif activeButton == self.Properties.PatternsButton then
numButtonsToSpawn = 2
end
if numButtonsToSpawn > 0 then
self.spawnerHandler = UiSpawnerNotificationBus.Connect(self, self.Properties.SpawnerElement)
end
-- spawn the required number of radio buttons
for i = 1,numButtonsToSpawn do
UiSpawnerBus.Event.Spawn(self.Properties.SpawnerElement)
end
self.spawnsPending = numButtonsToSpawn
end
end
-- Helper function to set the text on a child component of the radio button.
-- We know that the radio button element in our dynamic slice has a child called "Text"
function RadioButtonSpawner:SetRadioButtonText(rb, value)
local textEntity = UiElementBus.Event.FindChildByName(rb, "Text")
if (textEntity and textEntity:IsValid()) then
UiTextBus.Event.SetText(textEntity, value)
end
end
return RadioButtonSpawner
@@ -0,0 +1,88 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local Spawn3Elements =
{
Properties =
{
SpawnerElement = {default = EntityId()},
},
}
function Spawn3Elements:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.spawnsPending = 0
self.spawnTicket1 = nil
self.spawnTicket2 = nil
self.spawnTicket3 = nil
end
function Spawn3Elements:OnDeactivate()
self.buttonHandler:Disconnect()
end
function Spawn3Elements:OnButtonClick()
if self.spawnTicket1 == nil and self.spawnTicket2 == nil and self.spawnTicket3 == nil then
self.spawnerHandler = UiSpawnerNotificationBus.Connect(self, self.Properties.SpawnerElement)
self.spawnTicket1 = UiSpawnerBus.Event.Spawn(self.Properties.SpawnerElement)
self.spawnTicket2 = UiSpawnerBus.Event.Spawn(self.Properties.SpawnerElement)
self.spawnTicket3 = UiSpawnerBus.Event.Spawn(self.Properties.SpawnerElement)
self.spawnsPending = 3
end
end
function Spawn3Elements:OnTopLevelEntitiesSpawned(ticket, ids)
if ticket == self.spawnTicket1 or ticket == self.spawnTicket2 or ticket == self.spawnTicket3 then
local color = Color(0, 0, 0)
if ticket == self.spawnTicket1 then
color = Color(1, 0, 0)
elseif ticket == self.spawnTicket2 then
color = Color(0, 1, 0)
elseif ticket == self.spawnTicket3 then
color = Color(0, 0, 1)
end
for i = 1,#ids do
local parent = UiElementBus.Event.GetParent(ids[i])
if parent == self.Properties.SpawnerElement then
UiImageBus.Event.SetColor(ids[i], color)
end
end
self.spawnsPending = self.spawnsPending - 1
if self.spawnsPending == 0 then
self.spawnerHandler:Disconnect()
self.spawnTicket1 = nil
self.spawnTicket2 = nil
self.spawnTicket3 = nil
end
end
end
function Spawn3Elements:OnSpawnFailed(ticket)
if ticket == self.spawnTicket1 or ticket == self.spawnTicket2 or ticket == self.spawnTicket3 then
self.spawnsPending = self.spawnsPending - 1
if self.spawnsPending == 0 then
self.spawnerHandler:Disconnect()
self.spawnTicket1 = nil
self.spawnTicket2 = nil
self.spawnTicket3 = nil
end
end
end
return Spawn3Elements
@@ -0,0 +1,65 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local SpawnElements =
{
Properties =
{
SpawnerElement = {default = EntityId()},
},
}
function SpawnElements:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
self.spawnTicket = nil
end
function SpawnElements:OnDeactivate()
self.buttonHandler:Disconnect()
end
function SpawnElements:OnButtonClick()
-- don't spawn another dynamic slice until we have processed the last one
if self.spawnTicket == nil then
self.spawnerHandler = UiSpawnerNotificationBus.Connect(self, self.Properties.SpawnerElement)
self.spawnTicket = UiSpawnerBus.Event.Spawn(self.Properties.SpawnerElement)
end
end
function SpawnElements:OnEntitySpawned(ticket, id)
if ticket == self.spawnTicket then
-- this could be the image element or the child text element.
-- But we just set all images to yellow and all texts to black.
-- Alternatively we could use OnTopLevelEntitiesSpawned and
-- just get the image element and then get its child.
UiImageBus.Event.SetColor(id, Color(1, 1, 0))
UiTextBus.Event.SetColor(id, Color(0, 0, 0))
end
end
function SpawnElements:OnSpawnEnd(ticket)
if ticket == self.spawnTicket then
self.spawnerHandler:Disconnect()
self.spawnTicket = nil
end
end
function SpawnElements:OnSpawnFailed(ticket)
if ticket == self.spawnTicket then
self.spawnerHandler:Disconnect()
self.spawnTicket = nil
end
end
return SpawnElements
@@ -0,0 +1,51 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local FontSizeSlider =
{
Properties =
{
RerenderedFontEntity = {default = EntityId()},
FontEntity = {default = EntityId()},
},
}
function FontSizeSlider:OnActivate()
-- Connect to the slider notification bus
self.sliderHandler = UiSliderNotificationBus.Connect(self, self.entityId)
end
function FontSizeSlider:OnDeactivate()
-- Deactivate from the slider notification bus
self.sliderHandler:Disconnect()
end
function UpdateFontSize(entity, percent)
-- Resize the font
UiTextBus.Event.SetFontSize(entity, 12 + percent)
end
function FontSizeSlider:OnSliderValueChanging(percent)
-- Set the size value to the slider value
UpdateFontSize(self.Properties.RerenderedFontEntity, percent)
UpdateFontSize(self.Properties.FontEntity, percent)
end
function FontSizeSlider:OnSliderValueChanged(percent)
-- Set the size value to the slider value
UpdateFontSize(self.Properties.RerenderedFontEntity, percent)
UpdateFontSize(self.Properties.FontEntity, percent)
end
return FontSizeSlider
@@ -0,0 +1,218 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ImageMarkup =
{
Properties =
{
AttribInteractables = { default = { EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId() } },
AttribEnabledCBs = { default = { EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId(), EntityId() } },
VAlignDDContent = {default = EntityId()},
HeightDDContent = {default = EntityId()},
DefaultsButton = {default = EntityId()},
MarkupText = {default = EntityId()},
},
-- Attributes
vAlignIndex = 1,
heightIndex = 2,
scaleIndex = 3,
yOffsetIndex = 4,
xPaddingIndex = 5,
lPaddingIndex = 6,
rPaddingIndex = 7,
numAttributes = 7,
-- Attribute names
attribNames = { "vAlign", "height", "scale", "yOffset", "xPadding", "lPadding", "rPadding" },
-- Attribute default values
attribDefaults = { "baseline", "fontAscent", 1, 0, 0, 0, 0 },
-- Attribute current values
curAttribValues = {},
}
function ImageMarkup:OnActivate()
self.notificationHandlers = {}
self.notificationHandlers[#self.notificationHandlers + 1] = UiButtonNotificationBus.Connect(self, self.Properties.DefaultsButton)
self.notificationHandlers[#self.notificationHandlers + 1] = UiDropdownNotificationBus.Connect(self, self:GetAttribInteractable(self.vAlignIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiDropdownNotificationBus.Connect(self, self:GetAttribInteractable(self.heightIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiSliderNotificationBus.Connect(self, self:GetAttribInteractable(self.scaleIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiSliderNotificationBus.Connect(self, self:GetAttribInteractable(self.yOffsetIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiSliderNotificationBus.Connect(self, self:GetAttribInteractable(self.xPaddingIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiSliderNotificationBus.Connect(self, self:GetAttribInteractable(self.lPaddingIndex))
self.notificationHandlers[#self.notificationHandlers + 1] = UiSliderNotificationBus.Connect(self, self:GetAttribInteractable(self.rPaddingIndex))
for i = 0, self.numAttributes - 1 do
self.notificationHandlers[#self.notificationHandlers + 1] = UiCheckboxNotificationBus.Connect(self, self.Properties.AttribEnabledCBs[i])
end
self.tickBusHandler = TickBus.Connect(self);
end
function ImageMarkup:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.vAlignOptions = {}
local numOptions = UiElementBus.Event.GetNumChildElements(self.Properties.VAlignDDContent)
for i = 0, numOptions - 1 do
local child = UiElementBus.Event.GetChild(self.Properties.VAlignDDContent, i)
local name = UiElementBus.Event.GetName(child)
self.vAlignOptions[name] = child
end
self.heightOptions = {}
numOptions = UiElementBus.Event.GetNumChildElements(self.Properties.HeightDDContent)
for i = 0, numOptions - 1 do
local child = UiElementBus.Event.GetChild(self.Properties.HeightDDContent, i)
local name = UiElementBus.Event.GetName(child)
self.heightOptions[name] = child
end
self:SetToDefaults()
end
function ImageMarkup:OnDeactivate()
for index, handler in ipairs(self.notificationHandlers) do
handler:Disconnect()
end
end
function ImageMarkup:GetAttribInteractable(index)
return self.Properties.AttribInteractables[index - 1]
end
function ImageMarkup:GetAttribIndexFromCheckbox(checkbox)
for i = 1, self.numAttributes do
if self.Properties.AttribEnabledCBs[i - 1] == checkbox then
return i
end
end
return -1
end
function ImageMarkup:GetAttribIndexFromInteractable(interactable)
for i = 1, self.numAttributes do
if self:GetAttribInteractable(i) == interactable then
return i
end
end
return -1
end
function ImageMarkup:SetToDefaults()
for i = 1, self.numAttributes do
self.curAttribValues[i] = self.attribDefaults[i]
end
UiDropdownBus.Event.SetValue(self:GetAttribInteractable(self.vAlignIndex), self.vAlignOptions[self.curAttribValues[self.vAlignIndex]])
UiRadioButtonGroupBus.Event.SetState(self.Properties.VAlignDDContent, self.vAlignOptions[self.attribDefaults[self.vAlignIndex]], true)
UiDropdownBus.Event.SetValue(self:GetAttribInteractable(self.heightIndex), self.heightOptions[self.curAttribValues[self.heightIndex]])
UiRadioButtonGroupBus.Event.SetState(self.Properties.HeightDDContent, self.heightOptions[self.attribDefaults[self.heightIndex]], true)
UiSliderBus.Event.SetValue(self:GetAttribInteractable(self.scaleIndex), self.curAttribValues[self.scaleIndex])
UiSliderBus.Event.SetValue(self:GetAttribInteractable(self.yOffsetIndex), self.curAttribValues[self.yOffsetIndex])
UiSliderBus.Event.SetValue(self:GetAttribInteractable(self.xPaddingIndex), self.curAttribValues[self.xPaddingIndex])
UiSliderBus.Event.SetValue(self:GetAttribInteractable(self.lPaddingIndex), self.curAttribValues[self.lPaddingIndex])
UiSliderBus.Event.SetValue(self:GetAttribInteractable(self.rPaddingIndex), self.curAttribValues[self.rPaddingIndex])
self:SetCheckboxState(self.Properties.AttribEnabledCBs[self.lPaddingIndex - 1], false)
self:SetCheckboxState(self.Properties.AttribEnabledCBs[self.rPaddingIndex - 1], false)
self:UpdateMarkupText()
end
function ImageMarkup:GetImageTagText(imagePath)
local tagText = "<img src=" .. '\"' .. imagePath .. '\"'
local attribsString = ""
for i = 1, self.numAttributes do
local enabled = UiInteractableBus.Event.IsHandlingEvents(self:GetAttribInteractable(i))
if enabled then
if self.curAttribValues[i] ~= self.attribDefaults[i] or i > self.xPaddingIndex then
attribsString = attribsString .. ' ' .. self.attribNames[i] .. '=' .. '\"' .. self.curAttribValues[i] .. '\"'
end
end
end
tagText = tagText .. attribsString .. "/>"
return tagText
end
function ImageMarkup:UpdateMarkupText()
local image1TagText = self:GetImageTagText("UI/Textures/LyShineExamples/scroll_box_icon_4")
local image2TagText = self:GetImageTagText("UI/Textures/LyShineExamples/scroll_box_icon_3")
local markupText = "This text" .. image1TagText .. "contains images using the attribute" .. image2TagText .. "values above."
UiTextBus.Event.SetText(self.Properties.MarkupText, markupText)
end
function ImageMarkup:HandleCheckboxStateChange(checkbox, checked)
local attribIndex = self:GetAttribIndexFromCheckbox(checkbox)
UiInteractableBus.Event.SetIsHandlingEvents(self:GetAttribInteractable(attribIndex), checked)
end
function ImageMarkup:SetCheckboxState(checkbox, checked)
UiCheckboxBus.Event.SetState(checkbox, checked)
self:HandleCheckboxStateChange(checkbox, checked)
end
-- Button handlers
function ImageMarkup:OnButtonClick()
self:SetToDefaults()
end
-- Dropdown handlers
function ImageMarkup:OnDropdownValueChanged(entityId)
local dropdown = UiDropdownNotificationBus.GetCurrentBusId()
local attribIndex = self:GetAttribIndexFromInteractable(dropdown)
self.curAttribValues[attribIndex] = UiElementBus.Event.GetName(entityId)
self:UpdateMarkupText()
end
-- Slider handlers
function ImageMarkup:OnSliderValueChanging(value)
self:OnSliderValueChanged(value)
end
function ImageMarkup:OnSliderValueChanged(value)
local slider = UiSliderNotificationBus.GetCurrentBusId()
local attribIndex = self:GetAttribIndexFromInteractable(slider)
local roundedValue = tonumber(string.format("%.2f", value))
self.curAttribValues[attribIndex] = roundedValue
self:UpdateMarkupText()
end
-- Checkbox handlers
function ImageMarkup:OnCheckboxStateChange(checked)
local checkbox = UiCheckboxNotificationBus.GetCurrentBusId()
self:HandleCheckboxStateChange(checkbox, checked)
self:UpdateMarkupText()
end
return ImageMarkup
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local MarkupCheckBox =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function MarkupCheckBox:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function MarkupCheckBox:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetIsMarkupEnabledRecursive(element, isMarkupEnabled)
UiTextBus.Event.SetIsMarkupEnabled(element, isMarkupEnabled)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsMarkupEnabledRecursive(children[i], isMarkupEnabled)
end
end
function MarkupCheckBox:OnCheckboxStateChange(isChecked)
SetIsMarkupEnabledRecursive(self.Properties.ContainerElement, isChecked)
end
return MarkupCheckBox
@@ -0,0 +1,45 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local OverflowModeDropdrown =
{
Properties =
{
TextContent = {default = EntityId()},
Overflow = {default = EntityId()},
ClipText = {default = EntityId()},
Ellipsis = {default = EntityId()},
},
}
function OverflowModeDropdrown:OnActivate()
self.radioButtonGroupBusHandler = UiRadioButtonGroupNotificationBus.Connect(self, self.entityId);
end
function OverflowModeDropdrown:OnRadioButtonGroupStateChange(checkedRadioButton)
if (checkedRadioButton == self.Properties.Overflow) then
UiTextBus.Event.SetOverflowMode(self.Properties.TextContent, eUiTextOverflowMode_OverflowText)
elseif (checkedRadioButton == self.Properties.ClipText) then
UiTextBus.Event.SetOverflowMode(self.Properties.TextContent, eUiTextOverflowMode_ClipText)
else
UiTextBus.Event.SetOverflowMode(self.Properties.TextContent, eUiTextOverflowMode_Ellipsis)
end
end
function OverflowModeDropdrown:OnDeactivate()
self.radioButtonGroupBusHandler:Disconnect()
end
return OverflowModeDropdrown
@@ -0,0 +1,67 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local OverflowTextAnimate =
{
Properties =
{
OverflowText = {default = EntityId()},
},
}
function OverflowTextAnimate:OnActivate()
self.tickBusHandler = TickBus.Connect(self)
self.ScriptedEntityTweener = require("Scripts.ScriptedEntityTweener.ScriptedEntityTweener")
self.ScriptedEntityTweener:OnActivate()
self.timeline = self.ScriptedEntityTweener:TimelineCreate()
end
function OverflowTextAnimate:OnTick(deltaTime, timePoint)
-- Disconnect from the tick bus
self.tickBusHandler:Disconnect()
-- Start animating element size on loop
local elementScaleFactor = 0.6
local elementWidth = UiTransform2dBus.Event.GetLocalWidth(self.Properties.OverflowText)
local elementHeight = UiTransform2dBus.Event.GetLocalHeight(self.Properties.OverflowText)
self.timeline:Add(self.Properties.OverflowText, 0,
{
["w"] = elementWidth,
["h"] = elementHeight
})
self.timeline:Add(self.Properties.OverflowText, 3,
{
ease = "SineInOut",
["w"] = elementWidth * elementScaleFactor,
["h"] = elementHeight * elementScaleFactor,
})
self.timeline:Add(self.Properties.OverflowText, 3,
{
ease = "SineInOut",
["w"] = elementWidth,
["h"] = elementHeight,
onComplete = function() self.timeline:Play() end
})
-- Start the timeline
self.timeline:Play()
end
function OverflowTextAnimate:OnDeactivate()
self.ScriptedEntityTweener:TimelineDestroy(self.timeline)
self.ScriptedEntityTweener:OnDeactivate()
end
return OverflowTextAnimate
@@ -0,0 +1,40 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local PlayAnimationOnStart =
{
Properties =
{
AnimName = {default = ""},
},
}
function PlayAnimationOnStart:OnActivate()
self.tickBusHandler = TickBus.Connect(self);
end
function PlayAnimationOnStart:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
-- Start the idle button sequence
UiAnimationBus.Event.StartSequence(self.canvas, self.Properties.AnimName)
end
function PlayAnimationOnStart:OnDeactivate()
end
return PlayAnimationOnStart
@@ -0,0 +1,45 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ShrinkToFitDropdown =
{
Properties =
{
TextContent = {default = EntityId()},
NoneOption = {default = EntityId()},
UniformOption = {default = EntityId()},
WidthOnlyOption = {default = EntityId()},
},
}
function ShrinkToFitDropdown:OnActivate()
self.radioButtonGroupBusHandler = UiRadioButtonGroupNotificationBus.Connect(self, self.entityId);
end
function ShrinkToFitDropdown:OnRadioButtonGroupStateChange(checkedRadioButton)
if (checkedRadioButton == self.Properties.NoneOption) then
UiTextBus.Event.SetShrinkToFit(self.Properties.TextContent, eUiTextShrinkToFit_None)
elseif (checkedRadioButton == self.Properties.UniformOption) then
UiTextBus.Event.SetShrinkToFit(self.Properties.TextContent, eUiTextShrinkToFit_Uniform)
elseif (checkedRadioButton == self.Properties.WidthOnlyOption) then
UiTextBus.Event.SetShrinkToFit(self.Properties.TextContent, eUiTextShrinkToFit_WidthOnly)
end
end
function ShrinkToFitDropdown:OnDeactivate()
self.radioButtonGroupBusHandler:Disconnect()
end
return ShrinkToFitDropdown
@@ -0,0 +1,67 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local StylingMarkupLinkText =
{
Properties =
{
ClickDataText = {default = EntityId()},
},
}
function StylingMarkupLinkText:OnActivate()
self.markupButtonNotificationBusHandler = UiMarkupButtonNotificationsBus.Connect(self, self.entityId);
self.ScriptedEntityTweener = require("Scripts.ScriptedEntityTweener.ScriptedEntityTweener")
self.ScriptedEntityTweener:OnActivate()
self.timeline = self.ScriptedEntityTweener:TimelineCreate()
self.initializationHandler = UiInitializationBus.Connect(self, self.entityId);
end
function StylingMarkupLinkText:InGamePostActivate()
self.initializationHandler:Disconnect()
self.initializationHandler = nil
-- The clickable link text description will scale out of view (down to zero scale)
-- via animation.
self.timeline:Add(self.Properties.ClickDataText, 0,
{
["scaleX"] = 1.0,
["scaleY"] = 1.0
})
self.timeline:Add(self.Properties.ClickDataText, 1,
{
delay = 2.0,
ease = "SineInOut",
["scaleX"] = 0.0,
["scaleY"] = 0.0,
})
end
function StylingMarkupLinkText:OnClick(linkId, action, data)
UiTextBus.Event.SetText(self.Properties.ClickDataText, "Link clicked: action = " .. action .. ", data = " .. data)
-- Start the timeline
self.timeline:Play()
end
function StylingMarkupLinkText:OnDeactivate()
self.markupButtonNotificationBusHandler:Disconnect()
self.ScriptedEntityTweener:TimelineDestroy(self.timeline)
self.ScriptedEntityTweener:OnDeactivate()
end
return StylingMarkupLinkText
@@ -0,0 +1,42 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local WrapTextDropdown =
{
Properties =
{
TextContent = {default = EntityId()},
NoWrapOption = {default = EntityId()},
WrapTextOption = {default = EntityId()},
},
}
function WrapTextDropdown:OnActivate()
self.radioButtonGroupBusHandler = UiRadioButtonGroupNotificationBus.Connect(self, self.entityId);
end
function WrapTextDropdown:OnRadioButtonGroupStateChange(checkedRadioButton)
if (checkedRadioButton == self.Properties.NoWrapOption) then
UiTextBus.Event.SetWrapText(self.Properties.TextContent, eUiTextWrapTextSetting_NoWrap)
elseif (checkedRadioButton == self.Properties.WrapTextOption) then
UiTextBus.Event.SetWrapText(self.Properties.TextContent, eUiTextWrapTextSetting_Wrap)
end
end
function WrapTextDropdown:OnDeactivate()
self.radioButtonGroupBusHandler:Disconnect()
end
return WrapTextDropdown
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ToggleInputEnabledOnElementChildren =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ToggleInputEnabledOnElementChildren:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function ToggleInputEnabledOnElementChildren:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetIsHandlingEventsRecursive(element, isHandlingEvents)
UiInteractableBus.Event.SetIsHandlingEvents(element, isHandlingEvents)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsHandlingEventsRecursive(children[i], isHandlingEvents)
end
end
function ToggleInputEnabledOnElementChildren:OnCheckboxStateChange(isChecked)
SetIsHandlingEventsRecursive(self.Properties.ContainerElement, isChecked)
end
return ToggleInputEnabledOnElementChildren
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ToggleInteractionMaskingOnElementChildren =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ToggleInteractionMaskingOnElementChildren:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function ToggleInteractionMaskingOnElementChildren:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetIsInteractionMaskEnabledRecursive(element, isMasking)
UiMaskBus.Event.SetIsInteractionMaskingEnabled(element, isMasking)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsInteractionMaskEnabledRecursive(children[i], isMasking)
end
end
function ToggleInteractionMaskingOnElementChildren:OnCheckboxStateChange(isChecked)
SetIsInteractionMaskEnabledRecursive(self.Properties.ContainerElement, isChecked)
end
return ToggleInteractionMaskingOnElementChildren
@@ -0,0 +1,44 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local ToggleMaskingOnElementChildren =
{
Properties =
{
ContainerElement = {default = EntityId()},
},
}
function ToggleMaskingOnElementChildren:OnActivate()
self.checkboxHandler = UiCheckboxNotificationBus.Connect(self, self.entityId)
end
function ToggleMaskingOnElementChildren:OnDeactivate()
self.checkboxHandler:Disconnect()
end
function SetIsMaskEnabledRecursive(element, isMasking)
UiMaskBus.Event.SetIsMaskingEnabled(element, isMasking)
-- iterate over children of the specified element
local children = UiElementBus.Event.GetChildren(element)
for i = 1,#children do
SetIsMaskEnabledRecursive(children[i], isMasking)
end
end
function ToggleMaskingOnElementChildren:OnCheckboxStateChange(isChecked)
SetIsMaskEnabledRecursive(self.Properties.ContainerElement, isChecked)
end
return ToggleMaskingOnElementChildren
@@ -0,0 +1,86 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local Styles =
{
Properties =
{
TooltipDisplays = { default = { EntityId(), EntityId(), EntityId(), EntityId() } },
StyleButtons = { default = { EntityId(), EntityId(), EntityId(), EntityId() } },
},
}
function Styles:OnActivate()
self.buttonHandlers = {}
for i = 0, #self.Properties.StyleButtons do
self.buttonHandlers[i] = UiButtonNotificationBus.Connect(self, self.Properties.StyleButtons[i])
end
self.tickBusHandler = TickBus.Connect(self);
end
function Styles:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
self.canvas = UiElementBus.Event.GetCanvas(self.entityId)
-- Initialize selection
self:UpdateSelection(0)
end
function Styles:OnDeactivate()
for i = 0, #self.Properties.StyleButtons do
self.buttonHandlers[i]:Disconnect()
end
end
function Styles:OnButtonClick()
local styleIndex = self:GetButtonIndex(UiButtonNotificationBus.GetCurrentBusId())
-- Update selection
self:UpdateSelection(styleIndex)
-- Change tooltip display element
UiCanvasBus.Event.SetTooltipDisplayElement(self.canvas, self.Properties.TooltipDisplays[styleIndex])
-- Typically on a button click, the tooltip hides and does not show until the
-- button changes hover states. Force the tooltip of the newly pressed
-- button to show so the new tooltip display can be seen right away
local invalidEntityId = EntityId()
UiCanvasBus.Event.ForceHoverInteractable(self.canvas, invalidEntityId)
UiCanvasBus.Event.ForceHoverInteractable(self.canvas, UiButtonNotificationBus.GetCurrentBusId())
end
function Styles:GetButtonIndex(entityId)
for i = 0, #self.Properties.StyleButtons do
if (self.Properties.StyleButtons[i] == entityId) then
return i
end
end
return 0
end
function Styles:UpdateSelection(selectedIndex)
for i = 0, #self.Properties.StyleButtons do
local selectedImage = UiElementBus.Event.FindChildByName(self.Properties.StyleButtons[i], "Selected")
if (i == selectedIndex) then
UiElementBus.Event.SetIsEnabled(selectedImage, true)
else
UiElementBus.Event.SetIsEnabled(selectedImage, false)
end
end
end
return Styles
@@ -0,0 +1,147 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local TextOptions =
{
Properties =
{
WrapCheckbox = {default = EntityId()},
AlignCheckbox = {default = EntityId()},
RedSlider = {default = EntityId()},
GreenSlider = {default = EntityId()},
BlueSlider = {default = EntityId()},
ColorImage = {default = EntityId()},
FontSizeSlider = {default = EntityId()},
FontSizeText = {default = EntityId()},
TooltipText = {default = EntityId()},
TooltipEntity = {default = EntityId()},
TriggerModeDropdown = {default = EntityId()},
DropdownOnClickOption = {default = EntityId()},
DropdownOnPressOption = {default = EntityId()},
DropdownOnHoverOption = {default = EntityId()}
},
}
function TextOptions:OnActivate()
self.wrapCBHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.WrapCheckbox)
self.alignCBHandler = UiCheckboxNotificationBus.Connect(self, self.Properties.AlignCheckbox)
self.redSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.RedSlider)
self.greenSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.GreenSlider)
self.blueSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.BlueSlider)
self.fontSizeSliderHandler = UiSliderNotificationBus.Connect(self, self.Properties.FontSizeSlider)
self.dropdownHandler = UiDropdownNotificationBus.Connect(self, self.Properties.TriggerModeDropdown)
self.tickBusHandler = TickBus.Connect(self);
end
function TextOptions:OnTick(deltaTime, timePoint)
self.tickBusHandler:Disconnect()
-- Init to the current color
local color = UiTextBus.Event.GetColor(self.Properties.TooltipText)
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
UiSliderBus.Event.SetValue(self.Properties.RedSlider, color.r)
UiSliderBus.Event.SetValue(self.Properties.GreenSlider, color.g)
UiSliderBus.Event.SetValue(self.Properties.BlueSlider, color.b)
-- Init to the current font size
local fontSize = UiTextBus.Event.GetFontSize(self.Properties.TooltipText)
UiSliderBus.Event.SetValue(self.Properties.FontSizeSlider, fontSize)
UiTextBus.Event.SetText(self.Properties.FontSizeText, fontSize)
-- Select OnHover as default trigger mode
UiDropdownBus.Event.SetValue(self.Properties.TriggerModeDropdown, self.Properties.DropdownOnHoverOption)
end
function TextOptions:OnDeactivate()
self.wrapCBHandler:Disconnect()
self.alignCBHandler:Disconnect()
self.redSliderHandler:Disconnect()
self.greenSliderHandler:Disconnect()
self.blueSliderHandler:Disconnect()
self.fontSizeSliderHandler:Disconnect()
self.dropdownHandler:Disconnect()
end
function TextOptions:OnSliderValueChanging(value)
self:HandleSliderValueChange(UiSliderNotificationBus.GetCurrentBusId(), value)
end
function TextOptions:OnSliderValueChanged(value)
self:HandleSliderValueChange(UiSliderNotificationBus.GetCurrentBusId(), value)
end
function TextOptions:HandleSliderValueChange(slider, value)
if (slider == self.Properties.RedSlider) then
local color = UiTextBus.Event.GetColor(self.Properties.TooltipText)
color.r = value
-- Set text color
UiTextBus.Event.SetColor(self.Properties.TooltipText, color)
-- Update color image
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
elseif (slider == self.Properties.GreenSlider) then
local color = UiTextBus.Event.GetColor(self.Properties.TooltipText)
color.g = value
-- Set text color
UiTextBus.Event.SetColor(self.Properties.TooltipText, color)
-- Update color image
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
elseif (slider == self.Properties.BlueSlider) then
local color = UiTextBus.Event.GetColor(self.Properties.TooltipText)
color.b = value
-- Set text color
UiTextBus.Event.SetColor(self.Properties.TooltipText, color)
-- Update color image
UiImageBus.Event.SetColor(self.Properties.ColorImage, color)
elseif (slider == self.Properties.FontSizeSlider) then
-- Set font size
UiTextBus.Event.SetFontSize(self.Properties.TooltipText, value)
-- Update font size text
UiTextBus.Event.SetText(self.Properties.FontSizeText, value)
end
end
function TextOptions:OnCheckboxStateChange(isChecked)
if (UiCheckboxNotificationBus.GetCurrentBusId() == self.Properties.WrapCheckbox) then
-- Set text wrapping
if (isChecked) then
UiTextBus.Event.SetWrapText(self.Properties.TooltipText, eUiTextWrapTextSetting_Wrap)
else
UiTextBus.Event.SetWrapText(self.Properties.TooltipText, eUiTextWrapTextSetting_NoWrap)
end
elseif (UiCheckboxNotificationBus.GetCurrentBusId() == self.Properties.AlignCheckbox) then
-- Set text alignment
if (isChecked) then
UiTextBus.Event.SetHorizontalTextAlignment(self.Properties.TooltipText, eUiHAlign_Center)
else
UiTextBus.Event.SetHorizontalTextAlignment(self.Properties.TooltipText, eUiHAlign_Left)
end
end
end
function TextOptions:OnDropdownValueChanged(value)
if (UiDropdownNotificationBus.GetCurrentBusId() == self.Properties.TriggerModeDropdown) then
if (value == self.Properties.DropdownOnHoverOption) then
UiTooltipDisplayBus.Event.SetTriggerMode(self.Properties.TooltipEntity, 0);
elseif (value == self.Properties.DropdownOnPressOption) then
UiTooltipDisplayBus.Event.SetTriggerMode(self.Properties.TooltipEntity, 1)
elseif (value == self.Properties.DropdownOnClickOption) then
UiTooltipDisplayBus.Event.SetTriggerMode(self.Properties.TooltipEntity, 2)
end
end
end
return TextOptions
@@ -0,0 +1,35 @@
----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local UnloadThisCanvasButton =
{
}
function UnloadThisCanvasButton:OnActivate()
self.buttonHandler = UiButtonNotificationBus.Connect(self, self.entityId)
end
function UnloadThisCanvasButton:OnDeactivate()
self.buttonHandler:Disconnect()
end
function UnloadThisCanvasButton:OnButtonClick()
-- get canvas name from element
canvasId = UiElementBus.Event.GetCanvas(self.entityId)
if (canvasId:IsValid()) then
UiCanvasManagerBus.Broadcast.UnloadCanvas(canvasId)
end
end
return UnloadThisCanvasButton