Esempio n. 1
0
        private void OnGUI()
        {
            EditorGUILayout.HelpBox("Mod dependency rules can be used to define relationships between this mod and other ones.", MessageType.Info, true);

            scrollPosition = GUILayoutHelper.ScrollView(scrollPosition, () =>
            {
                bool applyDeletionRequests = false;

                for (int i = 0; i < dependencies.Count; i++)
                {
                    ModDependencyEditorData dependency = dependencies[i];

                    EditorGUILayout.LabelField(dependency.TitleContent ?? RefreshTitleContent(ref dependency, i), foldoutStyle);

                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    GUILayoutHelper.Indent(() =>
                    {
                        GUILayoutHelper.Horizontal(() =>
                        {
                            using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
                            {
                                dependency.ModIndex = EditorGUILayout.Popup(modName, dependency.ModIndex, availableMods, GUILayout.MinWidth(100));
                                if (dependency.ModIndex < availableMods.Length - 1)
                                {
                                    dependency.Name = availableMods[dependency.ModIndex];
                                }
                                else
                                {
                                    dependency.Name = EditorGUILayout.TextField(dependency.Name, GUILayout.MinWidth(200));
                                }

                                if (changeCheckScope.changed)
                                {
                                    RefreshTitleContent(ref dependency, i);
                                }
                            }

                            EditorGUILayout.LabelField(".dfmod");

                            if (GUILayout.Button(deleteDependencyContent, EditorStyles.toolbarButton, GUILayout.Width(70)))
                            {
                                if (dependency.Name == null || EditorUtility.DisplayDialog("Delete dependency", $"Are you sure you want to delete dependency to {dependency.Name}?", "Yes", "No"))
                                {
                                    applyDeletionRequests |= dependency.DeletionRequest = true;
                                }
                            }
                        });

                        dependency.IsOptional = EditorGUILayout.Popup(requirement, dependency.IsOptional, requirementOptions);
                        dependency.IsPeer     = EditorGUILayout.Popup(loadOrder, dependency.IsPeer, loadOrderOptions);

                        GUILayoutHelper.Horizontal(() =>
                        {
                            dependency.RequireVersion = EditorGUILayout.Toggle(version, dependency.RequireVersion);

                            GUILayoutHelper.EnableGroup(dependency.RequireVersion, () =>
                            {
                                Vector3Int version = dependency.Version;
                                version.x          = EditorGUILayout.IntField(version.x);
                                version.y          = EditorGUILayout.IntField(version.y);
                                version.z          = EditorGUILayout.IntField(version.z);
                                dependency.Version = version;
                            });
                        });
                    });

                    dependencies[i] = dependency;

                    EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
                }

                if (applyDeletionRequests)
                {
                    var dependencies = new List <ModDependencyEditorData>();
                    for (int i = 0; i < this.dependencies.Count; i++)
                    {
                        if (!this.dependencies[i].DeletionRequest)
                        {
                            dependencies.Add(this.dependencies[i]);
                        }
                    }
                    this.dependencies = dependencies;
                }
            });

            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button(addDependencyContent))
                {
                    dependencies.Add(new ModDependencyEditorData()
                    {
                        ModIndex = availableMods.Length - 1
                    });
                }

                if (GUILayout.Button(saveAndCloseContent))
                {
                    SaveChanges();
                    Close();
                }
            });
        }