WoWInterface SVN MetaMapv4.0

[/] [trunk/] [MetaMap/] [MetaMapOptions.lua] - Rev 164

Compare with Previous | Blame | View Log

MetaMapOptions = {};
MetaMap_Options = {};
MetaMap_OptionsInfo = nil;
MetaMapOptions.MenuFont = 10;

MetaMap_NotesList_Initialized = false;

function MetaMapOptions_Init()
        MetaMap_Debug_Print("MetaMapOptions_Init",true);
        if (MetaMapOptions.SaveSet == 1) then
                if (MetaMapOptions.MetaMapAlpha1 < 0.15) then MetaMapOptions.MetaMapAlpha1 = 0.15; end
                MetaMapScaleSlider:SetValue(MetaMapOptions.MetaMapScale1);
                
                MetaMapAlphaSlider:SetValue(MetaMapOptions.MetaMapAlpha1);
                MetaMapTTScaleSlider:SetValue(MetaMapOptions.MetaMapTTScale1);
                MetaMap_CurrentAction = MetaMapOptions.ActionMode1;
        else
                if (MetaMapOptions.MetaMapAlpha2 < 0.15) then MetaMapOptions.MetaMapAlpha2 = 0.15; end
                MetaMapScaleSlider:SetValue(MetaMapOptions.MetaMapScale2);
        
                MetaMapAlphaSlider:SetValue(MetaMapOptions.MetaMapAlpha2);
                MetaMapTTScaleSlider:SetValue(MetaMapOptions.MetaMapTTScale2);
                MetaMap_CurrentAction = MetaMapOptions.ActionMode2;
        end

        if (MetaMap_CurrentAction) then
                WorldMapFrame.ScrollContainer:EnableMouse(false);
        else
                WorldMapFrame.ScrollContainer:EnableMouse(true);
        end
        if (MetaMapOptions.MetaMapButtonShown) then
                MetaMapButton_UpdatePosition();
                MetaMapButton:Show();
        else
                MetaMapButton:Hide();
        end
        if (MetaMapOptions.MetaMapCoords and not MetaMap_FullScreenMode) then
                MetaMap_MainCoords:Show();
        else
                MetaMap_MainCoords:Hide();
        end
        if (MetaMapOptions.MetaMapMiniCoords) then
                MetaMap_MiniCoords:Show();
        else
                MetaMap_MiniCoords:Hide();
        end
        MetaMap_UpdateAlpha();
        MetaMap_UpdateScale();
        MetaMap_UpdateTTScale();

        MetaMapContainerFrame:SetBackdropColor(0,0,0,MetaMapOptions.ContainerAlpha);
        MetaMap_MapListFrame:SetBackdropColor(0,0,0,MetaMapOptions.ContainerAlpha);
        MetaMap_CurrentSaveSet = MetaMapOptions.SaveSet;
        MetaMapButtonSlider:SetValue(MetaMapOptions.MetaMapButtonPosition);
        MetaMapMiniCoords:SetTextColor(MetaMap_Colors[MetaMapOptions.MiniColor].r, MetaMap_Colors[MetaMapOptions.MiniColor].g, MetaMap_Colors[MetaMapOptions.MiniColor].b);

        MetaMap_MapModeText:SetText(METAMAP_MENU_MAPSET.." "..MetaMapOptions.SaveSet);
end

function MetaMapButton_UpdatePosition()
        if (MetaMapOptions.MetaMapButtonPosition_Old ~= MetaMapOptions.MetaMapButtonPosition or not MetaMapOptions.MetaMapButtonPositionXY) then
                MetaMapButton:ClearAllPoints();
                MetaMapButton:SetPoint("TOPLEFT", Minimap, "TOPLEFT",
                        52 - (80 * cos(MetaMapOptions.MetaMapButtonPosition)),
                        (80 * sin(MetaMapOptions.MetaMapButtonPosition)) - 52
                );
                MetaMapOptions.MetaMapButtonPositionXY = nil;
                MetaMapOptions.MetaMapButtonPosition_Old = MetaMapOptions.MetaMapButtonPosition;
        end
end

function MetaMap_UpdateAlpha()
        if (MetaMapOptions.SaveSet == 1) then
                MetaMapOptions.MetaMapAlpha1 = MetaMapAlphaSlider:GetValue();
                WorldMapFrame:SetAlpha(MetaMapOptions.MetaMapAlpha1);
        else
                MetaMapOptions.MetaMapAlpha2 = MetaMapAlphaSlider:GetValue();
                WorldMapFrame:SetAlpha(MetaMapOptions.MetaMapAlpha2);
        end
        WorldMapFrame.ScrollContainer:SetAlpha(MetaMapAlphaSlider:GetValue() + 0.2);
end

local MetaMap_clickX = 0;
local MetaMap_clickY = 0;
function MetaMap_WorldMapFrame_OnMouseDown(self, button)
        MetaMap_clickX, MetaMap_clickY = GetCursorPosition();
end

local MetaMap_WorldMap_isMoving = false;
local MetaMap_dragStartX = 0;
local MetaMap_dragStartY = 0;
function MetaMap_FrameStartMoving(self, button)
        if ( not MetaMap_FullScreenMode and MetaMap_WorldMap_baseScale ~= 0 and button == "LeftButton" and not MetaMap_WorldMap_isMoving and self.canMove ) then
                MetaMap_WorldMap_isMoving = true;
                MetaMap_dragStartX = MetaMap_clickX;
                MetaMap_dragStartY = MetaMap_clickY;
                self:StartMoving();
        end
end

local MetaMap_saveScale = -1;
local MetaMap_WorldMap_sizeX = 0;
local MetaMap_WorldMap_sizeY = 0;
function MetaMap_FrameStopMoving(self, button)
        if ( MetaMap_WorldMap_isMoving ) then
                self:StopMovingOrSizing();
                local dragStopX, dragStopY = GetCursorPosition();
                local moveX = (dragStopX - MetaMap_dragStartX) / UIParent:GetEffectiveScale();
                local moveY = (dragStopY - MetaMap_dragStartY) / UIParent:GetEffectiveScale();
                local dispX = GetScreenWidth() * UIParent:GetEffectiveScale();
                local dispY = GetScreenHeight() * UIParent:GetEffectiveScale();
                local newPosX = min(max(MetaMapOptions.MetaMapPos1[1] + moveX, 0), dispX - MetaMap_WorldMap_sizeX / UIParent:GetEffectiveScale());
                local newPosY = max(min(MetaMapOptions.MetaMapPos1[2] + moveY, 0), -dispY + MetaMap_WorldMap_sizeY / UIParent:GetEffectiveScale());
                if (MetaMapOptions.SaveSet == 1) then
                        MetaMapOptions.MetaMapPos1 = { newPosX, newPosY };
                else
                        MetaMapOptions.MetaMapPos2 = { newPosX, newPosY };
                end
                MetaMap_WorldMap_isMoving = false;
        end
end

local MetaMap_WorldMap_baseX = 0;
local MetaMap_WorldMap_baseY = 0;
local MetaMap_WorldMap_sizeQ = 0;
local MetaMap_WorldMapScroll_sizeX = 0;
local MetaMap_WorldMapScroll_sizeY = 0;
local MetaMap_WorldMap_spacer = 0;
local MetaPap_WorldMapFrameBg_TopY = 0;
function MetaMap_UpdateScale()
        MetaMap_Debug_Print("MetaMap_UpdateScale", true);
        if ( InCombatLockdown() or MetaMap_WorldMap_isMoving ) then return; end

        if ( MetaMap_WorldMap_baseScale == 0 or MetaMap_WorldMap_baseX == 0 ) then
                MetaMap_WorldMap_baseScale = WorldMapFrame.ScrollContainer.baseScale;
                local nPoints = WorldMapFrame:GetNumPoints();
                if ( nPoints == 1 ) then
                        _, _, _, MetaMap_WorldMap_baseX, MetaMap_WorldMap_baseY = WorldMapFrame:GetPoint();
                        _, _, _, _, MetaMap_WorldMapFrameBg_TopY = WorldMapFrameBg:GetPoint();
                        local _, _, _, spacerX, spacerY = WorldMapFrame.TitleCanvasSpacerFrame:GetPoint(2);
                        MetaMap_WorldMap_spacer = -spacerY;
                        MetaMap_WorldMapScroll_sizeX = WorldMapFrame.minimizedWidth;
                        MetaMap_WorldMapScroll_sizeY = WorldMapFrame.minimizedHeight - MetaMap_WorldMap_spacer;
                        MetaMap_WorldMap_sizeQ = WorldMapFrame.questLogWidth;
                end
        end
        if ( MetaMapOptions.MetaMapPos1[1] == -1 ) then
                MetaMapOptions.MetaMapPos1 = { MetaMap_WorldMap_baseX, MetaMap_WorldMap_baseY };
        end
        if ( MetaMapOptions.MetaMapPos2[1] == -1 ) then
                MetaMapOptions.MetaMapPos2 = { MetaMap_WorldMap_baseX, MetaMap_WorldMap_baseY };
        end

        if (not MetaMap_FullScreenMode and MetaMap_WorldMap_baseScale ~= 0 ) then
                MetaMap_Debug_Print("MetaMap_UpdateScale-NoFullScreen", true);
                if (MetaMapOptions.SaveSet == 1) then
                        MetaMapOptions.MetaMapScale1 = math.floor((MetaMapScaleSlider:GetValue() + 0.025 ) * 20) / 20.0;
                        if (MetaMapOptions.MetaMapScale1 == 0) then MetaMapOptions.MetaMapScale1 = MetaMap_WorldMap_baseScale; end
                        MetaMap_SetWorldMapScale(MetaMapOptions.MetaMapScale1, MetaMapOptions.MetaMapPos1[1], MetaMapOptions.MetaMapPos1[2]);
                else
                        MetaMapOptions.MetaMapScale2 = math.floor((MetaMapScaleSlider:GetValue() + 0.025 ) * 20) / 20.0;
                        if (MetaMapOptions.MetaMapScale2 == 0) then MetaMapOptions.MetaMapScale2 = MetaMap_WorldMap_baseScale; end
                        MetaMap_SetWorldMapScale(MetaMapOptions.MetaMapScale2, MetaMapOptions.MetaMapPos2[1], MetaMapOptions.MetaMapPos2[2]);
                end
        end
