From 77f7f36ec6a9b4b981be6e6a868810320919830c Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Tue, 26 Jul 2016 04:49:26 +0200 Subject: [PATCH] post refactoring --- core.lua | 2 +- core.xml | 30 ------------------ gui.lua | 30 ++++++++++++++++++ tables/item_listing.lua | 26 ++++++++-------- tabs/post/core.lua | 18 +++++------ tabs/post/frames.lua | 68 +++++++++++++++++++++-------------------- 6 files changed, 89 insertions(+), 85 deletions(-) diff --git a/core.lua b/core.lua index 06087a2..0a3cffe 100644 --- a/core.lua +++ b/core.lua @@ -39,7 +39,7 @@ do end function public.on_load() - public.version = '3.3.0' + public.version = '3.4.0' public.blizzard_ui_shown = false public.bids_loaded = false public.current_owner_page = nil diff --git a/core.xml b/core.xml index 70214b1..a8f1623 100644 --- a/core.xml +++ b/core.xml @@ -18,36 +18,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/gui.lua b/gui.lua index 9b7a307..3aa0849 100644 --- a/gui.lua +++ b/gui.lua @@ -16,6 +16,15 @@ public.config = { off_color = {0.7, 0.3, 0.3}, } +do + local x = 0 + + function private.id() + x = x + 1 + return 'Aux_frame'..x + end +end + function public.inline_color(color) local r, g, b, a = unpack(color) return format('|c%02X%02X%02X%02X', a, r, g, b) @@ -324,6 +333,27 @@ function public.status_bar(parent) return self end +function public.item(parent) + local item = CreateFrame('Button', nil, parent) + item:SetWidth(193) + item:SetHeight(40) + local icon = CreateFrame('CheckButton', m.id(), item, 'ActionButtonTemplate') + icon:SetPoint('LEFT', 2, 0.5) + icon:SetHighlightTexture(nil) + icon:RegisterForClicks() + icon:EnableMouse(nil) + item.texture = getglobal(icon:GetName()..'Icon') + item.texture:SetTexCoord(0.06,0.94,0.06,0.94) + item.name = Aux.gui.label(icon) + item.name:SetJustifyH('LEFT') + item.name:SetPoint('LEFT', icon, 'RIGHT', 10, 0) + item.name:SetPoint('RIGHT', item, 'RIGHT', -10, 0.5) + item.name:SetPoint('TOP', item, 'TOP', -5, 0) + item.name:SetPoint('BOTTOM', item, 'BOTTOM', 5, 0) + item.count = getglobal(icon:GetName()..'Count') + return item +end + function public.label(parent, size) local label = parent:CreateFontString() label:SetFont(m.config.content_font, size or m.config.normal_font_size) diff --git a/tables/item_listing.lua b/tables/item_listing.lua index 952448e..b882d65 100644 --- a/tables/item_listing.lua +++ b/tables/item_listing.lua @@ -1,6 +1,6 @@ local m, public, private = Aux.module'item_listing' -local ROW_HEIGHT = 38 +local ROW_HEIGHT = 39 function public.render(item_listing) @@ -20,14 +20,14 @@ function public.render(item_listing) elseif not row.mouse_over then row.highlight:Hide() end - getglobal(row.item:GetName()..'IconTexture'):SetTexture(item_record.texture) - getglobal(row.item:GetName()..'Name'):SetText('['..item_record.name..']') + row.item.texture:SetTexture(item_record.texture) + row.item.name:SetText('['..item_record.name..']') local color = ITEM_QUALITY_COLORS[item_record.quality] - getglobal(row.item:GetName()..'Name'):SetTextColor(color.r, color.g, color.b) + row.item.name:SetTextColor(color.r, color.g, color.b) if item_record.aux_quantity > 1 then - getglobal(row.item:GetName()..'Count'):SetText(item_record.aux_quantity) + row.item.count:SetText(item_record.aux_quantity) else - getglobal(row.item:GetName()..'Count'):SetText() + row.item.count:SetText() end row:Show() else @@ -73,8 +73,8 @@ function public.create(parent, on_click, on_enter, on_leave, selected) while total_height + ROW_HEIGHT < max_height do local row = CreateFrame('Button', nil, content) row:SetHeight(ROW_HEIGHT) - row:SetWidth(193) - row:SetPoint('TOPLEFT', content, 0, -((row_index-1) * ROW_HEIGHT)) + row:SetWidth(195) + row:SetPoint('TOPLEFT', content, 2, -((row_index-1) * ROW_HEIGHT)) row:SetScript('OnClick', on_click) row:SetScript('OnEnter', function() row.highlight:Show() @@ -87,13 +87,15 @@ function public.create(parent, on_click, on_enter, on_leave, selected) on_leave() end) - local item = CreateFrame('Frame', name..'_item'..row_index, row, 'AuxItemTemplate') - row.item = item - item:SetPoint('CENTER', 4, 0) + row.item = Aux.gui.item(row) + row.item:EnableMouse(nil) + row.item:SetScale(0.9) + row.item:SetPoint('LEFT', 2, 0) + row.item:SetPoint('RIGHT', 2, 0) row:RegisterForClicks('LeftButtonUp', 'RightButtonUp') local highlight = row:CreateTexture() - highlight:SetAllPoints(item) + highlight:SetAllPoints(row) highlight:Hide() highlight:SetTexture(1, .9, .9, .1) row.highlight = highlight diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 94eec6b..4cb6143 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -276,10 +276,10 @@ function private.update_item_configuration() if not m.selected_item then m.refresh_button:Disable() - AuxPostItemIconTexture:SetTexture(nil) - AuxPostItemCount:SetText() - AuxPostItemName:SetTextColor(unpack(Aux.gui.config.label_color.enabled)) - AuxPostItemName:SetText('No item selected') + m.item.texture:SetTexture(nil) + m.item.count:SetText() + m.item.name:SetTextColor(unpack(Aux.gui.config.label_color.enabled)) + m.item.name:SetText('No item selected') m.unit_start_price:Hide() m.unit_buyout_price:Hide() @@ -299,14 +299,14 @@ function private.update_item_configuration() m.historical_value_button:Show() m.hide_checkbox:Show() - AuxPostItemIconTexture:SetTexture(m.selected_item.texture) - AuxPostItemName:SetText('['..m.selected_item.name..']') + m.item.texture:SetTexture(m.selected_item.texture) + m.item.name:SetText('['..m.selected_item.name..']') local color = ITEM_QUALITY_COLORS[m.selected_item.quality] - AuxPostItemName:SetTextColor(color.r, color.g, color.b) + m.item.name:SetTextColor(color.r, color.g, color.b) if m.selected_item.aux_quantity > 1 then - AuxPostItemCount:SetText(m.selected_item.aux_quantity) + m.item.count:SetText(m.selected_item.aux_quantity) else - AuxPostItemCount:SetText() + m.item.count:SetText() end m.stack_size_slider.editbox:SetNumber(m.stack_size_slider:GetValue()) diff --git a/tabs/post/frames.lua b/tabs/post/frames.lua index 535d3ff..2aa2588 100644 --- a/tabs/post/frames.lua +++ b/tabs/post/frames.lua @@ -19,44 +19,11 @@ Aux.post_tab.FRAMES(function(m, public, private) m.frame.parameters:SetPoint('TOPLEFT', m.frame.inventory, 'TOPRIGHT', 2.5, 0) m.frame.parameters:SetPoint('TOPRIGHT', 0, 0) - m.frame.parameters.item = CreateFrame('Button', 'AuxPostItem', m.frame.parameters, 'AuxItemTemplate') - m.frame.parameters.item:SetPoint('TOPLEFT', 10, -10) - m.frame.auctions = Aux.gui.panel(m.frame.content) m.frame.auctions:SetHeight(228) m.frame.auctions:SetPoint('BOTTOMLEFT', m.frame.inventory, 'BOTTOMRIGHT', 2.5, 0) m.frame.auctions:SetPoint('BOTTOMRIGHT', 0, 0) - m.frame.parameters.item:EnableMouse() - m.frame.parameters.item:SetScript('OnReceiveDrag', function() - local item_info = Aux.cursor_item() - if item_info then - m.select_item(item_info.item_key) - end - ClearCursor() - end) - m.frame.parameters.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 = m.frame.parameters.item:CreateTexture() - highlight:SetAllPoints(m.frame.parameters.item) - highlight:Hide() - highlight:SetTexture(1, .9, .9, .1) - m.frame.parameters.item:SetScript('OnEnter', function() - highlight:Show() - if m.selected_item then - Aux.info.set_tooltip(m.selected_item.itemstring, this, 'ANCHOR_RIGHT') - end - end) - m.frame.parameters.item:SetScript('OnLeave', function() - highlight:Hide() - GameTooltip:Hide() - end) - do local checkbox = CreateFrame('CheckButton', nil, m.frame.inventory, 'UICheckButtonTemplate') checkbox:SetWidth(22) @@ -150,6 +117,41 @@ Aux.post_tab.FRAMES(function(m, public, private) end) private.refresh_button = btn end + do + local item = Aux.gui.item(m.frame.parameters) + item:SetPoint('TOPLEFT', 10, -10) + item:EnableMouse() + item:SetScript('OnReceiveDrag', function() + local item_info = Aux.cursor_item() + if item_info then + m.select_item(item_info.item_key) + end + ClearCursor() + end) + item:SetScript('OnClick', function() + local item_info = Aux.cursor_item() + if item_info then + m.select_item(item_info.item_key) + end + ClearCursor() + end) + local highlight = item:CreateTexture() + highlight:SetPoint('TOPLEFT', -2, 2) + highlight:SetPoint('BOTTOMRIGHT', 2, -2) + highlight:Hide() + highlight:SetTexture(1, .9, .9, .1) + item:SetScript('OnEnter', function() + highlight:Show() + if m.selected_item then + Aux.info.set_tooltip(m.selected_item.itemstring, this, 'ANCHOR_RIGHT') + end + end) + item:SetScript('OnLeave', function() + highlight:Hide() + GameTooltip:Hide() + end) + private.item = item + end do local slider = Aux.gui.slider(m.frame.parameters) slider:SetValueStep(1)