Quantcast
Problem using a custom backdrop with the new backdrop system changes - WoWInterface
Thread Tools Display Modes
05-24-21, 08:42 PM   #1
fullmoon_sulfuras
A Deviate Faerie Dragon
Join Date: Dec 2019
Posts: 10
Problem using a custom backdrop with the new backdrop system changes

Hi there! I'm having a hard time understanding how to translate the old <Backdrop> tags to the new system.

I'm creating the following frame in XML:

Code:
<Frame name="TestFrame" parent="UIParent" inherits="BackdropTemplate">
    <KeyValues>
        <KeyValue key="backdropInfo" value="BACKDROP_TOOLTIP_16_16_5555" type="global"/>
        <KeyValue key="backdropBorderColor" value="LEGENDARY_ORANGE_COLOR" type="global"/>
        <KeyValue key="backdropBorderColorAlpha" value="0.25" type="number"/>
    </KeyValues>
    <Size x="300" y="300"/>
    <Anchors>
        <Anchor point="CENTER"/>
    </Anchors>
    <Scripts>
        <OnLoad inherit="prepend">
            print("Loaded!");
        </OnLoad>
    </Scripts>
</Frame>
This works perfectly. Now I want to customize my backdrop with the following info:

Lua Code:
  1. BACKDROP_TOOLTIP_MYBACKDROP = {
  2.     bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  3.     edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  4.     tile = true,
  5.     tileEdge = true,
  6.     tileSize = 16,
  7.     edgeSize = 16,
  8.     insets = { left = 5, right = 5, top = 5, bottom = 5 },
  9. };

I've added that to a .lua file that's listed in the ToC file, and changed my frame to:

Code:
<Frame name="TestFrame" parent="UIParent" inherits="BackdropTemplate">
    <KeyValues>
        <KeyValue key="backdropInfo" value="BACKDROP_TOOLTIP_MYBACKDROP" type="global"/>
        <KeyValue key="backdropBorderColor" value="LEGENDARY_ORANGE_COLOR" type="global"/>
        <KeyValue key="backdropBorderColorAlpha" value="0.25" type="number"/>
    </KeyValues>
    <Size x="300" y="300"/>
    <Anchors>
        <Anchor point="CENTER"/>
    </Anchors>
    <Scripts>
        <OnLoad inherit="prepend">
            print("Loaded!");
        </OnLoad>
    </Scripts>
</Frame>
The BACKDROP_TOOLTIP_MYBACKDROP is exactly the same as BACKDROP_TOOLTIP_16_16_5555. But now I don't get a frame anymore!

Do I need to place BACKDROP_TOOLTIP_MYBACKDROP somewhere special?

I've also tried to use:

Code:
<Frame name="TestFrame" parent="UIParent">
	<KeyValues>
		<KeyValue key="backdropInfo" value="BACKDROP_TOOLTIP_16_16_5555" type="global"/>
		<KeyValue key="backdropBorderColor" value="LEGENDARY_ORANGE_COLOR" type="global"/>
		<KeyValue key="backdropBorderColorAlpha" value="0.25" type="number"/>
	</KeyValues>
	<Size x="300" y="300"/>
	<Anchors>
		<Anchor point="CENTER"/>
	</Anchors>
	<Scripts>
		<OnLoad inherit="prepend">
			if BackdropTemplateMixin then -- if this is NOT a Classic type frame, add the backdrop mixin
				Mixin(self, BackdropTemplateMixin)
			end
			self:Setbackdrop( {
				bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
				edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
				tile = true,
				tileEdge = true,
				tileSize = 16,
				edgeSize = 16,
				insets = { left = 5, right = 5, top = 5, bottom = 5 }
			})
			print("Loaded!");
		</OnLoad>
	</Scripts>
</Frame>
But I get an error:

Code:
Message: [string "TestFrame:OnLoad"]:4: attempt to call method 'Setbackdrop' (a nil value)
Time: Mon May 24 22:39:22 2021
Count: 1
Stack: [string "TestFrame:OnLoad"]:4: attempt to call method 'Setbackdrop' (a nil value)
[string "*:OnLoad"]:4: in function <[string "*:OnLoad"]:1>
Thanks!
  Reply With Quote
05-24-21, 09:32 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,429
First decision. Do you want to make seperate xml frames for classic and non-classic

If yes then:
Classic: (same as always)
Lua Code:
  1. <Frame name="TestFrame" parent="UIParent">
  2.     <Size x="300" y="300"/>
  3.     <Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
  4.         <BackgroundInsets>
  5.             <AbsInset left="5" right="5" top="5" bottom="5"/>
  6.         </BackgroundInsets>
  7.         <TileSize>
  8.             <AbsValue val="16"/>
  9.         </TileSize>
  10.         <EdgeSize>
  11.             <AbsValue val="16"/>
  12.         </EdgeSize>
  13.     </Backdrop>    
  14.     <Anchors>
  15.         <Anchor point="CENTER"/>
  16.     </Anchors>
  17.     <Scripts>
  18.         <OnLoad inherit="prepend">
  19.             self:SetBackdropColor(0.5, 0.3, 0.3)
  20.             self:SetBackdropBorderColor(0.5, 0.3, 0.3, 0.25)
  21.             print("Loaded!");
  22.         </OnLoad>
  23.     </Scripts>
  24. </Frame>
Others, Mostly the same xml frame but inherits the BackdropTemplate and all backdrop information is set in lua (OnLoad)
Lua Code:
  1. <Frame name="TestFrame" parent="UIParent" inherits="BackdropTemplate">
  2.     <Size x="300" y="300"/>
  3.     <Anchors>
  4.         <Anchor point="CENTER"/>
  5.     </Anchors>
  6.     <Scripts>
  7.         <OnLoad inherit="prepend">
  8.             self:SetBackdrop( {
  9.                 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  10.                 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  11.                 tile = true,
  12.                 tileEdge = true,
  13.                 tileSize = 16,
  14.                 edgeSize = 16,
  15.                 insets = { left = 5, right = 5, top = 5, bottom = 5 }
  16.             })
  17.             self:SetBackdropColor(0.5, 0.3, 0.3)
  18.             self:SetBackdropBorderColor(0.5, 0.3, 0.3, 0.25)
  19.             print("Loaded!");
  20.         </OnLoad>
  21.     </Scripts>
  22. </Frame>

Or, do you want one frame for both Classic and the rest: Mostly the same xml frame but detecting if backdrop mixin (template) is needed and all backdrop information is set in lua (OnLoad)
Lua Code:
  1. <Frame name="TestFrame" parent="UIParent">
  2.     <Size x="300" y="300"/>
  3.     <Anchors>
  4.         <Anchor point="CENTER"/>
  5.     </Anchors>
  6.     <Scripts>
  7.         <OnLoad inherit="prepend">
  8.             if BackdropTemplateMixin then -- if this is NOT a Classic type frame, add the backdrop mixin
  9.                 Mixin(self, BackdropTemplateMixin)
  10.             end
  11.             self:SetBackdrop( {
  12.                 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
  13.                 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
  14.                 tile = true,
  15.                 tileEdge = true,
  16.                 tileSize = 16,
  17.                 edgeSize = 16,
  18.                 insets = { left = 5, right = 5, top = 5, bottom = 5 }
  19.             })
  20.             self:SetBackdropColor(0.5, 0.3, 0.3)
  21.             self:SetBackdropBorderColor(0.5, 0.3, 0.3, 0.25)
  22.             print("Loaded!");
  23.         </OnLoad>
  24.     </Scripts>
  25. </Frame>
Done this way to show separation of xml and lua. With the Classic and non-Classic you could use <KeyValues></KeyValues> for both but not with the one frame for multiple versions layout.

Definitions like BACKDROP_TOOLTIP_16_16_5555 and LEGENDARY_ORANGE_COLOR don't exist in Classic and may not BCC either so probably easiest not to use them and just define backdrop, colours, alpha manually in both.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-24-21 at 09:42 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem using a custom backdrop with the new backdrop system changes

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