Ok so I have one final problem that I can't seem to figure out, and my googling has turned up no help.
In addition to the color wheel, I have some hard coded color options that I want the user to be able to choose from via a drop down menu.
I was able to successfully get the drop down to successfully open, set the colors in my addon and then display the current color chosen in the drop down frame when it is closed. My saved variables get set properly so the color is saved between sessions.
What I can't figure out is how to get the drop down menu to read from the saved variables so that it will correctly display the chosen value when the user opens up the options menu in a different session.
When I reload the ui, it sets the value of the displayed text to "Default". I tried to not declare a default value for cvcolor at the top of the file, but then i get a nil value concat error.
cvred, cvgreen, cvblue, cvalpha, cvcolor are all declared in my toc and I can watch the saved variables file get updated when i reload the ui.
Again I'm probably missing something stupid easy.
Lua Code:
--Set color variables default values to avoid first load errors
cvred = 1
cvgreen = .996
cvblue = .545
cvalpha = 1
cvcolor = "Default"
--Hard coded color options table
local colorTable = {
["blue"] = {0, 0, 1},
["green"] = {0, 1, 0},
["red"] = {1, 0, 0},
["black"] = {0, 0, 0},
["white"] = {1, 1, 1},
["light blue"] = {0, 1, 1},
["light red"] = {1, .5, .5},
["pink"] = {1, .5, 1},
["purple"] = {.7, 0, 1},
["orange"] = {1, 0.5, 1},
["default"] = {1, .996, .545}
}
--Color Picker
local function ShowColorPicker(cvred, cvgreen, cvblue, cvalpha, changedCallback)
ColorPickerFrame:SetColorRGB(cvred, cvgreen, cvblue);
ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (cvalpha ~= nil), cvalpha;
ColorPickerFrame.previousValues = {cvred, cvgreen, cvblue, cvalpha};
ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc = changedCallback, changedCallback, changedCallback;
ColorPickerFrame:Hide();
ColorPickerFrame:Show();
end
function myColorCallback(restore)
local newR, newG, newB, newA;
if restore then
newR, newG, newB, newA = unpack(restore);
else
newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();
end
cvred, cvgreen, cvblue, cvalpha = newR, newG, newB, newA;
end
--Create a Frame to add to the default options panel
local cvrpanel = CreateFrame("Frame")
cvrpanel.name = "Convert Ratings"
--Options Panel Title
local cvropttitle = cvrpanel:CreateFontString("ARTWORK", nil, "GameFontNormalLarge")
cvropttitle:SetPoint("TOP")
cvropttitle:SetText("Convert Ratings")
--Add a dropdown menu to select a pre defined color
local cvrddtitle = cvrpanel:CreateFontString("ARTWORK", nil, "GameFontNormal")
cvrddtitle:SetPoint("TOPLEFT", cvrpanel, 0, - 80)
cvrddtitle:SetText("Pick a Color")
local cvrdropdown = CreateFrame("Frame", "CVRDropDown", cvrpanel, "UIDropDownMenuTemplate")
cvrdropdown:SetPoint("TOPLEFT", cvrpanel, -20, -100)
UIDropDownMenu_SetWidth(cvrdropdown, 150)
local function cvrdropdown_OnClick(self, arg1, arg2, checked)
cvred, cvgreen, cvblue = unpack(colorTable[string.lower(arg1)])
UIDropDownMenu_SetText(cvrdropdown, "Current Color: " .. arg1)
cvcolor = tostring(arg1)
end
function cvrdropdown_Menu(frame, level, menuList)
UIDropDownMenu_SetText(cvrdropdown, "Current Color: " .. cvcolor)
local info = UIDropDownMenu_CreateInfo()
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Default", "Default"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Blue", "Blue"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Green", "Green"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Red", "Red"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Black", "Black"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "White", "White"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Light Blue", "Light Blue"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Light Red", "Light Red"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Pink", "Pink"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Purple", "Purple"
UIDropDownMenu_AddButton(info)
info.func = cvrdropdown_OnClick
info.text, info.arg1 = "Orange", "Orange"
UIDropDownMenu_AddButton(info)
end
UIDropDownMenu_Initialize(cvrdropdown, cvrdropdown_Menu)
--Add a button to open the custom color picker
local cvrbutton = CreateFrame("Button", nil, cvrpanel, "UIPanelButtonTemplate")
cvrbutton:SetPoint("TOPLEFT", cvrpanel, 0, -40)
cvrbutton:SetText("Custom Color")
cvrbutton:SetWidth(150)
cvrbutton:HookScript("OnClick", function() ShowColorPicker(cvred, cvgreen, cvblue, nil, myColorCallback); cvcolor = "Custom"; UIDropDownMenu_SetText(cvrdropdown, "Current Color: " .. cvcolor) end)
--Add our panel to the options frame
InterfaceOptions_AddCategory(cvrpanel)
Edit: I just noticed that when I click on the dropdown menu in the options frame, the displayed text changes to the value currently set in the saved variable. So it knows what it is between sessions, it just doesn't update until i click on the drop down menu frame.