WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   SV and toggle show/hide frame question. (https://www.wowinterface.com/forums/showthread.php?t=58324)

myrroddin 10-19-20 10:58 AM

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


Fizzlemizz 10-19-20 11:39 AM

What is SHOW that is being upper()ed in the slash command?

Code:

TSMSC_DB.isShown = not TSMSC_DB.isShown
if TSMSC_DB.isShown then
  -- what is actioning the showing of the fame here?
else
  -- what is actioning the hiding of the fame here?
end


myrroddin 10-19-20 05:56 PM

Quote:

Originally Posted by Fizzlemizz (Post 337321)
What is SHOW that is being upper()ed in the slash command?

Line 13190 of GlobalStrings.lua https://www.townlong-yak.com/framexm...balStrings.lua

SDPhantom 10-20-20 01:25 AM

Quote:

Originally Posted by myrroddin (Post 337319)
Code:

TSMSC_DB.isShown = TSMSC_DB.isShown or true

This is forcing TSMSC_DB.isShown to true if it's false/nil right after you load your saved variable. If you're trying to set a default, you need to check for nil specifically.

myrroddin 10-20-20 02:37 PM

Oh, that makes sense.


All times are GMT -6. The time now is 10:01 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI