Mercurial > wow > reaction
diff Editor.lua @ 237:704f4a05a1d7
Demodulificate all bar options (except state options)
author | Flick |
---|---|
date | Thu, 24 Mar 2011 13:11:30 -0700 |
parents | a5d91d7fd485 |
children | f255cd69e890 |
line wrap: on
line diff
--- a/Editor.lua Thu Mar 24 13:09:44 2011 -0700 +++ b/Editor.lua Thu Mar 24 13:11:30 2011 -0700 @@ -20,7 +20,9 @@ BOTTOMRIGHT = L["Bottom Right"], } -local Editor = { } +local Editor = { + buttonHandlers = { } +} function Editor:New() -- create new self @@ -323,6 +325,7 @@ }, }, }, + buttonOpts = self:CreateButtonOptions(bar) }, plugins = { } } @@ -347,6 +350,17 @@ end end +function Editor:CreateButtonOptions(bar) + local buttonClass = bar:GetButtonClass() + local classID = buttonClass:GetButtonTypeID() + local handler = self.buttonHandlers[classID] + + if handler then + local h = handler:New(bar) + return h:GetOptions() + end +end + function Editor:RefreshBarOptions() for name, key in pairs(self.barOptMap) do if not ReAction:GetBar(name) then @@ -399,6 +413,548 @@ end end +------------------------------- +---- Action button handler ---- +------------------------------- + +do + local ActionHandler = { + buttonClass = ReAction.Button.Action, + options = { + hideEmpty = { + name = L["Hide Empty Buttons"], + order = 1, + type = "toggle", + width = "double", + get = "GetHideEmpty", + set = "SetHideEmpty", + }, + lockButtons = { + name = L["Lock Buttons"], + desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], + order = 2, + type = "toggle", + get = "GetLockButtons", + set = "SetLockButtons", + }, + lockOnlyCombat = { + name = L["Only in Combat"], + desc = L["Only lock the buttons when in combat"], + order = 3, + type = "toggle", + disabled = "LockButtonsCombatDisabled", + get = "GetLockButtonsCombat", + set = "SetLockButtonsCombat", + }, + pages = { + name = L["# Pages"], + desc = L["Use the Dynamic State tab to specify page transitions"], + order = 4, + type = "range", + min = 1, + max = 10, + step = 1, + get = "GetNumPages", + set = "SetNumPages", + }, + mindcontrol = { + name = L["Mind Control Support"], + desc = L["When possessing a target (e.g. via Mind Control), map the first 12 buttons of this bar to the possessed target's actions."], + order = 5, + type = "toggle", + width = "double", + set = "SetMindControl", + get = "GetMindControl", + }, + vehicle = { + name = L["Vehicle Support"], + desc = L["When on a vehicle, map the first 6 buttons of this bar to the vehicle actions. The vehicle-exit button is mapped to the 7th button. Pitch controls are not supported."], + order = 6, + type = "toggle", + width = "double", + get = "GetVehicle", + set = "SetVehicle", + }, + actions = { + name = L["Edit Action IDs"], + order = 7, + type = "group", + inline = true, + args = { + method = { + name = L["Assign"], + order = 1, + type = "select", + width = "double", + values = { [0] = L["Choose Method..."], + [1] = L["Individually"], + [2] = L["All at Once"], }, + get = "GetActionEditMethod", + set = "SetActionEditMethod", + }, + rowSelect = { + name = L["Row"], + desc = L["Rows are numbered top to bottom"], + order = 2, + type = "select", + width = "half", + hidden = "IsButtonSelectHidden", + values = "GetRowList", + get = "GetSelectedRow", + set = "SetSelectedRow", + }, + colSelect = { + name = L["Col"], + desc = L["Columns are numbered left to right"], + order = 3, + type = "select", + width = "half", + hidden = "IsButtonSelectHidden", + values = "GetColumnList", + get = "GetSelectedColumn", + set = "SetSelectedColumn", + }, + pageSelect = { + name = L["Page"], + order = 4, + type = "select", + width = "half", + hidden = "IsPageSelectHidden", + values = "GetPageList", + get = "GetSelectedPage", + set = "SetSelectedPage", + }, + single = { + name = L["Action ID"], + usage = L["Specify ID 1-120"], + order = 5, + type = "input", + width = "half", + hidden = "IsButtonSelectHidden", + get = "GetActionID", + set = "SetActionID", + validate = "ValidateActionID", + }, + multi = { + name = L["ID List"], + usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"], + order = 6, + type = "input", + multiline = true, + width = "double", + hidden = "IsMultiIDHidden", + get = "GetMultiID", + set = "SetMultiID", + validate = "ValidateMultiID", + }, + }, + }, + } + } + + Editor.buttonHandlers[ActionHandler.buttonClass:GetButtonTypeID()] = ActionHandler + + local meta = { __index = ActionHandler } + + function ActionHandler:New( bar ) + return setmetatable( + { + bar = bar, + config = bar:GetConfig(), + }, + meta) + end + + function ActionHandler:Refresh() + self.buttonClass:SetupBar(self.bar) + end + + function ActionHandler:UpdateButtonLock() + self.buttonClass:SetButtonLock(self.bar, self.config.lockButtons, self.config.lockButtonsCombat) + end + + function ActionHandler:GetLastButton() + return self.bar:GetButton(self.bar:GetNumButtons()) + end + + -- options handlers + function ActionHandler:GetOptions() + return { + type = "group", + name = L["Action Buttons"], + handler = self, + order = 2, + args = self.options + } + end + + function ActionHandler:SetHideEmpty(info, value) + if value ~= self.config.hideEmpty then + self.config.hideEmpty = value + for _, b in self.bar:IterateButtons() do + b:ShowGrid(not value) + end + end + end + + function ActionHandler:GetHideEmpty() + return self.config.hideEmpty + end + + function ActionHandler:GetLockButtons() + return self.config.lockButtons + end + + function ActionHandler:SetLockButtons(info, value) + self.config.lockButtons = value + self:UpdateButtonLock() + end + + function ActionHandler:GetLockButtonsCombat() + return self.config.lockButtonsCombat + end + + function ActionHandler:SetLockButtonsCombat(info, value) + self.config.lockButtonsCombat = value + self:UpdateButtonLock() + end + + function ActionHandler:LockButtonsCombatDisabled() + return not self.config.lockButtons + end + + function ActionHandler:GetNumPages() + return self.config.nPages + end + + function ActionHandler:SetNumPages(info, value) + self.config.nPages = value + self:Refresh() + end + + function ActionHandler:GetMindControl() + return self.config.mindcontrol + end + + function ActionHandler:SetMindControl(info, value) + self.config.mindcontrol = value + self:Refresh() + end + + function ActionHandler:GetVehicle() + return self.config.vehicle + end + + function ActionHandler:SetVehicle(info, value) + self.config.vehicle = value + self:Refresh() + end + + function ActionHandler:GetActionEditMethod() + return self.editMethod or 0 + end + + function ActionHandler:SetActionEditMethod(info, value) + self.editMethod = value + end + + function ActionHandler:IsButtonSelectHidden() + return self.editMethod ~= 1 + end + + function ActionHandler:GetRowList() + local r,c = self.bar:GetButtonGrid() + if self.rowList == nil or #self.rowList ~= r then + local list = { } + for i = 1, r do + table.insert(list,i) + end + self.rowList = list + end + return self.rowList + end + + function ActionHandler:GetSelectedRow() + local r, c = self.bar:GetButtonGrid() + local row = self.selectedRow or 1 + if row > r then + row = 1 + end + self.selectedRow = row + return row + end + + function ActionHandler:SetSelectedRow(info, value) + self.selectedRow = value + end + + function ActionHandler:GetColumnList() + local r,c = self.bar:GetButtonGrid() + if self.columnList == nil or #self.columnList ~= c then + local list = { } + for i = 1, c do + table.insert(list,i) + end + self.columnList = list + end + return self.columnList + end + + function ActionHandler:GetSelectedColumn() + local r, c = self.bar:GetButtonGrid() + local col = self.selectedColumn or 1 + if col > c then + col = 1 + end + self.selectedColumn = col + return col + end + + function ActionHandler:SetSelectedColumn(info, value) + self.selectedColumn = value + end + + function ActionHandler:IsPageSelectHidden() + return self.editMethod ~= 1 or (self.config.nPages or 1) < 2 + end + + function ActionHandler:GetPageList() + local n = self.config.nPages or 1 + if self.pageList == nil or #self.pageList ~= n then + local p = { } + for i = 1, n do + table.insert(p,i) + end + self.pageList = p + end + return self.pageList + end + + function ActionHandler:GetSelectedPage() + local p = self.selectedPage or 1 + if p > (self.config.nPages or 1) then + p = 1 + end + self.selectedPage = p + return p + end + + function ActionHandler:SetSelectedPage(info, value) + self.selectedPage = value + end + + function ActionHandler:GetActionID() + local row = self.selectedRow or 1 + local col = self.selectedColumn or 1 + local r, c = self.bar:GetButtonGrid() + local n = (row-1) * c + col + local btn = self.bar:GetButton(n) + if btn then + return tostring(btn:GetActionID(self.selectedPage or 1)) + end + end + + function ActionHandler:SetActionID(info, value) + local row = self.selectedRow or 1 + local col = self.selectedColumn or 1 + local r, c = self.bar:GetButtonGrid() + local n = (row-1) * c + col + local btn = self.bar:GetButton(n) + if btn then + btn:SetActionID(tonumber(value), self.selectedPage or 1) + end + end + + function ActionHandler:ValidateActionID(info, value) + value = tonumber(value) + if value == nil or value < 1 or value > 120 then + return L["Specify ID 1-120"] + end + return true + end + + function ActionHandler:IsMultiIDHidden() + return self.editMethod ~= 2 + end + + function ActionHandler:GetMultiID() + local p = { } + for i = 1, self.config.nPages or 1 do + local b = { } + for _, btn in self.bar:IterateButtons() do + table.insert(b, btn:GetActionID(i)) + end + table.insert(p, table.concat(b,",")) + end + return table.concat(p,";\n") + end + + + local function ParseMultiID(nBtns, nPages, s) + if s:match("[^%d%s,;]") then + return nil + end + local p = { } + for list in s:gmatch("[^;]+") do + local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns)) + local ids = { list:match(pattern) } + if #ids ~= nBtns then + return nil + end + table.insert(p,ids) + end + if #p ~= nPages then + return nil + end + return p + end + + function ActionHandler:SetMultiID(info, value) + local p = ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) + for page, b in ipairs(p) do + for button, id in ipairs(b) do + self.bar:GetButton(button):SetActionID(id, page) + end + end + end + + function ActionHandler:ValidateMultiID(info, value) + local bad = L["Invalid action ID list string"] + if value == nil or ParseMultiID(self.bar:GetNumButtons(), self.config.nPages or 1, value) == nil then + return bad + end + return true + end +end + + +---------------------------------- +---- PetAction button handler ---- +---------------------------------- + +do + local PetHandler = { + buttonClass = ReAction.Button.PetAction, + } + + Editor.buttonHandlers[PetHandler.buttonClass:GetButtonTypeID()] = PetHandler + + local meta = { __index = PetHandler } + + function PetHandler:New(bar) + return setmetatable( + { + bar = bar, + config = bar.config + }, meta) + end + + function PetHandler:GetLockButtons() + return self.config.lockButtons + end + + function PetHandler:SetLockButtons(info, value) + self.config.lockButtons = value + self.buttonClass:UpdateButtonLock(self.bar) + end + + function PetHandler:GetLockButtonsCombat() + return self.config.lockButtonsCombat + end + + function PetHandler:SetLockButtonsCombat(info, value) + self.config.lockButtonsCombat = value + self.buttonClass:UpdateButtonLock(self.bar) + end + + function PetHandler:LockButtonsCombatDisabled() + return not self.config.lockButtons + end + + function PetHandler:GetOptions() + return { + type = "group", + name = L["Pet Buttons"], + handler = self, + order = 2, + args = { + lockButtons = { + name = L["Lock Buttons"], + desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"], + order = 2, + type = "toggle", + get = "GetLockButtons", + set = "SetLockButtons", + }, + lockOnlyCombat = { + name = L["Only in Combat"], + desc = L["Only lock the buttons when in combat"], + order = 3, + type = "toggle", + disabled = "LockButtonsCombatDisabled", + get = "GetLockButtonsCombat", + set = "SetLockButtonsCombat", + }, + } + } + end +end + + +------------------------------------- +---- Vehicle Exit button handler ---- +------------------------------------- + +do + local VExitHandler = { + buttonClass = ReAction.Button.VehicleExit, + } + + Editor.buttonHandlers[VExitHandler.buttonClass:GetButtonTypeID()] = VExitHandler + + local meta = { __index = VExitHandler } + + function VExitHandler:New(bar) + return setmetatable( + { + bar = bar, + }, meta) + end + + function VExitHandler:GetConfig() + return self.bar:GetConfig() + end + + function VExitHandler:GetPassengerOnly() + return not self:GetConfig().withControls + end + + function VExitHandler:SetPassengerOnly(info, value) + self:GetConfig().withControls = not value + self.buttonClass:UpdateRegistration(self.bar) + end + + + function VExitHandler:GetOptions() + return { + type = "group", + name = L["Exit Vehicle"], + handler = self, + args = { + passengerOnly = { + name = L["Show only when passenger"], + desc = L["Only show the button when riding as a passenger in a vehicle (no vehicle controls)"], + order = 2, + width = "double", + type = "toggle", + get = "GetPassengerOnly", + set = "SetPassengerOnly", + }, + } + } + end +end + ---- Export to ReAction ----