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

📄 supermacro.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
SUPERMACRO_VERSION = "3.04";
UIPanelWindows["SuperMacroFrame"] = { area = "left", pushable = 7, whileDead = 1 };
UIPanelWindows["SuperMacroOptionsFrame"] = { area = "left", pushable = 0, whileDead = 1 };
--MACRO_ROWS = 3;
--MACRO_COLUMNS = 12;
--MACROS_SHOWN = 36;
MAX_MACROS = 18;
--MAX_TOTAL_MACROS = 36;
NUM_MACRO_ICONS_SHOWN = 20;
NUM_ICONS_PER_ROW = 5;
NUM_ICON_ROWS = 4;
MACRO_ROW_HEIGHT = 36;
MACRO_ICON_ROW_HEIGHT = 36;
--MACRO_MAX_LETTERS = 255;
EXTEND_MAX_LETTERS = 7000;
PRINT_COLOR_DEF = {r=1, g=1, b=1};
SM_VARS = {};
--SM_VARS.hideAction = 0;
--SM_VARS.printColor = PRINT_COLOR_DEF;
--SM_VARS.macroTip1 = 1;
--SM_VARS.macroTip2 = 0;
--SM_VARS.minimap = 1;
--SM_VARS.replaceIcon = 1;
SM_EXTEND = {};
local oldextend;

function SuperMacroFrame_OnLoad()
	SuperMacroFrameTitle:SetText(SUPERMACRO_TITLE.." "..SUPERMACRO_VERSION);
	SuperMacroFrameCharacterMacroText:SetText(format(CHARACTER_SPECIFIC_MACROS, UnitName("player")));
	SM_UpdateAction();
	this:RegisterEvent("VARIABLES_LOADED");
	this:RegisterEvent("TRADE_SKILL_SHOW");
	this:RegisterEvent("CRAFT_SHOW");
	lastActionUsed = nil;
	SuperMacroFrame_SetAccountMacros();
end

function SuperMacroFrame_OnShow()
	SuperMacroFrame.extendChanged=nil;
	SuperMacroFrame_Update();
	PlaySound("igCharacterInfoOpen");
end

function SuperMacroFrame_OnHide()
	SuperMacroPopupFrame:Hide();
	SuperMacroFrame_SaveMacro();
	--SaveMacros();
	PlaySound("igCharacterInfoClose");
	if ( SuperMacroFrame.extendChanged ) then
		SuperMacroSaveExtend();
	end
	SuperMacroFrame.extendChanged=nil;
	-- purge empty extends
	for m,e in ipairs(SM_EXTEND) do
		if ( e=="" ) then
			SM_EXTEND[m]=nil;
		end
	end
	SuperMacroRunScriptExtend();
end

function SuperMacroFrame_SetAccountMacros()
	local numAccountMacros, numCharacterMacros = GetNumMacros();
	if ( numAccountMacros > 0 ) then
		SuperMacroFrame_SelectMacro(1);
	else
		SuperMacroFrame_SetCharacterMacros();
	end
end

function SuperMacroFrame_SetCharacterMacros()
	local numAccountMacros, numCharacterMacros = GetNumMacros();
	if ( numCharacterMacros > 0 ) then
		SuperMacroFrame_SelectMacro(19);
	else
		SuperMacroFrame_SelectMacro(nil);
	end
end

function SuperMacroFrame_Update()
	local numMacros;
	local numAccountMacros, numCharacterMacros = GetNumMacros();
	local macroButton, macroIcon, macroName;
	local name, texture, body, isLocal;
	local selectedName, selectedBody, selectedIcon;

	-- Macro List
	for j=0, MAX_MACROS, MAX_MACROS do
		if ( j == 0 ) then
			numMacros = numAccountMacros;
		else
			numMacros = numCharacterMacros;
		end
	for i=1, 18 do
		local macroID = i+j;
		getglobal("SuperMacroButton"..macroID.."ID"):SetText(macroID);
		macroButton = getglobal("SuperMacroButton"..macroID);
		macroIcon = getglobal("SuperMacroButton"..macroID.."Icon");
		macroName = getglobal("SuperMacroButton"..macroID.."Name");
		if ( i <= numMacros ) then
			name, texture, body, isLocal = GetMacroInfo(macroID);
			macroButton:SetID(macroID);
			macroIcon:SetTexture(texture);
			macroName:SetText(name);
			macroButton:Enable();
			-- Highlight Selected Macro
			if ( macroID == SuperMacroFrame.selectedMacro ) then
				macroButton:SetChecked(1);
    				SuperMacroFrameSelectedMacroName:SetText(name);
				SuperMacroFrameText:SetText(body);
					SuperMacroFrameSelectedMacroButton:SetID(macroID);				
    				SuperMacroFrameSelectedMacroButtonIcon:SetTexture(texture);
			else
				macroButton:SetChecked(0);
			end
		else
			macroButton:SetChecked(0);
			macroIcon:SetTexture("");
			macroName:SetText("");
			macroButton:Disable();
		end
	end
	end

	-- Macro Details
	if ( SuperMacroFrame.selectedMacro ~= nil ) then
		SuperMacroFrame_ShowDetails();
		SuperMacroDeleteButton:Enable();
	else
		SuperMacroFrame_HideDetails();
		SuperMacroDeleteButton:Disable();
	end
	
	--Update New Button
	if ( numAccountMacros == MAX_MACROS ) then
		SuperMacroNewAccountButton:Disable();
	else
		SuperMacroNewAccountButton:Enable();
	end
	if ( numCharacterMacros == MAX_MACROS ) then
		SuperMacroNewCharacterButton:Disable();
	else
		SuperMacroNewCharacterButton:Enable();
	end

	-- Disable Buttons
	if ( SuperMacroPopupFrame:IsVisible() ) then
		SuperMacroEditButton:Disable();
		SuperMacroDeleteButton:Disable();
	else
		SuperMacroEditButton:Enable();
		SuperMacroDeleteButton:Enable();
	end

	if ( not SuperMacroFrame.selectedMacro ) then
		SuperMacroDeleteButton:Disable();
	end
