diff --git a/src/api/inventory/IPrefixItem.ts b/src/api/inventory/IPrefixItem.ts new file mode 100644 index 0000000..b65981f --- /dev/null +++ b/src/api/inventory/IPrefixItem.ts @@ -0,0 +1,9 @@ +export interface IPrefixItem +{ + id: number; + text: string; + color: string; + icon: string; + effect: string; + active: boolean; +} diff --git a/src/api/inventory/UnseenItemCategory.ts b/src/api/inventory/UnseenItemCategory.ts index cbd7e9b..0ac720c 100644 --- a/src/api/inventory/UnseenItemCategory.ts +++ b/src/api/inventory/UnseenItemCategory.ts @@ -6,4 +6,5 @@ export class UnseenItemCategory public static BADGE: number = 4; public static BOT: number = 5; public static GAMES: number = 6; + public static PREFIX: number = 7; } diff --git a/src/api/inventory/index.ts b/src/api/inventory/index.ts index 6a245d7..4e6ca21 100644 --- a/src/api/inventory/index.ts +++ b/src/api/inventory/index.ts @@ -5,6 +5,7 @@ export * from './GroupItem'; export * from './IBotItem'; export * from './IFurnitureItem'; export * from './IPetItem'; +export * from './IPrefixItem'; export * from './IUnseenItemTracker'; export * from './InventoryUtilities'; export * from './PetUtilities'; diff --git a/src/api/room/widgets/ChatBubbleMessage.ts b/src/api/room/widgets/ChatBubbleMessage.ts index 3e31e38..3fc6719 100644 --- a/src/api/room/widgets/ChatBubbleMessage.ts +++ b/src/api/room/widgets/ChatBubbleMessage.ts @@ -7,6 +7,10 @@ export class ChatBubbleMessage public height: number = 0; public elementRef: HTMLDivElement = null; public skipMovement: boolean = false; + public prefixText: string = ''; + public prefixColor: string = ''; + public prefixIcon: string = ''; + public prefixEffect: string = ''; private _top: number = 0; private _left: number = 0; diff --git a/src/api/room/widgets/index.ts b/src/api/room/widgets/index.ts index 5cef378..4892937 100644 --- a/src/api/room/widgets/index.ts +++ b/src/api/room/widgets/index.ts @@ -7,6 +7,7 @@ export * from './AvatarInfoUser'; export * from './AvatarInfoUtilities'; export * from './BotSkillsEnum'; export * from './ChatBubbleMessage'; +export * from './CommandDefinition'; export * from './ChatBubbleUtilities'; export * from './ChatMessageTypeEnum'; export * from './DimmerFurnitureWidgetPresetItem'; diff --git a/src/api/utils/PrefixUtils.ts b/src/api/utils/PrefixUtils.ts new file mode 100644 index 0000000..5da5133 --- /dev/null +++ b/src/api/utils/PrefixUtils.ts @@ -0,0 +1,53 @@ +export const PRESET_PREFIX_EFFECTS: { id: string; label: string; icon: string }[] = [ + { id: '', label: 'None', icon: '—' }, + { id: 'glow', label: 'Glow', icon: '✨' }, + { id: 'shadow', label: 'Shadow', icon: '🌑' }, + { id: 'italic', label: 'Italic', icon: '𝑰' }, + { id: 'outline', label: 'Outline', icon: '🔲' }, + { id: 'pulse', label: 'Pulse', icon: '💫' }, + { id: 'bold-glow', label: 'Neon', icon: '💡' }, +]; + +export const parsePrefixColors = (text: string, colorStr: string): string[] => +{ + if(!colorStr || !text) return []; + + const colors = colorStr.split(','); + return [ ...text ].map((_, i) => colors[Math.min(i, colors.length - 1)]); +}; + +export const getPrefixEffectStyle = (effect: string, color?: string): Record => +{ + const baseColor = color || '#FFFFFF'; + + switch(effect) + { + case 'glow': + return { textShadow: `0 0 6px ${ baseColor }, 0 0 12px ${ baseColor }80` }; + case 'shadow': + return { textShadow: '2px 2px 4px rgba(0,0,0,0.7), 1px 1px 2px rgba(0,0,0,0.5)' }; + case 'italic': + return { fontStyle: 'italic' }; + case 'outline': + return { + WebkitTextStroke: '0.5px rgba(0,0,0,0.6)', + textShadow: '1px 1px 0 rgba(0,0,0,0.3), -1px -1px 0 rgba(0,0,0,0.3), 1px -1px 0 rgba(0,0,0,0.3), -1px 1px 0 rgba(0,0,0,0.3)' + }; + case 'pulse': + return { animation: 'prefix-pulse 1.5s ease-in-out infinite' }; + case 'bold-glow': + return { + textShadow: `0 0 4px ${ baseColor }, 0 0 8px ${ baseColor }, 0 0 16px ${ baseColor }60`, + fontWeight: 900 + }; + default: + return {}; + } +}; + +export const PREFIX_EFFECT_KEYFRAMES = ` +@keyframes prefix-pulse { + 0%, 100% { opacity: 1; } + 50% { opacity: 0.5; } +} +`; diff --git a/src/api/utils/index.ts b/src/api/utils/index.ts index 1824add..4a4b221 100644 --- a/src/api/utils/index.ts +++ b/src/api/utils/index.ts @@ -11,6 +11,7 @@ export * from './LocalizeFormattedNumber'; export * from './LocalizeShortNumber'; export * from './LocalizeText'; export * from './PlaySound'; +export * from './PrefixUtils'; export * from './ProductImageUtility'; export * from './Randomizer'; export * from './RoomChatFormatter'; diff --git a/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx b/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx new file mode 100644 index 0000000..0b7f904 --- /dev/null +++ b/src/components/catalog/views/page/layout/CatalogLayoutCustomPrefixView.tsx @@ -0,0 +1,470 @@ +import { PurchasePrefixComposer } from '@nitrots/nitro-renderer'; +import { createPortal } from 'react-dom'; +import { FC, useEffect, useMemo, useRef, useState } from 'react'; +import { SendMessageComposer, PRESET_PREFIX_EFFECTS, parsePrefixColors, getPrefixEffectStyle, PREFIX_EFFECT_KEYFRAMES } from '../../../../../api'; +import { CatalogLayoutProps } from './CatalogLayout.types'; +import data from '@emoji-mart/data'; +import Picker from '@emoji-mart/react'; + +const PRESET_COLORS: string[] = [ + '#FF0000', '#FF6600', '#FFCC00', '#33CC00', '#00CCFF', + '#0066FF', '#9933FF', '#FF33CC', '#FFFFFF', '#CCCCCC', + '#999999', '#333333', '#FF9999', '#99FF99', '#9999FF', + '#FFD700', '#FF4500', '#00CED1', '#8A2BE2', '#DC143C' +]; + +export const CatalogLayoutCustomPrefixView: FC = props => +{ + const { page = null, hideNavigation = null } = props; + + useEffect(() => + { + hideNavigation(); + }, [ page, hideNavigation ]); + + const [ prefixText, setPrefixText ] = useState(''); + const [ colorMode, setColorMode ] = useState<'single' | 'perLetter'>('single'); + const [ singleColor, setSingleColor ] = useState('#FFFFFF'); + const [ letterColors, setLetterColors ] = useState>({}); + const [ selectedLetterIndex, setSelectedLetterIndex ] = useState(null); + const [ customColorInput, setCustomColorInput ] = useState('#FFFFFF'); + const [ selectedIcon, setSelectedIcon ] = useState(''); + const [ showIconPicker, setShowIconPicker ] = useState(false); + const [ selectedEffect, setSelectedEffect ] = useState(''); + const [ purchased, setPurchased ] = useState(false); + const pickerContainerRef = useRef(null); + + // Inject style into emoji-mart Shadow DOM to remove backdrop-filter blur + useEffect(() => + { + if(!showIconPicker) return; + + const timer = setTimeout(() => + { + const container = pickerContainerRef.current; + if(!container) return; + + const emPicker = container.querySelector('em-emoji-picker'); + if(!emPicker?.shadowRoot) return; + + const existing = emPicker.shadowRoot.querySelector('#no-blur-fix'); + if(existing) return; + + const style = document.createElement('style'); + style.id = 'no-blur-fix'; + style.textContent = `.sticky { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background-color: rgb(var(--em-rgb-background)) !important; } .menu { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background-color: rgb(var(--em-rgb-background)) !important; }`; + emPicker.shadowRoot.appendChild(style); + }, 50); + + return () => clearTimeout(timer); + }, [ showIconPicker ]); + + const colorString = useMemo(() => + { + if(colorMode === 'single') return singleColor; + + if(!prefixText.length) return singleColor; + + return [ ...prefixText ].map((_, i) => letterColors[i] || singleColor).join(','); + }, [ colorMode, singleColor, letterColors, prefixText ]); + + const previewColors = useMemo(() => + { + return parsePrefixColors(prefixText || '...', colorString || '#FFFFFF'); + }, [ prefixText, colorString ]); + + const isValid = useMemo(() => + { + if(!prefixText.trim().length || prefixText.trim().length > 15) return false; + + if(colorMode === 'single') return /^#[0-9A-Fa-f]{6}$/.test(singleColor); + + const colors = colorString.split(','); + return colors.every(c => /^#[0-9A-Fa-f]{6}$/.test(c)); + }, [ prefixText, colorMode, singleColor, colorString ]); + + const handlePurchase = () => + { + if(!isValid) return; + + SendMessageComposer(new PurchasePrefixComposer(prefixText.trim(), colorString, selectedIcon, selectedEffect)); + setPurchased(true); + setTimeout(() => setPurchased(false), 2000); + }; + + const handleColorSelect = (color: string) => + { + if(colorMode === 'single') + { + setSingleColor(color); + setCustomColorInput(color); + } + else if(selectedLetterIndex !== null) + { + setLetterColors(prev => ({ ...prev, [selectedLetterIndex]: color })); + setCustomColorInput(color); + + // Auto-advance to next letter + if(selectedLetterIndex < prefixText.length - 1) + { + const nextIdx = selectedLetterIndex + 1; + setSelectedLetterIndex(nextIdx); + setCustomColorInput(letterColors[nextIdx] || singleColor); + } + } + }; + + const handleCustomColorChange = (value: string) => + { + setCustomColorInput(value); + if(/^#[0-9A-Fa-f]{6}$/.test(value)) + { + if(colorMode === 'single') + { + setSingleColor(value); + } + else if(selectedLetterIndex !== null) + { + setLetterColors(prev => ({ ...prev, [selectedLetterIndex]: value })); + } + } + }; + + const handleTextChange = (newText: string) => + { + setPrefixText(newText); + if(selectedLetterIndex !== null && selectedLetterIndex >= newText.length) + { + setSelectedLetterIndex(newText.length > 0 ? newText.length - 1 : null); + } + }; + + const applyColorToAll = () => + { + if(!prefixText.length) return; + + const newColors: Record = {}; + [ ...prefixText ].forEach((_, i) => { newColors[i] = customColorInput; }); + setLetterColors(newColors); + }; + + const hasMultiColor = colorMode === 'perLetter' && previewColors.length > 1 && new Set(previewColors).size > 1; + + const currentActiveColor = colorMode === 'single' + ? singleColor + : (selectedLetterIndex !== null ? (letterColors[selectedLetterIndex] || singleColor) : singleColor); + + const effectStyle = getPrefixEffectStyle(selectedEffect, previewColors[0] || '#FFFFFF'); + + return ( +
+ + + { /* Header */ } + { page.localization.getImage(0) && + } + { page.localization.getText(0) && +
} + + { /* Live Preview */ } +
+
+ + { selectedIcon && { selectedIcon } } + + {'{'} + { hasMultiColor + ? [ ...(prefixText || '...') ].map((char, i) => ( + { char } + )) + : (prefixText || '...') + } + {'}'} + + + Username +
+ + { /* Text + Icon Row */ } +
+
+ +
+ handleTextChange(e.target.value) } /> + + { prefixText.length }/15 + +
+
+
+ +
+ + { selectedIcon && + + } +
+
+
+ + { /* Emoji Picker (emoji-mart) - portaled to body, no backdrop */ } + { showIconPicker && createPortal( + <> +
setShowIconPicker(false) } /> +
+ { setSelectedIcon(emoji.native); setShowIconPicker(false); } } + theme="dark" + previewPosition="none" + skinTonePosition="search" + perLine={ 8 } + maxFrequentRows={ 2 } + emojiSize={ 22 } + emojiButtonSize={ 30 } + dynamicWidth={ false } + set="native" + /> +
+ , + document.body + ) } + + { /* Effect Selector */ } +
+ +
+ { PRESET_PREFIX_EFFECTS.map(fx => ( + + )) } +
+
+ + { /* Color Mode Toggle */ } +
+ +
+ + +
+
+ + { /* Per-Letter Selector */ } + { colorMode === 'perLetter' && prefixText.length > 0 && ( +
+
+ + Select a letter, then choose a color. Auto-advances. + + +
+
+ { [ ...prefixText ].map((char, i) => + { + const charColor = letterColors[i] || singleColor; + const isSelected = selectedLetterIndex === i; + return ( +
{ setSelectedLetterIndex(i); setCustomColorInput(charColor); } }> + + { char } + +
+
+ ); + }) } +
+
+ ) } + + { /* Color Palette */ } +
+ { colorMode === 'perLetter' && selectedLetterIndex !== null && + + Selected letter: "{ prefixText[selectedLetterIndex] || '' }" + + } +
+ { PRESET_COLORS.map((color, idx) => + { + const isActive = currentActiveColor === color; + return ( +
handleColorSelect(color) } /> + ); + }) } +
+
+ + handleCustomColorChange(e.target.value) } /> +
+
+ + { /* Purchase Footer */ } +
+
+ Price: + 5 Credits +
+ +
+
+ ); +}; diff --git a/src/components/catalog/views/page/layout/GetCatalogLayout.tsx b/src/components/catalog/views/page/layout/GetCatalogLayout.tsx index a9a03ee..cae9fd4 100644 --- a/src/components/catalog/views/page/layout/GetCatalogLayout.tsx +++ b/src/components/catalog/views/page/layout/GetCatalogLayout.tsx @@ -2,6 +2,7 @@ import { ICatalogPage } from '../../../../../api'; import { CatalogLayoutProps } from './CatalogLayout.types'; import { CatalogLayoutBadgeDisplayView } from './CatalogLayoutBadgeDisplayView'; import { CatalogLayoutColorGroupingView } from './CatalogLayoutColorGroupingView'; +import { CatalogLayoutCustomPrefixView } from './CatalogLayoutCustomPrefixView'; import { CatalogLayoutDefaultView } from './CatalogLayoutDefaultView'; import { CatalogLayouGuildCustomFurniView } from './CatalogLayoutGuildCustomFurniView'; import { CatalogLayouGuildForumView } from './CatalogLayoutGuildForumView'; @@ -72,6 +73,8 @@ export const GetCatalogLayout = (page: ICatalogPage, hideNavigation: () => void) return ; case 'soundmachine': return ; + case 'custom_prefix': + return ; case 'bots': case 'default_3x3': default: diff --git a/src/components/inventory/InventoryView.tsx b/src/components/inventory/InventoryView.tsx index acafff6..65c3a11 100644 --- a/src/components/inventory/InventoryView.tsx +++ b/src/components/inventory/InventoryView.tsx @@ -2,7 +2,7 @@ import { AddLinkEventTracker, BadgePointLimitsEvent, GetLocalizationManager, Get import { FC, useEffect, useState } from 'react'; import { GroupItem, LocalizeText, UnseenItemCategory, isObjectMoverRequested, setObjectMoverRequested } from '../../api'; import { NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; -import { useInventoryBadges, useInventoryFurni, useInventoryTrade, useInventoryUnseenTracker, useMessageEvent, useNitroEvent } from '../../hooks'; +import { useInventoryBadges, useInventoryFurni, useInventoryPrefixes, useInventoryTrade, useInventoryUnseenTracker, useMessageEvent, useNitroEvent } from '../../hooks'; import { InventoryCategoryFilterView } from './views/InventoryCategoryFilterView'; import { InventoryBadgeView } from './views/badge/InventoryBadgeView'; import { InventoryBotView } from './views/bot/InventoryBotView'; @@ -10,13 +10,15 @@ import { InventoryFurnitureDeleteView } from './views/furniture/InventoryFurnitu import { InventoryFurnitureView } from './views/furniture/InventoryFurnitureView'; import { InventoryTradeView } from './views/furniture/InventoryTradeView'; import { InventoryPetView } from './views/pet/InventoryPetView'; +import { InventoryPrefixView } from './views/prefix/InventoryPrefixView'; const TAB_FURNITURE: string = 'inventory.furni'; const TAB_BOTS: string = 'inventory.bots'; const TAB_PETS: string = 'inventory.furni.tab.pets'; const TAB_BADGES: string = 'inventory.badges'; -const TABS = [ TAB_FURNITURE, TAB_PETS, TAB_BADGES, TAB_BOTS ]; -const UNSEEN_CATEGORIES = [ UnseenItemCategory.FURNI, UnseenItemCategory.PET, UnseenItemCategory.BADGE, UnseenItemCategory.BOT ]; +const TAB_PREFIXES: string = 'inventory.prefixes'; +const TABS = [ TAB_FURNITURE, TAB_PETS, TAB_BADGES, TAB_PREFIXES, TAB_BOTS ]; +const UNSEEN_CATEGORIES = [ UnseenItemCategory.FURNI, UnseenItemCategory.PET, UnseenItemCategory.BADGE, UnseenItemCategory.PREFIX, UnseenItemCategory.BOT ]; export const InventoryView: FC<{}> = props => { @@ -165,6 +167,8 @@ export const InventoryView: FC<{}> = props => } { (currentTab === TAB_BADGES) && } + { (currentTab === TAB_PREFIXES) && + } { (currentTab === TAB_BOTS) && }
diff --git a/src/components/inventory/views/prefix/InventoryPrefixView.tsx b/src/components/inventory/views/prefix/InventoryPrefixView.tsx new file mode 100644 index 0000000..d959546 --- /dev/null +++ b/src/components/inventory/views/prefix/InventoryPrefixView.tsx @@ -0,0 +1,136 @@ +import { FC, useEffect, useState } from 'react'; +import { FaTrashAlt } from 'react-icons/fa'; +import { IPrefixItem, LocalizeText, parsePrefixColors, getPrefixEffectStyle, PREFIX_EFFECT_KEYFRAMES } from '../../../../api'; +import { useInventoryPrefixes, useNotification } from '../../../../hooks'; +import { NitroButton } from '../../../../layout'; + +const PrefixPreview: FC<{ text: string; color: string; icon: string; effect?: string; className?: string; textSize?: string }> = ({ text, color, icon, effect = '', className = '', textSize = 'text-sm' }) => +{ + const colors = parsePrefixColors(text, color); + const hasMultiColor = colors.length > 1 && new Set(colors).size > 1; + const fxStyle = getPrefixEffectStyle(effect, colors[0] || '#FFFFFF'); + + return ( + + { effect === 'pulse' && } + { icon && { icon } } + + {'{'} + { hasMultiColor + ? [ ...text ].map((char, i) => ( + { char } + )) + : text + } + {'}'} + + + ); +}; + +const PrefixItemView: FC<{ + prefix: IPrefixItem; + isSelected: boolean; + onClick: () => void; +}> = ({ prefix, isSelected, onClick }) => +{ + return ( +
+ +
+ ); +}; + +export const InventoryPrefixView: FC<{}> = () => +{ + const [ isVisible, setIsVisible ] = useState(false); + const { prefixes = [], activePrefix = null, selectedPrefix = null, setSelectedPrefix = null, activatePrefix = null, deactivatePrefix = null, deletePrefix = null, activate = null, deactivate = null } = useInventoryPrefixes(); + const { showConfirm = null } = useNotification(); + + const attemptDeletePrefix = () => + { + if(!selectedPrefix) return; + + showConfirm( + `Are you sure you want to delete the prefix {${selectedPrefix.text}}?`, + () => deletePrefix(selectedPrefix.id), + null, + null, + null, + LocalizeText('inventory.delete.confirm_delete.title') + ); + }; + + useEffect(() => + { + if(!isVisible) return; + + const id = activate(); + + return () => deactivate(id); + }, [ isVisible, activate, deactivate ]); + + useEffect(() => + { + setIsVisible(true); + + return () => setIsVisible(false); + }, []); + + return ( +
+
+
+ { prefixes.map(prefix => ( + setSelectedPrefix(prefix) } /> + )) } +
+ { (!prefixes || prefixes.length === 0) && +
+ { LocalizeText('inventory.empty.title') } +
} +
+
+ { activePrefix && +
+ Active prefix +
+ +
+
} + { !activePrefix && +
+ Active prefix +
+ No active prefix +
+
} + { !!selectedPrefix && +
+
+ +
+
+ selectedPrefix.active ? deactivatePrefix() : activatePrefix(selectedPrefix.id) }> + { selectedPrefix.active ? 'Deactivate' : 'Activate' } + + { !selectedPrefix.active && + + + } +
+
} +
+
+ ); +}; diff --git a/src/components/room/widgets/chat/ChatWidgetMessageView.tsx b/src/components/room/widgets/chat/ChatWidgetMessageView.tsx index 46ef8ec..1dba1a9 100644 --- a/src/components/room/widgets/chat/ChatWidgetMessageView.tsx +++ b/src/components/room/widgets/chat/ChatWidgetMessageView.tsx @@ -1,6 +1,6 @@ import { GetRoomEngine, RoomChatSettings, RoomObjectCategory } from '@nitrots/nitro-renderer'; import { FC, useEffect, useMemo, useRef, useState } from 'react'; -import { ChatBubbleMessage } from '../../../../api'; +import { ChatBubbleMessage, parsePrefixColors, getPrefixEffectStyle, PREFIX_EFFECT_KEYFRAMES } from '../../../../api'; import { useOnClickChat } from '../../../../hooks'; interface ChatWidgetMessageViewProps @@ -90,6 +90,27 @@ export const ChatWidgetMessageView: FC = ({ ) }
+ { chat.prefixEffect === 'pulse' && } + { chat.prefixText && (() => { + const colors = parsePrefixColors(chat.prefixText, chat.prefixColor); + const hasMultiColor = colors.length > 1 && new Set(colors).size > 1; + const fxStyle = getPrefixEffectStyle(chat.prefixEffect, colors[0] || '#FFFFFF'); + return ( + + { chat.prefixIcon && { chat.prefixIcon } } + + {'{'} + { hasMultiColor + ? [ ...chat.prefixText ].map((char, i) => ( + { char } + )) + : chat.prefixText + } + {'}'} + + + ); + })() }
diff --git a/src/hooks/inventory/index.ts b/src/hooks/inventory/index.ts index 4e70819..ea39265 100644 --- a/src/hooks/inventory/index.ts +++ b/src/hooks/inventory/index.ts @@ -2,5 +2,6 @@ export * from './useInventoryBadges'; export * from './useInventoryBots'; export * from './useInventoryFurni'; export * from './useInventoryPets'; +export * from './useInventoryPrefixes'; export * from './useInventoryTrade'; export * from './useInventoryUnseenTracker'; diff --git a/src/hooks/inventory/useInventoryPrefixes.ts b/src/hooks/inventory/useInventoryPrefixes.ts new file mode 100644 index 0000000..1d761c1 --- /dev/null +++ b/src/hooks/inventory/useInventoryPrefixes.ts @@ -0,0 +1,126 @@ +import { ActivePrefixUpdatedEvent, PrefixReceivedEvent, RequestPrefixesComposer, SetActivePrefixComposer, DeletePrefixComposer, UserPrefixesEvent } from '@nitrots/nitro-renderer'; +import { useEffect, useState } from 'react'; +import { useBetween } from 'use-between'; +import { IPrefixItem, SendMessageComposer, UnseenItemCategory } from '../../api'; +import { useMessageEvent } from '../events'; +import { useSharedVisibility } from '../useSharedVisibility'; +import { useInventoryUnseenTracker } from './useInventoryUnseenTracker'; + +const useInventoryPrefixesState = () => +{ + const [ needsUpdate, setNeedsUpdate ] = useState(true); + const [ prefixes, setPrefixes ] = useState([]); + const [ activePrefix, setActivePrefix ] = useState(null); + const [ selectedPrefix, setSelectedPrefix ] = useState(null); + const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility(); + const { isUnseen = null, resetCategory = null } = useInventoryUnseenTracker(); + + useMessageEvent(UserPrefixesEvent, event => + { + const parser = event.getParser(); + const newPrefixes: IPrefixItem[] = parser.prefixes.map(p => ({ + id: p.id, + text: p.text, + color: p.color, + icon: p.icon || '', + effect: p.effect || '', + active: p.active + })); + + setPrefixes(newPrefixes); + + const active = newPrefixes.find(p => p.active) || null; + setActivePrefix(active); + }); + + useMessageEvent(PrefixReceivedEvent, event => + { + const parser = event.getParser(); + const newPrefix: IPrefixItem = { + id: parser.id, + text: parser.text, + color: parser.color, + icon: parser.icon || '', + effect: parser.effect || '', + active: false + }; + + setPrefixes(prevValue => [ newPrefix, ...prevValue ]); + }); + + useMessageEvent(ActivePrefixUpdatedEvent, event => + { + const parser = event.getParser(); + + setPrefixes(prevValue => + { + return prevValue.map(p => ({ + ...p, + active: p.id === parser.prefixId + })); + }); + + if(parser.prefixId === 0) + { + setActivePrefix(null); + } + else + { + setActivePrefix(prev => + { + const found = prefixes.find(p => p.id === parser.prefixId); + if(found) return { ...found, active: true }; + return { id: parser.prefixId, text: parser.text, color: parser.color, icon: parser.icon || '', effect: parser.effect || '', active: true }; + }); + } + }); + + const activatePrefix = (prefixId: number) => + { + SendMessageComposer(new SetActivePrefixComposer(prefixId)); + }; + + const deactivatePrefix = () => + { + SendMessageComposer(new SetActivePrefixComposer(0)); + }; + + const deletePrefix = (prefixId: number) => + { + SendMessageComposer(new DeletePrefixComposer(prefixId)); + }; + + useEffect(() => + { + if(!prefixes || !prefixes.length) return; + + setSelectedPrefix(prevValue => + { + if(prevValue && prefixes.find(p => p.id === prevValue.id)) return prevValue; + return prefixes[0]; + }); + }, [ prefixes ]); + + useEffect(() => + { + if(!isVisible) return; + + return () => + { + resetCategory(UnseenItemCategory.PREFIX); + }; + }, [ isVisible, resetCategory ]); + + useEffect(() => + { + if(!isVisible || !needsUpdate) return; + + SendMessageComposer(new RequestPrefixesComposer()); + + setNeedsUpdate(false); + }, [ isVisible, needsUpdate ]); + + return { prefixes, activePrefix, selectedPrefix, setSelectedPrefix, activatePrefix, deactivatePrefix, deletePrefix, activate, deactivate }; +}; + +export const useInventoryPrefixes = () => useBetween(useInventoryPrefixesState); diff --git a/src/hooks/rooms/widgets/index.ts b/src/hooks/rooms/widgets/index.ts index 9984450..ea35008 100644 --- a/src/hooks/rooms/widgets/index.ts +++ b/src/hooks/rooms/widgets/index.ts @@ -1,5 +1,6 @@ export * from './furniture'; export * from './useAvatarInfoWidget'; +export * from './useChatCommandSelector'; export * from './useChatInputWidget'; export * from './useChatWidget'; export * from './useDoorbellWidget'; diff --git a/src/hooks/rooms/widgets/useChatWidget.ts b/src/hooks/rooms/widgets/useChatWidget.ts index 648a102..0ff6f24 100644 --- a/src/hooks/rooms/widgets/useChatWidget.ts +++ b/src/hooks/rooms/widgets/useChatWidget.ts @@ -149,6 +149,11 @@ const useChatWidgetState = () => imageUrl, color); + chatMessage.prefixText = event.prefixText || ''; + chatMessage.prefixColor = event.prefixColor || ''; + chatMessage.prefixIcon = event.prefixIcon || ''; + chatMessage.prefixEffect = event.prefixEffect || ''; + setChatMessages(prevValue => { const newValue = [ ...prevValue, chatMessage ];