📄 equipcompare.lua
字号:
--
-- Global variables
--
-- Configuration settings
-- Default values when neither Khaos nor Cosmos are present
EquipCompare_Enabled = true;
EquipCompare_ControlMode = false;
EquipCompare_UseCV = true;
EquipCompare_AltMode = false;
EquipCompare_Shiftup = false;
-- Values for private use
EquipCompare_Recheck = true;
EquipCompare_Protected = false;
EquipCompare_CharactersViewer = false;
EquipCompare_TargetTooltip = nil;
EquipCompare_Alignment = nil;
EquipCompare_ShiftupObject = nil;
EquipCompare_ShiftupSide = nil;
EquipCompare_ShiftupMargin = 0;
EquipCompare_TooltipList = nil;
EquipCompare_BarList = nil;
GLIMEQUIPCOMPARE_WINDOW_TEXT = "装备对比";
COMPAREENABLE_WINDOW_DISPLAY_INFO = "设置是否开启装备对比";
COMPAREENABLE_WINDOW_DISPLAY = "开启装备对比";
CONTROLENABLE_WINDOW_DISPLAY_INFO = "勾选此项则只在按下Ctrl键时才与选中装备对比\n 只有开启装备对比此项才有效";
CONTROLENABLE_WINDOW_DISPLAY = "开启选择对比";
CONTROLMODE_WINDOW_DISPLAY_INFO = "设置是否开启控制按键模";
CONTROLMODE_WINDOW_DISPLAY = "开启控制按键模";
-- Data
INVTYPE_WEAPON_OTHER = INVTYPE_WEAPON.."_other";
INVTYPE_FINGER_OTHER = INVTYPE_FINGER.."_other";
INVTYPE_TRINKET_OTHER = INVTYPE_TRINKET.."_other";
EquipCompare_ItemTypes = {
[INVTYPE_WEAPONMAINHAND] = 16, -- Main Hand
[INVTYPE_2HWEAPON] = 16, -- Two-Hand
[INVTYPE_WEAPON] = 16, -- One-Hand
[INVTYPE_WEAPON_OTHER] = 17, -- One-Hand_other
[INVTYPE_SHIELD] = 17, -- Off Hand
[INVTYPE_WEAPONOFFHAND] = 17, -- Off Hand
[INVTYPE_HOLDABLE] = 17, -- Held In Off-hand
[INVTYPE_HEAD] = 1, -- Head
[INVTYPE_WAIST] = 6, -- Waist
[INVTYPE_SHOULDER] = 3, -- Shoulder
[INVTYPE_LEGS] = 7, -- Legs
[INVTYPE_CLOAK] = 15, -- Back
[INVTYPE_FEET] = 8, -- Feet
[INVTYPE_CHEST] = 5, -- Chest
[INVTYPE_ROBE] = 5, -- Chest
[INVTYPE_WRIST] = 9, -- Wrist
[INVTYPE_HAND] = 10, -- Hands
[INVTYPE_RANGED] = 18, -- Ranged
[INVTYPE_BODY] = 4, -- Shirt
[INVTYPE_TABARD] = 19, -- Tabard
[INVTYPE_FINGER] = 11, -- Finger
[INVTYPE_FINGER_OTHER] = 12, -- Finger_other
[INVTYPE_NECK] = 2, -- Neck
[INVTYPE_TRINKET] = 13, -- Trinket
[INVTYPE_TRINKET_OTHER] = 14, -- Trinket_other
[INVTYPE_WAND] = 18, -- Wand
[INVTYPE_GUN] = 18, -- Gun
[INVTYPE_GUNPROJECTILE] = 0, -- Projectile
[INVTYPE_BOWPROJECTILE] = 0, -- Projectile
[INVTYPE_CROSSBOW] = 18, -- Crossbow
[INVTYPE_THROWN] = 18, -- Thrown
};
EquipCompare_SlotIDtoSlotName = {
[0] = AMMOSLOT, -- 0
HEADSLOT, -- 1
NECKSLOT, -- 2
SHOULDERSLOT, -- 3
SHIRTSLOT, -- 4
CHESTSLOT, -- 5
WAISTSLOT, -- 6
LEGSSLOT, -- 7
FEETSLOT, -- 8
WRISTSLOT, -- 9
HANDSSLOT, -- 10
FINGER0SLOT, -- 11
FINGER1SLOT, -- 12
TRINKET0SLOT, -- 13
TRINKET1SLOT, -- 14
BACKSLOT, -- 15
MAINHANDSLOT, -- 16
SECONDARYHANDSLOT, -- 17
RANGEDSLOT, -- 18
TABARDSLOT, -- 19
};
--
-- Public API
--
--[[
success = EquipCompare_RegisterTooltip(object, priority)
Call this to register a tooltip object that you would like EquipCompare
to show comparison tooltips for.
Arguments:
* object: [Reference] The object to register with EquipeCompare
* priority (optional): [String] Permitted values are "high" and "low".
If not present, defaults to "low". Specifies whether you would like
to show comparison tooltips for this object in preference to the
game's main tooltip, if both are showing.
Returns:
* success: [Boolean] True if the registration was successful or the
object is already registered, false otherwise.
Note:
GameTooltip and ItemRefTooltip are registered by default. You only
need to register your own custom tooltips using this function. It is
permissible to call this function multiple times with the same object,
but it will result in a single registration.
]]
function EquipCompare_RegisterTooltip(object, priority)
local i;
if ( not priority ) then
priority = "low";
end
if ( not object or priority ~= "high" and priority ~= "low" ) then
return false;
end
if ( not EquipCompare_TooltipList ) then
EquipCompare_InitializeTooltipList();
end
for i = 1, table.getn(EquipCompare_TooltipList) do
if ( EquipCompare_TooltipList[i] == object ) then
return true;
end
end
if ( priority == "high" ) then
table.insert(EquipCompare_TooltipList, 1, object);
else
table.insert(EquipCompare_TooltipList, object);
end
local oldHandler = object:GetScript("OnTooltipCleared");
object:SetScript("OnTooltipCleared", function(a1,a2,a3,a4,a5)
local r1,r2,r3,r4,r5;
if ( oldHandler ) then
r1,r2,r3,r4,r5 = oldHandler(a1,a2,a3,a4,a5);
end
EquipCompare_PostClearTooltip();
return r1,r2,r3,r4,r5;
end);
return true;
end
--[[
success = EquipCompare_UnregisterTooltip(object)
Call this to unregister a tooltip object that you would no longer like
EquipCompare to show comparison tooltips for.
Arguments:
* object: [Reference] The object to unregister with EquipeCompare
Returns:
* success: [Boolean] True if the object was successfully unregistered,
false otherwise (for example because the object was not found in the
list of registered tooltips).
Note:
You will not be able to unregister GameTooltip and ItemRefTooltip,
and will receive a return value of false if you try. You should only
use this function to unregister your custom tooltips.
]]
function EquipCompare_UnregisterTooltip(object)
local i;
if ( not object or not EquipCompare_TooltipList ) then
return false;
end
for i = 1, table.getn(EquipCompare_TooltipList) do
if ( EquipCompare_TooltipList[i] == object ) then
table.remove(EquipCompare_TooltipList, i);
return true;
end
end
return false;
end
--[[
success = EquipCompare_RegisterExclusion(pattern)
Call this to register an object or set of objects which, when you hover
over it or them, you don't want EquipCompare to show comparison tooltips.
Arguments:
* pattern: [String] A standard Lua regexp pattern. Any object whose name
matches this pattern will not show comparison tooltips when hovered
over. Example: "^ActionButton", which avoids comparison tooltips when
hovering over any action bar buttons.
Returns:
* success: [Boolean] True if the pattern was successfully registered,
or if it has been registered before.
Note:
It is permissible to call this function multiple times with the exact
same pattern. It will however result in a single registration for that
pattern. The following patterns are registered by EquipCompare by
default: "^Character.*Slot","^CharactersViewer_Frame","^TempEnchant",
"^MultiBar","^ActionButton"
]]
function EquipCompare_RegisterExclusion(barname)
local i;
if ( type(barname) ~= "string" ) then
return false;
end
if ( not EquipCompare_BarList ) then
EquipCompare_InitializeBarList();
end
for i = 1, table.getn(EquipCompare_BarList) do
if ( EquipCompare_BarList[i] == barname ) then
return true;
end
end
table.insert(EquipCompare_BarList, barname);
return true;
end
--[[
success = EquipCompare_UnregisterExclusion(pattern)
Call this to unregister an exclusion pattern registered with
EquipCompare_RegisterExclusion. Use a standard Lua regular
expression pattern to specify the name(s) of the object(s).
Arguments:
* pattern: [String] The exact same pattern that was registered.
Returns:
* success: [Boolean] True if the pattern was successfully unregistered,
false if some error occurred, e.g. it wasn't in the registered list.
]]
function EquipCompare_UnregisterExclusion(barname)
local i;
if ( type(barname) ~= "string" or not EquipCompare_BarList ) then
return false;
end
for i = 1, table.getn(EquipCompare_BarList) do
if ( EquipCompare_BarList[i] == barname ) then
table.remove(EquipCompare_BarList, i);
return true;
end
end
return false;
end
--[[
object, alignment = EquipCompare_GetComparisonAnchor()
Call this when you need to know which side the comparison tooltips are on,
or would be on, relative to the object that EquipCompare currently prefers
to attach comparison tooltips to.
Returns:
* object: [Reference] The object (e.g. GameTooltip or ItemRefTooltip) that
EC currently is attaching to or would be attaching to if it was
displaying comparison tooltips. Set to nil if EC can't see any object to
attach to.
* alignment: [String] "left" or "right", depending on which side the
comparison tooltips are showing or would show up on for that object.
Set to nil if EC wouldn't show comparison tooltips for the object at the
moment.
]]
function EquipCompare_GetComparisonAnchor()
EquipCompare_CheckCompare();
if ( EquipCompare_ControlMode and not IsControlKeyDown() ) then
EquipCompare_HideTips();
end
return EquipCompare_TargetTooltip, EquipCompare_Alignment;
end
--[[
EquipCompare_RequestShift(object, side, margin)
Call this when you want to request EquipCompare to shift its tooltips if
necessary to make space under and to the side of an object, for example because
you want to occupy that space.
Arguments:
* object: [Reference] The object you are requesting a shift around
(e.g. GameTooltip or ItemRefTooltip).
* side: [String] Indicates which side under the object you need space.
Takes value "left" or "right".
* margin: [Integer] Indicates how much space in game-pixels you need.
Note:
It is permissible to call EquipCompare_RequestShift multiple types, even
without corresponding calls to EquipCompare_CancelShift(), for example,
to change the object or the margin. It is always the last call that
takes effect.
]]
function EquipCompare_RequestShift(object, side, margin)
-- error checking
if ( side ~= "left" and side ~= "right" or type(margin) ~= "number" ) then
EquipCompare_ShiftupObject = nil;
EquipCompare_ShiftupSide = nil;
EquipCompare_ShiftupMargin = 0;
return;
end
EquipCompare_ShiftupObject = object;
EquipCompare_ShiftupSide = side;
EquipCompare_ShiftupMargin = margin;
EquipCompare_Recheck = true;
EquipCompare_OnUpdate();
end
--[[
EquipCompare_CancelShift(object)
Call this when you no longer require EquipCompare to make space under
and to the side of an object.
Arguments:
* object: [Reference] The object you no longer need space around.
Note:
It is permissible to call this function multiple times, even without
corresponding calls to EquipCompare_RequestShift(). It is also
permissible to call this with a different object that you called
EquipCompare_RequestShift() with, or an object that EquipCompare
is not actually attaching to.
]]
function EquipCompare_CancelShift(object)
if ( object == EquipCompare_ShiftupObject ) then
EquipCompare_Recheck = true;
end
EquipCompare_ShiftupObject = nil;
EquipCompare_ShiftupSide = nil;
EquipCompare_ShiftupMargin = 0;
EquipCompare_OnUpdate();
end
--
-- Some local functions that are used throughout
--
-- CharactersViewer compatibility check
local function IsCharactersViewer()
if ( CharactersViewer and CharactersViewer.version and
type(CharactersViewer.version.number) == "number" and
CharactersViewer.version.number >= 55 and
type(CharactersViewer_Tooltip_SetInventoryItem)=="function" and
EquipCompare_UseCV ) then
return true;
else
return false;
end
end
-- Registration and configuration
function EquipCompare_Register_Khaos()
-- Note: Default to disabled if Khaos is present
Khaos.registerOptionSet (
"tooltip",
{
id = "EquipCompareConfigSet";
text = EQUIPCOMPARE_COSMOS_SECTION;
helptext = EQUIPCOMPARE_COSMOS_SECTION_INFO;
difficulty = 1;
callback = EquipCompare_Toggle;
default = false;
options = {
{
id = "EquipCompareOptionHeader";
type = K_HEADER;
difficulty = 1;
text = EQUIPCOMPARE_COSMOS_HEADER;
helptext = EQUIPCOMPARE_COSMOS_HEADER_INFO;
},{
id = "EquipCompareOptionControlMode";
type = K_TEXT;
difficulty = 3;
text = EQUIPCOMPARE_COSMOS_CONTROLMODE;
helptext = EQUIPCOMPARE_COSMOS_CONTROLMODE_INFO;
callback = function(state) EquipCompare_ToggleControl(state.checked); end;
feedback = function(state)
if (state.checked) then
return EQUIPCOMPARE_TOGGLECONTROL_ON;
else
return EQUIPCOMPARE_TOGGLECONTROL_OFF;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -