Exemple #1
0
 public VehicleChassiRequest(VehiclePart_Config _part, int _chassisVersion,
                             Dictionary <VehiclePart_Config, int> _requiredParts, Storage _deliverTo, FactoryMode _factoryMode)
     : base(_part, _deliverTo)
 {
     part           = _part;
     chassisVersion = _chassisVersion;
     requiredParts  = _requiredParts;
     deliverTo      = _deliverTo;
     factoryMode    = _factoryMode;
 }
Exemple #2
0
    private void readCurrentMission()
    {
        totalBombCount = 1;
        multipleBombsComponentPools    = new List <int>();
        multipleBombsGeneratorSettings = new Dictionary <int, KeyValuePair <KMGeneratorSetting, int> >();
        factoryMode = FactoryMode.Static;
        factoryModeComponentPool = -1;
        SerializedProperty componentPools = serializedObject.FindProperty("GeneratorSetting.ComponentPools");

        for (int i = 0; i < componentPools.arraySize; i++)
        {
            SerializedProperty componentPool = componentPools.GetArrayElementAtIndex(i);
            SerializedProperty modTypes      = componentPool.FindPropertyRelative("ModTypes");
            readComponentPool(modTypes, componentPool.FindPropertyRelative("Count").intValue, i);
        }
    }
Exemple #3
0
 private void readComponentPool(SerializedProperty modTypes, int count, int index)
 {
     if (modTypes.arraySize == 1)
     {
         string modType = modTypes.GetArrayElementAtIndex(0).stringValue;
         if (modType == MULTIPLE_BOMBS_COMPONENT_POOL_ID)
         {
             totalBombCount += count;
             multipleBombsComponentPools.Add(index);
         }
         else if (modType.StartsWith(FACTORY_MODE_COMPONENT_POOL_ID))
         {
             factoryMode = (FactoryMode)count;
             factoryModeComponentPool = index;
         }
         else if (modType.StartsWith(MULTIPLE_BOMBS_COMPONENT_POOL_ID + ":"))
         {
             string[] strings = modType.Split(new char[] { ':' }, 3);
             if (strings.Length != 3)
             {
                 return;
             }
             int bombIndex;
             if (!int.TryParse(strings[1], out bombIndex))
             {
                 return;
             }
             if (!multipleBombsGeneratorSettings.ContainsKey(bombIndex) && bombIndex > 0)
             {
                 KMGeneratorSetting generatorSetting;
                 try
                 {
                     generatorSetting = JsonConvert.DeserializeObject <KMGeneratorSetting>(strings[2]);
                 }
                 catch
                 {
                     return;
                 }
                 multipleBombsGeneratorSettings.Add(bombIndex, new KeyValuePair <KMGeneratorSetting, int>(generatorSetting, index));
             }
         }
     }
 }
