Blizzard_CovenantPreviewUI.lua 10.6 KB
Newer Older
TOM_RUS's avatar
TOM_RUS committed
1
local PLAYER_CHOICE_TEXTURE_KIT = "Oribos";
TOM_RUS's avatar
TOM_RUS committed
2

TOM_RUS's avatar
TOM_RUS committed
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

local closeButtonBorder = {
	["NightFae"] = {
		closeButtonX = -2,
		closeButtonY = 0,
		closeBorderX = -1,
		closeBorderY = 1,
	},
	["Kyrian"] = { 
		closeButtonX = 1,
		closeButtonY = 2,
		closeBorderX = -1,
		closeBorderY = 1,
	},
	["Venthyr"] = { 
		closeButtonX = 0,
		closeButtonY = 0,
		closeBorderX = -1,
		closeBorderY = 1,
	},
	["Necrolord"] = { 
		closeButtonX = -1,
		closeButtonY = 0,
		closeBorderX = 0,
		closeBorderY = 1,
	},
}

TOM_RUS's avatar
TOM_RUS committed
31 32 33 34 35 36 37 38
local backgroundTextureKitRegions = {
	["BackgroundTile"] = "UI-Frame-%s-BackgroundTile",
};

local titleTextureKitRegions = {
	["Left"] = "UI-Frame-%s-TitleLeft",
	["Right"] = "UI-Frame-%s-TitleRight",
	["Middle"] = "_UI-Frame-%s-TitleMiddle",
TOM_RUS's avatar
TOM_RUS committed
39 40 41
};

local abilityButtonTextureKitRegions = { 
TOM_RUS's avatar
TOM_RUS committed
42
	["IconBorder"] = "CovenantSanctum-Upgrade-Icon-Border-%s",
TOM_RUS's avatar
TOM_RUS committed
43 44
};

TOM_RUS's avatar
TOM_RUS committed
45 46 47 48 49 50 51 52 53 54
local abilityFrameTextureKitRegions = { 
	["Border"] = "covenantchoice-offering-ability-frame-%s",
}

local featureButtonTextureKitRegions = {
	["NormalTexture"] = "covenantsanctum-icon-border-%s",
};

local soulbindAtlasTexture = "covenantchoice-offering-portrait-%s-%s";

TOM_RUS's avatar
TOM_RUS committed
55 56 57 58 59 60 61 62 63
local infoPanelTextureKitRegions = {
	["Parchment"] = "CovenantChoice-Offering-Parchment-%s",
	["Crest"] = "CovenantChoice-Offering-Sigil-%s",
};

local modelSceneContainerTextureKitRegions = {
	["ModelSceneBorder"] = "CovenantChoice-Offering-Preview-Frame-%s",
	["Background"] =  "CovenantChoice-Offering-Preview-Frame-Background-%s",
};
TOM_RUS's avatar
TOM_RUS committed
64 65 66

local abilityTypeText = {
	[Enum.CovenantAbilityType.Class] = COVENANT_PREVIEW_CLASS_ABILITY, 
TOM_RUS's avatar
TOM_RUS committed
67
	[Enum.CovenantAbilityType.Signature] = COVENANT_PREVIEW_RACIAL_ABILITY, 
TOM_RUS's avatar
TOM_RUS committed
68 69 70 71 72
}

CovenantPreviewFrameMixin = { }; 
function CovenantPreviewFrameMixin:OnLoad() 
	self.AbilityButtonsPool = CreateFramePool("BUTTON", self.InfoPanel, "CovenantAbilityButtonTemplate");
TOM_RUS's avatar
TOM_RUS committed
73
	self.SoulbindButtonsPool = CreateFramePool("BUTTON", self.InfoPanel, "CovenantSoulbindButtonTemplate");
TOM_RUS's avatar
TOM_RUS committed
74 75 76 77
end 

function CovenantPreviewFrameMixin:OnShow()
	self:RegisterEvent("COVENANT_PREVIEW_CLOSE");
TOM_RUS's avatar
TOM_RUS committed
78
	self:RegisterEvent("PLAYER_CHOICE_CLOSE");
TOM_RUS's avatar
TOM_RUS committed
79
	UpdateScaleForFit(self); 
TOM_RUS's avatar
TOM_RUS committed
80 81 82
end

function CovenantPreviewFrameMixin:OnHide()
TOM_RUS's avatar
TOM_RUS committed
83 84 85 86
	if(self.showingFromPlayerChoice) then 
		PlayerChoiceFrame.BlackBackground:Hide(); 
	end 

TOM_RUS's avatar
TOM_RUS committed
87 88
	self:Reset(); 
	self:UnregisterEvent("COVENANT_PREVIEW_CLOSE");
TOM_RUS's avatar
TOM_RUS committed
89
	self:UnregisterEvent("PLAYER_CHOICE_CLOSE");
TOM_RUS's avatar
TOM_RUS committed
90 91 92 93
	C_CovenantPreview.CloseFromUI(); 
end 

function CovenantPreviewFrameMixin:OnEvent(event, ...) 
TOM_RUS's avatar
TOM_RUS committed
94
	if (event == "COVENANT_PREVIEW_CLOSE" or event =="PLAYER_CHOICE_CLOSE") then
TOM_RUS's avatar
TOM_RUS committed
95
		self:Hide();
TOM_RUS's avatar
TOM_RUS committed
96 97 98
	end 
end 

TOM_RUS's avatar
TOM_RUS committed
99 100 101 102
function CovenantPreviewFrameMixin:HandleEscape()
	if (self.showingFromPlayerChoice and PlayerChoiceFrame and PlayerChoiceFrame:IsShown()) then 
		HideUIPanel(PlayerChoiceFrame);
	end 
TOM_RUS's avatar
TOM_RUS committed
103
	self:Hide();
TOM_RUS's avatar
TOM_RUS committed
104 105
end 

TOM_RUS's avatar
TOM_RUS committed
106 107 108
function CovenantPreviewFrameMixin:Reset()
	self.lastAbility = nil;
	self.uiTextureKit = nil; 
TOM_RUS's avatar
TOM_RUS committed
109
	self.showingFromPlayerChoice = nil;
TOM_RUS's avatar
TOM_RUS committed
110 111
end 

TOM_RUS's avatar
TOM_RUS committed
112 113 114 115 116 117
function CovenantPreviewFrameMixin:SetupTextureKits(frame, regions, overrideTextureKit)
	if(overrideTextureKit) then 
		SetupTextureKitOnRegions(overrideTextureKit, frame, regions, TextureKitConstants.SetVisibility, TextureKitConstants.UseAtlasSize);
	else
		SetupTextureKitOnRegions(self.uiTextureKit, frame, regions, TextureKitConstants.SetVisibility, TextureKitConstants.UseAtlasSize);
	end 
TOM_RUS's avatar
TOM_RUS committed
118 119 120 121
end 

function CovenantPreviewFrameMixin:SetupFramesWithTextureKit()

TOM_RUS's avatar
TOM_RUS committed
122 123
	if (not self.showingFromPlayerChoice and self.uiTextureKit) then 
		NineSliceUtil.ApplyUniqueCornersLayout(self.BorderFrame, self.uiTextureKit);
TOM_RUS's avatar
TOM_RUS committed
124 125 126 127
	end
	self.BorderFrame:SetShown(not self.showingFromPlayerChoice);
	self.CloseButton:SetShown(not self.showingFromPlayerChoice);
	self.SelectButton:SetShown(self.showingFromPlayerChoice);
TOM_RUS's avatar
TOM_RUS committed
128
	self:SetupTextureKits(self.InfoPanel, infoPanelTextureKitRegions);
TOM_RUS's avatar
TOM_RUS committed
129 130
	self:SetupTextureKits(self.Background, backgroundTextureKitRegions, self.uiTextureKit);

