Skip to content

Commit

Permalink
Merge pull request #12949 from sebavan/SpriteDoublePick
Browse files Browse the repository at this point in the history
Sprite double pick

Former-commit-id: b551dbcd7e05eb6bf9e8326fc05d86b9c82f6878
  • Loading branch information
sebavan authored Sep 5, 2022
2 parents 14ce71c + 978a6cc commit 3f998ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/dev/core/src/Inputs/scene.inputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class InputManager {
}
} else {
for (const step of scene._pointerDownStage) {
pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt);
pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, false);
}
}

Expand Down Expand Up @@ -431,7 +431,7 @@ export class InputManager {
} else {
if (!clickInfo.ignore) {
for (const step of scene._pointerUpStage) {
pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt);
pickResult = step.action(this._unTranslatedPointerX, this._unTranslatedPointerY, pickResult, evt, clickInfo.doubleClick);
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion packages/dev/core/src/Sprites/spriteSceneComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,13 @@ export class SpriteSceneComponent implements ISceneComponent {
return pickResult;
}

private _pointerUp(unTranslatedPointerX: number, unTranslatedPointerY: number, pickResult: Nullable<PickingInfo>, evt: IPointerEvent): Nullable<PickingInfo> {
private _pointerUp(
unTranslatedPointerX: number,
unTranslatedPointerY: number,
pickResult: Nullable<PickingInfo>,
evt: IPointerEvent,
doubleClick: boolean
): Nullable<PickingInfo> {
const scene = this.scene;
if (scene.spriteManagers.length > 0) {
const spritePickResult = scene.pickSprite(unTranslatedPointerX, unTranslatedPointerY, this._spritePredicate, false, scene.cameraToUseForPointers || undefined);
Expand All @@ -409,13 +415,21 @@ export class SpriteSceneComponent implements ISceneComponent {
Constants.ACTION_OnPickUpTrigger,
ActionEvent.CreateNewFromSprite(spritePickResult.pickedSprite, scene, evt)
);

if (spritePickResult.pickedSprite.actionManager) {
if (!this.scene._inputManager._isPointerSwiping()) {
spritePickResult.pickedSprite.actionManager.processTrigger(
Constants.ACTION_OnPickTrigger,
ActionEvent.CreateNewFromSprite(spritePickResult.pickedSprite, scene, evt)
);
}

if (doubleClick) {
spritePickResult.pickedSprite.actionManager.processTrigger(
Constants.ACTION_OnDoublePickTrigger,
ActionEvent.CreateNewFromSprite(spritePickResult.pickedSprite, scene, evt)
);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3545,7 +3545,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
* @param data the data object to associate to the key for this Engine instance
* @return true if no such key were already present and the data was added successfully, false otherwise
*/
public addExternalData<T>(key: string, data: T): boolean {
public addExternalData<T extends Object>(key: string, data: T): boolean {
if (!this._externalData) {
this._externalData = new StringDictionary<Object>();
}
Expand All @@ -3570,7 +3570,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
* @param factory the factory that will be called to create the instance if and only if it doesn't exists
* @return the associated data, can be null if the factory returned null.
*/
public getOrAddExternalDataWithFactory<T>(key: string, factory: (k: string) => T): T {
public getOrAddExternalDataWithFactory<T extends Object>(key: string, factory: (k: string) => T): T {
if (!this._externalData) {
this._externalData = new StringDictionary<Object>();
}
Expand Down
8 changes: 7 additions & 1 deletion packages/dev/core/src/sceneComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ export type PointerMoveStageAction = (
/**
* Strong typing of a pointer up/down action.
*/
export type PointerUpDownStageAction = (unTranslatedPointerX: number, unTranslatedPointerY: number, pickResult: Nullable<PickingInfo>, evt: IPointerEvent) => Nullable<PickingInfo>;
export type PointerUpDownStageAction = (
unTranslatedPointerX: number,
unTranslatedPointerY: number,
pickResult: Nullable<PickingInfo>,
evt: IPointerEvent,
doubleClick: boolean
) => Nullable<PickingInfo>;

/**
* Representation of a stage in the scene (Basically a list of ordered steps)
Expand Down

0 comments on commit 3f998ce

Please sign in to comment.