diff --git a/src/views/groups/views/shared-tabs/tab-badge/GroupSharedTabBadgeView.tsx b/src/views/groups/views/shared-tabs/tab-badge/GroupSharedTabBadgeView.tsx index bb800f1f..09de6a59 100644 --- a/src/views/groups/views/shared-tabs/tab-badge/GroupSharedTabBadgeView.tsx +++ b/src/views/groups/views/shared-tabs/tab-badge/GroupSharedTabBadgeView.tsx @@ -24,10 +24,10 @@ export const GroupSharedTabBadgeView: FC = props = const badgeParts: GroupBadgePart[] = [ new GroupBadgePart(GroupBadgePart.BASE, badgeBases[0].id, badgePartColors[0].id), - new GroupBadgePart(GroupBadgePart.SYMBOL), - new GroupBadgePart(GroupBadgePart.SYMBOL), - new GroupBadgePart(GroupBadgePart.SYMBOL), - new GroupBadgePart(GroupBadgePart.SYMBOL) + new GroupBadgePart(GroupBadgePart.SYMBOL, 0, badgePartColors[0].id), + new GroupBadgePart(GroupBadgePart.SYMBOL, 0, badgePartColors[0].id), + new GroupBadgePart(GroupBadgePart.SYMBOL, 0, badgePartColors[0].id), + new GroupBadgePart(GroupBadgePart.SYMBOL, 0, badgePartColors[0].id) ]; dispatchGroupsState({ @@ -37,6 +37,12 @@ export const GroupSharedTabBadgeView: FC = props = }, [ badgeBases, badgePartColors, groupBadgeParts ]); + const switchIndex = useCallback((index: number) => + { + setIsSelectingModel(false); + setEditingIndex(index); + }, []); + const selectPartProperty = useCallback((property: string, key: number) => { const clonedBadgeParts = Array.from(groupBadgeParts); @@ -83,7 +89,7 @@ export const GroupSharedTabBadgeView: FC = props = { groupBadgeParts && groupBadgeParts.map((badgePart, partIndex) => { return ( -
setEditingIndex(partIndex) }> +
switchIndex(partIndex) }> { badgePart.code && } { !badgePart.code && }
diff --git a/src/views/shared/badge-image/BadgeImageView.tsx b/src/views/shared/badge-image/BadgeImageView.tsx index c815f7f7..37c2a70f 100644 --- a/src/views/shared/badge-image/BadgeImageView.tsx +++ b/src/views/shared/badge-image/BadgeImageView.tsx @@ -1,5 +1,6 @@ -import { FC } from 'react'; -import { GetConfiguration, LocalizeBadgeDescription, LocalizeBadgeName, LocalizeText } from '../../../api'; +import { BadgeImageReadyEvent, NitroSprite, TextureUtils } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useEffect, useState } from 'react'; +import { GetSessionDataManager, LocalizeBadgeDescription, LocalizeBadgeName, LocalizeText } from '../../../api'; import { BadgeInformationView } from './badge-info/BadgeInformationView'; import { BadgeImageViewProps } from './BadgeImageView.types'; @@ -7,19 +8,48 @@ export const BadgeImageView: FC = props => { const { badgeCode = null, isGroup = false, showInfo = false, customTitle = null } = props; - function getBadgeUrl(): string + const [ badgeUrl, setBadgeUrl ] = useState(''); + const [ isListening, setIsListening ] = useState(true); + + const onBadgeImageReadyEvent = useCallback((event: BadgeImageReadyEvent) => { - if(isGroup) + if(event.badgeId !== badgeCode) return; + + const nitroSprite = new NitroSprite(event.image); + setBadgeUrl(TextureUtils.generateImageUrl(nitroSprite)); + + if(isListening) { - return ((GetConfiguration('badge.asset.group.url')).replace('%badgedata%', badgeCode)); + GetSessionDataManager().events.removeEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent); + setIsListening(false); + } + }, [ badgeCode, isListening ]); + + useEffect(() => + { + const existing = (isGroup) ? GetSessionDataManager().loadGroupBadgeImage(badgeCode) : GetSessionDataManager().loadBadgeImage(badgeCode); + + if(!existing) + { + GetSessionDataManager().events.addEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent); } else { - return ((GetConfiguration('badge.asset.url')).replace('%badgename%', badgeCode)); + const image = (isGroup) ? GetSessionDataManager().getGroupBadgeImage(badgeCode) : GetSessionDataManager().getBadgeImage(badgeCode); + const nitroSprite = new NitroSprite(image); + setBadgeUrl(TextureUtils.generateImageUrl(nitroSprite)); } - } - const url = `url('${ getBadgeUrl() }')`; + return (() => + { + if(isListening) + { + GetSessionDataManager().events.removeEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent); + } + }); + }, [ badgeCode ]); + + const url = `url('${ badgeUrl }')`; return
{ showInfo && }