/// <summary>
    /// Draws and responds to a toggle box for a component type. Clears Special types, if set.
    /// </summary>
    private void DrawToggle(int poolIndex, KMComponentPool.ComponentTypeEnum typeToToggle)
    {
        KMMission       mission       = (KMMission)serializedObject.targetObject;
        KMComponentPool componentPool = mission.GeneratorSetting.ComponentPools[poolIndex];

        bool previousValue = componentPool.ComponentTypes.Contains(typeToToggle);

        if (EditorGUILayout.ToggleLeft(
                typeToToggle.ToString(),
                previousValue))
        {
            if (!componentPool.ComponentTypes.Contains(typeToToggle))
            {
                componentPool.ComponentTypes.Add(typeToToggle);
            }
        }
        else
        {
            componentPool.ComponentTypes.RemoveAll(x => x == typeToToggle);
        }

        //If we just toggled something, clear any special flags too
        bool currentValue = componentPool.ComponentTypes.Contains(typeToToggle);

        if (previousValue != currentValue)
        {
            componentPool.SpecialComponentType = KMComponentPool.SpecialComponentTypeEnum.None;
        }
    }
Пример #2
0
    private void drawToggle(SerializedProperty componentPool, KMComponentPool.ComponentTypeEnum componentType)
    {
        SerializedProperty componentTypes = componentPool.FindPropertyRelative("ComponentTypes");
        bool previousValue = false;

        for (int i = 0; i < componentTypes.arraySize; i++)
        {
            if (componentTypes.GetArrayElementAtIndex(i).intValue == (int)componentType)
            {
                previousValue = true;
                break;
            }
        }
        bool newValue = EditorGUILayout.ToggleLeft(componentType.ToString(), previousValue);

        if (newValue != previousValue)
        {
            if (previousValue)
            {
                for (int i = componentTypes.arraySize - 1; i >= 0; i--)
                {
                    if (componentTypes.GetArrayElementAtIndex(i).intValue == (int)componentType)
                    {
                        componentTypes.DeleteArrayElementAtIndex(i);
                    }
                }
            }
            else
            {
                componentTypes.InsertArrayElementAtIndex(componentTypes.arraySize);
                componentTypes.GetArrayElementAtIndex(componentTypes.arraySize - 1).intValue = (int)componentType;
            }
            componentPool.FindPropertyRelative("SpecialComponentType").intValue = (int)KMComponentPool.SpecialComponentTypeEnum.None;
        }
    }
    private void DrawExpandedComponentTypeSelection(int poolIndex, SerializedProperty componentPool)
    {
        EditorGUI.indentLevel++;
        //Component Pool Editing
        using (new EditorGUILayout.VerticalScope("box"))
        {
            //Special Component Types
            using (new EditorGUILayout.VerticalScope("box"))
            {
                GUILayout.Label("All Types:");

                //Special
                DrawSpecialPicker(poolIndex);

                //Sources
                DrawComponentSourcePicker(poolIndex);
            }

            //Custom, specific component types
            using (new EditorGUILayout.VerticalScope("box"))
            {
                GUILayout.Label("Specific Types:");

                using (new EditorGUILayout.VerticalScope())
                {
                    //Base game modules
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        //Here we make an assumption that ComponentTypeFlags has individual solvable components,
                        //followed by individual needy components
                        Array componentTypes = Enum.GetValues(typeof(KMComponentPool.ComponentTypeEnum));

                        //Solvable
                        EditorGUILayout.BeginVertical();
                        EditorGUILayout.LabelField("Solvable:");
                        for (int i = 0; i < componentTypes.Length; i++)
                        {
                            KMComponentPool.ComponentTypeEnum componentType = (KMComponentPool.ComponentTypeEnum)componentTypes.GetValue(i);

                            if ((componentType >= KMComponentPool.ComponentTypeEnum.Wires) &&
                                (componentType < KMComponentPool.ComponentTypeEnum.NeedyVentGas))
                            {
                                DrawToggle(poolIndex, componentType);
                            }
                        }
                        EditorGUILayout.EndVertical();


                        //Needy
                        using (new EditorGUILayout.VerticalScope())
                        {
                            EditorGUILayout.LabelField("Needy:");
                            for (int i = 0; i < componentTypes.Length; i++)
                            {
                                KMComponentPool.ComponentTypeEnum componentType = (KMComponentPool.ComponentTypeEnum)componentTypes.GetValue(i);

                                if (componentType >= KMComponentPool.ComponentTypeEnum.NeedyVentGas &&
                                    componentType <= KMComponentPool.ComponentTypeEnum.NeedyKnob)
                                {
                                    DrawToggle(poolIndex, componentType);
                                }
                            }
                        }
                    }

                    //Mod modules
                    DrawModTypesList(poolIndex);
                }
            }
        }

        EditorGUILayout.Separator();
        EditorGUI.indentLevel--;
    }
Пример #4
0
    private void drawExpandedComponentTypeSelection(SerializedProperty componentPool)
    {
        EditorGUI.indentLevel++;
        using (new EditorGUILayout.VerticalScope("box"))
        {
            using (new EditorGUILayout.VerticalScope("box"))
            {
                SerializedProperty specialComponentTypeProperty = componentPool.FindPropertyRelative("SpecialComponentType");
                int oldSpecialComponentType = specialComponentTypeProperty.intValue;
                EditorGUILayout.PropertyField(specialComponentTypeProperty);
                if (specialComponentTypeProperty.intValue != oldSpecialComponentType)
                {
                    componentPool.FindPropertyRelative("ComponentTypes").ClearArray();
                    componentPool.FindPropertyRelative("ModTypes").ClearArray();
                }
                SerializedProperty allowedSourcesProperty = componentPool.FindPropertyRelative("AllowedSources");
                allowedSourcesProperty.intValue = EditorGUILayout.IntPopup("Source:", allowedSourcesProperty.intValue, new string[] { "Base", "Mods", "Base and Mods" }, new int[] { (int)KMComponentPool.ComponentSource.Base, (int)KMComponentPool.ComponentSource.Mods, (int)(KMComponentPool.ComponentSource.Base | KMComponentPool.ComponentSource.Mods) });
            }

            using (new EditorGUILayout.VerticalScope("box"))
            {
                GUILayout.Label("Specific types:");

                using (new EditorGUILayout.VerticalScope())
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        //Here we make an assumption that ComponentTypeFlags has individual solvable components,
                        //followed by individual needy components
                        Array componentTypes = Enum.GetValues(typeof(KMComponentPool.ComponentTypeEnum));

                        //Solvable
                        EditorGUILayout.BeginVertical();
                        EditorGUILayout.LabelField("Solvable:");
                        for (int i = 0; i < componentTypes.Length; i++)
                        {
                            KMComponentPool.ComponentTypeEnum componentType = (KMComponentPool.ComponentTypeEnum)componentTypes.GetValue(i);
                            if ((componentType >= KMComponentPool.ComponentTypeEnum.Wires) && (componentType < KMComponentPool.ComponentTypeEnum.NeedyVentGas))
                            {
                                drawToggle(componentPool, componentType);
                            }
                        }
                        EditorGUILayout.EndVertical();

                        //Needy
                        EditorGUILayout.BeginVertical();
                        EditorGUILayout.LabelField("Needy:");
                        for (int i = 0; i < componentTypes.Length; i++)
                        {
                            KMComponentPool.ComponentTypeEnum componentType = (KMComponentPool.ComponentTypeEnum)componentTypes.GetValue(i);
                            if (componentType >= KMComponentPool.ComponentTypeEnum.NeedyVentGas && componentType <= KMComponentPool.ComponentTypeEnum.NeedyKnob)
                            {
                                drawToggle(componentPool, componentType);
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }

                    SerializedProperty modTypesProperty = componentPool.FindPropertyRelative("ModTypes");
                    EditorGUILayout.PropertyField(modTypesProperty, true);
                    for (int i = 0; i < modTypesProperty.arraySize; i++)
                    {
                        SerializedProperty element = modTypesProperty.GetArrayElementAtIndex(i);
                        element.stringValue = element.stringValue.Trim();
                    }

                    if (componentPool.FindPropertyRelative("ModTypes").arraySize != 0)
                    {
                        componentPool.FindPropertyRelative("SpecialComponentType").intValue = (int)KMComponentPool.SpecialComponentTypeEnum.None;
                    }
                }
            }
        }
        EditorGUILayout.Separator();
        EditorGUI.indentLevel--;
    }