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

📄 infcommand.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
--[[	Informant	An addon for World of Warcraft that shows pertinent information about	an item in a tooltip when you hover over the item in the game.	3.5.0.0912 (Platypus)	$Id: InfCommand.lua 854 2006-05-10 04:23:18Z mentalpower $	Command handler. Assumes responsibility for allowing the user to set the	options via slash command, Khaos, MyAddon etc.	License:		This program is free software; you can redistribute it and/or		modify it under the terms of the GNU General Public License		as published by the Free Software Foundation; either version 2		of the License, or (at your option) any later version.		This program is distributed in the hope that it will be useful,		but WITHOUT ANY WARRANTY; without even the implied warranty of		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the		GNU General Public License for more details.		You should have received a copy of the GNU General Public License		along with this program(see GLP.txt); if not, write to the Free Software		Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.--]]-- function prototypeslocal commandHandler, cmdHelp, onOff, genVarSet, chatPrint, registerKhaos, restoreDefault, cmdLocale, setLocale, isValidLocalelocal setKhaosSetKeyValue-- Localization function prototypeslocal delocalizeFilterVal, localizeFilterVal, getLocalizedFilterVal, delocalizeCommand, localizeCommand, buildCommandMaplocal commandMap = nil;local commandMapRev = nil;Informant_Khaos_Registered = nilInformant.InitCommands = function()	SLASH_INFORMANT1 = "/informant"	SLASH_INFORMANT2 = "/inform"	SLASH_INFORMANT3 = "/info"	SLASH_INFORMANT4 = "/inf"	SlashCmdList["INFORMANT"] = function(msg)		commandHandler(msg, nil)	end	chatPrint(string.format(_INFM('FrmtWelcome'), INFORMANT_VERSION))	if (Khaos) then		registerKhaos()	endendfunction setKhaosSetKeyValue(key, value)	if (Informant_Khaos_Registered) then		local kKey = Khaos.getSetKey("Informant", key)		if (not kKey) then			EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): key " .. key .. " does not exist")		elseif (kKey.checked ~= nil) then			if (type(value) == "string") then value = (value == "on"); end			Khaos.setSetKeyParameter("Informant", key, "checked", value)		elseif (kKey.value ~= nil) then			Khaos.setSetKeyParameter("Informant", key, "value", value)		else			EnhTooltip.DebugPrint("setKhaosSetKeyValue(): don't know how to update key ", key)		end	endendfunction buildCommandMap()	commandMap = {		[_INFM('CmdOn')]			=	'on',		[_INFM('CmdOff')]			=	'off',		[_INFM('CmdHelp')]			=	'help',		[_INFM('CmdToggle')]		=	'toggle',		[_INFM('CmdDisable')]		=	'disable',		[_INFM('CmdLocale')]		=	'locale',		[_INFM('CmdDefault')]		=	'default',		[_INFM('CmdEmbed')]			=	'embed',		[_INFM('ShowIcon')]			=	'show-icon',		[_INFM('ShowStack')]		=	'show-stack',		[_INFM('ShowUsage')]		=	'show-usage',		[_INFM('ShowQuest')]		=	'show-quest',		[_INFM('ShowMerchant')]		=	'show-merchant',		[_INFM('ShowVendor')]		=	'show-vendor',		[_INFM('ShowVendorBuy')]	=	'show-vendor-buy',		[_INFM('ShowVendorSell')]	=	'show-vendor-sell',	}	commandMapRev = {}	for k,v in pairs(commandMap) do		commandMapRev[v] = k;	endend--Cleaner Command Handling Functions (added by MentalPower)function commandHandler(command, source)	--To print or not to print, that is the question...	local chatprint = nil	if (source == "GUI") then chatprint = false	else chatprint = true end	--Divide the large command into smaller logical sections (Shameless copy from the original function)	local i,j, cmd, param = string.find(command, "^([^ ]+) (.+)$")	if (not cmd) then cmd = command end	if (not cmd) then cmd = "" end	if (not param) then param = "" end	cmd = delocalizeCommand(cmd);	--Now for the real Command handling	if ((cmd == "") or (cmd == "help")) then		cmdHelp()		return	elseif (cmd == "on" or cmd == "off" or cmd == "toggle") then		onOff(cmd, chatprint)	elseif (cmd == "disable") then		Stubby.SetConfig("Informant", "LoadType", "never");	elseif (cmd == "load") then		if (param == "always") or (param == "never") then			chatPrint("Setting Informant to "..param.." load for this toon");			Stubby.SetConfig("Informant", "LoadType", param);		end	elseif (cmd == "locale") then		setLocale(param, chatprint)	elseif (cmd == "default") then		restoreDefault(param, chatprint)	elseif (cmd == "embed" or cmd == "show-stack" or cmd == "show-usage" or			cmd == "show-quest" or cmd == "show-merchant" or cmd == "show-vendor" or			cmd == "show-vendor-buy" or cmd == "show-vendor-sell" or cmd == "show-icon") then		genVarSet(cmd, param, chatprint)	else		if (chatprint) then			chatPrint(string.format(_INFM('FrmtActUnknown'), cmd))		end	endend--Help ME!! (The Handler) (Another shameless copy from the original function)function cmdHelp()	local onOffToggle = " (".._INFM('CmdOn').."|".._INFM('CmdOff').."|".._INFM('CmdToggle')..")"	local lineFormat = "  |cffffffff/informant %s "..onOffToggle.."|r |cffff4020[%s]|r - %s"	chatPrint(_INFM('TextUsage'))	chatPrint("  |cffffffff/informant "..onOffToggle.."|r |cffff4020["..getLocalizedFilterVal('all').."]|r - " .. _INFM('HelpOnoff'))	chatPrint("  |cffffffff/informant ".._INFM('CmdDisable').."|r - " .. _INFM('HelpDisable'));	chatPrint(string.format(lineFormat, _INFM('ShowVendor'), getLocalizedFilterVal('show-vendor'), _INFM('HelpVendor')))	chatPrint(string.format(lineFormat, _INFM('ShowVendorSell'), getLocalizedFilterVal('show-vendor-sell'), _INFM('HelpVendorSell')))	chatPrint(string.format(lineFormat, _INFM('ShowVendorBuy'), getLocalizedFilterVal('show-vendor-buy'), _INFM('HelpVendorBuy')))	chatPrint(string.format(lineFormat, _INFM('ShowUsage'), getLocalizedFilterVal('show-usage'), _INFM('HelpUsage')))	chatPrint(string.format(lineFormat, _INFM('ShowMerchant'), getLocalizedFilterVal('show-merchant'), _INFM('HelpMerchant')))	chatPrint(string.format(lineFormat, _INFM('ShowStack'), getLocalizedFilterVal('show-stack'), _INFM('HelpStack')))	chatPrint(string.format(lineFormat, _INFM('ShowIcon'), getLocalizedFilterVal('show-icon'), _INFM('HelpIcon')))	chatPrint(string.format(lineFormat, _INFM('CmdEmbed'), getLocalizedFilterVal('embed'), _INFM('HelpEmbed')))	lineFormat = "  |cffffffff/informant %s %s|r |cffff4020[%s]|r - %s"	chatPrint(string.format(lineFormat, _INFM('CmdLocale'), _INFM('OptLocale'), getLocalizedFilterVal('locale'), _INFM('HelpLocale')))	lineFormat = "  |cffffffff/informant %s %s|r - %s"	chatPrint(string.format(lineFormat, _INFM('CmdDefault'), "", _INFM('HelpDefault')))end--The onOff(state, chatprint) function handles the state of the Informant AddOn (whether it is currently on or off)--If "on" or "off" is specified in the " state" variable then Informant's state is changed to that value,--If "toggle" is specified then it will toggle Informant's state (if currently on then it will be turned off and vice-versa)--If no keyword is specified then the functione will simply return the current state----If chatprint is "true" then the state will also be printed to the user.function onOff(state, chatprint)	if ((state == nil) or (state == "")) then		state = Informant.GetFilterVal("all")	elseif ((state == _INFM('CmdOn')) or (state == "on")) then		Informant.SetFilter("all", "on")	elseif ((state == _INFM('CmdOff')) or (state == "off")) then		Informant.SetFilter("all", "off")	elseif ((state == _INFM('CmdToggle')) or (state == "toggle")) then		Informant.SetFilter("all", not Informant.GetFilter("all"))		state = Informant.GetFilterVal("all")	end	--Print the change and alert the GUI if the command came from slash commands. Do nothing if they came from the GUI.	if (chatprint == true) then		if ((state == _INFM('CmdOn')) or (state == "on")) then			chatPrint(_INFM('StatOn'))			if (Informant_Khaos_Registered) then				Khaos.setSetKeyParameter("Informant", "enabled", "checked", true)			end		else			chatPrint(_INFM('StatOff'))			if (Informant_Khaos_Registered) then				Khaos.setSetKeyParameter("Informant", "enabled", "checked", false)			end		end	end	return stateendfunction restoreDefault(param, chatprint)	local oldLocale = InformantConfig.filters['locale']	local paramLocalized	if ( (param == nil) or (param == "") ) then		return	elseif ((param == _INFM('CmdClearAll')) or (param == "all")) then		param = "all";		InformantConfig.filters = {};	else		paramLocalized = param		param = delocalizeCommand(param)		Informant.SetFilter(param, nil);	end	-- Apply defaults for settings that went missing	Informant.SetFilterDefaults();	-- Apply new locale if needed	if (oldLocale ~= InformantConfig.filters['locale']) then setLocale(InformantConfig.filters['locale']); end	if (chatprint) then		if (param == "all") then			chatPrint(_INFM('FrmtActDefaultall'));			for k,v in pairs(InformantConfig.filters) do				setKhaosSetKeyValue(k, Informant.GetFilterVal(k));			end		else			chatPrint(string.format(_INFM('FrmtActDefault'), paramLocalized));			setKhaosSetKeyValue(param, Informant.GetFilterVal(param));		end	endendfunction genVarSet(variable, param, chatprint)	if (type(param) == "string") then		param = delocalizeFilterVal(param);	end	if (param == "on" or param == "off" or type(param) == "boolean") then		Informant.SetFilter(variable, param);	elseif (param == "toggle" or param == nil or param == "") then		param = Informant.SetFilter(variable, not Informant.GetFilter(variable));	end	if (chatprint) then		if (Informant.GetFilter(variable)) then			chatPrint(string.format(_INFM('FrmtActEnable'), localizeCommand(variable)))			setKhaosSetKeyValue(variable, true)		else			chatPrint(string.format(_INFM('FrmtActDisable'), localizeCommand(variable)))			setKhaosSetKeyValue(variable, false)		end	endendlocal function getKhaosLocaleList()	local options = { [_INFM('CmdDefault')] = 'default' };	for locale, data in InformantLocalizations do		options[locale] = locale;	end	return optionsendfunction registerKhaos()	local optionSet = {		id="Informant";		text="Informant";		helptext=function() 			return _INFM('GuiMainHelp')		end;		difficulty=1;		default={checked=true};		options={			{				id="Header";				text="Informant";				helptext=function() 					return _INFM('GuiMainHelp')				end;				type=K_HEADER;				difficulty=1;			};			{				id="enabled";				type=K_TEXT;				text=function() 					return _INFM('GuiMainEnable')				end;				helptext=function() 					return _INFM('HelpOnoff')				end;				callback=function(state)					onOff(state.checked)				end;				feedback=function(state)					if (state.checked) then						return _INFM('StatOn')					else						return _INFM('StatOff')					end				end;				check=true;				default={checked=true};				disabled={checked=false};				difficulty=1;			};			{				id="locale";				type=K_PULLDOWN;				setup = {					options = getKhaosLocaleList;					multiSelect = false;				};				text=function() 					return _INFM('GuiLocale')				end;				helptext=function() 					return _INFM('HelpLocale')				end;				callback = function(state)				end;				feedback = function (state)					setLocale(state.value);					return string.format(_INFM('FrmtActSet'), _INFM('CmdLocale'), state.value);				end;				default = {					value = getLocale();				};				disabled = {					value = getLocale();				};				dependencies={enabled={checked=true;}};				difficulty=2;			};			{				id="InformantInfoHeader";				type=K_HEADER;				text=function() 					return _INFM('GuiInfoHeader')				end;				helptext=function() 					return _INFM('GuiInfoHelp')				end;				difficulty=1;			};			{				id="show-icon";				type=K_TEXT;				text=function() 					return _INFM('GuiInfoIcon')				end;				helptext=function() 					return _INFM('HelpIcon')				end;				callback=function(state)					genVarSet("show-icon", state.checked)				end;				feedback=function(state)					if (state.checked) then						return (string.format(_INFM('FrmtActEnable'),  _INFM('ShowIcon')))					else						return (string.format(_INFM('FrmtActDisable'), _INFM('ShowIcon')))					end				end;				check=true;				default={checked=true};				disabled={checked=false};				dependencies={enabled={checked=true}};				difficulty=1;			};			{				id="show-stack";				type=K_TEXT;				text=function() 					return _INFM('GuiInfoStack')				end;				helptext=function() 

⌨️ 快捷键说明

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