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

📄 sm_tooltip.lua

📁 时间太紧了
💻 LUA
字号:
--SM_VARS.macroTip1 = 1; -- for spell, item
--SM_VARS.macroTip2 = 1; -- for macro code

oldActionButton_SetTooltip=ActionButton_SetTooltip;
function ActionButton_SetTooltip()
	oldActionButton_SetTooltip();
	SM_ActionButton_SetTooltip();
end
---[[
if ( DAB_ActionButton_OnEnter ) then
oldDAB_ActionButton_OnEnter=DAB_ActionButton_OnEnter;
function DAB_ActionButton_OnEnter()
	oldDAB_ActionButton_OnEnter();
	SM_ActionButton_SetTooltip();
end
end
--]]
function SM_ActionButton_SetTooltip()
	if ( not getglobal(this:GetName().."Name") ) then return end;
	local macroname=getglobal(this:GetName().."Name"):GetText();
	if ( macroname ) then
	local macro, a, body = GetMacroInfo(GetMacroIndexByName(macroname));
	if ( SM_VARS.macroTip1==1 ) then
		-- if find cast -> if find spell, rank -> setspell
		local id, book = FindFirstSpell( body );
		if ( id ) then
			GameTooltip:SetSpell(id, book);
			local s, r = GetSpellName(id, book);
			if ( r ) then
				GameTooltipTextRight1:SetText(r);
				GameTooltipTextRight1:Show();
				GameTooltip:Show();
			end
			return;
		end
		id, book = FindFirstItem( body );
		if ( id ) then
			if ( book ) then
				GameTooltip:SetBagItem(id, book);
			else
				GameTooltip:SetInventoryItem('player', id);
			end
			return;
		end
	end
	if ( SM_VARS.macroTip2 == 1 ) then
		-- show macro code
		if ( not GameTooltipTextLeft1:GetText() ) then return; end
			body = gsub(body, "\n$", "");
			GameTooltipTextLeft1:SetText( "|cff00ffff" .. GameTooltipTextLeft1:GetText() .. "|r" );
			GameTooltipTextLeft2:SetText("|cffffffff"..body.."|r");
			GameTooltipTextLeft2:Show();
			GameTooltipTextLeft1:SetWidth(284);
			GameTooltipTextLeft2:SetWidth(284);
			GameTooltip:SetWidth(300);
			GameTooltip:SetHeight( GameTooltipTextLeft1:GetHeight() + GameTooltipTextLeft2:GetHeight() + 23);
			GameTooltipTextLeft2:SetNonSpaceWrap(true);
			return;
		end
	end
-- show crit info for Attack
	if ( GameTooltipTextLeft1:GetText()=="Attack" ) then
		id, book = FindSpell("Attack","");
		GameTooltip:SetSpell(id, book);
		GameTooltip:Show();
	end
end

function SM_ActionButton_OnLeave()
	this.updateTooltip=nil;
	--GameTooltipTextLeft2:SetText('');
	GameTooltipTextLeft2:SetWidth(100);
	GameTooltipTextLeft2:Hide();
	GameTooltip:Hide();
end

local oldGetActionCooldown = GetActionCooldown;
function GetActionCooldown( actionid )
	if (not this) then
		return oldGetActionCooldown( actionid );
	end;
	local macroname = getglobal(this:GetName().."Name");
	if (not macroname) then
		return oldGetActionCooldown( actionid );
	end;
	local macro = macroname:GetText();
if ( macro ) then
	local pic = getglobal(this:GetName().."Icon");
	pic:SetTexture(GetActionTexture( actionid));
		local name, icon, body = GetMacroInfo(GetMacroIndexByName(macro));
		local id, book, texture, count= FindFirstSpell(body);
		if ( id ) then
			if ( SM_VARS.replaceIcon==1 and texture ) then
				pic:SetTexture(texture);
			end
			return GetSpellCooldown( id, book);
		end
		id, book, texture, count = FindFirstItem(body);
		if ( id ) then
			if ( SM_VARS.replaceIcon==1 and texture ) then
				pic:SetTexture(texture);
			end
			if ( count>1 ) then
				macroname:Hide();
				getglobal(this:GetName().."Count"):SetText(count);
			else
				macroname:Show();
				getglobal(this:GetName().."Count"):SetText("");
			end
			if ( book ) then
				return GetContainerItemCooldown(id, book);
			else
				return GetInventoryItemCooldown('player',id);
			end
		end
end
	return oldGetActionCooldown( actionid );
	-- start, duration, enable
end
--[[
local oldIsActionInRange = IsActionInRange;
function IsActionInRange( actionid )
	local macroname = GetActionText(actionid );
	local curstate = CursorHasSpell() or CursorHasItem() or CursorHasMoney()
	if ( macroname and not curstate ) then
		local macroid = GetMacroIndexByName(macroname);
		local _,_, body = GetMacroInfo( macroid );
		local id, book = FindFirstSpell(body);
		if ( id ) then
			PickupAction(120)
			PickupSpell(id, book);
			PlaceAction( 120 );	
			local range = oldIsActionInRange( 120 );
			return range;
		end
		local id, book = FindFirstItem(body);
		if ( book ) then
			PickupAction(120)
			PickupContainerItem(id, book);
			PlaceAction( 120 );
			local range = oldIsActionInRange( 120 );
			return range;
		elseif ( id ) then
			PickupAction(120)
			PickupInventoryItem(id, book);
			PlaceAction( 120 );
			local range = oldIsActionInRange( 120 );
			return range;			
		end
	end
	return oldIsActionInRange(actionid );
end
--]]

function FindFirstSpell( text )
	local body = text;
	if(not body) then
		return;
	end
	if (ReplaceAlias and ASFOptions.aliasOn) then
		-- correct aliases
		body = ReplaceAlias(body);
	end
	local id, book, texture;
	while ( string.find(body, "CastSpellByName") ) do
		local spell = gsub(body,'.-CastSpellByName.-%(.-(["\'])(.-)%1.*','%2');
		id, book = SM_FindSpell(spell);
		if ( id ) then
			texture = GetSpellTexture(id, book);
			break;
		end
		body = gsub(body, "CastSpellByName","",1);
	end
	if ( not id and string.find(body,"/cast") ) then
			local spell = gsub(body,"^.*/cast%s*([%w'%(%) ]+)[\n]?%s*.*$","%1");
			id, book = SM_FindSpell(spell);
			if ( id and book ) then
				texture = GetSpellTexture(id, book);
			end
	end
	if ( not id ) then
		while ( string.find(body, "[%p%s]cast%(") ) do
			local spell = gsub(body,'.-[%p%s]cast%(.-(["\'])(.-)%1.*','%2');
			id, book = SM_FindSpell(spell);
			if ( id ) then
				texture = GetSpellTexture(id, book);
				break;
			end
			body = gsub(body, "[%p%s]cast%(","", 1);
		end
	end
	if ( not id ) then
		while ( string.find(body, "CastSpell")) do
			local spell = gsub(body,'.-CastSpell.-%(%s-(.-)%s*%).*','%1');
			local _,_,spellid = strfind(spell,"^(%d+).*");
			if ( spellid ) then
				local _,_,spellbook=strfind(spell,"^.-"..spellid..",%s*'(%a+)'%s*");
				id=spellid;
				book=spellbook or 'spell';
				texture = GetSpellTexture(id, book);
				break;
			end
			body = gsub(body, "CastSpell","", 1);
		end
	end
	return id, book, texture;
end

function FindFirstItem( text )
	local body = text;
	if (ReplaceAlias and ASFOptions.aliasOn) then
		-- correct aliases
		body = ReplaceAlias(body);
	end
	local bag, slot, texture, count;
	if( not body ) then
		return;
	end
	if ( string.find(body,"UseItemByName") ) then
		while ( string.find(body, "UseItemByName") ) do
			local item = gsub(body,'.-UseItemByName.-%(.-(["\'])(.-)%1.*','%2');
			bag, slot, texture, count = FindItem(item);
			if ( bag ) then
				return bag, slot, texture, count;
			end
			body = gsub(body, "UseItemByName","", 1);
		end
	end
	if ( string.find(body,"/use") ) then
		while ( string.find(body, "/use") ) do
			local item = gsub(body,'^.-/use *(.-) *\n.*','%1');
			if ( item==body ) then
				item = gsub(body,'^.-/use *(.-) *$','%1');
			end
			bag, slot, texture, count = FindItem(item);
			if ( bag ) then
				return bag, slot, texture, count;
			end
			body = gsub(body, "/use","", 1);
		end
	end
	if ( string.find(body,"use") ) then
		while ( string.find(body, "use") ) do
			local item = gsub(body,'.-use.-%(.-(["\'])(.-)%1.*','%2');
			bag, slot, texture, count = FindItem(item);
			if ( bag ) then
				return bag, slot, texture, count;
			end
			body = gsub(body, "use","", 1);
		end
	end
	while ( string.find(body, "UseInventoryItem") ) do
		bag = gsub(body,'.-UseInventoryItem.-(%d+)%s-%).*','%1');
		if ( bag~=body) then
			texture = GetInventoryItemTexture('player', bag);
			count = GetInventoryItemCount('player', bag);
		end
		if ( texture ) then
			return bag, slot, texture, count;
		end
		body = gsub(body, "UseInventoryItem","", 1);
	end
	while ( string.find(body, "UseContainerItem") ) do
		bag = gsub(body,'.-UseContainerItem.-(%d+)%s-,%s-(%d+)%s-%).*','%1');
		slot = gsub(body,'.-UseContainerItem.-(%d+)%s-,%s-(%d+)%s-%).*','%2');
		if ( bag~=body and slot~=body) then
			texture, count = GetContainerItemInfo(bag, slot);
		end
		if ( bag~=body and slot~=body and texture ) then
			return bag, slot, texture, count;
		end
		body = gsub(body, "UseContainerItem","", 1);
	end
end

⌨️ 快捷键说明

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