A World of Warcraft Experience Bar addon
worldofwarcraft wow addon midnight

add position options and remove drag

bdbch 5626d04e 3cc2b9d8

+98 -72
+3
Config.lua
··· 7 7 questTrackingEnabled = true, 8 8 showTicks = true, 9 9 tickOpacity = 0.35, 10 + anchorPoint = "TOP", 11 + offsetX = 0, 12 + offsetY = 100, 10 13 -- Master visibility toggle (can be flipped with /nxp toggle) 11 14 enabled = true, 12 15
+82
Options.lua
··· 156 156 return y - 52 157 157 end 158 158 159 + local function CreateSliderWithInput(parent, key, label, y, minValue, maxValue, step, inputWidth) 160 + local name = "NXP_Options_" .. key .. "Slider" 161 + local slider = CreateFrame("Slider", name, parent, "OptionsSliderTemplate") 162 + slider:SetPoint("TOPLEFT", parent, "TOPLEFT", 16, y) 163 + slider:SetMinMaxValues(minValue, maxValue) 164 + slider:SetValueStep(step) 165 + slider:SetObeyStepOnDrag(true) 166 + 167 + local labelText = _G[name .. "Text"] 168 + local lowText = _G[name .. "Low"] 169 + local highText = _G[name .. "High"] 170 + if labelText then labelText:SetText(label) end 171 + if lowText then lowText:SetText(tostring(minValue)) end 172 + if highText then highText:SetText(tostring(maxValue)) end 173 + 174 + local edit = CreateFrame("EditBox", nil, parent, "InputBoxTemplate") 175 + edit:SetAutoFocus(false) 176 + edit:SetSize(inputWidth or 60, 20) 177 + edit:SetPoint("LEFT", slider, "RIGHT", 12, 0) 178 + edit:SetNumeric(true) 179 + 180 + slider:SetScript("OnValueChanged", function(self, value) 181 + if self._updating then return end 182 + local rounded = math.floor(value + 0.5) 183 + if step and step < 1 then 184 + rounded = value 185 + end 186 + self._updating = true 187 + self:SetValue(rounded) 188 + self._updating = false 189 + edit:SetNumber(rounded) 190 + SetNumericOption(key, rounded) 191 + end) 192 + 193 + local function commitEdit() 194 + local value = tonumber(edit:GetText()) 195 + if not value then return end 196 + if value < minValue then value = minValue end 197 + if value > maxValue then value = maxValue end 198 + slider._updating = true 199 + slider:SetValue(value) 200 + slider._updating = false 201 + edit:SetNumber(value) 202 + SetNumericOption(key, value) 203 + end 204 + 205 + edit:SetScript("OnEnterPressed", function(self) 206 + commitEdit() 207 + self:ClearFocus() 208 + end) 209 + 210 + edit:SetScript("OnEditFocusLost", function() 211 + commitEdit() 212 + end) 213 + 214 + controls[key] = { type = "offset", slider = slider, edit = edit } 215 + return y - 52 216 + end 217 + 159 218 local function BuildMediaList(kind, defaultLabel, defaultValue) 160 219 local list = {} 161 220 local order = {} ··· 306 365 local r, g, b, a = GetColorOption(key, control.fallback) 307 366 local tex = control.widget:GetNormalTexture() 308 367 if tex then tex:SetColorTexture(r, g, b, a) end 368 + elseif control.type == "offset" then 369 + local value = F.DB[key] 370 + if value == nil then value = defaults[key] end 371 + if value == nil then value = 0 end 372 + control.slider._updating = true 373 + control.slider:SetValue(tonumber(value) or 0) 374 + control.slider._updating = false 375 + control.edit:SetNumber(tonumber(value) or 0) 309 376 elseif control.type == "dropdown" then 310 377 local defaults = F.Config or {} 311 378 local value = F.DB[key] ··· 376 443 y = CreateCheckbox(content, "showTicks", "Show XP ticks", y) 377 444 y = y - 6 378 445 y = CreateSlider(content, "tickOpacity", "Tick opacity", y, 10, 100, 1) 446 + 447 + y = y - 10 448 + y = CreateHeader(content, "Position", y) 449 + y = y - 6 450 + local anchorList = { 451 + TOP = "Top", 452 + BOTTOM = "Bottom", 453 + LEFT = "Left", 454 + RIGHT = "Right", 455 + CENTER = "Center", 456 + } 457 + local anchorOrder = { "TOP", "BOTTOM", "LEFT", "RIGHT", "CENTER" } 458 + y = CreateDropdown(content, "anchorPoint", "Anchor position", y, anchorList, anchorOrder) 459 + y = CreateSliderWithInput(content, "offsetX", "X offset", y, -1000, 1000, 1, 60) 460 + y = CreateSliderWithInput(content, "offsetY", "Y offset", y, -1000, 1000, 1, 60) 379 461 380 462 y = y - 10 381 463 y = CreateHeader(content, "Bar Size", y)
+13 -72
UI.lua
··· 32 32 function F.UI.Create() 33 33 local f = CreateFrame("Frame", "NXP_Frame", UIParent) 34 34 f:SetSize(CFG.width, CFG.height) 35 - f:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 260) -- Default Position 35 + f:SetPoint("TOP", UIParent, "TOP", 0, 100) -- Default Position 36 36 f:SetFrameStrata("LOW") 37 37 38 - -- Enable dragging (only while Shift is held) 39 - f:SetMovable(true) 38 + f:SetMovable(false) 40 39 f:EnableMouse(false) 41 - f:RegisterForDrag("LeftButton") 42 - 43 - local function stopAndMaybeSnap(self) 44 - if self.__nxb_moving then 45 - self:StopMovingOrSizing() 46 - self.__nxb_moving = nil 47 - 48 - local fx, fy = self:GetCenter() 49 - if fx and fy then 50 - local cx, cy = UIParent:GetCenter() 51 - if cx and cy then 52 - local dx, dy = fx - cx, fy - cy 53 - local distSq = dx * dx + dy * dy 54 - local snapRadius = 40 55 - if distSq <= (snapRadius * snapRadius) then 56 - self:ClearAllPoints() 57 - self:SetPoint("CENTER", UIParent, "CENTER", 0, 0) 58 - end 59 - end 60 - end 61 - 62 - self:SetScript("OnUpdate", nil) 63 - end 64 - end 65 - 66 - f:SetScript("OnDragStart", function(self) 67 - if IsShiftKeyDown() then 68 - self:StartMoving() 69 - self.__nxb_moving = true 70 - 71 - self:SetScript("OnUpdate", function(self, elapsed) 72 - if not IsShiftKeyDown() or not IsMouseButtonDown("LeftButton") then 73 - stopAndMaybeSnap(self) 74 - end 75 - end) 76 - end 77 - end) 78 - 79 - f:SetScript("OnDragStop", stopAndMaybeSnap) 80 - 81 - f:SetScript("OnMouseDown", function(self, button) 82 - if button == "LeftButton" and IsShiftKeyDown() then 83 - self:StartMoving() 84 - self.__nxb_moving = true 85 - 86 - self:SetScript("OnUpdate", function(self, elapsed) 87 - if not IsShiftKeyDown() or not IsMouseButtonDown("LeftButton") then 88 - stopAndMaybeSnap(self) 89 - end 90 - end) 91 - end 92 - end) 93 - 94 - f:SetScript("OnMouseUp", function(self, button) 95 - if button == "LeftButton" then 96 - stopAndMaybeSnap(self) 97 - end 98 - end) 99 - 100 - f:RegisterEvent("MODIFIER_STATE_CHANGED") 101 - f:SetScript("OnEvent", function(self, event, key, state) 102 - if event == "MODIFIER_STATE_CHANGED" then 103 - -- Enable/disable clicks based on Shift state 104 - self:EnableMouse(IsShiftKeyDown()) 105 - if not IsShiftKeyDown() and self.__nxb_moving then 106 - stopAndMaybeSnap(self) 107 - end 108 - end 109 - end) 110 40 111 41 F.Frame = f 112 42 ··· 236 166 width = (stepPixels / scale) * 20 237 167 end 238 168 F.Frame:SetSize(width or db.barWidth, db.barHeight) 169 + end 170 + 171 + if db then 172 + local anchor = db.anchorPoint or "TOP" 173 + local x = tonumber(db.offsetX) or 0 174 + local y = tonumber(db.offsetY) or 0 175 + if anchor == "TOP" then 176 + y = -y 177 + end 178 + F.Frame:ClearAllPoints() 179 + F.Frame:SetPoint(anchor, UIParent, anchor, x, y) 239 180 end 240 181 241 182 if F.TickContainer then