﻿This application uses multiple plugin modules to enable more efficient storage and retrieval of map data.  Each map can have hundreds of default annotations, with 3 language possibilites for each resource string, multiplied by 176 maps, and there are many thousands of default annotations - if each map only has 100 annotations, that's 52,800 resource strings alone.  Keeping that information stored during the entire time the plugin is loaded will consume an excessive amount of memory with little if any benefit, not to mention the processing hit when all of those values have to be searched to display the current map's icons and seach list. For this reason, I chose to seperate the default data into separate files that only load the data for the currently selected map whenever the user makes a selection.

Great. So why multiple plugins? The custom annotations for each map are stored in .plugindata files. In an attempt to prevent interfacing with third party external applications in real time, Turbine does not allow plugins to save or load data from plugindata files in real time after the plugin has been initialized and prior to being unloaded. For this reason, there are two plugins that work together to allow the appearance of realtime data storage and retrieval. When the user selects a map, the main plugin "MoorMap" will load a secondary plugin, "MoorMapLoader" which exists solely to unload "MoorMap", which puts "MoorMap" into the "unloading" state and calls it's "Unload" method, allowing it to store a flag indicating that it is being reloaded as well as the current filter and search settings and the map to load. Then "MoorMapLoader" reloads "MoorMap".  Upon load, "MoorMap" checks for the "reloading" flag, and if present, loads the specified map, filter, and search settings while bypassing it's default settings.  This allows me to use far less memory and resources since I only retain the current map's annotations and resource strings in memory. This whole mechanism would be a LOT simpler without the ineffectual 15 second delay on saving/loading data (I say ineffectual because it is just an irritant to those who wish to write complex plugins that require external storage to be efficient and hasn't actually stopped anyone from accessing outside data in real time). I understand Turbine's concern, but the loss of efficiency in useful, legitimate plugins due to this mechanism is too high a price, especially when the restriction doesn't even work. OK. Enough soapboxing.

SETTING UP A SHORTCUT ALIAS FOR THE QUICK ANNOTATION TOOL:
The quick annotation tool can be accessed via a chat shortcut bound to a built-in quickslot. Unfortunately, this is not as simple as typeing the shortcut command since the ";loc" portion (or ";pos" for DE users) will resolve instantly and the value will be inserted into the shortcut. Getting around the ";loc" resolution requires use of the "/alias" command. "/alias" allows you to set up a string to represent another string when typing commands and is usually used to abbreviate long commands. In this case, we use it to avoid the auto resolution of ";loc":
1) set up an alias for "loc" using "/alias"
/alias ;abcdef loc

2) make sure you have nothing targetted (you can hit the "Esc" key to clear your current target) to avoid issues with ";target"

3) assign the quickslot using the alias - note the double semi-colons
/shortcut 70 /MoorMap add ;;abcdef:5::;target

4) clear the alias if you are done setting up quickslots - once the shortcut is assigned, the alias is no longer needed
/alias remove ;abcdef

EXTERNAL INTEGRATION USING THE "PING" COMMAND:
MoorMap can be controlled from an external plugin by adding a quickslot control with a shortcut command.  The shortcut can be programatically updated to contain the desired information so that when the user clicks on it, the correct map opens, an annotation is located or added and then a flashing "ping" is put on the map at the location.

The syntax for the "ping" command is fairly simple, "/Moormap ping MapID:NSCoord:EWCoord:Name:Description".  MapID is one of the predefined map IDs from the defaults.lua file. NSCoord is the North/South map coordinate, with north values being positive and south values being negative.  EWCoord is the East/West map coordinate with East values being positive and West values being negative.  Name is a short name that will be listed on the annotation and should be the proper name of the location/npc if possible to avoid creating duplicate annotations with different names. Description is the text that will be displayed when a user clicks on the annotation on the map.

Note, map ID and the coordinates must be valid for the map indicated or an error message will be written to the standard chat channel and no annotation will be added. Annotations with the same exact name within one map coordinate unit of each other will be considered to be the same annotation, no new annotation will be added, but the ping will display at the position in the ping command, either at or next to the existing annotation.

