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

📄 applebarfuntion.lua

📁 时间太紧了
💻 LUA
字号:
currenttime = nil;
inited = nil;


function AppleButton_UpdateState(button)
	if(not button) then
		button = this;
	end
	if ( IsCurrentAction(AppleButton_GetPagedID(button)) or IsAutoRepeatAction(AppleButton_GetPagedID(button)) ) then
		button:SetChecked(1);
	else
		button:SetChecked(0);
	end
	if( AppleBarSaved ) then
		if(AppleBarSaved[button:GetName()]["hide"]) then
			button:Hide();
		elseif(button.showgrid == 0 and HasAction(AppleButton_GetPagedID(button))) then
			button:Show();
		end
	else
		button:Hide();
	end
end

function AppleBarButton_SetTooltip(button)
	if ( GetCVar("UberTooltips") == "1" ) then
		GameTooltip_SetDefaultAnchor(GameTooltip, this);
	else
		if ( this:GetParent() == MultiBarBottomRight or this:GetParent() == MultiBarRight or this:GetParent() == MultiBarLeft ) then
			GameTooltip:SetOwner(this, "ANCHOR_LEFT");
		else
			GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
		end
		
	end
	
	if ( GameTooltip:SetAction(AppleButton_GetPagedID(this)) ) then
		this.updateTooltip = TOOLTIP_UPDATE_TIME;
	else
		this.updateTooltip = nil;
	end
end


function AppleBarButton_OnUpdate(elapsed)
	local isUsable, notEnoughMana = IsUsableAction(AppleButton_GetPagedID(this));
	if(not isUsable) then
		return;
	end
-- Blizzard code
	if ( AppleButton_IsFlashing() ) then
		this.flashtime = this.flashtime - elapsed;
		if ( this.flashtime <= 0 ) then
			local overtime = -this.flashtime;
			if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
				overtime = 0;
			end
			this.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime;

			local flashTexture = getglobal(this:GetName().."Flash");
			if ( flashTexture:IsVisible() ) then
				flashTexture:Hide();
			else
				flashTexture:Show();
			end
		end
	end
	
	-- Handle range indicator
	if ( this.rangeTimer ) then
		if ( this.rangeTimer < 0 ) then
			local count = getglobal(this:GetName().."HotKey");
			local texture = getglobal(this:GetName().."Icon");
			if ( IsActionInRange( AppleButton_GetPagedID(this)) == 0 ) then
				count:SetVertexColor(1.0, 0.1, 0.1);
				texture:SetVertexColor(0.9, 0.6, 0.6);

			else
				count:SetVertexColor(0.6, 0.6, 0.6);
				texture:SetVertexColor(1, 1, 1);
			end
			this.rangeTimer = TOOLTIP_UPDATE_TIME;
		else
			this.rangeTimer = this.rangeTimer - elapsed;
		end
	end

	if ( not this.updateTooltip ) then
		return;
	end

	this.updateTooltip = this.updateTooltip - elapsed;
	if ( this.updateTooltip > 0 ) then
		return;
	end

	if ( GameTooltip:IsOwned(this) ) then
		AppleBarButton_SetTooltip();
	else
		this.updateTooltip = nil;
	end
end


function AppleBarButton_OnLoad()
	this:RegisterEvent("VARIABLES_LOADED");
	this.showgrid = 0;
	this.flashing = 0;
	this.flashtime = 0;
	AppleBarButton_Update();
	this:RegisterForDrag("LeftButton", "RightButton");
	this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("UPDATE_BONUS_ACTIONBAR");
	this:RegisterEvent("ACTIONBAR_SHOWGRID");
	this:RegisterEvent("ACTIONBAR_HIDEGRID");
	this:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
	this:RegisterEvent("ACTIONBAR_SLOT_CHANGED");
	this:RegisterEvent("UPDATE_BINDINGS");
	AppleButton_UpdateHotkeys();
end

