Quantcast my slash command code conflicts with the frame - WoWInterface
Thread Tools Display Modes
01-13-19, 11:52 AM   #1
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 973
my slash command code conflicts with the frame

I don't understand this behaviour. If I comment out all the lines after line 47 the GUI frame shows up and works. I can enter text in the MultiLineEditBox and the Convert button does what it is supposed to do. However, as soon as I enable the slash command code the GUI frame loses all its child frames.

The slash command does toggle the GUI frame as expected, it is just that the child frames don't appear unless I comment out the slash command code.

Anyone have ideas?

Lua Code:
  1. local title, addon = ...
  2. local L = addon.L
  3. local gui = LibStub("AceGUI-3.0")
  4.  
  5. local text_store = "" -- store the edit box text
  6.  
  7. -- create the GUI and make it useful
  8. local main_frame = gui:Create("Frame")
  9. main_frame:SetTitle(L["TSM String Converter"])
  10. main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
  11. main_frame:SetCallback("OnClose", function(widget)
  12.     text_store = ""
  13.     gui:Release(widget)
  14. end)
  15. main_frame:SetLayout("Flow")
  16.  
  17. local edit_box = gui:Create("MultiLineEditBox")
  18. edit_box:SetLabel(L["Insert itemIDs"])
  19. edit_box:SetRelativeWidth(1.0)
  20. edit_box:SetNumLines(25)
  21. edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
  22. edit_box:DisableButton(true) -- disables the "Okay" button
  23. edit_box:SetCallback("OnTextChanged", function(widget, event, text)
  24.     edit_box:SetLabel(L["Insert itemIDs"])
  25.     text_store = text
  26. end)
  27. main_frame:AddChild(edit_box)
  28.  
  29. local button = gui:Create("Button")
  30. button:SetText(CONVERT)
  31. button:SetRelativeWidth(1.0)
  32. button:SetCallback("OnClick", function()
  33.     -- strip out all spaces, just in case
  34.     text_store = text_store:trim()
  35.     text_store = string.gsub(text_store, " ", "")
  36.  
  37.     -- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
  38.     text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")
  39.  
  40.     print("|cff32cd32TSMSC: |r" .. DONE_EDITING)
  41.  
  42.     edit_box:SetText(text_store)
  43.     edit_box:HighlightText()
  44.     edit_box:SetFocus()
  45.     edit_box:SetLabel(DONE_EDITING)
  46. end)
  47. main_frame:AddChild(button)
  48.  
  49. --[[
  50. local f = CreateFrame("Frame") -- for events
  51.  
  52. function addon:PLAYER_ENTERING_WORLD()
  53.     if main_frame:IsShown() then
  54.         main_frame:Hide()
  55.     end
  56. end
  57.  
  58.  
  59. -- create and handle slash command
  60. SLASH_TSMSC1 = L["/tsmsc"]
  61. SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
  62.     if main_frame:IsShown() then
  63.         main_frame:Hide()
  64.     else
  65.         main_frame:Show()
  66.     end
  67. end
  68.  
  69. f:SetScript("OnEvent", function(self, event, ...)
  70.     addon[event](self, ...) -- call one of the functions above
  71. end)
  72.  
  73. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  74. ]]--
Attached Thumbnails
Click image for larger version

Name:	no slash command.jpg
Views:	12
Size:	31.5 KB
ID:	9198  Click image for larger version

Name:	with slash command.jpg
Views:	12
Size:	49.5 KB
ID:	9199  
  Reply With Quote
01-13-19, 01:29 PM   #2
Kanegasi
A Rage Talon Dragon Guard
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 307
I'm not familiar with AddChild or Create (Ace3 stuff?), but have you tried adding edit_box:Show() and button:Show() to the slash command? The children are probably still there, but they might not be actual children that follow automatic visual rules of parent frames.
  Reply With Quote
01-13-19, 03:00 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 977
comment out
Code:
gui:Release(widget)
at line 13.

The disappearing child would happen also if you left the Release in, commented out the RegisterEvent, clicked close and then /tsmsc.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-13-19 at 05:16 PM.
  Reply With Quote
01-13-19, 05:35 PM   #4
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 973
Ah ha, I found a comment on the AceGUI-3.0 Tutorial page that worked. Like him, I am not sure if it is the best solution, but it works, huzzah!
Lua Code:
  1. local title, addon = ...
  2. local L = addon.L
  3. local gui = LibStub("AceGUI-3.0")
  4.  
  5. local text_store = "" -- store the edit box text
  6. local isShown = false -- toggle for main_frame
  7.  
  8. local function ShowFrame()
  9.     if isShown then return end
  10.  
  11.     isShown = true
  12.  
  13.     -- create the GUI and make it useful
  14.     local main_frame = gui:Create("Frame")
  15.     main_frame:SetTitle(L["TSM String Converter"])
  16.     main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
  17.     main_frame:SetCallback("OnClose", function(widget)
  18.         text_store = ""
  19.         isShown = false
  20.         gui:Release(widget)
  21.     end)
  22.     main_frame:SetLayout("Flow")
  23.  
  24.     local edit_box = gui:Create("MultiLineEditBox")
  25.     edit_box:SetLabel(L["Insert itemIDs"])
  26.     edit_box:SetRelativeWidth(1.0)
  27.     edit_box:SetNumLines(25)
  28.     edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
  29.     edit_box:DisableButton(true) -- disables the "Okay" button
  30.     edit_box:SetCallback("OnTextChanged", function(widget, event, text)
  31.         edit_box:SetLabel(L["Insert itemIDs"])
  32.         text_store = text
  33.     end)
  34.     main_frame:AddChild(edit_box)
  35.  
  36.     local button = gui:Create("Button")
  37.     button:SetText(CONVERT)
  38.     button:SetRelativeWidth(1.0)
  39.     button:SetCallback("OnClick", function()
  40.         -- strip out all spaces, just in case
  41.         text_store = text_store:trim()
  42.         text_store = string.gsub(text_store, " ", "")
  43.  
  44.         -- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
  45.         text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")
  46.  
  47.         print("|cff32cd32TSMSC: |r" .. DONE_EDITING)
  48.  
  49.         edit_box:SetText(text_store)
  50.         edit_box:HighlightText()
  51.         edit_box:SetFocus()
  52.         edit_box:SetLabel(DONE_EDITING)
  53.     end)
  54.     main_frame:AddChild(button)
  55. end -- end of ShowFrame()
  56.  
  57. ShowFrame()
  58.  
  59. -- create and handle slash command
  60. SLASH_TSMSC1 = L["/tsmsc"]
  61. SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
  62.     ShowFrame()
  63. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » my slash command code conflicts with the frame

Thread Tools
Display Modes

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