diff --git a/common/card_tooltip.xml b/common/card_tooltip.xml new file mode 100644 index 0000000..3bafe49 --- /dev/null +++ b/common/card_tooltip.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/desktop/scripts/desktop_card.lua b/desktop/scripts/desktop_card.lua index 475aa2f..dd81bf1 100644 --- a/desktop/scripts/desktop_card.lua +++ b/desktop/scripts/desktop_card.lua @@ -1,4 +1,4 @@ -local bPopped = false; +local winTooltip = nil; function onInit() -- highlight.setEnabled(false); @@ -30,12 +30,68 @@ function setCardSize(nWidth, nHeight) cardback.setAnchoredHeight(nHeight); end --- function onHover(hover) --- if hover and not bPopped then --- highlight.setVisible(true); --- bPopped = true; --- elseif not hover and bPopped then --- highlight.setVisible(false); --- bPopped = false; --- end --- end \ No newline at end of file +function onHover(hover) + if hover and winTooltip == nil then + local w, h = DeckedOutUtilities.getCardTooltipSize(); + if w == 0 or h == 0 then + return true; + end + + local winWidth, winHeight = getSize(); + + -- if for some reason the hand window is so ginormous that the cards are also huge + -- such that the tooltips would be smaller than the actual cards, don't show them. + if w <= winWidth or h <= winHeight then + return true; + end + + winTooltip = Interface.openWindow("card_tooltip", getDatabaseNode()) + winTooltip.setSize(w, h); -- Set the size before the position, since position relies on size + + local x, y = self.getPositionOfTooltip(); + winTooltip.setPosition(x, y); + elseif not hover and winTooltip then + winTooltip.close(); + winTooltip = nil; + end +end + +function getPositionOfTooltip() + local x, y = self.getAbovePositionForTooltip(); + + -- if the tooltip's y is below 0, then we need to switch to below the card + if y < 0 then + x, y = self.getBelowPositionForTooltip(); + end + + -- If the tooltip's x is below 0, nudge to the right + if x < 0 then + x = 0; + end + + -- If the tooltip's x value is beyond the right edge of the hand window, nudge it over + -- This might not be possible + local handwindow = Interface.findWindow("desktop_hand", ""); + local hx = handwindow.getPosition(); + local hw = handwindow.getSize(); + local tw = winTooltip.getSize(); + if x + tw > hw + hx then + x = (hw + hx) - tw; + end + + return x, y; +end + +function getAbovePositionForTooltip() + local x, y = getPosition(); + local w, h = getSize(); + local w2, h2 = winTooltip.getSize(); + return x + (w/2) - (w2/2), y - h2; +end + +function getBelowPositionForTooltip() + local x, y = getPosition(); + local w, h = getSize(); + local w2, h2 = winTooltip.getSize(); + return x + (w/2) - (w2/2), y + h; +end \ No newline at end of file diff --git a/extension.xml b/extension.xml index 0dae449..18ec671 100644 --- a/extension.xml +++ b/extension.xml @@ -12,6 +12,7 @@ + diff --git a/scripts/decked_out.lua b/scripts/decked_out.lua index 0ffe7f3..c6f66f9 100644 --- a/scripts/decked_out.lua +++ b/scripts/decked_out.lua @@ -1,3 +1,10 @@ +tCardTooltipSizes = { + ["normal"] = 250, + ["large"] = 300, + ["extralarge"] = 350, + ["huge"] = 400 +} + aRecords = { ["deck"] = { bExport = true, @@ -39,6 +46,8 @@ function onInit() { labels = "option_val_yes", values = "yes", baselabel = "option_val_no", baseval = "no", default = "no" }); OptionsManager.registerOption2("SHOW_GM_PEEK_MSG", false, "option_header_deckedout", "option_label_show_gm_peek", "option_entry_cycler", { labels = "option_val_yes", values = "yes", baselabel = "option_val_no", baseval = "no", default = "no" }); + OptionsManager.registerOption2("CARD_TOOLTIP_SIZE", true, "option_header_deckedout", "option_label_card_tooltip_size", "option_entry_cycler", + { labels = "option_val_cardtooltip_normal|option_val_cardtooltip_large|option_val_cardtooltip_extralarge|option_val_cardtooltip_huge", values = "normal|large|extralarge|huge", baselabel = "option_val_cardtooltip_disabled", baseval = "disabled", default = "normal" }); end function isBetterMenusLoaded() diff --git a/scripts/decked_out_utilities.lua b/scripts/decked_out_utilities.lua index 37f9d58..5c31627 100644 --- a/scripts/decked_out_utilities.lua +++ b/scripts/decked_out_utilities.lua @@ -65,6 +65,23 @@ function getHotkey(sOption) end end +---Gets the size of the card tooltips (when hovering in a hand) +---@return integer width +---@return integer height +function getCardTooltipSize() + local sOption = OptionsManager.getOption("CARD_TOOLTIP_SIZE"); + if sOption == "disabled" then + return 0, 0; + end + + local nSize = DeckedOut.tCardTooltipSizes[sOption]; + if not nSize then + return 0, 0; + end + + return nSize, nSize * 1.4 +end + ---Validates that a parameter is not nil. If it is nil, an error and the stack trace is printed in the console ---@param vParam any The parameter to validate ---@param sDisplayName string Display name for the parameter to be validated diff --git a/strings/cards_strings.xml b/strings/cards_strings.xml index 6531d4e..c8f23f5 100644 --- a/strings/cards_strings.xml +++ b/strings/cards_strings.xml @@ -72,7 +72,7 @@ Miscellaneous Put discarded cards back into the deck? - Allow players to pick up cards that are discarded from chat? + Allow players to grab discarded cards from chat? The GM Everyone @@ -178,4 +178,11 @@ No Show chat messages when a GM peeks at a card + + Card tooltip size + Disabled + Normal + Large + Extra Large + Huge \ No newline at end of file