Skip to content

Commit

Permalink
Added tooltips when hovering over cards in hands, as well as a game o…
Browse files Browse the repository at this point in the history
…ption to set how big the tooltips are.
  • Loading branch information
Gtaray committed Jan 6, 2023
1 parent 2f4a22f commit dbfbc17
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 11 deletions.
18 changes: 18 additions & 0 deletions common/card_tooltip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<windowclass name="card_tooltip">
<sizelimits>
<dynamic />
</sizelimits>
<sheetdata>
<tokenfield name="image">
<anchored>
<top />
<left />
<right />
<bottom />
</anchored>
</tokenfield>
</sheetdata>
</windowclass>
</root>
76 changes: 66 additions & 10 deletions desktop/scripts/desktop_card.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local bPopped = false;
local winTooltip = nil;

function onInit()
-- highlight.setEnabled(false);
Expand Down Expand Up @@ -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
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
1 change: 1 addition & 0 deletions extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<includefile source="campaign/record_char.xml" />
<includefile source="campaign/record_deck.xml" />
<includefile source="campaign/record_card.xml" />
<includefile source="common/card_tooltip.xml" />
<includefile source="common/deck_templates.xml" />

<includefile source="ct/ct_entries.xml" />
Expand Down
9 changes: 9 additions & 0 deletions scripts/decked_out.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
tCardTooltipSizes = {
["normal"] = 250,
["large"] = 300,
["extralarge"] = 350,
["huge"] = 400
}

aRecords = {
["deck"] = {
bExport = true,
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions scripts/decked_out_utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion strings/cards_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<string name="deckbox_settings_header_misc">Miscellaneous</string>
<string name="deckbox_settings_label_discard_to_deck">Put discarded cards back into the deck?</string>
<string name="deckbox_setting_label_allow_picking_from_discard">Allow players to pick up cards that are discarded from chat?</string>
<string name="deckbox_setting_label_allow_picking_from_discard">Allow players to grab discarded cards from chat?</string>

<string name="deckbox_settings_option_gm">The GM</string>
<string name="deckbox_settings_option_everyone">Everyone</string>
Expand Down Expand Up @@ -178,4 +178,11 @@
<string name="option_val_no">No</string>

<string name="option_label_show_gm_peek">Show chat messages when a GM peeks at a card</string>

<string name="option_label_card_tooltip_size">Card tooltip size</string>
<string name="option_val_cardtooltip_disabled">Disabled</string>
<string name="option_val_cardtooltip_normal">Normal</string>
<string name="option_val_cardtooltip_large">Large</string>
<string name="option_val_cardtooltip_extralarge">Extra Large</string>
<string name="option_val_cardtooltip_huge">Huge</string>
</root>

0 comments on commit dbfbc17

Please sign in to comment.