Blizzard_UIWidgetTemplateZoneControl.lua 1.88 KB
Newer Older
TOM_RUS's avatar
TOM_RUS committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
local function GetZoneControlVisInfoData(widgetID)
	local widgetInfo = C_UIWidgetManager.GetZoneControlVisualizationInfo(widgetID);
	if widgetInfo and widgetInfo.shownState ~= Enum.WidgetShownState.Hidden then
		return widgetInfo;
	end
end

UIWidgetManager:RegisterWidgetVisTypeTemplate(Enum.UIWidgetVisualizationType.ZoneControl, {frameType = "FRAME", frameTemplate = "UIWidgetTemplateZoneControl"}, GetZoneControlVisInfoData);

UIWidgetTemplateZoneControlMixin = CreateFromMixins(UIWidgetBaseTemplateMixin);

function UIWidgetTemplateZoneControlMixin:OnLoad()
	UIWidgetBaseTemplateMixin.OnLoad(self); 
	ResizeLayoutMixin.OnLoad(self); 
	self.entryPool = CreateFramePool("FRAME", self, "UIWidgetBaseControlZoneTemplate");
	self.lastVals = {};
end

function UIWidgetTemplateZoneControlMixin:SetZoneAnchors(zoneFrame, index)
	zoneFrame:ClearAllPoints();
	if index == 1 then
		zoneFrame:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0);
	elseif index == 2 then
		zoneFrame:SetPoint("TOPLEFT", self, "TOPLEFT", 150, 0);
	elseif index == 3 then
		zoneFrame:SetPoint("TOPLEFT", self, "TOPLEFT", 75, -100);
	elseif index == 4 then
		zoneFrame:SetPoint("TOPLEFT", self, "TOPLEFT", 75, -30);
	end
end

function UIWidgetTemplateZoneControlMixin:Setup(widgetInfo, widgetContainer)
	UIWidgetBaseTemplateMixin.Setup(self, widgetInfo, widgetContainer);

	self.entryPool:ReleaseAll();

	for index, zoneInfo in ipairs(widgetInfo.zoneEntries) do
		local entryFrame = self.entryPool:Acquire();
		entryFrame:Show();
		local lastVals = (self.lastVals[index] and (self.lastVals[index].state == zoneInfo.state)) and self.lastVals[index] or nil;
		entryFrame:Setup(index, zoneInfo, lastVals, widgetInfo.textureKitID);
		self:SetZoneAnchors(entryFrame, index);
		self.lastVals[index] = zoneInfo;
	end

	self:Layout();
end

function UIWidgetTemplateZoneControlMixin:OnReset()
	UIWidgetBaseTemplateMixin.OnReset(self);
	self.entryPool:ReleaseAll();
end