diff --git a/Game/src/base/KinkyDungeon.ts b/Game/src/base/KinkyDungeon.ts index f6286aba5..ba787a20c 100644 --- a/Game/src/base/KinkyDungeon.ts +++ b/Game/src/base/KinkyDungeon.ts @@ -1410,6 +1410,56 @@ let KDErrorTextTime = 0; let KDErrorTextTime_DELAY = 2500; let KDCurrentHoverButton: KDButtonParamData = null; +let KDCurrentHoverBox: KDButtonParamData; + +let KDHoverTypes = ["InventoryItem"] +let KDHoverFunctions = { + "InventoryItem": (hover) => { + let currentlyhovering = ((MouseX >= KDCurrentHoverBox.Left) && (MouseX <= KDCurrentHoverBox.Left + KDCurrentHoverBox.Width) && (MouseY >= KDCurrentHoverBox.Top) && (MouseY <= KDCurrentHoverBox.Top + KDCurrentHoverBox.Height)); + if (!currentlyhovering) { + KDCurrentHoverBox = undefined; + return; + } + let pad = 10; + let TooltipWidth = Math.max(20, 220, (Math.min(hover.Hover.name.length * 12, 350))); + let TooltipHeight = Math.max(20, ((pad * 2) + ((hover.Hover.ItemMods ?? []).length > 0 ? 46 : 20) + (hover.Hover.ItemMods ?? []).length * (20 + 10))); + + let tooltipX = KDCurrentHoverBox.Left + KDCurrentHoverBox.Width; + // Move the tooltip to the left if it would flow off the right side of the screen. + if ((tooltipX + TooltipWidth + 10) > 2000) { + tooltipX = KDCurrentHoverBox.Left - TooltipWidth; + } + let tooltipY = KDCurrentHoverBox.Top; + // Move the tooltip up if it would flow off the bottom of the screen. + if ((tooltipY + TooltipHeight + 10) > 1000) { + tooltipY = 1000 - TooltipHeight; + } + let YY = 20; + FillRectKD(kdcanvas, kdpixisprites, "InventoryItemTooltip_" + hover.Hover.name, { + Left: tooltipX, + Top: tooltipY, //- 25, + Width: TooltipWidth, + Height: TooltipHeight, //+ 20, + Color: KDBaseBlack, + LineWidth: 1, + zIndex: 700, + alpha: 0.8, + }); + + if (hover.Hover.name) { + DrawTextFitKD(`${hover.Hover.name}`, tooltipX + (TooltipWidth / 2), tooltipY + YY, TooltipWidth - 2 * pad, hover.Hover.TitleTextColor, hover.TitleTextColorBack, (hover.Hover.TitleTextSize ? hover.Hover.TitleTextSize : 24), "center", 701); + YY += (hover.TitleTextSize ? (hover.TitleTextSize + 4) : 16); + } + YY = YY + 30 + if (hover.Hover.ItemMods) { + hover.Hover.ItemMods.forEach((mod) => { + DrawTextFitKD(mod.str, tooltipX + pad, tooltipY + YY, TooltipWidth - 2 * pad, mod.colorFG, mod.colorBG, (mod.TextSize ? mod.TextSize : 20), "left", 701); + YY += (mod.TextSize + 10); + }) + } + } +} + let KDLastScrollableListUpdate = 0; let mouseHoldTaken = ""; @@ -3379,10 +3429,11 @@ interface KDButtonParamData { func?: (bdata: KDButtonPressData) => boolean, priority: number, scrollfunc?: (amount: number) => void, - hotkeyPress?: string, + hotkeyPress?: string, contextMenu?: string, hoverData?: any, onHover?: (button: KDButtonParamData) => void, + Hover?: any } let KDButtonsCache: Record = { @@ -3423,7 +3474,8 @@ function DrawButtonKD ( Image?: string, HoveringText?: string, Disabled?: boolean, - NoBorder?: boolean + NoBorder?: boolean, + Hover?: Function, ): void { let params = { @@ -3433,10 +3485,14 @@ function DrawButtonKD ( Height, enabled, priority: 0, + Hover }; let hover = ((MouseX >= Left) && (MouseX <= Left + Width) && (MouseY >= Top) && (MouseY <= Top + Height) && !CommonIsMobile && !Disabled); if (hover) { - if (!KDCurrentHoverButton) KDCurrentHoverButton = params; + if (!KDCurrentHoverButton) { + KDCurrentHoverButton = params; + KDCurrentHoverBox = params; + } else Disabled = true; } DrawButtonVis(Left, Top, Width, Height, Label, Color, Image, HoveringText, Disabled, NoBorder); @@ -3569,6 +3625,7 @@ function DrawButtonKDEx ( FontSize?: number, ShiftText?: boolean, options?: ButtonOptions, + Hover?: Function, ): boolean { let params = { @@ -3582,10 +3639,14 @@ function DrawButtonKDEx ( hotkeyPress: options?.hotkeyPress, hoverData: options?.hoverData, onHover: options?.onHover, + Hover, }; let hover = ((MouseX >= Left) && (MouseX <= Left + Width) && (MouseY >= Top) && (MouseY <= Top + Height) && !CommonIsMobile && !Disabled); if (hover) { - if (!KDCurrentHoverButton) KDCurrentHoverButton = params; + if (!KDCurrentHoverButton) { + KDCurrentHoverButton = params; + KDCurrentHoverBox = params; + } else Disabled = true; } DrawButtonVis(Left, Top, Width, Height, Label, Color, Image, HoveringText, Disabled, NoBorder, FillColor, FontSize, ShiftText, undefined, options?.zIndex, options); @@ -3735,6 +3796,7 @@ function DrawButtonKDExScroll ( FontSize?: number, ShiftText?: boolean, options?: any, + Hover?: Function, ): boolean { @@ -3750,10 +3812,14 @@ function DrawButtonKDExScroll ( hotkeyPress: options?.hotkeyPress, hoverData: options?.hoverData, onHover: options?.onHover, + Hover, }; let hover = ((MouseX >= Left) && (MouseX <= Left + Width) && (MouseY >= Top) && (MouseY <= Top + Height) && !CommonIsMobile && !Disabled); if (hover) { - if (!KDCurrentHoverButton) KDCurrentHoverButton = params; + if (!KDCurrentHoverButton) { + KDCurrentHoverButton = params; + KDCurrentHoverBox = params; + } else Disabled = true; } DrawButtonVis(Left, Top, Width, Height, Label, Color, Image, HoveringText, Disabled, NoBorder, FillColor, FontSize, ShiftText, undefined, options?.zIndex, options); diff --git a/Game/src/base/game/KinkyDungeonDraw.ts b/Game/src/base/game/KinkyDungeonDraw.ts index 96d8e7d17..472b6e7b8 100644 --- a/Game/src/base/game/KinkyDungeonDraw.ts +++ b/Game/src/base/game/KinkyDungeonDraw.ts @@ -1108,6 +1108,9 @@ function KinkyDungeonDrawGame() { KinkyDungeonCapStats(); + if (KDHoverTypes.includes(KDCurrentHoverBox?.Hover?.type)) { + KDHoverFunctions[KDCurrentHoverBox?.Hover?.type](KDCurrentHoverBox); + } if (KDContextMenu && KDCurrentHoverButton?.contextMenu) { KDDrawGameContextMenu[KDCurrentHoverButton.contextMenu](true, MouseX, MouseY); diff --git a/Game/src/item/KinkyDungeonInventory.ts b/Game/src/item/KinkyDungeonInventory.ts index a3c1928ea..806a13f14 100644 --- a/Game/src/item/KinkyDungeonInventory.ts +++ b/Game/src/item/KinkyDungeonInventory.ts @@ -1140,6 +1140,46 @@ function KinkyDungeonFilterInventory(Filter: string, enchanted?: boolean, ignore return ret; } +/** + * @param item + */ +function KDInventoryItemHover(item: any) { + let name = item.name; + let unidentified = KinkyDungeonStatsChoice.get("UnidentifiedWear") && KDIsUnidentified(item); + let prefix = "KinkyDungeonInventoryItem"; + let nameText = KDGetItemName(item.item) + if (item.type == Restraint || item.type == LooseRestraint) { + prefix = "Restraint"; + } + let mods = []; + if (item.item.events) { + item.item.events.forEach((t) => { + if (t.trigger == "inventoryTooltip") { + if (t.type == "varModifier") { + mods.push({ + str: TextGet("KDVariableModifier_" + t.msg) + .replace("AMNT", `${t.power >= 0 ? "+" : ""}${Math.round(t.power)}`) + .replace("DRTN", `${Math.round(t.duration)}`) + .replace("DMG", TextGet("KinkyDungeonDamageType" + t.damage)) + .replace("TYPE", `${t.kind}`), + colorFG: "#eeeeee", + colorBG: t.bgcolor || KDBaseBlack, + TextSize: 20 + }); + } + } + }) + } + let hoverobject = { + type: "InventoryItem", + item: item, + name: (unidentified ? "Unknown" : nameText), + TitleTextColor: KDBaseWhite, + TitleTextColorBack: KDBaseBlack, + ItemMods: mods + } + return hoverobject +} /** * @param item @@ -1588,7 +1628,8 @@ function KDDrawInventoryContainer ( (prefix ? KinkyDungeonCurrentPageContainer : KinkyDungeonCurrentPageInventory), colorcallback ? colorcallback(filteredInventory[index]) : KDTextGray1, undefined, undefined, { scaleImage: true, - }) && !tooltipitem) { + //@ts-ignore // This should have a type assigned to it probably, but I do not know where to trace to make it happy. -Enraa + }, KDInventoryItemHover(filteredInventory[index])) && !tooltipitem) { tooltipitem = filteredInventory[index]; } if (useIcons && filteredInventory[index].preview2)