refactoring, change of pickup/use behavior
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ function private.post_auction(slot, k)
|
||||
ClearCursor()
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
PickupContainerItem(unpack(slot))
|
||||
aux.orig.PickupContainerItem(unpack(slot))
|
||||
ClickAuctionSellItemButton()
|
||||
ClearCursor()
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ function private.move_item(from_slot, to_slot, amount, k)
|
||||
|
||||
ClearCursor()
|
||||
SplitContainerItem(from_slot[1], from_slot[2], amount)
|
||||
PickupContainerItem(unpack(to_slot))
|
||||
aux.orig.PickupContainerItem(unpack(to_slot))
|
||||
|
||||
return aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
|
||||
end
|
||||
|
||||
@@ -2,6 +2,37 @@ local addon = aux_module()
|
||||
aux = tremove(addon, 1)
|
||||
local m, public, private = unpack(addon)
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__newindex = function(self, key, value)
|
||||
self._f()[key] = value
|
||||
end,
|
||||
__index = function(self, key)
|
||||
return self._f()[key]
|
||||
end,
|
||||
__call = function(self)
|
||||
return self._f()
|
||||
end,
|
||||
}
|
||||
function public.dynamic_table(f)
|
||||
return setmetatable({_f=f}, mt)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__index = function(self, key)
|
||||
return self:_cb(key)
|
||||
end,
|
||||
__call = function(self)
|
||||
return self:_cb()
|
||||
end,
|
||||
}
|
||||
function public.index_function(cb)
|
||||
return setmetatable({_cb = cb}, mt)
|
||||
end
|
||||
end
|
||||
|
||||
private.modules = {}
|
||||
function private.initialize_module(public_declarator)
|
||||
public_declarator.LOAD = nil
|
||||
@@ -17,20 +48,21 @@ end
|
||||
|
||||
private.tabs = {}
|
||||
function public.tab(index, name)
|
||||
local ret = { m.module(name) }
|
||||
ret[2].ACTIVE = function()
|
||||
local tab = {m.module(name)}
|
||||
tab[2].ACTIVE = function()
|
||||
return m[name] == m.active_tab()
|
||||
end
|
||||
for _, handler in {'OPEN', 'CLOSE', 'CLICK_LINK', 'PICKUP_ITEM', 'USE_ITEM'} do
|
||||
tab[2][handler] = nil
|
||||
end
|
||||
m.tabs[index] = m[name]
|
||||
return unpack(ret)
|
||||
return unpack(tab)
|
||||
end
|
||||
do
|
||||
local active_tab_index
|
||||
function private.active_tab()
|
||||
if active_tab_index then
|
||||
return m.tabs[active_tab_index]
|
||||
end
|
||||
end
|
||||
private.active_tab = m.dynamic_table(function()
|
||||
return m.tabs[active_tab_index]
|
||||
end)
|
||||
function private.on_tab_click(index)
|
||||
if m.active_tab() then
|
||||
m.active_tab().CLOSE()
|
||||
@@ -104,37 +136,6 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__newindex = function(self, key, value)
|
||||
self._f()[key] = value
|
||||
end,
|
||||
__index = function(self, key)
|
||||
return self._f()[key]
|
||||
end,
|
||||
__call = function(self)
|
||||
return self._f()
|
||||
end,
|
||||
}
|
||||
function public.dynamic_table(f)
|
||||
return setmetatable({_f=f}, mt)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local mt = {
|
||||
__index = function(self, key)
|
||||
return self:_cb(key)
|
||||
end,
|
||||
__call = function(self)
|
||||
return self:_cb()
|
||||
end,
|
||||
}
|
||||
function public.index_function(cb)
|
||||
return setmetatable({_cb = cb}, mt)
|
||||
end
|
||||
end
|
||||
|
||||
function public.call(f, ...)
|
||||
if f then
|
||||
return f(unpack(arg))
|
||||
@@ -162,8 +163,6 @@ function public.on_load()
|
||||
aux.gui.set_window_style(AuxFrame)
|
||||
tinsert(UISpecialFrames, 'AuxFrame')
|
||||
|
||||
aux.control.event_listener('CURSOR_UPDATE', m.CURSOR_UPDATE)
|
||||
|
||||
do
|
||||
local tab_group = m.gui.tab_group(AuxFrame, 'DOWN')
|
||||
tab_group:create_tab('Search')
|
||||
@@ -427,63 +426,34 @@ function public.price_level_color(pct)
|
||||
end
|
||||
end
|
||||
|
||||
do -- TODO make it work for other ways to pick up things
|
||||
local last_picked_up
|
||||
function private.CURSOR_UPDATE()
|
||||
last_picked_up = nil
|
||||
end
|
||||
function private.PickupContainerItem(...)
|
||||
local bag, slot = unpack(arg)
|
||||
aux.control.thread(function()
|
||||
last_picked_up = {bag, slot}
|
||||
end)
|
||||
return m.orig.PickupContainerItem(unpack(arg))
|
||||
end
|
||||
function public.cursor_item()
|
||||
if last_picked_up and CursorHasItem() then
|
||||
return m.info.container_item(unpack(last_picked_up))
|
||||
end
|
||||
end
|
||||
function private.SetItemRef(...)
|
||||
if not arg[3] == 'RightButton' or not m.active_tab.CLICK_LINK or not strfind(arg[1], '^item:%d+') then
|
||||
return m.orig.SetItemRef(unpack(arg))
|
||||
end
|
||||
local item_info = m.info.item(tonumber(({strfind(arg[1], '^item:(%d+)')})[3]))
|
||||
if item_info then
|
||||
return m.active_tab.CLICK_LINK(item_info)
|
||||
end
|
||||
end
|
||||
|
||||
function private.SetItemRef(...)
|
||||
local itemstring, text, button = unpack(arg)
|
||||
if m.search_tab.ACTIVE() and button == 'RightButton' then
|
||||
local item_info = m.info.item(tonumber(({strfind(itemstring, '^item:(%d+)')})[3]))
|
||||
if item_info then
|
||||
m.search_tab.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.search_tab.execute(nil, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
return m.orig.SetItemRef(unpack(arg))
|
||||
function private.PickupContainerItem(...)
|
||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() or not m.active_tab.PICKUP_ITEM then
|
||||
return m.orig.PickupContainerItem(unpack(arg))
|
||||
end
|
||||
local item_info = m.info.container_item(arg[1], arg[2])
|
||||
if item_info then
|
||||
return m.active_tab.PICKUP_ITEM(item_info)
|
||||
end
|
||||
end
|
||||
|
||||
function private.UseContainerItem(...)
|
||||
local bag, slot = unpack(arg)
|
||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
|
||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() or not m.active_tab.USE_ITEM then
|
||||
return m.orig.UseContainerItem(unpack(arg))
|
||||
end
|
||||
|
||||
if m.search_tab.ACTIVE() then
|
||||
local item_info = m.info.container_item(bag, slot)
|
||||
item_info = item_info and m.info.item(item_info.item_id)
|
||||
if item_info then
|
||||
m.search_tab.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.search_tab.execute(nil, false)
|
||||
end
|
||||
return
|
||||
local item_info = m.info.container_item(arg[1], arg[2])
|
||||
if item_info then
|
||||
return m.active_tab.USE_ITEM(item_info)
|
||||
end
|
||||
|
||||
if m.post_tab.ACTIVE() then
|
||||
local item_info = m.info.container_item(bag, slot)
|
||||
if item_info then
|
||||
m.post_tab.select_item(item_info.item_key)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
return m.orig.UseContainerItem(unpack(arg))
|
||||
end
|
||||
|
||||
function public.is_player(name, current)
|
||||
|
||||
@@ -410,21 +410,22 @@ function public.status_bar(parent)
|
||||
end
|
||||
|
||||
function public.item(parent)
|
||||
local item = CreateFrame('Button', nil, parent)
|
||||
local item = CreateFrame('Frame', nil, parent)
|
||||
item:SetWidth(260)
|
||||
item:SetHeight(40)
|
||||
local icon = CreateFrame('CheckButton', 'aux_frame'..aux.id(), item, 'ActionButtonTemplate')
|
||||
icon:SetPoint('LEFT', 2, 0.5)
|
||||
icon:SetHighlightTexture(nil)
|
||||
icon:RegisterForClicks()
|
||||
icon:EnableMouse(nil)
|
||||
item.texture = getglobal(icon:GetName()..'Icon')
|
||||
local btn = CreateFrame('CheckButton', 'aux_frame'..aux.id(), item, 'ActionButtonTemplate')
|
||||
item.button = btn
|
||||
btn:SetPoint('LEFT', 2, 0.5)
|
||||
btn:SetHighlightTexture(nil)
|
||||
btn:RegisterForClicks()
|
||||
btn:EnableMouse(nil)
|
||||
item.texture = getglobal(btn:GetName()..'Icon')
|
||||
item.texture:SetTexCoord(0.06,0.94,0.06,0.94)
|
||||
item.name = aux.gui.label(icon, 15)
|
||||
item.name = aux.gui.label(btn, 15)
|
||||
item.name:SetJustifyH('LEFT')
|
||||
item.name:SetPoint('LEFT', icon, 'RIGHT', 10, 0)
|
||||
item.name:SetPoint('LEFT', btn, 'RIGHT', 10, 0)
|
||||
item.name:SetPoint('RIGHT', item, 'RIGHT', -10, 0.5)
|
||||
item.count = getglobal(icon:GetName()..'Count')
|
||||
item.count = getglobal(btn:GetName()..'Count')
|
||||
item.count:SetTextHeight(17)
|
||||
return item
|
||||
end
|
||||
|
||||
@@ -10,12 +10,12 @@ function m.LOAD()
|
||||
m.create_frames(m, public, private)
|
||||
end
|
||||
|
||||
function public.OPEN()
|
||||
function m.OPEN()
|
||||
m.frame:Show()
|
||||
m.scan_auctions()
|
||||
end
|
||||
|
||||
function public.CLOSE()
|
||||
function m.CLOSE()
|
||||
m.frame:Hide()
|
||||
end
|
||||
|
||||
|
||||
+2
-2
@@ -10,12 +10,12 @@ function m.LOAD()
|
||||
m.create_frames(m, public, private)
|
||||
end
|
||||
|
||||
function public.OPEN()
|
||||
function m.OPEN()
|
||||
m.frame:Show()
|
||||
m.scan_bids()
|
||||
end
|
||||
|
||||
function public.CLOSE()
|
||||
function m.CLOSE()
|
||||
m.frame:Hide()
|
||||
end
|
||||
|
||||
|
||||
+11
-3
@@ -17,7 +17,7 @@ function m.LOAD()
|
||||
m.create_frames(m, public, private)
|
||||
end
|
||||
|
||||
function public.OPEN()
|
||||
function m.OPEN()
|
||||
m.frame:Show()
|
||||
|
||||
m.deposit:SetText('Deposit: '..aux.money.to_string(0, nil, nil, nil, aux.gui.inline_color.text.enabled))
|
||||
@@ -30,11 +30,19 @@ function public.OPEN()
|
||||
m.refresh = true
|
||||
end
|
||||
|
||||
function public.CLOSE()
|
||||
function m.CLOSE()
|
||||
m.selected_item = nil
|
||||
m.frame:Hide()
|
||||
end
|
||||
|
||||
function m.PICKUP_ITEM(item_info)
|
||||
m.select_item(item_info.item_key)
|
||||
end
|
||||
|
||||
function m.USE_ITEM(item_info)
|
||||
m.select_item(item_info.item_key)
|
||||
end
|
||||
|
||||
function private.default_settings()
|
||||
return {
|
||||
duration = DURATION_8,
|
||||
@@ -358,7 +366,7 @@ function private.unit_vendor_price(item_key)
|
||||
|
||||
if aux.info.auctionable(item_info.tooltip, nil, item_info.lootable) then
|
||||
ClearCursor()
|
||||
PickupContainerItem(unpack(slot))
|
||||
aux.orig.PickupContainerItem(unpack(slot))
|
||||
ClickAuctionSellItemButton()
|
||||
local auction_sell_item = aux.info.auction_sell_item()
|
||||
ClearCursor()
|
||||
|
||||
+3
-24
@@ -118,34 +118,13 @@ aux.post_tab.FRAMES(function(m, public, private)
|
||||
do
|
||||
local item = aux.gui.item(m.frame.parameters)
|
||||
item:SetPoint('TOPLEFT', 6, -6)
|
||||
item:EnableMouse()
|
||||
item:SetScript('OnReceiveDrag', function()
|
||||
local item_info = aux.cursor_item()
|
||||
if item_info then
|
||||
m.select_item(item_info.item_key)
|
||||
end
|
||||
ClearCursor()
|
||||
end)
|
||||
item:SetScript('OnClick', function()
|
||||
local item_info = aux.cursor_item()
|
||||
if item_info then
|
||||
m.select_item(item_info.item_key)
|
||||
end
|
||||
ClearCursor()
|
||||
end)
|
||||
local highlight = item:CreateTexture()
|
||||
highlight:SetPoint('TOPLEFT', -2.5, 2)
|
||||
highlight:SetPoint('BOTTOMRIGHT', 2.5, -2)
|
||||
highlight:Hide()
|
||||
highlight:SetTexture(1, .9, .9, .1)
|
||||
item:SetScript('OnEnter', function()
|
||||
highlight:Show()
|
||||
item.button:EnableMouse(true)
|
||||
item.button:SetScript('OnEnter', function()
|
||||
if m.selected_item then
|
||||
aux.info.set_tooltip(m.selected_item.itemstring, this, 'ANCHOR_RIGHT')
|
||||
end
|
||||
end)
|
||||
item:SetScript('OnLeave', function()
|
||||
highlight:Hide()
|
||||
item.button:SetScript('OnLeave', function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
private.item = item
|
||||
|
||||
+17
-2
@@ -144,17 +144,32 @@ function m.LOAD()
|
||||
m.current_search().placeholder = true
|
||||
end
|
||||
|
||||
function public.OPEN()
|
||||
function m.OPEN()
|
||||
m.frame:Show()
|
||||
m.update_search_listings()
|
||||
end
|
||||
|
||||
function public.CLOSE()
|
||||
function m.CLOSE()
|
||||
m.close_settings()
|
||||
m.current_search().table:SetSelectedRecord()
|
||||
m.frame:Hide()
|
||||
end
|
||||
|
||||
function m.CLICK_LINK(item_info)
|
||||
m.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.execute(nil, false)
|
||||
end
|
||||
|
||||
function m.PICKUP_ITEM(item_info)
|
||||
m.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.execute(nil, false)
|
||||
end
|
||||
|
||||
function m.USE_ITEM(item_info)
|
||||
m.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.execute(nil, false)
|
||||
end
|
||||
|
||||
function private.update_search_listings()
|
||||
local favorite_search_rows = {}
|
||||
for i, favorite_search in aux_favorite_searches do
|
||||
|
||||
@@ -243,14 +243,6 @@ aux.search_tab.FRAMES(function(m, public, private)
|
||||
this:HighlightText(0, 0)
|
||||
end)
|
||||
editbox:SetScript('OnEnterPressed', m.execute)
|
||||
editbox:SetScript('OnReceiveDrag', function()
|
||||
local item_info = aux.cursor_item() and aux.info.item(aux.cursor_item().item_id)
|
||||
if item_info then
|
||||
m.set_filter(strlower(item_info.name)..'/exact')
|
||||
m.execute(nil, false)
|
||||
end
|
||||
ClearCursor()
|
||||
end)
|
||||
private.search_box = editbox
|
||||
end
|
||||
do
|
||||
|
||||
Reference in New Issue
Block a user