Quantcast
SV and toggle show/hide frame question. - WoWInterface
Thread Tools Display Modes
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,124
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
10-19-20, 11:39 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-19-20 at 05:39 PM.
  Reply With Quote
10-19-20, 05:56 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
Originally Posted by Fizzlemizz View Post
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
  Reply With Quote
10-20-20, 01:25 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,978
Originally Posted by myrroddin View Post
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.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-20-20 at 01:28 AM.
  Reply With Quote
10-20-20, 02:37 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
Oh, that makes sense.
  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