⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hunterbar_feedbutton.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
HUNTERBAR_NO_FOOD_MSG = "No food selected";
HUNTERBAR_NO_FOOD_MSG2 = "Drop some food onto the feed button first.";
HUNTERBAR_FEED_BUTTON_TITLE = "Click to feed pet";
HUNTERBAR_SHIFT_FEED_BUTTON_TITLE = "Double-click to feed pet";
HUNTERBAR_MSG_DRAG = "移动位置";
HUNTERBAR_MSG_RESIZE = "右键单击改变尺寸";
HUNTERBAR_MSG_LOCK = "Shift+右键单击锁定位置";
HUNTERBAR_MSG_FEEDING_PET = "正在喂食";
HUNTERBAR_MSG_FOOD_NOT_FOUND = "食物没有找到.";
HUNTERBAR_CLASSNAME = "Hunter";
HUNTERBAR_CONTENT = "content";
HUNTERBAR_HAPPY = "happy";
apple_temp_console = 0;
ZubanLib = {
	Const = {
		Texture = {
			HAWK = "Interface\\Icons\\Spell_Nature_RavenForm";
			MONKEY = "Interface\\Icons\\Ability_Hunter_AspectOfTheMonkey";
			CHEETAH = "Interface\\Icons\\Ability_Mount_JungleTiger";
		};
	};
	
	-- action bar
	Action = {
		BAG_VALUE = -2;
		NUM_SLOTS = 120;
	};
	
	-- paper doll
	Inventory = {
		BAG_VALUE = -1;
		NUM_SLOTS = 18;
	};
	
	-- bags
	Container = {};
	
	-- spellbook
	Spell = {};
	
	-- buffs
	Buff = {};
	
	-- write
	IO = {
		Chat = {};
		Screen = {};
	};
	
	-- stores extra cursor values
	Cursor = {};
};

-- localization, needs work but this is a start
if (GetLocale() == "frFR") then
	HUNTERBAR_NO_FOOD_MSG = "No food selected";
	HUNTERBAR_NO_FOOD_MSG2 = "Drop some food onto the feed button first.";
	HUNTERBAR_FEED_BUTTON_TITLE = "Click to feed pet";
	HUNTERBAR_SHIFT_FEED_BUTTON_TITLE = "Double-click to feed pet";
	HUNTERBAR_CLASSNAME = "Chasseur";
elseif (GetLocale() == "deDE") then
	HUNTERBAR_NO_FOOD_MSG = "Keine Nahrung ausgew\195\164hlt";
	HUNTERBAR_NO_FOOD_MSG2 = "Ziehe Nahrung auf den F\195\188tterungsbutton.";
	HUNTERBAR_FEED_BUTTON_TITLE = "Linksklicke zum f\195\188ttern";
	HUNTERBAR_SHIFT_FEED_BUTTON_TITLE = "Shift-Linksklicke zum f\195\188ttern";
	HUNTERBAR_CLASSNAME = "J\195\164ger";
elseif (GetLocale() == "zhCN") then
	HUNTERBAR_NO_FOOD_MSG = "没有选择食物.";
	HUNTERBAR_NO_FOOD_MSG2 = "请先在 feed button 中放入食物.";
	HUNTERBAR_FEED_BUTTON_TITLE = "单击喂养你的宠物.";
	HUNTERBAR_SHIFT_FEED_BUTTON_TITLE = "双击喂养你的宠物.";
	HUNTERBAR_CLASSNAME = "猎人";	
	HUNTERBAR_CONTENT = "满足";
	HUNTERBAR_HAPPY = "快乐";
end

HUNTERBAR_NO_FOOD_TRANSPARENCY = 0.3;
BINDING_HEADER_FEEDPETBUTTON = "自动喂养宠物";
BINDING_NAME_FEEDPETBUTTON1 = "喂养宠物";
BINDING_NAME_FEEDPETBUTTON2 = "在快乐时喂养";

FeedPetButton_Food = nil;
local Enabled = true;
local RealmName = "";
local PlayerName = "";
local ButtonSizeSmall = 0.6;
local PetInCombat = false;

