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

📄 tipbuddy.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 5 页
字号:
--[[

	TipBuddy: ---------
		copyright 2005 by Chester

]]

function TipBuddy_OnLoad()

	this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE");

	this:RegisterEvent("UNIT_LEVEL");
	this:RegisterEvent("UNIT_FACTION");
	this:RegisterEvent("UNIT_DYNAMIC_FLAGS");
	this:RegisterEvent("UNIT_CLASSIFICATION_CHANGED");
	this:RegisterEvent("PLAYER_PVPLEVEL_CHANGED");
	this:RegisterEvent("UNIT_AURA");
	this:RegisterEvent("PLAYER_FLAGS_CHANGED");
	this:RegisterEvent("UNIT_HEALTH");
	this:RegisterEvent("UNIT_MAXHEALTH");
	this:RegisterEvent("UNIT_MANA");
	this:RegisterEvent("UNIT_RAGE");
	this:RegisterEvent("UNIT_FOCUS");
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("UNIT_HAPPINESS");
	this:RegisterEvent("UNIT_MAXMANA");
	this:RegisterEvent("UNIT_MAXRAGE");
	this:RegisterEvent("UNIT_MAXFOCUS");
	this:RegisterEvent("UNIT_MAXENERGY");
	this:RegisterEvent("UNIT_MAXHAPPINESS");
	this:RegisterEvent("UNIT_DISPLAYPOWER");
	this:RegisterEvent("UPDATE_SHAPESHIFT_FORMS");

	SLASH_TIPBUDDY1 = "/tipbuddy";
	SLASH_TIPBUDDY2 = "/tbuddy";
	SLASH_TIPBUDDY3 = "/tip";
	SlashCmdList["TIPBUDDY"] = function(msg)
		TipBuddy_SlashCommand(msg);
	end
	
	-- commented out cause it fucked up my buttons
	-- Add TipBuddy_OptionsFrame to the UIPanelWindows list
	--UIPanelWindows['TipBuddy_OptionsFrame'] = {area = 'center', pushable = 0};
end
local function GlimToolTipReg()
		gLim_RegisterButton (
		"gLimTooltipConfig",
		"提示信息設置",
		"Interface\\AddOns\\gLimMod\\icon4",
		function()
			TipBuddy_ToggleOptionsFrame();
		end,
		1,
		10
		);
end
local lGameTooltip_OnEvent_Orig;
function TipBuddy_OnEvent()
	if( event == "VARIABLES_LOADED" ) then
		TipBuddy_Variable_Initialize();

		TipBuddy.uiScale = TipBuddy_GetUIScale();
		TipBuddy.xpoint, TipBuddy.xpos, TipBuddy.ypos = TipBuddy_GetFrameCursorOffset();
		TipBuddy.anchor, TipBuddy.fanchor, TipBuddy.offset = TipBuddy_GetFrameAnchorPos();
		
		--hooking GameTooltip's OnEvent
		lGameTooltip_OnEvent_Orig = GameTooltip:GetScript("OnEvent");
		GameTooltip:SetScript( "OnEvent", TipBuddy_GameTooltip_OnEvent );

		--hooking GameTooltip's OnShow
		--lGameTooltip_OnShow_Orig = GameTooltip:GetScript("OnShow");
		GameTooltip:SetScript( "OnShow", TipBuddy_GameTooltip_OnShow );

		--hooking SetUnit
		--lGameTooltip_SetUnit_Orig = GameTooltip.SetUnit; 
		--GameTooltip.SetUnit = TB_GameTooltip_SetUnit; 

		if (TipBuddy_SavedVars["general"].framepos_L or TipBuddy_SavedVars["general"].framepos_T) then
			TipBuddy_Header_Frame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", TipBuddy_SavedVars["general"].framepos_L, TipBuddy_SavedVars["general"].framepos_T);
		end
		if (not TipBuddy_SavedVars["general"].delaytime) then
			TipBuddy_SavedVars["general"].delaytime = "0.5";
		end
		if (not TipBuddy_SavedVars["general"].fadetime) then
			TipBuddy_SavedVars["general"].fadetime = "0.3";
		end
		if (not TipBuddy_SavedVars["general"].gtt_anchored) then
			TipBuddy_SavedVars["general"].gtt_anchored = 0;	
		end

		if (TipBuddy_SavedVars["general"].anchored == 1) then
			if (not TipBuddy_SavedVars["general"].anchor_vis_first or TipBuddy_SavedVars["general"].anchor_vis == 1) then
				TipBuddy_SavedVars["general"].anchor_vis_first = 1;
				TipBuddy_Header_Frame:Show();
			else
				TipBuddy_Header_Frame:Show();
				TipBuddy_Header_Frame:Hide();
			end
			TipBuddy.anchor, TipBuddy.fanchor, TipBuddy.offset = TipBuddy_GetFrameAnchorPos();
			this:SetPoint(TipBuddy.anchor, "TipBuddy_Header_Frame", TipBuddy.fanchor, 0, 1);
		else
			if (not TipBuddy_SavedVars["general"].anchor_vis_first) then
				TipBuddy_ResetAnchorPos();
				TipBuddy_Header_Frame:Hide();
			else
				TipBuddy_Header_Frame:Show();
				TipBuddy_Header_Frame:Hide();
			end
		end

		if( DEFAULT_CHAT_FRAME ) then
			--DEFAULT_CHAT_FRAME:AddMessage("|cffffd200TipBuddy |cffffff00v"..TIPBUDDY_VERSION.." loaded.");
		end

		TipBuddy_InitializeTextColors();

		-- Add TipBuddy to myAddOns addons list
		if (myAddOnsFrame) then	
			myAddOnsList.TipBuddy = {
					name = "|cff20ff20TipBuddy", 
					description = "Enhanced, configurable unit tooltip.", 
					version = "|cffffff00"..TIPBUDDY_VERSION,
					author = "chester",
					email = "chester.dent@gmail.com",
					category = MYADDONS_CATEGORY_OTHERS, 
					frame = "TipBuddy_OptionsFrame",
					optionsframe = "TipBuddy_OptionsFrame"
					};
		end

		GameTooltip:SetBackdrop({bgFile="Interface\\AddOns\\TipBuddy\\gfx\\UI-Tooltip-Background",edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",tile=true,tileSize=32,edgeSize=16,insets={ left = 4, right = 4, top = 4, bottom = 4 }});
		TipBuddy_Main_Frame:SetBackdrop({bgFile="Interface\\AddOns\\TipBuddy\\gfx\\UI-Tooltip-Background",edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",tile=true,tileSize=32,edgeSize=8,insets={ left = 2, right = 2, top = 2, bottom = 2 }});
		GlimToolTipReg();
	end
	if ( event == "UNIT_LEVEL" ) then
		if ( arg1 == "mouseover" ) then
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			--TB_AddMessage("UNIT_LEVEL");
			TipBuddy_SetFrame_Visibility( TipBuddy.targetType, "mouseover", 1 );
		
			TipBuddy_SetFrame_BackgroundColor( TipBuddy.targetType, "mouseover" );
		end
		return;
	end
	if ( event == "UNIT_FACTION" ) then
		if ( arg1 == "mouseover" ) then
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			TB_AddMessage(TB_WHT_TXT.."UNIT_FACTION");
			TipBuddy_SetFrame_Visibility( TipBuddy.targetType, "mouseover", 1 );
		
			TipBuddy_ShowRank( TipBuddy.targetType, "mouseover" );
		end
		return;
	end
	if ( event == "PLAYER_PVPLEVEL_CHANGED" ) then
		if ( arg1 == "mouseover" ) then
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			TipBuddy_ShowRank( TipBuddy.targetType, "mouseover" );
		end
		return;
	end
	if ( event == "UNIT_DYNAMIC_FLAGS" ) then
		if ( arg1 == "mouseover" ) then
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			TB_AddMessage(TB_WHT_TXT.."TB - UNIT_DYNAMIC_FLAGS");
			TipBuddy_SetFrame_Visibility( TipBuddy.targetType, "mouseover", 1 );
		
			TipBuddy_ShowRank( TipBuddy.targetType, "mouseover" );
			TipBuddy_SetFrame_BackgroundColor( TipBuddy.targetType, "mouseover" );
			TipBuddy_TargetBuffs_Update( TipBuddy.targetType, "mouseover" );
		end
		return;
	end
	if ( event == "UNIT_AURA" and arg1 == "mouseover" ) then
		TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
		TB_AddMessage(TB_WHT_TXT.."UNIT_AURA");
	
		TipBuddy_TargetBuffs_Update( TipBuddy.targetType, "mouseover" );
		return;
	end
	if ( event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" ) then
		if ( arg1 == "mouseover" or UnitIsPlayer("mouseover")) then
			TB_AddMessage(TB_WHT_TXT.."UNIT_HEALTH or UNIT_MAXHEALTH");
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			if (UnitHealth(arg1) <= 0) then
				TipBuddy_SetFrame_Visibility( TipBuddy.targetType, "mouseover", 1 );
				TipBuddy_SetFrame_BackgroundColor( TipBuddy.targetType, "mouseover" );
				return;
			end
			if (GameTooltip:IsVisible()) then
				TipBuddy_UpdateHealthText( TipBuddy_HealthTextGTT, TipBuddy.targetType, "mouseover" );
				TipBuddy_UpdateManaText( TipBuddy_ManaTextGTT, TipBuddy.targetType, "mouseover" );			
			else
				TipBuddy_UpdateHealthText( TipBuddy_HealthText, TipBuddy.targetType, "mouseover" );
				TipBuddy_UpdateManaText( TipBuddy_ManaText, TipBuddy.targetType, "mouseover" );
				TipBuddy_TargetInfo_FindExtras();
			end
		end
		return;
	end
	if ( event == "UNIT_MANA" or event == "UNIT_RAGE" or event == "UNIT_FOCUS" or event == "UNIT_ENERGY" or event == "UNIT_HAPPINESS" or event == "UNIT_MAXMANA" or event == "UNIT_MAXRAGE" or event == "UNIT_MAXFOCUS" or event == "UNIT_MAXENERGY" or event == "UNIT_MAXHAPPINESS" or event == "UNIT_DISPLAYPOWER" or event == "UPDATE_SHAPESHIFT_FORMS") then
		if ( arg1 == "mouseover" or UnitIsPlayer("mouseover")) then
			TB_AddMessage("UNIT_MANA");
			TipBuddy.targetType = TipBuddy_TargetInfo_GetTargetType( "mouseover" );
			if ( TipBuddy_SavedVars[TipBuddy.targetType].off ~= 0 ) then
				--TB_AddMessage(TB_WHT_TXT.."UNIT_MANA - go");
				TipBuddy_SetFrame_Visibility( TipBuddy.targetType, "mouseover", 1 );
		
				TipBuddy_SetFrame_BackgroundColor( TipBuddy.targetType, "mouseover" );
				TipBuddy_TargetBuffs_Update( TipBuddy.targetType, "mouseover" );
			end
		end
		return;
	end
end

--/script TB_AddMessage(TB_RED_TXT..UnitName("targettarget"));

function TipBuddy_SlashCommand(msg)
	if( not msg or msg == "" ) then
		TipBuddy_ToggleOptionsFrame();
	end
	if( msg == "rankname" ) then
		if (TipBuddy_SavedVars["general"].rankname == 1) then
			TipBuddy_SavedVars["general"].rankname = 0;
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: No longer showing full rank title in name.");
		else
			TipBuddy_SavedVars["general"].rankname = 1;
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Showing full rank titles in name.");
		end
	end
	if( msg == "resetanchor" ) then
		TipBuddy_ResetAnchorPos();
		DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Resetting TipBuddyAnchor position.");
	end
	if( msg == "report" ) then
		TipBuddy_ReportVarStats();
	end
	if( msg == "blizdefault" ) then
		if (TipBuddy_SavedVars["general"].blizdefault == 1) then
			TipBuddy_SavedVars["general"].blizdefault = 0;
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Default tooltips are now enhanced.");
		else
			TipBuddy_SavedVars["general"].blizdefault = 1;
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Default tooltips are no longer enhanced.");
		end
	end
	if (string.find(msg, "extras") ~= nil) then
		local type = "";
		for type in string.gfind(msg, "extras%s(.+)") do
			type = TipBuddy_ToggleExtras(type);
			TB_AddMessage(type);
		end
		if (not type) then
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Please specify a target type (ex: /tip extras pc_friend)");
			return;
		end
		return;
	end
	if (string.find(msg, "scale") ~= nil) then
		--local i, s = string.find(msg, "%d+");
		for scale in string.gfind(msg, "scale%s(%d.*)") do
			TipBuddy.s = tonumber(scale);
		end
		if (TipBuddy.s) then
			if (TipBuddy.s > 2) then
				TipBuddy.s = 2;
			elseif (TipBuddy.s < 0.25) then
				TipBuddy.s = 0.25;
			end
			GameTooltip:SetScale(2);
			--GameTooltip:SetScale(UIParent:GetScale() * TipBuddy.s);
			TipBuddy_SetEffectiveScale(GameTooltip, TipBuddy.s, UIParent);
			--TipBuddy_SavedVars["general"].gtt_scale = (UIParent:GetScale() * TipBuddy.s);
			TipBuddy_SavedVars["general"].gtt_scale = TipBuddy.s;
		else
			DEFAULT_CHAT_FRAME:AddMessage("|cff20ff20TipBuddy: Please type a scale number after 'scale' (valid numbers: 0.25-2)");
		end
		return;
	end

end

--------------------------------------------------------------------------------------------------------------------------------------
-- GET TARGET TYPE
--------------------------------------------------------------------------------------------------------------------------------------
function TipBuddy_TargetInfo_GetTargetType( unit )
	if (not unit) then
		return;
	end
	if ( ( UnitHealth(unit) <= 0 ) ) then
		return ( "corpse" );
	elseif ( ( UnitHealthMax(unit) > 0 ) ) then
		if (string.find(unit, "party.+")) then
			return ( "pc_party" );	
		end
		if (UnitPlayerControlled(unit)) then
			if (UnitIsFriend(unit, "player")) then
				if ( TipBuddy_TargetInfo_CheckPet() ) then
					return ( "pet_friend" );
				end
				
				if (UnitInParty(unit)) then
					return ( "pc_party" );
				else
					return ( "pc_friend" );
				end				
			elseif (UnitIsEnemy(unit, "player")) then
				if ( TipBuddy_TargetInfo_CheckPet() ) then
					return ( "pet_enemy" );
				else
					return ( "pc_enemy" );
				end
			else
				return ( "pet_friend" );
			end				
		else
			if (UnitIsFriend(unit, "player")) then
				if ( TipBuddy_TargetInfo_CheckPet() ) then
					return ( "pet_friend" );
				else
					return ( "npc_friend" );
				end
			elseif (UnitIsEnemy(unit, "player")) then
				if ( TipBuddy_TargetInfo_CheckPet() ) then
					return ( "pet_enemy" );
				else
					return ( "npc_enemy" );
				end
			else --neutral
				return ( "npc_neutral" );			
			end
		end	
	else
		TipBuddy_Hide( TipBuddy_Main_Frame );
		return;	
	end
end

--------------------------------------------------------------------------------------------------------------------------------------
-- HEALTH / MANA
--------------------------------------------------------------------------------------------------------------------------------------
ManaTextColor = {};
ManaTextColor[0] = { r = 0.50, g = 0.50, b = 1.00, prefix = TEXT(MANA) };
ManaTextColor[1] = { r = 1.00, g = 0.00, b = 0.00, prefix = TEXT(RAGE_POINTS) };
ManaTextColor[2] = { r = 1.00, g = 0.50, b = 0.25, prefix = TEXT(FOCUS_POINTS) };
ManaTextColor[3] = { r = 1.00, g = 1.00, b = 0.00, prefix = TEXT(ENERGY_POINTS) };
ManaTextColor[4] = { r = 0.00, g = 1.00, b = 1.00, prefix = TEXT(HAPPINESS_POINTS) };

function TipBuddy_UnitFrame_UpdateHealth( unit )
	UnitFrameHealthBar_Update(TipBuddy_TargetFrameHealthBar, unit);
end

function TipBuddy_UnitFrame_UpdateMana( unit )

⌨️ 快捷键说明

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