From 8a777258e6809fadb716a52d7326fb257b087b89 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 22 Aug 2016 21:27:13 +0200 Subject: [PATCH] big refactoring --- New Text Document.txt | 0 frame.lua | 121 +++++++++------------------ gui/core.lua | 137 ++++++++----------------------- util/color.lua | 61 ++++++++++++++ util/{scan_util.lua => scan.lua} | 0 5 files changed, 138 insertions(+), 181 deletions(-) create mode 100644 New Text Document.txt create mode 100644 util/color.lua rename util/{scan_util.lua => scan.lua} (100%) diff --git a/New Text Document.txt b/New Text Document.txt new file mode 100644 index 0000000..e69de29 diff --git a/frame.lua b/frame.lua index 532936e..2e7b894 100644 --- a/frame.lua +++ b/frame.lua @@ -1,85 +1,46 @@ -module 'aux' +module 'aux' import 'gui' -public.bids_loaded = false -public.current_owner_page = nil - -function LOAD() - import :_ 'util' 'gui' - do - local frame = CreateFrame('Frame', gui.name, UIParent) - tinsert(UISpecialFrames, 'aux_frame1') - gui.set_window_style(frame) - gui.set_size(frame, 768, 447) - frame:SetPoint('LEFT', 100, 0) - frame:SetToplevel(true) - frame:SetMovable(true) - frame:EnableMouse(true) - frame:SetClampedToScreen(true) - frame:RegisterForDrag 'LeftButton' - frame:SetScript('OnDragStart', function() this:StartMoving() end) - frame:SetScript('OnDragStop', function() this:StopMovingOrSizing() end) - frame:SetScript('OnShow', function() PlaySound 'AuctionWindowOpen' end) - frame:SetScript('OnHide', function() PlaySound 'AuctionWindowClose' CloseAuctionHouse() end) - frame.content = CreateFrame('Frame', nil, frame) - frame.content:SetPoint('TOPLEFT', 4, -80) - frame.content:SetPoint('BOTTOMRIGHT', -4, 35) - frame:Hide() - public.frame = frame - end - do - local tabs = gui.tabs(frame, 'DOWN') - tabs._on_select = on_tab_click - for _, tab in _m.tabs do tabs:create_tab(tab.name) end - function public.set_tab(id) tabs:select(id) end - end - do - local btn = gui.button(frame, 16) - btn:SetPoint('BOTTOMRIGHT', -6, 6) - gui.set_size(btn, 65, 24) - btn:SetText 'Close' - btn:SetScript('OnClick', L(frame.Hide, frame)) - public.close_button = btn - end - do - local btn = gui.button(frame, 16) - btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0) - gui.set_size(btn, 65, 24) - btn:SetText 'Default UI' - btn:SetScript('OnClick',function() - if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end - end) - end -end - -function public.log(...) - local msg = '[aux]' - for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end - DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg) -end - -tabs = {} -function public.tab(index, name) - local module_env = getfenv(2) - local tab = {name=name, env=module_env} - function module_env.public.accessor.ACTIVE() return tab == active_tab end - for handler in tmp-set-from . OPEN . CLOSE . CLICK_LINK . USE_ITEM do module_env.mutable[handler] = nil end - tabs[index] = tab +do + local frame = CreateFrame('Frame', 'aux_frame', UIParent) + tinsert(UISpecialFrames, 'aux_frame') + gui.set_window_style(frame) + gui.set_size(frame, 768, 447) + frame:SetPoint('LEFT', 100, 0) + frame:SetToplevel(true) + frame:SetMovable(true) + frame:EnableMouse(true) + frame:SetClampedToScreen(true) + frame:RegisterForDrag 'LeftButton' + frame:SetScript('OnDragStart', function() this:StartMoving() end) + frame:SetScript('OnDragStop', function() this:StopMovingOrSizing() end) + frame:SetScript('OnShow', function() PlaySound 'AuctionWindowOpen' end) + frame:SetScript('OnHide', function() PlaySound 'AuctionWindowClose' CloseAuctionHouse() end) + frame.content = CreateFrame('Frame', nil, frame) + frame.content:SetPoint('TOPLEFT', 4, -80) + frame.content:SetPoint('BOTTOMRIGHT', -4, 35) + frame:Hide() + public.aux_frame = frame end do - local active_tab_index - function accessor.active_tab() return tabs[active_tab_index] end - function on_tab_click(index) - call(active_tab_index and active_tab.env.CLOSE) - active_tab_index = index - call(active_tab_index and active_tab.env.OPEN) - end + local tabs = gui.tabs(frame, 'DOWN') + tabs._on_select = on_tab_click + for _, tab in _m.tabs do tabs:create_tab(tab.name) end + function public.set_tab(id) tabs:select(id) end end - -public.orig = setmetatable({[_g]={}}, {__index=function(self, key) return self[_g][key] end}) -function public.hook(name, handler, object) - handler = handler or getfenv(2)[name] - object = object or _g - orig[object] = orig[object] or {} - assert(not orig[object][name], '"'..name..'" is already hooked into.') - orig[object][name], object[name] = object[name], handler +do + local btn = gui.button(frame, 16) + btn:SetPoint('BOTTOMRIGHT', -6, 6) + gui.set_size(btn, 65, 24) + btn:SetText 'Close' + btn:SetScript('OnClick', L(frame.Hide, frame)) + public.close_button = btn +end +do + local btn = gui.button(frame, 16) + btn:SetPoint('RIGHT', close_button, 'LEFT' , -5, 0) + gui.set_size(btn, 65, 24) + btn:SetText 'Default UI' + btn:SetScript('OnClick',function() + if AuctionFrame:IsVisible() then HideUIPanel(AuctionFrame) else ShowUIPanel(AuctionFrame) end + end) end \ No newline at end of file diff --git a/gui/core.lua b/gui/core.lua index cd1f3ec..97892c0 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -1,25 +1,6 @@ module 'gui' public.config = { - colors = { - 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 = {background = {24, 24, 24, .93}, border = {30, 30, 30, 1}}, - panel = {background = {24, 24, 24, 1}, border = {255, 255, 255, .03}}, - content = {background = {42, 42, 42, 1}, border = {0, 0, 0, 0}}, - state = {enabled = {70, 180, 70, 1}, disabled = {190, 70, 70, 1}}, - - blue = {41, 146, 255, 1}, - green = {22, 255, 22, 1}, - yellow = {255, 255, 0, 1}, - orange = {255, 146, 24, 1}, - red = {255, 0, 0, 1}, - gray = {187, 187, 187, 1}, - - blizzard = {0, 180, 255, 1}, - aux = {255, 255, 154, 1}, - }, edge_size = 1.5, font = [[Fonts\ARIALN.TTF]], small_font_size = 13, @@ -32,104 +13,58 @@ public.config = { } do - local function index_handler(self, key) - self.private.table = self.private.table[key] - if getn(self.private.table) == 0 then - return self.public - else - local color = copy(self.private.table) - self.private.table = config.colors - return self.private.callback(color) - end - end - function color_accessor(callback) - return function() - return index_function({callback=callback, table=config.colors}, index_handler) - end + local id = 1 + function public.accessor.name() + id = id + 1 + return 'aux_frame'..id end end do - local mt = { - __call = function(self, text) - local r, g, b, a = unpack(self) - if text then - return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE - else - return r, g, b, a - end + local menu, structure, orig + menu = CreateFrame('Frame', name, UIParent, 'UIMenuTemplate') + hook('OnShow', menu) + orig = menu:GetScript 'OnShow' + menu:SetScript('OnShow', function() + UIMenu_Initialize() + for i=1,getn(structure) do + UIMenu_AddButton( + structure[i][1], + structure[i], + type(structure[i]) == 'string' and structure[element[3]] or element[3] + ) end - } - public.accessor.color = color_accessor(function(color) - local r, g, b, a = unpack(color) - return setmetatable({r/255, g/255, b/255, a}, mt) + return orig() end) -end - -public.accessor.inline_color = color_accessor(function(color) - local r, g, b, a = unpack(color) - return format('|c%02X%02X%02X%02X', a, r, g, b) -end) - -do - local id = 0 - function public.accessor.name() id = id + 1; return 'aux_frame'..id end -end - -do - local menu, structure function public.menu(menu_structure) structure = menu_structure menu:SetPoint('BOTTOMLEFT', GetCursorPosition()) menu:Show() end - function initialize_menu() - menu = CreateFrame('Frame', name, UIParent, 'UIMenuTemplate') - local orig = menu:GetScript 'OnShow' - menu:SetScript('OnShow', function() - UIMenu_Initialize() - for i=1,getn(structure) do - UIMenu_AddButton( - structure[i][1], - structure[i], - type(structure[i]) == 'string' and structure[element[3]] or element[3] - ) - end - return orig() - end) - end -end - -function LOAD() - import :_ 'util' - initialize_menu() - initialize_dropdown() end do local blizzard_backdrop, aux_background, aux_border - function initialize_dropdown() - aux_border = DropDownList1:CreateTexture() - aux_border:SetTexture(1, 1, 1, .02) - aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2) - aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5) - aux_border:SetBlendMode 'ADD' - aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY') - aux_background:SetTexture(color.content.background()) - aux_background:SetAllPoints(DropDownList1Backdrop) - blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() - hook('ToggleDropDownMenu', function(...) - local ret = {orig.ToggleDropDownMenu(unpack(arg))} - local dropdown = getglobal(arg[4] or '') or this:GetParent() - if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then - set_aux_dropdown_style(dropdown) - else - set_blizzard_dropdown_style() - end - return unpack(ret) - end) - end + aux_border = DropDownList1:CreateTexture() + aux_border:SetTexture(1, 1, 1, .02) + aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2) + aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5) + aux_border:SetBlendMode 'ADD' + aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY') + aux_background:SetTexture(color.content.background()) + aux_background:SetAllPoints(DropDownList1Backdrop) + blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() + hook('ToggleDropDownMenu', function(...) + local ret = {orig.ToggleDropDownMenu(unpack(arg))} + local dropdown = getglobal(arg[4] or '') or this:GetParent() + if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then + set_aux_dropdown_style(dropdown) + else + set_blizzard_dropdown_style() + end + return unpack(ret) + end) function set_aux_dropdown_style(dropdown) DropDownList1Backdrop:SetBackdrop{} diff --git a/util/color.lua b/util/color.lua new file mode 100644 index 0000000..e6bcfc0 --- /dev/null +++ b/util/color.lua @@ -0,0 +1,61 @@ +module 'util' + +COLORS = { + 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 = {background = {24, 24, 24, .93}, border = {30, 30, 30, 1}}, + panel = {background = {24, 24, 24, 1}, border = {255, 255, 255, .03}}, + content = {background = {42, 42, 42, 1}, border = {0, 0, 0, 0}}, + state = {enabled = {70, 180, 70, 1}, disabled = {190, 70, 70, 1}}, + + blue = {41, 146, 255, 1}, + green = {22, 255, 22, 1}, + yellow = {255, 255, 0, 1}, + orange = {255, 146, 24, 1}, + red = {255, 0, 0, 1}, + gray = {187, 187, 187, 1}, + + blizzard = {0, 180, 255, 1}, + aux = {255, 255, 154, 1}, +} + +do + local function index_handler(self, key) + self.private.table = self.private.table[key] + if getn(self.private.table) == 0 then + return self.public + else + local color = copy(self.private.table) + self.private.table = COLORS + return self.private.callback(color) + end + end + function color_accessor(callback) + return function() + return index_function({callback=callback, table=COLORS}, index_handler) + end + end +end + +do + local mt = { + __call = function(self, text) + local r, g, b, a = unpack(self) + if text then + return format('|c%02X%02X%02X%02X', a, r*255, g*255, b*255)..text..FONT_COLOR_CODE_CLOSE + else + return r, g, b, a + end + end + } + public.accessor.color = color_accessor(function(color) + local r, g, b, a = unpack(color) + return setmetatable({r/255, g/255, b/255, a}, mt) + end) +end + +public.accessor.inline_color = color_accessor(function(color) + local r, g, b, a = unpack(color) + return format('|c%02X%02X%02X%02X', a, r, g, b) +end) diff --git a/util/scan_util.lua b/util/scan.lua similarity index 100% rename from util/scan_util.lua rename to util/scan.lua