📄 myinventory.lua
字号:
local val=strsub(MyInventoryBags,(1+i),(1+i));
if val=="1" then
MyInventory_DEBUG("replacing bag "..i);
for j=1,NUM_CONTAINER_FRAMES,1 do
local containerFrame = getglobal("ContainerFrame"..j);
if containerFrame:GetID() == i then
containerFrame:Hide();
end
end
end
end
end
end -- }}}
function MyInventory_SetScale(scale) -- {{{
MyInventoryFrame:SetScale(tonumber(scale));
MyInventory_Toggle_Option("Scale", scale, 1);
end -- }}}
function MyInventoryFrame_SetColumns(col) -- {{{
if ( type(col) ~= "number" ) then
col = tonumber(col);
end
if (type(col) ~= "number" or col == 0) then
return
end
if MyInventoryBagView == 1 and col < 5 then
col = 5;
end
if ( ( col >= MYINVENTORY_COLUMNS_MIN ) and ( col <= MYINVENTORY_COLUMNS_MAX ) ) then
MyInventoryColumns = col;
MyInventoryProfile[PlayerName].Columns = MyInventoryColumns;
MyInventoryFrame_UpdateLook();
end
end -- }}}
-- }}}
-- Text related functions. {{{
function MyInventory_Trim (s) -- {{{
return (string.gsub(s, "^%s*(.-)%s*$", "%1"));
end --}}}
function MyInventory_Print(msg,r,g,b,frame,id,unknown4th) -- {{{
--if ( Print ) then
-- Print(msg, r, g, b, frame, id, unknown4th);
-- return;
--end
if(unknown4th) then
local temp = id;
id = unknown4th;
unknown4th = id;
end
if (not r) then r = 1.0; end
if (not g) then g = 1.0; end
if (not b) then b = 1.0; end
if not frame then
if DEFAULT_CHAT_FRAME then
frame = DEFAULT_CHAT_FRAME
else
MyInventory_DEBUG("quitting print");
return
end
end
if type(msg) == "table" then
for key, value in msg do
--frame:AddMessage(value, r, g, b,id,unknown4th);
end
else
--frame:AddMessage(msg, r, g, b,id,unknown4th);
end
end -- }}}
function MyInventory_DEBUG(msg) --{{{
-- If Debug is not set, just skip it.
if ( not MyInventoryDEBUG or MyInventoryDEBUG == 0 ) then
return;
end
msg = "*** DEBUG(MyInventory): "..msg;
if ( DEFAULT_CHAT_FRAME ) then
--DEFAULT_CHAT_FRAME:AddMessage(msg, 1.0, 1.0, 0.0);
end
end -- }}}
-- }}}
-- Toggle Frame {{{
function ToggleMyInventoryFrame() -- {{{
if ( MyInventoryFrame:IsVisible() ) then
CloseMyInventoryFrame();
else
OpenMyInventoryFrame();
end
MyInventory_UpdateBagState();
end -- }}}
function CloseMyInventoryFrame() -- {{{
if ( MyInventoryFrame:IsVisible() ) then
MyInventoryFrame:Hide();
end
MyInventory_UpdateBagState();
end --}}}
function OpenMyInventoryFrame() -- {{{
MyInventoryFrame_UpdateLookIfNeeded();
MyInventoryFrame:Show();
MyInventory_UpdateBagState();
end --}}}
-- }}}
-- Update Bag State: Setting Checks {{{
function MyInventory_IsBagOpen(id) -- {{{
local formatStr = "ContainerFrame%d";
local frame = nil;
for i = 1, NUM_CONTAINER_FRAMES do
frame = getglobal(format(formatStr, i));
if ( ( frame ) and ( frame:IsVisible() ) and ( frame:GetID() == id ) ) then
return true;
end
end
return false;
end --}}}
function MyInventory_GetBagState(toggle) -- {{{
if ( ( toggle == true ) or ( toggle == 1 ) ) then
return 1;
else
return 0;
end
end -- }}}
function MyInventory_UpdateBagState() -- {{{
local visible = MyInventoryFrame:IsVisible();
local val = strsub(MyInventoryBags, 1,1);
MainMenuBarBackpackButton:SetChecked(MyInventory_GetBagState((val=="1" and visible) or MyInventory_IsBagOpen(0)));
MyInventoryBackpackButton:SetChecked(MyInventory_GetBagState((val=="1" and visible)));
local bagButton = nil;
local mibagButton1 = nil
local mibagButton2 = nil
local formatStr = "CharacterBag%dSlot";
local formatStr2= "MyInventoBag%dSlot";
for i = 0, 3 do
local val = strsub(MyInventoryBags, i+2,i+2);
bagButton = getglobal(format(formatStr, i));
mibagButton2 = getglobal(format(formatStr2, i));
if ( bagButton ) then
bagButton:SetChecked(MyInventory_GetBagState((val=="1" and visible) or MyInventory_IsBagOpen(i+1)));
mibagButton2:SetChecked(MyInventory_GetBagState((val=="1" and visible) ));
end
end
end -- }}}
-- }}}
-- Frame Events {{{
function MyInventoryFrame_OnEvent(event) -- {{{
if ( event == "VARIABLES_LOADED" ) then
MyInventory_Setup_Hooks(1);
MyInventory_DEBUG("Variables Loaded...");
MyInventory_Loaded = true;
MyInventory_MyAddonsRegister();
MyInventory_InitializeProfile();
AllInOne_Register();
end
if not MyInventory_Loaded then
return
end
if ( event == "UNIT_NAME_UPDATE" and arg1 == "player" and UnitName("player") ~= UNKNOWNOBJECT) then
MyInventory_InitializeProfile();
end
if PlayerName == nil then
return
end
if ( event == "BAG_UPDATE" ) then
if ( this:IsVisible() ) then
MyInventory_DEBUG("BAG_UPDATE Event fired.");
MyInventoryFrame_Update(MyInventoryFrame);
end
elseif ( event == "ITEM_LOCK_CHANGED" or event == "BAG_UPDATE_COOLDOWN" or event == "UPDATE_INVENTORY_ALERTS" ) then
if ( this:IsVisible() ) then
MyInventoryFrame_Update(MyInventoryFrame);
end
end
end -- }}}
function MyInventoryFrame_OnHide() -- {{{
PlaySound("igBackPackClose");
MyInventory_UpdateBagState();
end -- }}}
function MyInventoryFrame_OnShow() -- {{{
if MyInventory_Initialized == false then
MyInventoryFrame:Hide();
return;
end
MyInventoryFrame_Update(MyInventoryFrame);
PlaySound("igBackPackOpen");
MyInventoryFrame:ClearAllPoints();
MyInventoryFrame:SetPoint("BOTTOMRIGHT", "MyInventoryAnchorFrame", "BOTTOMRIGHT");
local pScale = MyInventoryFrame:GetParent():GetScale();
MyInventoryFrame:SetScale(MyInventoryScale);
end -- }}}
function MyInventoryFrame_OnMouseDown(arg1) -- {{{
if ( arg1 == "LeftButton" ) then
if ( MyInventoryLock == 0 ) then
-- this:StartMoving();
MyInventoryAnchorFrame:StartMoving();
else
MyInventory_Print("MyInventory is locked and can not move...");
end
end
end -- }}}
function MyInventoryFrame_OnMouseUp(arg1) -- {{{
if ( arg1 == "LeftButton" ) then
this:StopMovingOrSizing();
MyInventoryAnchorFrame:StopMovingOrSizing();
end
end -- }}}
-- }}}
-- Item Button Events {{{
function MyInventoryFrameItemButton_OnLoad() -- {{{
this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
this:RegisterForDrag("LeftButton");
this.SplitStack = function(button, split)
SplitContainerItem(button:GetParent():GetID(), button:GetID(), split);
end
getglobal(this:GetName().."NormalTexture"):SetTexture("Interface\\AddOns\\AllInOneInventory\\Skin\\Button");
end -- }}}
function MyInventoryFrameItemButton_OnClick(button, ignoreShift) -- {{{
local bag, slot = this.bagIndex, this.itemIndex;
if ( button == "LeftButton" ) then
if ( IsShiftKeyDown() and not ignoreShift ) then
if ( ChatFrameEditBox:IsVisible() ) then
ChatFrameEditBox:Insert(GetContainerItemLink(bag, slot));
else
local texture, itemCount, locked = GetContainerItemInfo(bag, slot);
if ( not locked ) then
this.SplitStack = function(button, split)
SplitContainerItem(bag, slot, split);
end
OpenStackSplitFrame(this.count, this, "BOTTOMRIGHT", "TOPRIGHT");
end
end
-- Dressing Room
elseif ( IsControlKeyDown() ) then
DressUpItemLink(GetContainerItemLink(bag, slot));
else
PickupContainerItem(bag, slot);
end
elseif ( button == "RightButton" ) then
if ( IsShiftKeyDown() and MerchantFrame:IsVisible() and not ignoreShift ) then
this.SplitStack = function(button, split)
SplitContainerItem(button:GetParent():GetID(), button:GetID(), split);
MerchantItemButton_OnClick("LeftButton");
end
OpenStackSplitFrame(this.count, this, "BOTTOMRIGHT", "TOPRIGHT");
else
UseContainerItem(bag, slot);
end
end
end -- }}}
function MyInventory_ContainerFrameItemButton_OnEnter() -- {{{
MyInventoryFrameItemButton_OnEnter()
end --}}}
function MyInventoryFrameItemButton_OnEnter() -- {{{
local bag, slot = this.bagIndex, this.itemIndex;
this:GetParent():SetID(this.bagIndex);
this:SetID(this.itemIndex);
ContainerFrameItemButton_OnEnter()
MyInventory_HighlightItemBag(bag);
if true then
return
end
-- Mimiking: ContainerFrameItemButton_OnEnter() - BEGIN
GameTooltip:SetOwner(this, "ANCHOR_LEFT");
local hasCooldown, repairCost = GameTooltip:SetBagItem(bag, slot);
if ( hasCooldown ) then
this.updateTooltip = TOOLTIP_UPDATE_TIME;
else
this.updateTooltip = nil;
end
if ( InRepairMode() and (repairCost and repairCost > 0) ) then
GameTooltip:AddLine(TEXT(REPAIR_COST), "", 1, 1, 1);
SetTooltipMoney(GameTooltip, repairCost);
GameTooltip:Show();
elseif ( MerchantFrame:IsVisible() ) then
ShowContainerSellCursor(bag, slot);
elseif ( this.readable ) then
ShowInspectCursor();
end
-- Mimiking: ContainerFrameItemButton_OnEnter() - END
end -- }}}
function MyInventoryFrameItemButton_OnLeave() -- {{{
MyInventory_HighlightItemBag(this.bagIndex, 1);
this.updateTooltip = nil;
GameTooltip:Hide();
ResetCursor();
end -- }}}
function MyInventoryFrameItemButton_OnUpdate(elapsed) -- {{{
if ( not this.updateTooltip ) then
return;
end
this.updateTooltip = this.updateTooltip - elapsed;
if ( this.updateTooltip > 0 ) then
return;
end
if ( GameTooltip:IsOwned(this) ) then
MyInventoryFrameItemButton_OnEnter();
else
this.updateTooltip = nil;
end
end -- }}}
-- }}}
-- Bag Button Events {{{
function MyInventory_Backpack_OnEnter() -- {{{
GameTooltip:SetOwner(this,"ANCHOR_LEFT");
GameTooltip:SetText(TEXT(BACKPACK_TOOLTIP),1.0,1.0,1.0);
local keyBinding = GetBindingKey("TOGGLEBACKPACK");
if ( keyBinding ) then
GameTooltip:AppendText(" "..NORMAL_FONT_COLOR_CODE.."("..keyBinding..")"..FONT_COLOR_CODE_CLOSE);
end
MyInventory_HighlightBagItems(0);
end -- }}}
function MyInventory_Backpack_OnLeave() -- {{{
GameTooltip:Hide();
MyInventory_HighlightBagItems(0,1);
end -- }}}
function MyInventory_BagButton_OnEnter() -- {{{
GameTooltip:SetOwner(this,"ANCHOR_LEFT");
if GameTooltip:SetInventoryItem("player", this:GetID()) then
local bindingkey = GetBindingKey("TOGGLEBAG"..(4-(this:GetID()-CharacterBag0Slot:GetID())));
if bindingkey then
GameTooltip:AppendText(" "..NORMAL_FONT_COLOR_CODE.."("..bindingkey..")"..FONT_COLOR_CODE_CLOSE);
end
MyInventory_HighlightBagItems(1+this:GetID()-MyInventoBag0Slot:GetID());
else
GameTooltip:SetText(TEXT(EQUIP_CONTAINER),1.0,1.0,1.0);
end
end -- }}}
function MyInventory_BagButton_OnLeave() -- {{{
this.updateTooltip = nil;
GameTooltip:Hide();
ResetCursor();
local bagID = 1+this:GetID()-MyInventoBag0Slot:GetID();
MyInventory_HighlightBagItems(bagID, 1);
end -- }}}
function MyInventory_BagButton_OnClick(isMMB) -- {{{
--local index = tonumber(strsub(this:GetName(), 13, 13))+2;
local bagID = 1+this:GetID()-MyInventoBag0Slot:GetID();
local val = strsub(MyInventoryBags, bagID+1, bagID+1);
if not PutItemInBag(this:GetID()) then
if IsShiftKeyDown() or not isMMB then
MyInventory_HighlightBagItems(bagID, 1);
if val == "1" then
val = "0"
else
val = "1"
CloseBag(bagID);
end
MyInventoryBags = strsub(MyInventoryBags, 1, bagID)..val..strsub(MyInventoryBags, bagID+2);
MyInventory_Toggle_Option("Bags", MyInventoryBags);
MyInventory_UpdateBagState();
MyInventoryFrame_UpdateLook();
MyInventoryFrame_Update();
else
ToggleBag(bagID);
end
end
end -- }}}
function MyInventory_Backpack_OnClick(isMMB) -- {{{
local val = strsub(MyInventoryBags, 1, 1);
if not PutItemInBackpack() then
if IsShiftKeyDown() or not isMMB then
MyInventory_HighlightBagItems(0,1);
if val == "1" then
val = "0"
else
CloseBackpack();
val = "1"
end
MyInventoryBags = val..strsub(MyInventoryBags, 2);
MyInventory_UpdateBagState();
MyInventoryFrame_UpdateLook();
MyInventoryFrame_Update();
MyInventory_Toggle_Option("Bags", MyInventoryBags);
else
ToggleBackpack();
end
end
end -- }}}
function MyInventory_BagButton_OnDragStart() -- {{{
--BagSlotButton_OnDrag();
PickupBagFromSlot(this:GetID());
PlaySound("BAGMENUBUTTONPRESS");
end -- }}}
function MyInventory_BagButton_OnReceiveDrag() -- {{{
PutItemInBag(this:GetID());
end -- }}}
-- }}}
-- Highlighting {{{
function MyInventory_HighlightBagItems(bagID, off) -- {{{
if MyInventoryHighlightItems == 0 then
return
end
local found;
local itemButton;
for i = 1,MYINVENTORY_MAX_ID do
local bag, slot;
itemButton = getglobal("MyInventoryFrameItem"..i);
bag = itemButton.bagIndex;
if bag == bagID then
found = true;
if off and off == 1 then
itemButton:UnlockHighlight();
else
itemButton:LockHighlight();
end
else
if found then
break;
end
end
end
end -- }}}
function MyInventory_HighlightItemBag(bagID, off) -- {{{
if MyInventoryHighlightBags == 0 then
return
end
local BagButton1, BagButton2;
if bagID == 0 then
BagButton1= getglobal("MyInventoryBackpackButton");
BagButton2= getglobal("MainMenuBarBackpackButton");
else
BagButton1= getglobal("MyInventoBag"..(bagID-1).."Slot");
BagButton2= getglobal("CharacterBag"..(bagID-1).."Slot");
end
if off then
BagButton1:UnlockHighlight();
BagButton2:UnlockHighlight();
else
BagButton1:LockHighlight();
BagButton2:LockHighlight();
end
end -- }}}
-- }}}
-- Update Visuals, toggled options {{{
-- Update Look {{{
function MyInventoryFrame_UpdateLookIfNeeded() -- {{{
local slots = MyInventory_GetBagsTotalSlots();
if ( ( not MyInventoryFrame.size ) or ( slots ~= MyInventoryFrame.size ) ) then
MyInventoryFrame_UpdateLook();
end
end -- }}}
function MyInventoryFrame_UpdateLook() -- {{{
--local frameSize = MyInventory_GetBagsTotalSlots();
local frameSize = MyInventory_GetBagsReplacingSlots();
MyInventoryTitle_Update(); -- Update Title
MyInventory_SetLock(); -- Set Lock Icon
MyInventory_ShowButtons(); -- Show or Hide Buttons
MyInventoryFrame.size = frameSize;
local name = MyInventoryFrame:GetName();
-- Update Size Anchor to bottom right
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -