big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-22 14:09:41 +02:00
parent 9384a1910c
commit 57723491fb
6 changed files with 64 additions and 76 deletions
+42 -42
View File
@@ -31,46 +31,6 @@ public.config = {
huge_font_size = 23,
}
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
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.getter.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.getter.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.getter.name() id = id + 1; return 'aux_frame'..id end
@@ -78,13 +38,11 @@ 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'
@@ -103,6 +61,48 @@ do
end
function LOAD()
import :_ 'util'
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
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.getter.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.getter.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)
initialize_menu()
initialize_dropdown()
end