/
inventoryslot.lua
executable file
·3059 lines (2704 loc) · 131 KB
/
inventoryslot.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local slotTypeIndex = 0
local function CreateSlotType(slotType)
slotTypeIndex = slotTypeIndex + 1
_G[slotType] = slotTypeIndex
end
CreateSlotType("SLOT_TYPE_QUEST_ITEM")
CreateSlotType("SLOT_TYPE_ITEM")
CreateSlotType("SLOT_TYPE_EQUIPMENT")
CreateSlotType("SLOT_TYPE_MY_TRADE")
CreateSlotType("SLOT_TYPE_THEIR_TRADE")
CreateSlotType("SLOT_TYPE_STORE_BUY")
CreateSlotType("SLOT_TYPE_STORE_BUYBACK")
CreateSlotType("SLOT_TYPE_BUY_MULTIPLE")
CreateSlotType("SLOT_TYPE_BANK_ITEM")
CreateSlotType("SLOT_TYPE_GUILD_BANK_ITEM")
CreateSlotType("SLOT_TYPE_MAIL_QUEUED_ATTACHMENT")
CreateSlotType("SLOT_TYPE_MAIL_ATTACHMENT")
CreateSlotType("SLOT_TYPE_LOOT")
CreateSlotType("SLOT_TYPE_ACHIEVEMENT_REWARD")
CreateSlotType("SLOT_TYPE_PENDING_CHARGE")
CreateSlotType("SLOT_TYPE_ENCHANTMENT")
CreateSlotType("SLOT_TYPE_ENCHANTMENT_RESULT")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_POST_ITEM")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_ITEM_RESULT")
CreateSlotType("SLOT_TYPE_TRADING_HOUSE_ITEM_LISTING")
CreateSlotType("SLOT_TYPE_REPAIR")
CreateSlotType("SLOT_TYPE_PENDING_REPAIR")
CreateSlotType("SLOT_TYPE_STACK_SPLIT")
CreateSlotType("SLOT_TYPE_CRAFTING_COMPONENT")
CreateSlotType("SLOT_TYPE_PENDING_CRAFTING_COMPONENT")
CreateSlotType("SLOT_TYPE_MULTIPLE_PENDING_CRAFTING_COMPONENTS")
CreateSlotType("SLOT_TYPE_SMITHING_MATERIAL")
CreateSlotType("SLOT_TYPE_SMITHING_STYLE")
CreateSlotType("SLOT_TYPE_SMITHING_TRAIT")
CreateSlotType("SLOT_TYPE_SMITHING_BOOSTER")
CreateSlotType("SLOT_TYPE_LIST_DIALOG_ITEM")
CreateSlotType("SLOT_TYPE_DYEABLE_EQUIPMENT")
CreateSlotType("SLOT_TYPE_GUILD_SPECIFIC_ITEM")
CreateSlotType("SLOT_TYPE_LAUNDER")
CreateSlotType("SLOT_TYPE_GAMEPAD_INVENTORY_ITEM")
CreateSlotType("SLOT_TYPE_COLLECTIONS_INVENTORY")
CreateSlotType("SLOT_TYPE_CRAFT_BAG_ITEM")
CreateSlotType("SLOT_TYPE_PENDING_RETRAIT_ITEM")
local UpdateMouseoverCommand
--
-- Setup
--
function ZO_InventorySlot_SetType(slotControl, slotType)
slotControl.slotType = slotType
end
function ZO_InventorySlot_GetType(slotControl)
return slotControl.slotType
end
function ZO_InventorySlot_GetStackCount(slotControl)
return slotControl.stackCount or 0
end
local splittableTypes =
{
[SLOT_TYPE_BANK_ITEM] = true,
[SLOT_TYPE_ITEM] = true,
[SLOT_TYPE_GAMEPAD_INVENTORY_ITEM] = true,
}
function ZO_InventorySlot_IsSplittableType(slotControl)
return splittableTypes[slotControl.slotType]
end
function ZO_ItemSlot_SetupIconUsableAndLockedColor(control, meetsUsageRequirement, locked)
if meetsUsageRequirement == nil then
meetsUsageRequirement = true
end
if locked == nil then
locked = false
end
if control then
if meetsUsageRequirement then
control:SetColor(1, 1, 1)
else
control:SetColor(1, 0, 0)
end
if locked then
control:SetAlpha(0.5)
else
control:SetAlpha(1)
end
end
end
function ZO_ItemSlot_SetupTextUsableAndLockedColor(control, meetsUsageRequirement, locked)
if locked == nil then
locked = false
end
if control then
if locked then
control:SetAlpha(0.3)
else
control:SetAlpha(1)
end
end
end
function ZO_ItemSlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
local iconControl = GetControl(slotControl, "Icon")
ZO_ItemSlot_SetupIconUsableAndLockedColor(iconControl, meetsUsageRequirement, locked)
end
local USE_LOWERCASE_NUMBER_SUFFIXES = false
function ZO_ItemSlot_SetupSlotBase(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
local showSlot = true
if type(visible) == "function" then
showSlot = visible()
elseif visible ~= nil then
showSlot = visible
end
slotControl:SetHidden(not showSlot)
local iconControl = GetControl(slotControl, "Icon")
if iconControl then
if iconFile == nil or iconFile == "" then
iconControl:SetHidden(true)
else
iconControl:SetTexture(iconFile)
iconControl:SetHidden(false)
end
end
slotControl.stackCount = stackCount
local stackCountLabel = GetControl(slotControl, "StackCount")
if stackCount > 1 or slotControl.alwaysShowStackCount then
stackCountLabel:SetText(ZO_AbbreviateAndLocalizeNumber(stackCount, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
else
stackCountLabel:SetText("")
end
end
function ZO_ItemSlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
ZO_ItemSlot_SetupSlotBase(slotControl, stackCount, iconFile, meetsUsageRequirement, locked, visible)
-- Looks like this can be combined with the logic above, but certain animations (crafting) cannot
-- call ZO_ItemSlot_SetupUsableAndLockedColor, so keep that in mind if refactoring.
if stackCount > 1 or slotControl.alwaysShowStackCount then
local stackCountLabel = GetControl(slotControl, "StackCount")
if slotControl.minStackCount and stackCount < slotControl.minStackCount then
stackCountLabel:SetColor(1, 0, 0)
else
stackCountLabel:SetColor(1, 1, 1)
end
end
ZO_ItemSlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
end
function ZO_ItemSlot_SetAlwaysShowStackCount(slotControl, alwaysShowStackCount, minStackCount)
slotControl.alwaysShowStackCount = alwaysShowStackCount
slotControl.minStackCount = minStackCount or 1
end
function ZO_ItemSlot_GetAlwaysShowStackCount(slotControl)
return slotControl.alwaysShowStackCount
end
-- Bind a slot control to a specific type/bag/slot
-- This should be called for all item slots (trade, mail, store, backpack, bank, crafting, etc...)
-- The meaning of slotIndex/bagId are specific to those systems, but this is the API to bind the
-- data to the UI control.
function ZO_Inventory_BindSlot(slotControl, slotType, slotIndex, bagId)
ZO_InventorySlot_SetType(slotControl, slotType)
slotControl.slotIndex = slotIndex
slotControl.bagId = bagId
end
function ZO_Inventory_GetBagAndIndex(slotControl)
return slotControl.bagId, ZO_Inventory_GetSlotIndex(slotControl)
end
function ZO_Inventory_GetSlotIndex(slotControl)
return slotControl.slotIndex
end
function ZO_Inventory_GetSlotDataForInventoryControl(slotControl)
local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(slotControl)
return SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
end
function ZO_Inventory_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
ZO_ItemSlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
slotControl.inCooldown = false
slotControl.cooldown = GetControl(slotControl, "Cooldown")
slotControl.cooldown:SetTexture(iconFile)
ZO_InventorySlot_UpdateCooldowns(slotControl)
end
function ZO_Inventory_SetupQuestSlot(slotControl, questIndex, toolIndex, stepIndex, conditionIndex)
slotControl.questIndex = questIndex
slotControl.toolIndex = toolIndex
slotControl.stepIndex = stepIndex
slotControl.conditionIndex = conditionIndex
end
--Player Inventory Row
function ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
ZO_ItemSlot_SetupTextUsableAndLockedColor(GetControl(slotControl, "Name"), meetsUsageRequirement, locked)
ZO_ItemSlot_SetupTextUsableAndLockedColor(GetControl(slotControl, "SellPrice"), meetsUsageRequirement, locked)
ZO_ItemSlot_SetupUsableAndLockedColor(GetControl(slotControl, "Button"), meetsUsageRequirement, locked)
end
function ZO_PlayerInventorySlot_SetupSlot(slotControl, stackCount, iconFile, meetsUsageRequirement, locked)
ZO_Inventory_SetupSlot(GetControl(slotControl, "Button"), stackCount, iconFile, meetsUsageRequirement, locked)
ZO_PlayerInventorySlot_SetupUsableAndLockedColor(slotControl, meetsUsageRequirement, locked)
end
--
-- Control Utils
--
function ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
-- Figure out what got passed in...inventorySlot could be a list or button type...
local buttonPart = inventorySlot
local listPart
local multiIconPart
local controlType = inventorySlot:GetType()
if controlType == CT_CONTROL and buttonPart.slotControlType and buttonPart.slotControlType == "listSlot" then
listPart = inventorySlot
buttonPart = inventorySlot:GetNamedChild("Button")
multiIconPart = inventorySlot:GetNamedChild("MultiIcon")
elseif controlType == CT_BUTTON then
listPart = buttonPart:GetParent()
end
return buttonPart, listPart, multiIconPart
end
local g_highlightAnimationProvider = ZO_ReversibleAnimationProvider:New("ShowOnMouseOverLabelAnimation")
local g_controlScaleAnimationProvider = ZO_ReversibleAnimationProvider:New("IconSlotMouseOverAnimation")
function ZO_InventorySlot_SetHighlightHidden(listPart, hidden, instant)
if listPart then
local highlight = listPart:GetNamedChild("Highlight")
if highlight and highlight:GetType() == CT_TEXTURE then
if hidden then
g_highlightAnimationProvider:PlayBackward(highlight, instant)
else
g_highlightAnimationProvider:PlayForward(highlight, instant)
end
end
end
end
function ZO_InventorySlot_SetControlScaledUp(control, scaledUp, instant)
if control then
if scaledUp then
g_controlScaleAnimationProvider:PlayForward(control, instant)
else
g_controlScaleAnimationProvider:PlayBackward(control, instant)
end
end
end
function ZO_InventorySlot_OnPoolReset(inventorySlot)
local buttonPart, listPart, multiIconPart = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
local INSTANT = true
ZO_InventorySlot_SetHighlightHidden(listPart, true, INSTANT)
ZO_InventorySlot_SetControlScaledUp(buttonPart, false, INSTANT)
ZO_InventorySlot_SetControlScaledUp(multiIconPart, false, INSTANT)
ZO_ObjectPool_DefaultResetControl(inventorySlot)
end
--
-- Cooldowns
--
local NO_LEADING_EDGE = false
local function UpdateCooldown(inventorySlot, remaining, duration)
inventorySlot.inCooldown = (remaining > 0) and (duration > 0)
if inventorySlot.inCooldown then
inventorySlot.cooldown:StartCooldown(remaining, duration, CD_TYPE_RADIAL, CD_TIME_TYPE_TIME_UNTIL, NO_LEADING_EDGE)
else
inventorySlot.cooldown:ResetCooldown()
end
inventorySlot.cooldown:SetHidden(not inventorySlot.inCooldown)
end
local function QuestItemUpdateCooldown(inventorySlot)
if(inventorySlot) then
local remaining, duration = GetQuestToolCooldownInfo(inventorySlot.questIndex, inventorySlot.toolIndex)
UpdateCooldown(inventorySlot, remaining, duration)
end
return true
end
local function ItemUpdateCooldown(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local remaining, duration = GetItemCooldownInfo(bag, index)
UpdateCooldown(inventorySlot, remaining, duration)
return true
end
local function CollectibleItemUpdateCooldown(inventorySlot)
local remaining, duration = GetCollectibleCooldownAndDuration(inventorySlot.collectibleId)
UpdateCooldown(inventorySlot, remaining, duration)
return true
end
local InventoryUpdateCooldown =
{
[SLOT_TYPE_ITEM] =
{
[1] = function(inventorySlot)
return ItemUpdateCooldown(inventorySlot)
end,
},
[SLOT_TYPE_QUEST_ITEM] =
{
[1] = function(inventorySlot)
return QuestItemUpdateCooldown(inventorySlot)
end,
},
[SLOT_TYPE_COLLECTIONS_INVENTORY] =
{
[1] = function(inventorySlot)
return CollectibleItemUpdateCooldown(inventorySlot)
end,
}
}
function ZO_InventorySlot_UpdateCooldowns(inventorySlot)
local inventorySlotButton = ZO_InventorySlot_GetInventorySlotComponents(inventorySlot)
RunHandlers(InventoryUpdateCooldown, inventorySlotButton)
end
function ZO_GamepadItemSlot_UpdateCooldowns(inventorySlot, remaining, duration)
UpdateCooldown(inventorySlot, remaining, duration)
end
--
-- Actions that can be performed on InventorySlots (via various clicks and context menus)
--
local function IsSendingMail()
if MAIL_SEND and not MAIL_SEND:IsHidden() then
return true
elseif MAIL_MANAGER_GAMEPAD and MAIL_MANAGER_GAMEPAD:GetSend():IsAttachingItems() then
return true
end
return false
end
local function CanUseSecondaryActionOnSlot(inventorySlot)
if not inventorySlot then
return false
end
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return not (QUICKSLOT_KEYBOARD and QUICKSLOT_KEYBOARD:AreQuickSlotsShowing())
and not (TRADING_HOUSE_SEARCH and TRADING_HOUSE_SEARCH:IsAtTradingHouse())
and not (ZO_Store_IsShopping and ZO_Store_IsShopping())
and not IsSendingMail()
and not (TRADE_WINDOW and TRADE_WINDOW:IsTrading())
and not IsBankOpen()
and not IsGuildBankOpen()
and not (GetItemActorCategory(bag, index) == GAMEPLAY_ACTOR_CATEGORY_COMPANION)
end
local function CanUseItemQuestItem(inventorySlot)
if inventorySlot then
if inventorySlot.toolIndex then
return CanUseQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
elseif inventorySlot.conditionIndex then
return CanUseQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
end
end
return false
end
local function TryUseQuestItem(inventorySlot)
if inventorySlot then
if inventorySlot.toolIndex then
UseQuestTool(inventorySlot.questIndex, inventorySlot.toolIndex)
elseif inventorySlot.conditionIndex then
UseQuestItem(inventorySlot.questIndex, inventorySlot.stepIndex, inventorySlot.conditionIndex)
end
end
end
function ZO_InventorySlot_CanQuickslotItem(inventorySlot)
if inventorySlot.filterData then
if ZO_IsElementInNumericallyIndexedTable(inventorySlot.filterData, ITEMFILTERTYPE_QUICKSLOT) then
return true
elseif ZO_IsElementInNumericallyIndexedTable(inventorySlot.filterData, ITEMFILTERTYPE_QUEST_QUICKSLOT) then
return true
end
end
return false
end
function ZO_InventorySlot_CanSplitItemStack(inventorySlot)
if ZO_InventorySlot_GetStackCount(inventorySlot) > 1 then
local hasFreeSlot = FindFirstEmptySlotInBag(inventorySlot.bagId) ~= nil
if not hasFreeSlot then
if inventorySlot.bagId == BAG_BANK then
hasFreeSlot = FindFirstEmptySlotInBag(BAG_SUBSCRIBER_BANK)
elseif inventorySlot.bagId == BAG_SUBSCRIBER_BANK then
hasFreeSlot = FindFirstEmptySlotInBag(BAG_BANK)
end
end
return hasFreeSlot
end
end
function ZO_InventorySlot_TrySplitStack(inventorySlot)
if GetCursorContentType() == MOUSE_CONTENT_EMPTY then
return ZO_StackSplit_SplitItem(inventorySlot)
end
end
do
local g_listDialog
function ZO_InventorySlot_GetItemListDialog()
if not g_listDialog then
local function SetupItemRow(rowControl, slotInfo)
local bag, index = slotInfo.bag, slotInfo.index
local icon, _, _, _, _, _, _, _, displayQuality = GetItemInfo(bag, index)
local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_ITEM_QUALITY_COLORS, displayQuality)
local nameControl = rowControl:GetNamedChild("Name")
nameControl:SetText(zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemName(bag, index)))
nameControl:SetColor(r, g, b, 1)
local inventorySlot = rowControl:GetNamedChild("Button")
ZO_Inventory_BindSlot(inventorySlot, SLOT_TYPE_LIST_DIALOG_ITEM, index, bag)
ZO_Inventory_SetupSlot(inventorySlot, slotInfo.stack, icon)
rowControl:GetNamedChild("Selected"):SetHidden(g_listDialog:GetSelectedItem() ~= slotInfo)
local statusTextureControl = rowControl:GetNamedChild("StatusTexture")
if IsItemInArmory(bag, index) then
statusTextureControl:SetTexture(ZO_IN_ARMORY_BUILD_ICON)
statusTextureControl:SetHidden(false)
else
statusTextureControl:SetHidden(true)
end
if g_listDialog:GetSelectedItem() then
g_listDialog:SetFirstButtonEnabled(true)
end
end
g_listDialog = ZO_ListDialog:New("ZO_ListDialogInventorySlot", 52, SetupItemRow)
end
g_listDialog:SetFirstButtonEnabled(false)
return g_listDialog
end
end
local function CanEnchantItem(inventorySlot)
if CanUseSecondaryActionOnSlot(inventorySlot) then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return IsItemEnchantable(bag, index)
end
end
local function TryEnchantItem(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local function DoEnchant()
SYSTEMS:GetObject("enchant"):BeginItemImprovement(bag, index)
end
if IsItemBoPAndTradeable(bag, index) then
ZO_Dialogs_ShowPlatformDialog("CONFIRM_MODIFY_TRADE_BOP", {onAcceptCallback = DoEnchant}, {mainTextParams={GetItemName(bag, index)}})
else
DoEnchant()
end
end
local function CanConvertToStyle(inventorySlot, toStyle)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
if CanUseSecondaryActionOnSlot(inventorySlot) and not IsItemPlayerLocked(bag, index) then
return CanConvertItemStyle(bag, index, toStyle)
end
end
local function IsSlotLocked(inventorySlot)
local slotData = ZO_Inventory_GetSlotDataForInventoryControl(inventorySlot)
if slotData then
return slotData.locked
end
end
local function CanChargeItem(inventorySlot)
if CanUseSecondaryActionOnSlot(inventorySlot) then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return IsItemChargeable(bag, index)
end
end
local function TryChargingItem(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local charges, maxCharges = GetChargeInfoForItem(bag, index)
if charges == maxCharges then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_SOULGEMITEMCHARGINGREASON", SOUL_GEM_ITEM_CHARGING_ALREADY_CHARGED))
else
SYSTEMS:GetObject("soulgem"):BeginItemImprovement(bag, index)
end
end
local function CanKitRepairItem(inventorySlot)
if CanUseSecondaryActionOnSlot(inventorySlot) then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return DoesItemHaveDurability(bag, index)
end
end
local function TryKitRepairItem(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local condition = GetItemCondition(bag, index)
if condition == 100 then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_ITEMREPAIRREASON", ITEM_REPAIR_ALREADY_REPAIRED))
else
SYSTEMS:GetObject("repair"):BeginItemImprovement(bag, index)
end
end
local function PlaceInventoryItem(inventorySlot)
local cursorType = GetCursorContentType()
if cursorType ~= MOUSE_CONTENT_EMPTY then
local sourceBag = GetCursorBagId()
local sourceSlot = GetCursorSlotIndex()
local destBag, destSlot = ZO_Inventory_GetBagAndIndex(inventorySlot)
ClearCursor()
if ZO_InventorySlot_WillItemBecomeBoundOnEquip(sourceBag, sourceSlot) then
local itemDisplayQuality = GetItemDisplayQuality(sourceBag, sourceSlot)
local itemQualityColor = GetItemQualityColor(itemDisplayQuality)
ZO_Dialogs_ShowPlatformDialog("CONFIRM_EQUIP_ITEM", { onAcceptCallback = function() RequestMoveItem(sourceBag, sourceSlot, destBag, destSlot) end }, { mainTextParams = { itemQualityColor:Colorize(GetItemName(sourceBag, sourceSlot)) } })
else
RequestMoveItem(sourceBag, sourceSlot, destBag, destSlot)
end
return true
end
end
function TryPlaceInventoryItemInEmptySlot(targetBag)
local emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
if not emptySlotIndex and IsESOPlusSubscriber() then
-- The player may be trying to split a stack. If they're transacting on the bank or
-- subscriber bank, then the other bag is also a valid target for the split item.
if targetBag == BAG_BANK then
targetBag = BAG_SUBSCRIBER_BANK
emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
elseif targetBag == BAG_SUBSCRIBER_BANK then
targetBag = BAG_BANK
emptySlotIndex = FindFirstEmptySlotInBag(targetBag)
end
end
if emptySlotIndex ~= nil then
PlaceInInventory(targetBag, emptySlotIndex)
else
local errorStringId = (targetBag == BAG_BACKPACK) and SI_INVENTORY_ERROR_INVENTORY_FULL or SI_INVENTORY_ERROR_BANK_FULL
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, errorStringId)
end
end
local function TryGuildBankDepositItem(sourceBag, sourceSlot)
local guildId = GetSelectedGuildBankId()
if guildId then
if not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_DEPOSIT) then
ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_DEPOSIT_PERMISSION)
return
end
if not DoesGuildHavePrivilege(guildId, GUILD_PRIVILEGE_BANK_DEPOSIT) then
ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_GUILD_TOO_SMALL)
return
end
if IsItemStolen(sourceBag, sourceSlot) then
ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_DEPOSIT_STOLEN_ITEM)
return
end
if GetNumBagFreeSlots(BAG_GUILDBANK) == 0 then
ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_SPACE_LEFT)
return
end
local soundCategory = GetItemSoundCategory(sourceBag, sourceSlot)
PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
TransferToGuildBank(sourceBag, sourceSlot)
end
ClearCursor()
end
local function TryGuildBankWithdrawItem(sourceSlotIndex)
local guildId = GetSelectedGuildBankId()
if guildId then
if not DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_BANK_WITHDRAW) then
ZO_AlertEvent(EVENT_GUILD_BANK_TRANSFER_ERROR, GUILD_BANK_NO_WITHDRAW_PERMISSION)
return
end
if not DoesBagHaveSpaceFor(BAG_BACKPACK, BAG_GUILDBANK, sourceSlotIndex) then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
return
end
local soundCategory = GetItemSoundCategory(BAG_GUILDBANK, sourceSlotIndex)
PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
TransferFromGuildBank(sourceSlotIndex)
end
ClearCursor()
end
function ZO_TryMoveToInventoryFromBagAndSlot(bag, slotIndex)
if DoesBagHaveSpaceFor(BAG_BACKPACK, bag, slotIndex) then
local transferDialog = SYSTEMS:GetObject("ItemTransferDialog")
transferDialog:StartTransfer(bag, slotIndex, BAG_BACKPACK)
else
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
end
ClearCursor()
end
local function TryMoveToInventory(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
ZO_TryMoveToInventoryFromBagAndSlot(bag, index)
end
local function PlaceInventoryItemInStorage(targetInventorySlot)
-- When moving your items between bags/slots there are special-cased rules
-- that need to apply...instead of using the landing area for the empty slot
-- and trying to swap/stack items each dropped item will only try to stack.
-- If it can't stack on what it was dropped on, then it will attempt to place itself in an empty slot.
-- Swapping is only allowed when dragging from backpack to an equip slot, never the other way around.
local targetType = ZO_InventorySlot_GetType(targetInventorySlot)
local targetBag, targetSlotIndex = ZO_Inventory_GetBagAndIndex(targetInventorySlot)
local targetItemId = GetItemInstanceId(targetBag, targetSlotIndex)
local sourceType = GetCursorContentType()
local sourceBag, sourceSlotIndex = GetCursorBagId(), GetCursorSlotIndex()
local sourceItemId = GetItemInstanceId(sourceBag, sourceSlotIndex)
-- Transferring from Craft Bag is going to be handled independently here because it has special needs
if sourceBag == BAG_VIRTUAL then
-- We can really only transfer from the Craft Bag to the BACKPACK and when we transfer
-- we want to prompt the option to choose a quantity (up to 200)
if sourceType == MOUSE_CONTENT_INVENTORY_ITEM then
if targetType == SLOT_TYPE_ITEM and targetBag == BAG_BACKPACK then
ZO_TryMoveToInventoryFromBagAndSlot(sourceBag, sourceSlotIndex)
return true
end
end
return false
elseif targetType == SLOT_TYPE_ITEM or targetType == SLOT_TYPE_BANK_ITEM then
if sourceType == MOUSE_CONTENT_EQUIPPED_ITEM then
TryPlaceInventoryItemInEmptySlot(targetBag)
return true
elseif sourceType == MOUSE_CONTENT_INVENTORY_ITEM then
-- if the items can stack, move the source to the clicked slot, otherwise try to move to an empty slot.
-- never swap!
if sourceBag == BAG_GUILDBANK then
TryGuildBankWithdrawItem(sourceSlotIndex)
return true
else
if sourceItemId == targetItemId then
PlaceInInventory(targetBag, targetSlotIndex)
return true
else
if sourceBag == targetBag then
ClearCursor()
else
TryPlaceInventoryItemInEmptySlot(targetBag)
end
return true
end
end
elseif sourceType == MOUSE_CONTENT_QUEST_ITEM then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_NO_QUEST_ITEMS_IN_BANK))
return false
end
elseif targetType == SLOT_TYPE_GUILD_BANK_ITEM then
if sourceType == MOUSE_CONTENT_QUEST_ITEM then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_NO_QUEST_ITEMS_IN_BANK))
return false
elseif sourceBag == BAG_GUILDBANK then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_INVENTORY_ERROR_CANNOT_STACK_GUILD_BANK))
ClearCursor()
return false
else
TryGuildBankDepositItem(sourceBag, sourceSlotIndex)
return true
end
end
-- No special behavior...
return PlaceInventoryItem(targetInventorySlot)
end
local function TryBankItem(inventorySlot)
if IsBankOpen() then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
if bag == BAG_BANK or bag == BAG_SUBSCRIBER_BANK or IsHouseBankBag(bag) then
--Withdraw
if DoesBagHaveSpaceFor(BAG_BACKPACK, bag, index) then
PickupInventoryItem(bag, index)
PlaceInTransfer()
else
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_INVENTORY_ERROR_INVENTORY_FULL)
end
else
--Deposit
if IsItemStolen(bag, index) then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, SI_STOLEN_ITEM_CANNOT_DEPOSIT_MESSAGE)
else
local bankingBag = GetBankingBag()
local canAlsoBePlacedInSubscriberBank = bankingBag == BAG_BANK
if DoesBagHaveSpaceFor(bankingBag, bag, index) or (canAlsoBePlacedInSubscriberBank and DoesBagHaveSpaceFor(BAG_SUBSCRIBER_BANK, bag, index)) then
PickupInventoryItem(bag, index)
PlaceInTransfer()
else
if canAlsoBePlacedInSubscriberBank and not IsESOPlusSubscriber() then
if GetNumBagUsedSlots(BAG_SUBSCRIBER_BANK) > 0 then
TriggerTutorial(TUTORIAL_TRIGGER_BANK_OVERFULL)
else
TriggerTutorial(TUTORIAL_TRIGGER_BANK_FULL_NO_ESO_PLUS)
end
end
ZO_AlertEvent(EVENT_BANK_IS_FULL)
end
end
end
return true
end
end
local function CanMoveToCraftBag(bagId, slotIndex)
return HasCraftBagAccess() and CanItemBeVirtual(bagId, slotIndex) and not IsItemStolen(bagId, slotIndex)
end
local function TryMoveToCraftBag(bagId, slotIndex)
local slotData = SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex)
if slotData then
if slotData.isGemmable then
ZO_Dialogs_ShowPlatformDialog("CONFIRM_STOW_GEMIFIABLE", { sourceBagId = bagId, sourceSlotIndex = slotIndex })
else
local transferDialog = SYSTEMS:GetObject("ItemTransferDialog")
transferDialog:StartTransfer(bagId, slotIndex, BAG_VIRTUAL)
return true
end
end
end
local function TryPreviewDyeStamp(inventorySlot)
-- get item info and pass it to the preview dye stamp view
-- there, the player can spin the model and confirm or deny using the stamp
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local itemLink = GetItemLink(bag, index)
local dyeStampId = GetItemLinkDyeStampId(itemLink)
local onUseType = GetItemLinkItemUseType(itemLink)
if onUseType == ITEM_USE_TYPE_ITEM_DYE_STAMP then
local dyeStampUseResult = CanPlayerUseItemDyeStamp(dyeStampId)
if dyeStampUseResult ~= DYE_STAMP_USE_RESULT_NONE then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_DYESTAMPUSERESULT", dyeStampUseResult))
return
end
elseif onUseType == ITEM_USE_TYPE_COSTUME_DYE_STAMP then
local dyeStampUseResult = CanPlayerUseCostumeDyeStamp(dyeStampId)
if dyeStampUseResult ~= DYE_STAMP_USE_RESULT_NONE then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString("SI_DYESTAMPUSERESULT", dyeStampUseResult))
return
end
end
SYSTEMS:GetObject("dyeStamp_Confirmation"):SetTargetItem(bag, index)
SYSTEMS:PushScene("dyeStampConfirmation")
end
local function TryPreviewItem(bag, slot)
SYSTEMS:GetObject("itemPreview"):PreviewInventoryItem(bag, slot)
if not IsInGamepadPreferredMode() then
INVENTORY_MENU_BAR:UpdateInventoryKeybinds()
end
end
-- If called on an item inventory slot, returns the index of the attachment slot that's holding it, or nil if it's not attached.
local function GetQueuedItemAttachmentSlotIndex(inventorySlot)
local bag, attachmentIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
if bag then
for i = 1, MAIL_MAX_ATTACHED_ITEMS do
local bagId, slotIndex = GetQueuedItemAttachmentInfo(i)
if bagId == bag and attachmentIndex == slotIndex then
return i
end
end
end
end
local function IsItemAlreadyAttachedToMail(inventorySlot)
local index = GetQueuedItemAttachmentSlotIndex(inventorySlot)
if index then
return GetQueuedItemAttachmentInfo(index) ~= 0
end
end
local function TryMailItem(inventorySlot)
if IsSendingMail() then
for i = 1, MAIL_MAX_ATTACHED_ITEMS do
local queuedFromBag = GetQueuedItemAttachmentInfo(i)
if queuedFromBag == 0 then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
local result = QueueItemAttachment(bag, index, i)
if result == MAIL_ATTACHMENT_RESULT_ALREADY_ATTACHED then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ALREADY_ATTACHED))
elseif result == MAIL_ATTACHMENT_RESULT_BOUND then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_BOUND))
elseif result == MAIL_ATTACHMENT_RESULT_ITEM_NOT_FOUND then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ITEM_NOT_FOUND))
elseif result == MAIL_ATTACHMENT_RESULT_LOCKED then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_LOCKED))
elseif result == MAIL_ATTACHMENT_RESULT_STOLEN then
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_STOLEN_ITEM_CANNOT_MAIL_MESSAGE))
else
UpdateMouseoverCommand(inventorySlot)
end
return true
end
end
ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, GetString(SI_MAIL_ATTACHMENTS_FULL))
return true
end
end
local function RemoveQueuedAttachment(inventorySlot)
local index = GetQueuedItemAttachmentSlotIndex(inventorySlot)
RemoveQueuedItemAttachment(index)
UpdateMouseoverCommand(inventorySlot)
end
local function CanTradeItem(inventorySlot)
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return TRADE_WINDOW:IsTrading() and not IsItemBound(bag, index)
end
local function IsItemAlreadyBeingTraded(inventorySlot)
if ZO_InventorySlot_GetType(inventorySlot) == SLOT_TYPE_MY_TRADE then
local _, _, stackCount = GetTradeItemInfo(TRADE_ME, ZO_Inventory_GetSlotIndex(inventorySlot))
if stackCount > 0 then
return true
end
else
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
return ZO_IsItemCurrentlyOfferedForTrade(bag, index)
end
return false
end
local function TryTradeItem(inventorySlot)
if TRADE_WINDOW:IsTrading() then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
TRADE_WINDOW:AddItemToTrade(bag, index)
return true
end
end
local function TryRemoveFromTrade(inventorySlot)
if TRADE_WINDOW:IsTrading() then
if ZO_InventorySlot_GetType(inventorySlot) == SLOT_TYPE_MY_TRADE then
local tradeIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
local bagId, slotId = GetTradeItemBagAndSlot(TRADE_ME, tradeIndex)
if bagId and slotId then
local soundCategory = GetItemSoundCategory(bagId, slotId)
PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
TradeRemoveItem(tradeIndex)
end
else
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
for i = 1, TRADE_NUM_SLOTS do
local bagId, slotIndex = GetTradeItemBagAndSlot(TRADE_ME, i)
if bagId and slotIndex and bagId == bag and slotIndex == index then
local soundCategory = GetItemSoundCategory(bagId, slotIndex)
PlayItemSound(soundCategory, ITEM_SOUND_ACTION_PICKUP)
TradeRemoveItem(i)
break
end
end
end
UpdateMouseoverCommand(inventorySlot)
end
end
-- To prevent double-click attempting to equip items when at a store, this should just return whether or not the player is shopping.
-- We always want to try to sell when the user does the "primary" action at a store so that they don't mistakenly equip a 0-cost
-- item which replaces their existing gear...and then when the user continues to hit "E" or double-clicks they end up selling gear
-- they don't want to.
local function CanSellItem(inventorySlot)
return ZO_Store_IsShopping() and not SYSTEMS:GetObject("fence"):IsLaundering()
end
local function CanLaunderItem(inventorySlot)
return ZO_Store_IsShopping() and SYSTEMS:GetObject("fence"):IsLaundering()
end
local function TrySellItem(inventorySlot)
local itemData = {}
if CanSellItem() then
itemData.stackCount = ZO_InventorySlot_GetStackCount(inventorySlot)
if itemData.stackCount > 0 then
itemData.bag, itemData.slot = ZO_Inventory_GetBagAndIndex(inventorySlot)
if IsItemStolen(itemData.bag, itemData.slot) then
local totalSells, sellsUsed = GetFenceSellTransactionInfo()
if sellsUsed == totalSells then
ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, GetString("SI_STOREFAILURE", STORE_FAILURE_AT_FENCE_LIMIT))
return
end
end
itemData.itemName = GetItemName(itemData.bag, itemData.slot)
itemData.functionalQuality = GetItemFunctionalQuality(itemData.bag, itemData.slot)
itemData.displayQuality = GetItemDisplayQuality(itemData.bag, itemData.slot)
-- itemData.quality is deprecated, included here for addon backwards compatibility
itemData.quality = itemData.functionalQuality
if SCENE_MANAGER:IsShowing("fence_keyboard") and itemData.functionalQuality >= ITEM_FUNCTIONAL_QUALITY_ARTIFACT then
ZO_Dialogs_ShowDialog("CANT_BUYBACK_FROM_FENCE", itemData)
elseif IsItemInArmory(itemData.bag, itemData.slot) then
local armoryBuildList = { GetItemArmoryBuildList(itemData.bag, itemData.slot) }
local buildListString = ZO_GenerateCommaSeparatedListWithAnd(armoryBuildList)
ZO_Dialogs_ShowDialog("CONFIRM_SELL_ARMORY_ITEM_PROMPT", itemData, { mainTextParams = { ZO_SELECTED_TEXT:Colorize(buildListString), #armoryBuildList }})
else
SellInventoryItem(itemData.bag, itemData.slot, itemData.stackCount)
end
return true
end
end
end
local function TryLaunderItem(inventorySlot)
local totalLaunders, laundersUsed = GetFenceLaunderTransactionInfo()
if laundersUsed == totalLaunders then
ZO_Alert(UI_ALERT_CATEGORY_ALERT, SOUNDS.NEGATIVE_CLICK, GetString("SI_ITEMLAUNDERRESULT", ITEM_LAUNDER_RESULT_AT_LIMIT))
return
end
if CanLaunderItem() then
local stackCount = ZO_InventorySlot_GetStackCount(inventorySlot)
if stackCount > 0 then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
LaunderItem(bag, index, stackCount)
return true
end
end
end
local function CanBuyMultiple(inventorySlot)
return not (inventorySlot.isCollectible or inventorySlot.isUnique)
end
local function CanEquipItem(inventorySlot)
if not IsSlotLocked(inventorySlot) then
local bag, index = ZO_Inventory_GetBagAndIndex(inventorySlot)
if bag ~= BAG_WORN and bag ~= BAG_COMPANION_WORN then