diff --git a/HarvestRoute.lua b/HarvestRoute.lua
index 55a0c17..ff41171 100644
--- a/HarvestRoute.lua
+++ b/HarvestRoute.lua
@@ -1,15 +1,20 @@
HarvestRoute = {}
HarvestRoute.name = "HarvestRoute"
HarvestRoute.displayName = 'HarvestRoute for Harvestmap'
-HarvestRoute.version = "1.0.5"
+HarvestRoute.version = "1.0.6"
HarvestRoute.author = "generic"
-HarvestRoute.settingsVersion = 2
+HarvestRoute.settingsVersion = 3
HarvestRoute.savedVars = {}
HarvestRoute.defaultSettings = {
trackerRange = 5,
enableTrackerWindow = true,
- showTrackerWindow = false
+ showTrackerWindow = false,
+ usePathHeuristic = true,
+ wm = {
+ x = 1500,
+ y = 0,
+ },
}
local LibAddonMenu2 = LibAddonMenu2
@@ -94,7 +99,7 @@ local function initialize( eventCode, addOnName )
EVENT_MANAGER:RegisterForEvent("HarvestRoutePlayerActivated", EVENT_PLAYER_ACTIVATED, HarvestRoute.OnPlayerLoaded )
Harvest.callbackManager:RegisterForEvent(Harvest.events.TOUR_CHANGED, HarvestRoute.checkPath )
-
+ HarvestRoute.ApplyStyle()
if HarvestRoute.savedVars.enableTrackerWindow and HarvestRoute.savedVars.showTrackerWindow then
HarvestRoute:SetTrackerHidden( false )
HarvestRoute:InitTracker()
@@ -149,7 +154,6 @@ function HarvestRoute:InitializeSettingsMenu()
default = HarvestRoute.defaultSettings.showTrackerWindow,
disabled = TrackerWindowDisabled,
},
-
{
type = "slider",
name = HarvestRoute.GetLocalization("routerangemultiplier"),
@@ -159,7 +163,17 @@ function HarvestRoute:InitializeSettingsMenu()
getFunc = function () return HarvestRoute.savedVars.trackerRange end,
setFunc = function (value) HarvestRoute.savedVars.trackerRange = value end,
default = HarvestRoute.defaultSettings.trackerRange,
- }
+ },
+ {
+ type = "checkbox",
+ name = HarvestRoute.GetLocalization("usepathheuristics"),
+ tooltip = HarvestRoute.GetLocalization("usepathheuristicstooltip"),
+ getFunc = function () return HarvestRoute.savedVars.usePathHeuristic end,
+ setFunc = function (value)
+ HarvestRoute.savedVars.usePathHeuristic = value
+ end,
+ default = HarvestRoute.defaultSettings.usePathHeuristic,
+ },
}
LibAddonMenu2:RegisterAddonPanel(HarvestRoute.name.."OptionsMenu", panel)
LibAddonMenu2:RegisterOptionControls(HarvestRoute.name.."OptionsMenu", options)
@@ -278,6 +292,9 @@ function HarvestRoute:OnUpdate (time)
else
if pathNodeId then
HarvestRoute:debug('insert '..nodeId..' after path node '..pathNodeId..' ')
+ if HarvestRoute.savedVars.usePathHeuristic then
+ pathNodeId = HarvestRoute:checkPathHeuristic(pathNodeId, lastNodeAddedToPath, nodeId)
+ end
Farm.path:InsertAfter(pathNodeId, nodeId)
pathNodeId = nodeId
lastNodeAddedToPath = nodeId
@@ -311,6 +328,45 @@ function HarvestRoute:OnUpdate (time)
end --isActive
end
+function HarvestRoute:getNodeDistance(n1, n2)
+ local distance = 0
+ if MapCache.worldX and MapCache.worldX[n1] and MapCache.worldX[n2] then
+ local dx = MapCache.worldX[n1] - MapCache.worldX[n2]
+ local dy = MapCache.worldX[n1] - MapCache.worldX[n2]
+ distance = ( dx * dx + dy * dy ) ^ 0.5
+ end
+ return distance
+end
+
+function HarvestRoute:GetNextPathNode(nodeId)
+ local index = Farm.path:GetIndex(nodeId)
+ if not index then return nil end
+ index = ((index + 1) % Farm.path.numNodes)
+ return Farm.path.nodeIndices[index]
+end
+
+-- be "smart" and detect which of n1 or n2 adds less total length, to prevent zigzag accidents when backtracking
+function HarvestRoute:checkPathHeuristic(n1, n2, addNode)
+ if not n2 then return n1 end
+ if n1 == n2 then return n1 end
+ HarvestRoute:debug("checkPathHeuristic " .. n1 .." / ".. n2 .. " (" .. addNode ..")")
+ if Farm.path then
+ local n1next = HarvestRoute:GetNextPathNode(n1)
+ local n2next = HarvestRoute:GetNextPathNode(n2)
+ if n1next and n2next then
+ local d1 = HarvestRoute:getNodeDistance(n1, addNode) + HarvestRoute:getNodeDistance(n1next, addNode) - HarvestRoute:getNodeDistance(n1, n1next)
+ local d2 = HarvestRoute:getNodeDistance(n2, addNode) + HarvestRoute:getNodeDistance(n2next, addNode) - HarvestRoute:getNodeDistance(n2, n2next)
+ HarvestRoute:debug("Lastpathnode " .. d1 .. " / Lastinsertnode " .. d2 )
+ if d2 < d1 then
+ return n2
+ end
+ else
+ HarvestRoute:debug("NOT IN PATH n1 and n2")
+ end
+ end
+ return n1
+end
+
-- get the closest node to the player, using HarvestMap MapCache Divisions (and only check 4 divisions, from -50 to +50 from current position)
function HarvestRoute:GetClosestNode()
local bestNodeId = nil
@@ -390,6 +446,18 @@ function HarvestRoute:GetClosestNode()
end
-- UI element management
+function HarvestRoute:OnMoveStop( )
+ HarvestRoute.savedVars.wm.x = self:GetLeft()
+ HarvestRoute.savedVars.wm.y = self:GetTop()
+ HarvestRoute.savedVars.wm.width = self:GetWidth()
+ HarvestRoute.savedVars.wm.height = self:GetHeight()
+end
+
+function HarvestRoute:ApplyStyle()
+ HarvestRouteTracker:SetAnchor( TOPLEFT, GuiRoot, TOPLEFT, HarvestRoute.savedVars.wm.x, HarvestRoute.savedVars.wm.y )
+end
+
+
function HarvestRoute:SetTrackerHidden(value)
isTrackerVisible = false
if not HarvestRoute.savedVars.enableTrackerWindow then value = true end
@@ -444,7 +512,7 @@ function HarvestRoute:InitTracker()
end
function HarvestRoute:UpdateTracker()
- HarvestRoute:debug('UpdateTracker')
+ -- HarvestRoute:debug('UpdateTracker')
if not HarvestRoute.savedVars.enableTrackerWindow then
if isTrackerVisible then
HarvestRoute:SetTrackerHidden( true )
@@ -492,7 +560,7 @@ function HarvestRoute:UpdateTracker()
end
function HarvestRoute:debug(text)
- --CHAT_SYSTEM:AddMessage(text)
+ CHAT_SYSTEM:AddMessage(text)
end
EVENT_MANAGER:RegisterForEvent("HarvestRoute", EVENT_ADD_ON_LOADED, initialize)
\ No newline at end of file
diff --git a/Localization/de.lua b/Localization/de.lua
index 9cfe7df..51dc694 100644
--- a/Localization/de.lua
+++ b/Localization/de.lua
@@ -1,4 +1,5 @@
HarvestRoute.localizedStrings = {
+ -- Konfigurationstexte
["addonsettingstext"] = "Der HarvestRoute Tracker verwendet eine eigene Einstellung für die Reichweite der Node-Erkennung. Diese sollte normalerweise deutlich kleiner als die Sammel-Reichweite sein um sicherzustellen, dass nur Nodes hinzugefügt werden, die gezielt angelaufen wurden.",
["routenodes"] = "Visited Nodes and Farming Helper",
["routerangemultiplier"] = "Tracking Node Reichweite",
@@ -7,7 +8,10 @@ HarvestRoute.localizedStrings = {
["enabletrackerwindowtooltip"] = "Zeigt Farmtour-Infos, die nächste Resource und die letzte Resource der aktuellen Tour",
["showtrackerwindow"] = "Tracker Fenster automatisch anzeigen",
["showtrackerwindowtooltip"] = "Wenn ausgeschaltet wird der Tracker nur angezeigt wenn Du das Tracking startest",
+ ["usepathheuristics"] = "SmartPath aktivieren",
+ ["usepathheuristicstooltip"] = "Diese Einstellung reduziert Zickzack-Routen, indem geprüft wird ob eine neue Ressource nach der letzten HINZUGEFÜGTEN oder der letzten BESUCHTEN Ressource einen kürzeren Pfad erzeugt",
+ -- Tracker-Fenster
["trackeractive"] = "|C7FCF7FTracker läuft|r",
["trackerinactive"] = "|CFF7F7FTracker ist aus|r",
["pathinfomissing"] = "|CFF7F7Fkeine Tour aktiv|r",
@@ -19,7 +23,7 @@ HarvestRoute.localizedStrings = {
["lastpathnodetooltip"] = "Neue Nodes werden nach dieser Resource-Node in der Tour eingefügt",
["nodeinfounknown"] = "|CA0A0A0keine Node innerhalb von 50 m|r",
-
+ --- Harvestmap Tour Generator
["tourtrackerdescription"] = [[Nutze den Tracker um neue Nodes automagisch nach der zuletzt besuchten Node einzufügen.
Wenn noch keine Tour existiert, wird nach der 3. Node eine erstellt.
]] ,
diff --git a/Localization/default.lua b/Localization/default.lua
index d2041b9..e0e04c6 100644
--- a/Localization/default.lua
+++ b/Localization/default.lua
@@ -1,35 +1,36 @@
HarvestRoute.defaultLocalizedStrings = {
- -- top level description
-
-
-
- addonsettingstext = "The HarvestRoute Tour Tracker uses a separate range for node detection. Usually this should be considerably lower than the normal detection range to make sure, that you actually walked very close to a node to be added.",
+ -- configuration texts
+ addonsettingstext = "The HarvestRoute Tour Tracker uses a separate range for node detection. Usually this should be considerably lower than the normal detection range to make sure, that you actually walked very close to a node to be added.",
routenodes = "Visited Nodes and Farming Helper",
routerangemultiplier = "Tour tracking node range",
routerangemultipliertooltip = "Nodes within X meters are considered as visited by the tour tracker.",
enabletrackerwindow = "enable Tracker window",
enabletrackerwindowtooltip = "display tour info, nearest resource, and the last node from tour",
- showtrackerwindow = "always show Tracker window",
- showtrackerwindowtooltip = "if disabled, the Tracker window will only be shown once you activate the Tracker",
+ showtrackerwindow = "always show Tracker window",
+ showtrackerwindowtooltip = "if disabled, the Tracker window will only be shown once you activate the Tracker",
+ usepathheuristics = "enable smartpath",
+ usepathheuristicstooltip = "This option reduces zigzag paths by determining if inserting new resources after the last ADDED or the last VISITED node creates a shorter path",
+ -- tracker window
trackeractive = "|C7FCF7FTracker is active|r",
- trackerinactive = "|CFF7F7FTracker is off|r",
+ trackerinactive = "|CFF7F7FTracker is off|r",
pathinfomissing = "|CFF7F7Fno tour active|r",
- pathinfotitle = "current tour:",
- pathinfo = "<<1>> nodes |CA0A0A0(<<2>> m length)|r",
- nearestnodetitle = "nearest resource:",
- nearestnodetooltip = "the nearest resource to your position, that is not included in the current tour",
- lastpathnodetitle = "last resource from tour:",
- lastpathnodetooltip = "new nodes will be inserted after this node",
- nodeinfounknown = "|CA0A0A0no node within 50m|r",
+ pathinfotitle = "current tour:",
+ pathinfo = "<<1>> nodes |CA0A0A0(<<2>> m length)|r",
+ nearestnodetitle = "nearest resource:",
+ nearestnodetooltip = "the nearest resource to your position, that is not included in the current tour",
+ lastpathnodetitle = "last resource from tour:",
+ lastpathnodetooltip = "new nodes will be inserted after this node",
+ nodeinfounknown = "|CA0A0A0no node within 50m|r",
nodeinfo = [[<<1>> |CA0A0A0(<<2>> m)|r]],
- tourtrackerdescription = [[Use the tour tracker to automatically insert new nodes after the last visited node included in your tour.
- If there is no tour yet, one will be created after you visited at least 3 nodes.
+ -- harvestmap tour generator
+ tourtrackerdescription = [[The tour tracker will automatically insert new nodes after the last visited node included in your tour.
+ If there is no tour yet, one will be created after you visited at least 3 nodes, which must not be "unknown".
]],
- buttonstarttracker = "Enable tracking",
- buttonstoptracker = "Disable tracking",
+ buttonstarttracker = "Enable tracking",
+ buttonstoptracker = "Disable tracking",
}
local default = HarvestRoute.defaultLocalizedStrings
diff --git a/Localization/fr.lua b/Localization/fr.lua
index 36cc8eb..19dbbd4 100644
--- a/Localization/fr.lua
+++ b/Localization/fr.lua
@@ -9,6 +9,7 @@ HarvestRoute.localizedStrings = {
["enabletrackerwindowtooltip"] = "Affiche les informations sur le parcours, la ressource la plus proche et le dernier nœud du parcours.",
["showtrackerwindow"] = "Toujours afficher la fenêtre du Tracker",
["showtrackerwindowtooltip"] = "Lorsque cette option est désactivée, la fenêtre du tracker ne s'affichera qu'une fois que vous aurez activé le tracker.",
+ ["usepathheuristics"] = "Activer SmartPath",
["trackeractive"] = "|C7FCF7FLe tracker est activé|r",
["trackerinactive"] = "|CFF7F7FLe tracker est désactivé|r",
diff --git a/Tracker.xml b/Tracker.xml
index 0cdc165..8484355 100644
--- a/Tracker.xml
+++ b/Tracker.xml
@@ -1,7 +1,10 @@
<GuiXml>
<Controls>
<TopLevelControl name="HarvestRouteTracker" mouseEnabled="true" movable="true" hidden="true">
- <Anchor point="TOPRIGHT" offsetX="0" offsetY="0" />
+ <Anchor point="TOPLEFT" offsetX="0" offsetY="0" />
+ <OnMoveStop>
+ HarvestRoute.OnMoveStop( self )
+ </OnMoveStop>
<Dimensions x="300" y="250"/>
<Controls>
<Backdrop name="$(parent)BG" inherits="ZO_DefaultBackdrop" >