WoWInterface SVN AlphaMapFansUpdate

[/] [branches/] [AlphaMapBeta/] [AlphaMap_POI_Instances/] [AlphaMap_POI_Instances.lua] - Rev 12

Compare with Previous | Blame | View Log


-- The toggling of these POIs on/off is controlled by a variable
-- stored within the main AlphaMap SavedVariables .iLocs
-- A loop through AlphaMapConfigurations saves it as a global AlphaMap variable

-- Templates for these plugins is in the main AlphaMap AddOn


local AlphaMap_POI_Instances_Frame = CreateFrame("Frame");


-- Display of the actual POIs on the AlphaMap world maps
local function DisplayInstanceLocs(c, z, m, frame)

        local note, noteT;
        local width = frame:GetWidth();
        local height = frame:GetHeight();
        local amUnitScale = AlphaMap_GetUnitScale();
        local x, y;
        local i = 0;
        local lFloor = GetCurrentMapDungeonLevel();

        if ( ( AlphaMapConfig.iLocs ) and ( AM_INSTANCE_LOCS ) and ( AM_INSTANCE_LOCS[m] ) ) then
                for _, poi in ipairs(AM_INSTANCE_LOCS[m]) do
                        if ( ( not poi.floor ) or ( poi.floor == lFloor ) ) then
                                i = i + 1;
                                note = getglobal("AM_POII_Note_"..i);
                                if ( not note ) then
                                        note = CreateFrame("Button", "AM_POII_Note_"..i, frame, "AM_GenPOI_Template");
                                        note:SetScript("OnEnter", function(self)
                                                local x, y = GetCursorPosition();
                                                if ( x > 500 ) then
                                                        GameTooltip:SetOwner(this, "ANCHOR_TOPRIGHT");
                                                else
                                                        GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT");
                                                end

                                                GameTooltip:ClearLines();

                                                GameTooltip:AddLine(self.name);
                                                local i = 1;
                                                while( self.tooltip[i] ) do
                                                        GameTooltip:AddDoubleLine(self.tooltip[i], self.tooltip[i+1]);
                                                        i = i + 2;
                                                end

                                                AlphaMap_ShowTooltip();
                                        end)
                                        note:SetScript("OnLeave", function()
                                                AlphaMap_HideTooltip();
                                        end)
                                        note:SetScript("OnClick", function(self, mouseButton)
                                                if ( mouseButton == "LeftButton" ) then
                                                        local map = AMap.AlphaMap_GetMap(self.toMap);

                                                        if ( map ) then
                                                                AlphaMapFrame_Update( map );

                                                        elseif ( self.toWorldMap ) then
                                                                local cont, zone = AMap.AlphaMap_GetWorldMap(self.toWorldMap);
                                                                if ( cont ~= "error" ) then
                                                                        SetMapZoom(cont, zone); -- ))((
                                                                        AM_WorldMapSelected = true;
                                                                        AM_ManualMapChange = true;
                                                                        selectedCont = GetCurrentMapContinent();
                                                                        selectedZone = GetCurrentMapZone();
                                                                        selectedMap = GetMapInfo();
                                                                        AlphaMapFrame_Update();
                                                                end
                                                        end
                                                end
                                        end)
                                end
                                noteT = getglobal("AM_POII_Note_"..i.."Texture");
                                noteT:SetTexture( poi.icon );

                                x = ( poi.x * width ) / amUnitScale;
                                y = ( poi.y * height ) / amUnitScale;

                                note.name = poi.name;
                                note.tooltip = poi.tooltip;
                                note.toMap = poi.toMap;
                                note.toWorldMap = poi.toWorldMap;

                                note:ClearAllPoints();
                                note:SetScale(amUnitScale);
                                note:SetPoint("CENTER", frame, "TOPLEFT", x, -y);
                                note:Show();
                        end
                end
        end

        i = i + 1;
        note = getglobal("AM_POII_Note_"..i);
        while (note) do
                note:Hide();
                i = i + 1;
                note = getglobal("AM_POII_Note_"..i);
        end

end


local  POIIOld_AlphaMap_ResetAll;

function POIINew_AlphaMap_ResetAll()
        POIIOld_AlphaMap_ResetAll();
        AlphaMapConfig.iLocs = true;
        for configuration, configurations in pairs(AlphaMapConfigurations) do
                AlphaMapConfigurations[ configuration ].iLocs = AlphaMapConfig.iLocs;
        end
end

-- Variables_Loaded is the only event registered.
local function AlphaMap_POI_Instances_OnEvent()

        -- Hook the AlphaMap Options Reset Function
        POIIOld_AlphaMap_ResetAll = AlphaMap_ResetAll;
        AlphaMap_ResetAll = POIINew_AlphaMap_ResetAll;

        -- Set up Saved AlphaMap configuration options
        if ( AlphaMapConfig.iLocs == nil ) then
                AlphaMapConfig.iLocs = true;
        end
        for configuration, configurations in pairs(AlphaMapConfigurations) do
                AlphaMapConfigurations[ configuration ].iLocs = AlphaMapConfig.iLocs;
        end

        -- Insert Instance Display function code in to the main AlphaMap POI Plugin array
        -- AlphaMap will loop through these functions to display the required POIs
        table.insert(AMap.CustomPOIs, DisplayInstanceLocs);

        -- Set up the Control Check Button allowing people to toggle 
        -- display of Instance Locations off and on from the AlphaMap
        local i = #(AMap.CustomPOIControls) + 1;
        local controlButton = CreateFrame("Button", "AM_POIC"..i, UIParent, "AM_GenPOIControl_Template");
        controlButton.id = i;
        local controlButtonT = getglobal("AM_POIC"..i.."Texture");
        controlButtonT:SetTexture("Interface\\AddOns\\AlphaMap_POI_Instances\\Artwork\\Raid");
        local controlButtonC = getglobal("AM_POIC"..i.."Check");
        controlButtonC:SetScript("OnShow", function(self)
                self:SetFrameLevel( self:GetParent():GetFrameLevel() + 3 );
                if ( AlphaMapConfig.iLocs ) then
                        self:SetChecked(1);
                else
                        self:SetChecked(0);
                end
        end)
        controlButtonC:SetScript("OnClick", function(self)
                if ( self:GetChecked() ) then
                        PlaySound("igMainMenuOptionCheckBoxOff");
                        AlphaMapConfig.iLocs = false;
                        self:SetChecked(0);

                else
                        PlaySound("igMainMenuOptionCheckBoxOn");
                        AlphaMapConfig.iLocs = true;
                        self:SetChecked(1);
                end
                for configuration, configurations in pairs(AlphaMapConfigurations) do
                        AlphaMapConfigurations[ configuration ].iLocs = AlphaMapConfig.iLocs;
                end
                AlphaMapUnits_Update(1);
        end)
        controlButton:SetScript("OnClick", function(self)
                local v = getglobal(self:GetName() .. "Check");
                if ( v ) then
                        self = v;
                        v = v:GetScript("OnClick");
                        if ( v ) then v(self); end
                end
        end)

        -- Insert the Created control button in to the main AlphaMap array
        -- for display when the Control & Alt keys are pressed together
        table.insert(AMap.CustomPOIControls, controlButton);

end


-- Register Variables Loaded Event
AlphaMap_POI_Instances_Frame:SetScript("OnEvent", AlphaMap_POI_Instances_OnEvent);
AlphaMap_POI_Instances_Frame:RegisterEvent("VARIABLES_LOADED");

Compare with Previous | Blame