From 764d0e963498e3269a2c01482956fce7b0718942 Mon Sep 17 00:00:00 2001 From: Adrian Klingen Date: Tue, 12 Nov 2024 19:27:47 +0100 Subject: [PATCH] Allow addition of manual item notices --- ui/core/components/gear_picker/gear_picker.tsx | 11 +++++++++-- ui/core/components/item_notice/item_notice.tsx | 16 ++++++++++++---- ui/core/constants/item_notices.tsx | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ui/core/components/gear_picker/gear_picker.tsx b/ui/core/components/gear_picker/gear_picker.tsx index 2c6f971b63..0119d65508 100644 --- a/ui/core/components/gear_picker/gear_picker.tsx +++ b/ui/core/components/gear_picker/gear_picker.tsx @@ -1,5 +1,6 @@ import { ref } from 'tsx-vanilla'; +import { MISSING_RANDOM_SUFFIX_WARNING } from '../../constants/item_notices'; import { setItemQualityCssClass } from '../../css_utils'; import { Player } from '../../player'; import { ItemSlot, ItemType } from '../../proto/common'; @@ -139,10 +140,12 @@ export class ItemRenderer extends Component { update(newItem: EquippedItem) { const nameSpan = {newItem.item.name}; + const isEligibleForRandomSuffix = !!newItem.hasRandomSuffixOptions(); + const hasRandomSuffix = !!newItem.randomSuffix; this.nameElem.replaceChildren(nameSpan); this.ilvlElem.textContent = newItem.item.ilvl.toString(); - if (newItem.randomSuffix) { + if (hasRandomSuffix) { nameSpan.textContent += ' ' + newItem.randomSuffix.name; } @@ -150,7 +153,11 @@ export class ItemRenderer extends Component { this.nameElem.appendChild(createHeroicLabel()); } - this.notice = new ItemNotice(this.player, { itemId: newItem.item.id }); + this.notice = new ItemNotice(this.player, { + itemId: newItem.item.id, + additionalNoticeData: isEligibleForRandomSuffix && !hasRandomSuffix ? MISSING_RANDOM_SUFFIX_WARNING : undefined, + }); + if (this.notice.hasNotice) { this.nameContainerElem.appendChild(this.notice.rootElem); } diff --git a/ui/core/components/item_notice/item_notice.tsx b/ui/core/components/item_notice/item_notice.tsx index f9ff1cc0d3..d6a75a2a2e 100644 --- a/ui/core/components/item_notice/item_notice.tsx +++ b/ui/core/components/item_notice/item_notice.tsx @@ -15,6 +15,7 @@ export type ItemNoticeData = { type ItemNoticeConfig = { itemId: number; + additionalNoticeData?: JSX.Element; }; // Keys are item counts for each set bonus (typically 2 and 4), values are the @@ -26,11 +27,13 @@ export class ItemNotice extends Component { itemId: number; player: Player; tooltip: TippyInstance | null = null; + additionalNoticeData: ItemNoticeConfig['additionalNoticeData']; constructor(player: Player, config: ItemNoticeConfig) { super(null, 'item-notice'); this.rootElem.classList.add('d-inline'); this.itemId = config.itemId; this.player = player; + this.additionalNoticeData = config.additionalNoticeData; if (this.hasNotice && this.template) this.rootElem.appendChild(this.template!); @@ -41,21 +44,26 @@ export class ItemNotice extends Component { } get hasNotice() { - return ITEM_NOTICES.has(this.itemId); + return ITEM_NOTICES.has(this.itemId) || !!this.additionalNoticeData; } private get noticeContent() { if (!this.hasNotice) return null; const itemNotice = ITEM_NOTICES.get(this.itemId)!; - const specNotice = itemNotice[this.player.getSpec()]; - return typeof specNotice === 'boolean' ? null : specNotice || itemNotice[Spec.SpecUnknown]; + const specNotice = ( + <> + {itemNotice?.[this.player.getSpec()]} + {this.additionalNoticeData} + + ); + + return typeof specNotice === 'boolean' ? null : specNotice || itemNotice?.[Spec.SpecUnknown]; } private get template() { if (!this.hasNotice) return null; const tooltipContent = this.noticeContent?.cloneNode(true); if (!tooltipContent) return null; - const noticeIconRef = ref(); const template = ; diff --git a/ui/core/constants/item_notices.tsx b/ui/core/constants/item_notices.tsx index a4ab1450d8..d38d70d52e 100644 --- a/ui/core/constants/item_notices.tsx +++ b/ui/core/constants/item_notices.tsx @@ -3,6 +3,8 @@ import { Spec } from '../proto/common'; const WantToHelpMessage = () =>

Want to help out by providing additional information? Contact us on our Discord!

; +export const MISSING_RANDOM_SUFFIX_WARNING =

Please select a random suffix

; + const MISSING_IMPLEMENTATION_WARNING = ( <>

This item is not implemented!