参考 › 函数参考 › UI

UI.condition_position.constructor

依赖项

调用方式

UI.condition_position.constructor()

记录依赖项 UI.condition_position.constructor,然后按该名称调用。带命名空间的调用不会传入 self:请使用冒号调用,或自行传入该对象。

作用

Constructs a new RM-ConditionPositionPad widget around the shared workbench directional pad, with SetDisabled, firing OnOffsetChanged (horizontal and vertical direction, whether Center was pressed, and the step) only while its lease is live and it is enabled. It returns the registered but not yet acquired widget; addon:CreateConditionPositionPad acquires it.

参数

无。

返回值

1RMConditionWidgetThe new position pad widget, registered with the condition widget system.

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
CreateFrame经典旧世TBC 周年版经典进阶服永久服正式服
UIParent经典旧世TBC 周年版经典进阶服永久服正式服

示例

-- needs the dependency UI.condition_position.constructor
local pad = addon:AcquireConditionWidget("RM-ConditionPositionPad", UI.condition_position.constructor)
pad:SetCallback("OnOffsetChanged", function(_, _, dx, dy, center, amount)
    if center then value.x = 0 else value.x = (value.x or 0) + dx * amount end
end)
parent:AddChild(pad)

源码

UI/condition_position.lua,第 23 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

UI.condition_position.constructor()
    local w={type='RM-ConditionPositionPad',disabled=false}
    local frame=CreateFrame('Frame',nil,UIParent);w.frame=frame
    local pad=addon:CreateWorkbenchPositionPad(frame);w.pad=pad;pad:SetPoint('TOPLEFT')
    local clicks={}
    for name,button in pairs(pad.buttons) do clicks[name]=button:GetScript('OnClick') end
    function w:SetDisabled(value)
        self.disabled=value==true
        for _,button in pairs(pad.buttons) do if self.disabled then button:Disable() else button:Enable() end end
    end
    function w:OnAcquire()
        self:SetWidth(48);self:SetHeight(48);self:SetDisabled(false)
        local lease=self.rmLease
        local function live() return w.rmActive and w.rmLease==lease and not w.disabled and not w:IsReleasing() end
        pad:Bind(function(dx,dy,center,amount) w:Fire('OnOffsetChanged',dx,dy,center,amount) end,live,false)
        for name,button in pairs(pad.buttons) do
            local click=clicks[name]
            addon:SetUIScript(button,'OnClick',function(...) if live() then return click(...) end end)
        end
    end
    function w:OnRelease()
        pad:Bind(nil,nil,true);self.disabled=true
    end
    return addon:RegisterConditionWidget(w)

返回函数参考