//
    // Event Methods
    //

    protected override void OnToggleTool(bool isOn)
    {
        if (isOn)
        {
            // Create budget layer
            budgetLayer    = toolLayers.CreateGridMapLayer(budgetLayerPrefab, "WeightedLayer");
            highlightLayer = toolLayers.CreateGridMapLayer(highlightLayerPrefab, "HighlightLayer");
            highlightLayer.Show(false);

            // Store number of childs on start
            initChildsCount = transform.childCount + 1;

            // Add slider
            foreach (var panel in dataLayers.activeLayerPanels)
            {
                UpdateSlider(panel.DataLayer, true);
            }

            // Create output panel for tool
            municipalBudgetOutput      = Instantiate(outputPrefab);
            municipalBudgetOutput.name = "MunicipalBudget_OutputPanel";
            outputPanel.SetPanel(municipalBudgetOutput.transform);
            municipalBudgetOutput.OnItemHovering += OnItemHover;

            // Add event listeners
            siteBrowser.OnBeforeActiveSiteChange += OnBeforeActiveSiteChange;
            siteBrowser.OnAfterActiveSiteChange  += OnAfterActiveSiteChange;

            // Listen to any data layers being added/removed
            dataLayers.OnLayerAvailabilityChange += OnLayerAvailabilityChange;

            // Listen to any grids being added/removed
            var gridController = map.GetLayerController <GridLayerController>();
            gridController.OnShowGrid += OnShowGrid;

            // Initialize grids list with already visible grid layers
            foreach (var layer in gridController.mapLayers)
            {
                grids.Add(layer.Grid);
            }

            ShowBudgetLayer(false);

            // Add filter toggle event
            filterToggle.onValueChanged.AddListener(OnFilterToggleChange);
            noDataToggle.onValueChanged.AddListener(OnNoDataToggleChange);
            budgetLayer.useFilters = filterToggle.isOn;

            loadDataCR = StartCoroutine(LoadData());
        }
        else
        {
            if (loadDataCR != null)
            {
                StopCoroutine(loadDataCR);
            }

            // Remove listeners
            siteBrowser.OnBeforeActiveSiteChange -= OnBeforeActiveSiteChange;
            siteBrowser.OnAfterActiveSiteChange  -= OnAfterActiveSiteChange;
            dataLayers.OnLayerAvailabilityChange -= OnLayerAvailabilityChange;
            if (map != null)
            {
                var gridController = map.GetLayerController <GridLayerController>();
                if (gridController)
                {
                    gridController.OnShowGrid -= OnShowGrid;
                }
            }

            // Remove Output panel
            outputPanel.DestroyPanel(municipalBudgetOutput.gameObject);
            municipalBudgetOutput = null;

            // Remove map layer
            DeleteAllLayers();

            // Remove sliders
            foreach (var pair in sliders)
            {
                Destroy(pair.Value.gameObject);
            }
            sliders.Clear();

            grids.Clear();

            dataLayers.ResetToolOpacity();
        }
    }
Beispiel #2
0
    protected override void OnToggleTool(bool isOn)
    {
        if (isOn)
        {
            runningSnapshotCounter = 1;

            // Create contours layer
            contoursLayer = toolLayers.CreateMapLayer(contoursLayerPrefab, "Contours");
            contoursLayer.ExcludeCellsWithNoData(excludeNoDataToggle.isOn);

            // Listen to any data layers being added/removed
            dataLayers.OnLayerVisibilityChange   += OnLayerVisibilityChange;
            dataLayers.OnLayerAvailabilityChange += OnLayerAvailabilityChange;

            // Listen to any grid layers being added/removed
            var gridController = map.GetLayerController <GridLayerController>();
            gridController.OnShowGrid += OnShowGrid;

            // Initialize grids list with already visible grid layers
            grids.Clear();
            foreach (var mapLayer in gridController.mapLayers)
            {
                grids.Add(mapLayer.Grid);
            }

            // Reset buttons
            analysisToggle.isOn     = false;
            showContoursToggle.isOn = true;
            lockToggle.isOn         = false;
            //filteredToggle.isOn = true;		// Don't reset, user wants to keep this setting
            //excludeNoDataToggle.isOn = true;	// Don't reset, user wants to keep this setting
            deleteToggle.isOn         = false;
            deleteToggle.interactable = false;
            addButton.interactable    = true;
            cropToggle.isOn           = contoursLayer.CropWithViewArea;

            // Initialize listeners
            addButton.onClick.AddListener(OnAddSnapshotClick);
            deleteToggle.onValueChanged.AddListener(OnDeleteToggleChange);
            showContoursToggle.onValueChanged.AddListener(OnShowContoursChanged);
            cropToggle.onValueChanged.AddListener(OnCropWithViewAreaChanged);
            lockToggle.onValueChanged.AddListener(OnLockChanged);
            analysisToggle.onValueChanged.AddListener(OnAnalysisChanged);
            excludeNoDataToggle.onValueChanged.AddListener(OnExcludeNoDataChanged);

            // Show contours layer
            ShowContoursLayer(true);

            // Create the info panel
            infoPanel      = Instantiate(infoPanelPrefab);
            infoPanel.name = infoPanelPrefab.name;
            infoPanel.Init();
            var outputPanel = ComponentManager.Instance.Get <OutputPanel>();
            outputPanel.SetPanel(infoPanel.transform);

            var translator = LocalizationManager.Instance;
            infoPanel.AddEntry("CC", translator.Get("Current Contours"));
            infoPanel.AddEntry("SC", translator.Get("Selected Contours"));

            snapshots      = new Snapshot[snapshotCount];
            emptySnapshots = new RectTransform[snapshotCount];
            usedSnapshots  = 0;

            // Create empty snapshots
            for (int i = 0; i < snapshotCount; ++i)
            {
                var emptySnapshot = Instantiate(emptySnapshotPrefab, SnapshotList, false);
                emptySnapshot.name = emptySnapshotPrefab.name + (i + 1);
                emptySnapshots[i]  = emptySnapshot;
                infoPanel.AddEntry("S" + i, translator.Get("Snapshot") + " " + (i + 1));
            }

            UpdateContoursInfo();

            translator.OnLanguageChanged += OnLanguageChanged;

            GuiUtils.RebuildLayout(SnapshotList);
        }
        else
        {
            // Remove listeners
            addButton.onClick.RemoveAllListeners();
            showContoursToggle.onValueChanged.RemoveAllListeners();
            cropToggle.onValueChanged.RemoveAllListeners();
            lockToggle.onValueChanged.RemoveAllListeners();
            analysisToggle.onValueChanged.RemoveAllListeners();
            excludeNoDataToggle.onValueChanged.RemoveAllListeners();
            dataLayers.OnLayerVisibilityChange   -= OnLayerVisibilityChange;
            dataLayers.OnLayerAvailabilityChange -= OnLayerAvailabilityChange;
            inputHandler.OnLeftMouseUp           -= OnLeftMouseUp;

            if (map)
            {
                var gridController = map.GetLayerController <GridLayerController>();
                if (gridController)
                {
                    gridController.OnShowGrid -= OnShowGrid;
                }
            }

            // Remove the info panel
            ComponentManager.Instance.Get <OutputPanel>().DestroyPanel(infoPanel.gameObject);

            // Remove map layers
            DeleteAllLayers();

            // Remove snapshots UI
            foreach (var snapshot in snapshots)
            {
                if (snapshot != null)
                {
                    Destroy(snapshot.uiTransform.gameObject);
                }
            }
            snapshots = null;
            foreach (var emptySnapshot in emptySnapshots)
            {
                Destroy(emptySnapshot.gameObject);
            }
            emptySnapshots = null;
            usedSnapshots  = 0;

            grids.Clear();

            dataLayers.ResetToolOpacity();

            CancelRemoveSnapshotMode();

            LocalizationManager.Instance.OnLanguageChanged -= OnLanguageChanged;
        }
    }
Beispiel #3
0
    public override void OnToggleTool(bool isOn)
    {
        if (isOn)
        {
            runningSnapshotCounter = 1;

            // Create contours layer
            contoursLayer = CreateMapLayer(contoursLayerPrefab, "Contours");
            contoursLayer.ExcludeCellsWithNoData(excludeNoDataToggle.isOn);

            // Listen to any data layers being added/removed
            dataLayers.OnLayerVisibilityChange   += OnLayerVisibilityChange;
            dataLayers.OnLayerAvailabilityChange += OnLayerAvailabilityChange;

            // Listen to any grid layers being added/removed
            var gridController = map.GetLayerController <GridLayerController>();
            gridController.OnShowGrid += OnShowGrid;

            // Initialize grids list with already visible grid layers
            grids.Clear();
            foreach (var mapLayer in gridController.mapLayers)
            {
                mapLayer.Grid.OnFilterChange += OnGridFilterChange;
                grids.Add(mapLayer.Grid);
            }

            // Reset buttons
            showContoursToggle.isOn = true;
            lockToggle.isOn         = false;
            //filteredToggle.isOn = true;		// Don't reset, user wants to keep this setting
            //excludeNoDataToggle.isOn = true;	// Don't reset, user wants to keep this setting
            deleteToggle.isOn         = false;
            deleteToggle.interactable = false;
            addButton.interactable    = true;

            // Initialize listeners
            addButton.onClick.AddListener(OnAddButtonClick);
            deleteToggle.onValueChanged.AddListener(OnDeleteToggleChange);
            showContoursToggle.onValueChanged.AddListener(OnShowContoursChanged);
            filteredToggle.onValueChanged.AddListener(OnShowFilteredChanged);
            lockToggle.onValueChanged.AddListener(OnLockChanged);
            analysisToggle.onValueChanged.AddListener(OnAnalysisChanged);
            excludeNoDataToggle.onValueChanged.AddListener(OnExcludeNoDataChanged);

            // Show contours layer
            ShowContoursLayer(true);

            // Create output panel
            contoursOutput      = Instantiate(contoursOutputPrefab);
            contoursOutput.name = "Contours_OutputPanel";
            var outputPanel = ComponentManager.Instance.Get <OutputPanel>();
            outputPanel.SetPanel(contoursOutput.transform);
            contoursLayer.FetchGridValues();
            contoursOutput.AddGroup("All Contours", contoursLayer, true, false);

            // Create empty snapshots
            for (int i = 0; i < snapshotCount; ++i)
            {
                emptySnapshots.Add(Instantiate(emptySnapshotPrefab, SnapshotList, false));
            }
            GuiUtils.RebuildLayout(SnapshotList);
        }
        else
        {
            // Remove listeners
            addButton.onClick.RemoveAllListeners();
            showContoursToggle.onValueChanged.RemoveAllListeners();
            filteredToggle.onValueChanged.RemoveAllListeners();
            lockToggle.onValueChanged.RemoveAllListeners();
            analysisToggle.onValueChanged.RemoveAllListeners();
            excludeNoDataToggle.onValueChanged.RemoveAllListeners();
            dataLayers.OnLayerVisibilityChange   -= OnLayerVisibilityChange;
            dataLayers.OnLayerAvailabilityChange -= OnLayerAvailabilityChange;

            if (map)
            {
                var gridController = map.GetLayerController <GridLayerController>();
                if (gridController)
                {
                    gridController.OnShowGrid -= OnShowGrid;
                }
            }

            // for output update
            foreach (var grid in contoursLayer.grids)
            {
                grid.OnFilterChange -= OnGridFilterChange;
            }

            var outputPanel = ComponentManager.Instance.Get <OutputPanel>();
            outputPanel.RemovePanel(contoursOutput.transform);

            // Remove map layers
            DeleteAllLayers();

            // Remove snapshots UI
            foreach (var snapshot in snapshots)
            {
                Destroy(snapshot.uiTransform.gameObject);
            }
            snapshots.Clear();
            foreach (var emptySnapshot in emptySnapshots)
            {
                Destroy(emptySnapshot.gameObject);
            }
            emptySnapshots.Clear();

            grids.Clear();

            dataLayers.ResetToolOpacity();

            CancelRemoveSnapshotMode();
        }

        // Enable/disable map layer filters
        dataManager.EnableSiteFilters(!(isOn && filteredToggle.isOn));
    }