Skip to content

Commit 44bd8ab

Browse files
Hide palette selector for deckskins/collabs that have only a single palette (#1163)
1 parent 9edcff3 commit 44bd8ab

File tree

4 files changed

+242
-227
lines changed

4 files changed

+242
-227
lines changed

lovely/deck_skins.toml

Lines changed: 16 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,6 @@ priority = -10
66
#========================================================#
77
# Choose any rank for custom deck and use provided atlas #
88
#========================================================#
9-
[[patches]]
10-
[patches.pattern]
11-
target = "functions/UI_definitions.lua"
12-
pattern = "{n=G.UIT.O, config={object = face_cards}}"
13-
position = "at"
14-
payload = "{n=G.UIT.O, config={object = G.cdds_cards}}"
15-
match_indent = true
16-
overwrite = false
17-
18-
[[patches]]
19-
[patches.pattern]
20-
target = "functions/UI_definitions.lua"
21-
pattern = "table.insert(t, create_toggle({label = localize('b_high_contrast_cards'), ref_table = G.SETTINGS, ref_value = 'colourblind_option', callback = G.FUNCS.refresh_contrast_mode}))"
22-
position = "at"
23-
payload = '''
24-
local deckskin_key = G.COLLABS.options[_suit][current_option]
25-
26-
local palette_loc_options = SMODS.DeckSkin.get_palette_loc_options(deckskin_key, _suit)
27-
28-
local selected_palette = 1
29-
for i, v in ipairs(G.COLLABS.colour_palettes[deckskin_key]) do
30-
if G.SETTINGS.colour_palettes[_suit] == v then
31-
selected_palette = i
32-
end
33-
end
34-
35-
table.insert(t,
36-
{n=G.UIT.R, config={align = "cm", id = 'palette_selector'}, nodes={
37-
create_option_cycle({options = palette_loc_options, w = 5.5, cycle_shoulders = false, curr_suit = _suit, curr_skin = deckskin_key, opt_callback = 'change_colour_palette', current_option = selected_palette, colour = G.C.ORANGE, focus_args = {snap_to = true, nav = 'wide'}}),
38-
}}
39-
)
40-
'''
41-
match_indent = true
42-
overwrite = false
43-
44-
#=======================#
45-
# Extend custom deck ui #
46-
#=======================#
47-
[[patches]]
48-
[patches.regex]
49-
target = "functions/UI_definitions.lua"
50-
pattern = '''local face_cards = CardArea\(([\s\S]*?)\)'''
51-
position = "at"
52-
payload = '''
53-
local rankCount = 0
54-
local lookup = {}
55-
for i, s in ipairs(SMODS.Suit:obj_list(true)) do
56-
local options = G.COLLABS.options[s.key]
57-
for i = 1, #options do
58-
local skin = SMODS.DeckSkins[options[i]]
59-
if skin.palettes and not (skin.display_ranks or skin.ranks) then
60-
for _, p in ipairs(skin.palettes) do
61-
local p_ranks = p.display_ranks or p.ranks
62-
for j = 1, #p_ranks do
63-
if not lookup[p_ranks[j]] then
64-
lookup[p_ranks[j]] = true
65-
rankCount = rankCount + 1
66-
end
67-
end
68-
end
69-
elseif not skin.palettes and (skin.display_ranks or skin.ranks) then
70-
local ranks = skin.display_ranks or skin.ranks
71-
for j = 1, #ranks do
72-
if not lookup[skin.ranks[j]] then
73-
lookup[skin.ranks[j]] = true
74-
rankCount = rankCount + 1
75-
end
76-
end
77-
end
78-
79-
end
80-
end
81-
82-
G.cdds_cards = CardArea(
83-
0,0,
84-
math.min(math.max(rankCount*G.CARD_W*0.6, 4*G.CARD_W), 10*G.CARD_W),
85-
1.4*G.CARD_H,
86-
{card_limit = rankCount, type = 'title', highlight_limit = 0})
87-
88-
G.cdds_cards.rankCount = rankCount
89-
90-
'''
91-
92-
[[patches]]
93-
[patches.regex]
94-
target = "functions/UI_definitions.lua"
95-
pattern = '''for i = 1, 3 do([\s\S]*?)end'''
96-
position = "at"
97-
payload = '''
98-
G.FUNCS.update_collab_cards(current_option, _suit, true)
99-
'''
1009

10110
[[patches]]
10211
[patches.regex]
@@ -183,4 +92,19 @@ target = "functions/UI_definitions.lua"
18392
pattern = '''label = "Collabs",'''
18493
position = "after"
18594
payload = '''chosen = SMODS.init_collab_credits,'''
186-
match_indent = true
95+
match_indent = true
96+
97+
# Add note for overriden function
98+
[[patches]]
99+
[patches.pattern]
100+
target = 'functions/UI_definitions.lua'
101+
match_indent = true
102+
position = 'before'
103+
pattern = '''
104+
function G.UIDEF.custom_deck_tab(_suit)
105+
'''
106+
payload = '''
107+
-- WARNING
108+
-- This function is overriden by SMODS and can be found in src/ui.lua
109+
-- WARNING
110+
'''

src/overrides.lua

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ end
575575

576576

577577
function G.UIDEF.stake_option(_type)
578-
578+
579579
local middle = {n=G.UIT.R, config={align = "cm", minh = 1.7, minw = 7.3}, nodes={
580580
{n=G.UIT.O, config={id = nil, func = 'RUN_SETUP_check_stake2', object = Moveable()}},
581581
}}
582-
582+
583583
local stake_options = {}
584584
local curr_options = {}
585585
local deck_usage = G.PROFILES[G.SETTINGS.profile].deck_usage[G.GAME.viewed_back.effect.center.key]
@@ -590,7 +590,7 @@ function G.UIDEF.stake_option(_type)
590590
curr_options[i] = #stake_options
591591
end
592592
end
593-
593+
594594
return {n=G.UIT.ROOT, config={align = "tm", colour = G.C.CLEAR, minh = 2.03, minw = 8.3}, nodes={
595595
_type == 'Continue' and middle
596596
or create_option_cycle({options = stake_options, opt_callback = 'change_stake', current_option = curr_options[G.viewed_stake] or 1,
@@ -865,7 +865,7 @@ function tally_sprite(pos, value, tooltip, suit)
865865
local atlas_key_2 = ("ui_" .. (G.SETTINGS.colourblind_option and "2" or "1"))
866866
local atlas = SMODS.get_atlas(atlas_key_1) or SMODS.get_atlas(atlas_key_2)
867867
t_s = SMODS.create_sprite(0, 0, 0.3, 0.3, atlas, SMODS.Suits[suit].ui_pos)
868-
else
868+
else
869869
local atlas_key_1 = suit and SMODS.Suits[suit][G.SETTINGS.colourblind_option and "hc_ui_atlas" or "lc_ui_atlas"]
870870
local atlas_key_2 = ("ui_"..(G.SETTINGS.colourblind_option and "2" or "1"))
871871
local atlas = SMODS.get_atlas(atlas_key_1) or SMODS.get_atlas(atlas_key_2)
@@ -1219,7 +1219,7 @@ G.FUNCS.your_suits_page = function(args)
12191219
G.VIEWING_DECK = true
12201220
table.sort(G.playing_cards, function(a, b) return a:get_nominal('suit') > b:get_nominal('suit') end)
12211221
local SUITS = {}
1222-
local suit_map = {}
1222+
local suit_map = {}
12231223
for i = #SMODS.Suit.obj_buffer, 1, -1 do
12241224
SUITS[SMODS.Suit.obj_buffer[i]] = {}
12251225
suit_map[#suit_map + 1] = SMODS.Suit.obj_buffer[i]
@@ -1640,7 +1640,7 @@ function create_UIBox_current_hands(simple, in_collection)
16401640
no_pips = true,
16411641
in_collection = in_collection
16421642
}) }
1643-
} or nil }
1643+
} or nil }
16441644
}
16451645

