-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWritWorthy_Window.lua
More file actions
1735 lines (1575 loc) · 74.4 KB
/
WritWorthy_Window.lua
File metadata and controls
1735 lines (1575 loc) · 74.4 KB
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
-- WritWorthy UI window
--
-- Do NOT put tooltip or settings UI code here. Just the big list-of-writs
-- window.
local WritWorthy = _G['WritWorthy'] -- defined in WritWorthy_Define.lua
local WW = WritWorthy
WritWorthyInventoryList = ZO_SortFilterList:Subclass()
-- Inherits field "self.list" which is the scroll list control.
-- "WritWorthyInventoryList" is NOT the actual list control that has useful
-- "data members. Use WritWorthyInventoryList.singleton for that.
-- The header controls for each of our lists, recorded
-- during WritWorthyHeaderInit().
-- [column_name] = control
WritWorthyInventoryList.list_header_controls = {}
-- The master list of row data for the inventory list
-- in no particular order.
WritWorthyInventoryList.inventory_data_list = {}
-- Dolgubon's LibLazyCrafting, which maintains
-- a queue of "stuff to automatically craft next
-- time you're at a appropriate station." Often
-- called "LLC" for a shorter abbreviation.
--
-- version 0.3 has BS/CL/WW + Enchanting
-- version 0.4 has Alchemy and Provisioning.
-- version 1.2 has Alchemy and Provisioning,
-- released by Dolgubon in Writ/Set addons
-- had bugs that broke smithing and alchemy. DO NOT USE.
-- version 1.3 ZZ fixes to 1.2, works again
-- not released by Dolgubon."
WritWorthyInventoryList.LibLazyCrafting = nil
-- Live row_control used to lay out rows. Remembered
-- during SetupRowControl(). Used in
-- UpdateAllCellWidths().
WritWorthyInventoryList.row_control_list = {}
local Log = WritWorthy.Log
local Util = WritWorthy.Util
-- Inventory List UI, "row type".
--
-- We could choose to use different IDs for different types (consumables vs.
-- smithing) but that's more complexity than I want today. Sticking with
-- homogeneous data and a single data type. The list UI doesn't need to know or
-- care that some rows leave their cells blank because Provisioning writs lack
-- a "quality" field.
local TYPE_ID = 1
local CRAFTING_TYPE_JEWELRYCRAFTING = CRAFTING_TYPE_JEWELRYCRAFTING or 7
WritWorthyInventoryList.SORT_KEYS = {
["ui_type" ] = {tiebreaker="ui_voucher_ct"}
, ["ui_voucher_ct" ] = {tiebreaker="ui_detail1", isNumeric=true }
, ["ui_detail1" ] = {tiebreaker="ui_detail2"}
, ["ui_detail2" ] = {tiebreaker="ui_detail3"}
, ["ui_detail3" ] = {tiebreaker="ui_detail4"}
, ["ui_detail4" ] = {tiebreaker="ui_detail5"}
, ["ui_detail5" ] = {tiebreaker="ui_is_queued"}
, ["ui_is_queued" ] = {tiebreaker="ui_use_mimic"}
, ["ui_use_mimic" ] = {tiebreaker="ui_can_queue"}
-- Not visible columns, but still affect sort.
, ["ui_can_queue" ] = {}
, ["ui_station_sort"] = {tiebreaker="ui_voucher_ct"}
}
WritWorthyInventoryList.ROW_HEIGHT = 30
-- Values written to savedChariables
WritWorthyInventoryList.STATE_QUEUED = "queued"
WritWorthyInventoryList.STATE_COMPLETED = "completed"
WritWorthyInventoryList.COLOR_TEXT_CANNOT_QUEUE = "CC3333"
WritWorthyInventoryList.COLOR_TEXT_CAN_QUEUE = "CCCCCC"
WritWorthyInventoryList.COLOR_TEXT_QUEUED = "FFFFFF"
WritWorthyInventoryList.COLOR_TEXT_COMPLETED = "33AA33"
WritWorthyInventoryList.COLOR_TEXT_WW = "E0FF93"
WritWorthyInventoryList.COLOR_TEXT_CL = "A8E0FF"
WritWorthyInventoryList.COLOR_TEXT_BS = "FFCE93"
-- The XML name suffixes for each of our columns.
-- NOT used for UI display (although they often match).
-- Useful when iterating through columns/cells.
WritWorthyInventoryList.CELL_TYPE = "Type"
WritWorthyInventoryList.CELL_VOUCHERCT = "VoucherCt"
WritWorthyInventoryList.CELL_DETAIL1 = "Detail1"
WritWorthyInventoryList.CELL_DETAIL2 = "Detail2"
WritWorthyInventoryList.CELL_DETAIL3 = "Detail3"
WritWorthyInventoryList.CELL_DETAIL4 = "Detail4"
WritWorthyInventoryList.CELL_DETAIL5 = "Detail5"
WritWorthyInventoryList.CELL_ENQUEUE = "Enqueue"
WritWorthyInventoryList.CELL_MIMIC = "Mimic"
WritWorthyInventoryList.CELL_ENQUEUE_MASK = "EnqueueMask" -- not a cell on its own.
WritWorthyInventoryList.CELL_NAME_LIST = {
WritWorthyInventoryList.CELL_TYPE
, WritWorthyInventoryList.CELL_VOUCHERCT
, WritWorthyInventoryList.CELL_DETAIL1
, WritWorthyInventoryList.CELL_DETAIL2
, WritWorthyInventoryList.CELL_DETAIL3
, WritWorthyInventoryList.CELL_DETAIL4
, WritWorthyInventoryList.CELL_DETAIL5
, WritWorthyInventoryList.CELL_ENQUEUE
, WritWorthyInventoryList.CELL_MIMIC
}
-- Cells that are shown/hidden click buttons, not text data.
WritWorthyInventoryList.CELL_UNTEXT_LIST = {
[WritWorthyInventoryList.CELL_ENQUEUE] = true
, [WritWorthyInventoryList.CELL_MIMIC ] = true
}
-- WritWorthyUI: The window around the inventory list ------------------------
function WritWorthyUI_RestorePos()
Util.RestorePos(WritWorthyUI, "position")
end
function WritWorthyUI_SavePos() -- 2019-12-20 can dead code strip
Util.SavePos(WritWorthyUI, "position")
end
function WritWorthyUI_OnMoveStop()
Util.OnMoveStop(WritWorthyUI, "position")
end
function WritWorthyUI_OnResizeStop()
Util.OnResizeStop( WritWorthyUI
, WritWorthy.InventoryList
, WritWorthyInventoryList.singleton
, "position" )
end
function WritWorthyUI_ToggleUI()
local ui = WritWorthyUI
if not ui then
return
end
local h = WritWorthyUI:IsHidden()
if h then
WritWorthyUI_RestorePos()
local t = WritWorthyUIInventoryListTitle
if t then
local fmt = WW.Str("title_writ_inventory_player")
if WritWorthy.savedVariables.enable_banked_vouchers then
fmt = WW.Str("title_writ_inventory_player_bank")
end
local ss = string.format(fmt, GetUnitName("player"))
t:SetText(ss)
end
WritWorthyUI_Refresh()
WritWorthyInventoryList:UpdateAllCellWidths()
end
WritWorthyUI:SetHidden(not h)
end
-- Wrapper function called by "Refresh" shark arrow button.
function WritWorthyUI_RefreshUI()
Log.Debug("WritWorthyUI_RefreshUI")
WritWorthyUI_Refresh()
end
function WritWorthyUI_Refresh()
WritWorthy.RequiredSkill.ResetCache()
local list = WritWorthyInventoryList.singleton
list:BuildMasterlist()
list:Refresh()
list:UpdateSummaryAndQButtons()
end
-- Rather than waste CPU time re-calculating window display state
-- every time the user types a keystroke in a filter edit box,
-- queue up a request to update the entire UI soon, and then
-- only do so if the user has stopped typing.
function WritWorthyUI_RefreshSoon()
Util.CallSoon("refreshsoon_ms", WritWorthyUI_Refresh)
end
function WritWorthyUI_MaxGPV_TextChanged(new_text)
local new_max = tonumber(new_text)
if new_max == WritWorthy.savedVariables.filter_max_gold_per_voucher then
-- _TextChanged() called even if no change.
-- Causes infinite-loop due to _Refresh()'s call to
-- UpdateSummaryAndQButtons(), which unconditionally
-- writes to the MaxGPV edit field, which causes
-- _TextChanges() ...
-- Avoid infinite loop by returning here.
return
end
if new_max then
WritWorthy.savedVariables.filter_max_gold_per_voucher = new_max
else
WritWorthy.savedVariables.filter_max_gold_per_voucher = nil
end
WritWorthyUI_RefreshSoon()
end
-- Inventory List ------------------------------------------------------------
function WritWorthyInventoryList_HeaderInit(control, name, text, key)
local l10n_text = WW.Str("header_"..text) or text
ZO_SortHeader_Initialize( control -- control
, l10n_text -- name
, key or string.lower(text) -- key
, ZO_SORT_ORDER_DOWN -- initialDirection
, align or TEXT_ALIGN_LEFT -- alignment
, "ZoFontWinT1" -- font
, nil -- highlightTemplate
)
-- Remember this control!
--
-- The header cell control that we get here, and which
-- ZO_SortHeader_Initialize() fills in is NOT the same
-- as the XML template control reachable from
-- WritWorthyUIInventoryListHeaders:GetNamedChild().
-- We need this actual header cell control, which has
-- Text and alignment and live data, in addition to the
-- XML template control (which has dynamic width,
-- thanks to its two anchors).
WritWorthyInventoryList.list_header_controls[name] = control
WritWorthyInventoryList.HEADER_TOOLTIPS = {
[WritWorthyInventoryList.CELL_TYPE ] = WW.Str("header_tooltip_Type")
, [WritWorthyInventoryList.CELL_VOUCHERCT ] = WW.Str("header_tooltip_V")
, [WritWorthyInventoryList.CELL_DETAIL1 ] = WW.Str("header_tooltip_Detail1")
, [WritWorthyInventoryList.CELL_DETAIL2 ] = WW.Str("header_tooltip_Detail2")
, [WritWorthyInventoryList.CELL_DETAIL3 ] = WW.Str("header_tooltip_Detail3")
, [WritWorthyInventoryList.CELL_DETAIL4 ] = WW.Str("header_tooltip_Detail4")
, [WritWorthyInventoryList.CELL_DETAIL5 ] = WW.Str("header_tooltip_Detail5")
, [WritWorthyInventoryList.CELL_ENQUEUE ] = WW.Str("header_tooltip_Q")
, [WritWorthyInventoryList.CELL_MIMIC ] = WW.Str("header_tooltip_M")
}
local tooltip_text = WritWorthyInventoryList.HEADER_TOOLTIPS[name]
if tooltip_text then
ZO_SortHeader_SetTooltip(control, tooltip_text)
end
end
function WritWorthyInventoryList:New()
local o = ZO_SortFilterList.New(self, WritWorthyUIInventoryList)
WritWorthyInventoryList.singleton = o
return o
end
function WritWorthyInventoryList:Initialize(control)
self.InitUITypeStr()
ZO_SortFilterList.Initialize(self, control)
self.inventory_data_list = {}
self:SetEmptyText(WW.Str("status_list_empty_no_writs"))
-- Tell ZO_ScrollList how it can ask us to
-- create row controls.
ZO_ScrollList_AddDataType(
self.list -- scroll list control
, TYPE_ID -- row data type ID
, "WritWorthyInventoryListRow" -- template: virtual button defined in XML
, self.ROW_HEIGHT -- row height
-- setupCallback
, function(control, inventory_data)
self:SetupRowControl(control, inventory_data)
end
)
-- This call to ZO_ScrollList_EnableHighlight() seems
-- to do nothing. I have yet to get this working
-- correctly. Would be interesting to see row
-- highlighting during mouseover.
ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
-- How to order our table rows. Probably doesn't need
-- to be a specific data member with a specific name,
-- we just need to know how to find it and pass it to
-- table.sort() from within FilterScrollList() below.
self.sortFunction
= function(row_a, row_b)
return ZO_TableOrderingFunction( row_a.data
, row_b.data
, self.currentSortKey
, WritWorthyInventoryList.SORT_KEYS
, self.currentSortOrder
)
end
-- Set our initial sort key. Not sure this actually
-- works. And if it does, wouldn't it be polite to
-- save/restore the sort index in savedVariables?
--
-- After ZO_SortFilterList:Initialize() we have a
-- sortHeaderGroup. At least, that's how it works in
-- ScrollListExample.
self.sortHeaderGroup:SelectHeaderByKey("detail1")
ZO_SortHeader_OnMouseExit(WritWorthyUIInventoryListHeadersType)
self:RefreshData()
-- Create the summary grid at the bottom of the window.
local OFFSET_X = { 0, 72, 100, 400, 400+72, 400+100, 800 }
local OFFSET_Y = { 5, 30, 55, 80 }
local L = TEXT_ALIGN_LEFT -- for a LOT less typing
local R = TEXT_ALIGN_RIGHT
-- offsetX index into above table
-- offsetY index into above table
-- align
-- text
local GRID = { --
["SummaryQueuedWritCt" ] = { 1, 1, R, "" }
, ["SummaryQueuedVoucherCt" ] = { 1, 2, R, "" }
, ["SummaryQueuedMatCost" ] = { 1, 3, R, "" }
, ["SummaryQueuedVoucherCost" ] = { 1, 4, R, "" }
, ["SummaryQueuedWritCtUnit" ] = { 2, 1, L, "" }
, ["SummaryQueuedVoucherCtUnit" ] = { 2, 2, L, WW.Str("currency_suffix_voucher") }
, ["SummaryQueuedMatCostUnit" ] = { 2, 3, L, WW.Str("currency_suffix_gold") }
, ["SummaryQueuedVoucherCostUnit" ] = { 2, 4, L, WW.Str("currency_suffix_gold_per_voucher") }
, ["SummaryQueuedWritCtLabel" ] = { 3, 1, L, WW.Str("summary_queued_writ_ct") }
, ["SummaryQueuedVoucherCtLabel" ] = { 3, 2, L, WW.Str("summary_queued_voucher_ct") }
, ["SummaryQueuedMatCostLabel" ] = { 3, 3, L, WW.Str("summary_queued_mat_cost") }
, ["SummaryQueuedVoucherCostLabel" ] = { 3, 4, L, WW.Str("summary_queued_average_voucher_cost") }
, ["SummaryCompletedWritCt" ] = { 4, 1, R, "" }
, ["SummaryCompletedVoucherCt" ] = { 4, 2, R, "" }
, ["SummaryCompletedMatCost" ] = { 4, 3, R, "" }
, ["SummaryCompletedVoucherCost" ] = { 4, 4, R, "" }
, ["SummaryCompletedWritCtUnit" ] = { 5, 1, L, "" }
, ["SummaryCompletedVoucherCtUnit" ] = { 5, 2, L, WW.Str("currency_suffix_voucher") }
, ["SummaryCompletedMatCostUnit" ] = { 5, 3, L, WW.Str("currency_suffix_gold") }
, ["SummaryCompletedVoucherCostUnit" ] = { 5, 4, L, WW.Str("currency_suffix_gold_per_voucher") }
, ["SummaryCompletedWritCtLabel" ] = { 6, 1, L, WW.Str("summary_completed_writ_ct") }
, ["SummaryCompletedVoucherCtLabel" ] = { 6, 2, L, WW.Str("summary_completed_voucher_ct") }
, ["SummaryCompletedMatCostLabel" ] = { 6, 3, L, WW.Str("summary_completed_mat_cost") }
, ["SummaryCompletedVoucherCostLabel"] = { 6, 4, L, WW.Str("summary_completed_average_voucher_cost") }
}
for name, def in pairs(GRID) do
local offset_x = OFFSET_X[def[1]]
local offset_y = OFFSET_Y[def[2]]
local text_align = def[3]
local text = def[4]
local width = OFFSET_X[def[1]+1] - OFFSET_X[def[1]] - 2
-- local control = WritWorthyUI:GetNamedChild(name)
local control_name = "WritWorthyUI"..name
local control = WritWorthyUI:CreateControl(control_name, CT_LABEL)
control:SetHorizontalAlignment(text_align)
control:SetColor(255,255,255)
control:SetFont("ZoFontGame")
control:SetHeight(20)
control:SetWidth(width)
control:SetText(text)
control:ClearAnchors()
control:SetAnchor( TOPLEFT -- point
, WritWorthyUIInventoryList -- relativeTo
, BOTTOMLEFT -- relativePoint
, offset_x -- offsetX
, offset_y -- offsetY
)
end
end
-- Collect data that we'll eventually use to fill the inventory list UI.
-- Just data, no UI code here (that's FilterScrollList()'s job).
function WritWorthyInventoryList:BuildMasterlist()
self.inventory_data_list = WritWorthy:ScanInventoryForMasterWrits()
local u = {}
-- We need UI data before we can sort.
for _, inventory_data in pairs(self.inventory_data_list) do
self:PopulateUIFields(inventory_data)
u[inventory_data.unique_id] = inventory_data
end
self.inventory_data_by_unique_id = u
-- This seems as good a place as any to
-- make this once-a-day-or-so call.
-- Certainly do not want it once-per-init().
self:PurgeAncientSavedChariables()
end
-- Populate the ScrollList's rows, using our data model as a source.
function WritWorthyInventoryList:FilterScrollList()
local scroll_data = ZO_ScrollList_GetDataList(self.list)
ZO_ClearNumericallyIndexedTable(scroll_data)
for _, inventory_data in ipairs(self.inventory_data_list) do
table.insert( scroll_data
, ZO_ScrollList_CreateDataEntry(TYPE_ID, inventory_data))
end
end
function WritWorthyInventoryList:SortScrollList()
-- Original boilerplate SortScrollList() implementation that works
-- perfectly with the usual sortFunction
--
local scroll_data = ZO_ScrollList_GetDataList(self.list)
table.sort(scroll_data, self.sortFunction)
end
function WritWorthyInventoryList:Refresh()
Log:Add("WritWorthyInventoryList:Refresh")
self:RefreshData()
end
function WritWorthyInventoryList_Cell_OnMouseEnter(cell_control)
-- .tooltip_text is our own field, not ZOS'.
-- We set it in PopulateUIFields() with our
-- own "reasons why you cannot queue this row"
-- text (same red text that WritWorthy stuffs
-- into sealed writ tooltips).
if cell_control.tooltip_text then
ZO_Tooltips_ShowTextTooltip(
cell_control
, TOP
, cell_control.tooltip_text)
end
end
function WritWorthyInventoryList_Cell_OnMouseExit(cell_control)
ZO_Tooltips_HideTextTooltip()
end
function WritWorthyInventoryList_Cell_OnMouseDown(cell_control)
if not ( cell_control
and cell_control.inventory_data
and cell_control.inventory_data.item_link) then
return
end
-- Inject this item's unique_id so that our
-- WritWorthy.TooltipInsertOurText() code will see
-- it and display "Queued for crafting". Otherwise
-- an itemLink alone is insufficient to uniquely
-- identify a Sealed Master Writ within our inventory.
PopupTooltip.WritWorthy_UniqueId = cell_control.inventory_data.unique_id
ZO_PopupTooltip_SetLink(cell_control.inventory_data.item_link)
PopupTooltip.WritWorthy_UniqueId = nil
end
-- First time through a row's SetupRowControl(), programmatically create the
-- individual label controls that will hold cell text. Doing so
-- programmatically here is less maintenance work than trying to keep the XML
-- "virtual" row in sync with the XML headers.
--
-- Do not fill labels with live text: that's SetupRowControl()'s job.
function WritWorthyInventoryList:CreateRowControlCells(row_control, header_control)
for i, cell_name in ipairs(self.CELL_NAME_LIST) do
local header_cell_control = header_control:GetNamedChild(cell_name)
local control_name = row_control:GetName() .. cell_name
local cell_control = nil
local is_text = true
local rel_to_left = header_control:GetLeft()
if self.CELL_UNTEXT_LIST[cell_name] then
-- Non-text cells (aka the "Enqueue" checkbox button
-- are not created programmatically, they are already
-- created for us via XML. Find and use the existing
-- control.
cell_control = row_control:GetNamedChild(cell_name)
is_text = false
else
-- Text cells are programmatically created here, not
-- created by XML. Create now.
cell_control = row_control:CreateControl(control_name, CT_LABEL)
end
row_control[cell_name] = cell_control
local y_offset = 0
if is_text then y_offset = 3 end
Util.SetAnchorCellLeft( row_control
, cell_control
, header_cell_control
, i == 1
, y_offset
, rel_to_left )
cell_control:SetHidden(false)
if not is_text then
-- Lock our "Enqueue" checkbox to 20x20
cell_control:SetWidth(20)
cell_control:SetHeight(20)
else
cell_control:SetWidth(header_cell_control:GetWidth())
cell_control:SetHeight(self.ROW_HEIGHT - y_offset)
cell_control:SetFont("ZoFontGame")
cell_control:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
Util.SetCellToHeaderAlign( row_control
, header_control
, self.list_header_controls[cell_name] )
-- Click to toggle item tooltip for row's
-- Sealed Master Writ.
cell_control:SetMouseEnabled(true)
cell_control:SetHandler("OnMouseDown", WritWorthyInventoryList_Cell_OnMouseDown)
end
end
local cb = row_control:GetNamedChild(self.CELL_MIMIC)
if cb then
ZO_CheckButton_SetToggleFunction(cb, function(checkbox, is_checked)
WritWorthyInventoryList_MimicToggled(checkbox, is_checked)
end)
end
cb = row_control:GetNamedChild(self.CELL_ENQUEUE)
if cb then
ZO_CheckButton_SetToggleFunction(cb, function(checkbox, is_checked)
WritWorthyInventoryList_EnqueueToggled(checkbox, is_checked)
end)
end
cb:SetHandler("OnMouseEnter", WritWorthyInventoryList_Cell_OnMouseEnter)
cb:SetHandler("OnMouseExit", WritWorthyInventoryList_Cell_OnMouseExit)
-- Not a cell control, but a mask that floats above
-- one. Hook that up for fast access and tooltips.
local mask_control = row_control:GetNamedChild(self.CELL_ENQUEUE_MASK)
row_control[self.CELL_ENQUEUE_MASK] = mask_control
mask_control:SetHidden(false)
mask_control:SetHandler("OnMouseEnter", WritWorthyInventoryList_Cell_OnMouseEnter)
mask_control:SetHandler("OnMouseExit", WritWorthyInventoryList_Cell_OnMouseExit)
end
-- After a resize, widen our "detail1" column and nudge the others to its right.
function WritWorthyInventoryList:UpdateAllCellWidths()
for _, row_control in ipairs(self.row_control_list) do
self:UpdateColumnWidths(row_control)
end
end
-- Change column width/offsets after a window resize. NOP if nothing changed.
function WritWorthyInventoryList:UpdateColumnWidths(row_control)
-- Do nothing if we have not yet fully initialized.
local hc = WritWorthyUIInventoryListHeadersType
if not hc then return end
local rel_to_left = WritWorthyUIInventoryListHeaders:GetLeft()
-- Cache header cell controls from which we'll
-- gather column widths. We want the GetNamedChild()
-- controls (they have anchors and dynamic width)
-- not the ZO_SortHeader_Initialize() controls
-- (which appear to never change widths).
local hcl = {}
for cell_name, _ in pairs(self.list_header_controls) do
hcl[cell_name] = WritWorthyUIInventoryListHeaders:GetNamedChild(cell_name)
end
for cell_name, _ in pairs(self.list_header_controls) do
local cell_control = row_control:GetNamedChild(cell_name)
local header_cell_control = hcl[cell_name]
if header_cell_control then
local offsetX = header_cell_control:GetLeft() - rel_to_left
-- 1 bool isValidAnchor
-- 2 integer point
-- 3 object relativeTo
-- 4 integer relativePoint
-- 5 number offsetX
-- 6 number offsetY
-- 7 AnchorConstrains anchorConstrains
local a = { cell_control:GetAnchor(0) }
if a and a[1] then
cell_control:SetAnchor( LEFT -- point
, row_control -- relativeTo
, LEFT -- relativePoint
, offsetX -- offsetX
, a[6] ) -- offsetY
end
-- Resize text cells, but leave button cells locked
-- to whatever CreateRowControlCells() chose.
local is_text = not WritWorthyInventoryList.CELL_UNTEXT_LIST[cell_name]
if is_text then
cell_control:SetWidth(header_cell_control:GetWidth())
end
end
end
Util.StretchBGWidth(row_control)
end
-- Abbreviate strings so that they fit in narrow columns.
-- Increase data display density.
--
-- Also applies purple/gold color to epic/legendary
--
function WritWorthyInventoryList.Shorten(text)
if not text then return "" end
local s = WritWorthy.Shorten(text)
if s then return s end
return text
end
function WritWorthyInventoryList:IsQueued(inventory_data)
local LLC = WritWorthyInventoryList:GetLLC()
local x = LLC:findItemByReference(inventory_data.unique_id)
if 0 < #x then
return true
end
return false
end
function WritWorthyInventoryList:IsUseMimic(inventory_data)
if not ( inventory_data
and inventory_data.unique_id
and WritWorthy.savedChariables
and WritWorthy.savedChariables.writ_unique_id
and WritWorthy.savedChariables.writ_unique_id[inventory_data.unique_id]
) then
return false
end
return WritWorthy.savedChariables.writ_unique_id[inventory_data.unique_id].use_mimic
end
function WritWorthyInventoryList:IsCompleted(inventory_data)
if not ( inventory_data
and inventory_data.unique_id
and WritWorthy.savedChariables
and WritWorthy.savedChariables.writ_unique_id
and WritWorthy.savedChariables.writ_unique_id[inventory_data.unique_id]
) then
return false
end
return WritWorthy.savedChariables.writ_unique_id[inventory_data.unique_id].state
== WritWorthyInventoryList.STATE_COMPLETED
end
-- Can this row be queued in LibLazyCrafting?
--
-- If so, return true, "". If not, return false, "why not". "Why not" here is
-- often the same red text that WritWorthy inserts into the sealed master
-- writ's tooltip.
function WritWorthyInventoryList:CanQueue(inventory_data)
if self:IsCompleted(inventory_data) then
return false, "completed"
end
if not inventory_data.llc_func then
return false, "WritWorthy bug: Missing LLC data"
end
if inventory_data.parser.request_item
and inventory_data.parser.request_item.school
and inventory_data.parser.request_item.school.autocraft_not_implemented then
return false, "WritWorthy not yet implemented: jewelry crafting."
end
-- Is it below the maximum allowed cost per voucher?
local voucher_ct = WritWorthy.ToVoucherCount(inventory_data.item_link)
local mat_list = inventory_data.parser:ToMatList()
local mat_gold = WritWorthy.MatRow.ListTotal(mat_list) or 0
local max_gpv = WritWorthy.savedVariables.filter_max_gold_per_voucher
if max_gpv then
if max_gpv <= mat_gold/voucher_ct then
local msg = string.format("> %d gold per voucher", max_gpv)
return false, msg
end
end
-- Does this character have the required knowledge?
local text_list = {}
if inventory_data.parser.ToKnowList then
for _, know in ipairs(inventory_data.parser:ToKnowList()) do
if not know.is_known then
table.insert(text_list, know:TooltipText())
end
end
end
if 0 < #text_list then
return false, table.concat(text_list, "\n")
end
return true, ""
end
-- Can the user choose to use a Crown Mimic Stone on this writ?
--
-- Must be BS/CL/WW.
-- Must not yet be completed.
function WritWorthyInventoryList:CanMimic(inventory_data)
if self:IsCompleted(inventory_data) then
return false, "completed"
end
if inventory_data.parser
and inventory_data.parser.request_item
and inventory_data.parser.request_item.school
and inventory_data.parser.request_item.school.motif_required then
return true, ""
else
return false, "motif not required"
end
end
-- Thank you, Manavortex!
-- Cache these, because with inline == the string will be created just to compare
-- it each time the fn runs
local UI_TYPE_WOOD = nil -- GetString(SI_ITEMFILTERTYPE15)
local UI_TYPE_HEAVY = nil -- GetString(SI_ARMORTYPE3)
local UI_TYPE_MEDIUM = nil -- GetString(SI_ARMORTYPE2)
local UI_TYPE_LIGHT = nil -- GetString(SI_ARMORTYPE1)
local UI_TYPE_JEWELRY = nil -- GetString(SI_ITEMFILTERTYPE25)
local UI_TYPE_ALCHEMY = nil -- GetString(SI_ITEMFILTERTYPE16)
local UI_TYPE_ENCHANTING = nil -- GetString(SI_ITEMFILTERTYPE17)
local UI_TYPE_PROVISIONING = nil -- GetString(SI_ITEMFILTERTYPE18)
function WritWorthyInventoryList.InitUITypeStr()
if UI_TYPE_WOOD then return end
UI_TYPE_WOOD = WritWorthy.SI("SI_ITEMFILTERTYPE15" )
UI_TYPE_HEAVY = WritWorthy.SI("SI_ARMORTYPE3" )
UI_TYPE_MEDIUM = WritWorthy.SI("SI_ARMORTYPE2" )
UI_TYPE_LIGHT = WritWorthy.SI("SI_ARMORTYPE1" )
UI_TYPE_JEWELRY = WritWorthy.SI("SI_ITEMFILTERTYPE25" )
UI_TYPE_ALCHEMY = WritWorthy.SI("SI_ITEMFILTERTYPE16" )
UI_TYPE_ENCHANTING = WritWorthy.SI("SI_ITEMFILTERTYPE17" )
UI_TYPE_PROVISIONING = WritWorthy.SI("SI_ITEMFILTERTYPE18" )
end
-- Fill in all inventory_data.ui_xxx fields.
-- Here is where our data gets translated into user-visible text.
function WritWorthyInventoryList:PopulateUIFields(inventory_data)
inventory_data.ui_voucher_ct = WritWorthy.ToVoucherCount(inventory_data.item_link)
inventory_data.ui_is_queued = self:IsQueued(inventory_data)
inventory_data.ui_is_completed = self:IsCompleted(inventory_data)
local can, why_not = self:CanQueue(inventory_data)
inventory_data.ui_can_queue = can
if can then
inventory_data.ui_can_queue_tooltip = nil
else
inventory_data.ui_can_queue_tooltip = why_not
end
can, why_not = self:CanMimic(inventory_data)
inventory_data.ui_can_mimic = can
if can then
inventory_data.ui_use_mimic = self:IsUseMimic(inventory_data)
else
inventory_data.ui_use_mimic = false
end
-- For less typing.
local parser = inventory_data.parser
if parser.class == WritWorthy.Smithing.Parser.class then
local ri = parser.request_item -- For less typing.
if ri.school == WritWorthy.Smithing.SCHOOL_WOOD then
inventory_data.ui_type = UI_TYPE_WOOD
elseif ri.school == WritWorthy.Smithing.SCHOOL_JEWELRY then
inventory_data.ui_type = UI_TYPE_JEWELRY
else
inventory_data.ui_type = ri.school.armor_weight_name
end
inventory_data.ui_detail1 = parser.set_bonus.name
inventory_data.ui_detail2 = ri.item_name
inventory_data.ui_detail3 = (parser.motif and parser.motif.motif_name) or ""
inventory_data.ui_detail4 = WritWorthy.SI("SI_ITEMTRAITTYPE"..tostring(parser.trait_num)) -- or ri.trait_set[parser.trait_num].trait_name
inventory_data.ui_detail5 = parser.improve_level.name
elseif parser.class == WritWorthy.Alchemy.Parser.class then
inventory_data.ui_type = UI_TYPE_ALCHEMY
local mat_list = parser:ToMatList()
inventory_data.ui_detail1 = mat_list[1].name
inventory_data.ui_detail2 = mat_list[2].name
inventory_data.ui_detail3 = mat_list[3].name
inventory_data.ui_detail4 = mat_list[4].name
elseif parser.class == WritWorthy.Enchanting.Parser.class then
inventory_data.ui_type = UI_TYPE_ENCHANTING
if parser.level == 150 then
inventory_data.ui_detail1 = WW.Str("enchanting_cp150")
else
inventory_data.ui_detail1 = WW.Str("enchanting_cp160")
end
inventory_data.ui_detail2 = WW.Str(parser.glyph.name)
if parser.quality_num == 4 then
inventory_data.ui_detail5 = "|c973dd8"..WritWorthy.SI("SI_ITEMQUALITY4").."|r"
else
inventory_data.ui_detail5 = "|ce6c859"..WritWorthy.SI("SI_ITEMQUALITY5").."|r"
end
elseif parser.class == WritWorthy.Provisioning.Parser.class then
inventory_data.ui_type = UI_TYPE_PROVISIONING
inventory_data.ui_detail1 = parser.recipe.fooddrink_name
end
-- Since the point of these UI fields is to drive the
-- UI, we might as well shorten them here, once, rather
-- than over and over again later during display and
-- sort.
--
-- Shorten() also converts empty/nil to "" for safer
-- use later.
--
-- leave ui_voucher_ct as an integer for better sorting.
inventory_data.ui_type = self.Shorten(inventory_data.ui_type )
inventory_data.ui_detail1 = self.Shorten(inventory_data.ui_detail1 )
inventory_data.ui_detail2 = self.Shorten(inventory_data.ui_detail2 )
inventory_data.ui_detail3 = self.Shorten(inventory_data.ui_detail3 )
inventory_data.ui_detail4 = self.Shorten(inventory_data.ui_detail4 )
inventory_data.ui_detail5 = self.Shorten(inventory_data.ui_detail5 )
-- "Sort by station" key. Consumables to the front,
-- then set bonus sites.
if parser.class == WritWorthy.Alchemy.Parser.class then
inventory_data.ui_station_sort = "01 alchemy"
elseif parser.class == WritWorthy.Enchanting.Parser.class then
inventory_data.ui_station_sort = "02 enchanting"
elseif parser.class == WritWorthy.Provisioning.Parser.class then
inventory_data.ui_station_sort = "03 provisioning"
elseif parser.class == WritWorthy.Smithing.Parser.class then
local set_name = inventory_data.ui_detail1
local crafting_type = parser.request_item.school.trade_skill_type
local t = string.format( "04 %s %02d"
, set_name
, crafting_type
)
inventory_data.ui_station_sort = t
end
end
function WritWorthyInventoryList_MimicToggled(cell_control, checked)
Log:StartNewEvent()
Log:Add("WritWorthyInventoryList_MimicToggled() checked:"..tostring(checked)
.." unique_id:"..tostring(cell_control.inventory_data.unique_id))
local unique_id = cell_control.inventory_data.unique_id
WritWorthyInventoryList.SaveChariableMimic(unique_id, checked)
local self = WritWorthyInventoryList.singleton
self:Requeue(cell_control.inventory_data)
Log:EndEvent()
end
-- Toggling mimic stone setting for a queued item means we need to
-- tell LLC about the change.
function WritWorthyInventoryList:Requeue(inventory_data)
if not self:IsQueued(inventory_data) then return end
self:Dequeue(inventory_data)
self:Enqueue(inventory_data)
end
-- Called by ZOS code after user clicks in any of our "Enqueue" checkboxes.
function WritWorthyInventoryList_EnqueueToggled(cell_control, checked)
Log:StartNewEvent()
Log:Add("WritWorthyInventoryList_EnqueueToggled() checked:"..tostring(checked)
.." unique_id:"..tostring(cell_control.inventory_data.unique_id))
self = WritWorthyInventoryList.singleton
if checked then
self:Enqueue(cell_control.inventory_data)
else
self:Dequeue(cell_control.inventory_data)
end
-- self.LogLLCQueue(WritWorthyInventoryList:GetLLC().personalQueue)
self:UpdateUISoon(cell_control.inventory_data)
end
-- Called by ZOS code after user clicks "Enqueue All"
function WritWorthyInventoryList_EnqueueAll()
Log:StartNewEvent()
self = WritWorthyInventoryList.singleton
self:EnqueueAll()
self:Refresh()
self:UpdateSummaryAndQButtons()
end
-- Called by ZOS code after user clicks "Dequeue All"
function WritWorthyInventoryList_DequeueAll()
Log:StartNewEvent()
self = WritWorthyInventoryList.singleton
self:DequeueAll()
self:Refresh()
self:UpdateSummaryAndQButtons()
end
-- No longer used, but boy howdy this was a fun way to get the skill IDs for
-- all the crafting passives I'm interested in.
local function DumpSkills()
Log:StartNewEvent()
local num_types = GetNumSkillTypes()
Log:Add("num_types:"..tostring(num_types))
for skill_type = 1, num_types do
local num_lines = GetNumSkillLines(skill_type)
Log:Add("t:"..tostring(skill_type).." num_lines:"..tostring(num_lines))
for skill_index = 1, num_lines do
local num_abilities = GetNumSkillAbilities(skill_type, skill_index)
Log:Add("t:"..tostring(skill_type).." i:"..tostring(skill_index)
.." num_abilities:"..tostring(num_abilities))
for ability_index = 1, num_abilities do
local info = { GetSkillAbilityInfo(skill_type, skill_index, ability_index) }
local id = GetSkillAbilityId(skill_type, skill_index, ability_index, false)
Log:Add("t i a:"..tostring(skill_type).." "..tostring(skill_index)
.." "..tostring(ability_index)
.." id:"..tostring(id)
.." name:"..tostring(info[1])
.." tex:" ..tostring(info[2])
.." earnedRank:"..tostring(info[3])
.." passive:"..tostring(info[4])
.." ultimate:"..tostring(info[5])
.." purchased:"..tostring(info[6])
.." progression:"..tostring(info[7])
)
end
end
end
end
-- Called by ZOS code after user clicks "Sort by Station"
function WritWorthyInventoryList_SortByStation()
Log:StartNewEvent()
Log:Add("SortByStation")
self = WritWorthyInventoryList.singleton
self.currentSortKey = "ui_station_sort"
self.currentSortOrder = ZO_SORT_ORDER_UP
self:RefreshData()
end
-- ZO_ScrollFilterList will instantiate (or reuse!) a
-- WritWorthyInventoryListRow row_control to display some inventory_data. But
-- it's our job to fill in that control's nested labels with the appropriate
-- bits of data.
--
-- Called as self.setupCallback from ZO_ScrollList_Commit()
--
-- inventory_data is the instance passed to ZO_ScrollList_CreateDataEntry() by
-- FilterScrollList(), is an element of master list
-- WritWorthy.inventory_data_list.
function WritWorthyInventoryList:SetupRowControl(row_control, inventory_data)
-- Log:Add("SetupRowControl row_control:"..tostring(row_control)
-- .." inventory_data.unique_id:"..tostring(inventory_data.unique_id))
row_control.inventory_data = inventory_data
-- ZO_SortList reuses row_control instances, so there
-- is a good chance we've already created these cell
-- controls.
local already_created = row_control[self.CELL_TYPE]
if not already_created then
local header_control = WritWorthyUIInventoryListHeaders
self:CreateRowControlCells(row_control, header_control)
-- Retain pointers to our row_control instances so that
-- we can update all their cell widths later upon
-- window resize.
table.insert(self.row_control_list, row_control)
end
-- Refresh mutable state (aka queued/completed)
self:PopulateUIFields(inventory_data)
-- For less typing.
local rc = row_control
local i_d = inventory_data
-- Apply text color to entire row.
local fn = Util.color
local c = self.COLOR_TEXT_CAN_QUEUE
local c2 = nil
if inventory_data.ui_is_completed then
c = self.COLOR_TEXT_COMPLETED
elseif not inventory_data.ui_can_queue then
c = self.COLOR_TEXT_CANNOT_QUEUE
elseif inventory_data.ui_is_queued then
c = self.COLOR_TEXT_QUEUED
-- Manavortex supplied station-specific colors.
if WritWorthy.savedVariables.enable_station_colors then
if i_d.ui_type == UI_TYPE_WOOD then
c2 = self.COLOR_TEXT_WW
elseif (i_d.ui_type == UI_TYPE_LIGHT) or (i_d.ui_type == UI_TYPE_MEDIUM) then
c2 = self.COLOR_TEXT_CL
elseif i_d.ui_type == UI_TYPE_HEAVY then
c2 = self.COLOR_TEXT_BS
end
end
end
if not c2 then c2 = c end
-- Allow each cell's OnMouseDown handler easy
-- access to this row's data.
for _, name in ipairs(self.CELL_NAME_LIST) do
rc[name].inventory_data = i_d
end
-- Fill in the cells with data for this row.
rc[self.CELL_TYPE ]:SetText(fn(c2, i_d.ui_type))
rc[self.CELL_VOUCHERCT]:SetText(fn(c , tostring(i_d.ui_voucher_ct)))
rc[self.CELL_DETAIL1 ]:SetText(fn(c2, i_d.ui_detail1))
rc[self.CELL_DETAIL2 ]:SetText(fn(c , i_d.ui_detail2))
rc[self.CELL_DETAIL3 ]:SetText(fn(c , i_d.ui_detail3))
rc[self.CELL_DETAIL4 ]:SetText(fn(c , i_d.ui_detail4))
rc[self.CELL_DETAIL5 ]:SetText(fn(c , i_d.ui_detail5))
local bm = rc[self.CELL_MIMIC]
bm.inventory_data = inventory_data
bm:SetHidden(not i_d.ui_can_mimic)
if i_d.ui_can_mimic then
ZO_CheckButton_SetCheckState(bm, i_d.ui_use_mimic)
end
-- The "Enqueue" checkbox and its mask that makes it
-- look dimmed out when we cannot enqueue this row
-- due to lack of knowledge or WritWorthy code:
--
-- The mask does a lot for us:
-- 1. dims the checkbox
-- 2. intercepts mouse events
-- 3. provides tooltips
-- So there's no need to disable or hide the checkbox.
--
local b = rc[self.CELL_ENQUEUE ]