Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void ClearDecoratorGroup(int groupIndex)
        {
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, false);

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

            if (di != null)
            {
                di.RemoveDecorator(countryName);
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public void ForceUpdateDecorators()
 {
     for (int k = 0; k < NUM_GROUPS; k++)
     {
         CountryDecoratorGroupInfo dgi = GetDecoratorGroup(k, false);
         if (dgi != null)
         {
             dgi.UpdateDecorators(true);
         }
     }
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public CountryDecorator GetCountryDecorator(int groupIndex, string countryName)
        {
            CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, true);

            if (di != null)
            {
                return(di.GetDecorator(countryName));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 8
0
        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 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);
                ReloadGroupNames();
                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 (lastCountryCount != _map.countries.Length)
            {
                ReloadCountryNames();
            }
            int selection = EditorGUILayout.Popup(_decorator.GUICountryIndex, countryNames);

            if (selection != _decorator.GUICountryIndex)
            {
                _decorator.GUICountryName  = "";
                _decorator.GUICountryIndex = selection;
                FlyToCountry();
            }

            bool prevc = _decorator.groupByContinent;

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

            EditorGUILayout.EndHorizontal();

            // type of decoration
            if (_decorator.GUICountryName.Length > 0)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(120));
                if (GUILayout.Button("Toggle Zoom"))
                {
                    ToggleZoomState();
                }
                if (GUILayout.Button("Fly To"))
                {
                    FlyToCountry();
                }
                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("   Text", GUILayout.Width(120));
                        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);
                        if (decorator.labelOverridesColor)
                        {
                            GUILayout.Label("Color", GUILayout.Width(120));
                            Color prevColor = decorator.labelColor;
                            decorator.labelColor = EditorGUILayout.ColorField(decorator.labelColor);
                            if (prevColor != decorator.labelColor)
                            {
                                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 (decorator.isColorized != prevColorized)
                    {
                        requestChanges = true;
                    }
                    if (decorator.isColorized)
                    {
                        GUILayout.Label("Fill Color", GUILayout.Width(120));
                        Color prevColor = decorator.fillColor;
                        decorator.fillColor = EditorGUILayout.ColorField(decorator.fillColor);
                        if (prevColor != decorator.fillColor)
                        {
                            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();
                            Vector2 prevVector = decorator.textureScale;
                            decorator.textureScale = EditorGUILayout.Vector2Field("   Scale", decorator.textureScale);
                            if (prevVector != decorator.textureScale)
                            {
                                requestChanges = true;
                            }
                            EditorGUILayout.EndHorizontal();

                            EditorGUILayout.BeginHorizontal();
                            prevVector = decorator.textureOffset;
                            decorator.textureOffset = EditorGUILayout.Vector2Field("   Offset", 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();
                }
                EditorGUILayout.BeginHorizontal();
                if (decorator.isNew)
                {
                    if (GUILayout.Button("Assign"))
                    {
                        _decorator.SetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName, decorator);
                        ReloadGroupNames();
                        ReloadCountryNames();
                    }
                }
                else if (GUILayout.Button("Remove"))
                {
                    decorator = null;
                    _decorator.RemoveCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName);
                    ReloadGroupNames();
                    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);
                if (!Application.isPlaying)
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
        }