Skip to content

Commit aff8b25

Browse files
authored
Add Poker Hands to collection (#844)
1 parent 8e56517 commit aff8b25

File tree

4 files changed

+134
-52
lines changed

4 files changed

+134
-52
lines changed

lovely/poker_hand_screen.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ match_indent = true
3333
[[patches]]
3434
[patches.pattern]
3535
target = "functions/UI_definitions.lua"
36-
pattern = '''return (G.GAME.hands[handname].visible) and'''
36+
pattern = '''
37+
function create_UIBox_current_hand_row(handname, simple)
38+
return (G.GAME.hands[handname].visible) and
39+
'''
3740
position = "at"
3841
payload = '''
39-
return SMODS.is_poker_hand_visible(handname) and
42+
function create_UIBox_current_hand_row(handname, simple, in_collection)
43+
return (in_collection or SMODS.is_poker_hand_visible(handname)) and
4044
'''
4145
match_indent = true

lsp_def/classes/poker_hand.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
---@field visible? boolean|fun(self:SMODS.PokerHand|table): boolean? Sets hand visibility in the poker hands menu. If `false`, poker hand is shown only after being played once. A function allows more precise control over hand visibility in the poker hands menu.
1414
---@field above_hand? PokerHands|string Key to a poker hand. Used to order this poker hand above specified poker hand.
1515
---@field order_offset? number Adds this value to poker hand's mult and chips to offset ordering.
16+
---@field no_collection? boolean Sets whether the poker hand shows up in the collections menu.
1617
---@field __call? fun(self: SMODS.PokerHand|table, o: SMODS.PokerHand|table): nil|table|SMODS.PokerHand
1718
---@field extend? fun(self: SMODS.PokerHand|table, o: SMODS.PokerHand|table): table Primary method of creating a class.
1819
---@field check_duplicate_register? fun(self: SMODS.PokerHand|table): boolean? Ensures objects already registered will not register.

src/overrides.lua

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,19 +1536,31 @@ function G.FUNCS.get_poker_hand_info(_cards)
15361536
return text, loc_disp_text, poker_hands, scoring_hand, disp_text
15371537
end
15381538

1539-
function create_UIBox_current_hands(simple)
1539+
function create_UIBox_current_hands(simple, in_collection)
15401540
G.current_hands = {}
15411541

1542+
local _pool = in_collection and SMODS.collection_pool(SMODS.PokerHands) or nil
1543+
local handlist = in_collection and {} or nil
1544+
if _pool then
1545+
for _, v in ipairs(_pool) do
1546+
table.insert(handlist, v.key)
1547+
end
1548+
end
1549+
15421550
local visible_hands = {}
1543-
for _, v in ipairs(G.handlist) do
1544-
if SMODS.is_poker_hand_visible(v) then
1545-
table.insert(visible_hands, v)
1551+
if not handlist then
1552+
for _, v in ipairs(G.handlist) do
1553+
if SMODS.is_poker_hand_visible(v) then
1554+
table.insert(visible_hands, v)
1555+
end
15461556
end
1557+
else
1558+
visible_hands = handlist
15471559
end
15481560

15491561
local index = 0
1550-
for _, v in ipairs(G.handlist) do
1551-
local ui_element = create_UIBox_current_hand_row(v, simple)
1562+
for _, v in ipairs(handlist or G.handlist) do
1563+
local ui_element = create_UIBox_current_hand_row(v, simple, in_collection)
15521564
G.current_hands[index + 1] = ui_element
15531565
if ui_element then
15541566
index = index + 1
@@ -1558,48 +1570,71 @@ function create_UIBox_current_hands(simple)
15581570
end
15591571
end
15601572

1561-
15621573
local hand_options = {}
15631574
for i = 1, math.ceil(#visible_hands / 10) do
15641575
table.insert(hand_options,
15651576
localize('k_page') .. ' ' .. tostring(i) .. '/' .. tostring(math.ceil(#visible_hands / 10)))
15661577
end
15671578

1568-
local object = {n = G.UIT.ROOT, config = {align = "cm", colour = G.C.CLEAR}, nodes = {
1569-
{n = G.UIT.R, config = {align = "cm", padding = 0.04}, nodes =
1570-
G.current_hands},
1571-
-- UI consistency with vanilla
1572-
#visible_hands > 12 and {n = G.UIT.R, config = {align = "cm", padding = 0}, nodes = {
1573-
create_option_cycle({
1574-
options = hand_options,
1575-
w = 4.5,
1576-
cycle_shoulders = true,
1577-
opt_callback = 'your_hands_page',
1578-
focus_args = { snap_to = true, nav = 'wide' },
1579-
current_option = 1,
1580-
colour = G.C.RED,
1581-
no_pips = true
1582-
})}} or nil,
1583-
}}
1579+
local object = {
1580+
n = G.UIT.ROOT,
1581+
config = { align = "cm", colour = G.C.CLEAR },
1582+
nodes = {
1583+
{
1584+
n = G.UIT.R,
1585+
config = { align = "cm", padding = 0.04 },
1586+
nodes =
1587+
G.current_hands
1588+
},
1589+
-- UI consistency with vanilla
1590+
#visible_hands > 12 and {
1591+
n = G.UIT.R,
1592+
config = { align = "cm", padding = 0 },
1593+
nodes = {
1594+
create_option_cycle({
1595+
options = hand_options,
1596+
w = 4.5,
1597+
cycle_shoulders = true,
1598+
opt_callback = 'your_hands_page',
1599+
focus_args = { snap_to = true, nav = 'wide' },
1600+
current_option = 1,
1601+
colour = G.ACTIVE_MOD_UI and (G.ACTIVE_MOD_UI.ui_config or {}).collection_option_cycle_colour or
1602+
G.C.RED,
1603+
no_pips = true,
1604+
in_collection = in_collection
1605+
}) }
1606+
} or nil }
1607+
}
15841608

1585-
local t = {n = G.UIT.ROOT, config = {align = "cm", minw = 3, padding = 0.1, r = 0.1, colour = G.C.CLEAR}, nodes = {
1586-
{n = G.UIT.O, config = {
1587-
id = 'hand_list',
1588-
object = UIBox {
1589-
definition = object, config = {offset = { x = 0, y = 0 }, align = 'cm'}
1590-
}
1591-
}}}}
1592-
return t
1609+
local t = {
1610+
n = G.UIT.O,
1611+
config = {
1612+
id = 'hand_list',
1613+
object = UIBox {
1614+
definition = object, config = { offset = { x = 0, y = 0 }, align = 'cm' }
1615+
}
1616+
}
1617+
}
1618+
return not in_collection and
1619+
{ n = G.UIT.ROOT, config = { align = "cm", minw = 3, padding = 0.1, r = 0.1, colour = G.C.CLEAR }, nodes = { t } } or
1620+
t
15931621
end
15941622

15951623
G.FUNCS.your_hands_page = function(args)
15961624
if not args or not args.cycle_config then return end
15971625
G.current_hands = {}
1598-
1626+
local in_collection = args.cycle_config.in_collection
1627+
local _pool = in_collection and SMODS.collection_pool(SMODS.PokerHands) or nil
1628+
local handlist = in_collection and {} or nil
1629+
if _pool then
1630+
for _, v in ipairs(_pool) do
1631+
table.insert(handlist, v.key)
1632+
end
1633+
end
15991634

16001635
local index = 0
1601-
for _, v in ipairs(G.handlist) do
1602-
local ui_element = create_UIBox_current_hand_row(v, simple)
1636+
for _, v in ipairs(handlist or G.handlist) do
1637+
local ui_element = create_UIBox_current_hand_row(v, simple, in_collection)
16031638
if index >= (0 + 10 * (args.cycle_config.current_option - 1)) and index < 10 * args.cycle_config.current_option then
16041639
G.current_hands[index - (10 * (args.cycle_config.current_option - 1)) + 1] = ui_element
16051640
end
@@ -1614,10 +1649,14 @@ G.FUNCS.your_hands_page = function(args)
16141649
end
16151650

16161651
local visible_hands = {}
1617-
for _, v in ipairs(G.handlist) do
1618-
if SMODS.is_poker_hand_visible(v) then
1619-
table.insert(visible_hands, v)
1652+
if not handlist then
1653+
for _, v in ipairs(G.handlist) do
1654+
if SMODS.is_poker_hand_visible(v) then
1655+
table.insert(visible_hands, v)
1656+
end
16201657
end
1658+
else
1659+
visible_hands = handlist
16211660
end
16221661

16231662
local hand_options = {}
@@ -1626,10 +1665,16 @@ G.FUNCS.your_hands_page = function(args)
16261665
localize('k_page') .. ' ' .. tostring(i) .. '/' .. tostring(math.ceil(#visible_hands / 10)))
16271666
end
16281667

1629-
local object = {n = G.UIT.ROOT, config = {align = "cm", colour = G.C.CLEAR }, nodes = {
1630-
{n = G.UIT.R, config = {align = "cm", padding = 0.04 }, nodes = G.current_hands
1668+
local object = {
1669+
n = G.UIT.ROOT,
1670+
config = { align = "cm", colour = G.C.CLEAR },
1671+
nodes = {
1672+
{ n = G.UIT.R, config = { align = "cm", padding = 0.04 }, nodes = G.current_hands
16311673
},
1632-
{n = G.UIT.R, config = {align = "cm", padding = 0 }, nodes = {
1674+
{
1675+
n = G.UIT.R,
1676+
config = { align = "cm", padding = 0 },
1677+
nodes = {
16331678
create_option_cycle({
16341679
options = hand_options,
16351680
w = 4.5,
@@ -1638,9 +1683,10 @@ G.FUNCS.your_hands_page = function(args)
16381683
'your_hands_page',
16391684
focus_args = { snap_to = true, nav = 'wide' },
16401685
current_option = args.cycle_config.current_option,
1641-
colour = G
1642-
.C.RED,
1643-
no_pips = true
1686+
colour = G.ACTIVE_MOD_UI and (G.ACTIVE_MOD_UI.ui_config or {}).collection_option_cycle_colour or
1687+
G.C.RED,
1688+
no_pips = true,
1689+
in_collection = in_collection
16441690
})
16451691
}
16461692
}
@@ -1653,7 +1699,7 @@ G.FUNCS.your_hands_page = function(args)
16531699
hand_list.config.object:remove()
16541700
end
16551701
hand_list.config.object = UIBox {
1656-
definition = object, config = {offset = { x = 0, y = 0 }, align = 'cm', parent = hand_list }
1702+
definition = object, config = { offset = { x = 0, y = 0 }, align = 'cm', parent = hand_list }
16571703
}
16581704
end
16591705
end

src/ui.lua

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,11 @@ function create_UIBox_Other_GameObjects()
480480
{
481481
count = G.ACTIVE_MOD_UI and modsCollectionTally(SMODS.Stickers), --Returns nil outside of G.ACTIVE_MOD_UI but we don't use it anyways
482482
button = UIBox_button({button = 'your_collection_stickers', label = {localize('b_stickers')}, count = G.ACTIVE_MOD_UI and modsCollectionTally(SMODS.Stickers), minw = 5, id = 'your_collection_stickers'})
483-
}
483+
},
484+
{
485+
count = G.ACTIVE_MOD_UI and modsCollectionTally(SMODS.PokerHands, nil, true),
486+
button = UIBox_button({button = 'your_collection_poker_hands', label = {localize('b_poker_hands')}, count = G.ACTIVE_MOD_UI and modsCollectionTally(SMODS.PokerHands, nil, true), minw = 5, id = 'your_collection_poker_hands'})
487+
},
484488
}
485489

486490
if G.ACTIVE_MOD_UI then
@@ -814,7 +818,7 @@ G.FUNCS.achievments_tab_page = function(args)
814818
end
815819

816820
-- TODO: Optimize this.
817-
function modsCollectionTally(pool, set)
821+
function modsCollectionTally(pool, set, ignore_discovered)
818822
local set = set or nil
819823
local obj_tally = {tally = 0, of = 0}
820824

@@ -823,13 +827,13 @@ function modsCollectionTally(pool, set)
823827
if set then
824828
if v.set and v.set == set then
825829
obj_tally.of = obj_tally.of+1
826-
if v.discovered then
830+
if ignore_discovered or v.discovered then
827831
obj_tally.tally = obj_tally.tally+1
828832
end
829833
end
830834
else
831835
obj_tally.of = obj_tally.of+1
832-
if v.discovered then
836+
if ignore_discovered or v.discovered then
833837
obj_tally.tally = obj_tally.tally+1
834838
end
835839
end
@@ -2023,7 +2027,7 @@ G.FUNCS.your_collection_stickers = function(e)
20232027
end
20242028

20252029
create_UIBox_your_collection_stickers = function()
2026-
return SMODS.card_collection_UIBox(SMODS.Stickers, {5,5}, {
2030+
return SMODS.card_collection_UIBox(SMODS.Stickers, { 5, 5 }, {
20272031
snap_back = true,
20282032
hide_single_page = true,
20292033
collapse_single_page = true,
@@ -2035,7 +2039,34 @@ create_UIBox_your_collection_stickers = function()
20352039
center:apply(card, true)
20362040
end,
20372041
})
2038-
end
2042+
end
2043+
2044+
G.FUNCS.your_collection_poker_hands = function(e)
2045+
G.SETTINGS.paused = true
2046+
G.FUNCS.overlay_menu{
2047+
definition = create_UIBox_your_collection_poker_hands(),
2048+
}
2049+
end
2050+
2051+
create_UIBox_your_collection_poker_hands = function (args)
2052+
return create_UIBox_generic_options({
2053+
colour = G.ACTIVE_MOD_UI and
2054+
((G.ACTIVE_MOD_UI.ui_config or {}).collection_colour or (G.ACTIVE_MOD_UI.ui_config or {}).colour),
2055+
bg_colour = G.ACTIVE_MOD_UI and
2056+
((G.ACTIVE_MOD_UI.ui_config or {}).collection_bg_colour or (G.ACTIVE_MOD_UI.ui_config or {}).bg_colour),
2057+
back_colour = G.ACTIVE_MOD_UI and
2058+
((G.ACTIVE_MOD_UI.ui_config or {}).collection_back_colour or (G.ACTIVE_MOD_UI.ui_config or {}).back_colour),
2059+
outline_colour = G.ACTIVE_MOD_UI and ((G.ACTIVE_MOD_UI.ui_config or {}).collection_outline_colour or
2060+
(G.ACTIVE_MOD_UI.ui_config or {}).outline_colour),
2061+
back_func = (args and args.back_func) or G.ACTIVE_MOD_UI and "openModUI_" .. G.ACTIVE_MOD_UI.id or
2062+
'your_collection_other_gameobjects',
2063+
snap_back = args and args.snap_back,
2064+
infotip = args and args.infotip,
2065+
contents = {
2066+
create_UIBox_current_hands(nil, true)
2067+
}
2068+
})
2069+
end
20392070

20402071
-- warning for updating during run
20412072
local igo = Game.init_game_object

0 commit comments

Comments
 (0)