Example #1
0
        internal void SetModinfo(ModInfo modInfo)
        {
            this.modInfo = modInfo;

            ModDependency[] dependencies    = modInfo.Dependencies ?? Array.Empty <ModDependency>();
            var             editorDataGroup = new ModDependencyEditorData[dependencies.Length];

            for (int i = 0; i < dependencies.Length; i++)
            {
                ModDependency           dependency = dependencies[i];
                ModDependencyEditorData editorData = new ModDependencyEditorData();

                editorData.ModIndex = availableMods.ToList().IndexOf(dependency.Name);
                if (editorData.ModIndex == -1)
                {
                    editorData.ModIndex = availableMods.Length - 1;
                }
                editorData.Name = dependency.Name;

                editorData.IsOptional = dependency.IsOptional ? 1 : 0;
                editorData.IsPeer     = dependency.IsPeer ? 1 : 0;

                editorData.RequireVersion = !string.IsNullOrWhiteSpace(dependency.Version);
                if (editorData.RequireVersion)
                {
                    int[] versionParts = dependency.Version.Split('.').Select(x => int.Parse(x)).ToArray();
                    editorData.Version = new Vector3Int(versionParts[0], versionParts[1], versionParts[2]);
                }

                editorDataGroup[i] = editorData;
            }

            this.dependencies = editorDataGroup.ToList();
        }
Example #2
0
        private GUIContent RefreshTitleContent(ref ModDependencyEditorData dependency, int index)
        {
            string title;
            string iconName;

            if (string.IsNullOrWhiteSpace(dependency.Name))
            {
                title    = $"New #{index}";
                iconName = "PrefabModel On Icon";
            }
            else
            {
                var rawParts       = dependency.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var formattedParts = rawParts.Select(x => x.First().ToString().ToUpper() + x.Substring(1));
                title    = string.Join(" ", formattedParts);
                iconName = "PrefabModel Icon";
            }

            return(dependency.TitleContent = new GUIContent(title, EditorGUIUtility.IconContent(iconName).image));
        }
Example #3
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();
                }
            });
        }