Skip to content

Commit

Permalink
feat: add buttons release time parmater
Browse files Browse the repository at this point in the history
  • Loading branch information
Pejosonic committed Sep 5, 2024
1 parent c40bd4e commit 3b2021d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ We already implement the generic UI to use inside the mini-games. Like the Play
#### Menu Button UI

```ts
// MenuButton(position: TransformType, assetShape, assetIcon, hoverText, callback)
// MenuButton(position: TransformType, assetShape, assetIcon, hoverText, callback, enabledByDefault (optional), releaseTime (optional) )
import { ui } from '@dcl-sdk/mini-games/src'

// All the available icons
Expand Down
25 changes: 16 additions & 9 deletions src/ui/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ export class MenuButton {
buttonShapeDisabled: ButtonShapeData
iconGlowMat: PBMaterial_PbrMaterial
iconDisabledMat: PBMaterial_PbrMaterial
releaseTime: number

constructor(
transform: TransformTypeWithOptionals,
buttonShapeData: ButtonShapeData,
icon: IconData,
_hoverText: string,
callback: () => void,
enabledByDefault?: boolean
enabledByDefault?: boolean,
releaseTime: number = 500
) {
const {
engine,
Expand All @@ -41,8 +43,7 @@ export class MenuButton {
PointerEvents,
VisibilityComponent,
Tween,
TweenSequence,
TweenState
TweenSequence
},
tweenSystem
} = getSDK()
Expand All @@ -52,6 +53,8 @@ export class MenuButton {
this.enabled = enabledByDefault
}

this.releaseTime = releaseTime

this.buttonShapeEnabled = buttonShapeData
this.buttonShapeDisabled = uiAssets.shapes.RECT_BLACK
if (!buttonShapeData.isRect) {
Expand Down Expand Up @@ -102,13 +105,15 @@ export class MenuButton {

engine.addSystem(() => {
// TODO: Why is not been triggered ?
if (tweenSystem.tweenCompleted(this.button)) {
console.log('asd', Tween.getOrNull(this.button))
}
// if (tweenSystem.tweenCompleted(this.button)) {
// console.log('asd', Tween.getOrNull(this.button))
// }

// TODO: this should be tweenCompleted but no idea why is not working :sadcat:
if (TweenState.getOrNull(this.button)?.currentTime === 1 && TweenSequence.getOrNull(this.button)) {
// if (TweenState.getOrNull(this.button)?.currentTime === 1 && TweenSequence.getOrNull(this.button)) {
if (tweenSystem.tweenCompleted(this.button)) {
if (!TweenSequence.get(this.button).sequence.length) {
this.enable()
// Tween.deleteFrom(this.button)
TweenSequence.deleteFrom(this.button)
VisibilityComponent.getMutable(this.glowPlane).visible = false
Expand All @@ -120,11 +125,13 @@ export class MenuButton {
}
}
}
// this.disable()

if (inputSystem.isTriggered(InputAction.IA_POINTER, PointerEventType.PET_DOWN, this.button)) {
if (this.enabled) {
callback()
this.playSound('mini-game-assets/sounds/button_click.mp3')
this.disable()
//flash the emissive of the icon
Material.setPbrMaterial(this.icon, {
texture: Material.Texture.Common({ src: uiAtlas }),
Expand All @@ -137,7 +144,7 @@ export class MenuButton {
VisibilityComponent.getMutable(this.glowPlane).visible = true
//tween button inward
Tween.createOrReplace(this.button, {
duration: 500,
duration: this.releaseTime / 2,
currentTime: 0,
playing: true,
easingFunction: EasingFunction.EF_EASEOUTSINE,
Expand All @@ -146,7 +153,7 @@ export class MenuButton {
TweenSequence.createOrReplace(this.button, {
sequence: [
{
duration: 500,
duration: this.releaseTime / 2,
currentTime: 0,
playing: true,
easingFunction: EasingFunction.EF_EASEOUTSINE,
Expand Down

0 comments on commit 3b2021d

Please sign in to comment.