diff --git a/src/nitro/room/object/RoomObjectVariable.ts b/src/nitro/room/object/RoomObjectVariable.ts index be68b29a..db3c790d 100644 --- a/src/nitro/room/object/RoomObjectVariable.ts +++ b/src/nitro/room/object/RoomObjectVariable.ts @@ -50,7 +50,7 @@ export class RoomObjectVariable public static FURNITURE_COLOR: string = 'furniture_color'; public static FURNITURE_LIFT_AMOUNT: string = 'furniure_lift_amount'; public static FURNITURE_GUILD_CUSTOMIZED_GUILD_ID: string = 'furniture_guild_customized_guild_id'; - public static FURNITURE_GUILD_CUSTOMIZED_BADGE: string = 'furniture_guild_customized_badge'; + public static FURNITURE_GUILD_CUSTOMIZED_ASSET_NAME: string = 'furniture_guild_customized_asset_name'; public static FURNITURE_GUILD_CUSTOMIZED_COLOR_1: string = 'furniture_guild_customized_color_1'; public static FURNITURE_GUILD_CUSTOMIZED_COLOR_2: string = 'furniture_guild_customized_color_2'; public static FURNITURE_STATE_UPDATE_TIME: string = 'furniture_state_update_time'; diff --git a/src/nitro/room/object/logic/furniture/FurnitureGuildCustomizedLogic.ts b/src/nitro/room/object/logic/furniture/FurnitureGuildCustomizedLogic.ts index 3d7eb024..ff2ff8f6 100644 --- a/src/nitro/room/object/logic/furniture/FurnitureGuildCustomizedLogic.ts +++ b/src/nitro/room/object/logic/furniture/FurnitureGuildCustomizedLogic.ts @@ -1,5 +1,9 @@ +import { IRoomGeometry, RoomSpriteMouseEvent } from '../../../../../room'; import { RoomObjectUpdateMessage } from '../../../../../room/messages/RoomObjectUpdateMessage'; -import { ContextMenuEnum } from '../../../../ui/widget/enums/ContextMenuEnum'; +import { Nitro } from '../../../../Nitro'; +import { MouseEventType } from '../../../../ui'; +import { RoomObjectBadgeAssetEvent, RoomObjectWidgetRequestEvent } from '../../../events'; +import { ObjectGroupBadgeUpdateMessage, ObjectSelectedMessage } from '../../../messages'; import { ObjectDataUpdateMessage } from '../../../messages/ObjectDataUpdateMessage'; import { StringDataType } from '../../data/type/StringDataType'; import { RoomObjectVariable } from '../../RoomObjectVariable'; @@ -12,6 +16,17 @@ export class FurnitureGuildCustomizedLogic extends FurnitureMultiStateLogic public static COLOR1_KEY: number = 3; public static COLOR2_KEY: number = 4; + public getEventTypes(): string[] + { + const types = [ + RoomObjectBadgeAssetEvent.LOAD_BADGE, + RoomObjectWidgetRequestEvent.GUILD_FURNI_CONTEXT_MENU, + RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU + ]; + + return this.mergeTypes(super.getEventTypes(), types); + } + public processUpdateMessage(message: RoomObjectUpdateMessage): void { super.processUpdateMessage(message); @@ -27,6 +42,24 @@ export class FurnitureGuildCustomizedLogic extends FurnitureMultiStateLogic this.updateColors(data.getValue(FurnitureGuildCustomizedLogic.COLOR1_KEY), data.getValue(FurnitureGuildCustomizedLogic.COLOR2_KEY)); } } + + else if(message instanceof ObjectGroupBadgeUpdateMessage) + { + if(message.assetName !== 'loading_icon') + { + this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_ASSET_NAME, message.assetName); + + this.update(Nitro.instance.time); + } + } + + else if(message instanceof ObjectSelectedMessage) + { + if(!message.selected) + { + this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.CLOSE_FURNI_CONTEXT_MENU, this.object)); + } + } } protected updateGroupId(id: string): void @@ -36,7 +69,7 @@ export class FurnitureGuildCustomizedLogic extends FurnitureMultiStateLogic private updateBadge(badge: string): void { - this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_BADGE, badge); + this.eventDispatcher.dispatchEvent(new RoomObjectBadgeAssetEvent(RoomObjectBadgeAssetEvent.LOAD_BADGE, this.object, badge, true)); } public updateColors(color1: string, color2: string): void @@ -45,8 +78,21 @@ export class FurnitureGuildCustomizedLogic extends FurnitureMultiStateLogic this.object.model.setValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_COLOR_2, parseInt(color2, 16)); } - public get contextMenu(): string + public mouseEvent(event: RoomSpriteMouseEvent, geometry: IRoomGeometry): void { - return ContextMenuEnum.GROUP_FURNITURE; + if(!event || !geometry || !this.object) return; + + switch(event.type) + { + case MouseEventType.MOUSE_CLICK: + this.openContextMenu(); + } + + super.mouseEvent(event, geometry); + } + + private openContextMenu(): void + { + this.eventDispatcher.dispatchEvent(new RoomObjectWidgetRequestEvent(RoomObjectWidgetRequestEvent.GUILD_FURNI_CONTEXT_MENU, this.object)); } } diff --git a/src/nitro/room/object/visualization/furniture/FurnitureGuildCustomizedVisualization.ts b/src/nitro/room/object/visualization/furniture/FurnitureGuildCustomizedVisualization.ts index 9a9a0b47..d71ed348 100644 --- a/src/nitro/room/object/visualization/furniture/FurnitureGuildCustomizedVisualization.ts +++ b/src/nitro/room/object/visualization/furniture/FurnitureGuildCustomizedVisualization.ts @@ -1,27 +1,44 @@ +import { IGraphicAsset, IRoomObjectSprite } from '../../../../../room'; import { RoomObjectVariable } from '../../RoomObjectVariable'; import { FurnitureAnimatedVisualization } from './FurnitureAnimatedVisualization'; export class FurnitureGuildCustomizedVisualization extends FurnitureAnimatedVisualization { - public static DEFAULT_COLOR_1: number = 0xEEEEEE; - public static DEFAULT_COLOR_2: number = 0x4B4B4B; + public static PRIMARY_COLOUR_SPRITE_TAG: string = 'COLOR1'; + public static SECONDARY_COLOUR_SPRITE_TAG: string = 'COLOR2'; + public static BADGE: string = 'BADGE'; + public static DEFAULT_COLOR_1: number = 0xEEEEEE; + public static DEFAULT_COLOR_2: number = 0x4B4B4B; private _color1: number; private _color2: number; + private _badgeAssetNameNormalScale: string; + private _badgeAssetNameSmallScale: string; constructor() { super(); - this._color1 = FurnitureGuildCustomizedVisualization.DEFAULT_COLOR_1; - this._color2 = FurnitureGuildCustomizedVisualization.DEFAULT_COLOR_2; + this._color1 = FurnitureGuildCustomizedVisualization.DEFAULT_COLOR_1; + this._color2 = FurnitureGuildCustomizedVisualization.DEFAULT_COLOR_2; + this._badgeAssetNameNormalScale = ''; + this._badgeAssetNameSmallScale = ''; } protected updateModel(scale: number): boolean { const flag = super.updateModel(scale); - if(!flag) return false; + if(this._badgeAssetNameNormalScale === '') + { + const assetName = this.object.model.getValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_ASSET_NAME); + + if(assetName) + { + this._badgeAssetNameNormalScale = assetName; + this._badgeAssetNameSmallScale = (this._badgeAssetNameNormalScale + '_32'); + } + } this._color1 = this.object.model.getValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_COLOR_1); this._color2 = this.object.model.getValue(RoomObjectVariable.FURNITURE_GUILD_CUSTOMIZED_COLOR_2); @@ -35,10 +52,34 @@ export class FurnitureGuildCustomizedVisualization extends FurnitureAnimatedVisu switch(tag) { - case 'COLOR1': return this._color1; - case 'COLOR2': return this._color2; + case FurnitureGuildCustomizedVisualization.PRIMARY_COLOUR_SPRITE_TAG: return this._color1; + case FurnitureGuildCustomizedVisualization.SECONDARY_COLOUR_SPRITE_TAG: return this._color2; } return super.getLayerColor(scale, layerId, colorId); } -} \ No newline at end of file + + public getSpriteAssetName(scale: number, layerId: number): string + { + const tag = this.getLayerTag(scale, this._direction, layerId); + + if(tag === FurnitureGuildCustomizedVisualization.BADGE) + { + if(scale === 32) return this._badgeAssetNameSmallScale; + + return this._badgeAssetNameNormalScale; + } + + return super.getSpriteAssetName(scale, layerId); + } + + protected getLibraryAssetNameForSprite(asset: IGraphicAsset, sprite: IRoomObjectSprite): string + { + if(sprite.tag === FurnitureGuildCustomizedVisualization.BADGE) + { + return '%group.badge.url%' + sprite.libraryAssetName.replace('badge_', ''); + } + + return super.getLibraryAssetNameForSprite(asset, sprite); + } +} diff --git a/src/nitro/ui/widget/enums/ContextMenuEnum.ts b/src/nitro/ui/widget/enums/ContextMenuEnum.ts index 6d7c7deb..94896ffa 100644 --- a/src/nitro/ui/widget/enums/ContextMenuEnum.ts +++ b/src/nitro/ui/widget/enums/ContextMenuEnum.ts @@ -8,6 +8,5 @@ export class ContextMenuEnum public static MYSTERY_TROPHY: string = 'MYSTERY_TROPHY'; public static RANDOM_TELEPORT: string = 'RANDOM_TELEPORT'; public static PURCHASABLE_CLOTHING: string = 'PURCHASABLE_CLOTHING'; - public static GROUP_FURNITURE: string = 'GROUP_FURNITURE'; public static GENERIC_USABLE: string = 'GENERIC_USABLE'; }