Thread Tools Display Modes
Prev Previous Post   Next Post Next
10-19-20, 10:58 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
SV and toggle show/hide frame question.

I added a slash command toggle to TSM_StringConverter, which required adding a saved variable, which I assigned during PLAYER_LOGIN. That is working, but now previously working things stopped, with no BugSack errors, and I can't spot what I am doing wrong.
  1. The new code is not obeying the SV toggle during login or reloading the UI.
  2. The slash command opens the frame if I manually close it but it isn't toggling show and hide.
  3. The messages printed to chat are correct when the appropriate things happen, like logging in or using the slash command.
Pointers and help will be appreciated.
Code:
local title, addon = ...
local L = addon.L
local gui = LibStub("AceGUI-3.0")

local text_store = "" -- store the edit box text
local isShown = false -- toggle for main_frame

local function ShowFrame()
    if isShown then return end

    isShown = true

    -- create the GUI and make it useful
    local main_frame = gui:Create("Frame")
    main_frame:SetTitle(L["TSM String Converter"])
    main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
    main_frame:SetCallback("OnClose", function(widget)
        text_store = ""
        isShown = false
        gui:Release(widget)
    end)
    main_frame:SetLayout("Flow")

    local edit_box = gui:Create("MultiLineEditBox")
    edit_box:SetLabel(L["Insert itemIDs"])
    edit_box:SetRelativeWidth(1.0)
    edit_box:SetNumLines(25)
    edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
    edit_box:DisableButton(true) -- disables the "Okay" button
    edit_box:SetCallback("OnTextChanged", function(widget, event, text)
        edit_box:SetLabel(L["Insert itemIDs"])
        text_store = text
    end)
    main_frame:AddChild(edit_box)

    local button = gui:Create("Button")
    button:SetText(CONVERT)
    button:SetRelativeWidth(1.0)
    button:SetCallback("OnClick", function()
        -- strip out all spaces, just in case
        text_store = text_store:trim()
        text_store = string.gsub(text_store, " ", "")

        -- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
        text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")

        print("|cff32cd32TSMSC: |r" .. DONE_EDITING)

        edit_box:SetText(text_store)
        edit_box:HighlightText()
        edit_box:SetFocus()
        edit_box:SetLabel(DONE_EDITING)
    end)
    main_frame:AddChild(button)
end -- end of ShowFrame()

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, ...)
    if event == "PLAYER_LOGIN" then
        TSMSC_DB = TSMSC_DB or {}
        TSMSC_DB.isShown = TSMSC_DB.isShown or true
        print(L["Type /tsmsc show to toggle showing or hiding the frame during logging in."])

        if TSMSC_DB.isShown then
            ShowFrame()
        end
    end
end)

-- create and handle slash command
SLASH_TSMSC1 = L["/tsmsc"]
SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
    msg = msg:trim()
    if msg:upper() == SHOW:upper() then
        TSMSC_DB.isShown = not TSMSC_DB.isShown
        if TSMSC_DB.isShown then
            print(L["TSMSC: showing frame during logging in."])
        else
            print(L["TSMSC: hiding frame during logging in."])
        end
    elseif msg:upper() ~= SHOW:upper() then
        ShowFrame()
    end
end
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » SV and toggle show/hide frame question.

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