參考資料 › 函式參考 › 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

返回函式參考