public CountryDecoratorGroupInfo GetDecoratorGroup(int groupIndex, bool createIfNotExists)
        {
            if (decoratorLayer == null)
            {
                return(null);
            }

            // Find the decorator container and returns the group info
            CountryDecoratorGroupInfo[] dgis = decoratorLayer.GetComponentsInChildren <CountryDecoratorGroupInfo> (true);
            for (int k = 0; k < dgis.Length; k++)
            {
                if (dgis [k].groupIndex == groupIndex)
                {
                    return(dgis [k]);
                }
            }

            // If it doesn't exist, create a container in the scene
            if (!createIfNotExists)
            {
                return(null);
            }
            GameObject o = new GameObject("DecoratorGroup" + groupIndex);

            o.transform.SetParent(decoratorLayer.transform, false);
            CountryDecoratorGroupInfo dgi = o.AddComponent <CountryDecoratorGroupInfo> ();

            dgi.groupIndex = groupIndex;
            dgi.active     = true;
            return(dgi);
        }
        public void ClearDecoratorGroup(int groupIndex)
        {
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, false);

            if (di != null)
            {
                di.RemoveAllDecorators();
            }
        }
        public void RemoveCountryDecorator(int groupIndex, string countryName)
        {
            // Get the group decorator container
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, false);

            if (di != null)
            {
                di.RemoveDecorator(countryName);
            }
        }
 public void ForceUpdateDecorators()
 {
     for (int k = 0; k < NUM_GROUPS; k++)
     {
         CountryDecoratorGroupInfo dgi = GetDecoratorGroup(k, false);
         if (dgi != null)
         {
             dgi.UpdateDecorators(true);
         }
     }
 }
        public void SetCountryDecorator(int groupIndex, string countryName, CountryDecorator decorator)
        {
            // Get the group decorator container
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, true);

            if (decorator.countryName == null || !decorator.countryName.Equals(countryName))
            {
                decorator.countryName = countryName;
            }
            di.SetDecorator(decorator);
        }
        public List <string> GetDecoratedCountries(int groupIndex, bool addCountryIndexSuffix)
        {
            List <string>             decoratedCountries = new List <string> ();
            CountryDecoratorGroupInfo dg = GetDecoratorGroup(groupIndex, false);

            if (dg != null)
            {
                decoratedCountries.AddRange(dg.GetDecoratedCountries(addCountryIndexSuffix));
            }
            return(decoratedCountries);
        }
        public int GetCountryDecoratorCount(int groupIndex)
        {
            CountryDecoratorGroupInfo dg = GetDecoratorGroup(groupIndex, false);

            if (dg != null)
            {
                return(dg.decorators != null ? dg.decorators.Count : 0);
            }
            else
            {
                return(0);
            }
        }
        public CountryDecorator GetCountryDecorator(int groupIndex, string countryName)
        {
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, true);

            if (di != null)
            {
                return(di.GetDecorator(countryName));
            }
            else
            {
                return(null);
            }
        }
 public void UpdateDecoratorsCountryName(string oldName, string newName)
 {
     for (int k = 0; k < NUM_GROUPS; k++)
     {
         CountryDecorator decorator = GetCountryDecorator(k, oldName);
         if (decorator != null)
         {
             decorator.customLabel = newName;
             CountryDecoratorGroupInfo dg = GetDecoratorGroup(k, false);
             if (dg != null)
             {
                 dg.UpdateDecorators(false);
             }
         }
     }
 }
        public override void OnInspectorGUI()
        {
            if (_decorator == null)
            {
                return;
            }

            bool requestChanges = false;

            EditorGUILayout.Separator();
            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Group", GUILayout.Width(120));
            int oldGroup = _decorator.GUIGroupIndex;

            _decorator.GUIGroupIndex = EditorGUILayout.Popup(_decorator.GUIGroupIndex, groupNames, GUILayout.MaxWidth(200));
            if (_decorator.GUIGroupIndex != oldGroup || decoratorGroup == null)
            {
                decoratorGroup = _decorator.GetDecoratorGroup(_decorator.GUIGroupIndex, true);
            }

            if (GUILayout.Button("Clear"))
            {
                _decorator.ClearDecoratorGroup(_decorator.GUIGroupIndex);
                if (decorator != null)
                {
                    decorator.isNew = true;
                }
                ReloadGroupNames();
                _decorator.ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("   Enabled", GUILayout.Width(120));
            decoratorGroup.active = EditorGUILayout.Toggle(decoratorGroup.active, GUILayout.Width(20));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            // country selector
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Country", GUILayout.Width(120));
            if (_decorator.lastCountryCount != _map.countries.Length)
            {
                _decorator.ReloadCountryNames();
            }
            int selection = EditorGUILayout.Popup(_decorator.GUICountryIndex, _decorator.countryNames);

            if (selection != _decorator.GUICountryIndex)
            {
                SetCountryFromCombo(selection);
            }

            bool prevc = _decorator.groupByContinent;

            GUILayout.Label("Grouped");
            _decorator.groupByContinent = EditorGUILayout.Toggle(_decorator.groupByContinent, GUILayout.Width(20));
            if (_decorator.groupByContinent != prevc)
            {
                _decorator.ReloadCountryNames();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(120));
            DrawWarningLabel("(Click on SceneView to select a country)");
            EditorGUILayout.EndHorizontal();

            // type of decoration
            if (_decorator.GUICountryName.Length > 0)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(120));
                if (GUILayout.Button("Toggle Zoom"))
                {
                    ToggleZoomState();
                }
                EditorGUILayout.EndHorizontal();

                CountryDecorator existingDecorator = _decorator.GetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                if (existingDecorator != null)
                {
                    decorator = existingDecorator;
                }
                else if (decorator == null || !decorator.countryName.Equals(_decorator.GUICountryName))
                {
                    decorator = new CountryDecorator(_decorator.GUICountryName);
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Hidden", GUILayout.Width(120));
                bool prevHidden = decorator.hidden;
                decorator.hidden = EditorGUILayout.Toggle(decorator.hidden);
                if (prevHidden != decorator.hidden)
                {
                    requestChanges = true;
                }
                EditorGUILayout.EndHorizontal();

                if (!decorator.hidden)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Label Visible", GUILayout.Width(120));
                    bool prevLabelVisible = decorator.labelVisible;
                    decorator.labelVisible = EditorGUILayout.Toggle(decorator.labelVisible);
                    if (prevLabelVisible != decorator.labelVisible)
                    {
                        requestChanges = true;
                    }
                    EditorGUILayout.EndHorizontal();

                    if (decorator.labelVisible)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Label", GUILayout.Width(120));
                        decorator.labelOverride = EditorGUILayout.Toggle(decorator.labelOverride, GUILayout.Width(40));
                        if (decorator.labelOverride)
                        {
                            GUILayout.Label("Text", GUILayout.Width(40));
                            string prevLabel = decorator.customLabel;
                            decorator.customLabel = EditorGUILayout.TextField(decorator.customLabel);
                            if (!prevLabel.Equals(decorator.customLabel))
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Font", GUILayout.Width(120));
                        Font prevFont = decorator.labelFontOverride;
                        decorator.labelFontOverride = (Font)EditorGUILayout.ObjectField(decorator.labelFontOverride, typeof(Font), false);
                        if (decorator.labelFontOverride != prevFont)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Color", GUILayout.Width(120));
                        decorator.labelOverridesColor = EditorGUILayout.Toggle(decorator.labelOverridesColor, GUILayout.Width(40));
                        if (decorator.labelOverridesColor)
                        {
                            GUILayout.Label("Color", GUILayout.Width(40));
                            Color prevColor = decorator.labelColor;
                            decorator.labelColor = EditorGUILayout.ColorField(decorator.labelColor, GUILayout.Width(50));
                            if (prevColor != decorator.labelColor)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Custom Size", GUILayout.Width(120));
                        decorator.labelOverridesFontSize = EditorGUILayout.Toggle(decorator.labelOverridesFontSize, GUILayout.Width(40));
                        if (decorator.labelOverridesFontSize)
                        {
                            GUILayout.Label("Size", GUILayout.Width(40));
                            float prevSize = decorator.labelFontSize;
                            decorator.labelFontSize = EditorGUILayout.Slider(decorator.labelFontSize, 0.01f, 1.0f);
                            if (prevSize != decorator.labelFontSize)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();


                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Offset", GUILayout.Width(120));
                        Vector2 prevLabelOffset = decorator.labelOffset;
                        decorator.labelOffset = EditorGUILayout.Vector2Field("", decorator.labelOffset);
                        if (prevLabelOffset != decorator.labelOffset)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Rotation", GUILayout.Width(120));
                        float prevLabelRotation = decorator.labelRotation;
                        decorator.labelRotation = EditorGUILayout.Slider(decorator.labelRotation, 0, 359);
                        if (prevLabelRotation != decorator.labelRotation)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();
                    }


                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("Colorized", GUILayout.Width(120));
                    bool prevColorized = decorator.isColorized;
                    decorator.isColorized = EditorGUILayout.Toggle(decorator.isColorized);
                    if (prevColorized != decorator.isColorized)
                    {
                        requestChanges = true;
                    }
                    if (decorator.isColorized)
                    {
                        GUILayout.Label("Fill Color", GUILayout.Width(120));
                        Color prevColor = decorator.fillColor;
                        decorator.fillColor = EditorGUILayout.ColorField(decorator.fillColor, GUILayout.Width(50));
                        if (prevColor != decorator.fillColor)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("   Include All Regions", GUILayout.Width(120));
                        bool prevIncludeAllRegions = decorator.includeAllRegions;
                        decorator.includeAllRegions = EditorGUILayout.Toggle(decorator.includeAllRegions);
                        if (prevIncludeAllRegions != decorator.includeAllRegions)
                        {
                            requestChanges = true;
                        }
                        EditorGUILayout.EndHorizontal();

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label("Texture", GUILayout.Width(120));
                        Texture2D prevTexture = decorator.texture;
                        decorator.texture = (Texture2D)EditorGUILayout.ObjectField(decorator.texture, typeof(Texture2D), false);
                        if (decorator.texture != prevTexture)
                        {
                            requestChanges = true;
                        }

                        if (decorator.texture != null)
                        {
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Include All Regions", GUILayout.Width(120));
                            prevIncludeAllRegions = decorator.applyTextureToAllRegions;
                            decorator.applyTextureToAllRegions = EditorGUILayout.Toggle(decorator.applyTextureToAllRegions);
                            if (prevIncludeAllRegions != decorator.applyTextureToAllRegions)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Scale", GUILayout.Width(120));
                            Vector2 prevVector = decorator.textureScale;
                            decorator.textureScale = EditorGUILayout.Vector2Field("", decorator.textureScale);
                            if (prevVector != decorator.textureScale)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Offset", GUILayout.Width(120));
                            prevVector = decorator.textureOffset;
                            decorator.textureOffset = EditorGUILayout.Vector2Field("", decorator.textureOffset);
                            if (prevVector != decorator.textureOffset)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("   Rotation", GUILayout.Width(120));
                            float prevFloat = decorator.textureRotation;
                            decorator.textureRotation = EditorGUILayout.Slider(decorator.textureRotation, 0, 360);
                            if (prevFloat != decorator.textureRotation)
                            {
                                requestChanges = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.BeginHorizontal();
                if (decorator.isNew)
                {
                    if (GUILayout.Button("Assign"))
                    {
                        _decorator.SetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName, decorator);
                        ReloadGroupNames();
                        _decorator.ReloadCountryNames();
                    }
                }
                else if (GUILayout.Button("Remove"))
                {
                    decorator = null;
                    _decorator.RemoveCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                    ReloadGroupNames();
                    _decorator.ReloadCountryNames();
                }
                EditorGUILayout.EndHorizontal();

                if (!decoratorGroup.active)
                {
                    DrawWarningLabel("Enable the decoration group to activate changes");
                }
            }


            EditorGUILayout.EndVertical();

            if (requestChanges)
            {
                _decorator.ForceUpdateDecorators();
                SceneView.RepaintAll();
                EditorUtility.SetDirty(_map);
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
            }
        }