📄 damagemeters.lua
字号:
DamageMeters_waitingForChainHeal = false;
end
------------------
if (DM_Bypass["Update All"] == true) then
return;
end
-- Update quant cycling.
if (DamageMeters_flags[DMFLAG_cycleVisibleQuantity]) then
if (DamageMeters_textState < 1) then
if (GetTime() - DamageMeters_currentQuantStartTime > DamageMeters_QUANTITYSHOWDURATION) then
DamageMeters_CycleQuant(false, DamageMeters_flags[DMFLAG_applyFilterToAutoCycle]);
DamageMeters_textStateStartTime = GetTime();
updateBars = true;
end
end
end
-- Update visibility.
DamageMeters_UpdateVisibility();
-- Update count.
DamageMeters_UpdateCount();
-- Generate the frame if needed.
local forceSort = false;
if (DamageMeters_frameNeedsToBeGenerated) then
DamageMetersFrame_GenerateFrame();
DamageMeters_tablesDirty = true;
updateBars = true;
forceSort = true;
end
-- Update Background
-- Determine if we are still in combat.
local updateBackground = false;
if (DamageMeters_inCombat) then
if (DamageMeters_IsQuantityPS(DamageMeters_quantity)) then
updateBackground = true;
end
-- If the player isn't in combat and we haven't received any messages
-- in a while, automatically end combat.
if (not DamageMeters_playerInCombat and
DamageMeters_combatEndTime - DamageMeters_lastEventTime > DM_COMBAT_TIMEOUT_SECONDS) then
--DMPrintD("Stopping combat due to inactivity.");
DamageMeters_OnCombatEnd();
end
end
if (DM_Pause_Not ~= DamageMeters_pauseState) then
updateBackground = true;
end
if (updateBackground) then
DamageMeters_SetBackgroundColor();
end
-- Start delayed Sync.
if (DamageMeters_syncStartTime > 0) then
if (currentTime > DamageMeters_syncStartTime) then
DamageMeters_DoSync();
DamageMeters_syncStartTime = -1;
end
end
-- Update text state.
if (DamageMeters_textState > 0) then
local now = GetTime();
if (now - DamageMeters_textStateStartTime > DamageMeters_TEXTSTATEDURATION) then
local lastState = DamageMeters_textState;
repeat
DamageMeters_textState = DamageMeters_textState + 1;
if (DamageMeters_textState > DamageMeters_Text_MAX) then
DamageMeters_textState = 1;
if (DamageMeters_flags[DMFLAG_cycleVisibleQuantity]) then
DamageMeters_CycleQuant(false, DamageMeters_flags[DMFLAG_applyFilterToAutoCycle]);
end
end
-- This is a safety to keep us from looping forever.
if (DamageMeters_textState == lastState) then
-- Unnecessary, just break. Stay with the last state.
--DMPrintD("DamageMeters_textState infinite loop protection activated.");
--DamageMeters_textOptions[DamageMeters_Text_NAME] = true;
--DamageMeters_textState = DamageMeters_Text_NAME;
break;
end
until (DamageMeters_textOptions[DamageMeters_textState])
DamageMeters_textStateStartTime = now;
updateBars = true;
end
end
DamageMeters_StopDebugTimer(DMPROF_UPDATE);
----------------------------------
local bSecondHasPassedSinceLastBarUpdate = (currentTime - DamageMeters_lastBarUpdateTime > 1.0);
-- NOTE: DamageMeters_lastBarUpdateTime also means "last sort time". When the hidden frame
-- takes over sorting duties when we are hidden it uses that variable, even though no bars are
-- actually sorted.
if (DamageMeters_flags[DMFLAG_constantVisualUpdate] or bSecondHasPassedSinceLastBarUpdate) then
updateBars = true;
DamageMeters_lastBarUpdateTime = currentTime;
end
-- Sort the table.
if (forceSort or (DamageMeters_tablesDirty and (DamageMeters_flags[DMFLAG_constantVisualUpdate] or updateBars))) then
DamageMeters_UpdateTables();
end
----------------------------------
-- Code which calculates and uses totals.
-- Must come after Sorting, as some quantity's values are calculated from totals.
-- Calculate totals. These are used by tooltips and reports, and should be
-- calculated every update.
local quantIndex;
local totalValue = 0;
local maxUnitIndex = 0;
local maxUnitValue = 0;
local playerValue = 0;
local playerIndex = DamageMeters_GetPlayerIndex(UnitName("player"));
for quantIndex = 1, DMI_MAX do
DamageMeters_totals[quantIndex] = 0;
end
local dmi = DamageMeters_GetQuantityDMI(DamageMeters_quantity);
local index, playerStruct;
for index, playerStruct in DamageMeters_tables[DMT_VISIBLE] do
local unitValue = DamageMeters_GetQuantityValue(DamageMeters_quantity, DMT_VISIBLE, index);
if (playerIndex == index) then
playerValue = unitValue;
end
if (unitValue > maxUnitValue) then
maxUnitIndex = index;
maxUnitValue = unitValue;
end
totalValue = totalValue + unitValue;
for dmiIndex = 1, DMI_MAX do
DamageMeters_totals[dmiIndex] = DamageMeters_totals[dmiIndex] + playerStruct.dmiData[dmiIndex].q;
end
end
-- Total Button
if (DamageMeters_flags[DMFLAG_showTotal]) then
if (DamageMeters_quantity == DamageMeters_Quantity_TIME) then
DamageMeters_TotalButtonText:SetText("-");
elseif (DamageMeters_IsQuantityPS(DamageMeters_quantity)) then
DamageMeters_TotalButtonText:SetText(string.format("T=%.1f", totalValue));
else
DamageMeters_TotalButtonText:SetText(string.format("T=%d", totalValue));
end
end
-- Tooltip
if (DamageMetersTooltip:IsOwned(this)) then
DamageMeters_SetTooltipText();
end
----------------------------------
if (DM_Bypass["Update Bars"] == true) then
return;
end
-- Bar updating.
if (updateBars) then
--DMPrintD(string.format("Updating bars. %.3f", currentTime - DamageMeters_lastBarUpdateTime), nil, true);
DamageMeters_StartDebugTimer(DMPROF_BARS);
-- Initialize and clear the bars.
local i;
for i = 1,DamageMeters_barCount do
DamageMeters_bars[i]:SetMinMaxValues(0, maxUnitValue);
DamageMeters_bars[i]:SetValue(0);
DamageMeters_text[i]:SetText("");
end
-- Table index of first bar.
DamageMeters_barStartIndex = 1;
local playerIndex = DamageMeters_GetPlayerIndex(UnitName("Player"), DMT_VISIBLE);
if (DMVIEW_MIN == DamageMeters_viewMode) then
if (not playerIndex) then
if (DMVIEW_MIN == DamageMeters_viewMode) then
-- If we are in miniMode we need the player to be in the table:
-- add her by giving her some dummy data.
DamageMeters_AddValue(UnitName("Player"), 0, DM_DOT, DamageMeters_Relation_SELF, DamageMeters_Quantity_HEALINGRECEIVED, nil);
playerIndex = DamageMeters_GetPlayerIndex(UnitName("Player"), DMT_VISIBLE);
if (not playerIndex) then
-- Could fail if the table was full.
playerIndex = 1;
end
else
playerIndex = 1;
end
end
DamageMeters_barStartIndex = playerIndex;
if (DamageMeters_lastPlayerPosition ~= DamageMeters_barStartIndex) then
DMPrintD("Frame dirty: Player index changed..");
DamageMeters_frameNeedsToBeGenerated = true;
end
elseif (DMVIEW_MAX ~= DamageMeters_viewMode and DamageMeters_flags[DMFLAG_playerAlwaysVisible] and (playerIndex ~= nil) and DamageMeters_barCount) then
-- /script DMPrint(DamageMeters_flags[DMFLAG_playerAlwaysVisible] and "true" or "false");
--DMPrint("yes", nil, true);
local nonPlayerBars = DamageMeters_barCount - 1; -- 0
local top = ceil(nonPlayerBars / 2); -- 0
local first = playerIndex - top; -- 2
local last = playerIndex + (nonPlayerBars - top); -- 2
local totalBars = table.getn(DamageMeters_tables[DMT_VISIBLE]); -- 2
if (last > totalBars) then
first = totalBars - DamageMeters_barCount + 1;
end
if (first < 1) then
first = 1;
end
DamageMeters_barStartIndex = first;
end
DamageMeters_lastPlayerPosition = playerIndex;
--DMPrintD(string.format("setting bars %d to %d", DamageMeters_barStartIndex, table.getn(DamageMeters_tables[DMT_VISIBLE])));
-- Set bar info.
local barIndex = 1;
local struct;
for i,struct in DamageMeters_tables[DMT_VISIBLE] do
if (i >= DamageMeters_barStartIndex) then
if (barIndex <= DamageMeters_barCount) then
-- Wonky special case for health.
if (DamageMeters_Quantity_HEALTH == DamageMeters_quantity) then
DamageMeters_bars[i]:SetMinMaxValues(0, struct.maxHealth);
end
DamageMetersFrame_SetBarInfo(barIndex, i, totalValue, maxUnitValue, p == maxUnitIndex, playerValue);
barIndex = barIndex + 1;
end
end
end
DamageMeters_StopDebugTimer(DMPROF_BARS);
end
DamageMeters_lastUpdateTime = currentTime;
----------------------
-- Debug End
DamageMeters_UpdateDebugTimers();
end
function DamageMetersFrame_GenerateFrame(frame)
if (not frame) then
frame = DamageMetersFrame;
if (not frame) then
return;
end
end
-- Hide the title button if mini mode.
if (DMVIEW_MIN == DamageMeters_viewMode) then
DamageMetersFrame_TitleButton:Hide();
else
DamageMetersFrame_TitleButton:Show();
end
-- Show/hide the total button.
if (DamageMeters_flags[DMFLAG_showTotal] and not (DMVIEW_MIN == DamageMeters_viewMode)) then
DamageMetersFrame_TotalButton:Show();
else
DamageMetersFrame_TotalButton:Hide();
end
-- Hide all bars: update will reshow those that need to be seen.
local i;
for i = 1,DamageMeters_BARCOUNT_MAX do
DamageMeters_bars[i]:Hide();
DamageMeters_bars[i]:SetValue(0);
DamageMeters_text[i]:SetText("");
-- Put all bars under the first bar.
DamageMeters_bars[i]:SetPoint("TOPLEFT", frame:GetName(), "TOPLEFT", 5, -6);
end
--DMPrint("GenerateFrame : bar count = "..DamageMeters_barCount);
-- Set the size of the frame.
local rowCount = 0;
local columnCount = 1;
local newWidth = 0;
if (DamageMeters_barCount > (DamageMeters_BARCOUNT_MAX / 2)) then
rowCount = ceil(DamageMeters_barCount / 2);
columnCount = 2;
newWidth = DamageMeters_BARWIDTH * 2 + 10 + 2;
else
columnCount = 1;
rowCount = DamageMeters_barCount;
newWidth = DamageMeters_BARWIDTH + 10;
end
local newHeight = (DamageMeters_BARHEIGHT * rowCount) + 11;
local oldWidth = frame:GetWidth();
local oldHeight = frame:GetHeight();
frame:SetWidth( newWidth );
frame:SetHeight( newHeight );
--if (DamageMeters_debugEnabled) then
-- if (DamageMeters_firstGeneration) then
-- DMPrintD("Initializing position to "..frame:GetLeft()..", "..frame:GetTop());
-- end
--end
-- Update pos according to resize direction.
if (not DamageMeters_firstGeneration) then
if (DamageMeters_flags[DMFLAG_resizeLeft] or DamageMeters_flags[DMFLAG_resizeUp]) then
--DMPrint("Resizing...");
local xPos = frame:GetLeft();
local yPos = frame:GetTop();
if (DamageMeters_flags[DMFLAG_resizeLeft]) then
xPos = xPos - (newWidth - oldWidth);
end
if (DamageMeters_flags[DMFLAG_resizeUp]) then
yPos = yPos + (newHeight - oldHeight);
end
-- Note: anchoring to bottomleft since apparently the GetLeft and GetTop
-- values are relative to that point.
frame:SetPoint("TOPLEFT", "UIParent", "BOTTOMLEFT", xPos, yPos);
end
end
--DMPrint("DamageMeters: "..rowCount.." rows, "..columnCount.." columns.");
-- Position the bars.
local name = frame:GetName();
local row;
local column;
for row = 1, rowCount do
for column = 1, columnCount do
--DMPrint("Row = "..row..", column = "..column);
local index = row + (column - 1) * rowCount;
if (index <= DamageMeters_barCount) then
local itemButton = DamageMeters_bars[index];
local itemText = DamageMeters_text[index];
itemButton:SetWidth(DamageMeters_BARWIDTH);
local x = 5 + (column - 1) * (DamageMeters_BARWIDTH + 2);
local y = -6 - (row - 1) * DamageMeters_BARHEIGHT;
itemButton:SetPoint("TOPLEFT", name, "TOPLEFT", x, y);
itemText:SetPoint("CENTER", itemButton:GetName(), "CENTER", 0, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -