--[[-------------------------------------------------------------------------- ManiaxScroll — Interface options page. Everything here is also reachable from /mscroll; this exists because an add-on whose only interface is a slash command is one a player has to be told about. The panel writes straight into ManiaxScrollDB, which is the same table the engine reads, so there is one copy of the settings and no sync step. Turning something ON re-sweeps immediately and it works at once. Turning something OFF stops the handler doing anything, but the handler stays installed until a reload - which matters only in that the wheel still gets swallowed by that frame rather than falling through. The panel says so rather than pretending otherwise. Built in Lua rather than XML because the pack ships .toc and .lua for this add-on and adding an .xml means a third file loaded for eleven widgets. ----------------------------------------------------------------------------]] local NS = ManiaxScroll if not NS then return end local function get(key) return NS.Get(key) end local function set(key, value) ManiaxScrollDB[key] = value if value then NS.Rescan() end end local panel = CreateFrame("Frame", "ManiaxScrollOptionsPanel", UIParent) panel.name = "Maniax Scroll" panel:Hide() local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") title:SetPoint("TOPLEFT", 16, -16) title:SetText("Maniax Scroll") local blurb = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") blurb:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8) blurb:SetPoint("RIGHT", panel, "RIGHT", -32, 0) blurb:SetJustifyH("LEFT") blurb:SetJustifyV("TOP") blurb:SetText("Mouse wheel in every panel that has one, plus the systems that " .. "are not scroll frames at all: paged windows, models, and the two maps. " .. "Panels that already handle the wheel themselves are left alone.") --------------------------------------------------------------------------- -- Checkboxes. --------------------------------------------------------------------------- local CHECKS = { -- No master switch. Unticking the add-on is the off switch; a second one -- that persisted silently is what made this add-on look broken once. { key = "minimap", label = "Minimap zoom", tip = "Wheel over the minimap to zoom in and out." }, { key = "paged", label = "Paged windows", tip = "Merchant, spellbook, mail, books, companions and the auction browse " .. "list turn their pages on the wheel." }, { key = "pageAtEnd", label = "Turn the page at the end of a list", tip = "Wheeling past the last row of a paged list fetches the next page " .. "instead of stopping. This is what makes an auction search and a " .. "book read continuously." }, { key = "models", label = "Model zoom", tip = "Character sheet, dressing room, pet, stable, tabard and inspect. " .. "Zoom resets when the window closes." }, { key = "worldmap", label = "World map zoom", tip = "Wheel down to zoom out; wheel up retraces the way you came, since " .. "the client has no zoom-in of its own." }, { key = "message", label = "Message frames", tip = "Line buffers such as the guild bank log. Chat windows already " .. "handle the wheel and are not touched." }, { key = "modifiers", label = "Shift scrolls a page, Ctrl jumps to the end", tip = "Modifier keys while wheeling. Off means the wheel always moves by " .. "the step count below." }, } local widgets = {} local anchor = blurb local yGap = -12 for i, spec in ipairs(CHECKS) do local cb = CreateFrame("CheckButton", "ManiaxScrollCheck" .. i, panel, "InterfaceOptionsCheckButtonTemplate") cb:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 0, yGap) _G[cb:GetName() .. "Text"]:SetText(spec.label) cb.tooltipText = spec.label cb.tooltipRequirement = spec.tip cb:SetScript("OnClick", function(self) local on = self:GetChecked() and true or false set(spec.key, on) if not on then -- Honest about the one thing a runtime toggle cannot undo. NS.Say(spec.label .. " off. Already-wired frames stop responding now; " .. "they release the wheel on the next /reload.") end end) widgets[spec.key] = cb anchor = cb yGap = -4 end --------------------------------------------------------------------------- -- Steps per notch. --------------------------------------------------------------------------- local slider = CreateFrame("Slider", "ManiaxScrollLinesSlider", panel, "OptionsSliderTemplate") slider:SetPoint("TOPLEFT", anchor, "BOTTOMLEFT", 6, -24) slider:SetWidth(240) slider:SetMinMaxValues(1, 10) slider:SetValueStep(1) _G[slider:GetName() .. "Low"]:SetText("1") _G[slider:GetName() .. "High"]:SetText("10") slider.tooltipText = "Steps per wheel notch" slider.tooltipRequirement = "How far one notch of the wheel moves a list. " .. "Three is what retail uses." slider:SetScript("OnValueChanged", function(self, value) value = math.floor(value + 0.5) _G[self:GetName() .. "Text"]:SetText("Steps per wheel notch: " .. value) ManiaxScrollDB.lines = value end) --------------------------------------------------------------------------- -- Rescan, and what the sweep has found. --------------------------------------------------------------------------- local status = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") status:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", -6, -24) status:SetJustifyH("LEFT") local function refreshStatus() local c = NS.Counts() status:SetText(string.format( "Wired: |cffffffff%d|r scroll frames, |cffffffff%d|r message frames, " .. "|cffffffff%d|r paged windows, |cffffffff%d|r models, |cffffffff%d|r other.", c.scroll, c.message, c.paged, c.model, c.other)) end local rescan = CreateFrame("Button", "ManiaxScrollRescanButton", panel, "UIPanelButtonTemplate") rescan:SetPoint("TOPLEFT", status, "BOTTOMLEFT", 0, -10) rescan:SetWidth(130) rescan:SetHeight(22) rescan:SetText("Re-scan now") rescan:SetScript("OnClick", function() NS.Rescan() refreshStatus() end) local reset = CreateFrame("Button", "ManiaxScrollResetButton", panel, "UIPanelButtonTemplate") reset:SetPoint("LEFT", rescan, "RIGHT", 8, 0) reset:SetWidth(130) reset:SetHeight(22) reset:SetText("Defaults") reset:SetScript("OnClick", function() for k, v in pairs(NS.DEFAULTS) do ManiaxScrollDB[k] = v end NS.Rescan() panel.refresh() end) --------------------------------------------------------------------------- -- The four functions InterfaceOptionsFrame calls. -- -- Settings are written on click rather than on okay, so cancel has to put -- back what was there when the page was opened - otherwise Cancel would leave -- the changes applied, which is worse than having no Cancel at all. --------------------------------------------------------------------------- local snapshot function panel.refresh() snapshot = {} for k in pairs(NS.DEFAULTS) do snapshot[k] = get(k) end for key, cb in pairs(widgets) do cb:SetChecked(get(key) and true or false) end slider:SetValue(get("lines")) _G[slider:GetName() .. "Text"]:SetText("Steps per wheel notch: " .. get("lines")) refreshStatus() end function panel.okay() snapshot = nil end function panel.cancel() if not snapshot then return end for k, v in pairs(snapshot) do ManiaxScrollDB[k] = v end snapshot = nil NS.Rescan() end function panel.default() for k, v in pairs(NS.DEFAULTS) do ManiaxScrollDB[k] = v end NS.Rescan() panel.refresh() end InterfaceOptions_AddCategory(panel)