end

function SuperMacroFrame_AddMacroLine(line)
	if ( SuperMacroFrameText:IsVisible() ) then
		SuperMacroFrameText:SetText(SuperMacroFrameText:GetText()..line);
	end
end

function SuperMacroButton_OnClick()
	if ( SuperMacroFrame.extendChanged and SuperMacroFrame.selectedMacro ) then
		SuperMacroSaveExtend();
	end
	SuperMacroFrame_SaveMacro();
	SuperMacroFrame_SelectMacro(this:GetID());
	SuperMacroFrame_Update();
	SuperMacroPopupFrame:Hide();
	SuperMacroFrameText:ClearFocus();
	local macro=SuperMacroFrameSelectedMacroName:GetText();
	local extendText=SM_EXTEND[macro];
	if ( extendText ) then
		SuperMacroFrameExtendText:SetText(extendText);
	else
		SuperMacroFrameExtendText:SetText("");
	end
	if ( arg1=="RightButton" ) then
		RunMacro(this:GetID());
	end
end

function SuperMacroFrame_SelectMacro(id)
	SuperMacroFrame.selectedMacro = id;
end

function SuperMacroNewAccountButton_OnClick()
	SuperMacroFrame_SaveMacro();
	SuperMacroSaveExtend();
	oldextend=nil;
	SuperMacroPopupFrame.mode = "newaccount";
	SuperMacroPopupFrame:Show();
end

function SuperMacroNewCharacterButton_OnClick()
	SuperMacroFrame_SaveMacro();
	SuperMacroSaveExtend();
	oldextend=nil;
	SuperMacroPopupFrame.mode = "newcharacter";
	SuperMacroPopupFrame:Show();
end

function SuperMacroEditButton_OnClick()
	if ( SuperMacroFrame.extendChanged ) then
		SuperMacroSaveExtend();
	end
	-- erase old name extend
	oldextend=SuperMacroFrameExtendText:GetText();
	local oldmacro=SelectedMacroName();
	--SM_EXTEND[oldmacro]=nil;
	if ( not SameMacroName() ) then
		SuperMacroSaveExtend(oldmacro, 1); -- delete old extend
	end
	SuperMacroFrame_SaveMacro();
	SuperMacroPopupFrame.mode = "edit";
	SuperMacroPopupFrame:Show();
end

function SuperMacroFrame_HideDetails()
	SuperMacroEditButton:Hide();
	SuperMacroFrameCharLimitText:Hide();
	SuperMacroFrameText:Hide();
	SuperMacroFrameSelectedMacroName:Hide();
	SuperMacroFrameSelectedMacroBackground:Hide();
	SuperMacroFrameSelectedMacroButton:Hide();
end

function SuperMacroFrame_ShowDetails()
	SuperMacroEditButton:Show();
	SuperMacroFrameCharLimitText:Show();
	SuperMacroFrameEnterMacroText:Show();
	SuperMacroFrameText:Show();
	SuperMacroFrameSelectedMacroName:Show();
	SuperMacroFrameSelectedMacroBackground:Show();
	SuperMacroFrameSelectedMacroButton:Show();
end

function SuperMacroPopupFrame_OnShow()
	if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then
		SuperMacroFrameText:Hide();
		SuperMacroFrameSelectedMacroButtonIcon:SetTexture("");
		SuperMacroPopupFrame.selectedIcon = nil;
	end
	SuperMacroFrameText:ClearFocus();
	SuperMacroPopupEditBox:SetFocus();

	PlaySound("igCharacterInfoOpen");
	SuperMacroPopupFrame_Update();
	SuperMacroPopupOkayButton_Update();

	-- Disable Buttons
	SuperMacroEditButton:Disable();
	SuperMacroDeleteButton:Disable();
	SuperMacroNewAccountButton:Disable();
	SuperMacroNewCharacterButton:Disable();
end

function SuperMacroPopupFrame_OnHide()
	if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then
		SuperMacroFrameText:Show();
		SuperMacroFrameText:SetFocus();
	end
	
	-- Enable Buttons
	SuperMacroEditButton:Enable();
	SuperMacroDeleteButton:Enable();
	local numAccountMacros, numCharacterMacros = GetNumMacros();
	if ( numAccountMacros < MAX_MACROS ) then
		SuperMacroNewAccountButton:Enable();
	end
	if ( numCharacterMacros < MAX_MACROS ) then
		SuperMacroNewCharacterButton:Enable();
	end
end

function SuperMacroPopupFrame_Update()
	local numMacroIcons = GetNumMacroIcons();
	local macroPopupIcon, macroPopupButton;
	local macroPopupOffset = FauxScrollFrame_GetOffset( SuperMacroPopupScrollFrame );
	local index;
	
	-- Determine whether we're creating a new macro or editing an existing one
	if ( this.mode == "newaccount" or this.mode == "newcharacter" ) then
		SuperMacroPopupEditBox:SetText("");
	elseif ( this.mode == "edit" ) then
		local name, texture, body, isLocal = GetMacroInfo(SuperMacroFrame.selectedMacro);
		SuperMacroPopupEditBox:SetText(name);
	end
	
	-- Icon list
	for i=1, NUM_MACRO_ICONS_SHOWN do
		macroPopupIcon = getglobal("SuperMacroPopupButton"..i.."Icon");
		macroPopupButton = getglobal("SuperMacroPopupButton"..i);
		index = (macroPopupOffset * NUM_ICONS_PER_ROW) + i;
		if ( index <= numMacroIcons ) then
			macroPopupIcon:SetTexture(GetMacroIconInfo(index));
			macroPopupButton:Show();
		else
			macroPopupIcon:SetTexture("");
			macroPopupButton:Hide();
		end
		if ( index == SuperMacroPopupFrame.selectedIcon ) then
			macroPopupButton:SetChecked(1);
		else
			macroPopupButton:SetChecked(nil);
		end
	end
	
	-- Scrollbar stuff
	FauxScrollFrame_Update(SuperMacroPopupScrollFrame, ceil(numMacroIcons / NUM_ICONS_PER_ROW) , NUM_ICON_ROWS, MACRO_ICON_ROW_HEIGHT );
end

function SuperMacroPopupOkayButton_Update()
	if ( (strlen(SuperMacroPopupEditBox:GetText()) > 0) and SuperMacroPopupFrame.selectedIcon ) then
		SuperMacroPopupOkayButton:Enable();
	else
		SuperMacroPopupOkayButton:Disable();
	end
	if ( SuperMacroPopupFrame.mode == "edit" and (strlen(SuperMacroPopupEditBox:GetText()) > 0) ) then
		SuperMacroPopupOkayButton:Enable();
	end
end

function SuperMacroPopupButton_OnClick()
	SuperMacroPopupFrame.selectedIcon = this:GetID() + (FauxScrollFrame_GetOffset(SuperMacroPopupScrollFrame) * NUM_ICONS_PER_ROW);
	SuperMacroFrameSelectedMacroButtonIcon:SetTexture(GetMacroIconInfo(SuperMacroPopupFrame.selectedIcon));
	SuperMacroPopupOkayButton_Update();
	SuperMacroPopupFrame_Update();
end

function SuperMacroPopupOkayButton_OnClick()
	local index = 1;
	if ( SuperMacroPopupFrame.mode == "newaccount" ) then
		index = CreateMacro(SuperMacroPopupEditBox:GetText(), SuperMacroPopupFrame.selectedIcon, nil, nil, false );
	elseif ( SuperMacroPopupFrame.mode == "newcharacter" ) then
		index = CreateMacro(SuperMacroPopupEditBox:GetText(), SuperMacroPopupFrame.selectedIcon, nil, nil, true );
	elseif ( SuperMacroPopupFrame.mode == "edit" ) then
		index = EditMacro(SuperMacroFrame.selectedMacro, SuperMacroPopupEditBox:GetText(), SuperMacroPopupFrame.selectedIcon);
	end
	SuperMacroPopupFrame:Hide();

⌨️ 快捷键说明

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