initial commit

This commit is contained in:
Gitea
2020-11-13 14:13:12 -05:00
commit 05df49ff60
368 changed files with 128754 additions and 0 deletions

526
Core/UI/VendoringUI/Buy.lua Normal file
View File

@@ -0,0 +1,526 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Buy = TSM.UI.VendoringUI:NewPackage("Buy")
local L = TSM.Include("Locale").GetTable()
local Money = TSM.Include("Util.Money")
local String = TSM.Include("Util.String")
local Log = TSM.Include("Util.Log")
local TempTable = TSM.Include("Util.TempTable")
local Theme = TSM.Include("Util.Theme")
local ItemString = TSM.Include("Util.ItemString")
local ItemInfo = TSM.Include("Service.ItemInfo")
local Settings = TSM.Include("Service.Settings")
local UIElements = TSM.Include("UI.UIElements")
local private = {
settings = nil,
query = nil,
filterText = "",
}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Buy.OnInitialize()
private.settings = Settings.NewView()
:AddKey("global", "vendoringUIContext", "buyScrollingTable")
TSM.UI.VendoringUI.RegisterTopLevelPage(L["Buy"], private.GetFrame)
end
function Buy.UpdateCurrency(frame)
if not GetMerchantCurrencies() or frame:GetSelectedNavButton() ~= L["Buy"] then
return
end
frame:GetElement("content.buy.footer.altCost")
:SetText(private.GetCurrencyText())
frame:GetElement("content.buy.footer")
:Draw()
end
-- ============================================================================
-- Buy UI
-- ============================================================================
function private.GetFrame()
TSM.UI.AnalyticsRecordPathChange("vendoring", "buy")
private.filterText = ""
if not private.query then
private.query = TSM.Vendoring.Buy.CreateMerchantQuery()
:InnerJoin(ItemInfo.GetDBForJoin(), "itemString")
end
private.query:ResetFilters()
private.query:NotEqual("numAvailable", 0)
private.query:ResetOrderBy()
private.query:OrderBy("name", true)
local altCost = not TSM.IsWowClassic() and GetMerchantCurrencies()
local frame = UIElements.New("Frame", "buy")
:SetLayout("VERTICAL")
:AddChild(UIElements.New("Frame", "filters")
:SetLayout("HORIZONTAL")
:SetHeight(40)
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Input", "searchInput")
:SetMargin(0, 8, 0, 0)
:SetIconTexture("iconPack.18x18/Search")
:SetClearButtonEnabled(true)
:AllowItemInsert()
:SetHintText(L["Search Vendor"])
:SetScript("OnValueChanged", private.InputOnValueChanged)
)
:AddChild(UIElements.New("Button", "filterBtn")
:SetWidth("AUTO")
:SetMargin(0, 4, 0, 0)
:SetFont("BODY_BODY3_MEDIUM")
:SetText(FILTERS)
-- TODO
-- :SetScript("OnClick", private.FilterButtonOnClick)
)
:AddChild(UIElements.New("Button", "filterBtnIcon")
:SetBackgroundAndSize("iconPack.14x14/Filter")
-- TODO
-- :SetScript("OnClick", private.FilterButtonOnClick)
)
)
:AddChild(UIElements.New("QueryScrollingTable", "items")
:SetSettingsContext(private.settings, "buyScrollingTable")
:GetScrollingTableInfo()
:NewColumn("qty")
:SetTitle(L["Qty"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("stackSize")
:SetSortInfo("stackSize")
:Commit()
:NewColumn("item")
:SetTitle(L["Item"])
:SetIconSize(12)
:SetFont("ITEM_BODY3")
:SetJustifyH("LEFT")
:SetTextInfo(nil, private.GetItemText)
:SetIconInfo("itemString", ItemInfo.GetTexture)
:SetTooltipInfo("itemString")
:SetSortInfo("name")
:SetTooltipLinkingDisabled(true)
:DisableHiding()
:Commit()
:NewColumn("ilvl")
:SetTitle(L["ilvl"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("itemString", ItemInfo.GetItemLevel)
:Commit()
:NewColumn("cost")
:SetTitle(L["Cost"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo(nil, private.GetCostText)
:SetTooltipInfo("firstCostItemString", private.GetCostTooltip)
:SetSortInfo("price")
:SetTooltipLinkingDisabled(true)
:Commit()
:SetCursor("BUY_CURSOR")
:Commit()
:SetQuery(private.query)
:SetScript("OnRowClick", private.RowOnClick)
)
:AddChild(UIElements.New("Texture", "line")
:SetHeight(2)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("Frame", "footer")
:SetLayout("HORIZONTAL")
:SetHeight(40)
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Frame", "gold")
:SetLayout("HORIZONTAL")
:SetWidth(166)
:SetMargin(0, 8, 0, 0)
:SetPadding(4)
:AddChild(UIElements.New("PlayerGoldText", "text"))
)
:AddChild(UIElements.New("Texture", "line")
:SetSize(2, 22)
:SetMargin(0, 8, 0, 0)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("Button", "altCost")
:SetWidth("AUTO")
:SetMargin(0, 16, 0, 0)
:SetFont("TABLE_TABLE1")
:SetText(private.GetCurrencyText())
:SetTooltip(altCost and "currency:"..altCost or nil)
)
:AddChild(UIElements.New("ActionButton", "repairBtn")
:SetDisabled(not TSM.Vendoring.Buy.NeedsRepair())
:SetText(L["Repair"])
:SetModifierText(L["Repair from Guild Bank"], "ALT")
:SetTooltip(private.GetRepairTooltip)
:SetScript("OnClick", private.RepairOnClick)
)
)
if not altCost then
frame:GetElement("footer.line")
:Hide()
frame:GetElement("footer.altCost")
:Hide()
end
return frame
end
function private.GetItemText(row)
local itemString, numAvailable = row:GetFields("itemString", "numAvailable")
local itemName = TSM.UI.GetColoredItemName(itemString) or "?"
if numAvailable == -1 then
return itemName
elseif numAvailable > 0 then
return itemName..Theme.GetFeedbackColor("RED"):ColorText(" ("..numAvailable..")")
else
error("Invalid numAvailable: "..numAvailable)
end
end
function private.GetCostText(row)
local index, costItemsText, price, stackSize = row:GetFields("index", "costItemsText", "price", "stackSize")
local color = TSM.Vendoring.Buy.GetMaxCanAfford(index) < stackSize and Theme.GetFeedbackColor("RED"):GetTextColorPrefix()
if costItemsText == "" then
-- just a price
return Money.ToString(price, color)
elseif price == 0 then
-- just an extended cost string
return costItemsText
else
-- both
return Money.ToString(price, color).." "..costItemsText
end
end
function private.GetCostTooltip(itemString)
return itemString ~= "" and itemString or nil
end
function private.GetRepairTooltip()
local tooltipLines = TempTable.Acquire()
local repairAllCost, canRepair = GetRepairAllCost()
if canRepair and repairAllCost > 0 then
tinsert(tooltipLines, REPAIR_ALL_ITEMS)
if IsAltKeyDown() then
local amount = GetGuildBankWithdrawMoney()
local guildBankMoney = GetGuildBankMoney()
if amount == -1 then
amount = guildBankMoney
else
amount = min(amount, guildBankMoney)
end
tinsert(tooltipLines, GUILDBANK_REPAIR)
tinsert(tooltipLines, Money.ToString(amount))
if repairAllCost > amount then
local personalAmount = repairAllCost - amount
local personalMoney = GetMoney()
if personalMoney >= personalAmount then
tinsert(tooltipLines, GUILDBANK_REPAIR_PERSONAL)
tinsert(tooltipLines, Money.ToString(personalAmount))
else
tinsert(tooltipLines, Theme.GetFeedbackColor("RED"):ColorText(GUILDBANK_REPAIR_INSUFFICIENT_FUNDS))
end
end
else
tinsert(tooltipLines, Money.ToString(repairAllCost))
local personalMoney = GetMoney()
if repairAllCost > personalMoney then
tinsert(tooltipLines, Theme.GetFeedbackColor("RED"):ColorText(GUILDBANK_REPAIR_INSUFFICIENT_FUNDS))
end
tinsert(tooltipLines, L["Hold ALT to repair from the guild bank."])
end
end
return strjoin("\n", TempTable.UnpackAndRelease(tooltipLines))
end
-- ============================================================================
-- Local Script Handlers
-- ============================================================================
function private.InputOnValueChanged(input)
local text = input:GetValue()
if text == private.filterText then
return
end
private.filterText = text
private.query:ResetFilters()
private.query:NotEqual("numAvailable", 0)
if text ~= "" then
private.query:Matches("name", String.Escape(text))
end
input:GetElement("__parent.__parent.items"):UpdateData(true)
end
function private.RowOnClick(scrollingTable, row, mouseButton)
if IsShiftKeyDown() then
local itemString = row:GetField("itemString")
local dialogFrame = UIElements.New("Frame", "frame")
:SetLayout("VERTICAL")
:SetSize(328, 214)
:SetPadding(12)
:AddAnchor("CENTER")
:SetContext(row)
:SetMouseEnabled(true)
:SetBackgroundColor("FRAME_BG", true)
:AddChild(UIElements.New("Frame", "header")
:SetLayout("HORIZONTAL")
:SetHeight(24)
:SetMargin(0, 0, -4, 10)
:AddChild(UIElements.New("Spacer", "spacer")
:SetWidth(20)
)
:AddChild(UIElements.New("Text", "title")
:SetJustifyH("CENTER")
:SetFont("BODY_BODY1_BOLD")
:SetText(L["Purchase Item"])
)
:AddChild(UIElements.New("Button", "closeBtn")
:SetMargin(0, -4, 0, 0)
:SetBackgroundAndSize("iconPack.24x24/Close/Default")
:SetScript("OnClick", private.PurchaseCloseBtnOnClick)
)
)
:AddChild(UIElements.New("Frame", "item")
:SetLayout("HORIZONTAL")
:SetPadding(6)
:SetMargin(0, 0, 0, 16)
:SetBackgroundColor("PRIMARY_BG_ALT", true)
:AddChild(UIElements.New("Button", "icon")
:SetSize(36, 36)
:SetMargin(0, 8, 0, 0)
:SetBackground(ItemInfo.GetTexture(itemString))
:SetTooltip(itemString)
)
:AddChild(UIElements.New("Text", "name")
:SetHeight(36)
:SetFont("ITEM_BODY1")
:SetText(TSM.UI.GetColoredItemName(itemString))
)
)
:AddChild(UIElements.New("Frame", "qty")
:SetLayout("HORIZONTAL")
:SetHeight(24)
:SetMargin(0, 0, 0, 16)
:AddChild(UIElements.New("Text", "text")
:SetWidth("AUTO")
:SetFont("BODY_BODY2_MEDIUM")
:SetText(L["Quantity"]..":")
)
:AddChild(UIElements.New("Input", "input")
:SetWidth(156)
:SetMargin(12, 8, 0, 0)
:SetBackgroundColor("PRIMARY_BG_ALT")
:SetJustifyH("CENTER")
:SetSubAddEnabled(true)
:SetValidateFunc("NUMBER", "1:99999")
:SetValue(1)
:SetScript("OnValidationChanged", private.InputQtyOnValidationChanged)
:SetScript("OnValueChanged", private.InputQtyOnValueChanged)
:SetScript("OnEnterPressed", private.InputQtyOnEnterPressed)
)
:AddChild(UIElements.New("ActionButton", "max")
:SetText(L["Max"])
:SetScript("OnClick", private.MaxBtnOnClick)
)
)
:AddChild(UIElements.New("Frame", "cost")
:SetLayout("HORIZONTAL")
:SetHeight(20)
:SetMargin(0, 0, 0, 16)
:AddChild(UIElements.New("Spacer", "spacer"))
:AddChild(UIElements.New("Text", "label")
:SetWidth("AUTO")
:SetMargin(0, 8, 0, 0)
:SetJustifyH("RIGHT")
:SetFont("BODY_BODY2_MEDIUM")
:SetText(L["Current Price"]..":")
)
:AddChild(UIElements.New("Button", "text")
:SetWidth("AUTO")
:SetJustifyH("RIGHT")
:SetFont("TABLE_TABLE1")
:SetText(private.GetAltCostText(row, 1))
:SetTooltip(private.GetAltCostTooltip(row))
)
)
:AddChild(UIElements.New("ActionButton", "purchaseBtn")
:SetHeight(24)
:SetText(L["Purchase"])
:SetDisabled(TSM.Vendoring.Buy.GetMaxCanAfford(row:GetField("index")) < 1)
:SetScript("OnClick", private.PurchaseBtnOnClick)
)
scrollingTable:GetBaseElement():ShowDialogFrame(dialogFrame)
dialogFrame:GetElement("qty.input"):SetFocused(true)
elseif mouseButton == "RightButton" then
TSM.Vendoring.Buy.BuyItemIndex(row:GetFields("index", "stackSize"))
end
end
function private.PurchaseCloseBtnOnClick(button)
button:GetBaseElement():HideDialog()
end
function private.InputQtyOnValidationChanged(input)
local row = input:GetElement("__parent.__parent"):GetContext()
if input:IsValid() and tonumber(input:GetValue()) <= TSM.Vendoring.Buy.GetMaxCanAfford(row:GetField("index")) then
input:GetElement("__parent.__parent.purchaseBtn")
:SetDisabled(false)
:Draw()
else
input:GetElement("__parent.__parent.purchaseBtn")
:SetDisabled(true)
:Draw()
end
end
function private.InputQtyOnValueChanged(input)
local row = input:GetElement("__parent.__parent"):GetContext()
local value = tonumber(input:GetValue())
input:GetElement("__parent.__parent.cost.text")
:SetText(private.GetAltCostText(row, value))
input:GetElement("__parent.__parent.cost")
:Draw()
if input:IsValid() and value <= TSM.Vendoring.Buy.GetMaxCanAfford(row:GetField("index")) then
input:GetElement("__parent.__parent.purchaseBtn")
:SetDisabled(false)
:Draw()
else
input:GetElement("__parent.__parent.purchaseBtn")
:SetDisabled(true)
:Draw()
end
end
function private.InputQtyOnEnterPressed(input)
input:GetElement("__parent.__parent.purchaseBtn"):Click()
end
function private.MaxBtnOnClick(button)
local row = button:GetElement("__parent.__parent"):GetContext()
local value = max(1, min(TSM.Vendoring.Buy.GetMaxCanAfford(row:GetField("index")), ItemInfo.GetMaxStack(row:GetField("itemString")) * CalculateTotalNumberOfFreeBagSlots()))
button:GetElement("__parent.input")
:SetValue(value)
:Draw()
private.InputQtyOnValidationChanged(button:GetElement("__parent.input"))
button:GetElement("__parent.__parent.cost.text")
:SetText(private.GetAltCostText(row, tonumber(value)))
button:GetElement("__parent.__parent.cost")
:Draw()
end
function private.GetAltCostText(row, quantity)
local index, costItemsText, price, stackSize = row:GetFields("index", "costItemsText", "price", "stackSize")
local color = TSM.Vendoring.Buy.GetMaxCanAfford(index) < quantity and Theme.GetFeedbackColor("RED"):GetTextColorPrefix()
price = price * quantity / stackSize
if costItemsText == "" then
-- just a price
return Money.ToString(price, color)
elseif price == 0 then
-- just an extended cost string
return private.GetItemAltCostText(row, quantity)
else
-- both
return Money.ToString(price, color).." "..private.GetItemAltCostText(row, quantity)
end
end
function private.GetAltCostTooltip(row)
return row:GetField("firstCostItemString") or nil
end
function private.GetItemAltCostText(row, quantity)
local index = row:GetField("index")
local _, _, _, stackSize, _, _, _, extendedCost = GetMerchantItemInfo(index)
local numAltCurrencies = GetMerchantItemCostInfo(index)
-- bug with big keech vendor returning extendedCost = true for gold only items
if numAltCurrencies == 0 then
extendedCost = false
end
local costItemsText = ""
if extendedCost then
assert(numAltCurrencies > 0)
local costItems = TempTable.Acquire()
for j = 1, numAltCurrencies do
local _, costNum, costItemLink = GetMerchantItemCostItem(index, j)
costNum = costNum * quantity / stackSize
local costItemString = ItemString.Get(costItemLink)
local texture = nil
if costItemString then
texture = ItemInfo.GetTexture(costItemString)
elseif not TSM.IsWowClassic() and strmatch(costItemLink, "currency:") then
if TSM.IsShadowlands() then
texture = C_CurrencyInfo.GetCurrencyInfoFromLink(costItemLink).iconFileID
else
_, _, texture = GetCurrencyInfo(costItemLink)
end
else
error(format("Unknown item cost (%d, %d, %s)", index, costNum, tostring(costItemLink)))
end
if TSM.Vendoring.Buy.GetMaxCanAfford(index) < quantity then
costNum = Theme.GetFeedbackColor("RED"):ColorText(costNum)
end
tinsert(costItems, costNum.." |T"..(texture or "")..":12|t")
end
costItemsText = table.concat(costItems, " ")
TempTable.Release(costItems)
end
return costItemsText
end
function private.PurchaseBtnOnClick(button)
local row = button:GetElement("__parent"):GetContext()
TSM.Vendoring.Buy.BuyItemIndex(row:GetField("index"), button:GetElement("__parent.qty.input"):GetValue())
button:GetBaseElement():HideDialog()
end
function private.GetCurrencyText()
local name, amount, texturePath = "", nil, nil
if TSM.IsShadowlands() then
local firstCurrency = GetMerchantCurrencies()
if firstCurrency then
local info = C_CurrencyInfo.GetCurrencyInfo(firstCurrency)
name = info.name
amount = info.quantity
texturePath = info.iconFileID
end
elseif not TSM.IsWowClassic() then
name, amount, texturePath = GetCurrencyInfo(GetMerchantCurrencies() or "")
end
local text = ""
if name ~= "" and amount and texturePath then
text = amount.." |T"..texturePath..":12|t"
end
return text
end
function private.RepairOnClick(button)
PlaySound(SOUNDKIT.ITEM_REPAIR)
button:SetDisabled(true)
if IsAltKeyDown() then
if not TSM.Vendoring.Buy.CanGuildRepair() then
Log.PrintfUser(L["Cannot repair from the guild bank!"])
return
end
TSM.Vendoring.Buy.DoGuildRepair()
else
TSM.Vendoring.Buy.DoRepair()
end
end

View File

@@ -0,0 +1,123 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Buyback = TSM.UI.VendoringUI:NewPackage("Buyback")
local L = TSM.Include("Locale").GetTable()
local Money = TSM.Include("Util.Money")
local ItemInfo = TSM.Include("Service.ItemInfo")
local Settings = TSM.Include("Service.Settings")
local UIElements = TSM.Include("UI.UIElements")
local private = {
settings = nil,
query = nil,
}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Buyback.OnInitialize()
private.settings = Settings.NewView()
:AddKey("global", "vendoringUIContext", "buybackScrollingTable")
TSM.UI.VendoringUI.RegisterTopLevelPage(BUYBACK, private.GetFrame)
end
-- ============================================================================
-- Buy UI
-- ============================================================================
function private.GetFrame()
TSM.UI.AnalyticsRecordPathChange("vendoring", "buyback")
private.query = private.query or TSM.Vendoring.Buyback.CreateQuery()
private.query:ResetOrderBy()
private.query:OrderBy("name", true)
return UIElements.New("Frame", "buy")
:SetLayout("VERTICAL")
:AddChild(UIElements.New("QueryScrollingTable", "items")
:SetMargin(0, 0, -2, 0)
:SetSettingsContext(private.settings, "buybackScrollingTable")
:GetScrollingTableInfo()
:NewColumn("qty")
:SetTitle(L["Qty"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("quantity")
:SetSortInfo("quantity")
:Commit()
:NewColumn("item")
:SetTitle(L["Item"])
:SetIconSize(12)
:SetFont("ITEM_BODY3")
:SetJustifyH("LEFT")
:SetTextInfo("itemString", private.GetItemText)
:SetIconInfo("itemString", ItemInfo.GetTexture)
:SetTooltipInfo("itemString")
:SetSortInfo("name")
:SetTooltipLinkingDisabled(true)
:DisableHiding()
:Commit()
:NewColumn("cost")
:SetTitle(L["Cost"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("price", Money.ToString)
:SetSortInfo("price")
:Commit()
:SetCursor("BUY_CURSOR")
:Commit()
:SetQuery(private.query)
:SetScript("OnRowClick", private.RowOnClick)
)
:AddChild(UIElements.New("Texture", "line")
:SetHeight(2)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("Frame", "footer")
:SetLayout("HORIZONTAL")
:SetHeight(40)
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Frame", "gold")
:SetLayout("HORIZONTAL")
:SetWidth(166)
:SetMargin(0, 8, 0, 0)
:SetPadding(4)
:AddChild(UIElements.New("PlayerGoldText", "text"))
)
:AddChild(UIElements.New("ActionButton", "buybackAllBtn")
:SetText(L["Buyback All"])
:SetScript("OnClick", private.BuybackAllBtnOnClick)
)
)
end
function private.GetItemText(itemString)
return TSM.UI.GetColoredItemName(itemString) or "?"
end
-- ============================================================================
-- Local Script Handlers
-- ============================================================================
function private.RowOnClick(_, row, mouseButton)
if mouseButton == "RightButton" then
TSM.Vendoring.Buyback.BuybackItem(row:GetField("index"))
end
end
function private.BuybackAllBtnOnClick(button)
for _, row in private.query:Iterator() do
TSM.Vendoring.Buyback.BuybackItem(row:GetField("index"))
end
end

View File

@@ -0,0 +1,236 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local VendoringUI = TSM.UI:NewPackage("VendoringUI")
local L = TSM.Include("Locale").GetTable()
local Delay = TSM.Include("Util.Delay")
local FSM = TSM.Include("Util.FSM")
local Event = TSM.Include("Util.Event")
local ScriptWrapper = TSM.Include("Util.ScriptWrapper")
local Settings = TSM.Include("Service.Settings")
local UIElements = TSM.Include("UI.UIElements")
local private = {
settings = nil,
topLevelPages = {},
fsm = nil,
defaultUISwitchBtn = nil,
isVisible = false,
}
local MIN_FRAME_SIZE = { width = 560, height = 500 }
-- ============================================================================
-- Module Functions
-- ============================================================================
function VendoringUI.OnInitialize()
private.settings = Settings.NewView()
:AddKey("global", "vendoringUIContext", "showDefault")
:AddKey("global", "vendoringUIContext", "frame")
private.FSMCreate()
end
function VendoringUI.OnDisable()
-- hide the frame
private.fsm:ProcessEvent("EV_FRAME_HIDE")
end
function VendoringUI.RegisterTopLevelPage(name, callback)
tinsert(private.topLevelPages, { name = name, callback = callback })
end
function VendoringUI.IsVisible()
return private.isVisible
end
-- ============================================================================
-- Main Frame
-- ============================================================================
function private.CreateMainFrame()
TSM.UI.AnalyticsRecordPathChange("vendoring")
local frame = UIElements.New("LargeApplicationFrame", "base")
:SetParent(UIParent)
:SetSettingsContext(private.settings, "frame")
:SetMinResize(MIN_FRAME_SIZE.width, MIN_FRAME_SIZE.height)
:SetStrata("HIGH")
:AddSwitchButton(private.SwitchBtnOnClick)
:SetScript("OnHide", private.BaseFrameOnHide)
for _, info in ipairs(private.topLevelPages) do
frame:AddNavButton(info.name, info.callback)
end
return frame
end
-- ============================================================================
-- Local Script Handlers
-- ============================================================================
function private.BaseFrameOnHide()
TSM.UI.AnalyticsRecordClose("vendoring")
private.fsm:ProcessEvent("EV_FRAME_HIDE")
end
function private.SwitchBtnOnClick(button)
private.settings.showDefault = button ~= private.defaultUISwitchBtn
private.fsm:ProcessEvent("EV_SWITCH_BTN_CLICKED")
end
function private.SwitchButtonOnEnter(button)
button:SetTextColor("TEXT")
:Draw()
end
function private.SwitchButtonOnLeave(button)
button:SetTextColor("TEXT_ALT")
:Draw()
end
-- ============================================================================
-- FSM
-- ============================================================================
function private.FSMCreate()
local function MerchantShowDelayed()
private.fsm:ProcessEvent("EV_MERCHANT_SHOW")
end
local function CurrencyUpdate()
private.fsm:ProcessEvent("EV_CURRENCY_UPDATE")
end
Event.Register("MERCHANT_SHOW", function()
Delay.AfterFrame("MERCHANT_SHOW_DELAYED", 0, MerchantShowDelayed)
end)
Event.Register("MERCHANT_CLOSED", function()
private.fsm:ProcessEvent("EV_MERCHANT_CLOSED")
end)
MerchantFrame:UnregisterEvent("MERCHANT_SHOW")
local fsmContext = {
frame = nil,
defaultPoint = nil,
}
local function DefaultFrameOnHide()
private.fsm:ProcessEvent("EV_FRAME_HIDE")
end
private.fsm = FSM.New("MERCHANT_UI")
:AddState(FSM.NewState("ST_CLOSED")
:AddTransition("ST_DEFAULT_OPEN")
:AddTransition("ST_FRAME_OPEN")
:AddEvent("EV_FRAME_TOGGLE", function(context)
assert(not private.settings.showDefault)
return "ST_FRAME_OPEN"
end)
:AddEvent("EV_MERCHANT_SHOW", function(context)
if private.settings.showDefault then
return "ST_DEFAULT_OPEN"
else
return "ST_FRAME_OPEN"
end
end)
)
:AddState(FSM.NewState("ST_DEFAULT_OPEN")
:SetOnEnter(function(context, isIgnored)
MerchantFrame_OnEvent(MerchantFrame, "MERCHANT_SHOW")
if not private.defaultUISwitchBtn then
private.defaultUISwitchBtn = UIElements.New("ActionButton", "switchBtn")
:SetSize(60, TSM.IsWowClassic() and 16 or 15)
:AddAnchor("TOPRIGHT", TSM.IsWowClassic() and -26 or -27, TSM.IsWowClassic() and -3 or -4)
:SetFont("BODY_BODY3_MEDIUM")
:DisableClickCooldown()
:SetText(L["TSM4"])
:SetScript("OnClick", private.SwitchBtnOnClick)
:SetScript("OnEnter", private.SwitchButtonOnEnter)
:SetScript("OnLeave", private.SwitchButtonOnLeave)
private.defaultUISwitchBtn:_GetBaseFrame():SetParent(MerchantFrame)
end
if isIgnored then
private.defaultUISwitchBtn:Hide()
else
private.defaultUISwitchBtn:Show()
private.defaultUISwitchBtn:Draw()
end
ScriptWrapper.Set(MerchantFrame, "OnHide", DefaultFrameOnHide)
end)
:SetOnExit(function(context)
ScriptWrapper.Clear(MerchantFrame, "OnHide")
HideUIPanel(MerchantFrame)
end)
:AddTransition("ST_CLOSED")
:AddTransition("ST_FRAME_OPEN")
:AddEvent("EV_FRAME_HIDE", function(context)
CloseMerchant()
return "ST_CLOSED"
end)
:AddEvent("EV_MERCHANT_SHOW", MerchantFrame_Update)
:AddEventTransition("EV_MERCHANT_CLOSED", "ST_CLOSED")
:AddEvent("EV_SWITCH_BTN_CLICKED", function()
return "ST_FRAME_OPEN"
end)
)
:AddState(FSM.NewState("ST_FRAME_OPEN")
:SetOnEnter(function(context)
assert(not context.frame)
MerchantFrame_OnEvent(MerchantFrame, "MERCHANT_SHOW")
if not context.defaultPoint then
context.defaultPoint = { MerchantFrame:GetPoint(1) }
end
MerchantFrame:SetClampedToScreen(false)
MerchantFrame:ClearAllPoints()
MerchantFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 100000, 100000)
OpenAllBags()
context.frame = private.CreateMainFrame()
context.frame:Show()
context.frame:GetElement("titleFrame.switchBtn"):Show()
context.frame:Draw()
if not TSM.IsWowClassic() then
Event.Register("CURRENCY_DISPLAY_UPDATE", CurrencyUpdate)
end
private.isVisible = true
end)
:SetOnExit(function(context)
CloseAllBags()
MerchantFrame:ClearAllPoints()
local point, region, relativePoint, x, y = unpack(context.defaultPoint)
if point and region and relativePoint and x and y then
MerchantFrame:SetPoint(point, region, relativePoint, x, y)
else
MerchantFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 16, -116)
end
if not TSM.IsWowClassic() then
Event.Unregister("CURRENCY_DISPLAY_UPDATE", CurrencyUpdate)
end
private.isVisible = false
context.frame:Hide()
context.frame:Release()
context.frame = nil
end)
:AddTransition("ST_CLOSED")
:AddTransition("ST_DEFAULT_OPEN")
:AddEvent("EV_CURRENCY_UPDATE", function(context)
TSM.UI.VendoringUI.Buy.UpdateCurrency(context.frame)
end)
:AddEvent("EV_FRAME_HIDE", function(context)
CloseMerchant()
return "ST_CLOSED"
end)
:AddEvent("EV_MERCHANT_CLOSED", function(context)
return "ST_CLOSED"
end)
:AddEvent("EV_SWITCH_BTN_CLICKED", function()
return "ST_DEFAULT_OPEN"
end)
)
:Init("ST_CLOSED", fsmContext)
end

View File

@@ -0,0 +1,263 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Groups = TSM.UI.VendoringUI:NewPackage("Groups")
local L = TSM.Include("Locale").GetTable()
local TempTable = TSM.Include("Util.TempTable")
local FSM = TSM.Include("Util.FSM")
local Settings = TSM.Include("Service.Settings")
local UIElements = TSM.Include("UI.UIElements")
local private = {
settings = nil,
groupSearch = "",
fsm = nil,
}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Groups.OnInitialize()
private.settings = Settings.NewView()
:AddKey("char", "vendoringUIContext", "groupTree")
private.FSMCreate()
TSM.UI.VendoringUI.RegisterTopLevelPage(L["Groups"], private.GetFrame)
end
-- ============================================================================
-- Groups UI
-- ============================================================================
function private.GetFrame()
TSM.UI.AnalyticsRecordPathChange("vendoring", "groups")
return UIElements.New("Frame", "buy")
:SetLayout("VERTICAL")
:AddChild(UIElements.New("Frame", "container")
:SetLayout("VERTICAL")
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Text", "groupsText")
:SetHeight(18)
:SetMargin(0, 0, 0, 8)
:SetFont("BODY_BODY3")
:SetFormattedText(L["%d |4Group:Groups; Selected (%d |4Item:Items;)"], 0, 0)
)
:AddChild(UIElements.New("Frame", "search")
:SetLayout("HORIZONTAL")
:SetHeight(24)
:AddChild(UIElements.New("Input", "input")
:SetIconTexture("iconPack.18x18/Search")
:SetClearButtonEnabled(true)
:AllowItemInsert(true)
:SetValue(private.groupSearch)
:SetHintText(L["Search Groups"])
:SetScript("OnValueChanged", private.GroupSearchOnValueChanged)
)
:AddChild(UIElements.New("Button", "expandAllBtn")
:SetSize(24, 24)
:SetMargin(8, 4, 0, 0)
:SetBackground("iconPack.18x18/Expand All")
:SetScript("OnClick", private.ExpandAllGroupsOnClick)
:SetTooltip(L["Expand / Collapse All Groups"])
)
:AddChild(UIElements.New("Button", "selectAllBtn")
:SetSize(24, 24)
:SetBackground("iconPack.18x18/Select All")
:SetScript("OnClick", private.SelectAllGroupsOnClick)
:SetTooltip(L["Select / Deselect All Groups"])
)
)
)
:AddChild(UIElements.New("Texture", "line")
:SetHeight(2)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("ApplicationGroupTree", "groupTree")
:SetSettingsContext(private.settings, "groupTree")
:SetQuery(TSM.Groups.CreateQuery(), "Vendoring")
:SetSearchString(private.groupSearch)
:SetScript("OnGroupSelectionChanged", private.GroupTreeOnGroupSelectionChanged)
)
:AddChild(UIElements.New("Texture", "line")
:SetHeight(2)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("Frame", "footer")
:SetLayout("HORIZONTAL")
:SetHeight(40)
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Frame", "gold")
:SetLayout("HORIZONTAL")
:SetWidth(166)
:SetMargin(0, 8, 0, 0)
:SetPadding(4)
:AddChild(UIElements.New("PlayerGoldText", "text"))
)
:AddChild(UIElements.New("ActionButton", "buyBtn")
:SetMargin(0, 8, 0, 0)
:SetText(L["Buy Groups"])
:SetScript("OnClick", private.BuyBtnOnClick)
)
:AddChild(UIElements.New("ActionButton", "sellBtn")
:SetText(L["Sell Groups"])
:SetScript("OnClick", private.SellBtnOnClick)
)
)
:SetScript("OnUpdate", private.FrameOnUpdate)
:SetScript("OnHide", private.FrameOnHide)
end
-- ============================================================================
-- Local Script Handlers
-- ============================================================================
function private.FrameOnUpdate(frame)
frame:SetScript("OnUpdate", nil)
private.GroupTreeOnGroupSelectionChanged(frame:GetElement("groupTree"))
private.fsm:ProcessEvent("EV_FRAME_SHOW", frame)
end
function private.FrameOnHide(frame)
private.fsm:ProcessEvent("EV_FRAME_HIDE")
end
function private.GroupSearchOnValueChanged(input)
local text = strlower(input:GetValue())
if text == private.groupSearch then
return
end
private.groupSearch = text
input:GetElement("__parent.__parent.__parent.groupTree")
:SetSearchString(private.groupSearch)
:Draw()
end
function private.ExpandAllGroupsOnClick(button)
button:GetElement("__parent.__parent.__parent.groupTree")
:ToggleExpandAll()
end
function private.SelectAllGroupsOnClick(button)
button:GetElement("__parent.__parent.__parent.groupTree")
:ToggleSelectAll()
end
function private.GroupTreeOnGroupSelectionChanged(groupTree)
local footerFrame = groupTree:GetElement("__parent.footer")
footerFrame:GetElement("sellBtn")
:SetDisabled(groupTree:IsSelectionCleared())
footerFrame:GetElement("buyBtn")
:SetDisabled(groupTree:IsSelectionCleared())
footerFrame:Draw()
local numGroups, numItems = 0, 0
for _, groupPath in groupTree:SelectedGroupsIterator() do
numGroups = numGroups + 1
if groupPath == TSM.CONST.ROOT_GROUP_PATH then
-- TODO
else
for _ in TSM.Groups.ItemIterator(groupPath) do
numItems = numItems + 1
end
end
end
groupTree:GetElement("__parent.container.groupsText")
:SetFormattedText(L["%d |4Group:Groups; Selected (%d |4Item:Items;)"], numGroups, numItems)
:Draw()
end
function private.BuyBtnOnClick(button)
private.fsm:ProcessEvent("EV_BUTTON_CLICKED", "BUY")
end
function private.SellBtnOnClick(button)
private.fsm:ProcessEvent("EV_BUTTON_CLICKED", "SELL")
end
-- ============================================================================
-- FSM
-- ============================================================================
function private.FSMCreate()
local fsmContext = {
frame = nil,
currentOperation = nil,
}
local function UpdateFrame(context)
local footer = context.frame:GetElement("footer")
footer:GetElement("buyBtn")
:SetPressed(context.currentOperation == "BUY")
:SetDisabled(context.currentOperation)
footer:GetElement("sellBtn")
:SetPressed(context.currentOperation == "SELL")
:SetDisabled(context.currentOperation)
footer:Draw()
end
private.fsm = FSM.New("VENDORING_GROUPS")
:AddState(FSM.NewState("ST_FRAME_CLOSED")
:SetOnEnter(function(context)
context.frame = nil
assert(not context.currentOperation)
end)
:AddTransition("ST_FRAME_OPEN")
:AddTransition("ST_FRAME_CLOSED")
:AddEvent("EV_FRAME_SHOW", function(context, frame)
context.frame = frame
return "ST_FRAME_OPEN"
end)
)
:AddState(FSM.NewState("ST_FRAME_OPEN")
:SetOnEnter(function(context)
UpdateFrame(context)
end)
:AddTransition("ST_BUSY")
:AddTransition("ST_FRAME_CLOSED")
:AddEventTransition("EV_BUTTON_CLICKED", "ST_BUSY")
)
:AddState(FSM.NewState("ST_BUSY")
:SetOnEnter(function(context, operation)
assert(not context.currentOperation)
context.currentOperation = operation
local groups = TempTable.Acquire()
for _, groupPath in context.frame:GetElement("groupTree"):SelectedGroupsIterator() do
tinsert(groups, groupPath)
end
if operation == "BUY" then
TSM.Vendoring.Groups.BuyGroups(groups, private.FSMSellCallback)
elseif operation == "SELL" then
TSM.Vendoring.Groups.SellGroups(groups, private.FSMSellCallback)
else
error("Unexpected operation: "..tostring(operation))
end
TempTable.Release(groups)
UpdateFrame(context)
end)
:SetOnExit(function(context)
context.currentOperation = nil
TSM.Vendoring.Groups.StopBuySell()
end)
:AddTransition("ST_FRAME_OPEN")
:AddTransition("ST_FRAME_CLOSED")
:AddEventTransition("EV_SELL_DONE", "ST_FRAME_OPEN")
)
:AddDefaultEventTransition("EV_FRAME_HIDE", "ST_FRAME_CLOSED")
:Init("ST_FRAME_CLOSED", fsmContext)
end
function private.FSMSellCallback()
private.fsm:ProcessEvent("EV_SELL_DONE")
end

View File

@@ -0,0 +1,215 @@
-- ------------------------------------------------------------------------------ --
-- TradeSkillMaster --
-- https://tradeskillmaster.com --
-- All Rights Reserved - Detailed license information included with addon. --
-- ------------------------------------------------------------------------------ --
local _, TSM = ...
local Sell = TSM.UI.VendoringUI:NewPackage("Sell")
local L = TSM.Include("Locale").GetTable()
local Money = TSM.Include("Util.Money")
local TempTable = TSM.Include("Util.TempTable")
local String = TSM.Include("Util.String")
local Theme = TSM.Include("Util.Theme")
local ItemInfo = TSM.Include("Service.ItemInfo")
local Settings = TSM.Include("Service.Settings")
local UIElements = TSM.Include("UI.UIElements")
local private = {
settings = nil,
filterText = "",
query = nil,
}
-- ============================================================================
-- Module Functions
-- ============================================================================
function Sell.OnInitialize()
private.settings = Settings.NewView()
:AddKey("global", "vendoringUIContext", "sellScrollingTable")
TSM.UI.VendoringUI.RegisterTopLevelPage(L["Sell"], private.GetFrame)
end
-- ============================================================================
-- Sell UI
-- ============================================================================
function private.GetFrame()
TSM.UI.AnalyticsRecordPathChange("vendoring", "sell")
private.filterText = ""
if private.query then
TSM.Vendoring.Sell.ResetBagsQuery(private.query)
else
private.query = TSM.Vendoring.Sell.CreateBagsQuery()
end
return UIElements.New("Frame", "sell")
:SetLayout("VERTICAL")
:AddChild(UIElements.New("Frame", "header")
:SetLayout("VERTICAL")
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("Text", "ignoreText")
:SetHeight(36)
:SetMargin(0, 0, 0, 8)
:SetFont("BODY_BODY3")
:SetText(format(L["%sLeft-Click|r to ignore an item for this session. Hold %sShift|r to ignore permanently. You can remove items from permanent ignore in the Vendoring settings."], Theme.GetColor("INDICATOR"):GetTextColorPrefix(), Theme.GetColor("INDICATOR"):GetTextColorPrefix()))
)
:AddChild(UIElements.New("Frame", "filters")
:SetLayout("HORIZONTAL")
:SetHeight(24)
:AddChild(UIElements.New("Input", "searchInput")
:SetIconTexture("iconPack.18x18/Search")
:SetClearButtonEnabled(true)
:AllowItemInsert()
:SetHintText(L["Search Bags"])
:SetScript("OnValueChanged", private.InputOnValueChanged)
)
:AddChild(UIElements.New("Button", "filterBtn")
:SetWidth("AUTO")
:SetMargin(8, 8, 0, 0)
:SetFont("BODY_BODY3_MEDIUM")
:SetText(FILTERS)
-- TODO
-- :SetScript("OnClick", private.FilterButtonOnClick)
)
:AddChild(UIElements.New("Button", "filterBtnIcon")
:SetBackgroundAndSize("iconPack.14x14/Filter")
-- TODO
-- :SetScript("OnClick", private.FilterButtonOnClick)
)
)
)
:AddChild(UIElements.New("QueryScrollingTable", "items")
:SetSettingsContext(private.settings, "sellScrollingTable")
:GetScrollingTableInfo()
:NewColumn("item")
:SetTitle(L["Item"])
:SetIconSize(12)
:SetFont("ITEM_BODY3")
:SetJustifyH("LEFT")
:SetTextInfo("itemString", private.GetItemText)
:SetIconInfo("itemString", ItemInfo.GetTexture)
:SetTooltipInfo("itemString")
:SetSortInfo("name")
:SetTooltipLinkingDisabled(true)
:DisableHiding()
:Commit()
:NewColumn("vendorSell")
:SetTitle(L["Vendor Sell"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("vendorSell", private.GetVendorSellText)
:SetSortInfo("vendorSell")
:Commit()
:NewColumn("potential")
:SetTitle(L["Potential"])
:SetFont("TABLE_TABLE1")
:SetJustifyH("RIGHT")
:SetTextInfo("potentialValue", Money.ToString)
:SetSortInfo("potentialValue")
:Commit()
:SetCursor("BUY_CURSOR")
:Commit()
:SetQuery(private.query)
:SetScript("OnRowClick", private.RowOnClick)
)
:AddChild(UIElements.New("Texture", "line")
:SetHeight(2)
:SetTexture("ACTIVE_BG")
)
:AddChild(UIElements.New("Frame", "footer")
:SetLayout("HORIZONTAL")
:SetHeight(40)
:SetPadding(8)
:SetBackgroundColor("PRIMARY_BG_ALT")
:AddChild(UIElements.New("ActionButton", "sellTrashBtn")
:SetWidth(128)
:SetMargin(0, 8, 0, 0)
:SetText(L["Sell Trash"])
:SetScript("OnClick", private.SellTrashBtnOnClick)
)
:AddChild(UIElements.New("ActionButton", "sellBOEBtn")
:SetWidth(128)
:SetMargin(0, 8, 0, 0)
:SetText(L["Sell BoEs"])
:SetScript("OnClick", private.SellBOEBtnOnClick)
)
:AddChild(UIElements.New("ActionButton", "sellAllBtn")
:SetText(L["Sell All"])
:SetScript("OnClick", private.SellAllBtnOnClick)
)
)
end
function private.GetItemText(itemString)
return TSM.UI.GetColoredItemName(itemString) or "?"
end
function private.GetVendorSellText(vendorSell)
return vendorSell > 0 and Money.ToString(vendorSell) or ""
end
-- ============================================================================
-- Local Script Handlers
-- ============================================================================
function private.InputOnValueChanged(input)
local text = input:GetValue()
if text == private.filterText then
return
end
private.filterText = text
TSM.Vendoring.Sell.ResetBagsQuery(private.query)
if text ~= "" then
private.query:Matches("name", String.Escape(text))
end
input:GetElement("__parent.__parent.__parent.items"):UpdateData(true)
end
function private.RowOnClick(_, row, mouseButton)
local itemString = row:GetField("itemString")
if mouseButton == "RightButton" then
TSM.Vendoring.Sell.SellItem(itemString)
elseif IsShiftKeyDown() then
TSM.Vendoring.Sell.IgnoreItemPermanent(itemString)
else
TSM.Vendoring.Sell.IgnoreItemSession(itemString)
end
end
function private.SellTrashBtnOnClick(button)
for _, row in private.query:Iterator() do
local itemString, quality = row:GetFields("itemString", "quality")
if quality == (TSM.IsShadowlands() and Enum.ItemQuality.Poor or LE_ITEM_QUALITY_POOR) then
TSM.Vendoring.Sell.SellItem(itemString)
end
end
end
function private.SellBOEBtnOnClick(button)
-- checking if an item is disenchantable might cause our query to change since it depends on the ItemInfo DB, so cache the list of items first
local items = TempTable.Acquire()
for _, row in private.query:Iterator() do
tinsert(items, row:GetField("itemString"))
end
for _, itemString in ipairs(items) do
if ItemInfo.IsDisenchantable(itemString) then
TSM.Vendoring.Sell.SellItem(itemString)
end
end
TempTable.Release(items)
end
function private.SellAllBtnOnClick(button)
for _, row in private.query:Iterator() do
TSM.Vendoring.Sell.SellItem(row:GetField("itemString"))
end
end