local function ChatWriteColor(msg, red, green, blue)
	return ZubanLib.IO.Chat.Write(msg, red, green, blue);	
end
local function ChatWrite(msg)
	return ZubanLib.IO.Chat.Write(msg);
end

local function ScreenWrite(msg)
	return ZubanLib.IO.Screen.Write(msg);
end

local function ChatWarn(msg)
	return ZubanLib.IO.Chat.Warn(msg);
end

local function ScreenWarn(msg)
	return ZubanLib.IO.Screen.Warn(msg);
end

local function ToString(value)
	return ZubanLib.ToString(value);
end

function FeedButton_OnLoad()
	-- register events
	this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
	this:RegisterForDrag("LeftButton");
	this:RegisterEvent("UNIT_NAME_UPDATE");
	this:RegisterEvent("BAG_UPDATE");
	this:RegisterEvent("UNIT_HAPPINESS");
	this:RegisterEvent("PLAYER_PET_CHANGED");
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("PET_ATTACK_START");
	this:RegisterEvent("PET_ATTACK_STOP");
	
	-- setup slash command
	SLASH_FEEDPETBUTTON1 = "/feedpetbutton";
	SLASH_FEEDPETBUTTON2 = "/fpb";
	SlashCmdList["FEEDPETBUTTON"] = function(command)
		FeedButton_HandleSlashCommand(command);
	end

	--ChatWrite("HunterBar - Feed Pet Button AddOn Loaded. Type /feedpetbutton for usage.");
	--ScreenWrite("HunterBar - Feed Pet Button AddOn Loaded.");
end

function FeedButton_HandleSlashCommand(command)
	if (command == "lock") then
		FeedButton_Lock();
	elseif (command == "unlock") then
		FeedButton_Unlock();
	elseif (command == "small") then
		FeedButton_SetSizeSmall();
	elseif (command == "large") then
		FeedButton_SetSizeLarge();
	elseif (command == "debug") then
		FeedButton_Debug();
	elseif (command == "reset") then
		FeedButton_Reset();
	elseif (command == "togglesize") then
		FeedButton_ToggleSize();
	elseif (command == "togglelock") then
		FeedButton_ToggleLock();
	elseif (command == "autofeed"
		or command == "af") then
		FeedButton_ToggleAutoFeed();
	elseif (command == "autofeedlevel"
		or command == "afl") then
		FeedButton_ToggleAutoFeedLevel();
	elseif (command == "disable") then
		FeedButton_Disable();
	elseif (command == "show") then
		FeedButton_Show();
	elseif (command == "status") then
		FeedButton_ShowStatus();
	elseif (command == "aa") then
		FeedButton_Refresh();
	else
		ChatWrite("usage: /feedpetbutton [lock | unlock | small | large | reset | autofeed(af) | autofeedlevel(afl) | disable | show | status]");
	end
end

function FeedButton_Disable()
	FeedButtonMover:Hide();
	FeedButton:Hide();
	FeedButtonFrame:Hide();
	
--	ChatWrite("Feed Pet Button: Disabled.");
end

function FeedButton_Show()
	if (FeedPetButton_Food ~=nil) then
		if (not FeedPetButton_Food.Locked) then
			FeedButtonMover:Show();	
		end
	end
	FeedButton:Show();
	FeedButtonFrame:Show();
	FeedButton_Refresh();	
end

function FeedButton_Reset()
	if (UnitClass("player") == HUNTERBAR_CLASSNAME) then
		FeedButtonFrame:ClearAllPoints();
		FeedButtonFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 0);
		FeedButton_Unlock();
		FeedButton_SetSizeLarge();
		if (FeedPetButton_Food ~=nil) then
			if (FeedPetButton_Food.AutoFeed) then
				FeedButton_ToggleAutoFeed();
			end
			if (FeedPetButton_Food.AFLevel ==3) then
				FeedButton_ToggleAutoFeedLevel();
			end
		end
		FeedButtonFrame:Show();
	else
		FeedButtonFrame:Hide();		
	end
	--ChatWrite("Feed Pet Button: Reset.");
end

function FeedButton_SetSizeSmall()
	if (FeedPetButton_Food ~= nil) then
		FeedButton:SetScale(UIParent:GetScale() * ButtonSizeSmall);
		FeedPetButton_Food.Size = "小";
	end
end

function FeedButton_SetSizeLarge()
	if (FeedPetButton_Food ~= nil) then
		FeedButton:SetScale(UIParent:GetScale());
		FeedPetButton_Food.Size = "大";
	end
end

function FeedButton_ToggleSize()
	if (FeedPetButton_Food ~= nil) then
		if (FeedPetButton_Food.Size == "大") then
			FeedButton_SetSizeSmall();
		else
			FeedButton_SetSizeLarge();
		end
	end
end

function FeedButton_Lock()
	if (FeedPetButton_Food ~= nil) then
		FeedPetButton_Food.Locked = true;
		FeedButtonMover:Hide();
	end
end

function FeedButton_Unlock()
	if (FeedPetButton_Food ~= nil) then
		FeedPetButton_Food.Locked = false;
		FeedButtonMover:Show();
	end	
end

function FeedButton_ToggleLock()
	if (FeedPetButton_Food ~= nil) then
		if (FeedPetButton_Food.Locked) then
			FeedButton_Unlock();
		else
			FeedButton_Lock();
		end
	end
end

function FeedButton_ToggleAutoFeed()
	if (FeedPetButton_Food ~= nil) then
		if (FeedPetButton_Food.AutoFeed) then
			FeedPetButton_Food.AutoFeed = false;
			ChatWrite("关闭自动喂养功能");
		else
			FeedPetButton_Food.AutoFeed = true;
			ChatWrite("开启自动喂养功能");
		end
	end
end

function FeedButton_ToggleAutoFeedLevel()	
	if (FeedPetButton_Food ~=nil) then
		if (FeedPetButton_Food.AFLevel == 2) then
			FeedPetButton_Food.AFLevel = 3;
			ChatWrite("当宠物状态低与"..HUNTERBAR_HAPPY.."时自动喂养"); 
		else
			FeedPetButton_Food.AFLevel = 2;
			ChatWrite("当宠物状态低与"..HUNTERBAR_CONTENT.."时自动喂养");
		end
	end	
end

function FeedButton_ShowStatus()
	ChatWriteColor("喂养按钮状态:",0.2,1,0.2);

	if (FeedPetButton_Food) then
		ChatWrite("食物名字:"..ToString(FeedPetButton_Food.Name));
		ChatWrite("食物数量:"..ToString(FeedPetButton_Food.Count));
		if ( FeedPetButton_Food.AutoFeed) then
			ChatWrite("自动喂养:开启.");
		else
			ChatWrite("自动喂养:关闭.");
		end
		if (FeedPetButton_Food.AFLevel ==2 ) then
			ChatWrite("自动喂养状态:"..HUNTERBAR_CONTENT);
		else
			ChatWrite("自动喂养状态:"..HUNTERBAR_HAPPY); 
		end
		ChatWrite("按钮尺寸: "..ToString(FeedPetButton_Food.Size));
		ChatWrite("锁定按钮: "..ToString(FeedPetButton_Food.Locked));		
	end

end
function FeedButton_Debug()
	ChatWrite("Enabled="..ToString(Enabled));
	ChatWrite("RealmName="..ToString(RealmName));
	ChatWrite("PlayerName="..ToString(PlayerName));
	ChatWrite("PetName="..ToString(UnitName("pet")));
	ChatWrite("PetInCombat="..ToString(PetInCombat));
	if (FeedPetButton_Food) then
		ChatWrite("Name="..ToString(FeedPetButton_Food.Name));
		ChatWrite("Texture="..ToString(FeedPetButton_Food.Texture));
		ChatWrite("Count="..ToString(FeedPetButton_Food.Count));
		ChatWrite("Size="..ToString(FeedPetButton_Food.Size));
		ChatWrite("Locked="..ToString(FeedPetButton_Food.Locked));
		ChatWrite("AFLevel="..ToString(FeedPetButton_Food.AFLevel));
	end
end

function FeedButton_OnEnter()
	-- display tooltip
	GameTooltip:SetOwner(this, "ANCHOR_RIGHT");

	if (FeedPetButton_Food ~= nil and FeedPetButton_Food.Name) then
		if (Enabled) then
			GameTooltip:SetText(HUNTERBAR_FEED_BUTTON_TITLE);
		else
			GameTooltip:SetText(HUNTERBAR_SHIFT_FEED_BUTTON_TITLE);
		end
				
		GameTooltip:AddLine("食物: "..FeedPetButton_Food.Name, "", 1, 1, 1);
		GameTooltip:AddLine("数量: "..FeedPetButton_Food.Count, "", 1, 1, 1);
	else
		GameTooltip:AddLine(HUNTERBAR_NO_FOOD_MSG, "", 1, 1, 1);
	end

	GameTooltip:Show();
end

function FeedButtonMover_OnEnter()
	-- display tooltip
	GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
	GameTooltip:SetText(HUNTERBAR_MSG_DRAG);
	GameTooltip:AddLine(HUNTERBAR_MSG_RESIZE, "", 1, 1, 1);
	GameTooltip:AddLine(HUNTERBAR_MSG_LOCK, "", 1, 1, 1);
	GameTooltip:Show();
end

function FeedButton_OnLeave()
	-- hide tooltip
	GameTooltip:Hide();
end

function FeedButton_OnClick(button, isDoubleClick)
	if (FeedButton_PlaceFood()) then
		ZubanLib.Cursor:Clear();
		return;
	end

	if (isDoubleClick == nil) then
		isDoubleClick = false;
	end
	
	if (IsShiftKeyDown()) then
		-- clear the button on shift-click
		if (button == "LeftButton") then
			FeedButton_Clear();
		else
			FeedButton_ToggleLock();
		end
	elseif (FeedPetButton_Food.Name) then
		-- execute the feed button
		FeedButton_ExecuteFeedPet(isDoubleClick);
	else
		ChatWrite(HUNTERBAR_NO_FOOD_MSG2);
	end
	
	FeedButton_UpdateCount(this);
end

function FeedButton_OnEvent(event)	
	if (UnitName("player") and UnitName("player") ~= UNKNOWNOBJECT) then
		if( apple_temp_console == 0 ) then
			apple_temp_console = 1;
			-- unregistering causes a bug?
			--this:UnregisterEvent("UNIT_NAME_UPDATE");

			if (UnitClass("player") == HUNTERBAR_CLASSNAME) then
				RealmName = GetCVar("RealmName"); 
				PlayerName = UnitName("player");
		
				if (FeedPetButton_Config == nil) then
					FeedPetButton_Config = {};
				end
				
				if (FeedPetButton_Config[RealmName] == nil) then
					FeedPetButton_Config[RealmName] = {}
				end
		
				if (FeedPetButton_Config[RealmName][PlayerName] == nil) then
					FeedPetButton_Config[RealmName][PlayerName] = {}
				end
		
				FeedPetButton_Food = FeedPetButton_Config[RealmName][PlayerName];
				
				if (FeedPetButton_Food.Texture) then
					SetItemButtonTexture(this, FeedPetButton_Food.Texture);
				end
				
				if (FeedPetButton_Food.Size == "small") then
					FeedButton_SetSizeSmall();
				else
					FeedButton_SetSizeLarge();
				end

				if (FeedPetButton_Food.Locked) then
					FeedButtonMover:Hide();
				else
					FeedButtonMover:Show();
				end
				if (FeedPetButton_Food.AFLevel == nil) then
					FeedPetButton_Food.AFLevel = 3;	
				end
				if (UnitExists("pet")) then
					FeedButtonFrame:Show();
					FeedButton:Show();
					FeedButton_Refresh();
				else
					FeedButton:Show();
					FeedButtonFrame:Hide();
				end			
				if (gLimFPB == nil) then				
					gLimFPB = {};		
				end 
				if (gLimFPB.on == nil) then				
					gLimFPB.on = 1;		
				end
				if (gLimFPB.af == nil) then				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -