WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   <OnLoad> element makes my little window invisible (https://www.wowinterface.com/forums/showthread.php?t=59181)

Tinypower 07-25-22 08:34 PM

<OnLoad> element makes my little window invisible
 
So I have the following XML file. If I remove the line in red, the window appears alright---but it does not respond to mouse drag. If I keep this line, the window is invisible, but I can drag it---I know it because the close button can still be seen. What is causing this problem and how do I fix it?

Code:

<Ui xmlns="http://www.blizzard.com/wow/ui/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Frame name="BCHFrame" parent="UIParent" movable="true" enableMouse="true" inherits="BackdropTemplate" toplevel="true">
                <!--Anchors is a property element-->
                <Anchors>
                        <!-- An anchor can be created with frame:SetPoint() method-->
                        <Anchor point="LEFT" relativePoint="CENTER">
                                <Offset>
                                        <AbsDimension x="150" y="0" />
                                </Offset>
                        </Anchor>
                </Anchors>
               
                <Size>
                        <AbsDimension x="200" y="150" />
                </Size>
                <KeyValues>
                        <!-- a list of backdropInfo: https://www.townlong-yak.com/framexml/live/Backdrop.lua -->
                        <KeyValue key="backdropInfo" value="BACKDROP_DIALOG_32_32" type="global" />
                </KeyValues>
                <!-- Backdrop is now only available to frames that inherits backdrop template, and must only use BackdropInfo -->
                <!-- <Backdrop
                bgFile="Interface\DialogFrame\UI-DialogBox-Background"
                tile="true"
                edgeFile="Interface\DialogFrame\UI-DialogBox-Border">
                        <TileSize>
                                <AbsValue val="32"/>
                        </TileSize>
                        <EdgeSize>
                                <AbsValue val="32"/>
                        </EdgeSize>
                        <BackgroundInsets>
                                <AbsInset left="11" right="12" top="12" bottom="11"/>
                        </BackgroundInsets>
                </Backdrop> -->
                <Scripts>
                        <OnLoad>self:RegisterForDrag("LeftButton")</OnLoad>
                        <OnDragStart>self:StartMoving()</OnDragStart>
                        <OnDragStop>self:StopMovingOrSizing()</OnDragStop>
                </Scripts>
                <Frames>
                        <!-- close button -->
                        <Button name="$parent_CloseButton" inherits="UIPanelCloseButton">
                                <Anchors>
                                        <Anchor point="TOPRIGHT" relativePoint="TOPRIGHT">
                                                <Offset>
                                                        <AbsDimension x="0" y="0" />
                                                </Offset>
                                        </Anchor>
                                </Anchors>
                        </Button>
                </Frames>
               
        </Frame>
</Ui>

Also, if I remove the line, but instead type in game:
Code:

/run BCHFrame:RegisterForDrag("LeftButton")
then everything seems running alright

Fizzlemizz 07-25-22 09:24 PM

If you have an OnLoad you can set the backdrop there:

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.     <Frame name="BCHFrame" parent="UIParent"  toplevel="true" movable="true" enableMouse="true" inherits="BackdropTemplate">
  4.         <!--Anchors is a property element-->
  5.         <Size>
  6.             <AbsDimension x="200" y="150" />
  7.         </Size>
  8.         <Anchors>
  9.             <!-- An anchor can be created with frame:SetPoint() method-->
  10.             <Anchor point="LEFT" relativePoint="CENTER">
  11.                 <Offset>
  12.                     <AbsDimension x="150" y="0" />
  13.                 </Offset>
  14.             </Anchor>
  15.         </Anchors>
  16.         <Frames>
  17.             <!-- close button -->
  18.             <Button name="$parent_CloseButton" inherits="UIPanelCloseButton">
  19.                 <Anchors>
  20.                     <Anchor point="TOPRIGHT" relativePoint="TOPRIGHT">
  21.                         <Offset>
  22.                             <AbsDimension x="0" y="0" />
  23.                         </Offset>
  24.                     </Anchor>
  25.                 </Anchors>
  26.             </Button>
  27.         </Frames>
  28.         <Scripts>
  29.             <OnLoad>
  30.                 self:SetBackdrop(BACKDROP_DIALOG_32_32)
  31.                 self:RegisterForDrag("LeftButton")
  32.             </OnLoad>
  33.             <OnDragStart>self:StartMoving()</OnDragStart>
  34.             <OnDragStop>self:StopMovingOrSizing()</OnDragStop>
  35.         </Scripts>
  36.     </Frame>
  37. </Ui>

Tinypower 07-25-22 09:57 PM

Quote:

Originally Posted by Fizzlemizz (Post 340825)
If you have an OnLoad you can set the backdrop there:

Thank you very much! It works great!

SDPhantom 07-25-22 10:49 PM

To directly answer the question, BackdropTemplate uses its own OnLoad handler to set the backdrop. When you supply your own, the default behavior is to overwrite it and the original no longer runs. You can call self:OnBackdropLoaded() manually to run it in your own handler since the template still writes its function there. Alternatively, you can use the inherit property to run your handler before or after the template's by setting it to "prepend" or "append" respectively.

https://wowpedia.fandom.com/wiki/XML/Scripts


All times are GMT -6. The time now is 07:08 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI