Skip to content

Commit

Permalink
Merge pull request #7 from Gtaray/cards-facedown-in-hand
Browse files Browse the repository at this point in the history
Cards facedown in hand
  • Loading branch information
Gtaray authored Nov 20, 2022
2 parents 6449f66 + 8035645 commit 35de7a4
Show file tree
Hide file tree
Showing 20 changed files with 618 additions and 70 deletions.
35 changes: 35 additions & 0 deletions campaign/record_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<subwindow_record name="main">
<class>card_main</class>
<activate />
<fastinit />
</subwindow_record>

<close_recordsheet />
Expand All @@ -41,6 +42,33 @@

<windowclass name="card_main">
<margins control="0,0,0,2" />
<script>
local bPeek = false;
function onInit()
local node = getDatabaseNode();
DB.addHandler(DB.getPath(node, CardManager.CARD_FACING_PATH), "onUpdate", onFacingChanged)

onFacingChanged();
end

function onClose()
local node = getDatabaseNode();
DB.removeHandler(DB.getPath(node, CardManager.CARD_FACING_PATH), "onUpdate", onFacingChanged)
end

function onFacingChanged()
local bFaceUp = CardManager.isCardFaceUp(getDatabaseNode()) or bPeek;
image.setVisible(bFaceUp);
image.setEnabled(bFaceUp);
back.setVisible(not bFaceUp);
back.setEnabled(not bFaceUp);
end

function peek()
bPeek = true;
onFacingChanged()
end
</script>
<sheetdata>
<anchor_column name="columnanchor" />
<token_column name="image">
Expand All @@ -49,6 +77,13 @@
<anchored width="250" height="350" />
<gmdrag />
</token_column>
<token_card_back name="back">
<nodrag />
<anchored height="350" width="250">
<top parent="columnanchor" anchor="bottom" relation="relative" offset="7" />
<left />
</anchored>
</token_card_back>
</sheetdata>
</windowclass>
</root>
29 changes: 28 additions & 1 deletion common/deck_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,38 @@
</anchored>
</tokenfield>
</template>

<template name="token_card_back">
<tokencontrol>
<script>
function onInit()
local node = window.getDatabaseNode();
DB.addHandler(DB.getPath(node, "deckid"), "onUpdate", update);
update();
end
function onClose()
local node = window.getDatabaseNode();
DB.removeHandler(DB.getPath(node, "deckid"), "onUpdate", update);
end
function update()
local vCard = window.getDatabaseNode();
if DB.getValue(vCard, "deckid", "") == "" then
return;
end
setPrototype(CardManager.getCardBack(vCard));
end
</script>
<anchored>
<left />
<top />
</anchored>
</tokencontrol>
</template>

<template name="card_highlight">
<genericcontrol name="highlight">
<frame>cardhighlight</frame>
<anchored to="image">
<anchored>
<top offset="0"/>
<bottom offset="0" />
<left offset="0" />
Expand Down
44 changes: 43 additions & 1 deletion common/scripts/standardCardRadialOptions.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,63 @@
function onInit()
if super and super.onInit then
super.onInit();
end

local card = window.getDatabaseNode();

registerMenuItem(Interface.getString("card_menu_play_face_up"), "play_faceup", 1);
registerMenuItem(Interface.getString("card_menu_play_face_down"), "play_facedown", 5)

if not CardManager.isCardInDeck(card) then
registerMenuItem(Interface.getString("card_menu_reshuffle"), "reshuffle_card", 6)
end
if not CardManager.isCardDiscarded(card) then
registerMenuItem(Interface.getString("card_menu_discard_card"), "discard_card", 7);
end

if canpeek and DeckedOutUtilities.canPeekAtCards() then
registerMenuItem(Interface.getString("card_menu_peek"), "peek", 2);
end

DeckedOutUtilities.addOnCardFlippedHandler(card, onCardFlipped);
onCardFlipped();
end

function onClose()
if super and super.onClose then
super.onClose();
end
DeckedOutUtilities.removeOnCardFlippedHandler(card, onCardFlipped);
end

function onCardFlipped()
if not DeckedOutUtilities.canFlipCards() then
return
end

local vCard = window.getDatabaseNode();
if not CardManager.isCardInHand(vCard) then
return;
end

local text;
if CardManager.isCardFaceUp(vCard) then
text = Interface.getString("card_menu_flip_facedown");
else
text = Interface.getString("card_menu_flip_faceup");
end

if text then
registerMenuItem(text, "flip", 3);
end
end

function onMenuSelection(selection)
if selection == 1 then
playCard(DeckedOutUtilities.getFacedownHotkey())
elseif selection == 2 then
DesktopManager.peekCard(window.getDatabaseNode());
elseif selection == 3 then
CardManager.flipCardFacing(window.getDatabaseNode(), {})
elseif selection == 5 then
playCard(true);
elseif selection == 6 then
Expand Down
30 changes: 12 additions & 18 deletions deckbox/cardlist_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,7 @@

<windowclass name="cardlist_viewer_item">
<margins control="0,0,0,2" />
<script>
local bPopped = false;

function onInit()
highlight.setEnabled(false);
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
</script>
<script file="desktop/scripts/desktop_card.lua" />
<sheetdata>
<token_card name="image">
<script file="common/scripts/onCardDrag.lua" />
Expand All @@ -80,8 +64,18 @@
<left />
</anchored>
</token_card>
<token_card_back name="cardback">
<script file="common/scripts/onCardDrag.lua" />
<script file="common/scripts/standardCardRadialOptions.lua" />
<nodrag />
<canpeek />
<anchored height="140" width="100">
<top />
<left />
</anchored>
</token_card_back>
<icon_missing_token name="missingtoken" />
<card_highlight name="highlight" />
<!-- <card_highlight name="highlight" /> -->
</sheetdata>
</windowclass>
</root>
23 changes: 22 additions & 1 deletion deckbox/deckbox_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<windowclass name="deckbox_settings">
<frame>recordsheet</frame>
<placement>
<size width="700" height="400" />
<size width="700" height="500" />
</placement>
<script file="deckbox/scripts/deckbox_settings.lua" />
<sheetdata>
Expand Down Expand Up @@ -39,6 +39,13 @@
<center />
</header_column>

