From 90de68cfea5e46753f3d33702f6dc8d1954acf17 Mon Sep 17 00:00:00 2001 From: Peter Eliasson Date: Sun, 7 Aug 2016 18:43:21 +0200 Subject: [PATCH] Store realm with guild name if present. --- src/gui.lua | 13 ++++++++++--- src/main.lua | 26 ++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/gui.lua b/src/gui.lua index 2936fed..724364a 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -566,9 +566,16 @@ function gui:ShowMainFrame() gui:SetSelectedDifficulty(self.selectedDifficulty, true); gui:SetSelectedEncounter(self.selectedEncounter, true); gui:SetSelectedRole(self.selectedRole, true); - elseif addon.guildName then - -- Try pre-selecting own guild if has one. - gui:SetSelectedGuild(addon.guildName); + else + -- Try pre-selecting own guild if we have one and it exists + -- in the database. + local myGuildName = addon:GetGuildName("player"); + for guildId in pairs(addon.highscore:GetGuilds()) do + if guildId == myGuildName then + gui:SetSelectedGuild(addon.guildName); + break; + end + end end -- Have to do special for our tab group as it is never disabled diff --git a/src/main.lua b/src/main.lua index a373d4f..f31c0d1 100644 --- a/src/main.lua +++ b/src/main.lua @@ -21,6 +21,11 @@ local GetInstanceInfo = GetInstanceInfo; local GetRealZoneText = GetRealZoneText; local UnitIsUnit = UnitIsUnit; local GetExpansionLevel = GetExpansionLevel; +local GetDifficultyInfo = GetDifficultyInfo; +local UnitRealmRelationship = UnitRealmRelationship; +local FULL_PLAYER_NAME = FULL_PLAYER_NAME; +local LE_REALM_RELATION_SAME = LE_REALM_RELATION_SAME; +local LE_REALM_RELATION_VIRTUAL = LE_REALM_RELATION_VIRTUAL; -- Non-cached globals (for mikk's FindGlobals script) -- GLOBALS: LibStub @@ -95,6 +100,21 @@ function addon:Debug(...) end end + +-- Returns the name of the playerName's guild. +function addon:GetGuildName(playerName) + playerName = playerName or "player"; + + -- If the guild is cross-realm, add the realm to the name. + -- From Blizzard_GuildUI.lua:21 + local guildName, _, _, realm = GetGuildInfo(playerName); + if realm then + return format(FULL_PLAYER_NAME, guildName, realm); + else + return guildName + end +end + -- Tests if a player with name playerName is in the same -- guild as the player running this addon. function addon:IsInMyGuild(playerName) @@ -113,9 +133,7 @@ function addon:IsInMyGuild(playerName) return false; end - local myGuildName, _, _, myGuildRealm = GetGuildInfo("player"); - local otherGuildName, _, _, otherGuildRealm = GetGuildInfo(playerName); - return (myGuildName == otherGuildName and myGuildRealm == otherGuildRealm); + return (self:GetGuildName("player") == self:GetGuildName(playerName)); end -- Tests if a zone is in the addon's tracked zones. @@ -151,7 +169,7 @@ function addon:OnEncounterEndSuccess(encounterId, encounterName, difficultyId, r return; end - local guildName = GetGuildInfo("player"); + local guildName = self:GetGuildName("player"); if not guildName then self:Debug("Could not get the guild name of the player") return; -- 1.7.9.5