Skip to content

Instantly share code, notes, and snippets.

@SacredDuckwhale SacredDuckwhale/resike-code.lua Secret
Created Oct 17, 2017

Embed
What would you like to do?
local AddonName, Addon = ...
local AddOn = { }
math.round = function(self)
return math.floor(self + 0.5)
end
AddOn.events = CreateFrame("Frame")
AddOn.events:RegisterEvent("ADDON_LOADED")
AddOn.events:SetScript("OnEvent", function(self, event, ...)
AddOn[event](AddOn, ...)
end)
function AddOn:ADDON_LOADED(addon)
if addon == AddonName then
self:OnLoad()
self:OnLoad2()
end
end
function AddOn:OnLoad()
local frame = CreateFrame("Frame", "TestFrame", UIParent)
frame:SetSize(84, 84)
frame.width = 84
frame.height = 84
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", (UIParent:GetWidth() / 2) - (frame:GetWidth() / 2), (-UIParent:GetHeight() / 2) + (frame:GetHeight() / 2))
frame:SetClampedToScreen(true)
frame.backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 3, right = 3, top = 3, bottom = 3},
}
frame:SetBackdrop(frame.backdrop)
frame:SetBackdropColor(0.0, 0.0, 0.0, 0.5)
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame.scaled = CreateFrame("Frame", nil, frame)
frame.scaled:SetAllPoints(frame)
frame.texture1 = frame:CreateTexture(nil, "ARTWORK", nil, -8)
frame.texture1:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -10)
frame.texture1:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 10)
frame.texture1:SetColorTexture(1, 1, 1, 1)
frame.texture2 = frame:CreateTexture(nil, "ARTWORK", nil, -7)
frame.texture2:SetPoint("TOPLEFT", frame.texture1, "TOPLEFT", 2, -2)
frame.texture2:SetPoint("BOTTOMRIGHT", frame.texture1, "BOTTOMRIGHT", -2, 2)
frame.texture2:SetColorTexture(0, 0, 0, 2)
frame.texture3 = frame:CreateTexture(nil, "ARTWORK", nil, -6)
frame.texture3:SetPoint("TOPLEFT", frame.texture2, "TOPLEFT", 2, -2)
frame.texture3:SetPoint("BOTTOMRIGHT", frame.texture2, "BOTTOMRIGHT", -2, 2)
frame.texture3:SetColorTexture(1, 1, 1, 1)
frame.texture4 = frame:CreateTexture(nil, "ARTWORK", nil, -5)
frame.texture4:SetPoint("TOPLEFT", frame.texture3, "TOPLEFT", 2, -2)
frame.texture4:SetPoint("BOTTOMRIGHT", frame.texture3, "BOTTOMRIGHT", -2, 2)
frame.texture4:SetColorTexture(0, 0, 0, 1)
frame.texture5 = frame:CreateTexture(nil, "ARTWORK", nil, -4)
frame.texture5:SetPoint("TOPLEFT", frame.texture4, "TOPLEFT", 2, -2)
frame.texture5:SetPoint("BOTTOMRIGHT", frame.texture4, "BOTTOMRIGHT", -2, 2)
frame.texture5:SetColorTexture(1, 1, 1, 1)
frame.texture6 = frame:CreateTexture(nil, "ARTWORK", nil, -3)
frame.texture6:SetPoint("TOPLEFT", frame.texture5, "TOPLEFT", 2, -2)
frame.texture6:SetPoint("BOTTOMRIGHT", frame.texture5, "BOTTOMRIGHT", -2, 2)
frame.texture6:SetColorTexture(0, 0, 0, 1)
frame.texture7 = frame:CreateTexture(nil, "ARTWORK", nil, -2)
frame.texture7:SetPoint("TOPLEFT", frame.texture6, "TOPLEFT", 2, -2)
frame.texture7:SetPoint("BOTTOMRIGHT", frame.texture6, "BOTTOMRIGHT", -2, 2)
frame.texture7:SetColorTexture(1, 1, 1, 1)
frame.texture8 = frame:CreateTexture(nil, "ARTWORK", nil, -1)
frame.texture8:SetPoint("TOPLEFT", frame.texture7, "TOPLEFT", 2, -2)
frame.texture8:SetPoint("BOTTOMRIGHT", frame.texture7, "BOTTOMRIGHT", -2, 2)
frame.texture8:SetColorTexture(0, 0, 0, 1)
frame.texture9 = frame:CreateTexture(nil, "ARTWORK", nil, 0)
frame.texture9:SetPoint("TOPLEFT", frame.texture8, "TOPLEFT", 2, -2)
frame.texture9:SetPoint("BOTTOMRIGHT", frame.texture8, "BOTTOMRIGHT", -2, 2)
frame.texture9:SetColorTexture(1, 1, 1, 1)
frame.texture10 = frame:CreateTexture(nil, "ARTWORK", nil, 1)
frame.texture10:SetPoint("TOPLEFT", frame.texture9, "TOPLEFT", 2, -2)
frame.texture10:SetPoint("BOTTOMRIGHT", frame.texture9, "BOTTOMRIGHT", -2, 2)
frame.texture10:SetColorTexture(0, 0, 0, 1)
frame.texture11 = frame:CreateTexture(nil, "ARTWORK", nil, 2)
frame.texture11:SetPoint("TOPLEFT", frame.texture10, "TOPLEFT", 2, -2)
frame.texture11:SetPoint("BOTTOMRIGHT", frame.texture10, "BOTTOMRIGHT", -2, 2)
frame.texture11:SetColorTexture(1, 1, 1, 1)
frame.pixel = frame.scaled:CreateFontString(nil, "ARTWORK")
frame.pixel:SetPoint("TOPLEFT", frame.texture11, "TOPLEFT", 2, -2)
frame.pixel:SetPoint("BOTTOMRIGHT", frame.texture11, "BOTTOMRIGHT", -2, 2)
frame.pixel:SetFontObject(GameFontNormalSmall)
frame.pixel:SetText("PP")
-- Hooks
hooksecurefunc(frame, "SetPoint", function(self)
if self.moving then
return
end
self.moving = true
self:SetMovable(true)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
self:SetMovable(false)
self.moving = nil
end)
hooksecurefunc(frame, "StopMovingOrSizing", function(self)
self:SetMovable(true)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
self:SetMovable(false)
end)
frame:HookScript("OnSizeChanged", function(self)
self:SetSize(math.round(self:GetWidth()), math.round(self:GetHeight()))
local scale = self:GetWidth() / self.width
self.scaled:SetScale(scale)
self.texture2:SetPoint("TOPLEFT", self.texture1, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture2:SetPoint("BOTTOMRIGHT", self.texture1, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture3:SetPoint("TOPLEFT", self.texture2, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture3:SetPoint("BOTTOMRIGHT", self.texture2, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture4:SetPoint("TOPLEFT", self.texture3, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture4:SetPoint("BOTTOMRIGHT", self.texture3, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture5:SetPoint("TOPLEFT", self.texture4, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture5:SetPoint("BOTTOMRIGHT", self.texture4, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture6:SetPoint("TOPLEFT", self.texture5, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture6:SetPoint("BOTTOMRIGHT", self.texture5, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture7:SetPoint("TOPLEFT", self.texture6, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture7:SetPoint("BOTTOMRIGHT", self.texture6, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture8:SetPoint("TOPLEFT", self.texture7, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture8:SetPoint("BOTTOMRIGHT", self.texture7, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture9:SetPoint("TOPLEFT", self.texture8, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture9:SetPoint("BOTTOMRIGHT", self.texture8, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture10:SetPoint("TOPLEFT", self.texture9, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture10:SetPoint("BOTTOMRIGHT", self.texture9, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
self.texture11:SetPoint("TOPLEFT", self.texture10, "TOPLEFT", math.round(2 * scale), math.round(-2 * scale))
self.texture11:SetPoint("BOTTOMRIGHT", self.texture10, "BOTTOMRIGHT", math.round(-2 * scale), math.round(2 * scale))
end)
-- Moving and Resizing functions
frame:EnableMouse(true)
--frame:SetMaxResize(800, 400)
frame:SetMinResize(42, 42)
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:SetMovable(true)
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
self:SetMovable(false)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
end
end)
frame.br = CreateFrame("Frame", nil, frame)
frame.br:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT", 0, 0)
frame.br:SetSize(12, 12)
frame.br:EnableMouse(true)
frame.br.texture = frame.br:CreateTexture(nil, "OVERLAY")
frame.br.texture:SetPoint("TOPLEFT", frame.br, "TOPLEFT", 0, 0)
frame.br.texture:SetSize(12, 12)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.br:SetScript("OnEnter", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.br:SetScript("OnLeave", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.br:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame:SetResizable(true)
frame:StartSizing("BottomRight")
end
end)
frame.br:SetScript("OnMouseUp", function(self, button)
frame:StopMovingOrSizing()
frame:SetResizable(false)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
end
function AddOn:OnLoad2()
local frame = CreateFrame("Frame", "TestFrame2", UIParent)
frame:SetSize(84, 84)
frame.width = 84
frame.height = 84
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", (UIParent:GetWidth() / 2) - (frame:GetWidth() / 2) + 100, (-UIParent:GetHeight() / 2) + (frame:GetHeight() / 2))
frame:SetClampedToScreen(true)
frame.backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 3, right = 3, top = 3, bottom = 3},
}
frame:SetBackdrop(frame.backdrop)
frame:SetBackdropColor(0.0, 0.0, 0.0, 0.5)
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame.scaled = CreateFrame("Frame", nil, frame)
frame.scaled:SetAllPoints(frame)
frame.texture1 = frame:CreateTexture(nil, "ARTWORK", nil, -8)
frame.texture1:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -10)
frame.texture1:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 10)
frame.texture1:SetColorTexture(1, 1, 1, 1)
frame.texture2 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -7)
frame.texture2:SetPoint("TOPLEFT", frame.texture1, "TOPLEFT", 2, -2)
frame.texture2:SetPoint("BOTTOMRIGHT", frame.texture1, "BOTTOMRIGHT", -2, 2)
frame.texture2:SetColorTexture(0, 0, 0, 2)
frame.texture3 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -6)
frame.texture3:SetPoint("TOPLEFT", frame.texture2, "TOPLEFT", 2, -2)
frame.texture3:SetPoint("BOTTOMRIGHT", frame.texture2, "BOTTOMRIGHT", -2, 2)
frame.texture3:SetColorTexture(1, 1, 1, 1)
frame.texture4 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -5)
frame.texture4:SetPoint("TOPLEFT", frame.texture3, "TOPLEFT", 2, -2)
frame.texture4:SetPoint("BOTTOMRIGHT", frame.texture3, "BOTTOMRIGHT", -2, 2)
frame.texture4:SetColorTexture(0, 0, 0, 1)
frame.texture5 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -4)
frame.texture5:SetPoint("TOPLEFT", frame.texture4, "TOPLEFT", 2, -2)
frame.texture5:SetPoint("BOTTOMRIGHT", frame.texture4, "BOTTOMRIGHT", -2, 2)
frame.texture5:SetColorTexture(1, 1, 1, 1)
frame.texture6 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -3)
frame.texture6:SetPoint("TOPLEFT", frame.texture5, "TOPLEFT", 2, -2)
frame.texture6:SetPoint("BOTTOMRIGHT", frame.texture5, "BOTTOMRIGHT", -2, 2)
frame.texture6:SetColorTexture(0, 0, 0, 1)
frame.texture7 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -2)
frame.texture7:SetPoint("TOPLEFT", frame.texture6, "TOPLEFT", 2, -2)
frame.texture7:SetPoint("BOTTOMRIGHT", frame.texture6, "BOTTOMRIGHT", -2, 2)
frame.texture7:SetColorTexture(1, 1, 1, 1)
frame.texture8 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -1)
frame.texture8:SetPoint("TOPLEFT", frame.texture7, "TOPLEFT", 2, -2)
frame.texture8:SetPoint("BOTTOMRIGHT", frame.texture7, "BOTTOMRIGHT", -2, 2)
frame.texture8:SetColorTexture(0, 0, 0, 1)
frame.texture9 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 0)
frame.texture9:SetPoint("TOPLEFT", frame.texture8, "TOPLEFT", 2, -2)
frame.texture9:SetPoint("BOTTOMRIGHT", frame.texture8, "BOTTOMRIGHT", -2, 2)
frame.texture9:SetColorTexture(1, 1, 1, 1)
frame.texture10 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 1)
frame.texture10:SetPoint("TOPLEFT", frame.texture9, "TOPLEFT", 2, -2)
frame.texture10:SetPoint("BOTTOMRIGHT", frame.texture9, "BOTTOMRIGHT", -2, 2)
frame.texture10:SetColorTexture(0, 0, 0, 1)
frame.texture11 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 2)
frame.texture11:SetPoint("TOPLEFT", frame.texture10, "TOPLEFT", 2, -2)
frame.texture11:SetPoint("BOTTOMRIGHT", frame.texture10, "BOTTOMRIGHT", -2, 2)
frame.texture11:SetColorTexture(1, 1, 1, 1)
frame.pixel = frame.scaled:CreateFontString(nil, "ARTWORK")
frame.pixel:SetPoint("TOPLEFT", frame.texture11, "TOPLEFT", 2, -2)
frame.pixel:SetPoint("BOTTOMRIGHT", frame.texture11, "BOTTOMRIGHT", -2, 2)
frame.pixel:SetFontObject(GameFontNormalSmall)
frame.pixel:SetText("NPP")
frame:HookScript("OnSizeChanged", function(self)
self:SetSize(self:GetWidth(), self:GetHeight())
local scale = self:GetWidth() / self.width
self.scaled:SetScale(scale)
end)
-- Moving and Resizing functions
frame:EnableMouse(true)
--frame:SetMaxResize(800, 400)
frame:SetMinResize(42, 42)
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:SetMovable(true)
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
self:SetMovable(false)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = left
local y = -UIParent:GetHeight() + bottom + self:GetHeight()
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
end
end)
frame.br = CreateFrame("Frame", nil, frame)
frame.br:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT", 0, 0)
frame.br:SetSize(12, 12)
frame.br:EnableMouse(true)
frame.br.texture = frame.br:CreateTexture(nil, "OVERLAY")
frame.br.texture:SetPoint("TOPLEFT", frame.br, "TOPLEFT", 0, 0)
frame.br.texture:SetSize(12, 12)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.br:SetScript("OnEnter", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.br:SetScript("OnLeave", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.br:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame:SetResizable(true)
frame:StartSizing("BottomRight")
end
end)
frame.br:SetScript("OnMouseUp", function(self, button)
frame:StopMovingOrSizing()
frame:SetResizable(false)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.