Skip to content

Commit

Permalink
Merge branch 'discard-features'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gtaray committed Jan 12, 2023
2 parents 907811b + dbfbc17 commit 5682a25
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 31 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>
19 changes: 19 additions & 0 deletions deckbox/deckbox_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
<combobox_setting name="autoplay_from_deck" source="settings.autoplayfromdeck">
<parameter>DECK_SETTING_AUTO_PLAY_FROM_DECK</parameter>
</combobox_setting>

<header_column name="header_misc">
<static textres="deckbox_settings_header_misc" />
<center />
</header_column>

<setting_label name="discard_to_deck_label">
<static textres="deckbox_settings_label_discard_to_deck" />
</setting_label>
<combobox_setting name="discard_to_deck" source="settings.discardtodeck">
<parameter>DECK_SETTING_DISCARD_TO_DECK</parameter>
</combobox_setting>

<setting_label name="players_can_grab_discards_label">
<static textres="deckbox_setting_label_allow_picking_from_discard" />
</setting_label>
<combobox_setting name="players_can_grab_discards" source="settings.playerscangrabdiscards">
<parameter>DECK_SETTING_PLAYERS_CAN_GRAB_DISCARDS</parameter>
</combobox_setting>
</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
5 changes: 3 additions & 2 deletions extension.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<root version="3.3" release="1.0">
<announcement text="Decked Out v1.1.1 by Saagael." icon="decked_out" font="emotefont" />
<announcement text="Decked Out v1.2.0 by Saagael." icon="decked_out" font="emotefont" />
<properties>
<name>Feature: Decked Out</name>
<version>1.1.1</version>
<version>1.2.0</version>
<author>Saagael</author>
<description>Adds decks of cards</description>
<loadorder>1000</loadorder>
Expand All @@ -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
19 changes: 14 additions & 5 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 @@ -29,16 +36,18 @@ function onInit()

end

OptionsManager.registerOption2("HOTKEY_FACEDOWN", true, "option_header_deckedout", "option_label_facedown_hotkey", "option_entry_cycler",
OptionsManager.registerOption2("HOTKEY_FACEDOWN", false, "option_header_deckedout", "option_label_facedown_hotkey", "option_entry_cycler",
{ labels = "option_val_ctrl|option_val_alt", values = "control|alt", baselabel = "option_val_shift", baseval = "shift", default = "shift" })
OptionsManager.registerOption2("HOTKEY_DISCARD", true, "option_header_deckedout", "option_label_play_and_discard_hotkey", "option_entry_cycler",
OptionsManager.registerOption2("HOTKEY_DISCARD", false, "option_header_deckedout", "option_label_play_and_discard_hotkey", "option_entry_cycler",
{ labels = "option_val_alt|option_val_shift", values = "alt|shift", baselabel = "option_val_ctrl", baseval = "control", default = "control" });
OptionsManager.registerOption2("FLIP_PERMISSION", true, "option_header_deckedout", "option_label_permission_flip", "option_entry_cycler",
OptionsManager.registerOption2("FLIP_PERMISSION", false, "option_header_deckedout", "option_label_permission_flip", "option_entry_cycler",
{ labels = "option_val_yes", values = "yes", baselabel = "option_val_no", baseval = "no", default = "no" });
OptionsManager.registerOption2("PEEK_PERMISSION", true, "option_header_deckedout", "option_label_permission_peek", "option_entry_cycler",
OptionsManager.registerOption2("PEEK_PERMISSION", false, "option_header_deckedout", "option_label_permission_peek", "option_entry_cycler",
{ labels = "option_val_yes", values = "yes", baselabel = "option_val_no", baseval = "no", default = "no" });
OptionsManager.registerOption2("SHOW_GM_PEEK_MSG", true, "option_header_deckedout", "option_label_show_gm_peek", "option_entry_cycler",
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
29 changes: 27 additions & 2 deletions scripts/decked_out_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DECKEDOUT_EVENT_CARD_PLAYED = "cardplayed";
DECKEDOUT_EVENT_CARD_DISCARDED = "carddiscarded";
DECKEDOUT_EVENT_CARD_GIVEN = "cardgiven";
DECKEDOUT_EVENT_CARD_DEALT = "carddealt";
DECKEDOUT_EVENT_DEALT_FROM_DISCARD = "dealtfromdiscard";
DECKEDOUT_EVENT_CARD_ADDED_TO_STORAGE = "cardaddedtostorage";
DECKEDOUT_EVENT_CARD_MOVED = "cardmoved";
DECKEDOUT_EVENT_CARD_PUT_BACK_IN_DECK = "cardputbackindeck";
Expand Down Expand Up @@ -324,12 +325,17 @@ end
---@param vCard databasenode
---@param vDeck databasenode
---@param sIdentity string
---@param bFacedown boolean
---@param tEventTrace table
---@return table tEventTrace
function raiseOnCardReturnedToDeckEvent(vCard, vDeck, sIdentity, tEventTrace)
function raiseOnCardReturnedToDeckEvent(vCard, vDeck, sIdentity, bFacedown, tEventTrace)
local tArgs = { sIdentity = sIdentity, sCardNode = vCard.getNodeName(), sDeckNode = vDeck.getNodeName() }
if bFacedown then
tArgs.bFacedown = "true";
end
return DeckedOutEvents.raiseEvent(
DeckedOutEvents.DECKEDOUT_EVENT_CARD_PUT_BACK_IN_DECK,
{ sIdentity = sIdentity, sCardNode = vCard.getNodeName(), sDeckNode = vDeck.getNodeName() },
tArgs,
tEventTrace
);
end
Expand Down Expand Up @@ -391,6 +397,25 @@ function raiseOnDealCardEvent(vCard, sIdentity, bFacedown, tEventTrace)
);
end

---Raises the onCardDealtFromDiscard event event.
---@param vCard databasenode Card that is added to hand, AFTER is is added to the hand
---@param sIdentity string Character identity (or 'gm') of the person whose hand the card is being added to
---@param tEventTrace table. Event trace table
---@return table tEventTrace Event trace table
function raiseOnCardDealtFromDiscardEvent(vCard, sIdentity, bFacedown, tEventTrace)
local tArgs = { sCardNode = vCard.getNodeName(), sIdentity = sIdentity, bFacedown = "false" };
if bFacedown then
tArgs.bFacedown = "true";
end

return DeckedOutEvents.raiseEvent(
DeckedOutEvents.DECKEDOUT_EVENT_DEALT_FROM_DISCARD,
tArgs,
tEventTrace,
true -- True because this event technically happens after moveCard, and by then the trace is already updated
);
end

---Raises the onCardFlipped event
---@param vCard databasenode
---@param sIdentity string Charater identity (or 'gm') of the person flipping the card
Expand Down
32 changes: 32 additions & 0 deletions scripts/decked_out_messages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function onInit()
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_HAND_DISCARD_RANDOM, { fCallback = printRandomCardDiscardedMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_CARD_GIVEN, { fCallback = printCardGivenMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_CARD_DEALT, { fCallback = printCardDealtMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_DEALT_FROM_DISCARD, { fCallback = printCardDealtFromDiscardMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_HAND_DISCARDED, { fCallback = printHandDiscardedMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_MULTIPLE_CARDS_DEALT, { fCallback = printMultipleCardsDealtMessage, sTarget = "host" });
DeckedOutEvents.registerEvent(DeckedOutEvents.DECKEDOUT_EVENT_GROUP_DEAL, { fCallback = printGroupDealMessage, sTarget = "host" });
Expand Down Expand Up @@ -324,6 +325,37 @@ function printCardDealtMessage(tEventArgs, tEventTrace)
Comm.deliverOOBMessage(msg, "");
end

function printCardDealtFromDiscardMessage(tEventArgs, tEventTrace)
local vCard = DeckedOutUtilities.validateCard(tEventArgs.sCardNode);
if not vCard then return end

local sCardSource = CardManager.getCardSource(vCard);
if (not sCardSource) or sCardSource == "storage" then
return;
end

local bFacedown = tEventArgs.bFacedown == "true";

local msg = {};
msg.type = DeckedOutMessages.OOB_MSGTYPE_DECKEDOUT_STANDARD;
-- The GM should always be the card source here.
-- If we use value returned from getCardSource,
-- it will always say the PC since we dealt them the card prior to this event
msg.sender = tEventArgs.sIdentity;
msg.card_link = vCard.getNodeName();
msg.action = "deal";
msg.facedown = tEventArgs.bFacedown;
if bFacedown then
msg.text = Interface.getString("chat_msg_deal_card_from_discard_facedown");
else
msg.text = Interface.getString("chat_msg_deal_card_from_discard");
end
msg.text = string.format(msg.text, "[SENDER]", "[CARDNAME]");
msg.icon = "deal";

Comm.deliverOOBMessage(msg, "");
end

function printMultipleCardsDealtMessage(tEventArgs, tEventTrace)
-- If the event trace already contains the group deal cards event, then we don't want to print out any messages, so we bail
if DeckedOutEvents.doesEventTraceContain(tEventTrace, DeckedOutEvents.DECKEDOUT_EVENT_GROUP_DEAL) then
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
Loading

0 comments on commit 5682a25

Please sign in to comment.