View Single Post
06-05-13, 03:52 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Here's the code I use for a simplified text-only difficulty display in my private minimap addon:
Code:
MiniMapInstanceDifficulty:SetParent(Minimap)
MiniMapInstanceDifficulty:ClearAllPoints()
MiniMapInstanceDifficulty:SetPoint("TOPRIGHT", -2, 20)

MiniMapInstanceDifficultyText:ClearAllPoints()
MiniMapInstanceDifficultyText:SetPoint("RIGHT", 0, -9)
MiniMapInstanceDifficultyText:SetFontObject(TextStatusBarText)

MiniMapInstanceDifficultyTexture:Hide()

GuildInstanceDifficulty:Hide()

MiniMapInstanceDifficulty:HookScript("OnEvent", function(self, event, isGuildGroup)
	if event == "GUILD_PARTY_STATE_UPDATED" then
		self.__isGuildGroup = isGuildGroup
	end
end)

function MiniMapInstanceDifficulty_Update()
	local instanceName, instanceType, difficulty, _, maxPlayers, playerDifficulty, isDynamicInstance = GetInstanceInfo()
	local _, _, isHeroic, isChallengeMode = GetDifficultyInfo(difficulty)

	if MiniMapInstanceDifficulty.__isGuildGroup then
		instanceType = "GUILD"
	end

	local color = ChatTypeInfo[strupper(instanceType)]

	if color and maxPlayers > 0 then
		MiniMapInstanceDifficultyText:SetFormattedText("%d%s", maxPlayers, isChallengeMode and "++" or isHeroic and "+" or "")
		MiniMapInstanceDifficultyText:SetTextColor(color.r, color.g, color.b)
		MiniMapInstanceDifficulty:Show()
	else
		MiniMapInstanceDifficulty:Hide()
	end
end

local difficultyText = {
	DUNGEON_DIFFICULTY1,
	DUNGEON_DIFFICULTY2,
	RAID_DIFFICULTY1,
	RAID_DIFFICULTY2,
	RAID_DIFFICULTY3,
	RAID_DIFFICULTY4,
	UNKNOWN,
	CHALLENGE_MODE,
}

MiniMapInstanceDifficulty:EnableMouse(true)
MiniMapInstanceDifficulty:SetScript("OnEnter", function(self)
	local instanceName, instanceType, difficulty, difficultyText, maxPlayers, playerDifficulty, isDynamicInstance = GetInstanceInfo()

	GameTooltip:SetOwner(self, "ANCHOR_NONE")
	GameTooltip:SetPoint("TOPRIGHT", self, "LEFT")

	GameTooltip:AddLine(instanceName, 1, 0.82, 0)
	GameTooltip:AddLine(difficultyText, 1, 1, 1)
	GameTooltip:AddLine(difficultyText[difficulty] or UNKNOWN, 1, 1, 1)

	if self.__isGuildGroup then
		GameTooltip:AddLine(GUILD, 1, 1, 1)
	end

	GameTooltip:Show()
end)
MiniMapInstanceDifficulty:SetScript("OnLeave", GameTooltip_Hide)
Drycoded Broker conversion:
Code:
local DEFAULT_TEXT = ""

local isGuildGroup

local b = LibStub("LibDataBroker-1.1"):NewDataObject("InstanceDifficulty", {
	type = "data source",
	text = DEFAULT_TEXT,
	OnTooltipShow = function(GameTooltip)
		local instanceName, instanceType, difficultyID, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance = GetInstanceInfo()
		local difficultyText = GetDifficultyInfo(difficultyID)

		GameTooltip:AddLine(instanceName, 1, 0.82, 0)
		GameTooltip:AddLine(difficultyText, 1, 1, 1)

		if isGuildGroup then
			GameTooltip:AddLine(GUILD, 1, 1, 1)
		end

		GameTooltip:Show()
	end,
})

local f = CreateFrame("Frame")
f:RegisterEvent("GROUP_ROSTER_UPDATE")
f:RegisterEvent("GUILD_PARTY_STATE_UPDATED")
f:RegisterEvent("PARTY_MEMBER_DISABLE")
f:RegisterEvent("PARTY_MEMBER_ENABLE")
f:RegisterEvent("PLAYER_DIFFICULTY_CHANGED")
f:RegisterEvent("PLAYER_GUILD_UPDATE")
f:RegisterEvent("UPDATE_INSTANCE_INFO")
f:SetScript("OnEvent", function(self, event, ...)
	if event == "GUILD_PARTY_STATE_UPDATED" then
		isGuildGroup = ...
	elseif event ~= "UPDATE_INSTANCE_INFO" then
		RequestGuildPartyState()
	end

	local instanceName, instanceType, difficulty, _, maxPlayers, playerDifficulty, isDynamicInstance = GetInstanceInfo()
	local _, _, isHeroic, isChallengeMode = GetDifficultyInfo(difficulty)

	if isGuildGroup then
		instanceType = "GUILD"
	end

	local color = ChatTypeInfo[strupper(instanceType)]

	if color and maxPlayers > 0 then 
		b.text = format("|cff%02x%02x%02x%s%d", color.r * 255, color.g * 255, color.b * 255, isChallengeMode and "++" or isHeroic and "+" or "", maxPlayers)
	else
		b.text = DEFAULT_TEXT
	end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 06-05-13 at 07:20 PM.
  Reply With Quote