Skip to content

Commit

Permalink
Update color picker for Classic to be the same as retail now (Still i…
Browse files Browse the repository at this point in the history
…nverted alpha for some reason in Classic...)
  • Loading branch information
Luxocracy committed Sep 28, 2024
1 parent 09e8734 commit cb59177
Showing 1 changed file with 56 additions and 36 deletions.
92 changes: 56 additions & 36 deletions NeatPlates/NeatPlatesUtility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1023,57 +1023,71 @@ end
local CreateColorBox
do

local workingFrame
local function ChangeColorRetail(cancel)
local a, r, g, b
if cancel then
workingFrame:SetBackdropColor(ColorPickerFrame:GetPreviousValues())
-- For some reason alpha is inverse in some version...
local function CorrectAlphaValue(a)
if NEATPLATES_IS_CLASSIC then
return 1 - a
else
a, r, g, b = ColorPickerFrame:GetColorAlpha(), ColorPickerFrame:GetColorRGB();
workingFrame:SetBackdropColor(r,g,b,a)
if workingFrame.OnValueChanged then workingFrame:OnValueChanged() end
return a
end
end

local function ChangeColorClassic(cancel)
local workingFrame
local function ChangeColorRetail(cancel)
local a, r, g, b
if cancel then
r,g,b,a = unpack(ColorPickerFrame.startingval )
workingFrame:SetBackdropColor(r,g,b,a)
r, g, b, a = ColorPickerFrame:GetPreviousValues()
a = CorrectAlphaValue(a)
workingFrame:SetBackdropColor(r, g, b, a)
else
a, r, g, b = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
a, r, g, b = ColorPickerFrame:GetColorAlpha(), ColorPickerFrame:GetColorRGB();
a = CorrectAlphaValue(a)
workingFrame:SetBackdropColor(r,g,b,a)
if workingFrame.OnValueChanged then workingFrame:OnValueChanged() end
end
end

-- local function ChangeColorClassic(cancel)
-- local a, r, g, b
-- if cancel then
-- r,g,b,a = unpack(ColorPickerFrame.startingval )
-- workingFrame:SetBackdropColor(r,g,b,a)
-- else
-- a, r, g, b = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
-- workingFrame:SetBackdropColor(r,g,b,a)
-- if workingFrame.OnValueChanged then workingFrame:OnValueChanged() end
-- end
-- end

local function ChangeColor(cancel)
if NEATPLATES_IS_CLASSIC then
ChangeColorClassic(cancel)
else
-- if NEATPLATES_IS_CLASSIC and not NEATPLATES_IS_CLASSIC_ERA then
-- ChangeColorClassic(cancel)
-- else
ChangeColorRetail(cancel)
end
-- end
end


local function ShowColorPickerClassic(frame, onOkay)
local r,g,b,a = frame:GetBackdropColor()
workingFrame = frame
ColorPickerFrame.swatchFunc = ChangeColor
ColorPickerFrame.opacityFunc = function() if onOkay and not ColorPickerFrame:IsShown() then onOkay(RGBToHex(ColorPickerFrame:GetColorRGB())) end; ChangeColor() end
ColorPickerFrame.cancelFunc = ChangeColor
ColorPickerFrame.startingval = {r,g,b,a}
ColorPickerFrame:SetColorRGB(r,g,b);
ColorPickerFrame.hasOpacity = true
ColorPickerFrame.opacity = 1 - a
ColorPickerFrame:SetFrameStrata(frame:GetFrameStrata())
ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel()+1)
ColorPickerFrame:Hide(); ColorPickerFrame:Show(); -- Need to activate the OnShow handler.
end
-- local function ShowColorPickerClassic(frame, onOkay)
-- local r,g,b,a = frame:GetBackdropColor()
-- workingFrame = frame
-- ColorPickerFrame.swatchFunc = ChangeColor
-- ColorPickerFrame.opacityFunc = function() if onOkay and not ColorPickerFrame:IsShown() then onOkay(RGBToHex(ColorPickerFrame:GetColorRGB())) end; ChangeColor() end
-- ColorPickerFrame.cancelFunc = ChangeColor
-- ColorPickerFrame.startingval = {r,g,b,a}
-- ColorPickerFrame:SetColorRGB(r,g,b);
-- ColorPickerFrame.hasOpacity = true
-- ColorPickerFrame.opacity = 1 - a
-- ColorPickerFrame:SetFrameStrata(frame:GetFrameStrata())
-- ColorPickerFrame:SetFrameLevel(frame:GetFrameLevel()+1)
-- ColorPickerFrame:Hide(); ColorPickerFrame:Show(); -- Need to activate the OnShow handler.
-- end

local function ShowColorPickerRetail(frame, onOkay)
local r,g,b,a = frame:GetBackdropColor()

a = CorrectAlphaValue(a)

local handler = function(cancel)
ChangeColor(cancel)
if onOkay then
Expand All @@ -1100,11 +1114,11 @@ do
end

local function ShowColorPicker(frame, onOkay)
if NEATPLATES_IS_CLASSIC then
ShowColorPickerClassic(frame, onOkay)
else
-- if NEATPLATES_IS_CLASSIC and not NEATPLATES_IS_CLASSIC_ERA then
-- ShowColorPickerClassic(frame, onOkay)
-- else
ShowColorPickerRetail(frame, onOkay)
end
-- end
end

function CreateColorBox(self, reference, parent, label, onOkay, r, g, b, a)
Expand All @@ -1122,8 +1136,14 @@ do
colorbox.Label:SetPoint("TOPLEFT", colorbox, "TOPRIGHT", 4, -7)
colorbox.Label:SetText(label)

colorbox.GetValue = function() local color = {}; color.r, color.g, color.b, color.a = colorbox:GetBackdropColor(); return color end
colorbox.SetValue = function(self, color) colorbox:SetBackdropColor(color.r, color.g, color.b, color.a); end
colorbox.GetValue = function()
local color = {};
color.r, color.g, color.b, color.a = colorbox:GetBackdropColor();
return color
end
colorbox.SetValue = function(self, color)
colorbox:SetBackdropColor(color.r, color.g, color.b, color.a);
end
--colorbox.tooltipText = "Colorbox"
return colorbox
end
Expand Down

0 comments on commit cb59177

Please sign in to comment.