refactoring, change of pickup/use behavior

This commit is contained in:
Manuel Simon Hirsig
2016-08-07 23:06:31 +02:00
parent c3447aedd2
commit abc163d7f3
10 changed files with 108 additions and 143 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ function private.post_auction(slot, k)
ClearCursor() ClearCursor()
ClickAuctionSellItemButton() ClickAuctionSellItemButton()
ClearCursor() ClearCursor()
PickupContainerItem(unpack(slot)) aux.orig.PickupContainerItem(unpack(slot))
ClickAuctionSellItemButton() ClickAuctionSellItemButton()
ClearCursor() ClearCursor()
+1 -1
View File
@@ -61,7 +61,7 @@ function private.move_item(from_slot, to_slot, amount, k)
ClearCursor() ClearCursor()
SplitContainerItem(from_slot[1], from_slot[2], amount) 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) return aux.control.when(function() return m.stack_size(to_slot) == expected_size end, k)
end end
+60 -90
View File
@@ -2,6 +2,37 @@ local addon = aux_module()
aux = tremove(addon, 1) aux = tremove(addon, 1)
local m, public, private = unpack(addon) 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 = {} private.modules = {}
function private.initialize_module(public_declarator) function private.initialize_module(public_declarator)
public_declarator.LOAD = nil public_declarator.LOAD = nil
@@ -17,20 +48,21 @@ end
private.tabs = {} private.tabs = {}
function public.tab(index, name) function public.tab(index, name)
local ret = { m.module(name) } local tab = {m.module(name)}
ret[2].ACTIVE = function() tab[2].ACTIVE = function()
return m[name] == m.active_tab() return m[name] == m.active_tab()
end end
for _, handler in {'OPEN', 'CLOSE', 'CLICK_LINK', 'PICKUP_ITEM', 'USE_ITEM'} do
tab[2][handler] = nil
end
m.tabs[index] = m[name] m.tabs[index] = m[name]
return unpack(ret) return unpack(tab)
end end
do do
local active_tab_index local active_tab_index
function private.active_tab() private.active_tab = m.dynamic_table(function()
if active_tab_index then return m.tabs[active_tab_index]
return m.tabs[active_tab_index] end)
end
end
function private.on_tab_click(index) function private.on_tab_click(index)
if m.active_tab() then if m.active_tab() then
m.active_tab().CLOSE() m.active_tab().CLOSE()
@@ -104,37 +136,6 @@ do
end end
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, ...) function public.call(f, ...)
if f then if f then
return f(unpack(arg)) return f(unpack(arg))
@@ -162,8 +163,6 @@ function public.on_load()
aux.gui.set_window_style(AuxFrame) aux.gui.set_window_style(AuxFrame)
tinsert(UISpecialFrames, 'AuxFrame') tinsert(UISpecialFrames, 'AuxFrame')
aux.control.event_listener('CURSOR_UPDATE', m.CURSOR_UPDATE)
do do
local tab_group = m.gui.tab_group(AuxFrame, 'DOWN') local tab_group = m.gui.tab_group(AuxFrame, 'DOWN')
tab_group:create_tab('Search') tab_group:create_tab('Search')
@@ -427,63 +426,34 @@ function public.price_level_color(pct)
end end
end end
do -- TODO make it work for other ways to pick up things function private.SetItemRef(...)
local last_picked_up if not arg[3] == 'RightButton' or not m.active_tab.CLICK_LINK or not strfind(arg[1], '^item:%d+') then
function private.CURSOR_UPDATE() return m.orig.SetItemRef(unpack(arg))
last_picked_up = nil end
end local item_info = m.info.item(tonumber(({strfind(arg[1], '^item:(%d+)')})[3]))
function private.PickupContainerItem(...) if item_info then
local bag, slot = unpack(arg) return m.active_tab.CLICK_LINK(item_info)
aux.control.thread(function() end
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
end end
function private.SetItemRef(...) function private.PickupContainerItem(...)
local itemstring, text, button = unpack(arg) if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() or not m.active_tab.PICKUP_ITEM then
if m.search_tab.ACTIVE() and button == 'RightButton' then return m.orig.PickupContainerItem(unpack(arg))
local item_info = m.info.item(tonumber(({strfind(itemstring, '^item:(%d+)')})[3])) end
if item_info then local item_info = m.info.container_item(arg[1], arg[2])
m.search_tab.set_filter(strlower(item_info.name)..'/exact') if item_info then
m.search_tab.execute(nil, false) return m.active_tab.PICKUP_ITEM(item_info)
return end
end
end
return m.orig.SetItemRef(unpack(arg))
end end
function private.UseContainerItem(...) function private.UseContainerItem(...)
local bag, slot = unpack(arg) if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() or not m.active_tab.USE_ITEM then
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
return m.orig.UseContainerItem(unpack(arg)) return m.orig.UseContainerItem(unpack(arg))
end end
local item_info = m.info.container_item(arg[1], arg[2])
if m.search_tab.ACTIVE() then if item_info then
local item_info = m.info.container_item(bag, slot) return m.active_tab.USE_ITEM(item_info)
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
end 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 end
function public.is_player(name, current) function public.is_player(name, current)
+11 -10
View File
@@ -410,21 +410,22 @@ function public.status_bar(parent)
end end
function public.item(parent) function public.item(parent)
local item = CreateFrame('Button', nil, parent) local item = CreateFrame('Frame', nil, parent)
item:SetWidth(260) item:SetWidth(260)
item:SetHeight(40) item:SetHeight(40)
local icon = CreateFrame('CheckButton', 'aux_frame'..aux.id(), item, 'ActionButtonTemplate') local btn = CreateFrame('CheckButton', 'aux_frame'..aux.id(), item, 'ActionButtonTemplate')
icon:SetPoint('LEFT', 2, 0.5) item.button = btn
icon:SetHighlightTexture(nil) btn:SetPoint('LEFT', 2, 0.5)
icon:RegisterForClicks() btn:SetHighlightTexture(nil)
icon:EnableMouse(nil) btn:RegisterForClicks()
item.texture = getglobal(icon:GetName()..'Icon') btn:EnableMouse(nil)
item.texture = getglobal(btn:GetName()..'Icon')
item.texture:SetTexCoord(0.06,0.94,0.06,0.94) 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: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.name:SetPoint('RIGHT', item, 'RIGHT', -10, 0.5)
item.count = getglobal(icon:GetName()..'Count') item.count = getglobal(btn:GetName()..'Count')
item.count:SetTextHeight(17) item.count:SetTextHeight(17)
return item return item
end end
+2 -2
View File
@@ -10,12 +10,12 @@ function m.LOAD()
m.create_frames(m, public, private) m.create_frames(m, public, private)
end end
function public.OPEN() function m.OPEN()
m.frame:Show() m.frame:Show()
m.scan_auctions() m.scan_auctions()
end end
function public.CLOSE() function m.CLOSE()
m.frame:Hide() m.frame:Hide()
end end
+2 -2
View File
@@ -10,12 +10,12 @@ function m.LOAD()
m.create_frames(m, public, private) m.create_frames(m, public, private)
end end
function public.OPEN() function m.OPEN()
m.frame:Show() m.frame:Show()
m.scan_bids() m.scan_bids()
end end
function public.CLOSE() function m.CLOSE()
m.frame:Hide() m.frame:Hide()
end end
+11 -3
View File
@@ -17,7 +17,7 @@ function m.LOAD()
m.create_frames(m, public, private) m.create_frames(m, public, private)
end end
function public.OPEN() function m.OPEN()
m.frame:Show() m.frame:Show()
m.deposit:SetText('Deposit: '..aux.money.to_string(0, nil, nil, nil, aux.gui.inline_color.text.enabled)) 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 m.refresh = true
end end
function public.CLOSE() function m.CLOSE()
m.selected_item = nil m.selected_item = nil
m.frame:Hide() m.frame:Hide()
end 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() function private.default_settings()
return { return {
duration = DURATION_8, 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 if aux.info.auctionable(item_info.tooltip, nil, item_info.lootable) then
ClearCursor() ClearCursor()
PickupContainerItem(unpack(slot)) aux.orig.PickupContainerItem(unpack(slot))
ClickAuctionSellItemButton() ClickAuctionSellItemButton()
local auction_sell_item = aux.info.auction_sell_item() local auction_sell_item = aux.info.auction_sell_item()
ClearCursor() ClearCursor()
+3 -24
View File
@@ -118,34 +118,13 @@ aux.post_tab.FRAMES(function(m, public, private)
do do
local item = aux.gui.item(m.frame.parameters) local item = aux.gui.item(m.frame.parameters)
item:SetPoint('TOPLEFT', 6, -6) item:SetPoint('TOPLEFT', 6, -6)
item:EnableMouse() item.button:EnableMouse(true)
item:SetScript('OnReceiveDrag', function() item.button:SetScript('OnEnter', 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()
if m.selected_item then if m.selected_item then
aux.info.set_tooltip(m.selected_item.itemstring, this, 'ANCHOR_RIGHT') aux.info.set_tooltip(m.selected_item.itemstring, this, 'ANCHOR_RIGHT')
end end
end) end)
item:SetScript('OnLeave', function() item.button:SetScript('OnLeave', function()
highlight:Hide()
GameTooltip:Hide() GameTooltip:Hide()
end) end)
private.item = item private.item = item
+17 -2
View File
@@ -144,17 +144,32 @@ function m.LOAD()
m.current_search().placeholder = true m.current_search().placeholder = true
end end
function public.OPEN() function m.OPEN()
m.frame:Show() m.frame:Show()
m.update_search_listings() m.update_search_listings()
end end
function public.CLOSE() function m.CLOSE()
m.close_settings() m.close_settings()
m.current_search().table:SetSelectedRecord() m.current_search().table:SetSelectedRecord()
m.frame:Hide() m.frame:Hide()
end 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() function private.update_search_listings()
local favorite_search_rows = {} local favorite_search_rows = {}
for i, favorite_search in aux_favorite_searches do for i, favorite_search in aux_favorite_searches do
-8
View File
@@ -243,14 +243,6 @@ aux.search_tab.FRAMES(function(m, public, private)
this:HighlightText(0, 0) this:HighlightText(0, 0)
end) end)
editbox:SetScript('OnEnterPressed', m.execute) 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 private.search_box = editbox
end end
do do