From bf4af0cb0afb18a4e26f903efd4cb05a5ccc58cb Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 22 Aug 2016 23:08:18 +0200 Subject: [PATCH] big refactoring --- gui/auction_listing.lua | 6 ++-- gui/core.lua | 28 +++++++++---------- gui/item_listing.lua | 6 ++-- gui/listing.lua | 6 ++-- tabs/search/core.lua | 4 +-- tabs/search/filter.lua | 8 +++--- tabs/search/frame.lua | 2 +- util/filter.lua | 4 +-- util/info.lua | 62 +++++++++++++++++++++-------------------- 9 files changed, 64 insertions(+), 62 deletions(-) diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index 4db5aa4..72ab54e 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -1031,7 +1031,7 @@ function public.CreateAuctionResultsTable(parent, config) rt.scrollFrame = scrollFrame FauxScrollFrame_Update(rt.scrollFrame, 0, numRows, rt.ROW_HEIGHT) - local scrollBar = getglobal(scrollFrame:GetName()..'ScrollBar') + local scrollBar = _g[scrollFrame:GetName()..'ScrollBar'] scrollBar:ClearAllPoints() scrollBar:SetPoint('BOTTOMRIGHT', rt, -4, 4) scrollBar:SetPoint('TOPRIGHT', rt, -4, -HEAD_HEIGHT) @@ -1041,8 +1041,8 @@ function public.CreateAuctionResultsTable(parent, config) thumbTex:SetTexture(color.content.background()) thumbTex:SetHeight(150) thumbTex:SetWidth(scrollBar:GetWidth()) - getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() - getglobal(scrollBar:GetName()..'ScrollDownButton'):Hide() + _g[scrollBar:GetName()..'ScrollUpButton']:Hide() + _g[scrollBar:GetName()..'ScrollDownButton']:Hide() -- create the header cells rt.headCells = {} diff --git a/gui/core.lua b/gui/core.lua index 0effb83..9ab4a70 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -57,7 +57,7 @@ do blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() hook('ToggleDropDownMenu', function(...) local ret = {orig.ToggleDropDownMenu(unpack(arg))} - local dropdown = getglobal(arg[4] or '') or this:GetParent() + local dropdown = _g[arg[4] or ''] or this:GetParent() if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then set_aux_dropdown_style(dropdown) else @@ -75,20 +75,20 @@ do DropDownList1:ClearAllPoints() DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2) for i=1,UIDROPDOWNMENU_MAXBUTTONS do - local button = getglobal('DropDownList1Button'..i) + local button = _g['DropDownList1Button'..i] button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7) local text = button:GetFontString() text:SetFont(font, font_size.small2) text:SetPoint('TOPLEFT', 18, 0) text:SetPoint('BOTTOMRIGHT', -8, 0) - local highlight = getglobal('DropDownList1Button'..i..'Highlight') + local highlight = _g['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') + local check = _g['DropDownList1Button'..i..'Check'] check:SetWidth(16) check:SetHeight(16) check:SetPoint('LEFT', 3, -1) @@ -100,14 +100,14 @@ do aux_border:Hide() aux_background:Hide() for i=1,UIDROPDOWNMENU_MAXBUTTONS do - local button = getglobal('DropDownList1Button'..i) + local button = _g['DropDownList1Button'..i] local text = button:GetFontString() text:SetFont([[Fonts\FRIZQT__.ttf]], 10) text:SetShadowOffset(1, -1) - local highlight = getglobal('DropDownList1Button'..i..'Highlight') + local highlight = _g['DropDownList1Button'..i..'Highlight'] highlight:SetAllPoints() highlight:SetDrawLayer 'BACKGROUND' - local check = getglobal('DropDownList1Button'..i..'Check') + local check = _g['DropDownList1Button'..i..'Check'] check:SetWidth(24) check:SetHeight(24) check:SetPoint('LEFT', 0, 0) @@ -464,13 +464,13 @@ function public.item(parent) btn:SetPoint('LEFT', 2, .5) btn:SetHighlightTexture(nil) btn:RegisterForClicks() - item.texture = getglobal(btn:GetName()..'Icon') + item.texture = _g[btn:GetName()..'Icon'] item.texture:SetTexCoord(.06, .94, .06, .94) item.name = label(btn, 15) item.name:SetJustifyH 'LEFT' item.name:SetPoint('LEFT', btn, 'RIGHT', 10, 0) item.name:SetPoint('RIGHT', item, 'RIGHT', -10, .5) - item.count = getglobal(btn:GetName()..'Count') + item.count = _g[btn:GetName()..'Count'] item.count:SetTextHeight(17) return item end @@ -512,17 +512,17 @@ function public.dropdown(parent) local dropdown = CreateFrame('Frame', name, parent, 'UIDropDownMenuTemplate') set_content_style(dropdown, 0, 0, 4, 4) - getglobal(dropdown:GetName()..'Left'):Hide() - getglobal(dropdown:GetName()..'Middle'):Hide() - getglobal(dropdown:GetName()..'Right'):Hide() + _g[dropdown:GetName()..'Left']:Hide() + _g[dropdown:GetName()..'Middle']:Hide() + _g[dropdown:GetName()..'Right']:Hide() - local button = getglobal(dropdown:GetName()..'Button') + local button = _g[dropdown:GetName()..'Button'] button:ClearAllPoints() button:SetScale(0.9) button:SetPoint('RIGHT', dropdown, 0, 0) dropdown.button = button - local text = getglobal(dropdown:GetName()..'Text') + local text = _g[dropdown:GetName()..'Text'] text:ClearAllPoints() text:SetPoint('RIGHT', button, 'LEFT', -2, 0) text:SetPoint('LEFT', 8, 0) diff --git a/gui/item_listing.lua b/gui/item_listing.lua index ac5e888..a11a05f 100644 --- a/gui/item_listing.lua +++ b/gui/item_listing.lua @@ -48,15 +48,15 @@ function public.create(parent, on_click, selected) scroll_frame:SetPoint('TOPLEFT', content, 'TOPLEFT', 0, 15) scroll_frame:SetPoint('BOTTOMRIGHT', content, 'BOTTOMRIGHT', -4, -15) - local scrollBar = getglobal(scroll_frame:GetName()..'ScrollBar') + local scrollBar = _g[scroll_frame:GetName()..'ScrollBar'] scrollBar:SetWidth(12) local thumbTex = scrollBar:GetThumbTexture() thumbTex:SetPoint('CENTER', 0, 0) thumbTex:SetTexture(color.content.background()) thumbTex:SetHeight(50) thumbTex:SetWidth(12) - getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() - getglobal(scrollBar:GetName()..'ScrollDownButton'):Hide() + _g[scrollBar:GetName()..'ScrollUpButton']:Hide() + _g[scrollBar:GetName()..'ScrollDownButton']:Hide() local rows = {} local row_index = 1 diff --git a/gui/listing.lua b/gui/listing.lua index 4ae2db9..ddc5fd2 100644 --- a/gui/listing.lua +++ b/gui/listing.lua @@ -424,7 +424,7 @@ function public.CreateScrollingTable(parent) scrollFrame:SetAllPoints(contentFrame) st.scrollFrame = scrollFrame - local scrollBar = getglobal(scrollFrame:GetName()..'ScrollBar') + local scrollBar = _g[scrollFrame:GetName()..'ScrollBar'] scrollBar:SetWidth(12) st.scrollBar = scrollBar local thumbTex = scrollBar:GetThumbTexture() @@ -432,8 +432,8 @@ function public.CreateScrollingTable(parent) thumbTex:SetTexture(color.content.background()) thumbTex:SetHeight(50) thumbTex:SetWidth(12) - getglobal(scrollBar:GetName()..'ScrollUpButton'):Hide() - getglobal(scrollBar:GetName()..'ScrollDownButton'):Hide() + _g[scrollBar:GetName()..'ScrollUpButton']:Hide() + _g[scrollBar:GetName()..'ScrollDownButton']:Hide() -- create head line at default position st.headLine = gui.horizontal_line(st, 0) diff --git a/tabs/search/core.lua b/tabs/search/core.lua index cd0a73c..2b31881 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -20,7 +20,7 @@ StaticPopupDialogs['AUX_SEARCH_AUTO_BUY'] = { } do local function action() - _g.aux_auto_buy_filter = getglobal(this:GetParent():GetName()..'EditBox'):GetText() + _g.aux_auto_buy_filter = _g[this:GetParent():GetName()..'EditBox']:GetText() update_auto_buy_filter() end @@ -30,7 +30,7 @@ do button2 = 'Cancel', hasEditBox = 1, OnShow = function() - local edit_box = getglobal(this:GetName()..'EditBox') + local edit_box = _g[this:GetName()..'EditBox'] edit_box:SetMaxLetters(nil) edit_box:SetFocus() edit_box:HighlightText() diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index a33128c..8ece097 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -125,13 +125,13 @@ function get_filter_builder_query() for _, subclass in {blizzard_query.subclass} do local subclasses = {GetAuctionItemSubClasses(class)} add(strlower(subclasses[subclass])) - add(blizzard_query.slot and strlower(getglobal(blizzard_query.slot))) + add(blizzard_query.slot and strlower(_g[blizzard_query.slot])) end end local quality = blizzard_query.quality if quality and quality >= 0 then - add(strlower(getglobal('ITEM_QUALITY'..quality..'_DESC'))) + add(strlower(_g['ITEM_QUALITY'..quality..'_DESC'])) end local post_filter_string = filter.query_string{blizzard={}, post=post_filter} @@ -412,7 +412,7 @@ function initialize_slot_dropdown() for _, slot in {GetAuctionInvTypes(class_index, subclass_index)} do UIDropDownMenu_AddButton{ - text = getglobal(slot), + text = _g[slot], value = slot, func = on_click, } @@ -433,7 +433,7 @@ function initialize_quality_dropdown() } for i=0,4 do UIDropDownMenu_AddButton{ - text = getglobal('ITEM_QUALITY'..i..'_DESC'), + text = _g['ITEM_QUALITY'..i..'_DESC'], value = i, func = on_click, } diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index 765bef4..3024596 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -499,7 +499,7 @@ function create_frames() dropdown:SetScript('OnShow', function() UIDropDownMenu_Initialize(this, initialize_filter_dropdown) end) - getglobal(dropdown:GetName()..'Text'):Hide() + _g[dropdown:GetName()..'Text']:Hide() local label = gui.label(dropdown, gui.font_size.medium) label:SetPoint('RIGHT', dropdown, 'LEFT', -15, 0) label:SetText('Post Filter') diff --git a/util/filter.lua b/util/filter.lua index 9f8c261..f19aab6 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -392,7 +392,7 @@ function suggestions(components) -- slots if not components.blizzard.slot then for _, invtype in {GetAuctionInvTypes(index(components.blizzard.class, 2) or 0, index(components.blizzard.subclass, 2) or 0)} do - tinsert(suggestions, getglobal(invtype)) + tinsert(suggestions, _g[invtype]) end end @@ -401,7 +401,7 @@ function suggestions(components) -- rarities if not components.blizzard.quality then - for i=0,4 do tinsert(suggestions, getglobal('ITEM_QUALITY'..i..'_DESC')) end + for i=0,4 do tinsert(suggestions, _g['ITEM_QUALITY'..i..'_DESC']) end end -- item names diff --git a/util/info.lua b/util/info.lua index 6f5208a..7423e4b 100644 --- a/util/info.lua +++ b/util/info.lua @@ -238,8 +238,8 @@ function public.load_tooltip(frame, tooltip) end end for i =1,getn(tooltip) do -- TODO why is this needed? - getglobal(frame:GetName()..'TextLeft'..i):SetJustifyH('LEFT') - getglobal(frame:GetName()..'TextRight'..i):SetJustifyH('LEFT') + _g[frame:GetName()..'TextLeft'..i]:SetJustifyH('LEFT') + _g[frame:GetName()..'TextRight'..i]:SetJustifyH('LEFT') end end @@ -250,7 +250,7 @@ function public.display_name(item_id, no_brackets, no_color) name = '['..name..']' end if not no_color then - name = ({GetItemQualityColor(item_info.quality)})[4]..name..FONT_COLOR_CODE_CLOSE + name = select(4, GetItemQualityColor(item_info.quality))..name..FONT_COLOR_CODE_CLOSE end return name end @@ -274,12 +274,12 @@ function public.tooltip(mutator) AuxTooltip:Show() local tooltip = {} - for i = 1,AuxTooltip:NumLines() do + for i=1,AuxTooltip:NumLines() do tinsert(tooltip, { - left_text = getglobal('AuxTooltipTextLeft'..i):GetText(), - left_color = {getglobal('AuxTooltipTextLeft'..i):GetTextColor()}, - right_text = getglobal('AuxTooltipTextRight'..i):IsVisible() and getglobal('AuxTooltipTextRight'..i):GetText(), - right_color = {getglobal('AuxTooltipTextRight'..i):GetTextColor()}, + left_text = _g['AuxTooltipTextLeft'..i]:GetText(), + left_color = {_g['AuxTooltipTextLeft'..i]:GetTextColor()}, + right_text = _g['AuxTooltipTextRight'..i]:IsVisible() and _g['AuxTooltipTextRight'..i]:GetText(), + right_color = {_g['AuxTooltipTextRight'..i]:GetTextColor()}, }) end @@ -301,29 +301,31 @@ function item_charges(tooltip) return 1 end -function public.max_item_charges(item_id) - return ({ - -- wizard oil - [20744] = 5, - [20746] = 5, - [20750] = 5, - [20749] = 5, +do + local data = { + -- wizard oil + [20744] = 5, + [20746] = 5, + [20750] = 5, + [20749] = 5, - -- mana oil - [20745] = 5, - [20747] = 5, - [20748] = 5, + -- mana oil + [20745] = 5, + [20747] = 5, + [20748] = 5, - -- discombobulator - [4388] = 5, + -- discombobulator + [4388] = 5, - -- recombobulator - [4381] = 10, - [18637] = 10, + -- recombobulator + [4381] = 10, + [18637] = 10, - -- ... TODO - - })[item_id] + -- ... TODO + } + function public.max_item_charges(item_id) + return data[item_id] + end end function public.durability(tooltip) @@ -389,15 +391,15 @@ end function public.item_slot_index(class_index, subclass_index, slot_name) for i, slot in {GetAuctionInvTypes(class_index, subclass_index)} do - if strupper(getglobal(slot)) == strupper(slot_name) then - return i, getglobal(slot) + if strupper(_g[slot]) == strupper(slot_name) then + return i, _g[slot] end end end function public.item_quality_index(item_quality) for i=0,4 do - local quality = getglobal('ITEM_QUALITY'..i..'_DESC') + local quality = _g['ITEM_QUALITY'..i..'_DESC'] if strupper(item_quality) == strupper(quality) then return i, quality end