end

local saveQuestPanel = false;
function MetaMap_SetWorldMapScale(scale, posX, posY)
        local questPanel = WorldMapFrame:IsSidePanelShown();
        if ( scale == 0 ) then
                -- Reset WorldMapFrame
                WorldMapFrame:ClearAllPoints();
                WorldMapFrame:SetPoint("TOPLEFT",UIParent,"TOPLEFT",MetaMap_WorldMap_baseX,MetaMap_WorldMap_baseY);
                if ( scale ~= MetaMap_saveScale or questPanel ~= saveQuestPanel ) then
                        WorldMapFrame.ScrollContainer:CreateZoomLevels();
                        WorldMapFrame:ResetZoom();
                end
                WorldMapFrame.TitleCanvasSpacerFrame:SetScale(1.0);
                WorldMapFrame.BorderFrame:SetScale(1.0);
                WorldMapFrame.NavBar:SetScale(1.0);
                WorldMapFrame.SidePanelToggle:SetScale(1.0);
                WorldMapFrameBg:SetPoint("TOPLEFT",WorldMapFrame.BorderFrame,"TOPLEFT",2,MetaPap_WorldMapFrameBg_TopY);
                MetaMap_ModeToggleButton:SetScale(1.0);
                MetaMap_MoveToggleButton:SetScale(1.0);
                MetaMap_GoToCurrentZone:SetScale(1.0);
                MetaMap_OptionsButton:SetScale(1.0);
                MetaMap_InstanceButton:SetScale(1.0);
                QuestMapFrame:SetScale(1.0);
        else
                local nScale = scale / MetaMap_WorldMap_baseScale;
                local spacer = MetaMap_WorldMap_spacer * nScale;
                local sizeX = MetaMap_WorldMapScroll_sizeX / MetaMap_WorldMap_baseScale * scale;
                local sizeY = MetaMap_WorldMapScroll_sizeY / MetaMap_WorldMap_baseScale * scale;
                local setX = abs(posX) + sizeX;
                local setY = -(abs(posY) + sizeY + spacer);
                local bgPosY = MetaPap_WorldMapFrameBg_TopY / MetaMap_WorldMap_baseScale * nScale;
                if ( questPanel ) then
                        setX = setX + MetaMap_WorldMap_sizeQ * nScale;
                end
                MetaMap_WorldMap_sizeX = (setX - posX);
                MetaMap_WorldMap_sizeY = -(setY - posY);
                WorldMapFrame:ClearAllPoints();
                WorldMapFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", posX, posY);
                WorldMapFrame:SetPoint("BOTTOMRIGHT", UIParent, "TOPLEFT", setX, setY);
                if ( scale ~= MetaMap_saveScale or questPanel ~= saveQuestPanel ) then
                        WorldMapFrame.ScrollContainer:CreateZoomLevels();
                        WorldMapFrame:ResetZoom();
                end
                WorldMapFrame.TitleCanvasSpacerFrame:SetScale(nScale);
                WorldMapFrame.BorderFrame:SetScale(nScale);
                WorldMapFrame.NavBar:SetScale(nScale);
                WorldMapFrame.SidePanelToggle:SetScale(nScale);
                WorldMapFrameBg:SetPoint("TOPLEFT",WorldMapFrame.BorderFrame,"TOPLEFT",2,-bgPosY);
                MetaMap_ModeToggleButton:SetScale(nScale);
                MetaMap_MoveToggleButton:SetScale(nScale);
                MetaMap_GoToCurrentZone:SetScale(nScale);
                MetaMap_OptionsButton:SetScale(nScale);
                MetaMap_InstanceButton:SetScale(nScale);
                QuestMapFrame:SetScale(nScale);
        end
        MetaMap_saveScale = scale;
        saveQuestPanel = questPanel;
