Thread Tools Display Modes
Prev Previous Post   Next Post Next
02-06-23, 03:14 AM   #1
briskman3000
A Flamescale Wyrmkin
 
briskman3000's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 108
How to move my slash commands to the options panel?

So my brain hurts from trying to figure this out. I tried to look at some of the other addons that I have installed, but they all seem to use libraries for this, which I don't use or really understand.

So I currently use a set of slash commands to handle the only configurable portion of my addon, the color in which the text is displayed for the user.

Currently this is how I accomplish this:

Lua Code:
  1. --Set color variables default values to avoid first load errors
  2. cvred = 1
  3. cvgreen = .996
  4. cvblue = .545
  5. cvalpha = 1
  6.  
  7. --Hard coded color options table
  8. local colorTable = {
  9.     ["blue"] = {0, 0, 1},
  10.     ["green"] = {0, 1, 0},
  11.     ["red"] = {1, 0, 0},
  12.     ["black"] = {0, 0, 0},
  13.     ["white"] = {1, 1, 1},
  14.     ["lightblue"] = {0, 1, 1},
  15.     ["lightred"] = {1, .5, .5},
  16.     ["pink"] = {1, .5, 1},
  17.     ["purple"] = {.7, 0, 1},
  18.     ["orange"] = {1, 0.5, 1},
  19.     ["default"] = {1, .996, .545}
  20. }
  21.  
  22. --Color Picker
  23. function ShowColorPicker(cvred, cvgreen, cvblue, cvalpha, changedCallback)
  24.  ColorPickerFrame:SetColorRGB(cvred, cvgreen, cvblue);
  25.  ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (cvalpha ~= nil), cvalpha;
  26.  ColorPickerFrame.previousValues = {cvred, cvgreen, cvblue, cvalpha};
  27.  ColorPickerFrame.func, ColorPickerFrame.opacityFunc, ColorPickerFrame.cancelFunc =  changedCallback, changedCallback, changedCallback;
  28.  ColorPickerFrame:Hide();
  29.  ColorPickerFrame:Show();
  30.  end
  31.  
  32. local function myColorCallback(restore)
  33.  local newR, newG, newB, newA;
  34.  if restore then
  35.   newR, newG, newB, newA = unpack(restore);  
  36.  else
  37.   newA, newR, newG, newB = OpacitySliderFrame:GetValue(), ColorPickerFrame:GetColorRGB();  
  38.  end
  39.   cvred, cvgreen, cvblue, cvalpha = newR, newG, newB, newA;
  40. end
  41.  
  42. --Slash Command to change the color of the output
  43. SLASH_CONVERTRATINGS1, SLASH_CONVERTRATINGS2 = '/convertratings', '/cvr';
  44. function SlashCmdList.CONVERTRATINGS(msg, editBox)
  45.     --Grab the first input word as the command and the rest of the input as a user variable
  46.     local command, rest = msg:match("^(%S*)%s*(.-)$");
  47.     --Hard coded color options parsing
  48.    
  49.     if (colorTable[string.lower(command)]) then
  50.         cvred, cvgreen, cvblue = unpack(colorTable[string.lower(command)]);
  51.         print("Convert Ratings output color set to "..string.lower(command));
  52.     elseif string.lower(command) == 'custom' and rest == "" then
  53.         ShowColorPicker(cvred, cvgreen, cvblue, nil, myColorCallback);
  54.     else
  55.         --when no valid args entered, output this stuff
  56.         print("Convert Ratings: Valid color options are red, green, blue, black, white, lightblue, lightred, pink, purple, orange or custom")
  57.         print("Convert Ratings: The custom option will bring up the Color Picker for you to choose a color.")
  58.         print("Convert Ratings: To reset to the default color, use /convertratings default")
  59.     end
  60. end

I figured the first thing I would try to get working is adding a button to the options panel, which when you click on it, it calls my already defined color picker functions.

Lua Code:
  1. --Create a Frame to add to the default options panel
  2. local cvrpanel = CreateFrame("Frame")
  3. cvrpanel.name = "Convert Ratings"
  4.  
  5. --Options Panel Title
  6. local cvropttitle = cvrpanel:CreateFontString("ARTWORK", nil, "GameFontNormalLarge")
  7. cvropttitle:SetPoint("TOP")
  8. cvropttitle:SetText("Convert Ratings")
  9.  
  10. --Add a button to open the custom color picker
  11. local cvrbutton = CreateFrame("Button", nil, cvrpanel, "UIPanelButtonTemplate")
  12. cvrbutton:SetPoint("TOPLEFT", cvrpanel, 0, -40)
  13. cvrbutton:SetText("Custom Color")
  14. cvrbutton:SetWidth(150)
  15. cvrbutton:HookScript("OnClick", ShowColorPicker)
  16.    
  17. --Add our panel to the options frame   
  18. InterfaceOptions_AddCategory(cvrpanel)

