View Single Post
01-07-19, 03:14 AM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
This is one basic approach. Where you create your radio buttons, you could use something like (added some print statements to see what is happening):

Lua Code:
  1. content2.RadioButtons = {}
  2. local function ClearRadio(self)
  3.     if not self:GetChecked() then return end -- only action if a radio is checked when it's clicked
  4.     for i=1, #content2.RadioButtons do
  5.         local button = content2.RadioButtons[i]
  6.         if button ~= self and button:GetChecked() then
  7.             print(button:GetName(), "Unchecked")
  8.             button:SetChecked(false) -- Set other radio buttons unchecked
  9.             button:GetScript("OnClick")(button) -- Call the "OnClick" script if the buttons need to "do stuff" when unchecked
  10.         end
  11.     end
  12. end
  13. local button = CreateFrame("CheckButton", "Otvet1", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  14. button:SetHeight(20)
  15. button:SetWidth(20)
  16. button:ClearAllPoints()
  17. button:SetPoint("CENTER", content2, "TOP", -220, -50) --Расположение Чекбаттона
  18. _G[button:GetName() .. "Text"]:SetText("Ответ 1")
  19. tinsert(content2.RadioButtons, button)
  20. button:SetScript("OnClick", function(self)
  21.     ClearRadio(self)
  22.     if self:GetChecked() then
  23.         print(self:GetName(), "Checked")
  24.         -- do whatever this button does when checked
  25.     else
  26.         --  do whatever this button does when unchecked
  27.     end
  28. end)
  29. button:SetChecked(true) -- check button 1 (default)
  30. button:GetScript("OnClick")(button) -- click button 1 (default)
  31.  
  32. button = CreateFrame("CheckButton", "Otvet2", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  33. button:SetHeight(20)
  34. button:SetWidth(20)
  35. button:ClearAllPoints()
  36. button:SetPoint("CENTER", content2, "TOP", -220, -70) --Расположение Чекбаттона
  37. _G[button:GetName() .. "Text"]:SetText("Ответ 2")
  38. tinsert(content2.RadioButtons, button)
  39. button:SetScript("OnClick", function(self)
  40.     ClearRadio(self)
  41.     if self:GetChecked() then
  42.         print(self:GetName(), "Checked")
  43.         -- do whatever this button does when checked
  44.     else
  45.         -- do whatever this button does when unchecked
  46.     end
  47. end)
  48.  
  49. button = CreateFrame("CheckButton", "Otvet3", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  50. button:SetHeight(20)
  51. button:SetWidth(20)
  52. button:ClearAllPoints()
  53. button:SetPoint("CENTER", content2, "TOP", -220, -90) --Расположение Чекбаттона
  54. _G[button:GetName() .. "Text"]:SetText("Ответ 3")
  55. tinsert(content2.RadioButtons, button)
  56. button:SetScript("OnClick", function(self)
  57.     ClearRadio(self)
  58.     if self:GetChecked() then
  59.         print(self:GetName(), "Checked")
  60.         -- do whatever this button does when checked
  61.     else
  62.         -- do whatever this button does when unchecked
  63.     end
  64. end)
  65.  
  66. button = CreateFrame("CheckButton", "Otvet4", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  67. button:SetHeight(20)
  68. button:SetWidth(20)
  69. button:ClearAllPoints()
  70. button:SetPoint("CENTER", content2, "TOP", -220, -110) --Расположение Чекбаттона
  71. _G[button:GetName() .. "Text"]:SetText("Ответ 4")
  72. tinsert(content2.RadioButtons, button)
  73. button:SetScript("OnClick", function(self)
  74.     ClearRadio(self)
  75.     if self:GetChecked() then
  76.         print(self:GetName(), "Checked")
  77.         -- do whatever this button does when checked
  78.     else
  79.         -- do whatever this button does when unchecked
  80.     end
  81. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-07-19 at 03:19 AM.
  Reply With Quote