参考 › 函数参考 › Conditions

Conditions.common.Widget_SpellWidget

公共

调用方式

addon:Widget_SpellWidget(spec, editbox, value, nametoid, isvalid, update)

可直接通过 addon 使用,无需依赖项。

作用

为自定义条件控件创建一个带有建议、验证和法术链接支持的法术输入框。更新回调负责保存所选的值;将返回的控件添加到回调的父级。

参数

名称类型作用
selfRMAddonRotation Master 插件实例(使用冒号调用时隐含传入)。
specnumber用于解析法术建议的专精范围。
editboxstring用于法术建议的引用输入种类,例如 Spec_EditBox。
valuetable包含 spell、ranked 和 disabled 字段的条件值记录;会被原地更新。
nametoidfunction将输入的法术名称映射到其 ID 的解析器。
isvalidfunction验证拟议法术值的判断函数。
updatefunction接收已提交法术值的回调。

返回值

1RMConditionGroup包含动作图标、引用输入框和可选等级控件的法术字段组。

版本

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

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

插件如何调用它

以及另外 19 处: 宠物法术可用 (widget), 宠物法术充能 (widget), 宠物法术冷却 (widget), 宠物法术施放历史 (widget), 宠物法术施放历史时间 (widget), 宠物法术在射程内 (widget), 宠物法术充能时间 (widget), 法术生效中或待生效 (widget), 法术自动重复中 (widget), 法术可用 (widget), 法术充能 (widget), 法术冷却 (widget), 法术触发高亮 (widget), 法术施放历史 (widget), 法术施放历史时间 (widget), 法术在射程内 (widget), 法术充能时间 (widget), 存在特定图腾 (widget), 特定图腾剩余时间 (widget)

依赖项

源码

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

Conditions.common.Widget_SpellWidget(self, spec, editbox, value, nametoid, isvalid, update)
    local spell_group = addon:CreateConditionGroup()
    spell_group:SetLayout('RM-SpellField')
    local rankChoice

    local spell = addon:CreateSpellEditBox(editbox,value.spell)
    local initialSpell=type(value.spell)=="string" and SpellData:GetSpellId(value.spell) or value.spell
    local spellIcon = addon:CreateSpellActionIcon(spec == (BOOKTYPE_PET or "pet") and "pet" or "spell",initialSpell,isvalid)
    spellIcon:SetWidth(44)
    spellIcon:SetHeight(44)
    spellIcon:SetText(value.spell)
    spellIcon:SetCallback("OnEnterPressed", function(_, _, v)
        v = tonumber(v)
        if v and isvalid(v) then
            value.spell = v
            spellIcon:SetText(v)
            spell:SetText(SpellData:SpellName(value.spell, not value.ranked))
            if GameTooltip:IsOwned(spellIcon.frame) and GameTooltip:IsVisible() then
                GameTooltip:SetHyperlink("spell:" .. v)
            end
        else
            value.spell = nil
            spellIcon:SetText(nil)
            spell:SetText(nil)
            if GameTooltip:IsOwned(spellIcon.frame) and GameTooltip:IsVisible() then
                GameTooltip:Hide()
            end
        end
        update()
    end)
    spellIcon:SetCallback("OnEnter", function()
        if value.spell then
            GameTooltip:SetOwner(spellIcon.frame, "ANCHOR_BOTTOMRIGHT", 3)
            GameTooltip:SetHyperlink("spell:" .. value.spell)
        end
    end)
    spellIcon:SetCallback("OnLeave", function()
        if GameTooltip:IsOwned(spellIcon.frame) then
            GameTooltip:Hide()
        end
    end)
    spellIcon:SetDisabled(value.disabled)
    spell_group:AddChild(spellIcon)

    if addon:ClientHasSpellRanks() and spec ~= (BOOKTYPE_PET or "pet") then
        local nr_button = addon:CreateConditionCheckBox()
        nr_button:SetLabel(L["Use this exact spell rank"])
        nr_button.button.tooltip = RANK_TIP
        nr_button:SetValue(value.ranked or false)
        nr_button:SetCallback("OnValueChanged", function(_, _, val)
            value.ranked = val
            spell:SetUserData("norank", not val)
            spell:SetText(value.spell and SpellData:SpellName(value.spell, not value.ranked))
            update()
        end)
        nr_button:SetDisabled(value.disabled)
        rankChoice=nr_button
    end

    spell:SetFullWidth(true)
    spell:SetLabel('')
    spell:SetText(value.spell and SpellData:SpellName(value.spell, not value.ranked))
    spell:SetUserData("norank", not value.ranked)
    spell:SetUserData("spec", spec)
    spell:SetCallback("OnEnterPressed", function(_, _, v)
        if not addon.isint(v) then
            v = nametoid(v)
        else
            v = tonumber(v)
        end
        if isvalid(v) then
            value.spell = v
            spell:SetText(SpellData:SpellName(value.spell, not value.ranked))
        else
            value.spell = nil
            spell:SetText(nil)
        end
        spellIcon:SetText(value.spell)
        update()
    end)
    spell:SetDisabled(value.disabled)
    spell_group:AddChild(spell)
    if rankChoice then
        rankChoice.frame.GetFontString=function() return rankChoice.button:GetFontString() end
        spell_group:AddChild(rankChoice)
    end

    return spell_group

返回函数参考