This successfully adds a new panel to the ingame options window with the desired title displayed and the clickable button. However, when I actually click on the button, it throws an error:

Code:
5x ConvertRatings/ConvertRatings.lua:27: bad argument #1 to 'SetColorRGB' (Usage: self:SetColorRGB(rgb))
[string "=[C]"]: in function `SetColorRGB'
[string "@ConvertRatings/ConvertRatings.lua"]:27: in function <ConvertRatings/ConvertRatings.lua:26>

Locals:
(*temporary) = ColorPickerFrame {
 0 = <userdata>
 Center = Texture {
 }
 PixelSnapDisabled = true
 TopLeftCorner = Texture {
 }
 OnBackdropLoaded = <function> defined @SharedXML/Backdrop.lua:152
 Border = Frame {
 }
 BottomEdge = Texture {
 }
 GetBackdropColor = <function> defined @SharedXML/Backdrop.lua:390
 SetupTextureCoordinates = <function> defined @SharedXML/Backdrop.lua:214
 OnBackdropSizeChanged = <function> defined @SharedXML/Backdrop.lua:182
 HasBackdropInfo = <function> defined @SharedXML/Backdrop.lua:278
 SetBackdropBorderColor = <function> defined @SharedXML/Backdrop.lua:422
 RightEdge = Texture {
 }
 BottomRightCorner = Texture {
 }
 BottomLeftCorner = Texture {
 }
 GetEdgeSize = <function> defined @SharedXML/Backdrop.lua:188
 template = "Transparent"
 TopRightCorner = Texture {
 }
 TopEdge = Texture {
 }
 ApplyBackdrop = <function> defined @SharedXML/Backdrop.lua:294
 SetBackdrop = <function> defined @SharedXML/Backdrop.lua:329
 ClearBackdrop = <function> defined @SharedXML/Backdrop.lua:282
 backdropInfo = <table> {
 }
 GetBackdropBorderColor = <function> defined @SharedXML/Backdrop.lua:409
 GetBackdrop = <function> defined @SharedXML/Backdrop.lua:347
 SetBorderBlendMode = <function> defined @SharedXML/Backdrop.lua:266
 SetupPieceVisuals = <function> defined @SharedXML/Backdrop.lua:246
 SetBackdropColor = <function> defined @SharedXML/Backdrop.lua:399
 LeftEdge = Texture {
 }
 Header = Frame {
 }
}
(*temporary) = Button {
 SetTextToFit = <function> defined @SharedXML/SecureUIPanelTemplates.lua:440
 Right = Texture {
 }
 Left = Texture {
 }
 fitTextWidthPadding = 40
 FitToText = <function> defined @SharedXML/SecureUIPanelTemplates.lua:445
 Text = TopText {
 }
 0 = <userdata>
 Middle = Texture {
 }
 fitTextCanWidthDecrease = true
}
(*temporary) = "LeftButton"
(*temporary) = false
So my next though would be that I needed to change the hookscript line to:

Lua Code:
  1. cvrbutton:HookScript("OnClick", ShowColorPicker(cvred, cvgreen, cvblue, nil, myColorCallback))

but that just throws a different error when you load in:

Code:
2x ConvertRatings/ConvertRatings.lua:79: Usage: Button:HookScript("frameScriptTypeName", function[, bindingType])
[string "=[C]"]: in function `HookScript'
[string "@ConvertRatings/ConvertRatings.lua"]:79: in main chunk

Locals:
(*temporary) = Button {
 SetTextToFit = <function> defined @SharedXML/SecureUIPanelTemplates.lua:440
 Right = Texture {
 }
 Left = Texture {
 }
 fitTextWidthPadding = 40
 FitToText = <function> defined @SharedXML/SecureUIPanelTemplates.lua:445
 Text = TopText {
 }
 0 = <userdata>
 Middle = Texture {
 }
 fitTextCanWidthDecrease = true
}
(*temporary) = "OnClick"
My next thought was maybe I should change it from HookScript, to SetScript but just gave me the same errors referencing SetScript instead of HookScript.

What probably glaring issue am I not seeing here? Why does changing it from a slash command to a button press fuck it all up?
__________________
My Addons: Convert Ratings Honor Track
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » How to move my slash commands to the options panel?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off