TOM_RUS's avatar
TOM_RUS committed
131 132 133 134
	local layout = closeButtonBorder[self.uiTextureKit];
	self.CloseButton:ClearAllPoints(); 
	self.CloseButton:SetPoint("TOPRIGHT", self, "TOPRIGHT", layout.closeButtonX, layout.closeButtonY);
	UIPanelCloseButton_SetBorderAtlas(self.CloseButton, "UI-Frame-%s-ExitButtonBorder", layout.closeBorderX, layout.closeBorderY, self.uiTextureKit);
TOM_RUS's avatar
TOM_RUS committed
135

TOM_RUS's avatar
TOM_RUS committed
136 137 138 139 140 141 142 143 144 145 146
	if(self.showingFromPlayerChoice) then 
		self:SetupTextureKits(self.Title, titleTextureKitRegions, PLAYER_CHOICE_TEXTURE_KIT);
	else 
		self:SetupTextureKits(self.Title, titleTextureKitRegions, self.uiTextureKit);
	end 

	if(PlayerChoiceFrame) then 
		PlayerChoiceFrame.BlackBackground:SetShown(self.showingFromPlayerChoice);
	end 

	self.Background:SetShown(not self.showingFromPlayerChoice);
TOM_RUS's avatar
TOM_RUS committed
147 148
end

TOM_RUS's avatar
TOM_RUS committed
149
local function CovenantPreviewSortFunction(firstValue, secondValue)
TOM_RUS's avatar
TOM_RUS committed
150
	return firstValue < secondValue;
TOM_RUS's avatar
TOM_RUS committed
151 152
end

TOM_RUS's avatar
TOM_RUS committed
153 154 155 156 157 158 159
function CovenantPreviewFrameMixin:TryShow(covenantInfo)
	if(not covenantInfo) then
		return; 
	end 

	self:Reset();
	self.uiTextureKit = covenantInfo.textureKit; 
TOM_RUS's avatar
TOM_RUS committed
160
	self.showingFromPlayerChoice = covenantInfo.fromPlayerChoice;
TOM_RUS's avatar
TOM_RUS committed
161 162 163 164
	self.Title.Text:SetText(COVENANT_PREVIEW_TITLE:format(covenantInfo.covenantName)); 

	self:SetupFramesWithTextureKit(); 
	self:SetupModelSceneFrame(covenantInfo.transmogSetID, covenantInfo.mountID);
