📄 equipcompare.lua
字号:
function EquipCompare_ToggleCV(toggle)
-- workaround, as Cosmos sends a 0 when it wants to turn us off
if ( toggle == 0 ) then toggle = false; end
-- turn on
if ( toggle ) then
EquipCompare_UseCV = true;
if ( IsCharactersViewer() ) then
if ( EquipCompare_AltMode ) then
EquipCompare_CharactersViewer = lastAltState;
else
EquipCompare_CharactersViewer = true;
end
else
EquipCompare_CharactersViewer = false;
end
end
-- turn off
if ( not toggle ) then
EquipCompare_UseCV = false;
EquipCompare_CharactersViewer = false;
end
end
function EquipCompare_ToggleAlt(toggle)
-- workaround, as Cosmos sends a 0 when it wants to turn us off
if ( toggle == 0 ) then toggle = false; end
-- turn on
if ( toggle ) then
EquipCompare_AltMode = true;
end
-- turn off
if ( not toggle ) then
EquipCompare_AltMode = false;
if ( IsCharactersViewer() ) then
EquipCompare_CharactersViewer = true;
EquipCompare_Recheck = true;
end
end
end
function EquipCompare_ToggleShiftup(toggle)
-- workaround, as Cosmos sends a 0 when it wants to turn us off
if ( toggle == 0 ) then toggle = false; end
-- turn on
if ( toggle ) then
EquipCompare_Shiftup = true;
end
-- turn off
if ( not toggle ) then
EquipCompare_Shiftup = false;
end
EquipCompare_Recheck = true;
end
function EquipCompare_HideTips()
ComparisonTooltip1:Hide();
ComparisonTooltip2:Hide();
end
--
-- Local functions for ShowCompare()
--
-- Add a label at the top of the tooltip saying "Currently Equipped"
local function AddLabel(tooltip, slot)
local tLabel, tLabel1;
if (not tooltip or not tooltip:IsVisible()) then
return;
end
tLabel = getglobal(tooltip:GetName().."TextLeft0");
tLabel:SetText(EQUIPCOMPARE_EQUIPPED_LABEL);
tLabel:SetTextColor(0.5, 0.5, 0.5);
tLabel:Show();
tLabel1 = getglobal(tooltip:GetName().."TextLeft1");
if ( tLabel:IsVisible() and tLabel1:IsVisible() ) then
if ( tLabel:GetWidth() > tLabel1:GetWidth() ) then
tLabel1:SetWidth(tLabel:GetWidth());
tooltip:Show();
end
end
end
-- Display a comparison tooltip and set its contents to currently equipped item
-- occupying slotid
local function ShowComparisonTooltip(parent, slotid)
local leftAlign, donePlacing;
local left, right, i;
-- Set contents of tooltip.
-- Note: you can't set a tooltip's contents before specifying at least
-- one point. Hence anchor it to whatever, even if you later change
-- its placement.
ComparisonTooltip1:SetOwner(parent, "ANCHOR_LEFT");
if ( EquipCompare_CharactersViewer ) then
CharactersViewer_Tooltip_SetInventoryItem(ComparisonTooltip1, slotid);
else
ComparisonTooltip1:SetInventoryItem("player", slotid);
end
AddLabel(ComparisonTooltip1, slotid);
if ( not ComparisonTooltip1:IsVisible() ) then
return;
end;
-- Set placement of tooltip
leftAlign = false;
if ( parent == GameTooltip and GetMouseFocus() and
string.find(GetMouseFocus():GetName(),"^ContainerFrame.*Item") ) then
leftAlign = true;
end
donePlacing = true;
repeat
ComparisonTooltip1:ClearAllPoints();
if (leftAlign) then
ComparisonTooltip1:SetPoint("TOPRIGHT", parent:GetName(), "TOPLEFT", 0, -10);
else
ComparisonTooltip1:SetPoint("TOPLEFT", parent:GetName(), "TOPRIGHT", 0, -10);
end
local left = ComparisonTooltip1:GetLeft();
local right = ComparisonTooltip1:GetRight();
if ( left and right ) then
left, right = left - (right-left), right + (right-left);
end
-- If the comparison tooltip would be off the screen, place it on other
-- side instead. Only perform this check once to avoid endless loop.
if ( donePlacing ) then
if ( left and left<0 ) then
leftAlign = false;
donePlacing = false;
elseif ( right and right>UIParent:GetRight() ) then
leftAlign = true;
donePlacing = false;
end
else
donePlacing = true;
end
until donePlacing;
return leftAlign;
end
function EquipCompare_CheckCompare()
local tooltip = nil;
local i = 1;
if ( not EquipCompare_TooltipList ) then
EquipCompare_InitializeTooltipList();
end
-- Check which tooltip we are intersted in, in order of priority
repeat
tooltip = EquipCompare_TooltipList[i];
if ( not tooltip:IsVisible() ) then
tooltip = nil;
end
i = i + 1;
until tooltip or i > table.getn(EquipCompare_TooltipList)
EquipCompare_TargetTooltip = tooltip;
EquipCompare_Alignment = nil;
if ( tooltip ) then
EquipCompare_ShowCompare(tooltip);
end
end
function EquipCompare_ShowCompare(tooltip)
--
-- Main code of EquipCompare_ShowCompare starts here
--
local OverrideTooltips = nil;
local ttext, itype, slotid, other, leftAlign;
local i, cvplayer;
local shift, comptipclose, comptipfar, point, relative;
local mfocus;
-- Start processing
EquipCompare_Recheck = false;
EquipCompare_HideTips();
-- In some cases it is desirable to override the restrictions on showing
-- comparison tooltips, and show them anyway. Check for that here.
if ( EquipCompare_CharactersViewer ) then
cvplayer = CharactersViewer.index;
if ( cvplayer == nil ) then
cvplayer = UnitName("player");
end
if ( UnitName("player") ~= cvplayer ) then
OverrideTooltips = true;
end
if ( CharactersViewer_Frame:IsVisible() and
MouseIsOver(CharactersViewer_Frame) and tooltip == GameTooltip ) then
OverrideTooltips = false;
end
end
-- Special checks when we are attaching to GameTooltip. For some frames, we do
-- not want to provide comparison tooltips.
if ( tooltip == GameTooltip ) then
if ( GetMouseFocus() ) then
mfocus = GetMouseFocus():GetName();
end
if ( not OverrideTooltips and mfocus ) then
for i=1, table.getn(EquipCompare_BarList) do
if ( string.find(mfocus, EquipCompare_BarList[i]) ) then
return;
end
end
end
end
-- Infer the type of the item from one of the 2nd to 5th line of its tooltip description
-- Match this type against the appropriate slot
slotid = nil;
i = 2;
repeat
ttext = getglobal(tooltip:GetName().."TextLeft"..i);
if ( ttext and ttext:IsVisible() ) then
itype = ttext:GetText();
if ( itype ) then
slotid = EquipCompare_ItemTypes[itype];
end
end
i = i + 1;
until (slotid or i > 5)
if ( slotid ) then
-- Whilst we are in the process of displaying additional tooltips, we don't
-- want to reset the EquipCompare_Recheck flag. This protection is necessary
-- because calling SetOwner or SetxxxItem on any tooltip causes a
-- CLEAR_TOOLTIP event.
EquipCompare_Protected = true;
-- In case money line is visible on GameTooltip, must protect it by overriding
-- GameTooltip_ClearMoney. This is because calling SetOwner or SetxxxItem on
-- any tooltip causes money line of GameTooltip to be cleared.
local oldFunction = GameTooltip_ClearMoney;
GameTooltip_ClearMoney = EquipCompare_EmptyFunction;
-- Display a comparison tooltip and set its contents to currently equipped item
leftAlign = ShowComparisonTooltip(tooltip, slotid);
other = false;
-- If this is an item that can go into multiple slots, display additional
-- tooltips as appropriate
if ( itype == INVTYPE_FINGER ) then
other = EquipCompare_ItemTypes[INVTYPE_FINGER_OTHER];
end
if ( itype == INVTYPE_TRINKET ) then
other = EquipCompare_ItemTypes[INVTYPE_TRINKET_OTHER];
end
if ( itype == INVTYPE_WEAPON ) then
other = EquipCompare_ItemTypes[INVTYPE_WEAPON_OTHER];
end
if ( itype == INVTYPE_2HWEAPON ) then
other = EquipCompare_ItemTypes[INVTYPE_SHIELD];
end
if ( other ) then
if ( ComparisonTooltip1:IsVisible() ) then
-- First set the contents of the 2nd tooltip.
-- Note that we must use either at least an anchor or SetPoint
-- to be able to set the contents.
ComparisonTooltip2:SetOwner(ComparisonTooltip1, "ANCHOR_LEFT");
if ( EquipCompare_CharactersViewer ) then
CharactersViewer_Tooltip_SetInventoryItem(ComparisonTooltip2, other);
else
ComparisonTooltip2:SetInventoryItem("player", other);
end
AddLabel(ComparisonTooltip2, other);
if ( ComparisonTooltip2:IsVisible() ) then
-- Now place it in its rightful place
ComparisonTooltip2:ClearAllPoints();
if ( leftAlign ) then
ComparisonTooltip1:ClearAllPoints();
ComparisonTooltip2:SetPoint("TOPRIGHT", tooltip:GetName(), "TOPLEFT", 0, -10);
ComparisonTooltip1:SetPoint("TOPRIGHT", "ComparisonTooltip2", "TOPLEFT", 0, 0);
else
ComparisonTooltip2:SetPoint("TOPLEFT", "ComparisonTooltip1", "TOPRIGHT", 0, 0);
end
end
else
ShowComparisonTooltip(tooltip, other);
end
end
-- Record side of alignment
if ( leftAlign ) then
EquipCompare_Alignment = "left";
else
EquipCompare_Alignment = "right";
end
-- If shifting upwards is set by user or requested by an AddOn, deal with it here
if ( ComparisonTooltip1:IsVisible() and ( EquipCompare_Shiftup or
( EquipCompare_ShiftupObject == tooltip and EquipCompare_ShiftupSide ==
EquipCompare_Alignment and EquipCompare_ShiftupMargin > 0 ) ) ) then
if ( leftAlign ) then
if ( ComparisonTooltip2:IsVisible() ) then
comptipclose = ComparisonTooltip2;
comptipfar = ComparisonTooltip1;
else
comptipclose = ComparisonTooltip1;
comptipfar = ComparisonTooltip2;
end
point = "TOPRIGHT";
relative = "TOPLEFT";
else
comptipclose = ComparisonTooltip1;
comptipfar = ComparisonTooltip2;
point = "TOPLEFT";
relative = "TOPRIGHT";
end
shift = comptipclose:GetHeight()+10 - tooltip:GetHeight();
if ( shift > 0 ) then
comptipclose:ClearAllPoints();
comptipclose:SetPoint(point, tooltip:GetName(), relative, 0, -10+shift);
else
shift = 0;
end
if ( comptipfar:IsVisible() and ( EquipCompare_Shiftup or
EquipCompare_ShiftupMargin > comptipclose:GetWidth() ) ) then
shift = comptipfar:GetHeight()+10 - tooltip:GetHeight() - shift;
if ( shift > 0 ) then
comptipfar:ClearAllPoints();
comptipfar:SetPoint(point, comptipclose:GetName(), relative, 0, shift);
end
end
end
-- Restore GameTooltip_ClearMoney overriding.
GameTooltip_ClearMoney = oldFunction;
EquipCompare_Protected = false;
end
end
--glim reg
function EquipCompare_Register()
gLim_RegisterButton (
"Equip Compare",
"装备对比",
"Interface\\AddOns\\EquipCompare\\Icon",
function()
gLimModSecBookShowConfig("gLimEquipCompare");
end,
3,
7
);
gLim_RegisterConfigClass("gLimEquipCompare","Equip Compare","CraZy aPpLe");
gLim_RegisterConfigSection("gLimEquipCompareSection",GLIMEQUIPCOMPARE_WINDOW_TEXT,GLIMEQUIPCOMPARE_WINDOW_TEXT.." Last modified by CraZy aPpLe(gLim)",GLIMEQUIPCOMPARE_WINDOW_TEXT,"gLimEquipCompare");
gLim_RegisterConfigCheckBox(
"gLim_Compare_Enable",
COMPAREENABLE_WINDOW_DISPLAY,
COMPAREENABLE_WINDOW_DISPLAY_INFO,
EquipCompare_Enabled,
CompareEnable,
"gLimEquipCompare"
);
gLim_RegisterConfigCheckBox(
"gLim_Control_Enable",
CONTROLENABLE_WINDOW_DISPLAY,
CONTROLENABLE_WINDOW_DISPLAY_INFO,
EquipCompare_ControlMode,
CompareControlEnable,
"gLimEquipCompare"
);
end
function CompareEnable(toggle)
if (toggle == 1) then
EquipCompare_Enabled = true;
else
EquipCompare_Enabled = false;
end
end
function CompareControlEnable(toggle)
if (toggle == 1) then
EquipCompare_ControlMode = true;
else
EquipCompare_ControlMode = false;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -