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

📄 jotter-k.lua

📁 时间太紧了
💻 LUA
字号:
--[[
	Jotter-K v1.1c
	Author: jason.slaughter@gmail.com

	In-game notepad concept by Olios (original Jotter 0.4)
]]

BINDING_HEADER_JOTTERHEADER = "JotterK";

JotterK = {
	["共享"] = {
		[1] = "欢迎使用JotterK记事本\n\n您可以使用 /jt # 来跳到你想要去的页数\n ( # 代表您要去的页数)",
	},
	["Bookmarks"] = {}
};

Jotter = {
	version = "v1.1c";
	page = 1;
	user = "共享";
	bookmarks = nil;

	clearAll = function()
		Jotter.user = "共享";
		Jotter.page = 1;

		JotterK = {
			["Bookmarks"] = {},
			["共享"] = {
				[1] = "欢迎使用JotterK记事本\n\n您可以使用 /jt # 来跳到你想要去的页数\n ( # 代表您要去的页数)",
			},
		};
	end;

	onLoad = function()
		this:RegisterEvent("VARIABLES_LOADED");

		SlashCmdList["JOTTER"] = function (msg) Jotter.slashHandler(msg); end;
		SLASH_JOTTER1 = "/jotter";
		SLASH_JOTTER2 = "/jt";

		if ( EarthFeature_AddButton ) then
			EarthFeature_AddButton (
				           { 
						id = "jotter";
						name = "JotterK记事本";
						subtext = "使用";
						tooltip = "WOW中的多功能记事本";
						icon = "Interface\\Icons\\INV_Misc_Book_09";
						callback = Jotter.toggle;
				        	}
			        	);
		end
		
		if( DEFAULT_CHAT_FRAME ) then
			--DEFAULT_CHAT_FRAME:AddMessage("Jotter "..Jotter.version.." loaded.");
		end
		tinsert(UISpecialFrames,"JotterFrame");

		end;
		
	onEvent = function(event)
		if ( event == "VARIABLES_LOADED" ) then
			Jotter.varsLoaded = 1;
			if ( JotterK[1] ) then
				local newTable = Jotter.copyTable(JotterK);
				JotterK = {
					["Bookmarks"] = {},
				};
				JotterK["共享"] = Jotter.copyTable(newTable);
			end
			 gLim_RegisterButton (
			"jotter",
			"记事本",
			"Interface\\AddOns\\Jotter-K\\Icon", 
			function()	
				if( JotterFrame:IsVisible() ) then
					JotterFrame:Hide();
				else
					JotterFrame:Show();
				end
			end,
			4,
			10
			);
		end
	end;

	slashHandler = function(msg)
		if ( msg == "clear" ) then
			if ( Jotter.page ~= 1 and Jotter.page == getn(JotterK[Jotter.user]) ) then
				JotterK[Jotter.user][Jotter.page] = nil;
				Jotter.page = Jotter.page - 1;
			else
				JotterK[Jotter.user][Jotter.page] = "";
			end
			Jotter.onShow();
			return;
		elseif ( msg == "clearall" ) then
			Jotter.clearAll();
			Jotter.onShow();
			return;
		elseif ( msg == "help" ) then
			Jotter.chat("version "..Jotter.version.."\nType /jt to toggle Jotter.\n/jt bookmark clearall: Clear all bookmarks\n/jt <#>: Jump to <#>\n/jt clear: Clear current page\n/jt clearall: Clear all pages");
		elseif ( strfind(msg,"bookmark") ) then
			Jotter.tab.slashCmd(msg);
			return;
		elseif ( tonumber(msg) and JotterK[Jotter.user][tonumber(msg)] ) then
			Jotter.page = tonumber(msg);
			Jotter.onShow();
		else
			Jotter.toggle();
		end
	end;

	toggle = function()
		if( JotterFrame:IsVisible() ) then
			JotterFrame:Hide();
		else
			JotterFrame:Show();
		end
	end;

	onShow = function()
		Jotter.checkUser();
		Jotter.tab.init();
		local totalPages = getn(JotterK[Jotter.user]);
		local totalBookmarks = Jotter.tab.getTotal(Jotter.bookmarks);

		JotterCurrentPage:SetText(Jotter.page.." / "..totalPages.."页");
		JotterEditBox:SetText(JotterK[Jotter.user][Jotter.page]);

		if ( Jotter.page > 1 ) then
			JotterPrevPageButton:Enable();
		else
			JotterPrevPageButton:Disable();
		end
		if ( Jotter.page < totalPages ) then
			JotterNextPageButton:Enable();
		else
			JotterNextPageButton:Disable();
		end
		if ( totalPages < 254 ) then
			JotterNewPageButton:Enable();
		else
			JotterNewPageButton:Disable();
		end
		if ( totalBookmarks < 8 ) then
			JotterNewBookmarkButton:Enable();
		else
			JotterNewBookmarkButton:Disable();
		end
	end;

	updateText = function()
		JotterK[Jotter.user][Jotter.page] = JotterEditBox:GetText();
		JotterFrameSaveButtonTextLength:SetText(strlen(JotterEditBox:GetText()).." / 800 字符");
	end;

	changePage = function(back)
		if ( back and (Jotter.page - 1 ~= 0)) then
			Jotter.page = Jotter.page - 1;
		elseif ( (not back) and (Jotter.page + 1 <= getn(JotterK[Jotter.user])) ) then
			Jotter.page = Jotter.page + 1;
		else
			return;
		end

		PlaySound("igAbiliityPageTurn");
		Jotter.onShow();
	end;

	newPage = function()
		local nextPage = getn(JotterK[Jotter.user]) + 1;
		if ( nextPage < 255 and not JotterK[Jotter.user][nextPage] ) then
			JotterK[Jotter.user][nextPage] = "";
			Jotter.page = nextPage;
		end
		PlaySound("igAbiliityPageTurn");
		Jotter.onShow();
	end;

	newBookmark = function()
		local nextBookmark = Jotter.tab.getTotal() + 1;
		if ( nextBookmark <= 8 ) then
			Jotter.bookmarks[nextBookmark] = {
				["page"] = Jotter.page,
				["user"] = Jotter.user
			};
			table.setn(Jotter.bookmarks,Jotter.tab.getTotal());
			Jotter.tab.init();
		end
	end;

	checkUser = function()
		if ( not Jotter.bookmarks ) then
			if ( UnitName("player") ~= UNKNOWNOBJECT and not JotterK[UnitName("player").." 在 "..GetCVar("realmName")] ) then
				Jotter.addUser(UnitName("player").." 在 "..GetCVar("realmName"));
			end
			Jotter.user = UnitName("player").." 在 "..GetCVar("realmName");
			Jotter.bookmarks = JotterK["Bookmarks"][Jotter.user];
			JotterFrame:Hide();
			JotterFrame:Show();
			UIDropDownMenu_SetSelectedValue(Jotter_UserDropdown, Jotter.user);
		end
	end;

	addUser = function(user)
		if ( not JotterK[user] ) then
			JotterK[user] = {
				[1] = "欢迎, "..user
			};
			JotterK["Bookmarks"][user] = {};
		end
	end;

	userDropdown = {
		onLoad = function()
			UIDropDownMenu_Initialize(this, Jotter.userDropdown.init);
			UIDropDownMenu_SetSelectedValue(this, Jotter.user);
			UIDropDownMenu_SetWidth(240, Jotter_UserDropdown);
			OptionsFrame_EnableDropDown(Jotter_UserDropdown);
		end;

		init = function()
			local selectedValue = UIDropDownMenu_GetSelectedValue(Jotter_UserDropdown);
			local info;

			info = {};
			info.text = "共享";
			info.value = "共享";
			info.func = Jotter.userDropdown.onClick;
			if ( selectedValue == info.value ) then
				info.checked = 1;
			else
				info.checked = nil;
			end
			UIDropDownMenu_AddButton(info);

			for key, val in JotterK do
				local _,_,playerName,realmName = strfind(key,"(.+) 在 (.+)");
				if ( playerName and realmName and realmName == GetCVar("realmName") ) then
					info = {};
					info.text = key;
					info.value = key;
					info.func = Jotter.userDropdown.onClick;
					if ( selectedValue == info.value ) then
						info.checked = 1;
					else
						info.checked = nil;
					end
					UIDropDownMenu_AddButton(info);
				end
			end
		end;

		onClick = function()
			UIDropDownMenu_SetSelectedValue(Jotter_UserDropdown, this.value);
			if ( this.value ) then
				Jotter.user = this.value;
			end
			Jotter.page = 1;
			Jotter.onShow();
		end;
	};

	tab = {
		lastClicked = nil;

		getTotal = function()
			local total = 0;
			for key, val in Jotter.bookmarks do
				if ( tonumber(key) ) then
					total = total + 1;
				end
			end
			return total;
		end;

		onLoad = function()
			this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
			this:SetNormalTexture("Interface\\Icons\\INV_Misc_Note_01");
			this.tooltip = "Bookmark "..this:GetID();
		end;

		onClick = function(button, id)
			if ( IsAltKeyDown() ) then
				tremove(Jotter.bookmarks,id);
				Jotter.tab.init();
			elseif ( button == "RightButton" ) then
				Jotter.tab.lastClicked = id;
				local dialog = StaticPopup_Show("JOTTER_BOOKMARK");
			elseif ( Jotter.bookmarks[id] and Jotter.bookmarks[id].page and Jotter.bookmarks[id].user and JotterK[Jotter.bookmarks[id].user] and JotterK[Jotter.bookmarks[id].user][Jotter.bookmarks[id].page] ) then
				Jotter.page = Jotter.bookmarks[id].page;
				Jotter.user = Jotter.bookmarks[id].user;
				UIDropDownMenu_SetSelectedValue(Jotter_UserDropdown, Jotter.user);
				Jotter.onShow();
			else
				tremove(Jotter.bookmarks,id);
				Jotter.tab.init();
			end
			JotterEditBox:ClearFocus();
		end;

		init = function()
			for num = 1, 8 do
				if ( Jotter.bookmarks[num] ) then
					getglobal("JotterTab"..num):Show();
					if ( Jotter.bookmarks[num].name ) then
						getglobal("JotterTab"..num).tooltip = num.." - "..Jotter.bookmarks[num].name;
					else
						getglobal("JotterTab"..num).tooltip = "书签"..num;
					end
				else
					getglobal("JotterTab"..num):Hide();
				end
			end

			local totalBookmarks = Jotter.tab.getTotal(Jotter.bookmarks);
			if ( totalBookmarks < 8 ) then
				JotterNewBookmarkButton:Enable();
			else
				JotterNewBookmarkButton:Disable();
			end
		end;

		slashCmd = function(msg)
			local totalBookmarks = Jotter.tab.getTotal();
			if ( strfind(msg,"clearall") ) then
				Jotter.bookmarks = {};
			else
				Jotter.chat("To clear all bookmarks type: /jt bookmark clearall");
			end
			Jotter.tab.init();
		end;
	};

	-- Aux Funcs
	chat = function(msg,error)
		if( DEFAULT_CHAT_FRAME ) then
			if ( error ) then
				DEFAULT_CHAT_FRAME:AddMessage("<Jotter> "..msg, 1.0, 0.5, 0.0);
			else
				DEFAULT_CHAT_FRAME:AddMessage("<Jotter> "..msg, 1.0, 1.0, 0.0);
			end
		end
	end;

	copyTable = function(table, lookupTable)
		local copy = {};
		if ( not table ) then
			return {};
		end
		for key, val in table do
			if ( type(val) ~= "table" ) then
				copy[key] = val;
			else
				lookupTable = lookupTable or {};
				lookupTable[table] = copy;
				if ( lookupTable[val] ) then
					copy[key] = lookupTable[val];
				else
					copy[key] = Jotter.copyTable(val, lookupTable);
				end
			end
		end
		return copy;
	end;

	reloadOnEnter = function()
		local tipText = "重载插件\n"..NORMAL_FONT_COLOR_CODE.."重新载入您的插件"..FONT_COLOR_CODE_CLOSE;
		tipText = tipText.."\n\n|cff00ff00笔记本在你写字的时候进行保\n存,但是如果游戏没有正常退\n出刚刚做的改变将不会保存,\n重新载入插件将强制保存到磁\n盘的SavedVariables.lua文件中。\n"..FONT_COLOR_CODE_CLOSE;

		GameTooltip_SetDefaultAnchor(GameTooltip, this);
		GameTooltip:SetText(tipText,1.0,1.0,1.0);		
	end;

	portraitOnEnter = function()
		local tipText = "笔记本 "..Jotter.version.."\n"..NORMAL_FONT_COLOR_CODE.."欢迎使用您的笔记本"..FONT_COLOR_CODE_CLOSE;
		tipText = tipText.."\n\n|cff00ff00本插件是一个WOW中的记事本每一\n个用户最多可以有254页笔记,您\n可以点击书签到您想去页面,您也\n可以按住Alt单击他们来删除。"..FONT_COLOR_CODE_CLOSE;

		GameTooltip_SetDefaultAnchor(GameTooltip, this);
		GameTooltip:SetText(tipText,1.0,1.0,1.0);
	end;
};

StaticPopupDialogs["JOTTER_BOOKMARK"] = {
	text = TEXT("请输入书签的名字"),
	button1 = TEXT(ACCEPT),
	button2 = TEXT(CANCEL),
	hasEditBox = 1,
	maxLetters = 32,
	OnAccept = function()
		local id = Jotter.tab.lastClicked;
		local text = getglobal(this:GetParent():GetName().."EditBox"):GetText();
		if ( id and Jotter.bookmarks[id] ) then
			Jotter.bookmarks[id].name = text;
		end
		Jotter.tab.init();
	end,
	EditBoxOnEnterPressed = function()
		local id = Jotter.tab.lastClicked;
		local text = getglobal(this:GetParent():GetName().."EditBox"):GetText();
		if ( id and Jotter.bookmarks[id] ) then
			Jotter.bookmarks[id].name = text;
		end
		Jotter.tab.init();
	end,
	OnShow = function()
		local id = Jotter.tab.lastClicked;
		if ( id and Jotter.bookmarks[id] and Jotter.bookmarks[id].name ) then
			getglobal(this:GetName().."EditBox"):SetText(Jotter.bookmarks[id].name);
		end
		getglobal(this:GetName().."EditBox"):SetFocus();
	end,
	OnHide = function()
		if ( ChatFrameEditBox:IsVisible() ) then
			ChatFrameEditBox:SetFocus();
		end
		getglobal(this:GetName().."EditBox"):SetText("");
		Jotter.tab.lastClicked = nil;
	end,
	timeout = 0,
	exclusive = 1
};

⌨️ 快捷键说明

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