Add room ad events

This commit is contained in:
Bill 2021-07-22 00:29:34 -04:00
parent 0c48154274
commit 432c649ee1
5 changed files with 81 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -16,6 +16,7 @@ export * from './RoomObjectFurnitureActionEvent';
export * from './RoomObjectHSLColorEnabledEvent'; export * from './RoomObjectHSLColorEnabledEvent';
export * from './RoomObjectHSLColorEnableEvent'; export * from './RoomObjectHSLColorEnableEvent';
export * from './RoomObjectMoveEvent'; export * from './RoomObjectMoveEvent';
export * from './RoomObjectRoomAdEvent';
export * from './RoomObjectSamplePlaybackEvent'; export * from './RoomObjectSamplePlaybackEvent';
export * from './RoomObjectStateChangedEvent'; export * from './RoomObjectStateChangedEvent';
export * from './RoomObjectTileMouseEvent'; export * from './RoomObjectTileMouseEvent';

View File

@ -8,6 +8,7 @@ import { IRoomGeometry } from '../../../../../room/utils/IRoomGeometry';
import { IVector3D } from '../../../../../room/utils/IVector3D'; import { IVector3D } from '../../../../../room/utils/IVector3D';
import { Vector3d } from '../../../../../room/utils/Vector3d'; import { Vector3d } from '../../../../../room/utils/Vector3d';
import { MouseEventType } from '../../../../ui/MouseEventType'; import { MouseEventType } from '../../../../ui/MouseEventType';
import { RoomObjectRoomAdEvent } from '../../../events';
import { RoomObjectStateChangedEvent } from '../../../events/RoomObjectStateChangedEvent'; import { RoomObjectStateChangedEvent } from '../../../events/RoomObjectStateChangedEvent';
import { RoomObjectWidgetRequestEvent } from '../../../events/RoomObjectWidgetRequestEvent'; import { RoomObjectWidgetRequestEvent } from '../../../events/RoomObjectWidgetRequestEvent';
import { ObjectDataUpdateMessage } from '../../../messages/ObjectDataUpdateMessage'; import { ObjectDataUpdateMessage } from '../../../messages/ObjectDataUpdateMessage';
@ -133,6 +134,13 @@ export class FurnitureLogic extends MovingObjectLogic
return model.getValue<string>(RoomObjectVariable.FURNITURE_AD_URL); return model.getValue<string>(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 public update(time: number): void
{ {
super.update(time); super.update(time);
@ -256,6 +264,11 @@ export class FurnitureLogic extends MovingObjectLogic
{ {
if(this.eventDispatcher) 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); const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_ENTER, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
mouseEvent.localX = event.localX; mouseEvent.localX = event.localX;
@ -274,6 +287,11 @@ export class FurnitureLogic extends MovingObjectLogic
{ {
if(this.eventDispatcher) 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); const mouseEvent = new RoomObjectMouseEvent(RoomObjectMouseEvent.MOUSE_LEAVE, this.object, event.eventId, event.altKey, event.ctrlKey, event.shiftKey, event.buttonDown);
mouseEvent.localX = event.localX; mouseEvent.localX = event.localX;
@ -301,6 +319,13 @@ export class FurnitureLogic extends MovingObjectLogic
mouseEvent.spriteOffsetY = event.spriteOffsetY; mouseEvent.spriteOffsetY = event.spriteOffsetY;
this.eventDispatcher.dispatchEvent(mouseEvent); 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; return;
case MouseEventType.MOUSE_DOWN: case MouseEventType.MOUSE_DOWN:
@ -357,6 +382,8 @@ export class FurnitureLogic extends MovingObjectLogic
const adUrl = this.getAdClickUrl(this.object.model); const adUrl = this.getAdClickUrl(this.object.model);
if(this.widget) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.OPEN_WIDGET, this.object)); if(this.widget) this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.OPEN_WIDGET, this.object));
this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object)); this.eventDispatcher.dispatchEvent(new RoomObjectStateChangedEvent(RoomObjectStateChangedEvent.STATE_CHANGE, this.object));

View File

@ -1,4 +1,5 @@
import { IRoomObjectModel } from '../../../../../room/object/IRoomObjectModel'; import { IRoomObjectModel } from '../../../../../room/object/IRoomObjectModel';
import { HabboWebTools } from '../../../../utils';
import { RoomObjectVariable } from '../../RoomObjectVariable'; import { RoomObjectVariable } from '../../RoomObjectVariable';
import { FurnitureRoomBrandingLogic } from './FurnitureRoomBrandingLogic'; import { FurnitureRoomBrandingLogic } from './FurnitureRoomBrandingLogic';
@ -15,4 +16,18 @@ export class FurnitureRoomBillboardLogic extends FurnitureRoomBrandingLogic
{ {
return model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_URL); return model.getValue<string>(RoomObjectVariable.FURNITURE_BRANDING_URL);
} }
protected handleAdClick():void
{
const adUrl = this.getAdClickUrl(this.object.model);
if(adUrl.indexOf('http') === 0)
{
HabboWebTools.openWebPage(adUrl);
return;
}
super.handleAdClick();
}
} }

View File

@ -43,6 +43,11 @@ export class HabboWebTools
} }
} }
public static openWebPage(pageUrl: string): void
{
window.open(pageUrl);
}
public static sendHeartBeat(): void public static sendHeartBeat(): void
{ {
try try