TOM_RUS's avatar
TOM_RUS committed
165 166 167 168 169 170 171
	
	if (covenantInfo.covenantAbilities and #covenantInfo.covenantAbilities > 1) then
		table.sort(covenantInfo.covenantAbilities, function(a, b) 
			return CovenantPreviewSortFunction(a.type, b.type); 
		end);
	end 

TOM_RUS's avatar
TOM_RUS committed
172 173 174 175 176 177 178
	
	if (covenantInfo.covenantSoulbinds and #covenantInfo.covenantSoulbinds > 1) then
		table.sort(covenantInfo.covenantSoulbinds, function(a, b) 
			return CovenantPreviewSortFunction(a.sortOrder, b.sortOrder); 
		end);
	end 

TOM_RUS's avatar
TOM_RUS committed
179
	self:SetupAbilityButtons(covenantInfo.covenantAbilities);
TOM_RUS's avatar
TOM_RUS committed
180
	self:SetupSoulbindButtons(covenantInfo.covenantSoulbinds);
TOM_RUS's avatar
TOM_RUS committed
181
	self:SetupCovenantInfoPanel(covenantInfo); 
TOM_RUS's avatar
TOM_RUS committed
182
	self:SetupCovenantFeature(covenantInfo.featureInfo) 
TOM_RUS's avatar
TOM_RUS committed
183
	self:Show();
TOM_RUS's avatar
TOM_RUS committed
184 185
end 

TOM_RUS's avatar
TOM_RUS committed
186 187 188 189 190 191
function CovenantPreviewFrameMixin:SetupCovenantFeature(covenantFeatureInfo) 
	local featureButton = self.InfoPanel.CovenantFeatureFrame.CovenantFeatureButton
	self:SetupTextureKits(featureButton, featureButtonTextureKitRegions);
	featureButton:Setup(covenantFeatureInfo); 
end 

TOM_RUS's avatar
TOM_RUS committed
192
function CovenantPreviewFrameMixin:SetupAbilityButtons(covenantAbilities)
TOM_RUS's avatar
TOM_RUS committed
193
	self:SetupTextureKits(self.InfoPanel.AbilitiesFrame, abilityFrameTextureKitRegions);
TOM_RUS's avatar
TOM_RUS committed
194 195 196 197 198 199 200 201 202 203 204
	self.lastAbility = nil;
	self.AbilityButtonsPool:ReleaseAll(); 
	for abilityIndex, ability in ipairs(covenantAbilities) do 
		self.lastAbility = self:SetupAndGetAbilityButton(abilityIndex, ability);
	end 
end 

function CovenantPreviewFrameMixin:SetupAndGetAbilityButton(index, abilityInfo)
	local abilityButton = self.AbilityButtonsPool:Acquire(); 

	if(not self.lastAbility) then 
TOM_RUS's avatar
TOM_RUS committed
205
		abilityButton:SetPoint("TOP", self.InfoPanel.AbilitiesFrame.Border, "TOP", 0, -23); 
TOM_RUS's avatar
TOM_RUS committed
206
	else 
TOM_RUS's avatar
TOM_RUS committed
207
		abilityButton:SetPoint("TOP", self.lastAbility, "BOTTOM", 0, -3);
TOM_RUS's avatar
TOM_RUS committed
208 209
	end		

TOM_RUS's avatar
TOM_RUS committed
210
	self:SetupTextureKits(abilityButton, abilityButtonTextureKitRegions);
TOM_RUS's avatar
TOM_RUS committed
211 212 213 214
	abilityButton:SetupButton(abilityInfo);
	return abilityButton;
end 

TOM_RUS's avatar
TOM_RUS committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

function CovenantPreviewFrameMixin:SetupSoulbindButtons(soulbinds)
	self.lastSoulbind = nil;
	self.SoulbindButtonsPool:ReleaseAll(); 
	for soulbindIndex, soulbind in ipairs(soulbinds) do 
		self.lastSoulbind = self:SetupAndGetSoulbindButton(soulbindIndex, soulbind);
	end 
end 

function CovenantPreviewFrameMixin:SetupAndGetSoulbindButton(index, soulbindInfo)
	local soulbindButton = self.SoulbindButtonsPool:Acquire(); 

	if(not self.lastSoulbind) then 
		soulbindButton:SetPoint("LEFT", self.InfoPanel.SoulbindsFrame, "LEFT", 0, 10); 
	else 
		soulbindButton:SetPoint("LEFT", self.lastSoulbind, "RIGHT", -20, 0);
	end		
	local soulbindButtonAtlas = soulbindAtlasTexture:format(self.uiTextureKit, soulbindInfo.uiTextureKit); 
	if(soulbindButtonAtlas) then 
		soulbindButton.Icon:SetAtlas(soulbindAtlasTexture:format(self.uiTextureKit, soulbindInfo.uiTextureKit))
	end 
	soulbindButton:SetupButton(soulbindInfo);
	return soulbindButton;
end 

TOM_RUS's avatar
TOM_RUS committed
240
function CovenantPreviewFrameMixin:SetupModelSceneFrame(transmogSetID, mountID)
TOM_RUS's avatar
TOM_RUS committed
241
	self:SetupTextureKits(self.ModelSceneContainer, modelSceneContainerTextureKitRegions);
TOM_RUS's avatar
TOM_RUS committed
242

TOM_RUS's avatar
TOM_RUS committed
243
	SetUpTransmogAndMountDressupFrame(self.ModelSceneContainer, transmogSetID, mountID, 414, 432, "CENTER", "CENTER", 0 , 0, true); 
TOM_RUS's avatar
TOM_RUS committed
244
	local sources = C_TransmogSets.GetAllSourceIDs(transmogSetID);
TOM_RUS's avatar
TOM_RUS committed
245 246
	DressUpTransmogSet(sources, TransmogAndMountDressupFrame);
	TransmogAndMountDressupFrame:RemoveWeapons();
TOM_RUS's avatar
TOM_RUS committed
247 248 249 250 251 252 253 254 255 256 257
end 

function CovenantPreviewFrameMixin:SetupCovenantInfoPanel(covenantInfo) 
	local infoPanel = self.InfoPanel; 
	infoPanel.Name:SetText(covenantInfo.covenantName); 
	infoPanel.Location:SetText(COVENANT_PREVIEW_ZONE_HOME:format(covenantInfo.covenantZone));
	infoPanel.Description:SetText(covenantInfo.description);
end 

CovenantAbilityButtonMixin = { }; 
function CovenantAbilityButtonMixin:OnEnter() 
TOM_RUS's avatar
TOM_RUS committed
258
	EmbeddedItemTooltip:Hide();
TOM_RUS's avatar
TOM_RUS committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
	GameTooltip:SetSpellByID(self.spellID);
	GameTooltip:Show(); 
end

function CovenantAbilityButtonMixin:OnLeave() 
	GameTooltip:Hide();
end

function CovenantAbilityButtonMixin:SetupButton(abilityInfo) 
	self.spellID = abilityInfo.spellID; 
	local spellName, _, spellIcon = GetSpellInfo(self.spellID);

	self.Icon:SetTexture(spellIcon);
	self:Show();
end 
TOM_RUS's avatar
TOM_RUS committed
275 276 277 278 279 280 281 282 283 284

CovenantFeatureButtonMixin = { };

function CovenantFeatureButtonMixin:Setup(covenantFeatureInfo)
	self.Icon:SetTexture(covenantFeatureInfo.texture);
	self.name = covenantFeatureInfo.name; 
	self.description = covenantFeatureInfo.description;
end 

function CovenantFeatureButtonMixin:OnEnter()
TOM_RUS's avatar
TOM_RUS committed
285
	EmbeddedItemTooltip:Hide();
TOM_RUS's avatar
TOM_RUS committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
	GameTooltip:SetOwner(self, "ANCHOR_RIGHT", -30, -30);
	GameTooltip_AddHighlightLine(GameTooltip, self.name); 
	GameTooltip_AddNormalLine(GameTooltip, self.description);
	GameTooltip:Show(); 
end 

function CovenantFeatureButtonMixin:OnLeave()
	GameTooltip:Hide(); 
end 

CovenantSoulbindButtonMixin = { };
function CovenantSoulbindButtonMixin:SetupButton(soulbindInfo) 
	self.spellID = soulbindInfo.spellID; 
	self.name = soulbindInfo.name
	self:Show();
end 

function CovenantSoulbindButtonMixin:OnEnter() 
	if(not self:IsMouseOver()) then 
		return; 
	end

TOM_RUS's avatar
TOM_RUS committed
308 309
	GameTooltip:Hide(); 

TOM_RUS's avatar
TOM_RUS committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323
	local spell = Spell:CreateFromSpellID(self.spellID);
	spell:ContinueOnSpellLoad(function()
		EmbeddedItemTooltip:SetOwner(self, "ANCHOR_RIGHT", -12, -10);
		GameTooltip_AddHighlightLine(EmbeddedItemTooltip, self.name);
		GameTooltip_AddBlankLineToTooltip(EmbeddedItemTooltip); 
		GameTooltip_AddNormalLine(EmbeddedItemTooltip, COVENANT_PREVIEW_SOULBIND_SPELL_INTRO);
		GameTooltip_AddBlankLineToTooltip(EmbeddedItemTooltip); 
		EmbeddedItemTooltip_SetSpellWithTextureByID(EmbeddedItemTooltip.ItemTooltip, self.spellID, spell:GetSpellTexture());
		EmbeddedItemTooltip:Show();
	end);
end

function CovenantSoulbindButtonMixin:OnLeave() 
	EmbeddedItemTooltip:Hide();
TOM_RUS's avatar
TOM_RUS committed
324 325 326 327 328
end

CovenantPreviewModelSceneContainerMixin = { };
function CovenantPreviewModelSceneContainerMixin:ShouldAcceptDressUp()
	return false;
TOM_RUS's avatar
TOM_RUS committed
329
end