📄 statusbars.lua
字号:
local t = UnitExists(vars.unit) and not UnitIsDeadOrGhost(vars.unit);
if t ~= vars._unitExists then
vars._unitExists = t;
vars.softEnable = t;
updateCommon(vars);
end
end
-- detect druid mana updates
local function updateDruid()
local c = druid:getCurrent();
local m = druid:getMax();
if c ~= druid.lastValue or m ~= druid.lastMax then
updateCommon(druid);
end
end
-- update druid mana visibility
local function updateDruidEnable()
local hasDBar = DruidBar_keepthemana ~= nil or DruidBarKey ~= nil;
local t = hasDBar and UnitPowerType('player') ~= 0 and UnitClass('player') == STATUSBARS_DRUID;
if t ~= druid._druidEnabled then
druid._druidEnabled = t;
druid.softEnable = t;
updateCommon(druid);
end
end
-- update buff icons
local function updateBuffs(vars, display)
local num = 0;
local live = not UnitIsDeadOrGhost(vars.unit);
for i = 1, MaxBuffs do
local buff;
if live then
buff = vars.buffFunc(vars.unit, i);
end
if buff then
num = num + 1;
end
if display then
if buff then
vars.textures[i]:Show();
vars.textures[i]:SetTexture(buff);
else
vars.textures[i]:Hide();
end
end
end
vars._numBuffs = num;
end
-- print option value
local function printOption(target, cmd)
local t = optionT(target, cmd);
if type(t) == 'boolean' then
if t == true then
t = 'on';
else
t = 'off';
end
end
consolePrint(target .. '.' .. cmd .. ' = ' .. t);
end
-- apply an option to a single target
local function applyOption(target, cmd, value, report)
local current = optionT(target, cmd);
if current == nil then
consolePrint(STATUSBARS_INVALID_TARGET .. target .. STATUSBARS_OR_OPTION .. cmd .. '".');
return false;
end
local t;
if value == 'print' then
printOption(target, cmd);
return;
elseif value == 'reset' then
setOptionT(target, cmd, nil);
printOption(target, cmd);
return;
elseif cmd == 'color' then
if compileColorRules(value) then
t = value;
else
return false;
end
elseif cmd == 'enable' then
if value == EnableAlways or value == EnableInCombat or value == EnableInCombatOnly
or value == EnableNondefault or value == EnableNever then
t = value;
end
elseif cmd == 'group' then
table.foreach(groupContainers,
function(name, val)
if string.lower(name) == value then
t = value;
end
end
);
elseif type(current) == 'number' then
if string.find(value, '^-?[0-9]+%.?[0-9]*$') then
t = tonumber(value);
end
elseif type(current) == 'boolean' then
if value == 'on' then
t = true;
elseif value == 'off' then
t = false;
end
else
t = value;
end
if t == nil then
if report then
consolePrint(STATUSBARS_INVALID_VALUE .. value .. STATUSBARS_FOR_OPTION .. cmd .. '".');
return false;
else
return;
end
end
setOptionT(target, cmd, t);
printOption(target, cmd);
end
-- slash command handler
-- needs improvement
local function slashHandler(command)
local i,j, target, cmd, value, name;
i,j, cmd, name = string.find(command, '^([a-z]+)[ ]+([^ ]+)$');
if command == 'lock' then
StatusBars_locked = true;
consolePrint(STATUSBARS_LOCKED);
return;
elseif command == 'unlock' then
StatusBars_locked = false;
consolePrint(STATUSBARS_UNLOCKED);
return;
elseif cmd == 'load' then
local t = StatusBars_Settings5[name];
if name == 'defaults' then
StatusBars_Settings5[playerName] = {};
consolePrint(STATUSBARS_DEFAULTS_LOADED);
updateAllSettings();
elseif t then
StatusBars_Settings5[playerName] = clone(t);
consolePrint(STATUSBARS_LOADED .. name .. '"');
updateAllSettings();
else
consolePrint(STATUSBARS_LOAD_NONEXISTANT .. name .. '"');
end
return;
elseif cmd == 'save' then
if name == 'defaults' then
consolePrint(STATUSBARS_NO_SAVEDEFAULTS);
else
StatusBars_Settings5[name] = clone(StatusBars_Settings5[playerName]);
consolePrint(STATUSBARS_SAVED .. name .. '"');
end
return;
end
i,j, target, cmd, value = string.find(command, '^([a-z]+)[ ]+([a-z]+)[ ]*(.*)$');
if value == '' and cmd ~= 'text' and cmd ~= 'ptext' then
value = nil;
end
if value == nil then
consolePrint(STATUSBARS_SYNTAX_LOCK);
consolePrint(STATUSBARS_SYNTAX_LOAD);
consolePrint(STATUSBARS_SYNTAX);
consolePrint(STATUSBARS_TARGETS);
consolePrint(' all, player, target, pet, power, tpower, ppower, ');
consolePrint(' health, mana, rage, energy, focus, combo, druid, buff, debuff, ');
consolePrint(' thealth, tmana, trage, tenergy, tfocus, tdebuff, tbuff, ');
consolePrint(' phealth, pmana, prage, penergy, pfocus, phappy, pbuff, pdebuff');
consolePrint(STATUSBARS_OPTIONS);
consolePrint(' alpha (decimal, default=' .. DefaultAlpha .. ')');
consolePrint(' enable (always/never/combat/combatonly/auto)');
consolePrint(' color, tcolor, pcolor (string, see Readme.html)');
consolePrint(' flash (on/off)');
consolePrint(' group (player/target/pet/group1/group2/...)');
consolePrint(' percentage (none/left/right, default=' .. DefaultPercentage .. ')');
consolePrint(' ptext (string, default=' .. DefaultPercentageText .. ', see Readme.html)');
consolePrint(' scale (decimal, default=1)');
consolePrint(' text (string, see Readme.html or print the current value)');
consolePrint(' warn (decimal, default=' .. DefaultWarnLimit .. ')');
elseif target == 'all' then
table.foreach(defaultSettings,
function(key, val)
return applyOption(key, cmd, value, false);
end
);
elseif target == 'power' then
applyOption('mana', cmd, value, true);
applyOption('rage', cmd, value, true);
applyOption('energy', cmd, value, true);
applyOption('focus', cmd, value, true);
elseif target == 'player' then
applyOption('health', cmd, value, true);
applyOption('mana', cmd, value, true);
applyOption('rage', cmd, value, true);
applyOption('energy', cmd, value, true);
applyOption('focus', cmd, value, true);
applyOption('combo', cmd, value, true);
applyOption('druid', cmd, value, true);
applyOption('buff', cmd, value, true);
applyOption('debuff', cmd, value, true);
elseif target == 'tpower' then
applyOption('tmana', cmd, value, true);
applyOption('trage', cmd, value, true);
applyOption('tenergy', cmd, value, true);
applyOption('tfocus', cmd, value, true);
elseif target == 'target' then
applyOption('thealth', cmd, value, true);
applyOption('tmana', cmd, value, true);
applyOption('trage', cmd, value, true);
applyOption('tenergy', cmd, value, true);
applyOption('tfocus', cmd, value, true);
applyOption('tbuff', cmd, value, true);
applyOption('tdebuff', cmd, value, true);
elseif target == 'ppower' then
applyOption('pmana', cmd, value, true);
applyOption('prage', cmd, value, true);
applyOption('penergy', cmd, value, true);
applyOption('pfocus', cmd, value, true);
elseif target == 'pet' then
applyOption('phealth', cmd, value, true);
applyOption('pmana', cmd, value, true);
applyOption('prage', cmd, value, true);
applyOption('penergy', cmd, value, true);
applyOption('pfocus', cmd, value, true);
applyOption('phappy', cmd, value, true);
applyOption('pbuff', cmd, value, true);
applyOption('pdebuff', cmd, value, true);
else
applyOption(target, cmd, value, true);
end
updateAllSettings();
end
-- returns a string representing the level of the unit
local function levelString(unit)
if UnitExists(unit) then
local l = UnitLevel(unit);
local s = tostring(l);
if l < 1 or l > 100 then
s = '??';
end
if UnitIsPlusMob(unit) then
s = s .. '+';
end
return s;
else
return '';
end
end
local function happinessString()
local value = happiness.lastValue;
if value > 0 then
return getglobal("PET_HAPPINESS" .. value);
else
return '';
end
end
-- default initialization for the bar information containers
local function init(this, vars, name)
-- events
this:RegisterEvent('PLAYER_ENTER_COMBAT');
this:RegisterEvent('PLAYER_LEAVE_COMBAT');
this:RegisterEvent('PLAYER_REGEN_ENABLED');
this:RegisterEvent('PLAYER_REGEN_DISABLED');
this:RegisterEvent('PLAYER_ALIVE');
this:RegisterEvent('VARIABLES_LOADED');
this:RegisterEvent('PLAYER_ENTERING_WORLD');
this:RegisterEvent('UNIT_CLASSIFICATION_CHANGED');
-- store ui elements
local barname = 'StatusBars_' .. name .. 'Bar';
vars.frame = getglobal(barname);
vars.bar = getglobal(barname .. '_Status');
vars.text = getglobal(barname .. '_Text');
vars.ptext = getglobal(barname .. '_PercentageText');
vars.foverlay = getglobal(barname .. '_FlashOverlay');
assert(vars.frame);
assert(vars.text);
assert(vars.ptext);
-- init display
vars.frame:SetAlpha(0);
vars.frame:Show();
-- store variables for use in callbacks
this._StatusBars_vars = vars;
-- visibility
vars.visible = false; -- current visibility, changes are delayed if fading
vars.targetVisibility = false;
vars.fading = false;
vars.softEnable = true; -- visibility override, causes fade transitions
-- value
vars.lastValue = 0; -- last property value
vars.lastMax = 0; -- last maximum property value
vars.lastFraction = 0.5; -- lastValue / lastMax
vars.default = 1; -- default fraction value of the property
-- health, mana, energy = 1
-- rage, combo = 0
-- combat
vars._inCombat = false; -- in combat, as reported by PLAYER_ENTER_COMBAT
vars._hasAggro = false; -- in hate list
-- color
vars.colorrules = { default = { 0, 0, 0, }, rules = {} };
function vars:getText(optionName)
local str = option(self, optionName);
if str == '' then
return '';
end
str = string.gsub(str, '&cur', tostring(self.lastValue));
str = string.gsub(str, '&max', tostring(self.lastMax));
str = string.gsub(str, '&%-cur', tostring(self.lastMax - self.lastValue));
str = string.gsub(str, '&frac', tostring(ceil(self.lastFraction*100)));
str = string.gsub(str, '&name', tostring(UnitName(self.unit)));
str = string.gsub(str, '&class', tostring(UnitClass(self.unit)));
str = string.gsub(str, '&type', tostring(UnitCreatureType(self.unit)));
str = string.gsub(str, '&rank', GetPVPRankInfo(UnitPVPRank(self.unit)) or '');
str = string.gsub(str, '&lvl', levelString(self.unit));
str = string.gsub(str, '&happy', happinessString());
return trim(str);
end
function vars:updateColor()
local c = getBarColor(self, '');
self.bar:SetStatusBarColor(c[1], c[2], c[3]);
updateTextColors(self);
end
if vars.foverlay then
function vars:updateFlashDisplay()
updateFlashDisplayCommon(self, self);
end
else
function vars:updateFlashDisplay() end
end
function vars:updateTickEnable()
if vars._flashing then
tickingBars[self] = true;
else
tickingBars[self] = nil;
end
end
function vars:updateFlash()
updateFlashCommon(self);
end
function vars:abortFlash()
abortFlashCommon(self);
end
-- behaviour
function vars:updateTextDisplays()
if self.text:IsVisible() then
self.text:SetText(self:getText('text'));
end
if self.ptext:IsVisible() then
self.ptext:SetText(self:getText('ptext'));
end
end
function vars:updateValueDisplay()
self:updateTextDisplays();
self.bar:SetValue(self.lastFraction);
self:updateColor();
end
function vars:onUpdate()
self:updateFlash();
end
vars:abortFlash();
end
-- init combo bar
function StatusBars_ComboBar2_OnLoad()
this:RegisterEvent('PLAYER_COMBO_POINTS');
this:RegisterEvent('UNIT_DISPLAYPOWER');
this:RegisterEvent('PLAYER_TARGET_CHANGED');
function combo:getCurrent()
if UnitIsDeadOrGhost('target') then
return 0;
else
return GetComboPoints('player');
end
end
function combo:getMax()
return 5;
end
combo._flashing = false;
init(this, combo, 'Combo');
combo.unit = 'player';
combo.default = 0;
combo.logical = 'combo';
combo._extraFlashEnd = 0;
combo.minibars = { n = 5 };
local i;
for i = 1, 5 do
local t = {};
local base = 'StatusBars_Combo_' .. i;
t.frame = getglobal(base);
t.bar = getglobal(base.. '_Status');
t.foverlay = getglobal(base .. '_Flash');
t.frame:SetBackdropColor(0, 0, 0, DefaultBGAlpha);
t._extraFlash = 0;
t._extraFlashEnd = 0;
combo.minibars[i] = t;
end
function combo:onEvent(event)
if combo.never then return; end
local v = combo:getCurrent();
if v > combo.lastValue and v > 0 then
combo._flashing = true;
local endtime = GetTime() + ComboFlashDuration;
combo._extraFlashEnd = endtime;
combo.minibars[v]._extraFlashEnd = endtime;
end
eventCommon(combo, event);
updateComboEnable();
updateCommon(combo);
combo:updateFlash();
end
function combo:updateValueDisplay()
self:updateTextDisplays();
local i;
for i = 1, 5 do
if combo.lastValue >= i then
combo.minibars[i].bar:SetValue(1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -