欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

supermacro.lua

时间太紧了
LUA
第 1 页 / 共 2 页
字号:
	SuperMacroFrame_SelectMacro(index);
	SuperMacroFrame_Update();
	
	-- if edited name, use oldextend
	if ( oldextend ) then
		SuperMacroFrameExtendText:SetText(oldextend);
	elseif ( SameMacroName() ) then
	-- get extend with same name, else empty
		local text = SuperMacroGetExtend( GetMacroInfo( SameMacroName(),"name" ) ) ;
			if ( text ) then
				SuperMacroFrameExtendText:SetText( text );
			end
	else
		SuperMacroFrameExtendText:SetText("");
	end
	SuperMacroSaveExtend();
	oldextend=nil;
end

function SuperMacroOptionsButton_OnClick()
	ShowUIPanel(SuperMacroOptionsFrame);
end

function SuperMacroFrame_SaveMacro()
	if ( SuperMacroFrame.textChanged and SuperMacroFrame.selectedMacro ) then
		EditMacro(SuperMacroFrame.selectedMacro, nil, nil, SuperMacroFrameText:GetText());
		SuperMacroFrame.textChanged = nil;
	end
end

function SuperMacroFrame_OnEvent(event)
	if ( event=="TRADE_SKILL_SHOW") then
		if ( not old_SM_TradeSkillSkillButton_OnClick) then
			old_SM_TradeSkillSkillButton_OnClick = TradeSkillSkillButton_OnClick;
			TradeSkillSkillButton_OnClick = SM_TradeSkillSkillButton_OnClick;
			SM_TradeSkillItem_OnClick();
		end
	end
	if ( event=="CRAFT_SHOW") then
		if ( not old_SM_CraftButton_OnClick) then
			old_SM_CraftButton_OnClick = CraftButton_OnClick;
			CraftButton_OnClick = SM_CraftButton_OnClick;
			SM_CraftItem_OnClick();
		end
	end
	if ( event=="VARIABLES_LOADED" ) then
		if ( not SM_VARS.hideAction ) then
			SM_VARS.hideAction = 0;
		end
		if ( not SM_VARS.printColor ) then
			SM_VARS.printColor = PRINT_COLOR_DEF;
		end
		if ( not SM_VARS.macroTip1 ) then
			SM_VARS.macroTip1= 1;
		end
		if ( not SM_VARS.macroTip2 ) then
			SM_VARS.macroTip2= 0;
		end
		if ( not SM_VARS.minimap ) then
			SM_VARS.minimap = 1;
		end
		if ( not SM_VARS.replaceIcon ) then
			SM_VARS.replaceIcon = 1;
		end
		HideActionText();
		ToggleSMMinimap();
		SuperMacroRunScriptExtend();
		SuperMacroFrame.extendChanged=nil;
	end
end

function RunMacro(index)
	-- close edit boxes, then enter body line by line
	if ( SuperMacroFrame_SaveMacro ) then
		SuperMacroFrame_SaveMacro();
	end
	if ( MacroFrame_SaveMacro ) then
		MacroFrame_SaveMacro();
	end
	local name, texture, body, isLocal;
	if ( type(index) == "number" ) then
		name, texture, body, isLocal = GetMacroInfo(index);
	elseif ( type(index) == "string" ) then
		name, texture, body, isLocal = GetMacroInfo(GetMacroIndexByName(index));
	end
	if ( not body ) then return; end

	if ( ChatFrameEditBox:IsVisible() ) then
		ChatEdit_OnEscapePressed(ChatFrameEditBox);
	end
	RunBody(body);
end

Macro=RunMacro;

function RunBody(body)
	local length = string.len(body);
	local text="";
	for i = 1, length do
		text=text..string.sub(body,i,i);
		if ( string.sub(body,i,i) == "\n" or i == length ) then
			RunLine(text);
			text="";
		end
	end
end

function RunLine(...)
-- execute a line in a macro
-- if script or cast, then rectify and RunScript
-- else send to chat edit box
for k=1,arg.n do
	local text=arg[k];
	if (ReplaceAlias and ASFOptions.aliasOn) then
		-- correct aliases
		text = ReplaceAlias(text);
	end
	if ( string.find(text,"^/cast") ) then
		local i, book = SM_FindSpell(gsub(text,"^%s*/cast%s*(%w.*[%w%)])%s*$","%1"));
		if ( i ) then
			CastSpell(i,book);
		end
	else
		if ( string.find(text,"^/script ")) then
			RunScript(gsub(text,"^/script ",""));
		else
			text = gsub( text, "\n", ""); -- cannot send newlines, will disconnect
			ChatFrameEditBox:SetText(text);
			ChatEdit_SendText(ChatFrameEditBox);
		end
	end
end -- for

end -- RunLine()

function SM_FindSpell(spell)
	local s = gsub(spell, "%s*(.-)%s*%(.*","%1");
	local r;
	local num = tonumber(gsub( spell, "%D*(%d+)%D*", "%1"),10);
	if ( string.find(spell, "%(%s*[Rr]acial")) then
		r = "racial"
	elseif ( string.find(spell, "%(%s*[Ss]ummon")) then
		r = "summon"
	elseif ( string.find(spell, "%(%s*[Aa]pprentice")) then
		r = "apprentice"
	elseif ( string.find(spell, "%(%s*[Jj]ourneyman")) then
		r = "journeyman"
	elseif ( string.find(spell, "%(%s*[Ee]xpert")) then
		r = "expert"
	elseif ( string.find(spell, "%(%s*[Aa]rtisan")) then
		r = "artisan"
	elseif ( string.find(spell, "%(%s*[Mm]aster")) then
		r = "master"
	elseif ( string.find(spell, "[Rr]ank%s*%d+") and num and num > 0) then
		r = gsub(spell, ".*%(.*[Rr]ank%s*(%d+).*", "Rank "..num);
	else
		r = ""
	end
	return FindSpell(s,r);
end

function FindSpell(spell, rank)
	local i = 1;
	local booktype = { "spell", "pet", };
	--local booktype = "spell";
	local s,r;
	local ys, yr;
	for k, book in booktype do
		while spell do
		s, r = GetSpellName(i,book);
		if ( not s ) then
			i = 1;
			break;
		end
		if ( string.lower(s) == string.lower(spell)) then ys=true; end
		if ( (r == rank) or (r and rank and string.lower(r) == string.lower(rank))) then yr=true; end
		if ( rank=='' and ys and (not GetSpellName(i+1, book) or string.lower(GetSpellName(i+1, book)) ~= string.lower(spell) )) then
			yr = true; -- use highest spell rank if omitted
		end
		if ( ys and yr ) then
			return i,book;
		end
		i=i+1;
		ys = nil;
		yr = nil;
		end
	end
	return;
end

function SuperMacroSaveExtendButton_OnClick()
	SuperMacroSaveExtend();
	SuperMacroRunScriptExtend();
end

function SuperMacroDeleteExtendButton_OnClick()
	SuperMacroSaveExtend(SelectedMacroName(),1);
	SuperMacroRunScriptExtend();
end

function SuperMacroSaveExtend(macro, delete)
	local text=SuperMacroFrameExtendText:GetText();
	if ( delete ) then text = nil; end
	if ( not macro ) then
		macro = SelectedMacroName();
	end
	if ( macro ) then
    	if ( text and text~="" ) then
		SM_EXTEND[macro]=text;
	else
		SM_EXTEND[macro]=nil;
			if ( macro == SelectedMacroName() ) then
			SuperMacroFrameExtendText:SetText('');
			end
	end
	end
	SuperMacroFrame.extendChanged=nil;
	SuperMacroFrameExtendText:ClearFocus();
end

function SuperMacroGetExtend(macro)
	return SM_EXTEND[macro];
end

function SuperMacroRunScriptExtend()
	for m,e in pairs(SM_EXTEND) do
		if ( e ) then
			RunScript(e);
		end
	end
end

function SuperMacroDeleteButton_OnClick()
-- check other macros with same name to see if save extend
	local macro=GetMacroInfo(SuperMacroFrame.selectedMacro,"name");
	if ( SameMacroName()==false ) then
		SuperMacroSaveExtend(macro,1); -- delete extend
	end
	DeleteMacro(SuperMacroFrame.selectedMacro);
	SuperMacroFrame_OnLoad();
	SuperMacroFrame_Update();
	local name = GetMacroInfo(1,"name");
	oldextend = SM_EXTEND[name];
	if ( oldextend ) then
		SuperMacroFrameExtendText:SetText(oldextend);
	end
	oldextend = nil;
	SuperMacroFrameText:ClearFocus();
end

function SameMacroName(macroindex)
	if ( not macroindex and SuperMacroFrame.selectedMacro ) then
		macroindex = SuperMacroFrame.selectedMacro;
	else
		return; -- error check for nil, no macro selected
	end
	local macro=GetMacroInfo(macroindex,"name");
	local prevmacro, nextmacro = GetMacroInfo(macroindex-1,"name"), GetMacroInfo(macroindex+1,"name");
	if ( prevmacro == macro ) then
		return macroindex-1;
	elseif ( nextmacro == macro ) then
		return macroindex+1;
	else
		return false; -- must check "==false"
		-- don't check "not SameMacroName()" unless error check or no macro selected
	end
end

function SelectedMacroName()
	return SuperMacroFrameSelectedMacroName:GetText();
end

local oldGetMacroInfo=GetMacroInfo;
function GetMacroInfo(index, code)
	if ( not index ) then return; end
	-- code can be "name", "texture", "body", "islocal"
	local a={};
	a.name,a.texture,a.body,a.islocal=oldGetMacroInfo(index);
	if (not code) then
		return a.name,a.texture,a.body,a.islocal;
	else
		return a[code];
	end
end

function SetActionMacro( actionid , macro ) 
	local macroid = GetMacroIndexByName( macro )
	if ( macroid and actionid > 0 and actionid < 120 ) then
		PickupAction( actionid );
		PickupMacro( macroid );
		PlaceAction ( actionid );
	end
end

oldUseAction=UseAction;
function UseAction( id, click, selfcast)
	lastActionUsed = id;
	if ( SuperMacroFrame_SaveMacro ) then
		SuperMacroFrame_SaveMacro();
	end
	oldUseAction( id, click, selfcast );
end

function ToggleSMMinimap()
	if ( SM_VARS.minimap == 1 ) then
		SuperMacroMinimapButton:Show();
	else
		SuperMacroMinimapButton:Hide();
	end
end

function SM_UpdateAction()
	-- Update Macros on action bars
	local function doUpdate(button)
		if ( button ) then
			button:SetScript("OnLeave", SM_ActionButton_OnLeave);
			if ( not getglobal(button:GetName().."Name") ) then return end;
			local macroName = getglobal(button:GetName().."Name"):GetText();
			if ( macroName ) then
				local macroID = GetMacroIndexByName(macroName);
				if ( macroID ) then
					local name, texture, body, isLocal = GetMacroInfo(macroID);
					EditMacro(macroID, nil, nil, body, isLocal);
				end
			end
		end
	end
	for i=1,72 do
		doUpdate(getglobal("ActionButton"..i));
		doUpdate(getglobal("BonusActionButton"..i));
		doUpdate(getglobal("MultiBarBottomLeftButton"..i));
		doUpdate(getglobal("MultiBarBottomRightButton"..i));
		doUpdate(getglobal("MultiBarRightButton"..i));
		doUpdate(getglobal("MultiBarLeftButton"..i));
	end
	---[[
	if ( DAB_ActionButton_1 ) then
	for i=1, 120 do
		doUpdate(getglobal("DAB_ActionButton_"..i));
	end
	end
	--]]
end

⌨️ 快捷键说明

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