Quest HUD - SDK UI
The Quests Client library provides a default UI (HUD). This displays the player’s progress, listing the steps in the quest and their status.
This default UI is highly customizable, but you can also build your own UI, entirely from scratch.
HUD Properties #
This HUD is fully-customizable. Below are the full set of options that can be set up:
type LabelProps = EntityPropTypes & UiLabelProps
export type QuestHudOptions = {
autoRender?: boolean
leftSidePanel?: UiTransformProps
questBox?: {
uiBackground?: UiBackgroundProps
uiTransform?: UiTransformProps
}
questNameContainer?: {
uiTransform?: UiTransformProps
label?: LabelProps
}
stepsContainer?: {
uiTransform: UiTransformProps
labels?: {
labelUiEntity?: UiTransformProps
props?: LabelProps
}
showTasksButton?: {
buttonUiEntity: UiTransformProps
buttonProps?: UiButtonProps
}
}
tasksBox?: {
uiTransform?: UiTransformProps
uiBackground?: UiBackgroundProps
labels?: {
labelUiEntity?: UiTransformProps
props?: LabelProps
}
}
nextSteps?: {
nextTitleUiEntity?: UiTransformProps
nextTitleProps?: LabelProps
labels?: {
labelUiEntity?: UiTransformProps
props?: LabelProps
}
}
questCompletionLabel?: {
uiTransform?: UiTransformProps
label?: LabelProps
}
showHideToggleButton?: UiButtonProps
closeTasksBoxButton?: UiButtonProps
}
-
autoRender
: Iftrue
, the HUD is rendered automatically. Iffalse
, you will need to call therender
function to render the HUD. By default, it’s not rendered automatically. -
leftSidePanel
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
containing the box that contains all the Quest progress and the “Hide/Show” toggle button. In web terms, this would be the div acting as a container for the box and button. -
questBox
: An object that contains two fields:uiBackground
: TheUiBackgroundProps
type from@dcl/sdk/react-ecs
. Use this to modify the background of theUiEntity
containing the box with the Quest name and steps. In web terms, this would be thediv
acting as a container for the Quest name and steps.uiTransform
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
containing the box with the Quest name and steps. In web terms, this would be thediv
acting as a container for the Quest name and steps.
-
questNameContainer
: An object that contains two fields:uiTransform
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
containing the Quest name. In web terms, this would be thediv
acting as a container for the Quest name.label
: TheLabelProps
type defined in the snippet above. Use this to modify theLabel
with the Quest name. In web terms, this would be thep
tag containing the Quest name.
-
stepsContainer
: An object that contains three fields:uiTransform
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
listing the steps and theirdescription
. In web terms, this would be thediv
acting as a container for the steps.labels
: An object that contains two fields:labelUiEntity
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify everyUiEntity
that contains the step’sdescription
and the “Show Tasks” button. In web terms, this would be thediv
acting as a container for the step’sdescription
and the “Show Tasks” button.props
: TheLabelProps
type defined in the snippet above. Use this to modify everyLabel
containing the step’sdescription
. In web terms, this would be thep
tag containing the step’sdescription
.
showTasksButton
: An object that contains two fields:buttonUiEntity
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify everyUiEntity
containing the “Show Tasks” button. In web terms, this would be thediv
acting as a container for the “Show Tasks” button.buttonProps
: TheUiButtonProps
type from@dcl/sdk/react-ecs
. Use this to modify all the “Show Tasks”Button
s.
-
tasksBox
: An object that contains three fields:uiTransform
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify everyUiEntity
containing and listing each step tasks with theirdescription
. In web terms, this would be thediv
acting as a container for a step tasks.uiBackground
: TheUiBackgroundProps
type from@dcl/sdk/react-ecs
. Use this to modify the background of everyUiEntity
listing each step tasks with theirdescription
. In web terms, this would be thediv
acting as a container for the tasks.labels
: An object that contains two fields:labelUiEntity
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify everyUiEntity
containing the task’sdescription
. In web terms, this would be thediv
acting as a container for the task’sdescription
.props
: TheLabelProps
type defined in the snippet above. Use this to modify everyLabel
containing the task’sdescription
. In web terms, this would be thep
tag containing the task’sdescription
.
-
nextSteps
: An object that contains three fields:nextTitleUiEntity
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
containing the “Next Steps” title. In web terms, this would be thediv
acting as a container for the “Next Steps” title.nextTitleProps
: TheLabelProps
type defined in the snippet above. Use this to modify theLabel
containing the “Next Steps” title. In web terms, this would be thep
tag containing the “Next Steps” title.labels
: An object that contains two fields:labelUiEntity
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify everyUiEntity
containing the next step’sdescription
. In web terms, this would be thediv
acting as a container for the next step’sdescription
.props
: TheLabelProps
type defined in the snippet above. Use this to modify everyLabel
containing the next step’sdescription
. In web terms, this would be thep
tag containing the next step’sdescription
.
-
questCompletionLabel
: An object that contains two fields:uiTransform
: TheUiTransformProps
type from@dcl/sdk/react-ecs
. Use this to modify theUiEntity
containing the Quest completion label. In web terms, this would be thediv
acting as a container for the Quest completion label.label
: TheLabelProps
type defined in the snippet above. Use this to modify theLabel
containing the text that lets the users know they have completed the Quest. In web terms, this would be thep
tag containing the text noticing the completion of the Quest.
-
showHideToggleButton
: TheUiButtonProps
type from@dcl/sdk/react-ecs
. Use this to modify the “Hide” and “Show Quest Progress” toggleButton
. In web terms, this would be thebutton
tag. -
closeTasksBoxButton
: TheUiButtonProps
type from@dcl/sdk/react-ecs
. Use this to modify the “Close”Button
that appears when the user clicks on the “Show Tasks”Button
. In web terms, this would be thebutton
tag.
Methods of the QuestHUD object #
Once you created a Quest HUD with createQuestHUD()
, you’re returned a QuestHUD
object. This object has the following methods:
type QuestHUD = {
upsert: (instance: QuestInstance) => void
getHUDComponent: () => () => ReactEcs.JSX.Element
render: () => void
updateOptions: (opts: QuestHudOptions) => void
getHUDComponentWithUpdatedOptions: (
newOpts: QuestHudOptions
) => () => ReactEcs.JSX.Element
}
-
upsert
: Update the Quest HUD with the player’s progress, you may want to call it when the users starts the Quest and when they make some progress. Also when the player loads into the scene with the quest already partially completed. This function receives aQuestInstance
object. It creates an entity with this data to be used by a ReactECS UI component. This component is rendered in the scene UI, displaying the Quest progress. -
getHUDComponent
: Get the ReactECS UI component that renders a ready-to-use Quest HUD. This is useful when you already have a UI to render, sinceReactEcsRenderer.setUiRenderer
overrides everything that previously exists. -
render
: Render the Quest HUD. You may want to call this function when you have theautoRender
option set tofalse
and you want to render the Quest HUD manually.
To use it, import the createQuestHUD
function from @dcl/quests-client/dist/hud
. For example:
// index.ts
//...
import { executeTask } from '@dcl/sdk/ecs'
import { createQuestsClient, QuestInstance } from '@dcl/quests-client'
import { createQuestHUD } from '@dcl/quests-client/dist/hud'
const questHud = createQuestHUD()
const MY_QUEST_ID = 'quest-id-1234-5678-9012'
executeTask(async () => {
const serviceUrl = 'wss://quests-rpc.decentraland.zone'
try {
const questsClient = await createQuestsClient(serviceUrl, MY_QUEST_ID)
console.log('Quests Client is ready to use!')
client.onStarted((quest: QuestInstance) => {
// react to the start of your Quest
questHud.upsert(quest)
})
client.onUpdate((quest: QuestInstance) => {
// update your state here to react to the quest updates
questHud.upsert(quest)
})
} catch (e) {
console.error('Error on connecting to Quests Service')
}
})
The above code creates a default Quest HUD object, with no customization. You can find the defaults in the code here , or render the HUD to see how it looks.
When the quest is stated or it receives any player progress update, the questHud.upsert
function is called to update this UI. This function receives a QuestInstance
object. It creates an SDK entity with this data to be used by a ReactECS UI component. This component is rendered in the scene UI, displaying the Quest progress, including which steps and tasks are completed or not.
Customizing the Quest HUD #
// index.ts
//....
const questHud = createQuestHUD({
autoRender: true,
leftSidePanel: {
position: { top: '8%' },
},
questBox: {
uiBackground: {
color: Color4.fromHexString('ff2d5382'),
},
},
})
//....
//....
The above code creates a customized Quest HUD. This HUD is rendered automatically, so it’s updated whenever the player starts the Quest or makes progress or the upsert
function is called.
This Quest HUD is configured to be rendered 8%
far from the top of the screen. This works well in Worlds, where there is no minimap. The default is 28%
places the quest HUD below the height of the minimap, ideal for quests inside Genesis Plaza.
This example also sets the Quest box background color to #ff2d5382
. This is the primary color of Decentraland (a light red), with almost 50% of opacity.
You are free to use the SDK to create your own custom UI to display quest progress based on this same information. See Onscreen UI for guidance about how to do this.