Not tolerant of empty names #3


  • Fixed
Closed
  • DahkCeles created this issue Apr 4, 2019

    L_Create_UIDropDownMenu is not tolerant of an "empty" name that might be appropriate when there is no desire to have a global variable.  The user has to convert nil to an empty string, to avoid concatentation errrors.

     

    function myfunc(name,parent)

      -- OLD CODE -- CreateFrame("Frame", name, parent, "L_UIDropDownMenu");

      L_Create_UIDropDownMenu(name or "", parent);

    end

     

    In the example above, you can see that it used to be possible to pass the variable name directly into creating a frame.   Now I have to check for nil.

     

    I recommend in your new L_Create_UIDropDownMenu function that you check for nil and convert it yourself to "" so that this is a non-issue for all developers.

  • DahkCeles posted a comment Jun 7, 2019

    I looked at your library and realized you are assuming name is a non-empty value when you create the various sub-frames in lua format.

     

    The blizzard (xml-based) implementation uses $parent that can be a global name or just an object reference created during CreateFrame().

     

    I believe you can re-create this behaviour using f:getName() such as in the example below.  (I can't test this right now because WoW servers are down.)

     

    STARTING AT LINE 281

     

    -- //////////////////////////////////////////////////////////////
    -- L_UIDropDownMenuTemplate
    local function create_UIDropDownMenu(name, parent)
    local f
    if type(name) == "table" then
    f = name
    -- name = f:getName(); -- delete me! this line is replaced below the conditional
    else
    f = CreateFrame("Frame", name, parent or nil)
    end

    -- if name was originally a table, it now becomes name:getName()
    -- if name was originally a string, it remains unchanged and is a global because of CreateFrame()
    -- if name was originally empty, it now becomes the instantiation that happens during CreateFrame()
    name = f:GetName();


     

    CONTINUE THE REST OF function create_UIDropDownMenu()


    Edited Jun 7, 2019
  • DahkCeles posted a comment Jun 8, 2019

    Okay, game is working and I can say the above solution won't do it.  This code will:

     

     

    -- //////////////////////////////////////////////////////////////
    -- L_UIDropDownMenuTemplate
    
    local function create_UIDropDownMenu(name, parent)
    	local f
    	if type(name) == "table" then
    		f = name
    		name = f:GetName();
    	else
    		f = CreateFrame("Frame", name, parent or nil)
    	end
    	
    	f:SetSize(40, 32)
    	
    	f.Left = f:CreateTexture(name and name.."Left"), "ARTWORK")
    	f.Left:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame")
    	f.Left:SetSize(25, 64)
    	f.Left:SetPoint("TOPLEFT", f, 0, 17)
    	f.Left:SetTexCoord(0, 0.1953125, 0, 1)
    	
    	f.Middle = f:CreateTexture(name and name.."Middle", "ARTWORK")
    	f.Middle:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame")
    	f.Middle:SetSize(115, 64)
    	f.Middle:SetPoint("LEFT", f.Left, "RIGHT")
    	f.Middle:SetTexCoord(0.1953125, 0.8046875, 0, 1)
    	
    	f.Right = f:CreateTexture(name and name.."Right", "ARTWORK")
    	f.Right:SetTexture("Interface\\Glues\\CharacterCreate\\CharacterCreate-LabelFrame")
    	f.Right:SetSize(25, 64)
    	f.Right:SetPoint("LEFT", f.Middle, "RIGHT")
    	f.Right:SetTexCoord(0.8046875, 1, 0, 1)
    	
    	f.Text = f:CreateFontString(name and name.."Text", "ARTWORK", "GameFontHighlightSmall")
    	f.Text:SetWordWrap(false)
    	f.Text:SetJustifyH("RIGHT")
    	f.Text:SetSize(0, 10)
    	f.Text:SetPoint("RIGHT", f.Right, -43, 2)
    	
    	f.Icon = f:CreateTexture(name and name.."Icon", "OVERLAY")
    	f.Icon:Hide()
    	f.Icon:SetSize(16, 16)
    	f.Icon:SetPoint("LEFT", 30, 2)
    	
    	f.Button = CreateFrame("Button", name and name.."Button", f)
    	f.Button:SetMotionScriptsWhileDisabled(true)
    	f.Button:SetSize(24, 24)
    	f.Button:SetPoint("TOPRIGHT", f.Right, -16, -18)
    	
    	f.Button.NormalTexture = f.Button:CreateTexture(name and name.."NormalTexture")
    	f.Button.NormalTexture:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Up")
    	f.Button.NormalTexture:SetSize(24, 24)
    	f.Button.NormalTexture:SetPoint("RIGHT", f.Button, 0, 0)
    	f.Button:SetNormalTexture(f.Button.NormalTexture)
    	
    	f.Button.PushedTexture = f.Button:CreateTexture(name and name.."PushedTexture")
    	f.Button.PushedTexture:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Down")
    	f.Button.PushedTexture:SetSize(24, 24)
    	f.Button.PushedTexture:SetPoint("RIGHT", f.Button, 0, 0)
    	f.Button:SetPushedTexture(f.Button.PushedTexture)
    	
    	f.Button.DisabledTexture = f.Button:CreateTexture(name and name.."DisabledTexture")
    	f.Button.DisabledTexture:SetTexture("Interface\\ChatFrame\\UI-ChatIcon-ScrollDown-Disabled")
    	f.Button.DisabledTexture:SetSize(24, 24)
    	f.Button.DisabledTexture:SetPoint("RIGHT", f.Button, 0, 0)
    	f.Button:SetDisabledTexture(f.Button.DisabledTexture)
    	
    	f.Button.HighlightTexture = f.Button:CreateTexture(name and name.."HighlightTexture")
    	f.Button.HighlightTexture:SetTexture("Interface\\Buttons\\UI-Common-MouseHilight")
    	f.Button.HighlightTexture:SetSize(24, 24)
    	f.Button.HighlightTexture:SetPoint("RIGHT", f.Button, 0, 0)
    	f.Button.HighlightTexture:SetBlendMode("ADD")
    	f.Button:SetHighlightTexture(f.Button.HighlightTexture)

    Edited Mar 28, 2021
  • arithmandar added a tag Fixed Jun 24, 2021
  • arithmandar closed issue Feb 28, 2022

To post a comment, please login or register a new account.