Exemple #4
0
    public override void OnInspectorGUI()
    {
        if (target != null)
        {
            serializedObject.Update();

            //Basic mission meta-data
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("ID");
            EditorGUILayout.SelectableLabel(serializedObject.targetObject.name);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("ID In-Game");
            EditorGUILayout.SelectableLabel(string.Format("mod_{0}_{1}", ModConfig.ID, serializedObject.targetObject.name));
            EditorGUILayout.EndHorizontal();

            SerializedProperty displayNameProperty = serializedObject.FindProperty("DisplayName");
            EditorGUILayout.PropertyField(displayNameProperty);
            displayNameProperty.stringValue = displayNameProperty.stringValue.Trim();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Description"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("PacingEventsEnabled"));

            SerializedProperty componentPools = serializedObject.FindProperty("GeneratorSetting.ComponentPools");

            if (factoryMode <= FactoryMode.FiniteSequenceGlobalTimeStrikes)
            {
                int newTotalBombCount = EditorGUILayout.IntField("Bomb Count", totalBombCount);
                setTotalBombCount(newTotalBombCount);
            }
            else
            {
                bool wasEnabled = GUI.enabled;
                GUI.enabled = false;
                EditorGUILayout.TextField("Bomb Count", "Infinite");
                GUI.enabled = wasEnabled;
            }

            FactoryMode newFactoryMode = (FactoryMode)EditorGUILayout.Popup("Factory Mode", (int)factoryMode, FactoryModeFriendlyNames);
            if (newFactoryMode != factoryMode)
            {
                if (newFactoryMode == FactoryMode.Static)
                {
                    if (factoryModeComponentPool != -1)
                    {
                        componentPools.DeleteArrayElementAtIndex(factoryModeComponentPool);
                        readCurrentMission();
                    }
                }
                else if (factoryModeComponentPool == -1)
                {
                    int index = addComponentPool(serializedObject.FindProperty("GeneratorSetting"));
                    SerializedProperty componentPool = componentPools.GetArrayElementAtIndex(index);
                    componentPool.FindPropertyRelative("Count").intValue     = (int)newFactoryMode;
                    componentPool.FindPropertyRelative("ModTypes").arraySize = 1;
                    componentPool.FindPropertyRelative("ModTypes").GetArrayElementAtIndex(0).stringValue = FACTORY_MODE_COMPONENT_POOL_ID;
                    factoryModeComponentPool = index;
                }
                else
                {
                    componentPools.GetArrayElementAtIndex(factoryModeComponentPool).FindPropertyRelative("Count").intValue = (int)newFactoryMode;
                }
                if (newFactoryMode >= FactoryMode.InfiniteSequence)
                {
                    setTotalBombCount(1);
                }
                factoryMode = newFactoryMode;
            }

            //Generator Settings
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Generator Settings");

            List <string> unusedGeneratorSettings     = new List <string>();
            List <KeyValuePair <int, string> > tabMap = new List <KeyValuePair <int, string> >();
            tabMap.Add(new KeyValuePair <int, string>(0, "Bomb 0"));
            foreach (KeyValuePair <int, KeyValuePair <KMGeneratorSetting, int> > kv in multipleBombsGeneratorSettings)
            {
                if (kv.Key < totalBombCount || factoryMode >= FactoryMode.InfiniteSequence)
                {
                    tabMap.Add(new KeyValuePair <int, string>(kv.Key, "Bomb " + kv.Key));
                }
                else
                {
                    unusedGeneratorSettings.Add(kv.Key.ToString());
                }
            }
            tabMap.Sort((x, y) => x.Key.CompareTo(y.Key));

            if (unusedGeneratorSettings.Count > 0)
            {
                string unusedGeneratorSettingsWarningMessage = "The mission contains unused generator settings (for " + (unusedGeneratorSettings.Count > 1 ? "bombs " + string.Join(", ", unusedGeneratorSettings.ToArray()) : "bomb " + unusedGeneratorSettings[0]) + ").";
                EditorGUILayout.HelpBox(unusedGeneratorSettingsWarningMessage, MessageType.Warning);
            }

            EditorGUILayout.BeginVertical("box");
            int currentTab = activeGeneratorSetting != -1 ? tabMap.FindIndex((x) => x.Key == activeGeneratorSetting) : tabMap.Count;
            if (currentTab == -1)
            {
                activeGeneratorSetting = 0;
                currentTab             = 0;
            }
            List <string> tabs = new List <string>();
            tabs.Add(tabMap[0].Value);
            float minWidth = new GUIStyle("ButtonLeft").CalcSize(new GUIContent(tabMap[0].Value)).x;
            for (int i = 1; i < tabMap.Count; i++)
            {
                tabs.Add(tabMap[i].Value);
                float width = new GUIStyle("Button").CalcSize(new GUIContent(tabMap[i].Value)).x;
                if (width > minWidth)
                {
                    minWidth = width;
                }
            }
            tabs.Add("+");
            bool fits = Screen.width / tabs.Count > minWidth; //Screen.width is not an accurate measure of the available width but having the bar space always visible was too ugly
            if (!fits)
            {
                scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(40));
            }
            int newTab = GUILayout.Toolbar(currentTab, tabs.ToArray());
            if (!fits)
            {
                EditorGUILayout.EndScrollView();
            }
            if (newTab != currentTab)
            {
                if (newTab == tabs.Count - 1)
                {
                    activeGeneratorSetting = -1;
                }
                else
                {
                    activeGeneratorSetting     = tabMap[newTab].Key;
                    activeComponentPool        = -1;
                    GUIUtility.keyboardControl = 0;
                }
            }

            if (activeGeneratorSetting == -1)
            {
                if (factoryMode <= FactoryMode.FiniteSequenceGlobalTimeStrikes)
                {
                    List <int> vaildBombs = new List <int>();
                    for (int i = 1; i < totalBombCount; i++)
                    {
                        if (!multipleBombsGeneratorSettings.ContainsKey(i))
                        {
                            vaildBombs.Add(i);
                        }
                    }
                    if (vaildBombs.Count == 0)
                    {
                        EditorGUILayout.HelpBox("All of the bombs have a Generator Setting.", MessageType.None);
                    }
                    else
                    {
                        if (!vaildBombs.Contains(currentAddGeneratorSettingIndex))
                        {
                            currentAddGeneratorSettingIndex = vaildBombs[0];
                        }
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Add Generator Setting for bomb");
                        currentAddGeneratorSettingIndex = vaildBombs[EditorGUILayout.Popup(vaildBombs.IndexOf(currentAddGeneratorSettingIndex), vaildBombs.Select((x) => x.ToString()).ToArray(), GUILayout.Width(60))];
                        EditorGUILayout.EndHorizontal();
                    }
                    bool wasEnabled = GUI.enabled;
                    GUI.enabled = vaildBombs.Count != 0;
                    if (GUILayout.Button("Add Generator Setting"))
                    {
                        addGeneratorSetting(currentAddGeneratorSettingIndex);
                    }
                    GUI.enabled = wasEnabled;
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Add Generator Setting for bomb");
                    currentAddGeneratorSettingIndex = EditorGUILayout.IntField(currentAddGeneratorSettingIndex, GUILayout.Width(60));
                    EditorGUILayout.EndHorizontal();
                    bool isVaildBomb = currentAddGeneratorSettingIndex != 0 && !multipleBombsGeneratorSettings.ContainsKey(currentAddGeneratorSettingIndex);
                    if (!isVaildBomb)
                    {
                        EditorGUILayout.HelpBox("Bomb " + currentAddGeneratorSettingIndex + " already has a Generator Setting.", MessageType.None);
                    }
                    bool wasEnabled = GUI.enabled;
                    GUI.enabled = isVaildBomb;
                    if (GUILayout.Button("Add Generator Setting"))
                    {
                        addGeneratorSetting(currentAddGeneratorSettingIndex);
                    }
                    GUI.enabled = wasEnabled;
                }
            }
            else if (activeGeneratorSetting == 0)
            {
                bool wasEnabled = GUI.enabled;
                GUI.enabled = false;
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Button("Delete");
                EditorGUILayout.EndHorizontal();
                GUI.enabled = wasEnabled;
                drawGeneratorSetting(serializedObject.FindProperty("GeneratorSetting"), true);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                bool delete = GUILayout.Button("Delete");
                EditorGUILayout.EndHorizontal();
                if (delete)
                {
                    removeGeneratorSetting(activeGeneratorSetting);
                }
                else
                {
                    KeyValuePair <KMGeneratorSetting, int> activeKV = multipleBombsGeneratorSettings[activeGeneratorSetting];
                    KMMission dummyMission = CreateInstance <KMMission>();
                    dummyMission.GeneratorSetting = activeKV.Key;
                    SerializedObject dummyMissionObject = new SerializedObject(dummyMission);
                    drawGeneratorSetting(dummyMissionObject.FindProperty("GeneratorSetting"), false);
                    if (dummyMissionObject.ApplyModifiedProperties())
                    {
                        serializedObject.FindProperty("GeneratorSetting").FindPropertyRelative("ComponentPools").GetArrayElementAtIndex(activeKV.Value).FindPropertyRelative("ModTypes").GetArrayElementAtIndex(0).stringValue = "Multiple Bombs:" + activeGeneratorSetting + ":" + JsonConvert.SerializeObject(activeKV.Key);
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
        serializedObject.ApplyModifiedProperties();
    }
Exemple #5
0
 public void Init(FactoryMode _factoryMode)
 {
     factoryMode = _factoryMode;
     Debug.Log(workshopIndex + " MODE: " + _factoryMode);
 }