<setting_label name="deal_facing_label">
<static textres="deckbox_settings_label_default_deal_facing" />
</setting_label>
<combobox_setting name="deal_facing" source="settings.defaultdealfacing">
<parameter>DECK_SETTING_DEFAULT_DEAL_FACING</parameter>
</combobox_setting>

<setting_label name="deal_vis_label">
<static textres="deckbox_settings_label_deal_visibility" />
</setting_label>
Expand Down Expand Up @@ -67,6 +74,20 @@
<parameter>DECK_SETTING_GIVE_VISIBILITY</parameter>
</combobox_setting>

<setting_label name="flip_vis_label">
<static textres="deckbox_settings_label_flip_visibility" />
</setting_label>
<combobox_setting name="flip_vis" source="settings.flipvisibility">
<parameter>DECK_SETTING_FLIP_VISIBILITY</parameter>
</combobox_setting>

<setting_label name="peek_vis_label">
<static textres="deckbox_settings_label_peek_visibility" />
</setting_label>
<combobox_setting name="peek_vis" source="settings.peekvisibility">
<parameter>DECK_SETTING_PEEK_VISIBILITY</parameter>
</combobox_setting>

<setting_label name="gm_sees_facedown_label">
<static textres="deckbox_settings_label_gm_sees_facedown" />
</setting_label>
Expand Down
5 changes: 4 additions & 1 deletion deckbox/scripts/combobox_setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function setComboValue(sValue)
if (sValue or "") == "" then
self.setListIndex(1);
sValue = self.getSelectedValue();
DB.setValue(getDatabaseNode().getPath(), "string", sValue);
local node = getDatabaseNode();
if node then
DB.setValue(node.getPath(), "string", sValue);
end
elseif hasValue(sValue) then
for nIndex,sKnownValue in ipairs(getValues()) do
if sValue == sKnownValue then
Expand Down
30 changes: 7 additions & 23 deletions desktop/desktop_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,19 @@
<root>
<windowclass name="desktop_card">
<margins control="0,0,0,0" />
<script>
local bPopped = false;

function onInit()
highlight.setEnabled(false);
end

function setCardSize(nWidth, nHeight)
image.setAnchoredWidth(nWidth);
image.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
</script>
<script file="desktop/scripts/desktop_card.lua" />
<sheetdata>
<token_card name="image">
<script file="common/scripts/onCardDrag.lua" />
<script file="common/scripts/standardCardRadialOptions.lua" />
</token_card>
<token_card_back name="cardback">
<script file="common/scripts/onCardDrag.lua" />
<script file="common/scripts/standardCardRadialOptions.lua" />
<canpeek />
</token_card_back>
<icon_missing_token name="missingtoken" />
<card_highlight name="highlight" />
<!-- <card_highlight name="highlight" /> -->
</sheetdata>
</windowclass>
</root>
41 changes: 41 additions & 0 deletions desktop/scripts/desktop_card.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local bPopped = false;

function onInit()
-- highlight.setEnabled(false);

local node = getDatabaseNode();
DB.addHandler(DB.getPath(node, CardManager.CARD_FACING_PATH), "onUpdate", onFacingChanged)

onFacingChanged();
end

function onClose()
local node = getDatabaseNode();
DB.removeHandler(DB.getPath(node, CardManager.CARD_FACING_PATH), "onUpdate", onFacingChanged)
end

function onFacingChanged(nodeUpdated)
local bFaceUp = CardManager.isCardFaceUp(getDatabaseNode());
image.setVisible(bFaceUp);
image.setEnabled(bFaceUp);
cardback.setVisible(not bFaceUp);
cardback.setEnabled(not bFaceUp);

end

function setCardSize(nWidth, nHeight)
image.setAnchoredWidth(nWidth);
image.setAnchoredHeight(nHeight);
cardback.setAnchoredWidth(nWidth);
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
4 changes: 2 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.0.4 by Saagael." icon="decked_out" font="emotefont" />
<announcement text="Decked Out v1.1.0 by Saagael." icon="decked_out" font="emotefont" />
<properties>
<name>Feature: Decked Out</name>
<version>1.0.4</version>
<version>1.1.0</version>
<author>Saagael</author>
<description>Adds decks of cards</description>
<loadorder>1000</loadorder>
Expand Down
2 changes: 2 additions & 0 deletions graphics/graphics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<icon name="deal_multiperson" file="graphics/radial/deal_multiperson.png" />
<icon name="multideal" file="graphics/radial/multideal.png" />
<icon name="multideal_multiperson" file="graphics/radial/multideal_multiperson.png" />
<icon name="peek" file="graphics/radial/peekcard.png" />
<icon name="flip" file="graphics/radial/flipcard.png" />

<!-- Misc -->
<icon name="missing_token" file="graphics/icons/missing_token.png" />
Expand Down
6 changes: 6 additions & 0 deletions scripts/decked_out.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function onInit()
{ 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",
{ 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",
{ 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",
{ 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",
{ labels = "option_val_yes", values = "yes", baselabel = "option_val_no", baseval = "no", default = "no" });
end

function isBetterMenusLoaded()
Expand Down
Loading

0 comments on commit 35de7a4

Please sign in to comment.