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 therenderfunction to render the HUD. By default, it’s not rendered automatically. -
leftSidePanel: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitycontaining 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: TheUiBackgroundPropstype from@dcl/sdk/react-ecs. Use this to modify the background of theUiEntitycontaining the box with the Quest name and steps. In web terms, this would be thedivacting as a container for the Quest name and steps.uiTransform: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitycontaining the box with the Quest name and steps. In web terms, this would be thedivacting as a container for the Quest name and steps.
-
questNameContainer: An object that contains two fields:uiTransform: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitycontaining the Quest name. In web terms, this would be thedivacting as a container for the Quest name.label: TheLabelPropstype defined in the snippet above. Use this to modify theLabelwith the Quest name. In web terms, this would be theptag containing the Quest name.
-
stepsContainer: An object that contains three fields:uiTransform: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitylisting the steps and theirdescription. In web terms, this would be thedivacting as a container for the steps.labels: An object that contains two fields:labelUiEntity: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify everyUiEntitythat contains the step’sdescriptionand the “Show Tasks” button. In web terms, this would be thedivacting as a container for the step’sdescriptionand the “Show Tasks” button.props: TheLabelPropstype defined in the snippet above. Use this to modify everyLabelcontaining the step’sdescription. In web terms, this would be theptag containing the step’sdescription.
showTasksButton: An object that contains two fields:buttonUiEntity: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify everyUiEntitycontaining the “Show Tasks” button. In web terms, this would be thedivacting as a container for the “Show Tasks” button.buttonProps: TheUiButtonPropstype from@dcl/sdk/react-ecs. Use this to modify all the “Show Tasks”Buttons.
-
tasksBox: An object that contains three fields:uiTransform: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify everyUiEntitycontaining and listing each step tasks with theirdescription. In web terms, this would be thedivacting as a container for a step tasks.uiBackground: TheUiBackgroundPropstype from@dcl/sdk/react-ecs. Use this to modify the background of everyUiEntitylisting each step tasks with theirdescription. In web terms, this would be thedivacting as a container for the tasks.labels: An object that contains two fields:labelUiEntity: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify everyUiEntitycontaining the task’sdescription. In web terms, this would be thedivacting as a container for the task’sdescription.props: TheLabelPropstype defined in the snippet above. Use this to modify everyLabelcontaining the task’sdescription. In web terms, this would be theptag containing the task’sdescription.
-
nextSteps: An object that contains three fields:nextTitleUiEntity: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitycontaining the “Next Steps” title. In web terms, this would be thedivacting as a container for the “Next Steps” title.nextTitleProps: TheLabelPropstype defined in the snippet above. Use this to modify theLabelcontaining the “Next Steps” title. In web terms, this would be theptag containing the “Next Steps” title.labels: An object that contains two fields:labelUiEntity: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify everyUiEntitycontaining the next step’sdescription. In web terms, this would be thedivacting as a container for the next step’sdescription.props: TheLabelPropstype defined in the snippet above. Use this to modify everyLabelcontaining the next step’sdescription. In web terms, this would be theptag containing the next step’sdescription.
-
questCompletionLabel: An object that contains two fields:uiTransform: TheUiTransformPropstype from@dcl/sdk/react-ecs. Use this to modify theUiEntitycontaining the Quest completion label. In web terms, this would be thedivacting as a container for the Quest completion label.label: TheLabelPropstype defined in the snippet above. Use this to modify theLabelcontaining the text that lets the users know they have completed the Quest. In web terms, this would be theptag containing the text noticing the completion of the Quest.
-
showHideToggleButton: TheUiButtonPropstype from@dcl/sdk/react-ecs. Use this to modify the “Hide” and “Show Quest Progress” toggleButton. In web terms, this would be thebuttontag. -
closeTasksBoxButton: TheUiButtonPropstype from@dcl/sdk/react-ecs. Use this to modify the “Close”Buttonthat appears when the user clicks on the “Show Tasks”Button. In web terms, this would be thebuttontag.
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 aQuestInstanceobject. 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.setUiRendereroverrides everything that previously exists. -
render: Render the Quest HUD. You may want to call this function when you have theautoRenderoption set tofalseand 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.