⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 titanguild.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 3 页
字号:
-- version
TITAN_GUILD_VERSION = "2.5";
--[[

	Titan Panel [Guild]: A simple guild list for the Titan Panel AddOn.
		copyright 2005 by chicogrande (jluzier@gmail.com)
		tooltip coloration enhancements and frame detection by Dsanai
		
	- Lists online guild members in a tooltip, green rank text indicating an officer
	- Menu shows names of online members, with click to /whisper functionality. Green text = officer
	- Menu has options to /guild chat and /officer chat
	- Menu has option to toggle Show offline members, which changes this setting in your Social frame, Guild tab
	- Advanced menus to /w, /invite, /friend or /who guild members
	- Shows default messages if the player is not a member of a guild
	- Updates the guild listing every 5 minutes to accomodate the GuildRoster() delay. The update only takes place if
	  the player is 'idle' and not accessing conflicting UI frames or Titan elements
	- Tooltip and right-click menu content is sortable using the Sort menu option, works like the guild frame
	- Colors rank names (Advanced) or player names (Simple) based on rank index
	- To save space, player can turn off menu options
	- Filtering on a level range and zone, as it relates to the player
	- Filtering on a single class in the player's faction
	- Paging of simple and advanced right-click menu contents to deal with large-guild issues
]]

----------------------------------------------------------------------
--  Local variables
----------------------------------------------------------------------
TITAN_GUILD_ID = "Guild";
-- attempting to update every 300 seconds
TITAN_GUILD_FREQUENCY = 300;
-- the guild tab #
TITAN_GUILD_TAB_NUMBER = 3;
-- function used to hide options
TITAN_GUILD_BUTTON_SHOWOPTIONS = "TitanPanelGuildButton_ToggleShowMenuOptions";
TITAN_GUILD_BUTTON_CLOSEMENU = "TitanPanelGuildButton_CloseMenu";
TITAN_GUILD_BUTTON_COMPUTEPAGES = "TitanPanelGuildButton_ComputePages";
TITAN_GUILD_BUTTON_FORWARDPAGE = "TitanPanelGuildButton_PageForward";
TITAN_GUILD_BUTTON_BACKWARDPAGE = "TitanPanelGuildButton_PageBackward";

-- threshold for leaf level items in right-click menu
TITAN_GUILD_LIST_THRESHOLD = 15;
TITAN_GUILD_TOOLTIP_THRESHOLD = 26;

-- used to help hide the FriendsFame on GuildRoster() calls
hide_TitanPanelGuildButton_FriendsFrame = 0;
-- my internal timer used to keep track of when to run GuildRoster()
guild_TimeCounter = 0;
-- tables used to build the rank based right-click messaging menu
masterTable = {};
masterTableSimple = {};
-- level range for filtering on level +/- TITAN_GUILD_LEVEL_RANGE
TITAN_GUILD_LEVEL_RANGE = 5;

-- paging vars
currIndex = 1;
maxIndex = TITAN_GUILD_LIST_THRESHOLD;
numGuildOnline = 0;
numGuildOnlineFiltered = 0;
numPages = 0;
currPage = 1;
pagingRemainder = 0;
priorAdvMenuValue = TITAN_NIL;
TitanGuildFirstCycle = true;

-- hooking
local pre_TitanPanelGuildButton_FriendsFrame_OnShow;
local pre_TitanPanelGuildButton_FriendsFrame_OnHide;

----------------------------------------------------------------------
--  TitanPanelGuildButton_OnLoad()
----------------------------------------------------------------------
function TitanPanelGuildButton_OnLoad()
	if( DEFAULT_CHAT_FRAME ) then
		--DEFAULT_CHAT_FRAME:AddMessage("Titan Panel [Guild] v"..TITAN_GUILD_VERSION.." loaded");
	end
	-- init hide_TitanPanelGuildButton_FriendsFrame
	hide_TitanPanelGuildButton_FriendsFrame = 0;	
	-- init guild_TimeCounter
	guild_TimeCounter = 0;
	masterTable = {};
	masterTableSimple = {};
	--TitanPanelGuildButton_ListInitMaster();
	this.registry = { 
		id = TITAN_GUILD_ID,
		menuText = TITAN_GUILD_MENU_TEXT, 
		buttonTextFunction = "TitanPanelGuildButton_GetButtonText",
		tooltipTitle = TITAN_GUILD_TOOLTIP,
		tooltipTextFunction = "TitanPanelGuildButton_GetTooltipText",
		icon = "Interface\\PetitionFrame\\GuildCharter-Icon.blp",	
		iconWidth = 16,
		savedVariables = {
			ShowLabelText = 1,
			ShowIcon = 1,
			ShowAdvancedMenus = 0,
			ShowMenuOptions = 1,
			ShowTooltipName = 1,
			ShowTooltipZone = 1,
			ShowTooltipRank = 1,
			ShowTooltipNote = TITAN_NIL,
			ShowTooltipLevel = 1,
			ShowTooltipClass = 1,
			FilterMyLevel = TITAN_NIL,
			FilterMyZone = TITAN_NIL,
			FilterClasses = TITAN_NIL,
			SortByValue = TITAN_NIL,
			DisableRosterUpdates = TITAN_NIL,
		}
	};
	this:RegisterEvent("GUILD_ROSTER_SHOW");
	this:RegisterEvent("GUILD_ROSTER_UPDATE");
	this:RegisterEvent("GUILD_REGISTRAR_SHOW");
	this:RegisterEvent("GUILD_REGISTRAR_CLOSED");
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("SYSMSG");
	
	-- hooking FriendsFrame_OnShow()
	pre_TitanPanelGuildButton_FriendsFrame_OnShow = FriendsFrame_OnShow;
	FriendsFrame_OnShow = TitanPanelGuildButton_FriendsFrame_OnShow;
	-- hooking FriendsFrame_OnHide()
	pre_TitanPanelGuildButton_FriendsFrame_OnHide = FriendsFrame_OnHide;
	FriendsFrame_OnHide = TitanPanelGuildButton_FriendsFrame_OnHide;		
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_FriendsFrame_OnShow()
--  used to hook the FriendsFrame_OnShow() call
--  and not play a sound when the Titan Guild is updating
----------------------------------------------------------------------
function TitanPanelGuildButton_FriendsFrame_OnShow()
	-- if the variable exists, TitanGuild is being used
	if (hide_TitanPanelGuildButton_FriendsFrame) then
		if (hide_TitanPanelGuildButton_FriendsFrame == 0) then
			pre_TitanPanelGuildButton_FriendsFrame_OnShow();
		elseif (hide_TitanPanelGuildButton_FriendsFrame == 1) then
			-- From Interface\FrameXML\FriendsFrame.lua
			FriendsFrame_Update();
			UpdateMicroButtons();
			--PlaySound("igMainMenuOpen");
			GuildFrame.selectedGuildMember = 0;
			SetGuildRosterSelection(0);
		end
	else
		-- it's a reglar old FriendsFrame_OnShow() call
		pre_TitanPanelGuildButton_FriendsFrame_OnShow();
	end
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_FriendsFrame_OnHide()
--  used to hook the FriendsFrame_OnHide() call
--  and not play a sound when the Titan Guild is updating
----------------------------------------------------------------------
function TitanPanelGuildButton_FriendsFrame_OnHide()
	-- if the variable exists, TitanGuild is being used
	if (hide_TitanPanelGuildButton_FriendsFrame) then
		if (hide_TitanPanelGuildButton_FriendsFrame == 0) then
			pre_TitanPanelGuildButton_FriendsFrame_OnHide();
		elseif (hide_TitanPanelGuildButton_FriendsFrame == 1) then
			-- From Interface\FrameXML\FriendsFrame.lua
			UpdateMicroButtons();
			--PlaySound("igMainMenuClose");
			SetGuildRosterSelection(0);
			GuildFrame.selectedGuildMember = 0;
			GuildControlPopupFrame:Hide();
			hide_TitanPanelGuildButton_FriendsFrame = 0;
		end
	else
		-- it's a reglar old FriendsFrame_OnHide() call
		pre_TitanPanelGuildButton_FriendsFrame_OnHide();
		return;
	end
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_OnEvent()
--  traps and deals with GUILD_ROSTER_SHOW and GUILD_ROSTER_UPDATE
----------------------------------------------------------------------
function TitanPanelGuildButton_OnEvent()
	-- hide the FriendsFrame by capturing the GUILD_ROSTER_SHOW event	
	if (event == "PLAYER_ENTERING_WORLD") then
		--guildPrintDebugMessage(event);
		-- having issues on initial load
		GuildRoster();
		TitanPanelGuildButton_SortGuildRoster();	
		TitanPanelGuildButton_ListInitMaster();
		TitanPanelGuildButton_GetGuildRoster(0); -- EMERALD
	elseif (event == "GUILD_ROSTER_SHOW") then
		--guildPrintDebugMessage(event);
		-- build the table used to generate the right-click menus
		TitanPanelGuildButton_ListInitMaster();
		if(hide_TitanPanelGuildButton_FriendsFrame == 1) then
			HideUIPanel(FriendsFrame);
		end
	elseif (event == "GUILD_ROSTER_UPDATE") then
		--guildPrintDebugMessage(event);
		-- having issues on initial load
		TitanPanelGuildButton_ListInitMaster();
	--elseif (event == "SYSMSG") then
		--DEFAULT_CHAT_FRAME:AddMessage("DEBUG(SYSMSG): arg1="..arg1);
	end
	TitanPanelButton_UpdateButton(TITAN_GUILD_ID);	
	TitanPanelButton_UpdateTooltip();
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_OnEnter()
----------------------------------------------------------------------
function TitanPanelGuildButton_OnEnter()
	--TitanPanelButton_UpdateButton(TITAN_GUILD_ID);	
	--TitanPanelButton_UpdateTooltip();	
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_OnClick(arg1)
----------------------------------------------------------------------
function TitanPanelGuildButton_OnClick(button)
	-- open the guild pane on a left click
	if ( button == "LeftButton" and not IsControlKeyDown()) then
		if (GuildOrg) then -- EMERALD: If GuildOrg is installed, open its window instead of the Blizzard default one
			if (not GuildOrg:IsVisible()) then
				ShowUIPanel(GuildOrg);
			elseif (GuildOrg:IsVisible()) then
				HideUIPanel(GuildOrg);
			end
		else
			if (not FriendsFrame:IsVisible()) then
				PanelTemplates_SetTab(FriendsFrame, TITAN_GUILD_TAB_NUMBER);
				ShowUIPanel(FriendsFrame);
			elseif (FriendsFrame:IsVisible()) then
				HideUIPanel(FriendsFrame);
			end
		end
	elseif ( button == "LeftButton" and IsControlKeyDown()) then
		-- forcing an update, since auto-update might be off
		GuildRoster();
		TitanPanelGuildButton_ListInitMaster();
	end
end

----------------------------------------------------------------------
--  TitanPanelGuildButton_OnUpdate()
----------------------------------------------------------------------
function TitanPanelGuildButton_OnUpdate(elapsed)
	-- using my own damn timer
	-- EMERALD: That worked well  :P  j/k  ;)
	if (TitanGuildFirstCycle) then -- This will prevent the login delay before first update
		guild_TimeCounter = TITAN_GUILD_FREQUENCY;
		if (not (TitanGetVar(TITAN_GUILD_ID, "DisableRosterUpdates"))) then
			TitanPanelGuildButton_GetGuildRoster(timeLeft);
		end
		TitanGuildFirstCycle = false;
	else
		local timeLeft = guild_TimeCounter - elapsed;
		if (timeLeft <= 0) then
			guild_TimeCounter = TITAN_GUILD_FREQUENCY;
			if (not (TitanGetVar(TITAN_GUILD_ID, "DisableRosterUpdates"))) then
				TitanPanelGuildButton_GetGuildRoster(timeLeft);
			end
		else
			guild_TimeCounter = timeLeft;
		end
	end
end

----------------------------------------------------------------------
-- TitanPanelGuildButton_GetButtonText(id)
----------------------------------------------------------------------
function TitanPanelGuildButton_GetButtonText(id)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -