diff --git a/GroupLeader.lua b/GroupLeader.lua index c5c6274..df98167 100755 --- a/GroupLeader.lua +++ b/GroupLeader.lua @@ -14,8 +14,8 @@ local colors = { ['Green'] = "g.dds", ['Blue'] = "b.dds", } -local textureKeys = GroupLeader.GetTableKeys(textures) -local colorKeys = GroupLeader.GetTableKeys(colors) +local textureKeys = GetTableKeys(textures) +local colorKeys = GetTableKeys(colors) local mapPinType = "GroupLeaderMap" local compassPinType = "GroupLeaderCompass" @@ -59,7 +59,7 @@ end local pinTooltipCreator = { creator = function(pin) --TODO - --InformationTooltip:AddLine("Tracking" .. leaderName) + InformationTooltip:AddLine("Tracker") end, tooltip = InformationTooltip, } @@ -113,21 +113,21 @@ end local function CommandHandler(text) -- Display help if text == nil or string.len(text) <= 0 or string.lower(text) == "help" then - GroupLeader.ChatMessage("GroupLeader Help:") - GroupLeader.ChatMessage("/gl : display help.") - GroupLeader.ChatMessage(" aliases: /groupleader, /gl help") - GroupLeader.ChatMessage("/gl leader : toggle leader tracking") - GroupLeader.ChatMessage("/gl map : toggle map tracking") - GroupLeader.ChatMessage("/gl compass : toggle compass tracking") - GroupLeader.ChatMessage("/gl add [name] -symbol -color : add a custom tracker") - GroupLeader.ChatMessage(" -symbol and -color are optional") - GroupLeader.ChatMessage(" e.g., /gl add adein -circle -red") - GroupLeader.ChatMessage("/gl del [name] : delete a custom tracker") - GroupLeader.ChatMessage("/gl clear : clear all custom trackers") + ChatMessage("GroupLeader Help:") + ChatMessage("/gl : display help.") + ChatMessage(" aliases: /groupleader, /gl help") + ChatMessage("/gl leader : toggle leader tracking") + ChatMessage("/gl map : toggle map tracking") + ChatMessage("/gl compass : toggle compass tracking") + ChatMessage("/gl add [name] -symbol -color : add a custom tracker") + ChatMessage(" -symbol and -color are optional") + ChatMessage(" e.g., /gl add adein -circle -red") + ChatMessage("/gl del [name] : delete a custom tracker") + ChatMessage("/gl clear : clear all custom trackers") elseif text ~= nil and string.len(text) > 0 then MapNamesToUnitTags() local input = string.lower(text) - local params = GroupLeader.SplitString(input) + local params = SplitString(input) local paramCount = table.getn(params) if params[1] == "leader" then db.leaderEnabled = not db.leaderEnabled @@ -137,7 +137,7 @@ local function CommandHandler(text) else status = "disabled" end - GroupLeader.ChatMessage("Tracking group leader " .. status) + ChatMessage("Tracking group leader " .. status) elseif params[1] == "map" then db.mapEnabled = not db.mapEnabled local status = nil @@ -146,7 +146,7 @@ local function CommandHandler(text) else status = "disabled" end - GroupLeader.ChatMessage("Map tracking " .. status) + ChatMessage("Map tracking " .. status) elseif params[1] == "compass" then db.compassEnabled = not db.compassEnabled local status = nil @@ -155,12 +155,12 @@ local function CommandHandler(text) else status = "disabled" end - GroupLeader.ChatMessage("Compass tracking " .. status) + ChatMessage("Compass tracking " .. status) elseif params[1] == "add" then local name = nil local symbol = 'Circle' local color = 'Red' - for paramCounter = 2, paramCounter, 1 do + for paramCounter = 2, paramCount, 1 do param = params[paramCounter] if string.sub(param, 1, string.len("-"))=="-" then local paramNoDash = string.sub(param, 2, -1) @@ -169,6 +169,7 @@ local function CommandHandler(text) if paramNoDash == tex then symbol = tex break + end end end if not color then @@ -176,6 +177,7 @@ local function CommandHandler(text) if paramNoDash == col then color = col break + end end end else @@ -190,14 +192,14 @@ local function CommandHandler(text) if unitTag then for k, v in pairs(trackers) do if v.tag == unitTag then - GroupLeader.ChatMessage("Already tracking that player!") + ChatMessage("Already tracking that player!") return end end table.insert(trackers, {tag=unitTag, name=name, symbol=symbol, color=color, X=0, Y=0}) - GroupLeader.ChatMessage("Now tracking " .. name) + ChatMessage("Now tracking " .. name) else - GroupLeader.ChatMessage("Player not found in group!") + ChatMessage("Player not found in group!") end elseif params[1] == "del" then local name = nil @@ -217,18 +219,18 @@ local function CommandHandler(text) end end if deleted then - GroupLeader.ChatMessage("Deleted " .. name .. " from tracking list") + ChatMessage("Deleted " .. name .. " from tracking list") else - GroupLeader.ChatMessage("Player not found in tracking list!") + ChatMessage("Player not found in tracking list!") end elseif params[1] == "clear" then - GroupLeader.ChatMessage("Clearing custom trackers") + ChatMessage("Clearing custom trackers") local trackerCount = table.getn(trackers) - 1 for trackerCounter = 1, trackerCount, 1 do table.remove(trackerCounter) end else - GroupLeader.ChatMessage("Unknown GroupLeader command!") + ChatMessage("Unknown GroupLeader command!") end end end @@ -291,7 +293,7 @@ local function RefreshAllPins() end -- Called on game UI updates -function GroupLeader.OnGroupLeaderUpdate(time) +function OnGroupLeaderUpdate(time) for k, v in pairs(trackers) do if v.tag then v.X, v.Y = GetMapPlayerPosition(v.tag) diff --git a/GroupLeader.xml b/GroupLeader.xml index 7170d0c..76cff9e 100755 --- a/GroupLeader.xml +++ b/GroupLeader.xml @@ -2,7 +2,7 @@ <Controls> <TopLevelControl name="GroupLeader"> <OnUpdate> - GroupLeader.OnGroupLeaderUpdate(time) + OnGroupLeaderUpdate(time) </OnUpdate> </TopLevelControl> </Controls> diff --git a/Util.lua b/Util.lua index 4d626bf..bc35d23 100755 --- a/Util.lua +++ b/Util.lua @@ -1,5 +1,5 @@ -- Get a list of the keys from a table -function GroupLeader.GetTableKeys(aTable) +function GetTableKeys(aTable) local keys = {} local n = 0 for k, v in pairs(aTable) do @@ -10,18 +10,11 @@ function GroupLeader.GetTableKeys(aTable) end -- Add a message to the chat window -function GroupLeader.ChatMessage(message) +function ChatMessage(message) CHAT_SYSTEM:AddMessage(message) end -function GroupLeader.RGBPercToHex(r, g, b) - r = r <= 1 and r >= 0 and r or 0 - g = g <= 1 and g >= 0 and g or 0 - b = b <= 1 and b >= 0 and b or 0 - return string.format("%02x%02x%02x", r*255, g*255, b*255) -end - -function GroupLeader.SplitString(input) +function SplitString(input) local result = {} local counter = 1 for s in string.gmatch(input, "%S+") do diff --git a/libs/CustomCompassPins/CustomCompassPins.lua b/libs/CustomCompassPins/CustomCompassPins.lua index 2ccaa5b..920346e 100755 --- a/libs/CustomCompassPins/CustomCompassPins.lua +++ b/libs/CustomCompassPins/CustomCompassPins.lua @@ -1,14 +1,14 @@ -- CustomCompassPins by Shinni -local version = 1.12 +local version = 1.13 local onlyUpdate = false if COMPASS_PINS then - if COMPASS_PINS.version and COMPASS_PINS.version >= version then - return - end - onlyUpdate = true + if COMPASS_PINS.version and COMPASS_PINS.version >= version then + return + end + onlyUpdate = true else - COMPASS_PINS = {} + COMPASS_PINS = {} end local PARENT = COMPASS.container @@ -21,77 +21,79 @@ local FOV = math.pi * 0.6 local CompassPinManager = ZO_ControlPool:Subclass() function COMPASS_PINS:New( ... ) - if onlyUpdate then - self:UpdateVersion() - else - self:Initialize( ... ) - end - - self.control:SetHidden(false) - self.control:SetHandler("OnUpdate", function() self:Update() end ) - self.version = version - self.defaultFOV = FOV - return result + if onlyUpdate then + self:UpdateVersion() + else + self:Initialize( ... ) + end + + self.control:SetHidden(false) + self.control:SetHandler("OnUpdate", function() self:Update() end ) + self.version = version + self.defaultFOV = FOV + --EVENT_MANAGER:RegisterForEvent("CustomCompassPins", EVENT_ZONE_CHANGED, function() +-- self:RefreshPins() end ) + return result end function COMPASS_PINS:UpdateVersion() - local pins = self.pinManager.pins - local data = self.pinManager.pinData - self.pinManager = CompassPinManager:New() - if pins then - self.pinManager.pins = pins - end - if data then - self.pinManager.pinData = data - end + --local pins = self.pinManager.pins + local data = self.pinManager.pinData + self.pinManager = CompassPinManager:New() + --if pins then + -- self.pinManager.pins = pins + --end + if data then + self.pinManager.pinData = data + end end function COMPASS_PINS:Initialize( ... ) - self.control = WINDOW_MANAGER:CreateControlFromVirtual("CP_Control", GuiRoot, "ZO_MapPin") - self.pinCallbacks = {} - self.pinLayouts = {} - self.pinManager = CompassPinManager:New() + self.control = WINDOW_MANAGER:CreateControlFromVirtual("CP_Control", GuiRoot, "ZO_MapPin") + self.pinCallbacks = {} + self.pinLayouts = {} + self.pinManager = CompassPinManager:New() end -- pinType should be a string eg "skyshard" -- pinCallbacks should be a function, it receives the pinManager as argument --- layout should be table, currently only the key texture is used (which should return a string) +-- layout should be table, currently only the key texture is used (which should return a string) function COMPASS_PINS:AddCustomPin( pinType, pinCallback, layout ) - self.pinCallbacks[ pinType ] = pinCallback - self.pinLayouts[ pinType ] = layout - self.pinManager:CreatePinType( pinType ) + self.pinCallbacks[ pinType ] = pinCallback + self.pinLayouts[ pinType ] = layout + self.pinManager:CreatePinType( pinType ) end -- refreshes/calls the pinCallback of the given pinType -- refreshes all custom pins if no pinType is given function COMPASS_PINS:RefreshPins( pinType ) - self.pinManager:RemovePins( pinType ) - if pinType then - if not self.pinCallbacks[ pinType ] then - return - end - self.pinCallbacks[ pinType ]( self.pinManager ) - else - for tag, callback in pairs( self.pinCallbacks ) do - callback( self.pinManager ) - end - end - + self.pinManager:RemovePins( pinType ) + if pinType then + if not self.pinCallbacks[ pinType ] then + return + end + self.pinCallbacks[ pinType ]( self.pinManager ) + else + for tag, callback in pairs( self.pinCallbacks ) do + callback( self.pinManager ) + end + end + end -- updates the pins (recalculates the position of the pins) function COMPASS_PINS:Update() - -- maybe add some delay, because pin update could be to expensive to be calculated every frame - local heading = GetPlayerCameraHeading() - if not heading then - return - end - if heading > math.pi then --normalize heading to [-pi,pi] - heading = heading - 2 * math.pi - end - - local x, y = GetMapPlayerPosition("player") - self.pinManager:Update( x, y, heading ) + -- maybe add some delay, because pin update could be to expensive to be calculated every frame + local heading = GetPlayerCameraHeading() + if not heading then + return + end + if heading > math.pi then --normalize heading to [-pi,pi] + heading = heading - 2 * math.pi + end + + local x, y = GetMapPlayerPosition("player") + self.pinManager:Update( x, y, heading ) end -- @@ -99,158 +101,163 @@ end -- function CompassPinManager:New( ... ) - - local result = ZO_ControlPool.New(self, "ZO_MapPin", PARENT, "Pin") - result:Initialize( ... ) - - return result + + local result = ZO_ControlPool.New(self, "ZO_MapPin", PARENT, "Pin") + result:Initialize( ... ) + + return result end function CompassPinManager:Initialize( ... ) - self.pins = {} - self.pinData = {} - self.defaultAngle = 1 + --self.pins = {} + self.pinData = {} + self.defaultAngle = 1 end function CompassPinManager:CreatePinType( pinType ) - self.pins[ pinType ] = {} + --self.pins[ pinType ] = {} end function CompassPinManager:GetNewPin( data ) - local pin, pinKey = self:AcquireObject() - table.insert( self.pins[ data.pinType ], pinKey ) - self:ResetPin( pin ) - pin:SetHandler("OnMouseDown", nil) - pin:SetHandler("OnMouseUp", nil) - pin:SetHandler("OnMouseEnter", nil) - pin:SetHandler("OnMouseExit", nil) - - pin.xLoc = data.xLoc - pin.yLoc = data.yLoc - pin.pinType = data.pinType - pin.pinTag = data.pinTag - - local layout = COMPASS_PINS.pinLayouts[ data.pinType ] - local texture = pin:GetNamedChild( "Background" ) - texture:SetTexture( layout.texture ) - - return pin, pinKey + local pin, pinKey = self:AcquireObject() + --table.insert( self.pins[ data.pinType ], pinKey ) + self:ResetPin( pin ) + pin:SetHandler("OnMouseDown", nil) + pin:SetHandler("OnMouseUp", nil) + pin:SetHandler("OnMouseEnter", nil) + pin:SetHandler("OnMouseExit", nil) + + pin.xLoc = data.xLoc + pin.yLoc = data.yLoc + pin.pinType = data.pinType + pin.pinTag = data.pinTag + + local layout = COMPASS_PINS.pinLayouts[ data.pinType ] + local texture = pin:GetNamedChild( "Background" ) + texture:SetTexture( layout.texture ) + + return pin, pinKey end -- creates a pin of the given pinType at the given location -- (radius is not implemented yet) function CompassPinManager:CreatePin( pinType, pinTag, xLoc, yLoc ) - local data = {} - - data.xLoc = xLoc - data.yLoc = yLoc - data.pinType = pinType - data.pinTag = pinTag - - table.insert(self.pinData, data) + local data = {} + + data.xLoc = xLoc + data.yLoc = yLoc + data.pinType = pinType + data.pinTag = pinTag + + table.insert(self.pinData, data) end function CompassPinManager:RemovePins( pinType ) - if not pinType then - self:ReleaseAllObjects() - self.pinData = {} - for pinType, _ in pairs( self.pins ) do - self.pins[ pinType ] = {} - end - else - if not self.pins[ pinType ] then - return - end - for _, pinKey in pairs( self.pins[ pinType ] ) do - self:ReleaseObject( pinKey ) - end - for key, data in pairs( self.pinData ) do - if data.pinType == pinType then - self.pinData[key] = nil - end - end - self.pins[ pinType ] = {} - end + if not pinType then + self:ReleaseAllObjects() + self.pinData = {} + --for pinType, _ in pairs( self.pins ) do + -- self.pins[ pinType ] = {} + --end + else + --if not self.pins[ pinType ] then + -- return + --end + --for _, pinKey in pairs( self.pins[ pinType ] ) do + -- self:ReleaseObject( pinKey ) + --end + for key, data in pairs( self.pinData ) do + if data.pinType == pinType then + if data.pinKey then + self:ReleaseObject( data.pinKey ) + end + self.pinData[key] = nil + end + end + --self.pins[ pinType ] = {} + end end function CompassPinManager:ResetPin( pin ) - for _, layout in pairs(COMPASS_PINS.pinLayouts) do - if layout.additionalLayout then - layout.additionalLayout[2]( pin ) - end - end + for _, layout in pairs(COMPASS_PINS.pinLayouts) do + if layout.additionalLayout then + layout.additionalLayout[2]( pin ) + end + end end function CompassPinManager:Update( x, y, heading ) - local value - local pin - local angle - local normalizedAngle - local xDif, yDif - local layout - local normalizedDistance - for _, pinData in pairs( self.pinData ) do - - layout = COMPASS_PINS.pinLayouts[ pinData.pinType ] - xDif = x - pinData.xLoc - yDif = y - pinData.yLoc - normalizedDistance = (xDif * xDif + yDif * yDif) / (layout.maxDistance * layout.maxDistance) - if normalizedDistance < 1 then - - if pinData.pinKey then - pin = self:GetExistingObject( pinData.pinKey ) - else - pin, pinData.pinKey = self:GetNewPin( pinData ) - end - - if pin then - --self:ResetPin( pin ) - pin:SetHidden( true ) - angle = -math.atan2( xDif, yDif ) - angle = (angle + heading) - if angle > math.pi then - angle = angle - 2 * math.pi - elseif angle < -math.pi then - angle = angle + 2 * math.pi - end - - normalizedAngle = 2 * angle / (layout.FOV or COMPASS_PINS.defaultFOV) - - if zo_abs(normalizedAngle) > (layout.maxAngle or self.defaultAngle) then - pin:SetHidden( true ) - else - - pin:ClearAnchors() - pin:SetAnchor( CENTER, PARENT, CENTER, 0.5 * PARENT:GetWidth() * normalizedAngle, 0) - pin:SetHidden( false ) - - if layout.sizeCallback then - layout.sizeCallback( pin, angle, normalizedAngle, normalizedDistance ) - else - if zo_abs(normalizedAngle) > 0.25 then - pin:SetDimensions( 36 - 16 * zo_abs(normalizedAngle), 36 - 16 * zo_abs(normalizedAngle) ) - else - pin:SetDimensions( 32 , 32 ) - end - end - - pin:SetAlpha(1 - normalizedDistance) - - if layout.additionalLayout then - layout.additionalLayout[1]( pin, angle, normalizedAngle, normalizedDistance) - end - - -- end for inside maxAngle - end --stupid lua has no continue/next in loops >_> - end - else - if pinData.pinKey then - self:ReleaseObject( pinData.pinKey ) - pinData.pinKey = nil - else - - end - end - end + local value + local pin + local angle + local normalizedAngle + local xDif, yDif + local layout + local normalizedDistance + for _, pinData in pairs( self.pinData ) do + + layout = COMPASS_PINS.pinLayouts[ pinData.pinType ] + xDif = x - pinData.xLoc + yDif = y - pinData.yLoc + normalizedDistance = (xDif * xDif + yDif * yDif) / (layout.maxDistance * layout.maxDistance) + if normalizedDistance < 1 then + + if pinData.pinKey then + pin = self:GetExistingObject( pinData.pinKey ) + else + pin, pinData.pinKey = self:GetNewPin( pinData ) + end + + if pin then + --self:ResetPin( pin ) + pin:SetHidden( true ) + angle = -math.atan2( xDif, yDif ) + angle = (angle + heading) + if angle > math.pi then + angle = angle - 2 * math.pi + elseif angle < -math.pi then + angle = angle + 2 * math.pi + end + + normalizedAngle = 2 * angle / (layout.FOV or COMPASS_PINS.defaultFOV) + + if zo_abs(normalizedAngle) > (layout.maxAngle or self.defaultAngle) then + pin:SetHidden( true ) + else + + pin:ClearAnchors() + pin:SetAnchor( CENTER, PARENT, CENTER, 0.5 * PARENT:GetWidth() * normalizedAngle, 0) + pin:SetHidden( false ) + + if layout.sizeCallback then + layout.sizeCallback( pin, angle, normalizedAngle, normalizedDistance ) + else + if zo_abs(normalizedAngle) > 0.25 then + pin:SetDimensions( 36 - 16 * zo_abs(normalizedAngle), 36 - 16 * zo_abs(normalizedAngle) ) + else + pin:SetDimensions( 32 , 32 ) + end + end + + pin:SetAlpha(1 - normalizedDistance) + + if layout.additionalLayout then + layout.additionalLayout[1]( pin, angle, normalizedAngle, normalizedDistance) + end + + end + else + d("CustomCompassPin Error:") + d("no pin with key : " .. pinData.pinKey .. ", found!") + end + else + if pinData.pinKey then + self:ReleaseObject( pinData.pinKey ) + pinData.pinKey = nil + else + + end + end + end end COMPASS_PINS:New() @@ -261,10 +268,10 @@ COMPASS_PINS:New() example: COMPASS_PINS:CreatePinType( "skyshard", function (pinManager) - for _, skyshard in pairs( mySkyshards ) do - pinManager:CreatePin( "skyshard", skyshard.x, skyshard.y ) - end - end, - { texture = "esoui/art/compass/quest_assistedareapin.dds" } ) - + for _, skyshard in pairs( mySkyshards ) do + pinManager:CreatePin( "skyshard", skyshard.x, skyshard.y ) + end + end, + { texture = "esoui/art/compass/quest_assistedareapin.dds" } ) + ]]-- \ No newline at end of file