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

📄 statusbars.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 4 页
字号:
			else
				combo.minibars[i].bar:SetValue(0);
			end
		end
		combo:updateColor();
	end
	function combo:updateColor()
		local c = getBarColor(combo, '');
		local i;
		for i = 1, 5 do
			combo.minibars[i].bar:SetStatusBarColor(c[1], c[2], c[3]);
		end
		updateTextColors(combo);
	end
	function combo:updateFlashDisplay()
		local i;
		for i = 1, 5 do
			local bv = combo.minibars[i];
			updateFlashDisplayCommon(combo, bv);
		end
	end
	function combo:updateFlash()
		local t = GetTime();
		if t < combo._extraFlashEnd or combo._flashing or combo._extraFlashActive then
			combo._extraFlashActive = false;
			local i;
			for i = 1, 5 do
				local bv = combo.minibars[i];
				local et = bv._extraFlashEnd;
				local ef = 0;
				if t < et then
					local d = et - t;
					if d >= 0 and d <= ComboFlashDuration then
						ef = 1 - abs(d - ComboFlashDuration*0.5) / (ComboFlashDuration*0.5);
						combo._extraFlashActive = true;
					else
						bv._extraFlash = 0;
					end
				end
				bv._extraFlash = ef;
			end
			updateFlashCommon(combo, true);
		end
	end
	function combo:updateTickEnable()
		local t = GetTime();
		if t < combo._extraFlashEnd or combo._flashing or combo._extraFlashActive then
			tickingBars[combo] = true;
		else
			tickingBars[combo] = nil;
		end
	end
	function combo:abortFlash()
		local i;
		for i = 1, 5 do
			local bv = combo.minibars[i];
			bv._extraFlash = 0;
			bv._extraFlashEnd = 0;
		end
		abortFlashCommon(combo);
	end

	updateTextVisibility(combo);
	update(combo);
end
-- init druid mana bar
function StatusBars_DruidBar_OnLoad()
	this:RegisterEvent('UPDATE_SHAPESHIFT_FORMS');
	this:RegisterEvent('UNIT_DISPLAYPOWER');

	function druid:getCurrent()
		if DruidBarKey ~= nil then
			return round(DruidBarKey.keepthemana or 0);
		elseif DruidBar_keepthemana ~= nil then
			return round(DruidBar_keepthemana);
		else
			return 0;
		end
	end
	function druid:getMax()
		if DruidBarKey ~= nil then
			return round(DruidBarKey.maxmana or 0);
		elseif DruidBar_maxmana ~= nil then
			return round(DruidBar_maxmana);
		else
			return 0;
		end
	end

	init(this, druid, 'Druid');
	druid.logical = 'druid';
	druid.unit = 'player';

	function druid:onEvent(event)
		if druid.never then return; end
		eventCommon(druid, event);
		updateDruidEnable();
		updateCommon(druid);
	end
	function druid:onUpdate()
		updateDruid();
		druid:updateFlash();
	end
	function druid:updateTickEnable()
		if druid.softEnable then
			tickingBars[self] = true;
		else
			tickingBars[self] = nil;
		end
	end

	updateTextVisibility(druid);
	updateCommon(druid);
	update(druid);
end
-- init pet happiness bar
function StatusBars_HappinessBar_OnLoad()
	this:RegisterEvent('UNIT_HAPPINESS');
	this:RegisterEvent('PLAYER_PET_CHANGED');

	consolePrint('happy');

	function happiness:getCurrent()
		return GetPetHappiness() or 0;
	end
	function happiness:getMax()
		if GetPetHappiness() then
			return 3;
		else
			return 0;
		end
	end

	init(this, happiness, 'Happiness');
	happiness.logical = 'phappy';
	happiness.unit = 'pet';
	happiness.nospace = true;

	function happiness:onEvent(event)
		if happiness.never then return; end
		eventCommon(happiness, event);
		updateOtherUnitCommon(happiness);
		updateCommon(happiness);
	end

	updateTextVisibility(happiness);
	update(happiness);
end
-- init health bar
function initOtherUnitHealthBar(vars, name, logical, unit)
	this:RegisterEvent('UNIT_HEALTH');
	this:RegisterEvent('UNIT_MAXHEALTH');

	function vars:getCurrent()
		if UnitExists(unit) then
			return UnitHealth(unit);
		else
			return 0;
		end
	end
	function vars:getMax()
		if UnitExists(unit) then
			return UnitHealthMax(unit);
		else
			return 0;
		end
	end

	init(this, vars, name);
	vars.logical = logical;
	vars.unit = unit;

	function vars:onEvent(event)
		if vars.never then return; end
		eventCommon(vars, event);
		updateOtherUnitCommon(vars);
		updateCommon(vars);
	end

	updateTextVisibility(vars);
	update(vars);
end

-- init power bar
function initOtherUnitPowerBar(vars, name, unit, prefix)
	this:RegisterEvent('UNIT_ENERGY');
	this:RegisterEvent('UNIT_MAXENERGY');
	this:RegisterEvent('UNIT_MANA');
	this:RegisterEvent('UNIT_MAXMANA');
	this:RegisterEvent('UNIT_RAGE');
	this:RegisterEvent('UNIT_MAXRAGE');
	this:RegisterEvent('UNIT_DISPLAYPOWER');

	function vars:getCurrent()
		if UnitExists(unit) then
			return UnitMana(unit);
		else
			return 0;
		end
	end
	function vars:getMax()
		if UnitExists(unit) then
			return UnitManaMax(unit);
		else
			return 0;
		end
	end

	init(this, vars, name);
	vars.unit = unit;
	vars.prefix = prefix;

	function vars:onEvent(event)
		if vars.never then return; end
		eventCommon(self, event);
		updatePowerType(self, unit, self.prefix);
		updateOtherUnitCommon(self);
		if UnitManaMax(self.unit) < 1 then
			self.softEnable = false;
		end
		updateCommon(self);
	end

	update(vars);
	updateTextVisibility(vars);
end

-- init buff bar
function initOtherUnitBuffBar(vars, name, logical, unit)
	this:RegisterEvent('UNIT_AURA');

	function vars:getCurrent()
		return vars._numBuffs;
	end
	function vars:getMax()
		return MaxBuffs;
	end

	vars._numBuffs = 0;
	init(this, vars, name);
	vars.default = 0;
	vars.logical = logical;
	vars.unit = unit;

	vars.textures = {};
	local i;
	local base = 'StatusBars_' .. name .. '_Texture';
	for i = 1, MaxBuffs do
		local t = getglobal(base .. i);
		assert(t);
		vars.textures[i] = t;
	end

	-- behaviour
	function vars:updateFlash()
	end
	function vars:abortFlash()
	end
	function vars:updateValueDisplay()
		self:updateTextDisplays();
		updateBuffs(self, true);
	end
	function vars:onEvent(event)
		if vars.never then return; end
		if event == 'UNIT_AURA' and arg1 == self.unit then
			updateBuffs(self, false);
		elseif event == 'PLAYER_TARGET_CHANGED' and 'target' == self.unit then
			updateBuffs(self, false);
		end
		eventCommon(self, event);
		updateOtherUnitCommon(self);
		updateCommon(self);
	end
	function vars:updateColor()
	end

	updateBuffs(vars, true);
	update(vars);
end

-- health bars
function StatusBars_HealthBar_OnLoad()
	SlashCmdList['STATUSBARS'] = slashHandler;
	SLASH_STATUSBARS1 = '/statusbars';

	initOtherUnitHealthBar(health, 'Health', 'health', 'player');
end
function StatusBars_TargetHealthBar_OnLoad()
	this:RegisterEvent('PLAYER_TARGET_CHANGED');
	initOtherUnitHealthBar(targetHealth, 'TargetHealth', 'thealth', 'target');

	function getHPP()
		local m = UnitHealthMax('target');
		if m ~= 100 or MobHealthDB == nil then
			return;
		end
		local index = UnitName('target') .. ':' .. UnitLevel('target');
		local t = MobHealthDB[index];
		if t == nil then
			return;
		end
		local pts, pct;
		if type(t) == 'table' then
			pts = t.damPts or 0;
			pct = t.damPct or 0;
		else
			local i,j;
			i,j, pts, pct = string.find(t, "^(%d+)/(%d+)$");
			pct = tonumber(pct);
		end
		if pct ~= 0 then
			return pts / tonumber(pct);
		end
	end

	if MobHealthFrame ~= nil then
		consolePrint('MobHealth detected');
		function targetHealth:getCurrent()
			if UnitExists('target') then
				local v = UnitHealth('target');
				local hpp = getHPP();
				if hpp then
					return round(hpp * v);
				else
					return v;
				end
			else
				return 0;
			end
		end
		function targetHealth:getMax()
			if UnitExists('target') then
				local v = UnitHealthMax('target');
				local hpp = getHPP();
				if hpp then
					return round(hpp * v);
				else
					return v;
				end
			else
				return 0;
			end
		end
	end
end
function StatusBars_PetHealthBar_OnLoad()
	this:RegisterEvent('PLAYER_PET_CHANGED');
	this:RegisterEvent('UNIT_HAPPINESS');
	initOtherUnitHealthBar(petHealth, 'PetHealth', 'phealth', 'pet');
end

-- power bars
function StatusBars_PowerBar_OnLoad()
	initOtherUnitPowerBar(power, 'Power', 'player', '');
end
function StatusBars_TargetPowerBar_OnLoad()
	this:RegisterEvent('PLAYER_TARGET_CHANGED');
	initOtherUnitPowerBar(targetPower, 'TargetPower', 'target', 't');
end
function StatusBars_PetPowerBar_OnLoad()
	this:RegisterEvent('PLAYER_PET_CHANGED');
	this:RegisterEvent('UNIT_HAPPINESS');
	initOtherUnitPowerBar(petPower, 'PetPower', 'pet', 'p');
end

-- buff bars
function StatusBars_BuffBar_OnLoad()
	buff.buffFunc = UnitBuff;
	initOtherUnitBuffBar(buff, 'Buff', 'buff', 'player');
end
function StatusBars_DebuffBar_OnLoad()
	debuff.buffFunc = UnitDebuff;
	initOtherUnitBuffBar(debuff, 'Debuff', 'debuff', 'player');
end
function StatusBars_TargetBuffBar_OnLoad()
	this:RegisterEvent('PLAYER_TARGET_CHANGED');
	targetBuff.buffFunc = UnitBuff;
	initOtherUnitBuffBar(targetBuff, 'TargetBuff', 'tbuff', 'target');
end
function StatusBars_TargetDebuffBar_OnLoad()
	this:RegisterEvent('PLAYER_TARGET_CHANGED');
	targetDebuff.buffFunc = UnitDebuff;
	initOtherUnitBuffBar(targetDebuff, 'TargetDebuff', 'tdebuff', 'target');
end
function StatusBars_PetBuffBar_OnLoad()
	petBuff.buffFunc = UnitBuff;
	initOtherUnitBuffBar(petBuff, 'PetBuff', 'pbuff', 'pet');
end
function StatusBars_PetDebuffBar_OnLoad()
	petDebuff.buffFunc = UnitDebuff;
	initOtherUnitBuffBar(petDebuff, 'PetDebuff', 'pdebuff', 'pet');
end

local shiftIsDown = false;
function StatusBars_GlobalUpdate()
	if load_time > 0 and GetTime() > load_time then
		load_time = 0;
		fully_initialized = true;

		-- replace initialization stub functions with live versions
		update = update_real;
		updateCommon = updateCommon_real;
		eventCommon = eventCommon_real;
		StatusBars_GlobalUpdate = StatusBars_GlobalUpdate_real;

		consolePrint(STATUSBARS_LOADED .. playerName .. '"');

		updateAllSettings();
	end
end
function StatusBars_GlobalUpdate_real()
	local sd = IsShiftKeyDown() and not StatusBars_locked;
	if sd ~= shiftIsDown then
		shiftIsDown = sd;

		if sd then sd = 1 else sd = 0 end;
		table.foreach(groupContainers,
			function(name, t)
				local frame = getglobal('StatusBars_' .. name .. 'Container')
				frame:EnableMouse(sd);
				if not shiftIsDown then
					frame:StopMovingOrSizing();
				end
			end
		);
		if not shiftIsDown then
			StatusBars_moving = nil;
		end
	end
	table.foreach(tickingBars,
		function(vars, t)
			vars:onUpdate();
		end
	);
end

⌨️ 快捷键说明

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