Mercurial > wow > buffalo2
diff Config/Config.lua @ 49:16465f3fd919
- remove UpdateAnchorAnchors and use hardlink for the one frame that this applied to
author | Nenue |
---|---|
date | Fri, 29 Apr 2016 10:50:27 -0400 |
parents | 1a322b92dbfa |
children | 07ef62fe201f |
line wrap: on
line diff
--- a/Config/Config.lua Thu Apr 28 06:58:13 2016 -0400 +++ b/Config/Config.lua Fri Apr 29 10:50:27 2016 -0400 @@ -3,14 +3,13 @@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 3/12/2016 12:49 AM -local B, _G = select(2,...).frame, _G -local M = B:RegisterModule("Options") -local tostring, tonumber, floor, format = tostring, tonumber, floor, string.format -local unpack, select, pairs, ipairs, type, wipe = unpack, select, pairs, ipairs, type, table.wipe +local vn, _G = select(2,...).frame, _G +local M = vn:RegisterModule("Options") +local tostring, tonumber, floor, max, assert = tostring, tonumber, floor, math.max, assert +local unpack, setmetatable, pairs, ipairs, type, wipe = unpack, setmetatable, pairs, ipairs, type, table.wipe local CreateFrame, IsControlKeyDown = _G.CreateFrame, _G.IsControlKeyDown -local max = math.max local OpacitySliderFrame, ColorPickerFrame = _G.OpacitySliderFrame, _G.ColorPickerFrame -local print = B.print('Cfgl') +local print = vn.print('Cfgl') local function round(number, decimals) if floor(number) == number then return ('%d'):format(number) @@ -19,27 +18,43 @@ return (("%%.%df"):format(decimals)):format(number) end +--- Set up this way to ensure that all the necessary data exists before things domino into something inscrutable +M.prototypes = { + value = setmetatable({}, {__call = function(self, frame) + assert(frame, 'Expected table (received '..type(frame.OptInfo)..')') + assert(frame.OptRoot, 'Invalid config table for frame '.. frame:GetName().. '') + return self[frame.ValueType](frame.OptTab, frame.OptKey, frame.OptRoot) + end}), + reset = setmetatable({}, {__call = function(self, frame) + assert(frame.GetName, 'Invalid frame reference (received '..type(frame.OptInfo)..')') + assert(frame.OptInfo, 'Expecting a table (received '..type(frame.OptInfo)..')') + return self[frame.OptType](frame, frame.OptInfo) + end}) +} +M.config = {} M.defaults = { enable = true } - +local GetValue = M.prototypes.value +local ResetField = M.prototypes.reset --- STATE VARIABLES local configInit --- Dummies for addon table upvalues local configFrames = {} -- actual frame objects -local displays = B.displays -- anchor objects dummy +local displays = vn.displays -- anchor objects dummy --- Returns a value retreival function and the current value stored in config -- @paramsig value, previousValue = configInteger(key) -- @param key Name of the config field being represented. local defaultGroup = 'BuffButton' -local configInteger = function(group, key) - return function(self ,display) + +GetValue.Integer = function(group, key, parent) + return function(self) return floor(tonumber(self:GetValue()) + 0.5) - end, (B.Conf[group ..key] or B.Conf[defaultGroup..key]) + end, (parent[group ..key] or parent[defaultGroup..key]) end -local configPercent = function(group, key) +GetValue.Percent = function(group, key, parent) return function(self, display) local value = self:GetValue() if display then @@ -47,9 +62,9 @@ else return floor((value*100+0.5))/100 end - end, (B.Conf[group ..key] or B.Conf[defaultGroup..key]) + end, (parent[group ..key] or parent[defaultGroup..key]) end -local configColor = function(group, key) +GetValue.Color = function(group, key, parent) -- table for config, color value list for text return function(self, display) if display then @@ -58,70 +73,71 @@ else return self.rgba end - end, (B.Conf[group ..key] or B.Conf[defaultGroup..key]) + end, (parent[group ..key] or parent[defaultGroup..key]) end -local configCheck = function(group, key) - return function(self) return self:GetChecked() end, B.Conf[group ..key] or B.Conf[defaultGroup..key] +GetValue.Check = function(group, key, parent) + return function(self) return self:GetChecked() end, parent[group ..key] or vn.Conf[defaultGroup..key] end -- initializes the corresponding type of config field local frameTypeConv = { Color = 'Button', Font = 'Frame', } -local configTypeParams = { - Slider = function(frame, optionInfo) + + +ResetField.Slider = function(frame, optionInfo) frame:SetMinMaxValues(optionInfo[5], optionInfo[6]) frame:SetValueStep(optionInfo[7]) frame:SetStepsPerPage(optionInfo[8]) print(frame.OptName, '\n {', optionInfo[5], optionInfo[6], optionInfo[7], optionInfo[8], '}') - end, - CheckButton = function(frame, optionInfo) + end +ResetField.CheckButton = function(frame, optionInfo) frame.SetValue = function(self, ...) self:SetChecked(...) - B.Conf[self.OptName] = self:GetChecked() + self.OptRoot[self.OptName] = self:GetChecked() print(self.OptTab) - B.UpdateAll() + vn.UpdateAll() end frame:SetScript("OnClick",function(self) - B.Conf[self.OptName] = self:GetChecked() - print(B.Conf[self.OptName], self:GetChecked()) - B.UpdateAll() + self.OptRoot[self.OptName] = self:GetChecked() + print(self.OptRoot[self.OptName], self:GetChecked()) + vn.UpdateAll() end) - end, - Color = function(frame, optionInfo) - frame.rgba = { frame.current:GetVertexColor() } - local colorPickerCallback = function(restore) - local newR, newG, newB, newA - if restore then - newR, newG, newB, newA = unpack(restore) - else - newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB() - print('not cancel', newA, newR, newB, newG) - end - frame:SetValue({newR, newG, newB, newA}) - B.UpdateBuffs(frame.OptTab) + end +ResetField.Color = function(frame, optionInfo) + frame.rgba = { frame.current:GetVertexColor() } + local colorPickerCallback = function(restore) + local newR, newG, newB, newA + if restore then + newR, newG, newB, newA = unpack(restore) + else + newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB() + print('not cancel', newA, newR, newB, newG) end - frame:SetScript("OnClick", function(self) - print('got a click') - local r, g, b, a = frame.current:GetVertexColor() - ColorPickerFrame:SetColorRGB(r, g, b) - ColorPickerFrame.hasOpacity = (a ~= nil) - ColorPickerFrame.opacity = a - ColorPickerFrame.previousValues = {r,g,b,a} - ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = - colorPickerCallback, colorPickerCallback,colorPickerCallback - ColorPickerFrame:Hide() - ColorPickerFrame:Show() - end) - frame.SetValue = function(self, rgba) - print(rgba) - frame.rgba = rgba - B.Conf[self.OptName] = rgba - frame.current:SetVertexColor(unpack(rgba)) - frame.fieldvalue:SetText(frame.OptValue(frame, true)) - end + frame:SetValue({newR, newG, newB, newA}) + vn.UpdateBuffs(frame.OptTab) end -} + frame:SetScript("OnClick", function(self) + print('got a click') + local r, g, b, a = frame.current:GetVertexColor() + ColorPickerFrame:SetColorRGB(r, g, b) + ColorPickerFrame.hasOpacity = (a ~= nil) + ColorPickerFrame.opacity = a + ColorPickerFrame.previousValues = {r,g,b,a} + ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = + colorPickerCallback, colorPickerCallback,colorPickerCallback + ColorPickerFrame:Hide() + ColorPickerFrame:Show() + end) + frame.SetValue = function(self, rgba) + print(rgba) + frame.rgba = rgba + self.OptRoot[self.OptName] = rgba + frame.current:SetVertexColor(unpack(rgba)) + frame.fieldvalue:SetText(frame.OptValue(frame, true)) + end +end + --- configDialog -- @usage tinsert(configDialog, {prefix, row, [...] }) -- Each top level member defines a group of config value handlers, structured as an iterative table where the @@ -130,48 +146,48 @@ -- the string literal widget suffix. -- widget table: ... {'suffix', 'description', valueCallback, 'template', [widget parameters]} -- widget copy: ... 'suffix', ... -local configDialog = { +M.config.BuffFrame = { {'BuffButton', 1, - {'Max', 'Max', configInteger, 'Slider', + {'Max', 'Max', 'Integer', 'Slider', 1, _G.BUFF_MAX_DISPLAY, 1, 1}, -- valueMin, valueMax, valueStep, stepsPerPage - {'PerRow', 'Per Row', configInteger, 'Slider', + {'PerRow', 'Per Row', 'Integer', 'Slider', 1, _G.BUFF_MAX_DISPLAY, 1, 1}, -- valueMin, valueMax, valueStep, stepsPerPage, - {'Size', 'Icon Size', configInteger, 'Slider', + {'Size', 'Icon Size', 'Integer', 'Slider', 1, 256, 1, 1}, - {'Spacing', 'Icon Spacing', configInteger, 'Slider', + {'Spacing', 'Icon Spacing', 'Integer', 'Slider', 1, 50, 1, 1}, - {'DurationSize', 'Duration Text Height', configInteger, 'Slider', + {'DurationSize', 'Duration Text Height', 'Integer', 'Slider', 1, 72, 1, 1}, - {'Zoom', 'Icon Zoom', configInteger, 'Slider', + {'Zoom', 'Icon Zoom', 'Integer', 'Slider', 0, 100, 1, 1}, - {'Border', 'Border', configInteger, 'Slider', + {'Border', 'Border', 'Integer', 'Slider', 1, 16, 1, 1}, - {'Color', 'Default Border', configColor, 'Color'}, - {'RaidColor', 'RaidBuff Border', configColor, 'Color'}, - {'PlayerColor', 'Player Buffs', configColor, 'Color'}, - {'BossColor', 'Encounter Buffs', configColor, 'Color'}, - {'ShowSelfCast', 'Show name for self-casts', configCheck, 'CheckButton'} + {'Color', 'Default Border', 'Color', 'Color'}, + {'RaidColor', 'RaidBuff Border', 'Color', 'Color'}, + {'PlayerColor', 'Player Buffs', 'Color', 'Color'}, + {'BossColor', 'Encounter Buffs', 'Color', 'Color'}, + {'ShowSelfCast', 'Show name for self-casts', 'Check', 'CheckButton'} }, { 'DebuffButton', 1, - {'Max', 'Max', configInteger, 'Slider', + {'Max', 'Max', 'Integer', 'Slider', 1, _G.DEBUFF_MAX_DISPLAY, 1, 1 } , - {'PerRow', 'Per Row', configInteger, 'Slider', + {'PerRow', 'Per Row', 'Integer', 'Slider', 1, _G.DEBUFF_MAX_DISPLAY, 1, 1 }, 'Size', 'Spacing', 'DurationSize', 'Zoom', 'Border', 'Color', 'RaidColor', 'PlayerColor', 'BossColor', }, { 'TempEnchant', 1, - {'Max', 'Max', configInteger, 'Slider', + {'Max', 'Max', 'Integer', 'Slider', 1, _G.NUM_TEMP_ENCHANT_FRAMES, 1, 1 }, - {'PerRow', 'Per Row', configInteger, 'Slider', + {'PerRow', 'Per Row', 'Integer', 'Slider', 1, _G.NUM_TEMP_ENCHANT_FRAMES, 1, 1}, 'Size', 'Spacing', 'DurationSize', 'Zoom', 'Border', 'Color', 'RaidColor', 'PlayerColor', 'BossColor', }, { 'ConsolidatedBuff', 2, - {'Position', 'Slot Position', configInteger, 'Slider', + {'Position', 'Slot Position', 'Integer', 'Slider', 1, _G.BUFF_MAX_DISPLAY, 1, 1 } }, @@ -179,7 +195,7 @@ 'Size' }, { 'Raid', 3, - {'ShowMissing', 'Verbose missing raid buffs', configCheck, 'CheckButton'} + {'ShowMissing', 'Verbose missing raid buffs', 'Check', 'CheckButton'} } } @@ -193,7 +209,7 @@ --- Walks the structure table to generate a pretty config panel local InitConfig = function() configInit = true - local configWidth = B:GetWidth() + local configWidth = vn:GetWidth() local optionWidth = (configWidth - configPadding) / 3 - configSpacing local configHeight = 0 local bottom_extent = 0 @@ -202,7 +218,8 @@ local lastCluster local cluster = 1 local col = 0 - for t, taboptions in ipairs(configDialog) do + for moduleName, moduleOpts in pairs(M.config) do + for t, taboptions in ipairs(moduleOpts) do local group = taboptions[1] cluster = taboptions[2] col = col + 1 @@ -230,7 +247,9 @@ if type(optionInfo) == 'string' then optionInfo = optionTemplates[optionInfo] end - local key, fieldname, valueFuncGenerator, configType = unpack(optionInfo) + local key, fieldname, valueType, configType = unpack(optionInfo) + assert(GetValue[valueType], 'Invalid valueType \''..tostring(valueType)..'\' ('..type(valueType)..')') + assert(ResetField[configType], 'Invalid fieldType \''..tostring(configType)..'\' ('..type(configType)..')') if not optionTemplates[key] then optionTemplates[key] = optionInfo @@ -243,14 +262,19 @@ print('building frame', t, group, row) local frameTemplate = 'VeneerConfig'..configType local frameType = frameTypeConv[configType] or configType - configFrames[t][row] = CreateFrame(frameType, fullkey, B, frameTemplate) + configFrames[t][row] = CreateFrame(frameType, 'Vn_'.. moduleName ..'_'.. fullkey, vn, frameTemplate) local f = configFrames[t][row] + f.ValueType = valueType + f.OptType = configType + f.FrameType = frameType f.OptKey = key + f.OptRoot = vn.Conf[moduleName] f.OptTab = group f.OptName = fullkey - local valueFunc, initialValue = valueFuncGenerator(group, key) - print(' value getter', fullkey,'->', valueFunc,initialValue) - configTypeParams[configType](f, optionInfo) + f.OptInfo = optionInfo + local valueFunc, initialValue = GetValue(f) + print(' value getter', '|cFFFFFF00'..moduleName..'|r.|cFF00FFFF'.. tostring(fullkey),'|r->', valueFunc,initialValue) + ResetField(f) f.OptValue = valueFunc --- Enclosing these to @@ -276,14 +300,13 @@ configInit = nil end local newValue = valueFunc(self) - if newValue ~= B.Conf[fullkey] then + if newValue ~= self.OptRoot[fullkey] then print(newValue, fullkey) f.fieldvalue:SetText(valueFunc(self, true)) - B.Conf[fullkey] = valueFunc(self) + self.OptRoot[fullkey] = valueFunc(self) -- prepare to update - wipe(B.drawn[f.OptTab]) - B.UpdateBuffs(self.OptTab) - B.UpdateConfigLayers() + vn[moduleName]:OnUpdate() + vn.UpdateConfigLayers() end end @@ -303,7 +326,7 @@ local base if (row == 1) then bottom_extent = 0 - base = B.header + base = vn.header x = (col-1) * (optionWidth+configSpacing) y = -configPadding else @@ -328,66 +351,68 @@ --print('y', floor(yBuffer+0.5), 'f:H', floor(f:GetHeight()+0.5), 'hTally', floor(bottom_extent+0.5), 'hMax', floor(configHeight+0.5)) end end + end end + -- grab the last cluster if lastCluster == cluster then print('|cFF00FF00##scooping up last cluster info') configHeight = configHeight + clusterHeight end - if not B.configFramesCreated then - B.configFramesCreated = true - B:SetHeight(B.header:GetStringHeight() + configSpacing*3 + configHeight) + if not vn.configFramesCreated then + vn.configFramesCreated = true + vn:SetHeight(vn.header:GetStringHeight() + configSpacing*3 + configHeight) end if configInit then configInit = nil end end M.Command = function(enable, editbox) - displays = B.displays + displays = vn.displays if type(enable) == 'boolean' then - B.Conf.ConfigMode = enable + vn.Conf.ConfigMode = enable else - B.Conf.ConfigMode = (B.Conf.ConfigMode == false) and true or false + vn.Conf.ConfigMode = (vn.Conf.ConfigMode == false) and true or false end - print('/BUFF', B.Conf.ConfigMode, type(B.Conf.ConfigMode)) - if B.Conf.ConfigMode then - if not B.configFramesCreated then + print('/BUFF', vn.Conf.ConfigMode, type(vn.Conf.ConfigMode)) + if vn.Conf.ConfigMode then + if not vn.configFramesCreated then InitConfig() end print('Veneer config') - B:Show() + vn:Show() else - B:Hide() + vn:Hide() end - B.UpdateAll() - B.UpdateConfigLayers() + vn.UpdateAll() + vn.UpdateConfigLayers() end -B.Close = function () +vn.Close = function () M.Command() end -B.ToggleGuides = function(_, self) - B.Conf.GuidesMode = (not B.Conf.GuidesMode) - if B.Conf.GuidesMode then +vn.ToggleGuides = function(_, self) + vn.Conf.GuidesMode = (not vn.Conf.GuidesMode) + if vn.Conf.GuidesMode then self:GetNormalTexture():SetTexture(0.94, 0.21, 0.21, 1) else self:GetNormalTexture():SetTexture(0, 0, 0, 1) end - B.UpdateConfigLayers() + vn.UpdateConfigLayers() end M.OnEnable = function() - print('|cFFFF0088config module', B.Conf.ConfigMode) - M.Command(B.Conf.ConfigMode) + print('|cFFFF0088config module', vn.Conf.ConfigMode) + M.Command(vn.Conf.ConfigMode) end M.OnInitialize = function() - DEFAULT_CHAT_FRAME:AddMessage("|cFF22D822Veneer|r") - SLASH_BUFFALO1, SLASH_BUFFALO2 = "/buffalo", "/buff" - SlashCmdList.BUFFALO = M.Command + DEFAULT_CHAT_FRAME:AddMessage("|cFF22D822Veneer|r confogulator loaded. Type |cFF00FFFF/vn|r to begin.") + SLASH_VENEER1, SLASH_VENEER2 = "/veneer", "/vn" + SlashCmdList.VENEER = M.Command end \ No newline at end of file