function AppleBarButton_Update(button)
	-- Special case code for bonus bar buttons
	-- Prevents the button from updating if the bonusbar is still in an animation transition
	if(not button) then
		button = this;
	end
	if ( this.isBonus and this.inTransition ) then
		AppleButton_UpdateUsable();
		AppleButton_UpdateCooldown();
		return;
	end
	
	local icon = getglobal(button:GetName().."Icon");
	local buttonCooldown = getglobal(button:GetName().."Cooldown");
	local texture = GetActionTexture(AppleButton_GetPagedID(button));
	if ( texture ) then
		icon:SetTexture(texture);
		icon:Show();
		button.rangeTimer = -1;
		button:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
		-- Save texture if the button is a bonus button, will be needed later
		if ( button.isBonus ) then
			button.texture = texture;
		end
	else
		icon:Hide();
		buttonCooldown:Hide();
		button.rangeTimer = nil;
		button:SetNormalTexture("Interface\\Buttons\\UI-Quickslot");
		getglobal(button:GetName().."HotKey"):SetVertexColor(0.6, 0.6, 0.6);
		getglobal(button:GetName().."NormalTexture"):SetVertexColor(1.0, 1.0, 1.0, 0.5);
	end
	if( AppleBarSaved) then
		if(AppleBarSaved["number"]) then
			AppleBar_UpdateCount(button);
		end
	end
	if ( HasAction(AppleButton_GetPagedID(button)) ) then
		button:RegisterEvent("ACTIONBAR_UPDATE_STATE");
		button:RegisterEvent("ACTIONBAR_UPDATE_USABLE");
		button:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN");
		button:RegisterEvent("UPDATE_INVENTORY_ALERTS");
		button:RegisterEvent("PLAYER_AURAS_CHANGED");
		button:RegisterEvent("PLAYER_TARGET_CHANGED");
		button:RegisterEvent("UNIT_INVENTORY_CHANGED");
		button:RegisterEvent("CRAFT_SHOW");
		button:RegisterEvent("CRAFT_CLOSE");
		button:RegisterEvent("TRADE_SKILL_SHOW");
		button:RegisterEvent("TRADE_SKILL_CLOSE");
		button:RegisterEvent("PLAYER_ENTER_COMBAT");
		button:RegisterEvent("PLAYER_LEAVE_COMBAT");
		button:RegisterEvent("START_AUTOREPEAT_SPELL");
		button:RegisterEvent("STOP_AUTOREPEAT_SPELL");
		--button:Show();
		AppleButton_UpdateState(button);
		AppleButton_UpdateUsable(button);
		AppleButton_UpdateCooldown(button);
		AppleButton_UpdateFlash(button);
	else
		button:UnregisterEvent("ACTIONBAR_UPDATE_STATE");
		button:UnregisterEvent("ACTIONBAR_UPDATE_USABLE");
		button:UnregisterEvent("ACTIONBAR_UPDATE_COOLDOWN");
		button:UnregisterEvent("UPDATE_INVENTORY_ALERTS");
		button:UnregisterEvent("PLAYER_AURAS_CHANGED");
		button:UnregisterEvent("PLAYER_TARGET_CHANGED");
		button:UnregisterEvent("UNIT_INVENTORY_CHANGED");
		button:UnregisterEvent("CRAFT_SHOW");
		button:UnregisterEvent("CRAFT_CLOSE");
		button:UnregisterEvent("TRADE_SKILL_SHOW");
		button:UnregisterEvent("TRADE_SKILL_CLOSE");
		button:UnregisterEvent("PLAYER_ENTER_COMBAT");
		button:UnregisterEvent("PLAYER_LEAVE_COMBAT");
		button:UnregisterEvent("START_AUTOREPEAT_SPELL");
		button:UnregisterEvent("STOP_AUTOREPEAT_SPELL");

		if ( button.showgrid == 0 ) then
			button:Hide();
		else
			buttonCooldown:Hide();
		end
	end

	-- Add a green border if button is an equipped item
	local border = getglobal(button:GetName().."Border");
	if ( IsEquippedAction(AppleButton_GetPagedID(button)) ) then
		border:SetVertexColor(0, 1.0, 0, 0.35);
		border:Show();
	else
		border:Hide();
	end

	if ( GameTooltip:IsOwned(button) ) then
		AppleBarButton_SetTooltip();
	else
		button.updateTooltip = nil;
	end

	-- Update Macro Text
	local macroName = getglobal(button:GetName().."Name");
	macroName:SetText(GetActionText(AppleButton_GetPagedID(button)));
end

function AppleButton_UpdateCooldown(button)
	if(not button) then
		button = this;
	end
	local cooldown = getglobal(button:GetName().."Cooldown");
	local start, duration, enable = GetActionCooldown(AppleButton_GetPagedID(button));
	CooldownFrame_SetTimer(cooldown, start, duration, enable);
end


function AppleButton_GetPagedID(button)
	if( button == nil ) then
		message("非法按钮");
		return 0;
	end
	-- this doesnt seem to work with stances
	--if (CURRENT_ACTIONBAR_PAGE == NUM_ACTIONBAR_PAGES) then
	--	return (button:GetId());
	--end
	
--	local actualPage = math.mod(CURRENT_ACTIONBAR_PAGE-1,NUM_ACTIONBAR_PAGES) +1;
	
	-- had to change this to handle different page bys
--	return (button:GetID() + ((actualPage - 1) * NUM_ACTIONBAR_BUTTONS) + 12);

	return button:GetID();
end

function AppleButton_UpdateUsable(button)
	if( not button) then
		button = this;
	end
	local icon = getglobal(button:GetName().."Icon");
	local normalTexture = getglobal(button:GetName().."NormalTexture");
	local isUsable, notEnoughMana = IsUsableAction(AppleButton_GetPagedID(button));
	if ( isUsable ) then
		icon:SetVertexColor(1.0, 1.0, 1.0);
		normalTexture:SetVertexColor(1.0, 1.0, 1.0);
	elseif ( notEnoughMana ) then
		icon:SetVertexColor(0.5, 0.5, 1.0);
		normalTexture:SetVertexColor(0.5, 0.5, 1.0);
	else
		icon:SetVertexColor(0.4, 0.4, 0.4);
		normalTexture:SetVertexColor(1.0, 1.0, 1.0);
	end
end
function AppleButton_UpdateFlash(button)
	if(not button) then
		button = this;
	end
	local pagedID = AppleButton_GetPagedID(button);
	if ( (IsAttackAction(pagedID) and IsCurrentAction(pagedID)) or IsAutoRepeatAction(pagedID) ) then
		AppleButton_StartFlash(button);
	else
		AppleButton_StopFlash(button);
	end
end

function AppleButton_StartFlash(button)
	if( not button ) then
		button = this;
	end
	button.flashing = 1;
	button.flashtime = 0;
	AppleButton_UpdateState(button);
end

function AppleButton_StopFlash(button)
	if( not button ) then
		button = this;
	end
	button.flashing = 0;
	getglobal(button:GetName().."Flash"):Hide();
	AppleButton_UpdateState(button);
end

function AppleButton_IsFlashing()
	if ( this.flashing == 1 ) then
		return 1;
	else
		return nil;
	end
end


function AppleButton_UpdateHotkeys()
	local hotkey = getglobal(this:GetName().."HotKey");
	local action = this:GetName();
	local text = GetBindingText(GetBindingKey(action), "KEY_");
	if( text ) then
		text = string.gsub(text, "CTRL--", "C-");
		text = string.gsub(text, "ALT--", "A-");
		text = string.gsub(text, "SHIFT--", "S-");
		text = string.gsub(text, "NUM PAD", "NP");
		text = string.gsub(text, "BACKSPACE", "Bksp");
		text = string.gsub(text, "SPACEBAR", "Space");
		text = string.gsub(text, "PAGE", "Pg");
		text = string.gsub(text, "DOWN", "Dn");
		text = string.gsub(text, "ARROW", "");
		text = string.gsub(text, "INSERT", "Ins");
		text = string.gsub(text, "DELETE", "Del");
	else
		text = "";
	end
	hotkey:SetText(text);
end


