From 432c649ee18a61cc67687efa4bd97bd75db4eafe Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 22 Jul 2021 00:29:34 -0400 Subject: [PATCH] Add room ad events --- .../room/events/RoomObjectRoomAdEvent.ts | 31 +++++++++++++++++++ src/nitro/room/events/index.ts | 1 + .../object/logic/furniture/FurnitureLogic.ts | 27 ++++++++++++++++ .../furniture/FurnitureRoomBillboardLogic.ts | 17 +++++++++- src/nitro/utils/HabboWebTools.ts | 7 ++++- 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/nitro/room/events/RoomObjectRoomAdEvent.ts diff --git a/src/nitro/room/events/RoomObjectRoomAdEvent.ts b/src/nitro/room/events/RoomObjectRoomAdEvent.ts new file mode 100644 index 00000000..9f948933 --- /dev/null +++ b/src/nitro/room/events/RoomObjectRoomAdEvent.ts @@ -0,0 +1,31 @@ +import { IRoomObject, RoomObjectEvent } from '../../../room'; + +export class RoomObjectRoomAdEvent extends RoomObjectEvent +{ + public static ROOM_AD_LOAD_IMAGE: string = 'RORAE_ROOM_AD_LOAD_IMAGE'; + public static ROOM_AD_FURNI_CLICK: string = 'RORAE_ROOM_AD_FURNI_CLICK'; + public static ROOM_AD_FURNI_DOUBLE_CLICK: string = 'RORAE_ROOM_AD_FURNI_DOUBLE_CLICK'; + public static ROOM_AD_TOOLTIP_SHOW: string = 'RORAE_ROOM_AD_TOOLTIP_SHOW'; + public static ROOM_AD_TOOLTIP_HIDE: string = 'RORAE_ROOM_AD_TOOLTIP_HIDE'; + + private _imageUrl: string = ''; + private _clickUrl: string = ''; + + constructor(type: string, object: IRoomObject, imageUrl: string = '', clickUrl: string = '') + { + super(type, object); + + this._imageUrl = imageUrl; + this._clickUrl = clickUrl; + } + + public get imageUrl(): string + { + return this._imageUrl; + } + + public get clickUrl(): string + { + return this._clickUrl; + } +} diff --git a/src/nitro/room/events/index.ts b/src/nitro/room/events/index.ts index 54ea2f56..4ed46c10 100644 --- a/src/nitro/room/events/index.ts +++ b/src/nitro/room/events/index.ts @@ -16,6 +16,7 @@ export * from './RoomObjectFurnitureActionEvent'; export * from './RoomObjectHSLColorEnabledEvent'; export * from './RoomObjectHSLColorEnableEvent'; export * from './RoomObjectMoveEvent'; +export * from './RoomObjectRoomAdEvent'; export * from './RoomObjectSamplePlaybackEvent'; export * from './RoomObjectStateChangedEvent'; export * from './RoomObjectTileMouseEvent'; diff --git a/src/nitro/room/object/logic/furniture/FurnitureLogic.ts b/src/nitro/room/object/logic/furniture/FurnitureLogic.ts index 41c54c86..42c86b99 100644 --- a/src/nitro/room/object/logic/furniture/FurnitureLogic.ts +++ b/src/nitro/room/object/logic/furniture/FurnitureLogic.ts @@ -8,6 +8,7 @@ import { IRoomGeometry } from '../../../../../room/utils/IRoomGeometry'; import { IVector3D } from '../../../../../room/utils/IVector3D'; import { Vector3d } from '../../../../../room/utils/Vector3d'; import { MouseEventType } from '../../../../ui/MouseEventType'; +import { RoomObjectRoomAdEvent } from '../../../events'; import { RoomObjectStateChangedEvent } from '../../../events/RoomObjectStateChangedEvent'; import { RoomObjectWidgetRequestEvent } from '../../../events/RoomObjectWidgetRequestEvent'; import { ObjectDataUpdateMessage } from '../../../messages/ObjectDataUpdateMessage'; @@ -133,6 +134,13 @@ export class FurnitureLogic extends MovingObjectLogic return model.getValue(RoomObjectVariable.FURNITURE_AD_URL); } + protected handleAdClick():void + { + if(!this.eventDispatcher) return; + + this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_FURNI_CLICK, this.object)); + } + public update(time: number): void { super.update(time); @@ -256,6 +264,11 @@ export class FurnitureLogic extends MovingObjectLogic { if(this.eventDispatcher) { + if(adUrl && (adUrl.indexOf('http') === 0)) + { + this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_SHOW, this.object)); + } + const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_ENTER, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown); mouseEvent.localX = event.localX; @@ -274,6 +287,11 @@ export class FurnitureLogic extends MovingObjectLogic { if(this.eventDispatcher) { + if(adUrl && (adUrl.indexOf('http') === 0)) + { + this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_HIDE, this.object)); + } + const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_LEAVE, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown); mouseEvent.localX = event.localX; @@ -301,6 +319,13 @@ export class FurnitureLogic extends MovingObjectLogic mouseEvent.spriteOffsetY = event.spriteOffsetY; this.eventDispatcher.dispatchEvent(mouseEvent); + + if(adUrl && (adUrl.indexOf('http') === 0)) + { + this.eventDispatcher.dispatchEvent(new RoomObjectRoomAdEvent(RoomObjectRoomAdEvent.ROOM_AD_TOOLTIP_HIDE, this.object)); + } + + if(adUrl && adUrl.length) this.handleAdClick(); } return; case MouseEventType.MOUSE_DOWN: @@ -357,6 +382,8 @@ export class FurnitureLogic extends MovingObjectLogic const adUrl = this.getAdClickUrl(this.object.model); + + if(this.widget) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.OPEN_WIDGET, this.object)); this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object)); diff --git a/src/nitro/room/object/logic/furniture/FurnitureRoomBillboardLogic.ts b/src/nitro/room/object/logic/furniture/FurnitureRoomBillboardLogic.ts index 0c1aa11b..3496f2d7 100644 --- a/src/nitro/room/object/logic/furniture/FurnitureRoomBillboardLogic.ts +++ b/src/nitro/room/object/logic/furniture/FurnitureRoomBillboardLogic.ts @@ -1,4 +1,5 @@ import { IRoomObjectModel } from '../../../../../room/object/IRoomObjectModel'; +import { HabboWebTools } from '../../../../utils'; import { RoomObjectVariable } from '../../RoomObjectVariable'; import { FurnitureRoomBrandingLogic } from './FurnitureRoomBrandingLogic'; @@ -15,4 +16,18 @@ export class FurnitureRoomBillboardLogic extends FurnitureRoomBrandingLogic { return model.getValue(RoomObjectVariable.FURNITURE_BRANDING_URL); } -} \ No newline at end of file + + protected handleAdClick():void + { + const adUrl = this.getAdClickUrl(this.object.model); + + if(adUrl.indexOf('http') === 0) + { + HabboWebTools.openWebPage(adUrl); + + return; + } + + super.handleAdClick(); + } +} diff --git a/src/nitro/utils/HabboWebTools.ts b/src/nitro/utils/HabboWebTools.ts index 2765f0f3..b089d650 100644 --- a/src/nitro/utils/HabboWebTools.ts +++ b/src/nitro/utils/HabboWebTools.ts @@ -43,6 +43,11 @@ export class HabboWebTools } } + public static openWebPage(pageUrl: string): void + { + window.open(pageUrl); + } + public static sendHeartBeat(): void { try @@ -330,4 +335,4 @@ export class HabboWebTools NitroLogger.log('External interface not working. Could not update figure.'); } } -} \ No newline at end of file +}