16461646
local t = {
@@ -1944,9 +1944,9 @@ function create_UIBox_notify_alert(_achievement, _type)
19441944
t_s.states.drag.can = false
19451945
t_s.states.hover.can = false
19461946
t_s.states.collide.can = false
1947-
1947+
19481948
local subtext = _type == 'achievement' and localize(G.F_TROPHIES and 'k_trophy' or 'k_achievement') or
1949-
_type == 'Joker' and localize('k_joker') or
1949+
_type == 'Joker' and localize('k_joker') or
19501950
_type == 'Voucher' and localize('k_voucher') or
19511951
_type == 'Back' and localize('k_deck') or
19521952
_c.set and localize('k_' .. _c.set:lower()) or
@@ -2031,7 +2031,7 @@ end
20312031
-- silent = boolean value
20322032
function Card:set_edition(edition, immediate, silent, delay)
20332033
SMODS.enh_cache:write(self, nil)
2034-
2034+
20352035
if self.edition then
20362036
self.ability.card_limit = self.ability.card_limit - (self.edition.card_limit or 0)
20372037
self.ability.extra_slots_used = self.ability.extra_slots_used - (self.edition.extra_slots_used or 0)
@@ -2442,16 +2442,21 @@ G.FUNCS.change_collab = function(args)
24422442
end
24432443
G.FUNCS.update_suit_colours(args.cycle_config.curr_suit, deckskin_key, selected_palette)
24442444
G.FUNCS.update_collab_cards(args.to_key, args.cycle_config.curr_suit)
2445-
if swap_node then
2446-
for i=1, #swap_node.children do
2447-
swap_node.children[i]:remove()
2448-
swap_node.children[i] = nil
2449-
end
2450-
local new_palette_selector = {n=G.UIT.R, config={align = "cm", id = 'palette_selector'}, nodes={
2451-
create_option_cycle({options = palette_loc_options, w = 5.5, cycle_shoulders = false, curr_suit = args.cycle_config.curr_suit, curr_skin = deckskin_key, opt_callback = 'change_colour_palette', current_option = selected_palette, colour = G.C.ORANGE, focus_args = {snap_to = true, nav = 'wide'}}),
2445+
2446+
local swap_node = G.OVERLAY_MENU:get_UIE_by_ID('palette_selector')
2447+
for i=1, #swap_node.children do
2448+
swap_node.children[i]:remove()
2449+
swap_node.children[i] = nil
2450+
end
2451+
if #palette_loc_options > 1 then
2452+
local opt_cycle = create_option_cycle({options = palette_loc_options, w = 4.5, h = 0.5, text_scale = 0.3, cycle_shoulders = false, curr_suit = args.cycle_config.curr_suit, curr_skin = deckskin_key, opt_callback = 'change_colour_palette', current_option = selected_palette, colour = G.C.ORANGE, focus_args = {snap_to = true, nav = 'wide'}})
2453+
opt_cycle.nodes[1].config.padding = 0.085
2454+
local new_palette_selector = {n=G.UIT.R, config={align = "cm", id = 'palette_selector', minh = 0.85}, nodes={
2455+
opt_cycle
24522456
}}
24532457
swap_node.UIBox:add_child(new_palette_selector, swap_node)
2454-
end
2458+
end
2459+
24552460
for k, v in pairs(G.I.CARD) do
24562461
if v.config and v.config.card and v.children.front and v.ability.effect ~= 'Stone Card' then
24572462
v:set_sprites(nil, v.config.card)
@@ -2496,7 +2501,7 @@ end
24962501
local debuff_card = Blind.debuff_card
24972502
function Blind:debuff_card(card, from_blind)
24982503
local flags = SMODS.calculate_context({ debuff_card = card, ignore_debuff = true })
2499-
if flags.prevent_debuff then
2504+
if flags.prevent_debuff then
25002505
if card.debuff then card:set_debuff(false) end
25012506
return
25022507
elseif flags.debuff then
@@ -2571,7 +2576,7 @@ function Card:set_base(card, initial, manual_sprites)
25712576
SMODS.merge_defaults(contexts, {change_rank = true, other_card = self, new_rank = new_rank, old_rank = self.base.id, rank_increase = ((self.base.id < new_rank) and true) or false})
25722577
end
25732578
end
2574-
if card and card.suit and self.base.suit ~= card.suit then
2579+
if card and card.suit and self.base.suit ~= card.suit then
25752580
SMODS.merge_defaults(contexts, {change_suit = true, other_card = self, new_suit = card.suit, old_suit = self.base.suit})
25762581
end
25772582
if next(contexts) then

0 commit comments

Comments
 (0)