You may want to add an additional control on top of the quickslot control with a map icon for cosmetic purposes, just be sure to setMouseVisible(false) for the icon so that clicks will be sent through to the quickslot under it since the only way for Lua to actually cause an action is by user input.

Remember to verify that MoorMap is loaded when you set the shortcut command or it will not be able to respond.  To verify that MoorMap is loaded, use the following code:
	local found=false;
	for tmpIndex,tmpPlugin in ipairs(Turbine.PluginManager:GetLoadedPlugins()) do
		if tmpPlugin.Name=="MoorMap" then
			found=true;
			break;
		end
	end
	if not found then
		Turbine.PluginManager.LoadPlugin("MoorMap");
	end

You should test whether the user has installed MoorMap and use a variable to track that status so that you can conditionally enable/disable the quickslot functionality.  To test whether MoorMap is installed, use:

	MoorMapInstalled=false;
	Turbine.PluginManager:RefreshAvailablePlugins(); -- just in case the user installed MoorMap since the client has been running.
	for tmpIndex,tmpPlugin in ipairs(Turbine.PluginManager:GetAvailablePlugins()) do
		if tmpPlugin.Name=="MoorMap" then
			MoorMapInstalled=true;
			break;
		end
	end


If MoorMap has never been run before, it will automatically load it's defaults. MoorMap will load minimized by default (there are options to display on load or to hide the minimized icon in the Options dialog).

MAP IDs
The map IDs can be found in the defaults.lua file. The index of the tmpMap‌Info element is the ID of the map. The map name is in the comment at the end of the tmpMapInfo line.

OVERLAYS
An Overlay is just a transparent .tga file (or .jpg if you don't want transparency) used to show a guide or highlight a portion of a map. To use an Overlay, you must first create the .tga file. There is a very simple set of steps to creating most overlays.

First, make a screenshot of the map for which you want to create an Overlay. This will serve as a temporary background over which you will draw your Overlay so keep as many icons, etc. displayed as possible so that you will be able to better know where to draw for your Overlay.
Second, open the Overlay Maintenance window and check the size of the Map. The size shown in the Maintenance window is the native size before the map is stretched for your display. Most maps are natively drawn as 1024 x 768, but some are 1600 x 1200. It is easiest to create an overlay if your image is the same size as the map.
Third, open the screenshot in an image editor that allows "Layers". Paint.NET is free and does a wonderful job with Layers. Before you draw, you must resize the image to the native size - most players play in resolutions that are significantly higher than the native images so your screenshot will be the wrong size. Once the image is resized, you will add a layer so that you can draw on top of the screenshot while keeping your drawing separate from the screenshot. Now draw all of the information that you want on your overlay, leaving the rest of the new layer transparent. When you are finished drawing, remove the first layer (the original screenshot) and save the resulting image as a .tga file.
Last, copy the .tga file to the "...My Documents\The Lord of the Rings Online\Plugins\GaranStuff\MoorMap\Overlays" folder. You can organize your overlays by creating a subfolder inside the Overlays folder.

Now, in the game client, load MoorMap, open the map for the Overlay and open the Overlay Maintenance window. In the Overlay info area, select "New", enter a descriptive name and enter the file name of the .tga file. If you have entered the file name correctly (including any subfolder path you may have created) the Size fields will display the size of the .tga file. Leave the Position fields blank unless you want your overlay offset from the map (once you get used to creating overlays, you can create smaller overlays and display them offset on the map to save file space). Click "Save" and your overlay will be displayed on the map and will show in the "Show/Order" listbox.
In the Show/Order listbox, you can select which overlays should display - you may choose to leave some overlays defined but not shown to save memory until you need to see them (the client is notorious for retaining Lua images in memory when they are no longer needed). You can also determine the order in which the overlays are displayed, those higher in the list are displayed on top of those lower in the list. That way if one overlay partially masks another, you can decide which one should be on top.
