魔兽UI跟随鼠标移动

魔兽UI跟随鼠标移动,第1张

算是自己给自己记录一下,

能看到的人用T也能实现

UI跟随鼠标移动,首先就是获取鼠标位置,DzAPI里面有三个获取鼠标位置函数:

// 获取鼠标在游戏内的坐标X
native DzGetMouseTerrainX takes nothing returns real

// 获取鼠标在游戏内的坐标Y
native DzGetMouseTerrainY takes nothing returns real

// 获取鼠标在游戏内的坐标Z
native DzGetMouseTerrainZ takes nothing returns real

// 获取鼠标屏幕坐标X
native DzGetMouseX takes nothing returns integer

// 获取鼠标屏幕坐标Y
native DzGetMouseY takes nothing returns integer

// 获取鼠标游戏窗口坐标X
native DzGetMouseXRelative takes nothing returns integer

// 获取鼠标游戏窗口坐标Y
native DzGetMouseYRelative takes nothing returns integer

其他几个也有用, 暂时用处不在这儿, 很明显 要获取游戏窗口坐标
接下来获得屏幕坐标:
// 获取war3窗口宽度
native DzGetWindowWidth takes nothing returns integer
// 获取war3窗口高度
native DzGetWindowHeight takes nothing returns integer

这里的屏幕高度 我实测下来, 宽会有20留白 高会有40留白,这一部分在换算成UI位置的时候要去掉
然后UI位置是从左下角作为0,0点,
而屏幕位置是从左上角作为0,0点
宽,也就是x 我们不需要有任何改变
高的话就需要翻转一下,屏幕高度减去获取到的鼠标位置 才是正确的UI位置

这边gif也不会做,直接贴一个转换的代码:
没有相关语言支持,随便选个c了

 // 获取鼠标当前UI位置-->x
    function mouseposx2Uiposx takes nothing returns real 
        local real curMouseposx = DzGetMouseXRelative()
        local integer windowWidth = DzGetWindowWidth() - 20
        local real res
        // 0.8是因为魔兽UI宽最大值就是0.8
        set res = curMouseposx/I2R(windowWidth) * 0.8
        return res
    endfunction
    // 获取鼠标当前UI位置-->y
    function mouseposx2Uiposy takes nothing returns real 
        local real curMouseposy = DzGetMouseYRelative()
        local integer windowHeight = DzGetWindowHeight() - 40
        local real res
        // 0.6是因为魔兽UI高最大值就是0.6
        set res = (I2R(windowHeight) - curMouseposy)/I2R(windowHeight) * 0.6
        return res
    endfunction

最后就比较简单了,直接就设置UI位置,两个参数传一下就搞定了UI就跟着鼠标了
DzFrameSetAbsolutePoint(ui,x,y)

T党设置个变量,然后执行一下这个函数就能获取到了

tips:其实当时B站上看到过,现在搜还能看到把,但是没有贴出图,感觉纯粹是秀给新手看的,真的感觉魔兽的圈子还是挺封闭的,感觉有啥多分享分享挺好,互联网精神么

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/731966.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存