Commit ad9e164a authored by Thijmen's avatar Thijmen
Browse files

Pet catalog updates

parent 556609f6
import { Component } from '@angular/core';
import { Component, NgZone, OnInit } from '@angular/core';
import { CatalogLayout } from '../../../CatalogLayout';
import { CatalogService } from '../../../services/catalog.service';
import { MarketplaceService } from '../../../services/marketplace.service';
import { SellablePetPaletteData } from 'nitro-renderer/src/nitro/communication/messages/parser/catalog/utils/SellablePetPaletteData';
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
import { CatalogRequestPetBreedsComposer } from 'nitro-renderer/src/nitro/communication/messages/outgoing/catalog/CatalogRequestPetBreedsComposer';
import { SellablePetPalettesEvent } from 'nitro-renderer/src/nitro/communication/messages/incoming/catalog/SellablePetPalettesEvent';
import { IProductData } from 'nitro-renderer/src/nitro/session/product/IProductData';
@Component({
templateUrl: './pets.template.html'
})
export class CatalogLayoutPetsComponent extends CatalogLayout
export class CatalogLayoutPetsComponent extends CatalogLayout implements OnInit
{
public static CODE: string = 'pets';
}
\ No newline at end of file
public petIndex: number = -1;
private colorsShowing: boolean = false;
public sellablePalettes: SellablePetPaletteData[] = [];
private selectedColorIndex: number = -1;
private sellableColors: number[][] = [];
private _palettesEvent: SellablePetPalettesEvent = null;
private productData: IProductData;
public selectedPalette: number = -1;
public ngOnInit(): void
{
this._catalogService.setPetsPage(this);
if(!this.offers || !this.offers.length) return;
const offer = this.offers[0];
if(!offer) return;
this.setPetIndex(this.getPetIndexFromLocalization(offer.localizationId));
this.setColorsShowing(false);
this.productData = Nitro.instance.sessionDataManager.getProductData(offer.localizationId);
Nitro.instance.communication.connection.send(new CatalogRequestPetBreedsComposer(this.productData.type));
}
private setColorsShowing(show: boolean): void
{
this.colorsShowing = show;
}
private setPetIndex(index: number): void
{
this.petIndex = index;
if(index === -1) return;
const colors = this.getPetAvailableColors(index, this.sellablePalettes);
this.selectedColorIndex = colors.length ? 0 : -1;
this.sellableColors = colors;
}
public getColor()
{
if(!this.sellableColors.length || this.selectedColorIndex === -1) return 0xFFFFFF;
return this.sellableColors[this.selectedColorIndex][0];
}
private getPetIndexFromLocalization(localization: string): number
{
if(!localization.length) return 0;
let index = (localization.length - 1);
while(index >= 0)
{
if(isNaN(parseInt(localization.charAt(index)))) break;
index--;
}
if(index > 0) return parseInt(localization.substring(index + 1));
return -1;
}
private getPetAvailableColors(petIndex: number, palettes: SellablePetPaletteData[]): number[][]
{
switch(petIndex)
{
case 0:
return [[16743226], [16750435], [16764339], [0xF59500], [16498012], [16704690], [0xEDD400], [16115545], [16513201], [8694111], [11585939], [14413767], [6664599], [9553845], [12971486], [8358322], [10002885], [13292268], [10780600], [12623573], [14403561], [12418717], [14327229], [15517403], [14515069], [15764368], [16366271], [0xABABAB], [0xD4D4D4], [0xFFFFFF], [14256481], [14656129], [15848130], [14005087], [14337152], [15918540], [15118118], [15531929], [9764857], [11258085]];
case 1:
return [[16743226], [16750435], [16764339], [0xF59500], [16498012], [16704690], [0xEDD400], [16115545], [16513201], [8694111], [11585939], [14413767], [6664599], [9553845], [12971486], [8358322], [10002885], [13292268], [10780600], [12623573], [14403561], [12418717], [14327229], [15517403], [14515069], [15764368], [16366271], [0xABABAB], [0xD4D4D4], [0xFFFFFF], [14256481], [14656129], [15848130], [14005087], [14337152], [15918540], [15118118], [15531929], [9764857], [11258085]];
case 2:
return [[16579283], [15378351], [8830016], [15257125], [9340985], [8949607], [6198292], [8703620], [9889626], [8972045], [12161285], [13162269], [8620113], [12616503], [8628101], [0xD2FF00], [9764857]];
case 3:
return [[0xFFFFFF], [0xEEEEEE], [0xDDDDDD]];
case 4:
return [[0xFFFFFF], [16053490], [15464440], [16248792], [15396319], [15007487]];
case 5:
return [[0xFFFFFF], [0xEEEEEE], [0xDDDDDD]];
case 6:
return [[0xFFFFFF], [0xEEEEEE], [0xDDDDDD], [16767177], [16770205], [16751331]];
case 7:
return [[0xCCCCCC], [0xAEAEAE], [16751331], [10149119], [16763290], [16743786]];
default:
{
const colors: number[][] = [];
for(const palette of palettes)
{
const petColorResult = Nitro.instance.roomEngine.getPetColorResult(petIndex, palette.paletteId);
if(!petColorResult) continue;
if(petColorResult._Str_5845 === petColorResult._Str_6659)
{
colors.push([petColorResult._Str_5845]);
}
else
{
colors.push([petColorResult._Str_5845, petColorResult._Str_6659]);
}
}
return colors;
}
}
}
public setPalettes(event: SellablePetPalettesEvent): void
{
this._ngZone.run(() =>
{
this._palettesEvent = event;
const palettes: SellablePetPaletteData[] = [];
for(const paletteData of event.getParser().palettes)
{
if(!paletteData.sellable) continue;
palettes.push(paletteData);
}
this.sellablePalettes = palettes;
});
}
public selectPalette(index: number): void
{
this.selectedPalette = index;
if(!this.roomPreviewer) return;
this.roomPreviewer.reset(false);
if(index === -1 || !this.sellablePalettes.length) return;
let petFigureString = `${this.petIndex} ${this.sellablePalettes[index].paletteId}`;
if(index <= 7) petFigureString += ` ${this.getColor().toString(16)}`;
this.roomPreviewer.addPetIntoRoom(petFigureString);
}
public getPetBreedName(): string
{
if(this.petIndex === -1 || !this.sellablePalettes.length || this.selectedPalette === -1) return '';
return Nitro.instance.localization.getValue(`pet.breed.${this.petIndex}.${this.sellablePalettes[this.selectedPalette].breedId}`);
}
}
<div class="d-flex flex-column w-100 h-100 card nitro-catalog-layout-pets2-component">
</div>
\ No newline at end of file
<div class="d-flex flex-column w-100 h-100">
<div *ngIf="selectedPalette >= 0"
class="position-relative d-flex flex-column justify-content-center align-items-center w-100 mb-2">
<div class="position-absolute bg-secondary rounded text-center m-2 p-2 t-0 l-0"
style="z-index:1;">{{getPetBreedName() }}</div>
<div class="room-preview" nitro-room-preview-component [roomPreviewer]="roomPreviewer" [width]="366"
[height]="180"></div>
</div>
<div *ngIf="sellablePalettes.length > 0"
class="d-flex flex-column w-100 h-100 card nitro-catalog-layout-pets2-component">
<perfect-scrollbar class="grid-container w-100" style="min-height:209px;max-height:209px;height:209px;">
<div class="grid-items grid-6">
<div (click)="selectPalette(i)" *ngFor="let palette of sellablePalettes; let i = index;"
class="d-flex flex-column item-detail justify-content-center align-items-center">
<button pet-image [asBackground]="true" [paletteId]="palette.paletteId"
[headOnly]="true" [direction]="2" [typeId]="petIndex" type="button"
class="position-relative btn btn-secondary align-items-end detail-info has-image"></button>
</div>
</div>
</perfect-scrollbar>
</div>
</div>
......@@ -53,6 +53,8 @@ import { CatalogLayoutVipBuyComponent } from '../components/layouts/vip-buy/vip-
import { CatalogMainComponent } from '../components/main/main.component';
import { GiftWrappingConfiguration } from '../gifts/gift-wrapping-configuration';
import { Purse } from '../purse/purse';
import { SellablePetPalettesEvent } from 'nitro-renderer/src/nitro/communication/messages/incoming/catalog/SellablePetPalettesEvent';
import { CatalogLayoutPetsComponent } from '../components/layouts/pets/pets.component';
@Injectable()
export class CatalogService implements OnDestroy
......@@ -62,6 +64,7 @@ export class CatalogService implements OnDestroy
private _messages: IMessageEvent[] = [];
private _component: CatalogMainComponent = null;
private _giftConfiguratorComponent: CatalogCustomizeGiftComponent = null;
private _petsComponent: CatalogLayoutPetsComponent = null;
private _catalogMode: number = -1;
private _catalogRoot: CatalogPageData = null;
private _activePage: ICatalogPageParser = null;
......@@ -79,6 +82,7 @@ export class CatalogService implements OnDestroy
private _offersToRoots: AdvancedMap<number, CatalogPageData[]> = null;
private _searchResultsPages: CatalogSearchData;
private _petPalettes: SellablePetPalettesEvent = null;
constructor(
private _settingsService: SettingsService,
......@@ -120,6 +124,7 @@ export class CatalogService implements OnDestroy
new CatalogClubGiftsEvent(this.onCatalogClubGiftsEvent.bind(this)),
new CatalogRedeemVoucherErrorEvent(this.onCatalogRedeemVoucherError.bind(this)),
new CatalogRedeemVoucherOkEvent(this.onCatalogRedeemVoucherOk.bind(this)),
new SellablePetPalettesEvent(this.onReceiveSellablePetPalettesEvent.bind(this)),
];
for(const message of this._messages) Nitro.instance.communication.registerMessageEvent(message);
......@@ -336,11 +341,11 @@ export class CatalogService implements OnDestroy
this._ngZone.run(() =>
{
this._isLoading = false;
this._catalogMode = -1;
this._catalogRoot = null;
this._activePage = null;
this._activePageData = null;
this._isLoading = false;
this._catalogMode = -1;
this._catalogRoot = null;
this._activePage = null;
this._activePageData = null;
if(this._component) this._component.reset();
......@@ -365,6 +370,19 @@ export class CatalogService implements OnDestroy
this._notificationService.alert('${catalog.alert.voucherredeem.error.description.' + parser.errorCode + '}', '${catalog.alert.voucherredeem.error.title}');
}
private onReceiveSellablePetPalettesEvent(event: SellablePetPalettesEvent): void
{
if(!event) return;
const parser = event.getParser();
if(!parser) return;
this._petPalettes = event;
if(this._petsComponent) this._petsComponent.setPalettes(event);
}
private onCatalogRedeemVoucherOk(event: CatalogRedeemVoucherOkEvent): void
{
if(!event) return;
......@@ -394,10 +412,10 @@ export class CatalogService implements OnDestroy
{
if(!mode) return;
this._isLoading = true;
this._catalogRoot = null;
this._activePage = null;
this._activePageData = null;
this._isLoading = true;
this._catalogRoot = null;
this._activePage = null;
this._activePageData = null;
(this._component && this._component.reset());
......@@ -492,9 +510,9 @@ export class CatalogService implements OnDestroy
this.purchaseById(page.pageId, offer.offerId, quantity, extra);
}
public purchaseGiftOffer(activePage: ICatalogPageParser, activeOffer: CatalogPageOfferData, extraData:string, receiverName: string, giftMessage: string, spriteId: number, color: number, ribbonId: number, anonymousGift: boolean): void
public purchaseGiftOffer(activePage: ICatalogPageParser, activeOffer: CatalogPageOfferData, extraData: string, receiverName: string, giftMessage: string, spriteId: number, color: number, ribbonId: number, anonymousGift: boolean): void
{
Nitro.instance.communication.connection.send(new CatalogPurchaseGiftComposer(activePage.pageId, activeOffer.offerId, extraData, receiverName, giftMessage, spriteId, color, ribbonId, anonymousGift ));
Nitro.instance.communication.connection.send(new CatalogPurchaseGiftComposer(activePage.pageId, activeOffer.offerId, extraData, receiverName, giftMessage, spriteId, color, ribbonId, anonymousGift));
}
public purchaseById(pageId: number, offerId: number, quantity: number, extra: string = null)
......@@ -649,8 +667,8 @@ export class CatalogService implements OnDestroy
for(const furniItem of furni)
{
const hasOffer = this.getOfferPages(furniItem.purchaseOfferId);
const hasRentOffer = this.getOfferPages(furniItem.rentOfferId);
const hasOffer = this.getOfferPages(furniItem.purchaseOfferId);
const hasRentOffer = this.getOfferPages(furniItem.rentOfferId);
const combinedOfferPages = [hasOffer, hasRentOffer];
......@@ -694,7 +712,12 @@ export class CatalogService implements OnDestroy
return this._searchResultsPages;
}
public clearSearchResults(): void
public setPetsPage(page: CatalogLayoutPetsComponent): void
{
this._petsComponent = page;
}
public clearSearchResults(): void
{
this._searchResultsPages = null;
this.component && this.component.reselectCurrentTab();
......
......@@ -30,6 +30,15 @@ export class PetImageDirective implements OnInit, OnChanges, IGetImageListener
@Input()
public asBackground: boolean = false;
@Input()
public typeId: number = null;
@Input()
public paletteId: number =null;
@Input()
public color: number = 0xFFFFFF;
private _petImageCache: AdvancedMap<string, string> = new AdvancedMap();
public petUrl: string = null;
......@@ -82,7 +91,6 @@ export class PetImageDirective implements OnInit, OnChanges, IGetImageListener
this.needsUpdate = false;
const imageUrl = this.getPetImageUrl();
if(!imageUrl || !imageUrl.length) return;
const element = this._elementRef.nativeElement;
......@@ -126,11 +134,14 @@ export class PetImageDirective implements OnInit, OnChanges, IGetImageListener
let imageResult: ImageResult = null;
const typeId = this.petFigureData ? this.petFigureData.typeId : this.typeId;
const paletteId = this.petFigureData ? this.petFigureData.paletteId : this.paletteId;
const color = this.petFigureData ? this.petFigureData.color : this.color;
this._ngZone.runOutsideAngular(() =>
{
const typeId = this.petFigureData.typeId;
imageResult = Nitro.instance.roomEngine.getRoomObjectPetImage(typeId, this.petFigureData.paletteId, this.petFigureData.color, new Vector3d((this.direction * 45)), 64, this, this.headOnly, 0, this.petFigureData.customParts, 'std');
imageResult = Nitro.instance.roomEngine.getRoomObjectPetImage(typeId, paletteId, color, new Vector3d((this.direction * 45)), 64, this, this.headOnly, 0, null, 'std');
if(imageResult)
{
......@@ -184,6 +195,9 @@ export class PetImageDirective implements OnInit, OnChanges, IGetImageListener
public getPetBuildString(): string
{
if(!this.petFigureData) return '';
return (`${ this.petFigureData.figureString }:${ this.headOnly }:${ this.direction }`);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment