-
-
Save merlight/25e02368a1e6187f989c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
AlignGrid.lua | |
Author: Skyraker | |
Assistance by: Garkin and Merlight | |
]]-- | |
----------------------- Addon Locals -------------------------- | |
local WM = WINDOW_MANAGER | |
local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0") | |
local AlignGridWindow | |
local AlignGrid_SavedVars = AlignGrid_SavedVars or {} | |
--------------------------------------------------------------- | |
------------------------- Addon Default Settings --------------- | |
local AlignGridDefault = { | |
reset = false, | |
GRID_SIZE = 32, | |
LINE_THICKNESS = 2, | |
GRID_ALPHA = 0.45, | |
LINE_COLOR = {r = 0, g = 0, b = 0, a = 0.45}, | |
CENT_COLOR = {r = 255, g = 0, b = 0, a = 0.45} | |
} | |
---------------------------------------------------------------- | |
--------------------- Line Creation and Pool Storage -------------------------- | |
local function createLine(pool) | |
local line = WM:CreateControl(nil,AlignGridWindow,CT_TEXTURE) | |
line:SetColor(0,0,0,AlignGrid_SavedVars.settings.GRID_ALPHA) | |
line:SetPixelRoundingEnabled(false) | |
return line | |
end | |
local function resetLines(object) | |
object:SetHidden(true) | |
end | |
AlignGridLinePool = ZO_ObjectPool:New(createLine,resetLines) | |
local function resetGrid() | |
AlignGridLinePool:ReleaseAllObjects() | |
end | |
local function showGrid() | |
AlignGridWindow:SetHidden(false) | |
end | |
local function hideGrid() | |
AlignGridWindow:SetHidden(true) | |
end | |
local function createGrid() | |
local SCREEN_WIDTH, SCREEN_HEIGHT = GuiRoot:GetDimensions() | |
local gridStep = AlignGrid_SavedVars.settings.GRID_SIZE / GetUIGlobalScale() | |
local centAlpha = AlignGrid_SavedVars.settings.GRID_ALPHA | |
local centColor = AlignGrid_SavedVars.settings.CENT_COLOR | |
local lineColor = AlignGrid_SavedVars.settings.LINE_COLOR | |
local lineWidth = AlignGrid_SavedVars.settings.LINE_THICKNESS / GetUIGlobalScale() | |
local function addLine(width, height, offsetX, offsetY, level, color, alpha) | |
local line = AlignGridLinePool:AcquireObject() | |
line:SetDimensions(width, height) | |
line:SetAnchor(CENTER, AlignGridWindow, CENTER, offsetX, offsetY) | |
line:SetDrawLevel(level) | |
line:SetColor(color.r, color.g, color.b, alpha or color.a) | |
line:SetHidden(false) | |
end | |
local function getAlpha(index) | |
if index % 10 == 0 then | |
return centAlpha | |
elseif index % 5 == 0 then | |
return centAlpha * 0.7 | |
else | |
return centAlpha * 0.4 | |
end | |
end | |
resetGrid() | |
-- center cross | |
addLine(lineWidth, SCREEN_HEIGHT, 0, 0, 20, centColor, centAlpha) | |
addLine(SCREEN_WIDTH, lineWidth, 0, 0, 20, centColor, centAlpha) | |
-- vertical lines | |
for i = 1, zo_floor(SCREEN_WIDTH / gridStep / 2) do | |
local a = getAlpha(i) | |
addLine(lineWidth, SCREEN_HEIGHT, i * gridStep, 0, 10, lineColor, a) | |
addLine(lineWidth, SCREEN_HEIGHT, -i * gridStep, 0, 10, lineColor, a) | |
end | |
-- horizontal lines | |
for i = 1, zo_floor(SCREEN_HEIGHT / gridStep / 2) do | |
local a = getAlpha(i) | |
addLine(SCREEN_WIDTH, lineWidth, 0, i * gridStep, 10, lineColor, a) | |
addLine(SCREEN_WIDTH, lineWidth, 0, -i * gridStep, 10, lineColor, a) | |
end | |
end | |
------------------------------------------------------------------------------------------------------------- | |
----------------------------- Setting Menu ----------------------------------------------------------------- | |
local panelData = { | |
type = "panel", | |
name = "AlignGrid", | |
author = "Skyraker", | |
version = "0.2", | |
slashCommand = "/align" | |
} | |
local optionsData = { | |
[1] = { | |
type = "button", | |
name = "Reset Grid", | |
tooltip = "Resets grid with currently selected sizes", | |
func = function() | |
AlignGrid_SavedVars.settings.reset = true | |
createGrid() | |
end | |
}, | |
[2] = { | |
type = "slider", | |
name = "Grid Size", | |
tooltip = "Adjust grid box size", | |
min = 16, | |
max = 54, | |
step = 4, | |
getFunc = function() return AlignGrid_SavedVars.settings.GRID_SIZE end, | |
setFunc = function(value) | |
AlignGrid_SavedVars.settings.GRID_SIZE = value | |
end, | |
warning = "PRESS Reset Grid button to show changes" | |
}, | |
[3] = { | |
type = "slider", | |
name = "Thickness", | |
tooltip = "Adjust thickness of gridlines", | |
min = 1, | |
max = 6, | |
step = 1, | |
getFunc = function() return AlignGrid_SavedVars.settings.LINE_THICKNESS end, | |
setFunc = function(value) | |
AlignGrid_SavedVars.settings.LINE_THICKNESS = value | |
end, | |
warning = "PRESS Reset Grid button to show changes" | |
}, | |
[4] = { | |
type = "slider", | |
name = "Transparency", | |
tooltip = "Adjust transparency of grid.", | |
min = 0, | |
max = 10, | |
step = .5, | |
getFunc = function() return AlignGrid_SavedVars.settings.GRID_ALPHA * 10.0 end, | |
setFunc = function(value) | |
AlignGrid_SavedVars.settings.GRID_ALPHA = value / 10.0 | |
for i = 1, AlignGridLinePool:GetActiveObjectCount() do | |
AlignGridLinePool.m_Active[i]:SetAlpha(value / 10.0) | |
end | |
end | |
}, | |
[5] = { | |
type = "colorpicker", | |
name = "Center Line Color", | |
tooltip = "Color the horizontal and vertical center lines.", | |
getFunc = function() return AlignGrid_SavedVars.settings.CENT_COLOR.r, AlignGrid_SavedVars.settings.CENT_COLOR.g, AlignGrid_SavedVars.settings.CENT_COLOR.b end, | |
setFunc = function(r,g,b,a) | |
AlignGrid_SavedVars.settings.CENT_COLOR.r = r | |
AlignGrid_SavedVars.settings.CENT_COLOR.g = g | |
AlignGrid_SavedVars.settings.CENT_COLOR.b = b | |
end, | |
warning = "PRESS Reset Grid button to show changes" | |
} | |
} | |
LAM2:RegisterAddonPanel("AlignGridOptions", panelData) | |
LAM2:RegisterOptionControls("AlignGridOptions", optionsData) | |
---------------------------------------------------------------------------------------------------------- | |
---------------------------------- Addon Initialization -------------------------------------------------- | |
local function setupSavedVars() | |
AlignGrid_SavedVars = { | |
["settings"] = ZO_SavedVars:New("AlignGrid_SavedVars",1,"settings",AlignGridDefault,nil) | |
} | |
return AlignGrid_SavedVars | |
end | |
local function AddOnLoaded(eventID,addonName) | |
if addonName == "AlignGrid" then | |
EVENT_MANAGER:UnregisterForEvent("AlignGrid_Start",eventID) | |
setupSavedVars() | |
AlignGridWindow = WM:CreateTopLevelWindow("AlignGrid") | |
AlignGridWindow:SetAnchorFill(GuiRoot) | |
AlignGridWindow:SetDrawLayer(DL_BACKGROUND) | |
AlignGridWindow:SetMouseEnabled(false) | |
SLASH_COMMANDS["/grid"] = function() | |
if AlignGridWindow:IsHidden() then | |
AlignGridWindow:SetHidden(false) | |
else | |
AlignGridWindow:SetHidden(true) | |
end | |
end | |
createGrid() | |
hideGrid() | |
end | |
end | |
EVENT_MANAGER:RegisterForEvent("AlignGrid_Start",EVENT_ADD_ON_LOADED,AddOnLoaded) | |
--------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment