From 3b18493a4105761d8c8a75f52b76560d20dfb32a Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 17 Jul 2021 12:34:49 -0400 Subject: [PATCH] Add catalog purchase animation --- .../CatalogRoomPreviewerView.tsx | 55 +++++++++++++++++++ .../default/CatalogLayoutDefaultView.tsx | 4 +- .../CatalogLayoutGuildCustomFurniView.tsx | 4 +- .../page/layout/pets/CatalogLayoutPetView.tsx | 6 +- .../spaces-new/CatalogLayoutSpacesView.tsx | 4 +- .../trophies/CatalogLayoutTrophiesView.tsx | 4 +- .../CatalogLayoutSearchResultView.tsx | 4 +- .../room-previewer/RoomPreviewerView.tsx | 4 +- 8 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 src/views/catalog/views/catalog-room-previewer/CatalogRoomPreviewerView.tsx diff --git a/src/views/catalog/views/catalog-room-previewer/CatalogRoomPreviewerView.tsx b/src/views/catalog/views/catalog-room-previewer/CatalogRoomPreviewerView.tsx new file mode 100644 index 00000000..94fc5ca8 --- /dev/null +++ b/src/views/catalog/views/catalog-room-previewer/CatalogRoomPreviewerView.tsx @@ -0,0 +1,55 @@ +import { NitroToolbarAnimateIconEvent, TextureUtils, ToolbarIconEnum } from 'nitro-renderer'; +import { FC, useCallback, useRef } from 'react'; +import { GetRoomEngine } from '../../../../api'; +import { CatalogEvent } from '../../../../events'; +import { useUiEvent } from '../../../../hooks'; +import { RoomPreviewerView } from '../../../shared/room-previewer/RoomPreviewerView'; +import { RoomPreviewerViewProps } from '../../../shared/room-previewer/RoomPreviewerView.types'; + +export const CatalogRoomPreviewerView: FC = props => +{ + const { roomPreviewer = null } = props; + const elementRef = useRef(null); + + const animatePurchase = useCallback(() => + { + if(!elementRef) return; + + const renderTexture = roomPreviewer.getRoomObjectCurrentImage(); + + if(!renderTexture) return; + + const image = TextureUtils.generateImage(renderTexture); + + if(!image) return; + + const bounds = elementRef.current.getBoundingClientRect(); + + const x = (bounds.x + (bounds.width / 2)); + const y = (bounds.y + (bounds.height / 2)); + + const event = new NitroToolbarAnimateIconEvent(image, x, y); + + event.iconName = ToolbarIconEnum.INVENTORY; + + GetRoomEngine().events.dispatchEvent(event); + }, [ roomPreviewer ]); + + const onCatalogEvent = useCallback((event: CatalogEvent) => + { + switch(event.type) + { + case CatalogEvent.PURCHASE_SUCCESS: + animatePurchase(); + return; + } + }, [ animatePurchase ]); + + useUiEvent(CatalogEvent.PURCHASE_SUCCESS, onCatalogEvent); + + return ( +
+ +
+ ); +} diff --git a/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx b/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx index 076a0ee2..db599364 100644 --- a/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx +++ b/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx @@ -1,8 +1,8 @@ import { FC } from 'react'; import { LimitedEditionCompletePlateView } from '../../../../../shared/limited-edition/complete-plate/LimitedEditionCompletePlateView'; -import { RoomPreviewerView } from '../../../../../shared/room-previewer/RoomPreviewerView'; import { GetCatalogPageImage, GetCatalogPageText, GetOfferName } from '../../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../../context/CatalogContext'; +import { CatalogRoomPreviewerView } from '../../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogPageOffersView } from '../../offers/CatalogPageOffersView'; import { CatalogPurchaseView } from '../../purchase/CatalogPurchaseView'; import { CatalogLayoutDefaultViewProps } from './CatalogLayoutDefaultView.types'; @@ -29,7 +29,7 @@ export const CatalogLayoutDefaultView: FC = props } { product &&
- + { product.uniqueLimitedItem && }
{ GetOfferName(activeOffer) }
diff --git a/src/views/catalog/views/page/layout/guild-custom-furni/CatalogLayoutGuildCustomFurniView.tsx b/src/views/catalog/views/page/layout/guild-custom-furni/CatalogLayoutGuildCustomFurniView.tsx index 0057dfa0..5cefaaf0 100644 --- a/src/views/catalog/views/page/layout/guild-custom-furni/CatalogLayoutGuildCustomFurniView.tsx +++ b/src/views/catalog/views/page/layout/guild-custom-furni/CatalogLayoutGuildCustomFurniView.tsx @@ -2,9 +2,9 @@ import { CatalogGroupsComposer } from 'nitro-renderer'; import { FC, useEffect } from 'react'; import { SendMessageHook } from '../../../../../../hooks/messages'; import { LocalizeText } from '../../../../../../utils/LocalizeText'; -import { RoomPreviewerView } from '../../../../../shared/room-previewer/RoomPreviewerView'; import { GetOfferName } from '../../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../../context/CatalogContext'; +import { CatalogRoomPreviewerView } from '../../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogPageOffersView } from '../../offers/CatalogPageOffersView'; import { CatalogPurchaseView } from '../../purchase/CatalogPurchaseView'; import { CatalogLayoutGuildCustomFurniViewProps } from './CatalogLayoutGuildCustomFurniView.types'; @@ -30,7 +30,7 @@ export const CatalogLayouGuildCustomFurniView: FC { product &&
- +
{ GetOfferName(activeOffer) }
{ groups.length === 0 &&
{ LocalizeText('catalog.guild_selector.members_only') } diff --git a/src/views/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx b/src/views/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx index 0651cca6..38388178 100644 --- a/src/views/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx +++ b/src/views/catalog/views/page/layout/pets/CatalogLayoutPetView.tsx @@ -4,10 +4,10 @@ import { GetProductDataForLocalization } from '../../../../../../api/nitro/sessi import { SendMessageHook } from '../../../../../../hooks/messages/message-event'; import { LocalizeText } from '../../../../../../utils/LocalizeText'; import { PetImageView } from '../../../../../shared/pet-image/PetImageView'; -import { RoomPreviewerView } from '../../../../../shared/room-previewer/RoomPreviewerView'; import { GetCatalogPageImage, GetCatalogPageText, GetPetAvailableColors, GetPetIndexFromLocalization } from '../../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../../context/CatalogContext'; import { CatalogActions } from '../../../../reducers/CatalogReducer'; +import { CatalogRoomPreviewerView } from '../../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogLayoutPetViewProps } from './CatalogLayoutPetView.types'; import { CatalogLayoutPetPurchaseView } from './purchase/CatalogLayoutPetPurchaseView'; @@ -169,12 +169,12 @@ export const CatalogLayoutPetView: FC = props =>
} { (petIndex >= 0) &&
- + { (petIndex > -1 && petIndex <= 7) && } - +
{ petBreedName }
} diff --git a/src/views/catalog/views/page/layout/spaces-new/CatalogLayoutSpacesView.tsx b/src/views/catalog/views/page/layout/spaces-new/CatalogLayoutSpacesView.tsx index 54ca82e5..148d3c85 100644 --- a/src/views/catalog/views/page/layout/spaces-new/CatalogLayoutSpacesView.tsx +++ b/src/views/catalog/views/page/layout/spaces-new/CatalogLayoutSpacesView.tsx @@ -2,10 +2,10 @@ import { CatalogPageOfferData, IFurnitureData } from 'nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { GetSessionDataManager } from '../../../../../../api'; import { LocalizeText } from '../../../../../../utils/LocalizeText'; -import { RoomPreviewerView } from '../../../../../shared/room-previewer/RoomPreviewerView'; import { GetCatalogPageImage, GetCatalogPageText, GetOfferName } from '../../../../common/CatalogUtilities'; import { ProductTypeEnum } from '../../../../common/ProductTypeEnum'; import { useCatalogContext } from '../../../../context/CatalogContext'; +import { CatalogRoomPreviewerView } from '../../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogPageOffersView } from '../../offers/CatalogPageOffersView'; import { CatalogPurchaseView } from '../../purchase/CatalogPurchaseView'; import { CatalogLayoutSpacesViewProps } from './CatalogLayoutSpacesView.types'; @@ -88,7 +88,7 @@ export const CatalogLayoutSpacesView: FC = props =
} { product &&
- +
{ GetOfferName(activeOffer) }
} diff --git a/src/views/catalog/views/page/layout/trophies/CatalogLayoutTrophiesView.tsx b/src/views/catalog/views/page/layout/trophies/CatalogLayoutTrophiesView.tsx index fb68497c..471001a1 100644 --- a/src/views/catalog/views/page/layout/trophies/CatalogLayoutTrophiesView.tsx +++ b/src/views/catalog/views/page/layout/trophies/CatalogLayoutTrophiesView.tsx @@ -1,7 +1,7 @@ import { FC, useState } from 'react'; -import { RoomPreviewerView } from '../../../../../shared/room-previewer/RoomPreviewerView'; import { GetOfferName } from '../../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../../context/CatalogContext'; +import { CatalogRoomPreviewerView } from '../../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogPageOffersView } from '../../offers/CatalogPageOffersView'; import { CatalogPurchaseView } from '../../purchase/CatalogPurchaseView'; import { CatalogLayoutTrophiesViewProps } from './CatalogLayoutTrophiesView.types'; @@ -25,7 +25,7 @@ export const CatalogLayoutTrophiesView: FC = pro
{ product &&
- +
{ GetOfferName(activeOffer) }
} diff --git a/src/views/catalog/views/page/search-result/CatalogLayoutSearchResultView.tsx b/src/views/catalog/views/page/search-result/CatalogLayoutSearchResultView.tsx index d5e147f2..a234f840 100644 --- a/src/views/catalog/views/page/search-result/CatalogLayoutSearchResultView.tsx +++ b/src/views/catalog/views/page/search-result/CatalogLayoutSearchResultView.tsx @@ -1,8 +1,8 @@ import { FC } from 'react'; import { LimitedEditionCompletePlateView } from '../../../../shared/limited-edition/complete-plate/LimitedEditionCompletePlateView'; -import { RoomPreviewerView } from '../../../../shared/room-previewer/RoomPreviewerView'; import { GetOfferName } from '../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../context/CatalogContext'; +import { CatalogRoomPreviewerView } from '../../catalog-room-previewer/CatalogRoomPreviewerView'; import { CatalogPurchaseView } from '../purchase/CatalogPurchaseView'; import { CatalogLayoutSearchResultViewProps } from './CatalogLayoutSearchResultView.types'; import { CatalogSearchResultOffersView } from './offers/CatalogSearchResultOffersView'; @@ -22,7 +22,7 @@ export const CatalogLayoutSearchResultView: FC { product &&
- + { product.uniqueLimitedItem && }
{ GetOfferName(activeOffer) }
diff --git a/src/views/shared/room-previewer/RoomPreviewerView.tsx b/src/views/shared/room-previewer/RoomPreviewerView.tsx index cc4a3016..b2e972a4 100644 --- a/src/views/shared/room-previewer/RoomPreviewerView.tsx +++ b/src/views/shared/room-previewer/RoomPreviewerView.tsx @@ -1,5 +1,5 @@ import { ColorConverter, IRoomRenderingCanvas, Nitro, TextureUtils } from 'nitro-renderer'; -import { createRef, FC, useCallback, useEffect, useState } from 'react'; +import { FC, useCallback, useEffect, useRef, useState } from 'react'; import { RoomPreviewerViewProps } from './RoomPreviewerView.types'; export const RoomPreviewerView: FC = props => @@ -8,7 +8,7 @@ export const RoomPreviewerView: FC = props => const [ renderingCanvas, setRenderingCanvas ] = useState(null); - const elementRef = createRef(); + const elementRef = useRef(); const update = useCallback((time: number) => {