📄 hunterbar_feedbutton.lua
字号:
gLimFPB.af = 0;
end
FeedButton_UpdateCount(this);
Glim_Hunter_Feed_Register();
else
this:UnregisterEvent("BAG_UPDATE");
this:UnregisterEvent("UNIT_HAPPINESS");
this:UnregisterEvent("PLAYER_PET_CHANGED");
end
end
end
if ( event == "PET_ATTACK_START" )
then
PetInCombat = true;
end
if ( event == "PET_ATTACK_STOP" )
then
PetInCombat = false;
end
if (event == "BAG_UPDATE") then
if (FeedPetButton_Food ~= nil and FeedPetButton_Food.Name ~= nil) then
-- determine the count of the selected food
FeedButton_UpdateCount(this);
end
return;
end
if (event == "UNIT_HAPPINESS" and arg1 == "pet" and UnitClass("player") == HUNTERBAR_CLASSNAME) then
FeedButton_Refresh();
-- correct the button scaling in case it was changed by an alt-tab
if (FeedPetButton_Food ~= nil and FeedPetButton_Food.Size == "small") then
FeedButton_SetSizeSmall();
else
FeedButton_SetSizeLarge();
end
return;
end
if (event == "PLAYER_PET_CHANGED" and UnitClass("player") == HUNTERBAR_CLASSNAME) then
if (UnitExists("pet")) then
FeedButtonFrame:Show();
FeedButton_Refresh();
else
FeedButtonFrame:Hide();
end
return;
end
end
function FeedButton_OnReceiveDrag()
FeedButton_PlaceFood();
end
function FeedButton_PlaceFood()
if (CursorHasItem()
and ZubanLib.Cursor ~= nil
and ZubanLib.Cursor.Attributes ~= nil
and ZubanLib.Cursor.Attributes.Location == "Container"
and ZubanLib.Cursor.Attributes.Name ~= nil
and ZubanLib.Cursor.Attributes.Texture ~= nil
and ZubanLib.Cursor.Attributes.Bag ~= nil
and ZubanLib.Cursor.Attributes.Slot ~= nil) then
-- drop the cursor item onto the feed button
FeedPetButton_Food.Name = ZubanLib.Cursor.Attributes.Name;
FeedPetButton_Food.Texture = ZubanLib.Cursor.Attributes.Texture;
SetItemButtonTexture(this, ZubanLib.Cursor.Attributes.Texture);
GameTooltip:Hide();
PickupContainerItem(ZubanLib.Cursor.Attributes.Bag, ZubanLib.Cursor.Attributes.Slot);
ZubanLib.Cursor:Clear();
FeedButton_UpdateCount(this);
FeedButton_Refresh();
return true;
end
return false;
end
function FeedButton_Clear()
-- remove the selected food
FeedPetButton_Food.Name = nil;
FeedPetButton_Food.Texture = nil;
FeedPetButton_Food.Count = nil;
SetItemButtonCount(this, 0);
SetItemButtonTexture(this, nil);
getglobal(this:GetName().."CountWarn"):Hide();
GameTooltip:Hide();
ZubanLib.Cursor:Clear();
FeedButton_Refresh();
end
function FeedButton_ExecuteKeyPress(override)
if (FeedPetButton_Food.Name) then
-- execute the feed button
FeedButton_ExecuteFeedPet(override);
else
ChatWrite(HUNTERBAR_NO_FOOD_MSG2);
end
end
function FeedButton_ExecuteFeedPet(override)
if (override == nil) then
override = false;
end
if (Enabled or override) then
local bag, slot = ZubanLib.Container.FindBagSlotByName(FeedPetButton_Food.Name);
if (bag and slot) then
PickupContainerItem(bag, slot);
-- do not record this pickup
ZubanLib.Cursor:Clear();
if (CursorHasItem()) then
DropItemOnUnit("pet");
else
ChatWarn("Feed Pet Button: Could not pickup Food.");
ScreenWarn("Could not pickup Food.");
end
-- hack: if the food fails to drop on the pet and remains on the
-- cursor, then drop it back into the container
if (CursorHasItem()) then
PickupContainerItem(bag, slot);
-- do not record this pickup
ZubanLib.Cursor:Clear();
else
ChatWrite(HUNTERBAR_MSG_FEEDING_PET.." "..UnitName("pet").." : "..FeedPetButton_Food.Name..".");
end
else
ChatWarn(HUNTERBAR_MSG_FOOD_NOT_FOUND);
ScreenWarn(HUNTERBAR_MSG_FOOD_NOT_FOUND);
end
end
end
function FeedButton_UpdateCount(button)
if (FeedPetButton_Food ~= nil and FeedPetButton_Food.Name) then
FeedPetButton_Food.Count = ZubanLib.Container.CountByName(FeedPetButton_Food.Name);
SetItemButtonCount(button, FeedPetButton_Food.Count);
if (FeedPetButton_Food.Count < 3) then
getglobal(button:GetName().."CountWarn"):SetText(FeedPetButton_Food.Count);
getglobal(button:GetName().."CountWarn"):Show();
else
getglobal(button:GetName().."CountWarn"):Hide();
end
end
end
function FeedButton_Refresh()
local happiness = GetPetHappiness();
local petHealth = UnitHealth("pet");
if (happiness ~= nil
and happiness < 3
and not ZubanLib.InCombat()
and not PetInCombat
and petHealth ~= nil
and petHealth > 0) then
FeedButton:SetAlpha(1);
Enabled = true;
else
if (FeedPetButton_Food ~= nil and FeedPetButton_Food.Name) then
FeedButton:SetAlpha(HUNTERBAR_NO_FOOD_TRANSPARENCY);
else
FeedButton:SetAlpha(1);
end
Enabled = false;
end
end
function FeedButton_Feeding()
local i = 1;
local buff;
buff = UnitBuff("pet", i);
while buff do
if ( string.find(buff, "Ability_Hunter_BeastTraining") )
then
return true;
end
i = i + 1;
buff = UnitBuff("pet", i);
end
return false;
end
function Glim_Hunter_Feed_Register()
gLim_RegisterButton (
"FPB",
"自动喂养",
"Interface\\AddOns\\HunterBar_FeedButton\\Icon",
function()
gLimModSecBookShowConfig("gLimFPB");
end,
2,
5
);
gLim_RegisterConfigClass(
"gLimFPB",
"自动喂养",
"CraZy aPpLe"
);
gLim_RegisterConfigSection(
"gLimFPB",
"自动喂养",
"自动喂养 Modified CraZy aPpLe(gLim)",
"CraZy aPpLe",
"gLimFPB"
);
gLim_RegisterConfigCheckBox(
"gLimFPBShow",
"开启自动喂养",
"开启自动喂养宠物的功能",
gLimFPB.on,
gLimFPB_on,
"gLimFPB"
);
gLim_RegisterConfigCheckBox(
"gLimFPBAF",
"开启全自动喂养",
"当宠物的状态低与设置的值时,自动喂食宠物",
gLimFPB.af,
gLimFPB_af,
"gLimFPB"
);
gLim_RegisterConfigButton(
"gLimFPBAFM",
"满足/快乐",
"改变全自动喂养的模式,当宠物状态低与快乐/满足时喂食",
"满足/快乐",
glimFPB_AFM,
"gLimFPB"
);
gLim_RegisterConfigButton(
"gLimFPBReset",
"重置按钮位置",
"初始化喂养按钮位置",
"重置按钮",
glimFPB_Reset,
"gLimFPB"
);
gLim_RegisterConfigButton(
"gLimFPBBinding",
"设置自动喂养快捷键",
"调出自动喂养快捷键设置栏",
"快捷键设置",
function()
gLimKeyBinding("HEADER_FEEDPETBUTTON");
gLimConfigSubFrame:Hide();
end,
"gLimFPB"
);
if(gLimFPB.on == 1) then
FeedButton_Show()
else
FeedButton_Disable()
end
end
function gLimFPB_on(toggle)
gLimFPB.on = toggle
if(gLimFPB.on == 1) then
FeedButton_Show()
else
FeedButton_Disable()
end
end
function gLimFPB_af(toggle)
gLimFPB.af = toggle
if (toggle == 1) then
FeedPetButton_Food.AutoFeed = true;
ChatWrite("开启自动喂养功能");
else
FeedPetButton_Food.AutoFeed = false;
ChatWrite("关闭自动喂养功能");
end
end
function glimFPB_AFM()
FeedButton_ToggleAutoFeedLevel()
end
function glimFPB_Reset()
FeedButton_Reset()
end
function ZubanLib.Container.CountByName(name)
local total = 0;
local itemLink;
local itemcount;
for bag = 0, NUM_BAG_FRAMES do
for slot = 1, GetContainerNumSlots(bag) do
itemLink = GetContainerItemLink(bag, slot);
if (itemLink ~= nil) then
local _,_,itemLink = string.find(itemLink, "^.*%[(.*)%].*$");
local _,_,name = string.find(name, "^.*%[(.*)%].*$");
if (itemLink == name) then
_, itemcount = GetContainerItemInfo(bag, slot);
total = total + itemcount;
end
end
end
end
return total;
end
function ZubanLib.Container.FindBagSlotByName(name)
local itemLink;
for bag = 0, NUM_BAG_FRAMES do
for slot = 1, GetContainerNumSlots(bag) do
itemLink = GetContainerItemLink(bag, slot);
if (itemLink) then
--ZubanLib.IO.Chat.Write(itemLink);
if (itemLink == name) then
return bag, slot;
end
end
end
end
return nil, nil;
end
function ZubanLib.Cursor:Clear()
self.Attributes = {};
end
function ZubanLib.IsBoolean(value)
return (value == true or value == false);
end
function ZubanLib.ToString(value)
if (value == nil) then
return "nil";
elseif (ZubanLib.IsBoolean(value)) then
if (value) then
return "true";
else
return "false";
end
else
return value;
end
end
function ZubanLib.InCombat()
if (MGplayer ~= nil) then
-- compatibility with MiniGroup addon created by Kaitlin
return MGplayer.inCombat;
elseif (PlayerFrame ~= nil) then
return PlayerFrame.inCombat;
else
return nil;
end
end
function ZubanLib.IO.Chat.Warn(message)
ZubanLib.IO.Chat.Write(message, 1, 0.2, 0.2);
end
function ZubanLib.IO.Chat.Write(message, red, green, blue, frame)
if (not red) then
red = 1;
end
if (not green) then
green = 1;
end
if (not blue) then
blue = 1;
end
if (frame) then
frame:AddMessage(message, red, green, blue, 1.0, UIERRORS_HOLD_TIME);
elseif (DEFAULT_CHAT_FRAME) then
DEFAULT_CHAT_FRAME:AddMessage(message, red, green, blue);
end
end
function ZubanLib.IO.Screen.Warn(message)
ZubanLib.IO.Screen.Write(message, 1, 0.2, 0.2);
end
function ZubanLib.IO.Screen.Write(message, red, green, blue)
ZubanLib.IO.Chat.Write(message, red, green, blue, UIErrorsFrame);
end
local BasePickupContainer = PickupContainerItem;
function PickupContainerItem(bag, slot)
local result = BasePickupContainer(bag, slot);
if (CursorHasItem()) then
ZubanLib.Cursor:PickupContainerItem(bag, slot);
end
return result;
end
function ZubanLib.Cursor:PickupContainerItem(bag, slot)
local link = GetContainerItemLink(bag, slot);
local texture, itemcount, locked, quality, readable = GetContainerItemInfo(bag, slot);
self.Attributes = {};
self.Attributes.Location = "Container";
self.Attributes.Name = link;
self.Attributes.Bag = bag;
self.Attributes.Slot = slot;
self.Attributes.Texture = texture;
self.Attributes.Count = itemcount;
self.Attributes.Locked = locked;
self.Attributes.Quality = quality;
self.Attributes.Readable = readable;
--self:Write();
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -