--[[ OctoBus settings window: /ob options, or right-click the minimap icon. Changes apply at once and are saved with the rest of OctoBus's settings. ]] local font = STANDARD_TEXT_FONT or "Fonts\\FRIZQT__.TTF" local W = 300 local frame, controls = nil, {} local loading = false local function Backdrop(f) f:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8X8", edgeFile = "Interface\\Buttons\\WHITE8X8", tile = false, tileSize = 0, edgeSize = 1, insets = { left = 1, right = 1, top = 1, bottom = 1 }, }) f:SetBackdropColor(0.02, 0.02, 0.02, 0.92) f:SetBackdropBorderColor(0.3, 0.3, 0.3, 1) end local function Heading(text, y) local fs = frame:CreateFontString(nil, "OVERLAY") fs:SetFont(font, 11, "OUTLINE") fs:SetPoint("TOPLEFT", frame, "TOPLEFT", 12, y) fs:SetText("|cff33ffcc" .. text .. "|r") end local sliderCount = 0 -- get() returns the setting's current value; set(v) applies it; fmt(v) is the label text local function Slider(label, y, lo, hi, step, get, set, fmt) sliderCount = sliderCount + 1 local name = "OctoBusOptionsSlider" .. sliderCount local s = CreateFrame("Slider", name, frame, "OptionsSliderTemplate") s:SetPoint("TOPLEFT", frame, "TOPLEFT", 18, y) s:SetWidth(W - 36) s:SetMinMaxValues(lo, hi) s:SetValueStep(step) getglobal(name .. "Low"):SetText("") getglobal(name .. "High"):SetText("") local text = getglobal(name .. "Text") text:SetFont(font, 10) s.Update = function() loading = true s:SetValue(get()) loading = false text:SetText(label .. ": |cffffffff" .. fmt(get()) .. "|r") end s:SetScript("OnValueChanged", function() if loading then return end local v = math.floor(this:GetValue() / step + 0.5) * step set(v) text:SetText(label .. ": |cffffffff" .. fmt(v) .. "|r") end) table.insert(controls, s) return s end local checkCount = 0 local function Check(label, x, y, get, set) checkCount = checkCount + 1 local name = "OctoBusOptionsCheck" .. checkCount local c = CreateFrame("CheckButton", name, frame, "OptionsCheckButtonTemplate") c:SetWidth(24) c:SetHeight(24) c:SetPoint("TOPLEFT", frame, "TOPLEFT", x, y) local text = getglobal(name .. "Text") text:SetFont(font, 10) text:SetText(label) c.Update = function() c:SetChecked(get() and 1 or nil) end c:SetScript("OnClick", function() set(this:GetChecked() and true or false) end) table.insert(controls, c) return c end local function pct(v) return math.floor(v * 100 + 0.5) .. "%" end local function Build() local OB = OctoBus local C = OB.cfg frame = CreateFrame("Frame", "OctoBusOptions", UIParent) frame:SetWidth(W) frame:SetHeight(538) frame:SetPoint("CENTER", UIParent, "CENTER", 0, 60) frame:SetFrameStrata("DIALOG") frame:SetClampedToScreen(true) frame:SetMovable(true) frame:EnableMouse(true) frame:RegisterForDrag("LeftButton") frame:SetScript("OnDragStart", function() this:StartMoving() end) frame:SetScript("OnDragStop", function() this:StopMovingOrSizing() end) Backdrop(frame) table.insert(UISpecialFrames, "OctoBusOptions") -- Escape closes it local title = frame:CreateFontString(nil, "OVERLAY") title:SetFont(font, 12, "OUTLINE") title:SetPoint("TOP", frame, "TOP", 0, -10) title:SetText("|cff33ffccOcto|rBus settings") local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton") close:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 2, 2) local function look(key) return function(v) C[key] = v OB.ApplyLook() end end Heading("Window", -34) Slider("Background opacity", -64, 0, 1, 0.05, function() return C.bgAlpha or 0.75 end, look("bgAlpha"), pct) Slider("Window opacity", -102, 0.2, 1, 0.05, function() return C.alpha or 1 end, look("alpha"), pct) Slider("Text size", -140, 0.7, 1.5, 0.05, function() return C.textScale or 1 end, look("textScale"), pct) Slider("Window size", -178, OB.scaleMin, OB.scaleMax, 0.05, function() return C.scale or 1 end, function(v) OB.SetScale(v) end, pct) Check("Lock position and size", 14, -204, function() return C.locked end, function(v) OB.SetLocked(v) end) -- which corner stays in place when the list gets longer or shorter local corner = frame:CreateFontString(nil, "OVERLAY") corner:SetFont(font, 10) corner:SetPoint("TOPLEFT", frame, "TOPLEFT", 18, -234) corner:SetText("Corner that stays put as the list grows or shrinks:") corner:SetTextColor(1, 0.82, 0) local CORNERS = { { "TOPLEFT", "Top left", 14, -248 }, { "TOPRIGHT", "Top right", 150, -248 }, { "BOTTOMLEFT", "Bottom left", 14, -272 }, { "BOTTOMRIGHT", "Bottom right", 150, -272 }, } for i = 1, table.getn(CORNERS) do local a = CORNERS[i][1] Check(CORNERS[i][2], CORNERS[i][3], CORNERS[i][4], function() return (C.anchor or "BOTTOMLEFT") == a end, function() OB.SetAnchor(a) for j = 1, table.getn(controls) do controls[j].Update() end -- one corner at a time end) end Heading("Routes", -302) Check("Open by itself only at route ends", 14, -320, function() return C.zoneOnly end, function(v) C.zoneOnly = v end) Check("Show all routes (not just for where you are)", 14, -344, function() return C.full end, function(v) C.full = v OB.Refresh() end) Check("Show the Sparkwater Port boat", 14, -368, function() return not C.hideBoat end, function(v) C.hideBoat = not v OB.Refresh() end) Heading("Alerts (click a row to put a bell on it)", -400) Slider("Warn before arrival", -430, 10, 120, 5, function() return C.alert or 45 end, function(v) C.alert = v end, function(v) return math.floor(v + 0.5) .. " s" end) Check("Chat message", 14, -452, function() return C.chat end, function(v) C.chat = v end) Check("Sound", 120, -452, function() return C.sound end, function(v) C.sound = v end) Check("Flash the minimap icon", 14, -476, function() return C.flash end, function(v) C.flash = v end) local reset = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") reset:SetWidth(150) reset:SetHeight(20) reset:SetPoint("BOTTOM", frame, "BOTTOM", 0, 12) reset:SetText("Reset window look") reset:SetScript("OnClick", function() C.bgAlpha, C.alpha, C.textScale = nil, nil, nil OB.SetScale(1) OB.ApplyLook() for i = 1, table.getn(controls) do controls[i].Update() end end) end function OctoBus_Options() if not OctoBus then DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccOctoBus:|r not running, so its settings are unavailable.") return end if not frame then Build() end if frame:IsShown() then frame:Hide() return end for i = 1, table.getn(controls) do controls[i].Update() end OctoBus.Show() -- show the timer window so changes can be seen frame:Show() end