function AppleBarButton_OnEvent(event)
	if(event == "VARIABLES_LOADED") then			
		if( not Inited) then
			currenttime = GetTime();
			AppleBarOnUpdate:Show();
			Inited = 1;
			return;
		end
	end
	if ( event == "ACTIONBAR_SLOT_CHANGED" ) then
		if ( arg1 == -1 or arg1 == AppleButton_GetPagedID(this) ) then
			AppleBarButton_Update();
		end
		return;
	end
	if ( event == "PLAYER_ENTERING_WORLD" or event == "ACTIONBAR_PAGE_CHANGED"  ) then
		AppleBarButton_Update();
		return;
	end
	if ( event == "UPDATE_BONUS_ACTIONBAR" ) then
		if ( this.isBonus ) then
			AppleButton_Update();
		end
		return;
	end
	if ( event == "ACTIONBAR_SHOWGRID" ) then
		AppleButton_ShowGrid();
		return;
	end
	if ( event == "ACTIONBAR_HIDEGRID" ) then
		AppleButton_HideGrid();
		return;
	end
	if ( event == "UPDATE_BINDINGS" ) then
		AppleButton_UpdateHotkeys();
		return;
	end

	-- All event handlers below this line are only set when the button has an action

	if ( event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_AURAS_CHANGED" ) then
		AppleButton_UpdateUsable();
	elseif ( event == "UNIT_INVENTORY_CHANGED" ) then
		if ( arg1 == "player" ) then
			AppleBarButton_Update();
		end
	elseif ( event == "ACTIONBAR_UPDATE_STATE" ) then
		AppleButton_UpdateState();
	elseif ( event == "ACTIONBAR_UPDATE_USABLE" or event == "UPDATE_INVENTORY_ALERTS" or event == "ACTIONBAR_UPDATE_COOLDOWN" ) then
		AppleButton_UpdateUsable();
		AppleButton_UpdateCooldown();
	elseif ( event == "CRAFT_SHOW" or event == "CRAFT_CLOSE" or event == "TRADE_SKILL_SHOW" or event == "TRADE_SKILL_CLOSE" ) then
		AppleButton_UpdateState();
	elseif ( event == "PLAYER_ENTER_COMBAT" ) then
		if ( IsAttackAction(AppleButton_GetPagedID(this)) ) then
			AppleButton_StartFlash();
		end
	elseif ( event == "PLAYER_LEAVE_COMBAT" ) then
		if ( IsAttackAction(AppleButton_GetPagedID(this)) ) then
			AppleButton_StopFlash();
		end
	elseif ( event == "START_AUTOREPEAT_SPELL" ) then
		if ( IsAutoRepeatAction(AppleButton_GetPagedID(this)) ) then
			AppleButton_StartFlash();
		end
	elseif ( event == "STOP_AUTOREPEAT_SPELL" ) then
		if ( AppleButton_IsFlashing() and not IsAttackAction(AppleButton_GetPagedID(this)) ) then
			AppleButton_StopFlash();
		end
	end
end





function AppleButton_ShowGrid(button)
	--if( AppleBarSaved["showgrid"]==1 ) then
	--	return;
	--end
	if ( not button ) then
		button = this;
	end	
	button.showgrid = button.showgrid+1;
	if( AppleBarSaved[button:GetName()]["hide"]==1 ) then
		return;
	end
	getglobal(button:GetName().."NormalTexture"):SetVertexColor(1.0, 1.0, 1.0, 0.5);	
	button:Show();
end

function AppleButton_HideGrid(button)	
	--if( AppleBarSaved["showgrid"]==1 ) then
	--	return;
	--end
	if ( not button ) then
		button = this;
	end	
	button.showgrid = button.showgrid-1;
	if ( button.showgrid == 0 and not HasAction(AppleButton_GetPagedID(button)) ) then
		if( AppleBarSaved["showgrid"]==0 ) then
			button:Hide();
		end
	end
end


function AppleButtonDown(id)
	local button = getglobal("AppleBarButton"..id);
	if ( button:GetButtonState() == "NORMAL" ) then
		button:SetButtonState("PUSHED");
	end
end

function AppleButtonUp(id, onSelf)
	local button = getglobal("AppleBarButton"..id);
	if ( button:GetButtonState() == "PUSHED" ) then
		button:SetButtonState("NORMAL");
		if ( MacroFrame_SaveMacro ) then
			MacroFrame_SaveMacro();
		end
		UseAction(AppleButton_GetPagedID(button), 0, onSelf);
		if ( IsCurrentAction(AppleButton_GetPagedID(button)) ) then
			button:SetChecked(1);
		else
			button:SetChecked(0);
		end
	end
end


function AppleBar_UpdateCount(button)
	if(not button) then
		button = this;
	end
	local text = getglobal(button:GetName().."Count");
	if ( IsConsumableAction(AppleButton_GetPagedID(button)) ) then
		text:SetText(GetActionCount(AppleButton_GetPagedID(button)));
	else
		text:SetText("");
	end
end



⌨️ 快捷键说明

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