big refactoring
This commit is contained in:
+10
-11
@@ -10,7 +10,7 @@ game_tooltip_money = nil
|
|||||||
function LOAD()
|
function LOAD()
|
||||||
for func, hook in game_tooltip_hooks do
|
for func, hook in game_tooltip_hooks do
|
||||||
local func, hook = func, hook
|
local func, hook = func, hook
|
||||||
hook(
|
_m.hook(
|
||||||
func,
|
func,
|
||||||
function(...)
|
function(...)
|
||||||
hooked_setter = true
|
hooked_setter = true
|
||||||
@@ -211,24 +211,23 @@ function game_tooltip_hooks:SetCraftItem(skill, slot)
|
|||||||
else
|
else
|
||||||
link, quantity = GetCraftItemLink(skill), 1
|
link, quantity = GetCraftItemLink(skill), 1
|
||||||
end
|
end
|
||||||
if link then extend_tooltip(GameTooltip, link, quantity) end
|
if link then
|
||||||
|
extend_tooltip(GameTooltip, link, quantity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function game_tooltip_hooks:SetCraftSpell(slot)
|
function game_tooltip_hooks:SetCraftSpell(slot)
|
||||||
local link = GetCraftItemLink(slot)
|
if x(GetCraftItemLink(slot)) then
|
||||||
if link then
|
extend_tooltip(GameTooltip, __, 1)
|
||||||
extend_tooltip(GameTooltip, link, 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
|
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
|
||||||
local link, quantity
|
local link, quantity
|
||||||
if slot then
|
if slot then
|
||||||
link = GetTradeSkillReagentItemLink(skill, slot)
|
link, quantity = GetTradeSkillReagentItemLink(skill, slot), select(3, GetTradeSkillReagentInfo(skill, slot))
|
||||||
quantity = ({GetTradeSkillReagentInfo(skill, slot)})[3]
|
|
||||||
else
|
else
|
||||||
link = GetTradeSkillItemLink(skill)
|
link, quantity = GetTradeSkillItemLink(skill), 1
|
||||||
quantity = 1
|
|
||||||
end
|
end
|
||||||
if link then
|
if link then
|
||||||
extend_tooltip(GameTooltip, link, quantity)
|
extend_tooltip(GameTooltip, link, quantity)
|
||||||
@@ -236,11 +235,11 @@ function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function game_tooltip_hooks:SetAuctionSellItem()
|
function game_tooltip_hooks:SetAuctionSellItem()
|
||||||
local name, _, quantity, _, _, _ = GetAuctionSellItemInfo()
|
local name, _, quantity = GetAuctionSellItemInfo()
|
||||||
if name then
|
if name then
|
||||||
for slot in inventory do
|
for slot in inventory do
|
||||||
local link = GetContainerItemLink(unpack(slot))
|
local link = GetContainerItemLink(unpack(slot))
|
||||||
if link and ({info.parse_link(link)})[5] == name then
|
if link and select(5, info.parse_link(link)) == name then
|
||||||
extend_tooltip(GameTooltip, link, quantity)
|
extend_tooltip(GameTooltip, link, quantity)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ function LOAD()
|
|||||||
local frame = CreateFrame('Frame', gui.name, UIParent)
|
local frame = CreateFrame('Frame', gui.name, UIParent)
|
||||||
tinsert(UISpecialFrames, 'aux_frame1')
|
tinsert(UISpecialFrames, 'aux_frame1')
|
||||||
gui.set_window_style(frame)
|
gui.set_window_style(frame)
|
||||||
frame:SetWidth(768)
|
gui.set_size(frame, 768, 447)
|
||||||
frame:SetHeight(447)
|
|
||||||
frame:SetPoint('LEFT', 100, 0)
|
frame:SetPoint('LEFT', 100, 0)
|
||||||
frame:SetToplevel(true)
|
frame:SetToplevel(true)
|
||||||
frame:SetMovable(true)
|
frame:SetMovable(true)
|
||||||
@@ -36,8 +35,7 @@ function LOAD()
|
|||||||
do
|
do
|
||||||
local btn = gui.button(frame, 16)
|
local btn = gui.button(frame, 16)
|
||||||
btn:SetPoint('BOTTOMRIGHT', -6, 6)
|
btn:SetPoint('BOTTOMRIGHT', -6, 6)
|
||||||
btn:SetWidth(65)
|
gui.set_size(btn, 65, 24)
|
||||||
btn:SetHeight(24)
|
|
||||||
btn:SetText 'Close'
|
btn:SetText 'Close'
|
||||||
btn:SetScript('OnClick', L(frame.Hide, frame))
|
btn:SetScript('OnClick', L(frame.Hide, frame))
|
||||||
public.close_button = btn
|
public.close_button = btn
|
||||||
@@ -45,8 +43,7 @@ function LOAD()
|
|||||||
do
|
do
|
||||||
local btn = gui.button(frame, 16)
|
local btn = gui.button(frame, 16)
|
||||||
btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0)
|
btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0)
|
||||||
btn:SetWidth(65)
|
gui.set_size(btn, 65, 24)
|
||||||
btn:SetHeight(24)
|
|
||||||
btn:SetText 'Default UI'
|
btn:SetText 'Default UI'
|
||||||
btn:SetScript('OnClick',function()
|
btn:SetScript('OnClick',function()
|
||||||
if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end
|
if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end
|
||||||
|
|||||||
@@ -524,8 +524,7 @@ end
|
|||||||
|
|
||||||
function public.item(parent)
|
function public.item(parent)
|
||||||
local item = CreateFrame('Frame', nil, parent)
|
local item = CreateFrame('Frame', nil, parent)
|
||||||
item:SetWidth(260)
|
set_size(item, 260, 40)
|
||||||
item:SetHeight(40)
|
|
||||||
local btn = CreateFrame('CheckButton', name, item, 'ActionButtonTemplate')
|
local btn = CreateFrame('CheckButton', name, item, 'ActionButtonTemplate')
|
||||||
item.button = btn
|
item.button = btn
|
||||||
btn:SetPoint('LEFT', 2, .5)
|
btn:SetPoint('LEFT', 2, .5)
|
||||||
|
|||||||
+23
-24
@@ -1,15 +1,16 @@
|
|||||||
local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
|
local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
|
||||||
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16
|
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR, INITIALIZED = 0, 1, 2, 4, 8, 16, 32
|
||||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, accessor=ACCESSOR+PROPERTY, mutator=MUTATOR+PROPERTY}
|
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, accessor=ACCESSOR+PROPERTY, mutator=MUTATOR+PROPERTY}
|
||||||
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+ACCESSOR+MUTATOR, public=MUTABLE+ACCESSOR+MUTATOR, mutable=PRIVATE+PUBLIC, accessor=PRIVATE+PUBLIC, mutator=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+ACCESSOR+MUTATOR, public=MUTABLE+ACCESSOR+MUTATOR, mutable=PRIVATE+PUBLIC, accessor=PRIVATE+PUBLIC, mutator=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
||||||
local error, declaration_error, immutable_error, collision_error, void_error, set_property, lock_mt, env_mt, interface_mt, declarator_mt, importer_mt
|
local error, modifier_error, property_error, immutable_error, collision_error, null_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt
|
||||||
lock_mt = {}
|
local _state, _modules = {}, {}
|
||||||
local _state, _modules = {}, setmetatable({}, lock_mt)
|
local NULL = setmetatable({}, {__metatable=false, __index=error'NULL', __newindex=error'NULL'})
|
||||||
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
|
function error(message, ...) return function() _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 10, 0)) end end
|
||||||
function declaration_error(level) error('Malformed declaration.', level + 1) end
|
modifier_error = error 'Invalid modifiers.'
|
||||||
function immutable_error(key, level) error('Field "%s" is immutable.', level + 1, key) end
|
property_error = error 'Accessor/Mutator must be function.'
|
||||||
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
function immutable_error(key) return error('Field "%s" is immutable.', key) end
|
||||||
function void_error(key, level) error('No field "%s".', level + 1, key) end
|
function collision_error(key) return error('Field "%s" already exists.', key) end
|
||||||
|
function null_error(key) error('No field "%s".', key) end
|
||||||
importer_mt = {__metatable=false}
|
importer_mt = {__metatable=false}
|
||||||
function importer_mt.__index(self, key) _state[self][self] = key; return self end
|
function importer_mt.__index(self, key) _state[self][self] = key; return self end
|
||||||
function importer_mt.__call(self, arg1, arg2)
|
function importer_mt.__call(self, arg1, arg2)
|
||||||
@@ -31,7 +32,7 @@ function importer_mt.__call(self, arg1, arg2)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
function set_property(data, property, value)
|
function set_property(data, property, value)
|
||||||
if property and not data[property] and type(value) == 'function' or declaration_error(2) then
|
if property and not data[property] and type(value) == 'function' or property_error() then
|
||||||
data[property] = value
|
data[property] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -39,20 +40,20 @@ declarator_mt = {__metatable=false}
|
|||||||
function declarator_mt.__index(self, key)
|
function declarator_mt.__index(self, key)
|
||||||
local state, modifier = _state[self], MODIFIER[key]; local modifiers = state.modifiers
|
local state, modifier = _state[self], MODIFIER[key]; local modifiers = state.modifiers
|
||||||
if modifier then
|
if modifier then
|
||||||
if mask(MODIFIER_MASK[key], modifiers) ~= modifiers then declaration_error(2) end
|
if mask(MODIFIER_MASK[key], modifiers) ~= modifiers then modifier_error() end
|
||||||
state.modifiers = modifiers + modifier; return self
|
state.modifiers = modifiers + modifier; return self
|
||||||
elseif not state.metadata[key] or collision_error(key, 2) then
|
elseif not state.metadata[key] or collision_error(key) then
|
||||||
if mask(PROPERTY_MASK, modifiers) ~= modifiers then declaration_error(2) end
|
if mask(PROPERTY_MASK, modifiers) ~= modifiers then modifier_error() end
|
||||||
state.property, state.metadata[key], state.modifiers = key, modifiers + PROPERTY, PRIVATE
|
state.property, state.metadata[key], state.modifiers = key, modifiers + PROPERTY, PRIVATE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function declarator_mt.__newindex(self, key, value)
|
function declarator_mt.__newindex(self, key, value)
|
||||||
local state = _state[self]
|
local state = _state[self]
|
||||||
if state.metadata[key] then collision_error(key, 2) end
|
if state.metadata[key] then collision_error(key) end
|
||||||
state.metadata[key] = state.modifiers
|
state.metadata[key] = state.modifiers
|
||||||
if mask(PROPERTY, state.modifiers) == 0 then
|
if mask(PROPERTY, state.modifiers) == 0 then
|
||||||
state.data[key] = value
|
state.data[key] = value
|
||||||
elseif type(value) == 'function' or declaration_error(2) then
|
elseif type(value) == 'function' or property_error() then
|
||||||
local data = mask(ACCESSOR, state.modifiers) ~= 0 and state.accessors or state.mutators
|
local data = mask(ACCESSOR, state.modifiers) ~= 0 and state.accessors or state.mutators
|
||||||
state.property, data[key] = key, value
|
state.property, data[key] = key, value
|
||||||
end
|
end
|
||||||
@@ -67,7 +68,7 @@ do
|
|||||||
return state.data[key]
|
return state.data[key]
|
||||||
else
|
else
|
||||||
local accessor = state.accessors[key]
|
local accessor = state.accessors[key]
|
||||||
if accessor then return accessor() else return default[key] or void_error(key, 2) end
|
if accessor then return accessor() else return default[key] or null_error(key) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -77,7 +78,7 @@ do
|
|||||||
if modifiers then
|
if modifiers then
|
||||||
local mutator = state.mutators[key]
|
local mutator = state.mutators[key]
|
||||||
if mutator then return mutator(value) end
|
if mutator then return mutator(value) end
|
||||||
if mask(MUTABLE, modifiers) == 0 then immutable_error(key, 2) end
|
if mask(MUTABLE, modifiers) == 0 then immutable_error(key) end
|
||||||
else
|
else
|
||||||
state.metadata[key] = state.modifiers
|
state.metadata[key] = state.modifiers
|
||||||
end
|
end
|
||||||
@@ -85,10 +86,10 @@ do
|
|||||||
end
|
end
|
||||||
interface_mt = {__metatable=false, __index=index(PUBLIC, {})}
|
interface_mt = {__metatable=false, __index=index(PUBLIC, {})}
|
||||||
function interface_mt.__newindex(self, key, value)
|
function interface_mt.__newindex(self, key, value)
|
||||||
local state = _state[self]; local metadata = state.metadata or void_error(key, 2)
|
local state = _state[self]; local metadata = state.metadata or null_error(key)
|
||||||
if mask(PUBLIC+MUTATOR, metadata) == PUBLIC+MUTATOR then
|
if mask(PUBLIC+MUTATOR, metadata) == PUBLIC+MUTATOR then
|
||||||
return state.mutators[key](value)
|
return state.mutators[key](value)
|
||||||
elseif mask(PUBLIC, metadata) == PUBLIC or immutable_error(key, 2) then
|
elseif mask(PUBLIC, metadata) == PUBLIC or immutable_error(key) then
|
||||||
state.data[key] = value
|
state.data[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -105,13 +106,11 @@ function module(name)
|
|||||||
mutators = {accessor=function(value) set_property(accessors, state.property, value) end, mutator=function(value) set_property(mutators, state.property, value) end}
|
mutators = {accessor=function(value) set_property(accessors, state.property, value) end, mutator=function(value) set_property(mutators, state.property, value) end}
|
||||||
state = {
|
state = {
|
||||||
env=env, interface=interface, modifiers=PRIVATE,
|
env=env, interface=interface, modifiers=PRIVATE,
|
||||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+ACCESSOR, public=PROPERTY+ACCESSOR, mutable=PROPERTY+ACCESSOR, accessor=PROPERTY+ACCESSOR+MUTATOR, mutator=PROPERTY+ACCESSOR+MUTATOR}, lock_mt),
|
metadata = {NULL=PRIVATE, _g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+ACCESSOR, public=PROPERTY+ACCESSOR, mutable=PROPERTY+ACCESSOR, accessor=PROPERTY+ACCESSOR+MUTATOR, mutator=PROPERTY+ACCESSOR+MUTATOR},
|
||||||
data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators,
|
data = {NULL=NULL, _g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators,
|
||||||
}
|
}
|
||||||
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
|
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
|
||||||
setfenv(INIT, env); INIT()
|
setfenv(INIT, env); INIT()
|
||||||
end
|
end
|
||||||
setfenv(2, _modules[name].env)
|
setfenv(2, _modules[name].env)
|
||||||
end
|
end
|
||||||
local frame = CreateFrame 'Frame'; frame:RegisterEvent 'PLAYER_LOGIN'
|
|
||||||
frame:SetScript('OnEvent', function() lock_mt.__newindex = function() error 'Modules are frozen after the loading phase.' end end)
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'auction_listing'
|
module 'auction_listing' import 'gui'
|
||||||
|
|
||||||
_g.aux_price_per_unit = false
|
_g.aux_price_per_unit = false
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'auctions_tab'
|
module 'auctions_tab' import 'gui'
|
||||||
|
|
||||||
function create_frames()
|
function create_frames()
|
||||||
frame = CreateFrame('Frame', nil, frame)
|
frame = CreateFrame('Frame', nil, frame)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'bids_tab'
|
module 'bids_tab' import 'gui'
|
||||||
|
|
||||||
function create_frames()
|
function create_frames()
|
||||||
frame = CreateFrame('Frame', nil, frame)
|
frame = CreateFrame('Frame', nil, frame)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'post_tab'
|
module 'post_tab' import 'gui'
|
||||||
|
|
||||||
function create_frames()
|
function create_frames()
|
||||||
frame = CreateFrame('Frame', nil, frame)
|
frame = CreateFrame('Frame', nil, frame)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module 'search_tab'
|
module 'search_tab' import 'gui'
|
||||||
|
|
||||||
FILTER_SPACING = 28.5
|
FILTER_SPACING = 28.5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user