diff --git a/components/cache.lua b/components/cache.lua index 16bd47e..ceea720 100644 --- a/components/cache.lua +++ b/components/cache.lua @@ -13,7 +13,7 @@ aux_merchant_buy = {} aux_merchant_sell = {} aux_characters = {} -function public.LOAD() +function m.LOAD() m.scan_wdb() aux.control.event_listener('MERCHANT_SHOW', m.on_merchant_show) diff --git a/components/disenchant.lua b/components/disenchant.lua index a951369..32bbbf8 100644 --- a/components/disenchant.lua +++ b/components/disenchant.lua @@ -40,7 +40,7 @@ do end end -function public.LOAD() +function m.LOAD() private.armor = aux.util.set( 'INVTYPE_HEAD', 'INVTYPE_NECK', diff --git a/components/scan.lua b/components/scan.lua index 8e9f9c7..a3ea7b0 100644 --- a/components/scan.lua +++ b/components/scan.lua @@ -9,7 +9,7 @@ do for _, old_state in {scan_states[params.type]} do m.abort(old_state.id) end - local thread_id = aux.control.thread(aux.f(m.wait_for_callback, params.on_scan_start, m.scan)) + local thread_id = aux.control.thread(aux._(m.wait_for_callback, params.on_scan_start, m.scan)) scan_states[params.type] = { id = thread_id, params = params, @@ -27,14 +27,14 @@ do end end for _, state in aborted do - aux.safe_call(state.params.on_abort) + aux.call(state.params.on_abort) end end function private.complete() local on_complete = m.state.params.on_complete scan_states[m.state.params.type] = nil - aux.safe_call(on_complete) + aux.call(on_complete) end private.state = aux.dynamic_table(function() @@ -103,7 +103,7 @@ end function private.submit_query() aux.control.when(function() return m.state.params.type ~= 'list' or CanSendAuctionQuery() end, function() - aux.safe_call(m.state.params.on_submit_query) + aux.call(m.state.params.on_submit_query) m.state.last_query_time = GetTime() if m.state.params.type == 'bidder' then GetBidderAuctionItems(m.state.page) @@ -153,11 +153,11 @@ function private.scan_page(i) aux.history.process_auction(auction_info) - if aux.safe_call(m.state.params.auto_buy_validator, auction_info) then + if aux.call(m.state.params.auto_buy_validator, auction_info) then local send_signal, signal_received = aux.util.signal() aux.control.when(signal_received, recurse) - aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, aux.f(send_signal, true)) - return aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux.f(send_signal, false)) + aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, aux._(send_signal, true)) + return aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux._(send_signal, false)) elseif not m.query.validator or m.query.validator(auction_info) then return m.wait_for_callback(m.state.params.on_auction, auction_info, function(removed) if removed then diff --git a/components/stack.lua b/components/stack.lua index e1f936d..6188dcf 100644 --- a/components/stack.lua +++ b/components/stack.lua @@ -111,7 +111,7 @@ function public.stop() slot = nil end m.state = nil - aux.safe_call(callback, slot) + aux.call(callback, slot) end end diff --git a/components/tooltip.lua b/components/tooltip.lua index cfb8040..dd72455 100644 --- a/components/tooltip.lua +++ b/components/tooltip.lua @@ -6,7 +6,7 @@ private.game_tooltip_hooks = {} private.hooked_setter = nil private.game_tooltip_money = nil -function public.LOAD() +function m.LOAD() for func, hook in m.game_tooltip_hooks do local func, hook = func, hook aux.hook( @@ -28,7 +28,7 @@ function public.LOAD() local name, _, quality = GetItemInfo(arg[1]) if not IsShiftKeyDown() and not IsControlKeyDown() and name then local _, _, _, hex = GetItemQualityColor(quality) - local link = hex.. '|H'..arg[1]..'|h['..name..']|h|r' + local link = hex.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE m.extend_tooltip(ItemRefTooltip, link, 1) end return result @@ -131,7 +131,7 @@ function m.game_tooltip_hooks:SetHyperlink(itemstring) local name, _, quality = GetItemInfo(itemstring) if name then local _, _, _, hex = GetItemQualityColor(quality) - local link = hex.. '|H'..itemstring..'|h['..name..']|h|r' + local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE m.extend_tooltip(GameTooltip, link, 1) end end @@ -183,7 +183,7 @@ function m.game_tooltip_hooks:SetInboxItem(index) if id then local _, itemstring, quality = GetItemInfo(id) local _, _, _, hex = GetItemQualityColor(tonumber(quality)) - local link = hex.. '|H'..itemstring..'|h['..name..']|h|r' + local link = hex.. '|H'..itemstring..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE m.extend_tooltip(GameTooltip, link, quantity) end end diff --git a/control.lua b/control.lua index b51bb92..991ea95 100644 --- a/control.lua +++ b/control.lua @@ -5,7 +5,7 @@ private.listeners = {} private.threads = {} public.thread_id = nil -function public.LOAD() +function m.LOAD() m.event_frame:SetScript('OnUpdate', m.on_update) m.event_frame:SetScript('OnEvent', m.on_event) end @@ -55,7 +55,7 @@ function public.kill_thread(thread_id) end function public.event_listener(event, cb) - local listener_id = aux.unique() + local listener_id = aux.id() m.listeners[listener_id] = { event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then m.kill_listener(listener_id) end end } m.event_frame:RegisterEvent(event) return listener_id @@ -69,8 +69,8 @@ function public.on_next_event(event, callback) end function public.thread(k, ...) - local thread_id = aux.unique() - m.threads[thread_id] = { k = aux.f(k, unpack(arg)) } + local thread_id = aux.id() + m.threads[thread_id] = { k = aux._(k, unpack(arg)) } return thread_id end @@ -78,7 +78,7 @@ function public.wait(k, ...) if type(k) == 'number' then m.when(function() k = k - 1 return k <= 1 end, unpack(arg)) else - m.threads[m.thread_id].k = aux.f(k, unpack(arg)) + m.threads[m.thread_id].k = aux._(k, unpack(arg)) end end @@ -86,6 +86,6 @@ function public.when(p, k, ...) if p() then return k(unpack(arg)) else - return m.wait(m.when, p, aux.f(k, unpack(arg))) + return m.wait(m.when, p, aux._(k, unpack(arg))) end end diff --git a/core.lua b/core.lua index 67357af..5b9f204 100644 --- a/core.lua +++ b/core.lua @@ -2,13 +2,17 @@ local addon = aux_module() aux = tremove(addon, 1) local m, public, private = unpack(addon) -private.modules = { aux } +private.modules = {} +function private.initialize_module(public_declarator) + public_declarator.LOAD = nil +end +m.initialize_module(public) function public.module(name) - local module = aux_module() - local public_interface = tremove(module, 1) + local public_interface, private_interface, public_declarator, private_declarator = unpack(aux_module()) + m.initialize_module(public_declarator) tinsert(m.modules, public_interface) public[name] = public_interface - return unpack(module) + return private_interface, public_declarator, private_declarator end private.tabs = {} @@ -40,46 +44,104 @@ end do local x = 0 - function public.unique() + function public.id() x = x + 1 return x end end do - local mt = { - __newindex = function(self, key, value) - rawget(self, '_f')()[key] = value - end, - __index = function(self, key) - return rawget(self, '_f')()[key] - end, - __call = function(self) - return rawget(self, '_f')() - end, - } - function public.dynamic_table(f) - return setmetatable({ _f=f }, mt) - end -end - -function public.f(f, ...) - local params = arg - return function(...) - for i=1,arg.n do - tinsert(params, arg[i]) - end - return f(unpack(params)) + local mt = { + __newindex = function(self, name, method) + if strsub(name, 1, 2) == '__' then + self._metatable[name] = method + else + self._methods[name] = method + end + end, + __call = function(self, ...) + setmetatable(self._methods, self._metatable.__index) + self._metatable.__index =self._methods + local object = setmetatable({}, self._metatable) + for name, method in self._methods do + object[name] = method + end + self._constructor(object, unpack(arg)) + return object + end, + } + function public.class(constructor) + return setmetatable({_constructor=constructor, _methods={}, _metatable={}}, mt) end end -function public.safe_call(f, ...) +public.this = {} +do + local formal_parameters = {} + for i=1,9 do + local key = 'arg'..i + public[key] = {} + formal_parameters[m[key]] = i + end + local function call(f, arg1, arg2) + local params = {} + for i=1,arg1.n do + if arg1[i] == m.this then + tinsert(params, this) + elseif formal_parameters[arg1[i]] then + tinsert(params, arg2[formal_parameters[arg1[i]]]) + else + tinsert(params, arg1[i]) + end + end + return f(unpack(params)) + end + function public._(f, ...) + local arg1 = arg + return function(...) + return call(f, arg1, arg) + 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, ...) if f then return f(unpack(arg)) end end -function public.safe_index(t, ...) +function public.index(t, ...) for i=1,arg.n do if t then t = t[arg[i]] @@ -118,7 +180,7 @@ function public.on_load() btn:SetWidth(65) btn:SetHeight(24) btn:SetText('Close') - btn:SetScript('OnClick', m.f(HideUIPanel, AuxFrame)) + btn:SetScript('OnClick', m._(HideUIPanel, AuxFrame)) public.close_button = btn end @@ -138,9 +200,7 @@ function public.on_load() end for _, module in m.modules do - if module('LOAD') then - module.LOAD() - end + m.call(module.LOAD) end end @@ -148,7 +208,7 @@ function public.on_event() if event == 'VARIABLES_LOADED' then m.on_load() elseif event == 'ADDON_LOADED' then - m.safe_call(m.on_addon_load[arg1]) + m.call(m.on_addon_load[arg1]) elseif event == 'AUCTION_HOUSE_SHOW' then m.on_auction_house_show() elseif event == 'AUCTION_HOUSE_CLOSED' then @@ -274,7 +334,7 @@ do m.control.event_listener('CHAT_MSG_SYSTEM', function(kill) if arg1 == ERR_AUCTION_BID_PLACED then - aux.safe_call(on_success) + aux.call(on_success) locked = false kill() end @@ -301,7 +361,7 @@ do CancelAuction(index) m.control.event_listener('CHAT_MSG_SYSTEM', function(kill) if arg1 == ERR_AUCTION_REMOVED then - aux.safe_call(on_success) + aux.call(on_success) locked = false kill() end @@ -428,7 +488,7 @@ end function public.is_player(name, current) local realm = GetCVar('realmName') - return not current and aux.safe_index(aux_characters, realm, name) or UnitName('player') == name + return not current and aux.index(aux_characters, realm, name) or UnitName('player') == name end function public.unmodified() diff --git a/gui.lua b/gui.lua index 48379ae..a4beb92 100644 --- a/gui.lua +++ b/gui.lua @@ -1,44 +1,105 @@ local m, public, private = aux.module'gui' public.config = { - link_color = { 153, 255, 255, 1 }, -- TODO inline color needs 255, others need /255 + color = { + text = {enabled = {255, 254, 250, 1}, disabled = {147, 151, 139, 1}}, + label = {enabled = {216, 225, 211, 1}, disabled = {150, 148, 140, 1}}, + link = {153, 255, 255, 1}, + window = {backdrop = {24, 24, 24, .93}, border = {30, 30, 30, 1}}, + panel = {backdrop = {24, 24, 24, 1}, border = {255, 255, 255, .03}}, + content = {backdrop = {42, 42, 42, 1}, border = {0, 0, 0, 0}}, + state = {enabled = {60, 180, 60}, disabled = {180, 60, 60}}, + }, edge_size = 1.5, - window_color = { backdrop = {24/255, 24/255, 24/255, .93}, border = {30/255, 30/255, 30/255, 1} }, - panel_color = { backdrop = {24/255, 24/255, 24/255, 1}, border = {1, 1, 1, .03} }, - content_color = { backdrop = {42/255, 42/255, 42/255, 1}, border = {0, 0, 0, 0} }, font = [[Fonts\ARIALN.TTF]], tiny_font_size = 12, small_font_size = 13, medium_font_size = 15, large_font_size = 18, huge_font_size = 23, - text_color = { enabled = { 255/255, 254/255, 250/255, 1 }, disabled = { 147/255, 151/255, 139/255, 1 } }, - label_color = { enabled = { 216/255, 225/255, 211/255, 1 }, disabled = { 150/255, 148/255, 140/255, 1 } }, - on_color = {0.3, 0.7, 0.3}, - off_color = {0.7, 0.3, 0.3}, } -function public.inline_color(color) - local r, g, b, a = unpack(color) - return format('|c%02X%02X%02X%02X', a, r, g, b) +public.color = aux.index_function(function(self, key) + self._t = (rawget(self, '_t') or m.config.color)[key] + if getn(self._t) == 0 then + return self + end + local color = aux.util.copy(self._t) + self._t = nil + for i=1,3 do + color[i] = color[i]/255 + end + return color +end) + +public.inline_color = aux.index_function(function(self, key) + self._t = (rawget(self, '_t') or m.config.color)[key] + if getn(self._t) == 0 then + return self + end + local color = aux.util.copy(self._t) + self._t = nil + tinsert(color, 1, tremove(color)) + return format('|c%02X%02X%02X%02X', unpack(color)) +end) + +function m.LOAD() + + aux.hook('ToggleDropDownMenu', function(...) + local ret = {aux.orig.ToggleDropDownMenu(unpack(arg))} + local dropdown = getglobal(arg[4] or '') or this:GetParent() + if strfind(dropdown:GetName() or '', 'aux_frame') then + m.set_content_style(DropDownList1Backdrop) + DropDownList1:SetWidth(dropdown:GetWidth() * 0.9) + DropDownList1:SetHeight(DropDownList1:GetHeight() - 8) + DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, 0) + for i=1,UIDROPDOWNMENU_MAXBUTTONS do + local button = getglobal('DropDownList1Button'..i) + button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 8) + button:SetWidth(dropdown:GetWidth() - 30) + local text = button:GetFontString() + text:SetFont(m.config.font, m.config.medium_font_size) + text:SetPoint('TOPLEFT', 18, 0) + text:SetPoint('BOTTOMRIGHT', -8, 0) + local highlight = getglobal('DropDownList1Button'..i..'Highlight') + highlight:ClearAllPoints() + highlight:SetDrawLayer('OVERLAY') + highlight:SetHeight(14) + highlight:SetPoint('LEFT', 5, 0) + highlight:SetPoint('RIGHT', -3, 0) + local check = getglobal('DropDownList1Button'..i..'Check') + check:SetWidth(16) + check:SetHeight(16) + check:SetPoint('LEFT', 3, -1) + end + while getn(arg) < 4 do + tinsert(arg, nil) + end + tinsert(arg, 0) + tinsert(arg, 10) + + end + return unpack(ret) + end) + end function public.set_frame_style(frame, backdrop_color, border_color) - frame:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size, tile=true} - frame:SetBackdropColor(unpack(backdrop_color)) - frame:SetBackdropBorderColor(unpack(border_color)) + frame:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size, tile=true} + frame:SetBackdropColor(unpack(backdrop_color)) + frame:SetBackdropBorderColor(unpack(border_color)) end function public.set_window_style(frame) - m.set_frame_style(frame, m.config.window_color.backdrop, m.config.window_color.border) + m.set_frame_style(frame, m.color.window.backdrop, m.color.window.border) end function public.set_panel_style(frame) - m.set_frame_style(frame, m.config.panel_color.backdrop, m.config.panel_color.border) + m.set_frame_style(frame, m.color.panel.backdrop, m.color.panel.border) end function public.set_content_style(frame) - m.set_frame_style(frame, m.config.content_color.backdrop, m.config.content_color.border) + m.set_frame_style(frame, m.color.content.backdrop, m.color.content.border) end function public.panel(parent) @@ -50,13 +111,13 @@ end function public.checkbutton(parent, text_height) local button = m.button(parent, text_height) button.state = false - button:SetBackdropColor(unpack(m.config.off_color)) + button:SetBackdropColor(unpack(m.color.state.disabled)) function button:SetChecked(state) if state then - self:SetBackdropColor(unpack(m.config.on_color)) + self:SetBackdropColor(unpack(m.color.state.enabled)) self.state = true else - self:SetBackdropColor(unpack(m.config.off_color)) + self:SetBackdropColor(unpack(m.color.state.disabled)) self.state = false end end @@ -82,17 +143,17 @@ function public.button(parent, text_height) label:SetJustifyH('CENTER') label:SetJustifyV('CENTER') label:SetHeight(text_height) - label:SetTextColor(unpack(m.config.text_color.enabled)) + label:SetTextColor(unpack(m.color.text.enabled)) button:SetFontString(label) end button.default_Enable = button.Enable function button:Enable() - self:GetFontString():SetTextColor(unpack(m.config.text_color.enabled)) + self:GetFontString():SetTextColor(unpack(m.color.text.enabled)) return self:default_Enable() end button.default_Disable = button.Disable function button:Disable() - self:GetFontString():SetTextColor(unpack(m.config.text_color.disabled)) + self:GetFontString():SetTextColor(unpack(m.color.text.disabled)) return self:default_Disable() end @@ -121,7 +182,6 @@ do id = id, frame = parent, tabs = {}, - on_select = aux.util.pass, } function self:create_tab(text) @@ -132,7 +192,7 @@ do tab.group = self tab:SetHeight(24) tab:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size} - tab:SetBackdropBorderColor(unpack(m.config.panel_color.border)) + tab:SetBackdropBorderColor(unpack(m.color.panel.border)) local dock = tab:CreateTexture(nil, 'OVERLAY') dock:SetHeight(3) if orientation == 'UP' then @@ -142,7 +202,7 @@ do dock:SetPoint('TOPLEFT', 1, 1) dock:SetPoint('TOPRIGHT', -1, 1) end - dock:SetTexture(unpack(m.config.panel_color.backdrop)) + dock:SetTexture(unpack(m.color.panel.backdrop)) tab.dock = dock local highlight = tab:CreateTexture(nil, 'HIGHLIGHT') highlight:SetAllPoints() @@ -183,28 +243,27 @@ do m.resize_tab(tab, tab:GetFontString():GetStringWidth(), 4) - -- tab:Show() tinsert(self.tabs, tab) end function self:set_tab(id) self.selected = id self.update_tabs() - self.on_select(id) + aux.call(self.on_select, id) end function self.update_tabs() for _, tab in self.tabs do if tab.group.selected == tab.id then - tab.text:SetTextColor(unpack(m.config.label_color.enabled)) + tab.text:SetTextColor(unpack(m.color.label.enabled)) tab:Disable() - tab:SetBackdropColor(unpack(m.config.panel_color.backdrop)) + tab:SetBackdropColor(unpack(m.color.panel.backdrop)) tab.dock:Show() tab:SetHeight(29) else - tab.text:SetTextColor(unpack(m.config.text_color.enabled)) + tab.text:SetTextColor(unpack(m.color.text.enabled)) tab:Enable() - tab:SetBackdropColor(unpack(m.config.content_color.backdrop)) + tab:SetBackdropColor(unpack(m.color.content.backdrop)) tab.dock:Hide() tab:SetHeight(24) end @@ -225,24 +284,19 @@ function public.editbox(parent) editbox:SetFont(m.config.font, m.config.medium_font_size) editbox:SetShadowColor(0, 0, 0, 0) m.set_content_style(editbox) - - editbox:SetScript('OnEditFocusLost', aux.f(editbox.HighlightText, editbox, 0, 0)) - - editbox:SetScript('OnEscapePressed', aux.f(editbox.ClearFocus, editbox)) - + editbox:SetScript('OnEditFocusGained', aux._(editbox.HighlightText, editbox)) + editbox:SetScript('OnEditFocusLost', aux._(editbox.HighlightText, editbox, 0, 0)) + editbox:SetScript('OnEscapePressed', aux._(editbox.ClearFocus, editbox)) do local last_time, last_x, last_y - - editbox:SetScript('OnEditFocusGained', aux.f(editbox.HighlightText, editbox)) - editbox:SetScript('OnMouseUp', function() local x, y = GetCursorPosition() - if last_time and last_time > GetTime() - .5 and abs(x - last_x) < 10 and abs(y - last_y) < 10 then + if last_time and GetTime() - last_time < .5 and x == last_x and y == last_y then + last_time = nil this:HighlightText() - last_time = nil else last_time = GetTime() - last_x, last_y = GetCursorPosition() + last_x, last_y = x, y end end) end @@ -300,7 +354,7 @@ function public.status_bar(parent) text_frame:SetFrameLevel(level + 4) text_frame:SetAllPoints(self) local text = m.label(text_frame) - text:SetTextColor(unpack(m.config.text_color.enabled)) + text:SetTextColor(unpack(m.color.text.enabled)) text:SetPoint('CENTER', 0, 0) self.text = text end @@ -325,7 +379,7 @@ function public.item(parent) local item = CreateFrame('Button', nil, parent) item:SetWidth(193) item:SetHeight(40) - local icon = CreateFrame('CheckButton', 'aux_frame'..aux.unique(), item, 'ActionButtonTemplate') + local icon = CreateFrame('CheckButton', 'aux_frame'..aux.id(), item, 'ActionButtonTemplate') icon:SetPoint('LEFT', 2, 0.5) icon:SetHighlightTexture(nil) icon:RegisterForClicks() @@ -345,7 +399,7 @@ end function public.label(parent, size) local label = parent:CreateFontString() label:SetFont(m.config.font, size or m.config.medium_font_size) - label:SetTextColor(unpack(m.config.label_color.enabled)) + label:SetTextColor(unpack(m.color.label.enabled)) return label end @@ -355,9 +409,9 @@ function public.horizontal_line(parent, y_offset, inverted_color) texture:SetPoint('TOPRIGHT', parent, 'TOPRIGHT', -2, y_offset) texture:SetHeight(2) if inverted_color then - texture:SetTexture(unpack(m.config.panel_color.backdrop)) + texture:SetTexture(unpack(m.color.panel.backdrop)) else - texture:SetTexture(unpack(m.config.content_color.backdrop)) + texture:SetTexture(unpack(m.color.content.backdrop)) end return texture end @@ -368,20 +422,20 @@ function public.vertical_line(parent, x_offset, top_offset, bottom_offset, inver texture:SetPoint('BOTTOMLEFT', parent, 'BOTTOMLEFT', x_offset, bottom_offset or 2) texture:SetWidth(2) if inverted_color then - texture:SetTexture(unpack(m.config.panel_color.backdrop)) + texture:SetTexture(unpack(m.color.panel.backdrop)) else - texture:SetTexture(unpack(m.config.content_color.backdrop)) + texture:SetTexture(unpack(m.color.content.backdrop)) end return texture end function public.dropdown(parent) - local dropdown = CreateFrame('Frame', 'aux_frame'..aux.unique(), parent, 'UIDropDownMenuTemplate') + local dropdown = CreateFrame('Frame', 'aux_frame'..aux.id(), parent, 'UIDropDownMenuTemplate') dropdown:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size, insets={top=5,bottom=5}} - dropdown:SetBackdropColor(unpack(m.config.content_color.backdrop)) - dropdown:SetBackdropBorderColor(unpack(m.config.content_color.border)) + dropdown:SetBackdropColor(unpack(m.color.content.backdrop)) + dropdown:SetBackdropBorderColor(unpack(m.color.content.border)) local left = getglobal(dropdown:GetName()..'Left'):Hide() local middle = getglobal(dropdown:GetName()..'Middle'):Hide() local right = getglobal(dropdown:GetName()..'Right'):Hide() @@ -394,7 +448,7 @@ function public.dropdown(parent) text:ClearAllPoints() text:SetPoint('RIGHT', button, 'LEFT', -2, 0) text:SetPoint('LEFT', dropdown, 'LEFT', 8, 0) - text:SetFont(m.config.font, m.config.small_font_size) + text:SetFont(m.config.font, m.config.medium_font_size) text:SetShadowColor(0, 0, 0, 0) -- @@ -434,7 +488,7 @@ function public.slider(parent) m.set_panel_style(slider) local thumb_texture = slider:CreateTexture(nil, 'ARTWORK') thumb_texture:SetPoint('CENTER', 0, 0) - thumb_texture:SetTexture(unpack(m.config.content_color.backdrop)) + thumb_texture:SetTexture(unpack(m.color.content.backdrop)) thumb_texture:SetHeight(15) thumb_texture:SetWidth(8) slider:SetThumbTexture(thumb_texture) @@ -445,7 +499,7 @@ function public.slider(parent) label:SetJustifyH('LEFT') label:SetHeight(13) label:SetFont(m.config.font, m.config.small_font_size) - label:SetTextColor(unpack(m.config.label_color.enabled)) + label:SetTextColor(unpack(m.color.label.enabled)) local editbox = m.editbox(slider) editbox:SetPoint('LEFT', slider, 'RIGHT', 5, 0) @@ -457,41 +511,16 @@ function public.slider(parent) return slider end ---function m.checkbox() --- local frame = CreateFrame('Button', nil, UIParent) --- frame:Hide() --- frame:EnableMouse(true) --- frame:SetScript("OnEnter", Control_OnEnter) --- frame:SetScript("OnLeave", Control_OnLeave) --- frame:SetScript("OnMouseDown", CheckBox_OnMouseDown) --- frame:SetScript("OnMouseUp", CheckBox_OnMouseUp) --- --- local checkbox = CreateFrame('Button', nil, frame) --- checkbox:EnableMouse(false) --- checkbox:SetWidth(16) --- checkbox:SetHeight(16) --- checkbox:SetPoint('TOPLEFT', 4, -4) --- checkbox:SetBackdrop({ bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size }) --- checkbox:SetBackdropColor(unpack(m.config.content_color.backdrop)) --- checkbox:SetBackdropBorderColor(unpack(m.config.content_color.border)) --- local highlight = checkbox:CreateTexture(nil, 'HIGHLIGHT') --- highlight:SetAllPoints() --- highlight:SetTexture(1, 1, 1, .2) --- highlight:SetBlendMode('BLEND') --- --- local check = checkbox:CreateTexture(nil, 'OVERLAY') --- check:SetTexture([[Interface\Buttons\UI-CheckBox-Check]]) --- check:SetTexCoord(.12, .88, .12, .88) --- check:SetBlendMode('BLEND') --- check:SetPoint('BOTTOMRIGHT') --- --- local text = frame:CreateFontString(nil, 'OVERLAY') --- text:SetJustifyH('LEFT') --- text:SetHeight(18) --- text:SetPoint('LEFT', checkbox, 'RIGHT') --- text:SetPoint('RIGHT') --- text:SetFont(m.config.font, m.config.medium_font_size) --- --- checkbox.text = text --- return checkbox ---end \ No newline at end of file +function public.checkbox(parent) + local checkbox = CreateFrame('CheckButton', nil, parent, 'UICheckButtonTemplate') + checkbox:SetWidth(16) + checkbox:SetHeight(16) + m.set_content_style(checkbox) + checkbox:SetNormalTexture(nil) + checkbox:SetPushedTexture(nil) + checkbox:GetHighlightTexture():SetAllPoints() + checkbox:GetHighlightTexture():SetTexture(1, 1, 1, .2) + checkbox:GetCheckedTexture():SetTexCoord(.12, .88, .12, .88) + checkbox:GetHighlightTexture('BLEND') + return checkbox +end \ No newline at end of file diff --git a/module.lua b/module.lua index 79c2ab2..1684017 100644 --- a/module.lua +++ b/module.lua @@ -1,62 +1,62 @@ +local __ = {} + +local public_interface_mt = { + __newindex = function() + error('Unsupported operation.', 2) + end, + __index = function(self, key) + if __[self].public[key] then + return __[self].data[key] + else + error('Read of undeclared "'..key..'".', 2) + end + end, +} +local private_interface_mt = { + __newindex = function(self, key, value) + if not __[self].declared[key] then + error('Write of undeclared "'..key..'".', 2) + end + __[self].data[key] = value + end, + __index = function(self, key) + if not __[self].declared[key] then + error('Read of undeclared "'..key..'".', 2) + end + return __[self].data[key] + end, +} +local public_declarator_mt = { + __newindex = function(self, key, value) + if __[self].declared[key] then + error('Multiple declarations of "'..key..'".', 2) + end + __[self].data[key] = value + __[self].public[key] = true + __[self].declared[key] = true + end, + __index = function() + error('Unsupported operation.', 2) + end, +} +local private_declarator_mt = { + __newindex = function(self, key, value) + if __[self].declared[key] then + error('Multiple declarations of "'..key..'".', 2) + end + __[self].data[key] = value + __[self].declared[key] = true + end, + __index = function() + error('Unsupported operation.', 2) + end, +} + function aux_module() - local data, is_public, is_declared, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}, {} - setmetatable(public_interface, { - __newindex = function() - error('Unsupported operation.', 2) - end, - __index = function(_, key) - if not is_public[key] then - error('Read of undeclared "'..key..'".', 2) - end - if is_public[key] then - return data[key] - end - end, - __call = function(_, key) - return is_public[key] - end - }) - setmetatable(private_interface, { - __newindex = function(_, key, value) - if not is_declared[key] then - error('Write of undeclared "'..key..'".', 2) - end - data[key] = value - end, - __index = function(_, key) - if not is_declared[key] then - error('Read of undeclared "'..key..'".', 2) - end - return data[key] - end, - __call = function(_, key) - return is_declared[key] - end - }) - setmetatable(public, { - __newindex = function(_, key, value) - if is_declared[key] then - error('Multiple declarations of "'..key..'".', 2) - end - data[key] = value - is_public[key] = true - is_declared[key] = true - end, - __index = function() - error('Unsupported operation.', 2) - end, - }) - setmetatable(private, { - __newindex = function(_, key, value) - if is_declared[key] then - error('Multiple declarations of "'..key..'".', 2) - end - data[key] = value - is_declared[key] = true - end, - __index = function() - error('Unsupported operation.', 2) - end, - }) - return { public_interface, private_interface, public, private } + local dataset = {data={}, public={}, declared={}} + local module = {setmetatable({}, public_interface_mt), setmetatable({}, private_interface_mt), setmetatable({}, public_declarator_mt), setmetatable({}, private_declarator_mt)} + for _, component in module do + __[component] = dataset + end + return module end \ No newline at end of file diff --git a/tables/auction_listing.lua b/tables/auction_listing.lua index 68caa97..1c0a323 100644 --- a/tables/auction_listing.lua +++ b/tables/auction_listing.lua @@ -86,7 +86,7 @@ public.search_config = { width = 0.06, align = 'CENTER', set = function(cell, record, count, own, expandable) - local numAuctionsText = expandable and (aux.gui.inline_color(aux.gui.config.link_color)..count..'|r') or count + local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count if own > 0 then numAuctionsText = numAuctionsText..(' |cffffff00('..own..')|r') end @@ -132,7 +132,7 @@ public.search_config = { width = 0.13, align = 'CENTER', set = function(cell, record) - cell:SetText(aux.is_player(record.owner) and ('|cffffff00'..record.owner..'|r') or (record.owner or '---')) + cell:SetText(aux.is_player(record.owner) and ('|cffffff00'..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) end, cmp = function(record_a, record_b, desc) if not record_a.owner and not record_b.owner then @@ -256,7 +256,7 @@ public.auctions_config = { width = 0.06, align = 'CENTER', set = function(cell, record, count, own, expandable) - local numAuctionsText = expandable and (aux.gui.inline_color(aux.gui.config.link_color)..count..'|r') or count + local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count cell:SetText(numAuctionsText) end, cmp = function(record_a, record_b, desc) @@ -390,7 +390,7 @@ public.bids_config = { width = 0.06, align = 'CENTER', set = function(cell, record, count, own, expandable) - local numAuctionsText = expandable and (aux.gui.inline_color(aux.gui.config.link_color)..count..'|r') or count + local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count cell:SetText(numAuctionsText) end, cmp = function(record_a, record_b, desc) @@ -433,7 +433,7 @@ public.bids_config = { width = 0.13, align = 'CENTER', set = function(cell, record) - cell:SetText(aux.is_player(record.owner) and ('|cffffff00'..record.owner..'|r') or (record.owner or '---')) + cell:SetText(aux.is_player(record.owner) and ('|cffffff00'..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) end, cmp = function(record_a, record_b, desc) if not record_a.owner and not record_b.owner then @@ -996,7 +996,7 @@ local methods = { function public.CreateAuctionResultsTable(parent, config) - local rtName = 'aux_frame'..aux.unique() + local rtName = 'aux_frame'..aux.id() RT_COUNT = RT_COUNT + 1 local rt = CreateFrame('Frame', rtName, parent) rt.config = config @@ -1047,7 +1047,7 @@ function public.CreateAuctionResultsTable(parent, config) scrollBar:SetWidth(10) local thumbTex = scrollBar:GetThumbTexture() thumbTex:SetPoint('CENTER', 0, 0) - thumbTex:SetTexture(unpack(aux.gui.config.content_color.backdrop)) + thumbTex:SetTexture(unpack(aux.gui.color.content.backdrop)) thumbTex:SetHeight(150) thumbTex:SetWidth(scrollBar:GetWidth()) getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() @@ -1074,7 +1074,7 @@ function public.CreateAuctionResultsTable(parent, config) text:SetJustifyH('CENTER') text:SetJustifyV('CENTER') text:SetFont(aux.gui.config.font, aux.gui.config.tiny_font_size) - text:SetTextColor(unpack(aux.gui.config.label_color.enabled)) + text:SetTextColor(unpack(aux.gui.color.label.enabled)) cell:SetFontString(text) if not column_config.isPrice then cell:SetText(column_config.title or '') end -- TODO text:SetAllPoints() diff --git a/tables/item_listing.lua b/tables/item_listing.lua index f3ae2a0..706435e 100644 --- a/tables/item_listing.lua +++ b/tables/item_listing.lua @@ -60,7 +60,7 @@ function public.create(parent, on_click, on_enter, on_leave, selected) scrollBar:SetWidth(12) local thumbTex = scrollBar:GetThumbTexture() thumbTex:SetPoint('CENTER', 0, 0) - thumbTex:SetTexture(unpack(aux.gui.config.content_color.backdrop)) + thumbTex:SetTexture(unpack(aux.gui.color.content.backdrop)) thumbTex:SetHeight(50) thumbTex:SetWidth(12) getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() diff --git a/tables/listing.lua b/tables/listing.lua index 1806749..4f7b379 100644 --- a/tables/listing.lua +++ b/tables/listing.lua @@ -309,7 +309,7 @@ local methods = { local text = col:CreateFontString() text:SetJustifyV('CENTER') text:SetFont(aux.gui.config.font, aux.gui.config.medium_font_size) - text:SetTextColor(unpack(aux.gui.config.text_color.enabled)) + text:SetTextColor(unpack(aux.gui.color.text.enabled)) text:SetAllPoints() col.text = text col:SetFontString(text) @@ -433,7 +433,7 @@ function public.CreateScrollingTable(parent) st.scrollBar = scrollBar local thumbTex = scrollBar:GetThumbTexture() thumbTex:SetPoint('CENTER', 0, 0) - thumbTex:SetTexture(unpack(aux.gui.config.content_color.backdrop)) + thumbTex:SetTexture(unpack(aux.gui.color.content.backdrop)) thumbTex:SetHeight(50) thumbTex:SetWidth(12) getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index 2044822..008222b 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -6,7 +6,7 @@ function public.FRAMES(f) private.create_frames = f end -function public.LOAD() +function m.LOAD() m.create_frames(m, public, private) end @@ -92,7 +92,7 @@ do m.cancel_button:SetScript('OnClick', function() if m.test(record)(index) and m.listing:ContainsRecord(record) then - aux.cancel_auction(index, aux.f(m.listing.RemoveAuctionRecord, m.listing, record)) + aux.cancel_auction(index, aux._(m.listing.RemoveAuctionRecord, m.listing, record)) end end) m.cancel_button:Enable() diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index 5b82813..011cfc8 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -6,7 +6,7 @@ function public.FRAMES(f) private.create_frames = f end -function public.LOAD() +function m.LOAD() m.create_frames(m, public, private) end @@ -96,7 +96,7 @@ do aux.place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function() aux.info.bid_update(record) m.listing:SetDatabase() - end or aux.f(m.listing.RemoveAuctionRecord, m.listing, record)) + end or aux._(m.listing.RemoveAuctionRecord, m.listing, record)) end end) m.bid_button:Enable() @@ -105,7 +105,7 @@ do if record.buyout_price > 0 then m.buyout_button:SetScript('OnClick', function() if m.test(record)(index) and m.listing:ContainsRecord(record) then - aux.place_bid('bidder', index, record.buyout_price, aux.f(m.listing.RemoveAuctionRecord, m.listing, record)) + aux.place_bid('bidder', index, record.buyout_price, aux._(m.listing.RemoveAuctionRecord, m.listing, record)) end end) m.buyout_button:Enable() diff --git a/tabs/post/core.lua b/tabs/post/core.lua index f1a90c2..fd55226 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -13,14 +13,14 @@ function public.FRAMES(f) private.create_frames = f end -function public.LOAD() +function m.LOAD() m.create_frames(m, public, private) end function public.OPEN() m.frame:Show() - m.deposit:SetText('Deposit: '..aux.money.to_string(0, nil, nil, nil, aux.gui.inline_color({255, 254, 250, 1}))) + m.deposit:SetText('Deposit: '..aux.money.to_string(0, nil, nil, nil, aux.gui.inline_color.text.enabled)) m.set_unit_start_price(0) m.set_unit_buyout_price(0) @@ -278,7 +278,7 @@ function private.update_item_configuration() m.item.texture:SetTexture(nil) m.item.count:SetText() - m.item.name:SetTextColor(unpack(aux.gui.config.label_color.enabled)) + m.item.name:SetTextColor(unpack(aux.gui.color.label.enabled)) m.item.name:SetText('No item selected') m.unit_start_price:Hide() @@ -319,7 +319,7 @@ function private.update_item_configuration() stack_count = m.stack_count_slider:GetValue() local deposit = floor(m.selected_item.unit_vendor_price * deposit_factor * (m.selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(m.duration_dropdown) / 120 - m.deposit:SetText('Deposit: '..aux.money.to_string(deposit, nil, nil, nil, aux.gui.inline_color({255, 254, 250, 1}))) + m.deposit:SetText('Deposit: '..aux.money.to_string(deposit, nil, nil, nil, aux.gui.inline_color.text.enabled)) end m.refresh_button:Enable() diff --git a/tabs/post/frames.lua b/tabs/post/frames.lua index d02d9d8..607b148 100644 --- a/tabs/post/frames.lua +++ b/tabs/post/frames.lua @@ -25,15 +25,13 @@ aux.post_tab.FRAMES(function(m, public, private) m.frame.auctions:SetPoint('BOTTOMRIGHT', 0, 0) do - local checkbox = CreateFrame('CheckButton', nil, m.frame.inventory, 'UICheckButtonTemplate') - checkbox:SetWidth(22) - checkbox:SetHeight(22) - checkbox:SetPoint('TOPLEFT', 45, -15) + local checkbox = aux.gui.checkbox(m.frame.inventory) + checkbox:SetPoint('TOPLEFT', 49, -16) checkbox:SetScript('OnClick', function() m.refresh = true end) local label = aux.gui.label(checkbox, aux.gui.config.small_font_size) - label:SetPoint('LEFT', checkbox, 'RIGHT', 2, 1) + label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1) label:SetText('Show hidden items') private.show_hidden_checkbox = checkbox end @@ -224,10 +222,8 @@ aux.post_tab.FRAMES(function(m, public, private) private.duration_dropdown = dropdown end do - local checkbox = CreateFrame('CheckButton', nil, m.frame.parameters, 'UICheckButtonTemplate') - checkbox:SetWidth(22) - checkbox:SetHeight(22) - checkbox:SetPoint('TOPRIGHT', -85, -6) + local checkbox = aux.gui.checkbox(m.frame.parameters) + checkbox:SetPoint('TOPRIGHT', -83, -6) checkbox:SetScript('OnClick', function() local settings = m.read_settings() settings.hidden = this:GetChecked() @@ -235,7 +231,7 @@ aux.post_tab.FRAMES(function(m, public, private) m.refresh = true end) local label = aux.gui.label(checkbox, aux.gui.config.small_font_size) - label:SetPoint('LEFT', checkbox, 'RIGHT', 2, 1) + label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1) label:SetText('Hide this item') private.hide_checkbox = checkbox end diff --git a/tabs/search/core.lua b/tabs/search/core.lua index d88fae4..8a89270 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -66,7 +66,7 @@ function public.FRAMES(f) private.create_frames = f end -function public.LOAD() +function m.LOAD() m.create_frames(m, public, private) m.new_search('') m.update_tab(m.SAVED) @@ -233,8 +233,8 @@ function private.start_real_time_scan(query, search, continuation) if not ignore_page then if search.auto_buy then ctrl.suspend() - aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux.f(ctrl.resume, true)) - aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux.f(ctrl.resume, false)) + aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux._(ctrl.resume, true)) + aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux._(ctrl.resume, false)) else tinsert(new_records, auction_record) end @@ -329,8 +329,8 @@ function private.start_search(queries, continuation) on_auction = function(auction_record, ctrl) if search.auto_buy then ctrl.suspend() - aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux.f(ctrl.resume, true)) - aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux.f(ctrl.resume, false)) + aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux._(ctrl.resume, true)) + aux.control.thread(aux.control.when, aux.util.later(GetTime(), 10), aux._(ctrl.resume, false)) elseif getn(search.records) < 1000 then tinsert(search.records, auction_record) if getn(search.records) == 1000 then @@ -488,7 +488,7 @@ do aux.place_bid('list', index, record.bid_price, record.bid_price < record.buyout_price and function() aux.info.bid_update(record) search.table:SetDatabase() - end or aux.f(search.table.RemoveAuctionRecord, search.table, record)) + end or aux._(search.table.RemoveAuctionRecord, search.table, record)) end end) m.bid_button:Enable() @@ -497,7 +497,7 @@ do if record.buyout_price > 0 then m.buyout_button:SetScript('OnClick', function() if m.test(record)(index) and search.table:ContainsRecord(record) then - aux.place_bid('list', index, record.buyout_price, aux.f(search.table.RemoveAuctionRecord, search.table, record)) + aux.place_bid('list', index, record.buyout_price, aux._(search.table.RemoveAuctionRecord, search.table, record)) end end) m.buyout_button:Enable() diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 6398bb2..cac12ae 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -50,7 +50,7 @@ aux.search_tab.FRAMES(function(m, public, private) do local panel = CreateFrame('Frame', nil, m.frame) panel:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]]} - panel:SetBackdropColor(unpack(aux.gui.config.content_color.backdrop)) + panel:SetBackdropColor(unpack(aux.gui.color.content.backdrop)) panel:SetPoint('LEFT', m.settings_button, 'RIGHT', 0, 0) panel:SetPoint('RIGHT', 0, 0) panel:SetHeight(42) @@ -79,15 +79,15 @@ aux.search_tab.FRAMES(function(m, public, private) end) editbox:SetScript('OnTextChanged', function() if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then - this:SetBackdropColor(unpack(aux.gui.config.on_color)) + this:SetBackdropColor(unpack(aux.gui.color.state.enabled)) else - this:SetBackdropColor(unpack(aux.gui.config.off_color)) + this:SetBackdropColor(unpack(aux.gui.color.state.disabled)) end end) local label = aux.gui.label(editbox, aux.gui.config.medium_font_size) label:SetPoint('RIGHT', editbox, 'LEFT', -6, 0) label:SetText('Pages') - label:SetTextColor(unpack(aux.gui.config.text_color.enabled)) + label:SetTextColor(unpack(aux.gui.color.text.enabled)) private.first_page_input = editbox end do @@ -105,15 +105,15 @@ aux.search_tab.FRAMES(function(m, public, private) end) editbox:SetScript('OnTextChanged', function() if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then - this:SetBackdropColor(unpack(aux.gui.config.on_color)) + this:SetBackdropColor(unpack(aux.gui.color.state.enabled)) else - this:SetBackdropColor(unpack(aux.gui.config.off_color)) + this:SetBackdropColor(unpack(aux.gui.color.state.disabled)) end end) local label = aux.gui.label(editbox, aux.gui.config.medium_font_size) label:SetPoint('RIGHT', editbox, 'LEFT', -3.5, 0) label:SetText('-') - label:SetTextColor(unpack(aux.gui.config.text_color.enabled)) + label:SetTextColor(unpack(aux.gui.color.text.enabled)) private.last_page_input = editbox end do @@ -379,19 +379,17 @@ aux.search_tab.FRAMES(function(m, public, private) m.min_level_input:SetFocus() end end) - editbox:SetScript('OnEnterPressed', aux.f(editbox.ClearFocus, editbox)) + editbox:SetScript('OnEnterPressed', aux._(editbox.ClearFocus, editbox)) local label = aux.gui.label(editbox, aux.gui.config.small_font_size) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetText('Name') private.name_input = editbox end do - local checkbox = CreateFrame('CheckButton', nil, m.frame.filter, 'UICheckButtonTemplate') - checkbox:SetWidth(22) - checkbox:SetHeight(22) - checkbox:SetPoint('TOPLEFT', m.name_input, 'TOPRIGHT', 10, 0) + local checkbox = aux.gui.checkbox(m.frame.filter) + checkbox:SetPoint('TOPLEFT', m.name_input, 'TOPRIGHT', 16, 0) local label = aux.gui.label(checkbox, aux.gui.config.small_font_size) - label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', 1, -3) + label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1) label:SetText('Exact') private.exact_checkbox = checkbox end @@ -408,7 +406,7 @@ aux.search_tab.FRAMES(function(m, public, private) m.max_level_input:SetFocus() end end) - editbox:SetScript('OnEnterPressed', aux.f(editbox.ClearFocus, editbox)) + editbox:SetScript('OnEnterPressed', aux._(editbox.ClearFocus, editbox)) local label = aux.gui.label(editbox, aux.gui.config.small_font_size) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetText('Level Range') @@ -427,19 +425,17 @@ aux.search_tab.FRAMES(function(m, public, private) m.name_input:SetFocus() end end) - editbox:SetScript('OnEnterPressed', aux.f(editbox.ClearFocus, editbox)) + editbox:SetScript('OnEnterPressed', aux._(editbox.ClearFocus, editbox)) local label = aux.gui.label(editbox, aux.gui.config.medium_font_size) label:SetPoint('RIGHT', editbox, 'LEFT', -3, 0) label:SetText('-') private.max_level_input = editbox end do - local checkbox = CreateFrame('CheckButton', nil, m.frame.filter, 'UICheckButtonTemplate') - checkbox:SetWidth(22) - checkbox:SetHeight(22) - checkbox:SetPoint('TOPLEFT', m.max_level_input, 'TOPRIGHT', 10, 0) + local checkbox = aux.gui.checkbox(m.frame.filter) + checkbox:SetPoint('TOPLEFT', m.max_level_input, 'TOPRIGHT', 16, 0) local label = aux.gui.label(checkbox, aux.gui.config.small_font_size) - label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', 1, -3) + label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1) label:SetText('Usable') private.usable_checkbox = checkbox end diff --git a/util/core.lua b/util/core.lua index f8bb610..21e354e 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,18 +1,5 @@ local m, public, private = aux.module'util' -function public.pass() -end - -function public.id(x) - return x -end - -function public.const(x) - return function() - return x - end -end - function public.size(t) local x = 0 for _ in t do @@ -72,7 +59,11 @@ end function public.any(xs, p) local holds = false for _, x in xs do - holds = holds or p(x) + if p then + holds = holds or p(x) + else + holds = holds or x + end end return holds end @@ -80,7 +71,11 @@ end function public.all(xs, p) local holds = true for _, x in xs do - holds = holds and p(x) + if p then + holds = holds and p(x) + else + holds = holds and x + end end return holds end @@ -227,7 +222,6 @@ function public.bag_type(bag) if bag == 0 then return 1 end - if GetInventoryItemLink('player', ContainerIDToInventoryID(bag)) then local item_id = aux.info.parse_hyperlink(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) local item_info = aux.info.item(item_id) @@ -251,22 +245,8 @@ function public.signal() end end -function public.without_errors(f) - local orig = UIErrorsFrame.AddMessage - UIErrorsFrame.AddMessage = m.pass - f() - UIErrorsFrame.AddMessage = orig -end - -function public.without_sound(f) - local orig = GetCVar('MasterSoundEffects') - SetCVar('MasterSoundEffects', 0) - f() - SetCVar('MasterSoundEffects', orig) -end - function public.format_money(money, exact, color) - color = color or '|r' + color = color or FONT_COLOR_CODE_CLOSE local TEXT_NONE = '0' @@ -275,7 +255,7 @@ function public.format_money(money, exact, color) local GSC_COPPER = 'c8602c' local GSC_START = '|cff%s%d|r' local GSC_PART = color..'.|cff%s%02d|r' - local GSC_NONE = '|cffa0a0a0'..TEXT_NONE..'|r' + local GSC_NONE = '|cffa0a0a0'..TEXT_NONE..FONT_COLOR_CODE_CLOSE if not exact and money >= 10000 then -- Round to nearest silver diff --git a/util/filter.lua b/util/filter.lua index 72d0b4d..cc45a07 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -543,12 +543,12 @@ function public.indented_post_query_string(components) if component[1] == 'operator' and component[2] then no_line_break = component[2] == 'not' - str = str..'|cffffff00'..component[2]..(tonumber(component[3]) or '')..'|r' + str = str..'|cffffff00'..component[2]..(tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE tinsert(stack, component[3] or '*') elseif component[1] == 'filter' then - str = str..'|cffffff00'..component[2]..'|r' + str = str..'|cffffff00'..component[2]..FONT_COLOR_CODE_CLOSE if component[3] then - str = str..': '..'|cffff9218'..component[3]..'|r' + str = str..': '..'|cffff9218'..component[3]..FONT_COLOR_CODE_CLOSE end while getn(stack) > 0 and stack[getn(stack)] ~= '*' do local top = tremove(stack) @@ -570,29 +570,29 @@ function private.prettified_query_string(components) for _, filter in components.blizzard do blizzard_filters[filter[1]] = filter[2] or true if filter[1] == 'exact' then - prettified.prepend(aux.info.display_name(aux.cache.item_id(m.unquote(blizzard_filters.name))) or aux.gui.inline_color({216, 225, 211, 1})..'['..m.unquote(blizzard_filters.name)..']|r') + prettified.prepend(aux.info.display_name(aux.cache.item_id(m.unquote(blizzard_filters.name))) or aux.gui.inline_color.label.enabled..'['..m.unquote(blizzard_filters.name)..']|r') elseif filter[1] ~= 'name' then - prettified.append(aux.gui.inline_color({216, 225, 211, 1})..(filter[2] or filter[1])..'|r') + prettified.append(aux.gui.inline_color.label.enabled..(filter[2] or filter[1])..FONT_COLOR_CODE_CLOSE) end end if blizzard_filters.name and not blizzard_filters.exact then if m.unquote(blizzard_filters.name) == '' then - prettified.prepend('|cffff0000'..'No Filter'..'|r') + prettified.prepend(RED_FONT_COLOR_CODE..'No Filter'..FONT_COLOR_CODE_CLOSE) else - prettified.prepend(aux.gui.inline_color({216, 225, 211, 1})..m.unquote(blizzard_filters.name)..'|r') + prettified.prepend(aux.gui.inline_color.label.enabled..m.unquote(blizzard_filters.name)..FONT_COLOR_CODE_CLOSE) end end for _, component in components.post do if component[1] == 'operator' then - prettified.append('|cffffff00'..component[2]..(tonumber(component[3]) or '')..'|r') + prettified.append('|cffffff00'..component[2]..(tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE) elseif component[1] == 'filter' then if component[2] ~= 'tooltip' then - prettified.append('|cffffff00'..component[2]..'|r') + prettified.append('|cffffff00'..component[2]..FONT_COLOR_CODE_CLOSE) end if component[3] then - prettified.append('|cffff9218'..component[3]..'|r') + prettified.append('|cffff9218'..component[3]..FONT_COLOR_CODE_CLOSE) end end end @@ -676,15 +676,15 @@ function private.validator(components) if name == 'not' then tinsert(stack, not args[1]) elseif name == 'and' then - tinsert(stack, aux.util.all(args, aux.util.id)) + tinsert(stack, aux.util.all(args)) elseif name == 'or' then - tinsert(stack, aux.util.any(args, aux.util.id)) + tinsert(stack, aux.util.any(args)) end elseif type == 'filter' then tinsert(stack, validators[i](record) and true or false) end end - return aux.util.all(stack, aux.util.id) + return aux.util.all(stack) end end diff --git a/util/money.lua b/util/money.lua index 7f54a57..f43ce52 100644 --- a/util/money.lua +++ b/util/money.lua @@ -63,7 +63,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color) if is_negative then if color then - text = color..'-|r'..text + text = color..'-'..FONT_COLOR_CODE_CLOSE..text else text = '-'..text end @@ -99,7 +99,7 @@ function public.format_number(num, pad, decimal_padding, color) num = format('%0'..padding..'.0'..(decimal_padding or 0)..'f', num) if color then - return color..num..'|r' + return color..num..FONT_COLOR_CODE_CLOSE else return num end diff --git a/util/persistence.lua b/util/persistence.lua index 61b7db8..f8e119d 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -5,8 +5,8 @@ aux_datasets = {} do local realm, faction - function public.LOAD() - aux.control.thread(aux.control.when, function() faction = UnitFactionGroup('player') return faction end, aux.util.pass) + function m.LOAD() + aux.control.thread(aux.control.when, function() faction = UnitFactionGroup('player') return faction end, function() end) realm = GetCVar('realmName') end