Справочник › Справочник функций › UI

UI.condition_icon.constructor

зависимость

Как вызывать

UI.condition_icon.constructor()

Запишите зависимость UI.condition_icon.constructor и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.

Что делает

Constructs a new RM-ConditionIcon widget: a clickable image with an optional caption below it, with SetImage, SetImageByAtlas, SetImageSize, SetLabel and SetDisabled, firing OnClick, OnEnter and OnLeave while its lease is live. It returns the registered but not yet acquired widget; addon:CreateConditionIcon passes it to addon:AcquireConditionWidget.

Аргументы

Нет.

Возвращает

1RMConditionWidgetThe new icon widget, registered with the condition widget system.

Издания

Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.

  • Недоступно в этом издании (причина — во всплывающей подсказке)
  • Только пока включены запасные реализации Blizzard для устаревших функций
Игровой APIClassic EraTBC AnniversaryClassic ProgressionForeverRetail
CreateFrameClassic EraTBC AnniversaryClassic ProgressionForeverRetail
GameFontHighlightSmallClassic EraTBC AnniversaryClassic ProgressionForeverRetail
GameTooltipClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UIParentClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Пример

-- needs the dependency UI.condition_icon.constructor
local icon = addon:AcquireConditionWidget("RM-ConditionIcon", UI.condition_icon.constructor)
icon:SetImage("Interface\\Icons\\INV_Misc_QuestionMark")
icon:SetImageSize(36, 36)
icon:SetLabel(L["Spell"])
parent:AddChild(icon)

Исходный код

UI/condition_icon.lua, строка 27. В игре только для чтения; «Дублировать» создаёт редактируемую копию.

UI.condition_icon.constructor()
    local w={type='RM-ConditionIcon',alive=false,disabled=false}
    local frame=CreateFrame('Button',nil,UIParent);w.frame=frame;frame:EnableMouse(true)
    local image=frame:CreateTexture(nil,'ARTWORK');w.image=image;image:SetPoint('TOP',0,-5)
    local label=frame:CreateFontString(nil,'OVERLAY','GameFontHighlightSmall');w.label=label
    label:SetPoint('BOTTOMLEFT');label:SetPoint('BOTTOMRIGHT');label:SetJustifyH('CENTER');label:SetJustifyV('TOP');label:SetHeight(18)
    function w:SetLabel(text)
        self.labelText=text or '';label:SetText(self.labelText)
        if self.labelText~='' then label:Show() else label:Hide() end
        self:SetHeight(image:GetHeight()+(self.labelText~='' and 25 or 10))
    end
    function w:SetText(text) self:SetLabel(text) end
    function w:SetImage(path,...)
        image:SetTexture(path)
        local count=select('#',...)
        if count==4 or count==8 then image:SetTexCoord(...) else image:SetTexCoord(0,1,0,1) end
    end
    function w:SetImageByAtlas(atlas) image:SetAtlas(atlas) end
    function w:SetImageSize(width,height)
        image:SetSize(width,height);self:SetHeight(height+(self.labelText~='' and 25 or 10))
    end
    function w:SetDisabled(value)
        self.disabled=value==true
        if self.disabled then frame:Disable();image:SetVertexColor(.5,.5,.5,.5);label:SetTextColor(.5,.5,.5)
        else frame:Enable();image:SetVertexColor(1,1,1,1);label:SetTextColor(1,1,1) end
    end
    function w:OnAcquire()
        self.alive=true;self:SetWidth(110);self:SetLabel('');self:SetImage(nil);self:SetImageSize(64,64);self:SetDisabled(false)
        frame:RegisterForClicks('LeftButtonUp')
        local lease=self.rmLease
        local function live() return w.alive and w.rmActive and w.rmLease==lease and not w:IsReleasing() end
        addon:SetUIScript(frame,'OnClick',function(_,button) if live() and not w.disabled then w:Fire('OnClick',button) end end)
        addon:SetUIScript(frame,'OnEnter',function() if live() then w:Fire('OnEnter') end end)
        addon:SetUIScript(frame,'OnLeave',function() if live() then w:Fire('OnLeave') end end)
    end
    function w:OnRelease()
        self.alive=false
        if GameTooltip and GameTooltip:IsOwned(frame) then GameTooltip:Hide() end
        self:SetLabel('');self:SetImage(nil)
    end
    return addon:RegisterConditionWidget(w)

Назад: Справочник функций