0
点赞
收藏
分享

微信扫一扫

【魔兽世界插件】魔兽世界插件实战笔记从入门到放弃的心理历程 第六节 窗体对象的锚定

律楷粑粑 2022-04-29 阅读 32

锚很容易理解,就是向船落锚定位一样,把窗体固定到什么位置然后不动了,一个是这样,那两个窗体呢,他们互相是什么关系,他们和父窗体,和兄弟窗体之间又怎么定位呢?这就需要在xml中添加他们的锚定关系了。

左上 (TOPLEFT)
上 (TOP)
右上 (TOPRIGHT)
左 (LEFT)
中 (CENTER)
右 (RIGHT)
左下 (BOTTOMLEFT)
下 (BOTTOM)
右下 (BOTTOMRIGHT) 

这是几个主要的关键位置,主要就是靠他们互相锚定,当他们锚定后,就会成为一个整体,月亮走我也走。 

<Anchor point="TOPLEFT" relativePoint="BOTTOMRIGHT" relativeTo="FrameBackdrop" > 

举一个具体的例子,上面这句,解释一下就是我(point)的左上角,锚定了你(relativePoint

)的右下角,我们都认relativeTo属性为老大,他说东我们就一起到到东,他说西,我们就到西。

toc文件代码:

# 魔兽版本号
## Interface: 90200
# 标题
## Title: |cffffe00a[|r|cffff7d0a摸鱼儿|r|cffffe00a]|r |cff69ccf0第六节窗体对象的锚定|r
# 说明
## Notes: |cff69ccf0魔兽世界插件-窗体对象的锚定|r
# 作者
## Author: 摸鱼儿
# 插件的版本号,和魔兽版本号没有关系
## Version: 1.0.0


# 框体布局文件
UiFarme.xml


# 脚本文件,一般用来放功能实现函数
LuaFamrme.lua 

xml代码:

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Frame name="FrameBackdrop" parent="UIParent"  inherits="BackdropTemplate"  enableMouse="true"  movable="true">
            <Size>
            <!-- 尺寸设置 -->
            <AbsDimension x="200" y="200" />
            </Size>
            <Anchors>
            <Anchor point="CENTER">
            <!-- 偏移 -->
            <Offset x="-250" y="0" />
            </Anchor>
            </Anchors>
            <Layers>
            <Layer level="BACKGROUND">
            <!-- <Backdrop bgFile="Interface/Tooltips/UI-Tooltip-Background" edgeFile="Interface/Tooltips/UI-Tooltip-Border" tile="true">
            <BackgroundInsets>
            <AbsInset left="4" right="4" top="4" bottom="4" />
            </BackgroundInsets>
            <TileSize>
            <AbsValue val="32" />
            </TileSize>
            <EdgeSize>
            <AbsValue val="32" />
            </EdgeSize>
            </Backdrop> -->

            <!-- 材质设置 -->
            <Texture name="$parentHorizontal" >
            <Size x="180" y="180" />
            <!-- 锚点位置 -->
            <Anchors>
            <Anchor point="CENTER" relativePoint="CENTER" />
            </Anchors>
            </Texture>

            <FontString name="FrameFontString" font="Fonts\ARKai_T.TTF" text="魔兽世界坐标" justifyH="LEFT" justifyV="TOP">
            <Color r="1" g="1" b="1" a="0.2"/>
            <FontHeight val="23"/>
            <Anchors>
            <Anchor point="CENTER" relativeTo="$parent" x="0" y="5" />
            </Anchors>
            <Shadow>
            <Offset x="10" y="1" />
            <Color r="1" g="1" b="1"/>
            </Shadow>

            </FontString>
            </Layer>
            </Layers>


<Scripts>
    <OnLoad>
    <!-- 表示用鼠标的左键点击 -->
    self:RegisterForDrag("LeftButton")
        <!-- local backdropInfo = {
            bgFile		= "Interface/Tooltips/UI-Tooltip-Background",
            edgeFile	= "Interface/Tooltips/UI-Tooltip-Border",
            tile 		= true,
            tileEdge	= true,
            edgeSize = 16,
            insets = { left = 4, right = 4, top = 4, bottom = 4 },
        }
        self:SetBackdrop(backdropInfo);
        self:SetBackdropColor(0, 0, 1, .5) -->
    </OnLoad>

    <OnDragStart>
    self:StartMoving()
    </OnDragStart>

    <OnDragStop>
    self:StopMovingOrSizing()
    </OnDragStop>

</Scripts>

</Frame>


<!-- 左上 (TOPLEFT)
上 (TOP)
右上 (TOPRIGHT)
左 (LEFT)
中 (CENTER)
右 (RIGHT)
左下 (BOTTOMLEFT)
下 (BOTTOM)
右下 (BOTTOMRIGHT) -->