end

function MetaMap_UpdateTTScale()
        if (MetaMapOptions.SaveSet == 1) then
                MetaMapOptions.MetaMapTTScale1 = MetaMapTTScaleSlider:GetValue();
                WorldMapTooltip:SetScale(MetaMapOptions.MetaMapTTScale1);
        else
                MetaMapOptions.MetaMapTTScale2 = MetaMapTTScaleSlider:GetValue();
                WorldMapTooltip:SetScale(MetaMapOptions.MetaMapTTScale2);
        end
end

function MetaMap_ToggleDialog(tab)
        local subFrame = _G[tab];
        MetaMap_OptionsInfo:SetText("");
        MetaMap_GeneralDialog:Hide();
        MetaMap_NotesDialog:Hide();
        MetaMap_ModulesDialog:Hide();
        MetaMap_ImportDialog:Hide();
        MetaMap_ZoneShiftDialog:Hide();
        MetaMap_HelpDialog:Hide();
        if (BKP_BackUpFrame) then BKP_BackUpFrame:Hide(); end
        if (EXP_ExportFrame) then EXP_ExportFrame:Hide(); end
        if (CVT_ImportFrame) then CVT_ImportFrame:Hide(); end
        if (subFrame) then
                if (MetaMap_DialogFrame:IsVisible()) then
                        PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB);
                        _G[tab]:Show();
                else
                        ShowUIPanel(MetaMap_DialogFrame);
                        _G[tab]:Show();
                end
        end
end

function MetaMap_OptionsTab_OnClick(self)
        if (self:GetName() == "MetaMap_DialogFrameTab1") then
                MetaMap_ToggleDialog("MetaMap_GeneralDialog");
        elseif (self:GetName() == "MetaMap_DialogFrameTab2") then
                MetaMap_ToggleDialog("MetaMap_NotesDialog");
        elseif (self:GetName() == "MetaMap_DialogFrameTab3") then
                MetaMap_ToggleDialog("MetaMap_ModulesDialog");
        elseif (self:GetName() == "MetaMap_DialogFrameTab4") then
                MetaMap_ToggleDialog("MetaMap_ImportDialog");
        elseif (self:GetName() == "MetaMap_DialogFrameTab5") then
                MetaMap_ToggleDialog("MetaMap_ZoneShiftDialog");
        elseif (self:GetName() == "MetaMap_DialogFrameTab6") then
                MetaMap_ToggleDialog("MetaMap_HelpDialog");
        end
        PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB);
end

--[[old
function MetaMap_SetFrameStrata()
        local strata;
        if (MetaMapOptions.MetaMapFrameStrata == 4) then
                strata = "DIALOG";
        elseif (MetaMapOptions.MetaMapFrameStrata == 3) then
                strata = "HIGH";
        elseif (MetaMapOptions.MetaMapFrameStrata == 2) then
                strata = "MEDIUM";
        elseif (MetaMapOptions.MetaMapFrameStrata == 1) then
                strata = "LOW";
        else
                strata = "BACKGROUND";
        end
        WorldMapTooltip:SetFrameStrata("TOOLTIP");
-- not all parts of the WorldMapFrame are shown with the same FrameStrata
        WorldMapFrame:SetFrameStrata(strata);

        MetaMap_OptionsButton:SetFrameLevel("99");
        MetaMap_GoToCurrentZone:SetFrameLevel("99");
        MetaMap_ModeToggleButton:SetFrameLevel("99");
        MetaMap_InstanceButton:SetFrameLevel("99");
        MetaMap_MiscDisplay:SetFrameLevel("99");
        MetaMap_MainCoords:SetFrameLevel("99");

        WorldMapCompareTooltip1:SetFrameStrata("TOOLTIP");
        WorldMapCompareTooltip2:SetFrameStrata("TOOLTIP");
        WorldMapTooltip:SetFrameLevel("300");
end
--]]

function MetaMap_ToggleOptions(key, value)
        if (value) then
                MetaMapOptions[key] = value;
        else
                MetaMapOptions[key] = not MetaMapOptions[key];
        end

        MetaMapOptions_Init();

        return MetaMapOptions[key];
end

function MetaMap_NotesListInit()
        local Temp_List = {};
        for mapName, indexTable in pairs(MetaMap_Notes) do
                for index, value in pairs(indexTable) do
                        if (Temp_List[value.creator] == nil) then
                                Temp_List[value.creator] = value.creator;
                        end
                end
        end
        for index, creators in pairs(Temp_List) do
                local uText;
                if (Temp_List[index] == "") then
                        uText = "Unsigned";
                else
                        uText = Temp_List[index];
                end
                local info = {};
                info.checked = nil;
                info.notCheckable = 1;
                info.text = uText;
                info.value = uText;
                info.func = MetaMap_NotesList_OnClick;
                UIDropDownMenu_AddButton(info);
        end
end

function MetaMap_NotesList_OnClick(self)
        local creator = self.value;
        local button = MetaMap_NotesList_Button;
        button:SetText(creator);
        if (creator == "Unsigned") then
                cFlag = "";
        else
                cFlag = creator;
        end     
        local mapName, mapLevel, dataZone = MetaMap_GetCurrentMapInfo();
        StaticPopupDialogs["Delete_Notes"] = {
                text = TEXT(format(METAMAP_BATCHDELETE, mapName, creator)),
                button1 = TEXT(ACCEPT),
                button2 = TEXT(DECLINE),
                OnAccept = function()
                        MetaMap_DeleteNotes(cFlag, nil, mapName);
                        button:SetText(METAMAP_OPTIONS_CCREATOR);
                end,
                OnCancel = function()
                        button:SetText(METAMAP_OPTIONS_CCREATOR);
                end,
                timeout = 60,
                showAlert = 1,
        };
        StaticPopup_Show("Delete_Notes");
end

function MetaMap_DeleteNotes(creator, name, mapName)
        if (not creator) then return; end
        local continent;
        if (mapName) then
                for key, value in pairs(MetaMap_Continents) do
                        if (mapName == value) then continent = key; end
                end
        end
        if (continent ~= nil or mapName == nil) then
                for zone, indexTable in pairs(MetaMap_Notes) do
                        local cKey = MetaMap_NameToZoneID(zone);
                        if (continent == cKey or continent == 0 or continent == -1 or continent == nil) then
                                for id = #(indexTable), 1, -1 do
                                        if (creator == indexTable[id].creator and (name == indexTable[id].name or name == nil)) then
                                                MetaMap_DeleteMapNote(id, zone);
                                        end
                                end
                        end
                end
        else
                for id = #(MetaMap_Notes[mapName]), 1, -1 do
                        if (creator == MetaMap_Notes[mapName][id].creator) then
                                MetaMap_DeleteMapNote(id, mapName);
                        end
                end
        end
        if (creator == "") then creator = "Unsigned"; end
        if (mapName ~= nil) then
                if (MetaMap_NotesDialog:IsVisible()) then
                        MetaMap_OptionsInfo:SetText(format(METAMAP_DELETED_BY_ZONE, mapName, creator), true);
                else
                        MetaMap_Print(format(METAMAP_DELETED_BY_ZONE, mapName, creator), true);
                end
        elseif (name ~= nil) then
                MetaMap_Print(format(METAMAP_DELETED_BY_NAME, creator, name), true);
        else
                MetaMap_Print(format(METAMAP_DELETED_BY_CREATOR, creator), true);
        end
end

function MetaMap_round(num, idp)
        local mult = 10^(idp or 0);
        return (math.floor(num * mult + 0.5) / mult);
end

function MetaMap_ZoneCheckMenu_OnClick(self)
        UIDropDownMenu_SetText(MetaMap_ZoneCheckMenu, self.value);
        MetaMap_ZoneCheckButton:Enable();
end

function MetaMap_ZoneCheckMenu_Initialize(self)
        if (UIDROPDOWNMENU_MENU_LEVEL == 1) then
                for index, cName in pairs(MetaMap_Continents) do
                        if (index > 0) then
                                local info = {
                                        text = cName,
                                        textHeight = MetaMapOptions.MenuFont,
                                        value = index,
                                        hasArrow = 1,
                                        checked = nil,
                                        notCheckable = 1;
                                }
                                UIDropDownMenu_AddButton(info);
                        end
                end
                local info = {
                        text = METAMAP_BATTLEGROUNDS,
                        textHeight = MetaMapOptions.MenuFont,
                        value = "BG",
                        hasArrow = 1,
                        checked = nil,
                        notCheckable = 1;
                }
                UIDropDownMenu_AddButton(info);
                local info = {
                        text = METAMAP_INSTANCE_MENU_DUNGEONS,
                        textHeight = MetaMapOptions.MenuFont,
                        value = "DNI",
                        hasArrow = 1,
                        checked = nil,
                        notCheckable = 1;
                }
                UIDropDownMenu_AddButton(info);
                local info = {
                        text = METAMAP_INSTANCE_MENU_RAIDS,
                        textHeight = MetaMapOptions.MenuFont,
                        value = "RDI",
                        hasArrow = 1,
                        checked = nil,
                        notCheckable = 1;
                }
                UIDropDownMenu_AddButton(info);
                local info = {
                        text = METAMAP_INSTANCE_MENU_SCENARIOS,
                        textHeight = MetaMapOptions.MenuFont,
                        value = "SCN",
                        hasArrow = 1,
                        checked = nil,
                        notCheckable = 1;
                }
                UIDropDownMenu_AddButton(info);
                local info = {
                        checked = nil,
                        notCheckable = 1,
                        text = METAMAP_ZONE_DELETE,
                        textHeight = MetaMapOptions.MenuFont,
                        value = METAMAP_ZONE_DELETE,
                        func = MetaMap_ZoneCheckMenu_OnClick;
                }
                UIDropDownMenu_AddButton(info);
        end
        if (UIDROPDOWNMENU_MENU_LEVEL == 2) then
                local menuVal = MetaMap_SubMenuFix(self);
                if (menuVal == "BG") then
                        for index, value in pairs(MetaMap_ZoneTable) do
                                if (value.ztype == "BG") then
                                        local info = {
                                                checked = nil,
                                                notCheckable = 1,
                                                text = value[MetaMap_Locale],
                                                textHeight = MetaMapOptions.MenuFont,
                                                value = value[MetaMap_Locale],
                                                func = MetaMap_ZoneCheckMenu_OnClick;
                                        };
                                        UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                                end
                        end
                elseif (menuVal == "DNI" or menuVal == "RDI" or menuVal == "SCN") then
                        local idx;
                        if ( menuVal == "RDI" ) then idx = 600; end
                        if ( menuVal == "DNI" ) then idx = 700; end
                        if ( menuVal == "SCN" ) then idx = 800; end
                        for index, cName in pairs(MetaMap_Continents) do
                                if (index > 0) then
                                        local info = {
                                                text = cName,
                                                textHeight = MetaMapOptions.MenuFont,
                                                value = idx + index,
                                                hasArrow = 1,
                                                checked = nil,
                                                notCheckable = 1,
                                        }
                                        UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                                end
                        end
                else
                        for zKey, zName in pairs(MetaMap_GetMapZones(menuVal)) do
                                local name = MetaMap_ZoneIDToName(menuVal, zKey);
                                local info = {
                                        checked = nil,
                                        notCheckable = 1,
                                        text = name,
                                        textHeight = MetaMapOptions.MenuFont,
                                        value = name,
                                        func = MetaMap_ZoneCheckMenu_OnClick;
                                };
                                UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                        end
                end
        end
        if (UIDROPDOWNMENU_MENU_LEVEL == 3) then
                local menuVal = MetaMap_SubMenuFix(self);
                local ztype;
                if     ( menuVal > 800 ) then ztype = "SCN"; menuVal = menuVal - 800;
                elseif ( menuVal > 700 ) then ztype = "DNI"; menuVal = menuVal - 700;
                elseif ( menuVal > 600 ) then ztype = "RDI"; menuVal = menuVal - 600; end
                local menuList = {};
                for index, zoneTable in pairs(MetaMap_ZoneTable) do
                        if ( (zoneTable.ztype == ztype) and (zoneTable.Continent == menuVal) ) then
                                local name = MetaMap_MergeZoneName(zoneTable);
                                table.insert(menuList, {location = name});
                        end
                end
                local sort = MetaMap_sortType;
                MetaMap_sortType = METAMAP_SORTBY_LOCATION;
                table.sort(menuList, MetaMap_SortCriteria);
                MetaMap_sortType = sort;
                for zKey, zName in pairs(menuList) do
                        local info = {
                                checked = nil,
                                notCheckable = 1,
                                text = zName.location,
                                textHeight = MetaMapOptions.MenuFont,
                                value = zName.location,
                                func = MetaMap_ZoneCheckMenu_OnClick;
                        };
                        UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                end
                menuList = nil;
        end
end

function MetaMap_ZoneCheckButton_OnClick()
        local errata = "";
        if (MetaMap_Orphans == 0) then
                MetaMap_LoadWKB(3);
                MetaMap_LoadTRK(2);
                MetaMap_LoadQST(2);
                errata = MetaMap_CheckZones();
                if (MetaMap_Orphans > 0) then
                        MetaMap_ZoneShiftDisplay:Show();
                        MetaMap_ZoneCheckButton:SetText(METAMAP_ZONEMOVE_BUTTON);
                        MetaMap_OptionsInfo:SetText(METAMAP_ZONE_ERROR..errata);
                        for zone, value in pairs(MetaMap_ZoneErrata) do
                                MetaMap_OrphanFrameText:SetText(zone);
                                MetaMap_OrphanText1:SetText(format(METAMAP_ORPHAN_TEXT1, 1, MetaMap_Orphans));
                                break;
                        end
                else
                        MetaMap_ZoneShiftDisplay:Hide();
                        MetaMap_OptionsInfo:SetText(METAMAP_ZONE_NOSHIFT);
                        MetaMap_ZoneCheckButton:SetText(METAMAP_ZONECHECK_BUTTON);
                end
        elseif (MetaMap_Orphans > 0) then
                MetaMap_ShiftZones();
                if (MetaMap_Orphans > 0) then
                        MetaMap_ZoneShiftDisplay:Show();
                        MetaMap_ZoneCheckButton:SetText(METAMAP_ZONEMOVE_BUTTON);
                        for zone, value in pairs(MetaMap_ZoneErrata) do
                                MetaMap_OrphanFrameText:SetText(zone);
                                MetaMap_OrphanText1:SetText(format(METAMAP_ORPHAN_TEXT1, 1, MetaMap_Orphans));
                                break;
                        end
                else
                        MetaMap_ZoneShiftDisplay:Hide();
                        MetaMap_OptionsInfo:SetText(METAMAP_ZONE_NOSHIFT);
                        MetaMap_ZoneCheckButton:SetText(METAMAP_ZONECHECK_BUTTON);
                end
        end
        MetaMap_ZoneCheckButton:Disable();
end

function MetaMap_CheckZones()
        MetaMap_ZoneErrata = {};
        local errata;
        local found = "|cffff0000\n\n";
        for zone, indexTable in pairs(MetaMap_Notes) do
                if (not MetaMap_CheckValidZone(zone)) then
                        if (not MetaMap_ZoneErrata[zone]) then
                                MetaMap_ZoneErrata[zone] = true;
                        end
                        errata = "MetaMap";
                end
        end
        if (errata) then found = found..errata; errata = nil; end
        if (WKB_Data) then
                for zone, indexTable in pairs(WKB_Data) do
                        if (not MetaMap_CheckValidZone(zone)) then
                                if (not MetaMap_ZoneErrata[zone]) then
                                        MetaMap_ZoneErrata[zone] = true;
                                end
                                errata = " - MetaMapWKB";
                        end
                end
                if (errata) then found = found..errata; errata = nil; end
        end
        if (TRK_Data) then
                for zone, indexTable in pairs(TRK_Data) do
                        if (not MetaMap_CheckValidZone(zone)) then
                                if (not MetaMap_ZoneErrata[zone]) then
                                        MetaMap_ZoneErrata[zone] = true;
                                end
                                errata = " - MetaMapTRK";
                        end
                end
                if (errata) then found = found..errata; errata = nil; end
        end
        if (QST_QuestLog) then
                for index, value in ipairs(QST_QuestLog) do
                        if (value.qArea and value.qArea ~= QST_QUEST_UNKNOWN) then
                                if (not MetaMap_CheckValidZone(value.qArea)) then
                                        if (not MetaMap_ZoneErrata[value.qArea]) then
                                                MetaMap_ZoneErrata[value.qArea] = true;
                                        end
                                        errata = " - MetaMapQSTlog";
                                end
                        end
                end
                if (errata) then found = found..errata; errata = nil; end
                for index, value in ipairs(QST_QuestBase) do
                        if (value.qArea) then
                                if (value.qArea ~= QST_QUEST_UNKNOWN and not MetaMap_CheckValidZone(value.qArea)) then
                                        if (not MetaMap_ZoneErrata[value.qArea]) then
                                                MetaMap_ZoneErrata[value.qArea] = true;
                                        end
                                        errata = " - MetaMapQSTbase";
                                end
                        elseif (value.qZone ~= QST_QUEST_UNKNOWN and not MetaMap_CheckValidZone(value.qZone)) then
                                if (not MetaMap_ZoneErrata[value.qZone]) then
                                        MetaMap_ZoneErrata[value.qZone] = true;
                                end
                                errata = " - MetaMapQSTbase";
                        end
                end
                if (errata) then found = found..errata; errata = nil; end
        end
        for zone, value in pairs(MetaMap_ZoneErrata) do
                MetaMap_Orphans = MetaMap_Orphans + 1;
        end
        return found;
end

function MetaMap_ShiftZones()
        local oldZone = MetaMap_OrphanFrameText:GetText();
        local newZone = UIDropDownMenu_GetText(MetaMap_ZoneCheckMenu);
        if (MetaMap_Notes[oldZone]) then
                if ( newZone ~= METAMAP_ZONE_DELETE ) then
                        for index, value in ipairs(MetaMap_Notes[oldZone]) do
                                local noteAdded = MetaMap_SetNewNote(newZone, value.xPos, value.yPos, value.name, value.inf1, value.inf2, value.creator, value.icon, value.ncol, value.in1c, value.in2c);
                                if (noteAdded and MetaMap_Lines[oldZone]) then
                                        for i, lines in ipairs(MetaMap_Lines[oldZone]) do
                                                if (lines.x1 == value.xPos and lines.y1 == value.yPos) then
                                                        MetaMap_ToggleLine(newZone, lines.x1, lines.y1, lines.x2, lines.y2);
                                                end
                                        end
                                end
                        end
                end
                MetaMap_Notes[oldZone] = nil;
                MetaMap_Lines[oldZone] = nil;
        end
        if (WKB_Data and WKB_Data[oldZone]) then
                if ( newZone ~= METAMAP_ZONE_DELETE ) then
                        if (not WKB_Data[newZone]) then WKB_Data[newZone] = {}; end
                        for unit, value in pairs(WKB_Data[oldZone]) do
                                WKB_Data[newZone][unit] = value;
                        end
                end
                WKB_Data[oldZone] = nil;
        end
        if (TRK_Data and TRK_Data[oldZone]) then
                if ( newZone ~= METAMAP_ZONE_DELETE ) then
                        if (not TRK_Data[newZone]) then TRK_Data[newZone] = {}; end
                        for index, value in ipairs(TRK_Data[oldZone]) do
                                TRK_Data[newZone][index] = value;
                        end
                end
                TRK_Data[oldZone] = nil;
        end
        if (newZone == METAMAP_ZONE_DELETE) then newZone = QST_QUEST_UNKNOWN; end
        if (QST_QuestLog) then
                for index, value in ipairs(QST_QuestLog) do
                        if (value.qArea == oldZone) then
                                value.qArea = newZone;
                        end
                        if (value.qNPC[1] and value.qNPC[1].qZone == oldZone) then
                                value.qNPC[1].qZone = newZone;
                        end
                        if (value.qNPC[2] and value.qNPC[2].qZone == oldZone) then
                                value.qNPC[2].qZone = newZone;
                        end
                end
        end
        if (QST_QuestBase) then
                for index, value in ipairs(QST_QuestBase) do
                        if (value.qArea == oldZone) then
                                value.qArea = newZone;
                        elseif (value.qZone == oldZone) then
                                value.qZone = newZone;
                        end
                        if (value.qNPC[1] and value.qNPC[1].qZone == oldZone) then
                                value.qNPC[1].qZone = newZone;
                        end
                        if (value.qNPC[2] and value.qNPC[2].qZone == oldZone) then
                                value.qNPC[2].qZone = newZone;
                        end
                end
        end
        MetaMap_ZoneErrata[oldZone] = nil;
        MetaMap_Orphans = MetaMap_Orphans - 1;
        if (MetaMap_Orphans == 0) then MetaMap_ZoneErrata = nil; end
        MetaMap_OptionsInfo:SetText(format(METAMAP_ZONE_SHIFTED, oldZone, newZone));
        UIDropDownMenu_SetText(MetaMap_ZoneCheckMenu, "");
end

Compare with Previous | Blame