<Frame name="MyFrame1" parent="UIParent"  inherits="BackdropTemplate">
    <Size x="64" y="64" />
    <Anchors>
    <Anchor point="TOPLEFT" relativePoint="BOTTOMRIGHT" relativeTo="FrameBackdrop" >
            <!-- <Anchor point="CENTER" relativePoint="CNETER" relativeTo="UIParent"> -->
                    <!-- <Offset x="0" y="0" /> -->
            </Anchor>
    </Anchors>
    <Layers>
    <Layer level="BACKGROUND">
            <!-- 材质设置 -->
            <Texture name="MyFrameTexture1" >
            <Size x="64" y="64" />
            <!-- 锚点位置 -->
            <Anchors>
            <Anchor point="CENTER" relativePoint="CENTER" />
            </Anchors>
            </Texture>
    </Layer>
    </Layers>
</Frame>

<Frame name="MyFrame2" parent="UIParent"  inherits="BackdropTemplate">
    <Size x="64" y="64" />
    <Anchors>
    <Anchor point="BOTTOMRIGHT" relativePoint="TOPLEFT" relativeTo="FrameBackdrop" >
            <!-- <Anchor point="CENTER" relativePoint="CNETER" relativeTo="UIParent">
                    <Offset x="64" y="0" /> -->
            </Anchor>
    </Anchors>
    <Layers>
    <Layer level="BACKGROUND">
            <!-- 材质设置 -->
            <Texture name="MyFrameTexture2" >
            <Size x="64" y="64" />
            <!-- 锚点位置 -->
            <Anchors>
            <Anchor point="CENTER" relativePoint="CENTER" />
            </Anchors>
            </Texture>
    </Layer>
    </Layers>
</Frame>

<Frame name="MyFrame3" parent="UIParent"  inherits="BackdropTemplate">
    <Size x="64" y="64" />
    <Anchors>
    <Anchor point="BOTTOMLEFT" relativePoint="TOPRIGHT" relativeTo="FrameBackdrop" >
            <!-- <Anchor point="CENTER" relativePoint="CNETER" relativeTo="UIParent">
                    <Offset x="0" y="64" /> -->
            </Anchor>
    </Anchors>
    <Layers>
    <Layer level="BACKGROUND">
            <!-- 材质设置 -->
            <Texture name="MyFrameTexture3" >
            <Size x="64" y="64" />
            <!-- 锚点位置 -->
            <Anchors>
            <Anchor point="CENTER" relativePoint="CENTER" />
            </Anchors>
            </Texture>
    </Layer>
    </Layers>
</Frame>

<Frame name="MyFrame4" parent="UIParent"  inherits="BackdropTemplate">
    <Size x="64" y="64" />
    <Anchors>
        <Anchor point="TOPRIGHT" relativePoint="BOTTOMLEFT" relativeTo="FrameBackdrop" >
            <!-- <Anchor point="CENTER" relativePoint="CNETER" relativeTo="UIParent">
                    <Offset x="64" y="64" /> -->
            </Anchor>
    </Anchors>
    <Layers>
    <Layer level="BACKGROUND">
            <!-- 材质设置 -->
            <Texture name="MyFrameTexture4" >
            <Size x="64" y="64" />
            <!-- 锚点位置 -->
            <Anchors>
            <Anchor point="CENTER" relativePoint="CENTER" />
            </Anchors>
            </Texture>
    </Layer>
    </Layers>
</Frame>


</Ui> 

lua文件代码:

local myFrame
local myFontString
local myName


print("当前游戏版本号:",(select(4,GetBuildInfo())));


local backdropInfo = {
    bgFile		= "Interface/Tooltips/UI-Tooltip-Background",
    edgeFile	= "Interface/Tooltips/UI-Tooltip-Border",
    tile 		= true,
    tileEdge	= true,
    edgeSize = 16,
    insets = { left = 4, right = 4, top = 4, bottom = 4 },
}

-- name="FrameBackdrop"
myFrame =  FrameBackdrop
myFrame:SetBackdrop(backdropInfo);
myFrame:SetBackdropColor(0, 0, 1, .5)


myFontString = FrameFontString
-- myFontString:SetText("魔兽世界坐标水印")

myName = UnitName("player")
myFontString:SetText(myName .."专用")


local myFrame_1 =  MyFrame1
myFrame_1:SetBackdrop(backdropInfo);
myFrame_1:SetBackdropColor(0, 0, 1, .5)


local myFrame_2 =  MyFrame2
myFrame_2:SetBackdrop(backdropInfo);
myFrame_2:SetBackdropColor(0, 0, 1, .5)


local myFrame_3 =  MyFrame3
myFrame_3:SetBackdrop(backdropInfo);
myFrame_3:SetBackdropColor(0, 0, 1, .5)

local myFrame_4 =  MyFrame4
myFrame_4:SetBackdrop(backdropInfo);
myFrame_4:SetBackdropColor(0, 0, 1, .5) 

这一节还学习了一个暴雪提供的API函数,获取人物的名字:

local   myName = UnitName("player") 

呵呵,已经慢慢的接近实际功能了,我很期待啊。 

视频

魔兽世界插件实战笔记从入门到放弃的心理历程 第六节 窗体对象的锚定

我放在了B站,有兴趣的自己去看,高手略过,就是初步入门。

举报

相关推荐

0 条评论