private void DisplayGUI()
        {
            if (!streamingWorld.IsReady)
            {
                EditorGUILayout.HelpBox("Requires DaggerfallUnity singleton with Arena2 path set.", MessageType.Info);
                return;
            }

            if (!streamingWorld.LocalPlayerGPS)
            {
                EditorGUILayout.HelpBox("Requires player object with PlayerGPS component.", MessageType.Info);
                var propLocalPlayerGPS = Prop("LocalPlayerGPS");
                propLocalPlayerGPS.objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("", ""), propLocalPlayerGPS.objectReferenceValue, typeof(PlayerGPS), true);
                return;
            }

            DrawTravelMap();
            DrawDefaultInspector();

            EditorGUILayout.Space();
            var propFindLocationString = Prop("EditorFindLocationString");

            EditorGUILayout.LabelField(new GUIContent("Find Location", "Enter exact city name in format RegionName/CityName. Case-sensitive."));
            GUILayoutHelper.Horizontal(() =>
            {
                propFindLocationString.stringValue = EditorGUILayout.TextField(propFindLocationString.stringValue.Trim());
                if (GUILayout.Button("Find"))
                {
                    streamingWorld.__EditorFindLocation();
                }
            });

            EditorGUILayout.Space();
            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Get From PlayerGPS"))
                {
                    streamingWorld.__EditorGetFromPlayerGPS();
                    EditorUtility.SetDirty(streamingWorld.LocalPlayerGPS);
                }
                if (GUILayout.Button("Apply To PlayerGPS"))
                {
                    streamingWorld.__EditorApplyToPlayerGPS();
                    EditorUtility.SetDirty(streamingWorld.LocalPlayerGPS);
                }
            });
            //if (GUILayout.Button("Refresh Preview"))
            //{
            //    streamingWorld.__EditorRefreshPreview();
            //}
        }
        private void Keys_DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            int line = 0;

            Section section = data.Sections[currentSection];
            Key     key     = section[index];

            if (!sectionExpanded[currentSection])
            {
                EditorGUI.LabelField(LineRect(rect), ModSettingsData.FormattedName(key.Name));
                SetKeySize(currentSection, index, lineHeight);
                return;
            }

            if (IsPreset)
            {
                using (new EditorGUI.DisabledScope(!CurrentPreset[section.Name]))
                {
                    CurrentPreset[section.Name, key.Name] = EditorGUI.ToggleLeft(LineRect(rect, line++), key.Name, CurrentPreset[section.Name, key.Name]);
                    EditorGUI.LabelField(LineRect(rect, line++), key.Description);
                }
            }
            else
            {
                key.Name        = EditorGUI.TextField(LineRect(rect, line++), "Name", key.Name);
                key.Description = EditorGUI.TextField(LineRect(rect, line++), "Description", key.Description);
            }

            using (new EditorGUI.DisabledScope(IsPreset))
                data.SetType(currentSection, index, ref key, (KeyType)EditorGUI.EnumPopup(LineRect(rect, line++), "UI Control", key.KeyType));

            using (new EditorGUI.DisabledScope(IsPreset && !CurrentPreset[section.Name]))
            {
                rect.y += lineHeight * 3;
                int lines = key.OnEditorWindow(
                    rect,
                    (subrect, label, rects) => GUILayoutHelper.Horizontal(subrect, label, rects),
                    (subrect, linesPerItem, rects) => GUILayoutHelper.Vertical(subrect, linesPerItem, rects),
                    cache);

                SetKeySize(currentSection, index, (lines + 4) * lineHeight);
            }
        }
        private void Sections_DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)
        {
            Section section = data.Sections[currentSection = index];

            if (sectionsExpanded)
            {
                keys[index].DoList(rect);
            }
            else if (IsPreset)
            {
                CurrentPreset[section.Name] = EditorGUI.ToggleLeft(LineRect(rect), section.Name, CurrentPreset[section.Name]);
            }
            else
            {
                GUILayoutHelper.Vertical(rect, 1,
                                         (line) => GUILayoutHelper.Horizontal(line, null,
                                                                              (r) => section.Name       = EditorGUI.TextField(r, "Name", section.Name),
                                                                              (r) => section.IsAdvanced = EditorGUI.ToggleLeft(r, "Is Advanced or experimental", section.IsAdvanced)),
                                         (line) => section.Description = EditorGUI.TextField(line, "Description", section.Description));
            }
        }
        private void OnGUI()
        {
            lineHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            GUILayoutHelper.Vertical(() =>
            {
                GUILayoutHelper.Area(new Rect(0, 0, 3 * position.width / 8, position.height), () =>
                {
                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        GUILayout.Box((Texture2D)EditorGUIUtility.Load("Assets/Resources/AppIcon1.png"), GUILayout.Width(50), GUILayout.Height(50));
                        var titleStyle      = new GUIStyle(EditorStyles.largeLabel);
                        titleStyle.font     = EditorGUIUtility.Load("Assets/Resources/Fonts/TESFonts/Kingthings Petrock.ttf") as Font;
                        titleStyle.fontSize = 50;
                        GUILayout.Label(modName, titleStyle);
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        GUILayout.Label(localPath);

                        if (IconButton("d_editicon.sml", "Select target path"))
                        {
                            if (!string.IsNullOrEmpty(targetPath = EditorUtility.OpenFolderPanel("Select mod folder", rootPath, "Mod")))
                            {
                                Load();
                            }
                        }
                        if (IconButton("d_Refresh", "Reload and discharge unsaved changes"))
                        {
                            Load();
                        }
                        using (new EditorGUI.DisabledScope(modName == "None" || duplicateSections || duplicateKeys))
                            if (IconButton("d_P4_CheckOutLocal", "Save settings to disk"))
                            {
                                Save();
                            }
                    });

                    saveOnExit = EditorGUILayout.ToggleLeft(new GUIContent("Save on Exit", "Save automatically when window is closed."), saveOnExit);

                    if (data == null)
                    {
                        EditorGUILayout.HelpBox("Select a folder to store settings.", MessageType.Info);
                        return;
                    }

                    if (duplicateSections)
                    {
                        EditorGUILayout.HelpBox("Multiple sections with the same name detected!", MessageType.Error);
                    }
                    if (duplicateKeys)
                    {
                        EditorGUILayout.HelpBox("Multiple keys with the same name in a section detected!", MessageType.Error);
                    }

                    DrawHeader("Header");
                    EditorGUILayout.HelpBox("Version of settings checked against local values and presets.", MessageType.None);
                    data.Version = EditorGUILayout.TextField("Version", data.Version);

                    DrawHeader("Presets");
                    EditorGUILayout.HelpBox("Pre-defined values for all or a set of settings. Author is an optional field.", MessageType.None);
                    presetsScrollPosition = GUILayoutHelper.ScrollView(presetsScrollPosition, () => presets.DoLayoutList());
                    EditorGUILayout.Space();
                    if (presets.index != -1)
                    {
                        var preset    = data.Presets[presets.index];
                        preset.Author = EditorGUILayout.TextField("Author", preset.Author);
                        EditorGUILayout.PrefixLabel("Description");
                        preset.Description = EditorGUILayout.TextArea(preset.Description);
                    }

                    GUILayout.FlexibleSpace();

                    DrawHeader("Tools");
                    if (GUILayout.Button("Import Legacy INI"))
                    {
                        string iniPath;
                        if (!string.IsNullOrEmpty(iniPath = EditorUtility.OpenFilePanel("Select ini file", rootPath, "ini")))
                        {
                            data.ImportLegacyIni(new IniParser.FileIniDataParser().ReadFile(iniPath));
                        }
                    }
                    else if (GUILayout.Button("Merge presets"))
                    {
                        string path;
                        if (!string.IsNullOrEmpty(path = EditorUtility.OpenFilePanel("Select preset file", rootPath, "json")))
                        {
                            data.LoadPresets(path, true);
                        }
                    }
                    else if (GUILayout.Button("Export localization table"))
                    {
                        string path;
                        if (!string.IsNullOrEmpty(path = EditorUtility.OpenFolderPanel("Select a folder", textPath, "")))
                        {
                            MakeTextDatabase(Path.Combine(path, string.Format("mod_{0}.txt", modName)));
                        }
                    }

                    EditorGUILayout.Space();
                });

                if (data == null)
                {
                    return;
                }

                float areaWidth = 5 * position.width / 8;
                GUILayoutHelper.Area(new Rect(position.width - areaWidth, 0, areaWidth, position.height), () =>
                {
                    EditorGUILayout.Space();

                    if (data.Presets.Count > 0 && presets.index != -1)
                    {
                        if (GUILayout.SelectionGrid(IsPreset ? 1 : 0, new string[] { "Defaults", data.Presets[presets.index].Title }, 2) == 0)
                        {
                            if (IsPreset)
                            {
                                LoadPreset(-1);
                            }
                        }
                        else
                        {
                            if (currentPreset != presets.index)
                            {
                                LoadPreset(presets.index);
                            }
                        }
                    }

                    mainScrollPosition = GUILayoutHelper.ScrollView(mainScrollPosition, () =>
                    {
                        sections.DoLayoutList();

                        duplicateSections = duplicateKeys = false;
                        var sectionNames  = new List <string>();
                        foreach (var section in data.Sections)
                        {
                            section.Name = !string.IsNullOrEmpty(section.Name) ? section.Name.Replace(" ", string.Empty) : GetUniqueName(sectionNames, "Section");
                            sectionNames.Add(section.Name);

                            var keyNames = new List <string>();
                            foreach (var key in section.Keys)
                            {
                                key.Name = !string.IsNullOrEmpty(key.Name) ? key.Name.Replace(" ", string.Empty) : GetUniqueName(keyNames, "Key");
                                keyNames.Add(key.Name);
                            }

                            duplicateKeys |= DuplicatesDetected(keyNames);
                            this.keyNames.Add(keyNames);
                        }
                        this.sectionNames  = sectionNames;
                        duplicateSections |= DuplicatesDetected(sectionNames);
                    });

                    GUILayout.FlexibleSpace();
                    EditorGUILayout.Space();
                });
            });
        }
Ejemplo n.º 5
0
        void OnGUI()
        {
            EditorGUI.indentLevel++;

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Create New Mod"))
                {
                    modInfo      = new ModInfo();
                    modInfo.GUID = System.Guid.NewGuid().ToString();
                    fileOpen     = SaveModFile();
                    if (modInfo != null)
                    {
                        modInfo.DFUnity_Version = VersionInfo.DaggerfallUnityVersion;
                    }
                }

                else if (GUILayout.Button("Open Existing Mod Settings File"))
                {
                    try
                    {
                        currentFilePath = EditorUtility.OpenFilePanelWithFilters("", ModManager.EditorModsDirectory, new string[] { "JSON", "dfmod.json" });

                        if (!File.Exists(currentFilePath))
                        {
                            Debug.Log("Invalid file selection");
                            currentFilePath = null;
                            fileOpen        = false;
                            return;
                        }

                        modInfo = ReadModInfoFile(currentFilePath);
                        Debug.Log(string.Format("opened mod file for: {0}", modInfo.ModTitle));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("Error while trying to open mod file at: {0} \n {1}", currentFilePath, ex.Message));
                        currentFilePath = null;
                        fileOpen        = false;
                        return;
                    }

                    fileOpen = true;
                }

                if (GUILayout.Button(documentationGUIContent))
                {
                    Help.BrowseURL("https://www.dfworkshop.net/projects/daggerfall-unity/modding/");
                }
            });

            if (!isSupportedEditorVersion)
            {
                EditorGUILayout.HelpBox("Unsupported version of Unity Editor: generated mods may not be compatible with release builds!", MessageType.Warning);
            }

            if (modInfo == null)
            {
                fileOpen = false;
                modInfo  = new ModInfo();
            }

            if (!fileOpen) // if no fileopen, hide rest of UI
            {
                EditorGUILayout.HelpBox("Open a manifest file or create a new one to edit or build a mod.", MessageType.Info);
                return;
            }

            GUILayoutHelper.Vertical(() =>
            {
                EditorGUILayout.Space();
                GUILayoutHelper.Horizontal(() =>
                {
                    EditorGUILayout.LabelField(new GUIContent("Current File: "), titleStyle);
                    GUILayout.Space(-1000);
                    EditorGUILayout.LabelField(new GUIContent(currentFilePath), fieldStyle);
                });
                EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

                EditorGUI.indentLevel++;

                GUILayoutHelper.Vertical(() =>
                {
                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Title:"), titleStyle);
                        modInfo.ModTitle = EditorGUILayout.TextField(modInfo.ModTitle, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();


                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Version:"), titleStyle);
                        modInfo.ModVersion = EditorGUILayout.TextField(modInfo.ModVersion, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Creator:"), titleStyle);
                        modInfo.ModAuthor = EditorGUILayout.TextField(modInfo.ModAuthor, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Contact Info:"), titleStyle);
                        modInfo.ContactInfo = EditorGUILayout.TextField(modInfo.ContactInfo, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("DFUnity Version:"), titleStyle);
                        modInfo.DFUnity_Version = EditorGUILayout.TextField(modInfo.DFUnity_Version, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Description:"), titleStyle);
                        modInfo.ModDescription = EditorGUILayout.TextArea(modInfo.ModDescription, GUILayout.MinWidth(1000));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod GUID: "), titleStyle);
                        EditorGUILayout.LabelField(new GUIContent(modInfo.GUID));
                        if (GUILayout.Button("Generate New GUID"))
                        {
                            modInfo.GUID = System.Guid.NewGuid().ToString();
                        }
                        GUILayout.Space(300);
                    });
                });

                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUI.indentLevel--;

                GUILayoutHelper.Horizontal(() =>
                {
                    if (GUILayout.Button("Add Selected Asset(s)"))
                    {
                        AddSelectedAssetsToMod();
                    }

                    else if (GUILayout.Button("Remove Selected Asset(s)"))
                    {
                        if (Assets == null || Assets.Count < 1)
                        {
                            return;
                        }
                        else if (assetSelection < 0 || assetSelection > Assets.Count)
                        {
                            return;
                        }
                        else
                        {
                            Assets.RemoveAt(assetSelection);
                        }
                    }
                    else if (GUILayout.Button("Clear ALL Asset(s)"))
                    {
                        if (Assets != null)
                        {
                            Assets = new List <string>();
                        }
                    }
                });
            });

            EditorGUILayout.Space();

            ShowFileFoldOut = GUILayoutHelper.Foldout(ShowFileFoldOut, new GUIContent("Files"), () =>
            {
                scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
                {
                    assetSelection = GUILayout.SelectionGrid(assetSelection, modInfo.Files.ToArray(), 1);
                });
            });

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

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

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();

            GUILayout.Label("\tBuild Targets:\n", titleStyle);

            for (int i = 0; i < buildTargetsToggles.Length; i++)
            {
                buildTargetsToggles[i] = EditorGUILayout.Toggle(buildTargets[i].ToString(), buildTargetsToggles[i], GUILayout.ExpandWidth(false));
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical();

            GUILayout.Label("Compression Type:\n", titleStyle);
            compressionOption = (ModCompressionOptions)EditorGUILayout.EnumPopup("", compressionOption, GUILayout.MaxWidth(125));
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Collect Dependencies", GUILayout.MaxWidth(200)) && ModInfoReady)
            {
                foreach (var assetPath in Assets.ToArray())
                {
                    var depends = AssetDatabase.GetDependencies(assetPath);
                    foreach (var d in depends)
                    {
                        AddAssetToMod(d);
                    }
                }
            }

            GUILayout.Space(100);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

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

            EditorGUILayout.Space();

            GUILayoutHelper.Horizontal(() =>
            {
                EditorGUILayout.LabelField("Build Path:", titleStyle);
                GUILayout.Space(-1000);
                EditorGUILayout.LabelField(modOutPutPath, fieldStyle);
                if (GUILayout.Button("Set", GUILayout.Width(50)))
                {
                    modOutPutPath = EditorUtility.SaveFolderPanel("Select Destination,", Application.dataPath, "");
                    Debug.Log("build path: " + modOutPutPath);
                }
            });
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Save Mod Settings to File"))
                {
                    SaveModFile(File.Exists(currentFilePath));
                    Debug.Log("got path: " + currentFilePath);
                }
                else if (GUILayout.Button("Build Mod"))
                {
                    SaveModFile(true);
                    BuildMod();
                }
            });
        }
Ejemplo n.º 6
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();
                }
            });
        }
        void OnGUI()
        {
            EditorGUI.indentLevel++;

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Create New Mod"))
                {
                    fileOpen = true;
                    if (modInfo != null)
                    {
                        modInfo.DFUnity_Verion = VersionInfo.DaggerfallUnityVersion;
                    }
                }

                else if (GUILayout.Button("Open Existing Mod Settings File"))
                {
                    try
                    {
                        currentFilePath = EditorUtility.OpenFilePanelWithFilters("", Application.dataPath, new string[] { "JSON", "dfmod.json" });

                        if (!File.Exists(currentFilePath))
                        {
                            Debug.Log("Invalid file selection");
                            currentFilePath = null;
                            fileOpen        = false;
                            return;
                        }

                        string inPut = File.ReadAllText(currentFilePath);
                        modInfo      = (ModInfo)JsonUtility.FromJson(inPut, typeof(ModInfo));

                        Debug.Log(string.Format("opened mod file for: {0}", modInfo.ModTitle));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("Error while trying to open mod file at: {0} \n {1}", currentFilePath, ex.Message));
                        currentFilePath = null;
                        fileOpen        = false;
                        return;
                    }

                    fileOpen = true;
                }
            });

            if (modInfo == null)
            {
                fileOpen = false;
                modInfo  = new ModInfo();
            }
            if (!fileOpen) // if no fileopen, hide rest of UI
            {
                return;
            }

            GUILayoutHelper.Vertical(() =>
            {
                EditorGUILayout.LabelField(new GUIContent("Mod File Path:" + currentFilePath));
                EditorGUI.indentLevel++;

                GUILayoutHelper.Vertical(() =>
                {
                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod File Name:"));
                        modInfo.ModFileName = EditorGUILayout.TextField(modInfo.ModFileName.ToLower(), GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Title:"));
                        modInfo.ModTitle = EditorGUILayout.TextField(modInfo.ModTitle, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();


                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Version:"));
                        modInfo.ModVersion = EditorGUILayout.TextField(modInfo.ModVersion, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Creator:"));
                        modInfo.ModAuthor = EditorGUILayout.TextField(modInfo.ModAuthor, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Contact Info:"));
                        modInfo.ContactInfo = EditorGUILayout.TextField(modInfo.ContactInfo, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("DFUnity Version:"));
                        modInfo.DFUnity_Verion = EditorGUILayout.TextField(modInfo.DFUnity_Verion, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Description:"));
                        modInfo.ModDescription = EditorGUILayout.TextArea(modInfo.ModDescription, GUILayout.MinWidth(600));
                    });
                });

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;

                GUILayoutHelper.Horizontal(() =>
                {
                    if (GUILayout.Button("Add Selected Asset(s)"))
                    {
                        AddAssetToMod();
                    }

                    else if (GUILayout.Button("Remove Selected Asset(s)"))
                    {
                        if (Assets == null || Assets.Count < 1)
                        {
                            return;
                        }
                        else if (assetSelection < 0 || assetSelection > Assets.Count)
                        {
                            return;
                        }
                        else
                        {
                            Assets.RemoveAt(assetSelection);
                        }
                    }
                    else if (GUILayout.Button("Clear ALL Asset(s)"))
                    {
                        if (Assets != null)
                        {
                            Assets = new List <string>();
                        }
                    }
                });
            });

            EditorGUILayout.Space();

            ShowFileFoldOut = GUILayoutHelper.Foldout(ShowFileFoldOut, new GUIContent("Files"), () =>
            {
                scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
                {
                    assetSelection = GUILayout.SelectionGrid(assetSelection, modInfo.Files.ToArray(), 1);
                });
            });

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

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Save Mod Settings to File"))
                {
                    SaveModFile();
                    Debug.Log("got path: " + currentFilePath);
                }
                else if (GUILayout.Button("Build Mod"))
                {
                    SaveModFile();
                    BuildMod();
                }
            });
        }
Ejemplo n.º 8
0
        void OnGUI()
        {
            EditorGUI.indentLevel++;

            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Create New Mod"))
                {
                    modInfo      = new ModInfo();
                    modInfo.GUID = System.Guid.NewGuid().ToString();
                    fileOpen     = SaveModFile();
                    //currentFilePath = EditorUtility.SaveFilePanel("", GetTempModDirPath(), "", "dfmod.json");
                    if (modInfo != null)
                    {
                        modInfo.DFUnity_Version = VersionInfo.DaggerfallUnityVersion;
                    }
                }

                else if (GUILayout.Button("Open Existing Mod Settings File"))
                {
                    try
                    {
                        currentFilePath = EditorUtility.OpenFilePanelWithFilters("", GetTempModDirPath(), new string[] { "JSON", "dfmod.json" });

                        if (!File.Exists(currentFilePath))
                        {
                            Debug.Log("Invalid file selection");
                            currentFilePath = null;
                            fileOpen        = false;
                            return;
                        }

                        modInfo = ReadModInfoFile(currentFilePath);
                        Debug.Log(string.Format("opened mod file for: {0}", modInfo.ModTitle));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("Error while trying to open mod file at: {0} \n {1}", currentFilePath, ex.Message));
                        currentFilePath = null;
                        fileOpen        = false;
                        return;
                    }

                    fileOpen = true;
                }
            });

            if (modInfo == null)
            {
                fileOpen = false;
                modInfo  = new ModInfo();
            }
            if (!fileOpen) // if no fileopen, hide rest of UI
            {
                return;
            }

            GUILayoutHelper.Vertical(() =>
            {
                EditorGUILayout.Space();
                GUILayoutHelper.Horizontal(() =>
                {
                    EditorGUILayout.LabelField(new GUIContent("Current File:  " + currentFilePath));
                });
                EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

                EditorGUI.indentLevel++;

                GUILayoutHelper.Vertical(() =>
                {
                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Title:"));
                        modInfo.ModTitle = EditorGUILayout.TextField(modInfo.ModTitle, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();


                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Version:"));
                        modInfo.ModVersion = EditorGUILayout.TextField(modInfo.ModVersion, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Creator:"));
                        modInfo.ModAuthor = EditorGUILayout.TextField(modInfo.ModAuthor, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Contact Info:"));
                        modInfo.ContactInfo = EditorGUILayout.TextField(modInfo.ContactInfo, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("DFUnity Version:"));
                        modInfo.DFUnity_Version = EditorGUILayout.TextField(modInfo.DFUnity_Version, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod Description:"));
                        modInfo.ModDescription = EditorGUILayout.TextArea(modInfo.ModDescription, GUILayout.MinWidth(600));
                    });

                    EditorGUILayout.Space();

                    GUILayoutHelper.Horizontal(() =>
                    {
                        EditorGUILayout.LabelField(new GUIContent("Mod GUID: "));
                        EditorGUILayout.LabelField(new GUIContent(modInfo.GUID));
                        if (GUILayout.Button("Generate New GUID"))
                        {
                            modInfo.GUID = System.Guid.NewGuid().ToString();
                        }
                        //modInfo.ModDescription = EditorGUILayout.TextArea(modInfo.ModDescription, GUILayout.MinWidth(600));
                    });
                });

                EditorGUILayout.Space();
                EditorGUI.indentLevel--;

                GUILayoutHelper.Horizontal(() =>
                {
                    if (GUILayout.Button("Add Selected Asset(s)"))
                    {
                        AddSelectedAssetsToMod();
                    }

                    else if (GUILayout.Button("Remove Selected Asset(s)"))
                    {
                        if (Assets == null || Assets.Count < 1)
                        {
                            return;
                        }
                        else if (assetSelection < 0 || assetSelection > Assets.Count)
                        {
                            return;
                        }
                        else
                        {
                            Assets.RemoveAt(assetSelection);
                        }
                    }
                    else if (GUILayout.Button("Clear ALL Asset(s)"))
                    {
                        if (Assets != null)
                        {
                            Assets = new List <string>();
                        }
                    }
                });
            });

            EditorGUILayout.Space();

            ShowFileFoldOut = GUILayoutHelper.Foldout(ShowFileFoldOut, new GUIContent("Files"), () =>
            {
                scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
                {
                    assetSelection = GUILayout.SelectionGrid(assetSelection, modInfo.Files.ToArray(), 1);
                });
            });

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

            GUILayout.Label("Build Targets");

            GUILayoutHelper.Horizontal(() =>
            {
                for (int i = 0; i < buildTargetsToggles.Length; i++)
                {
                    buildTargetsToggles[i] = EditorGUILayout.Toggle(buildTargets[i].ToString(), buildTargetsToggles[i], GUILayout.ExpandWidth(true));
                }
            });

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);



            GUILayoutHelper.Horizontal(() =>
            {
                EditorGUILayout.LabelField("Build Path:     " + modOutPutPath);
                if (GUILayout.Button("Set", GUILayout.Width(50)))
                {
                    modOutPutPath = EditorUtility.SaveFolderPanel("Select Destination,", Application.dataPath, "");
                    Debug.Log("build path: " + modOutPutPath);
                }
            });
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);


            GUILayoutHelper.Horizontal(() =>
            {
                if (GUILayout.Button("Save Mod Settings to File"))
                {
                    SaveModFile(File.Exists(currentFilePath));
                    Debug.Log("got path: " + currentFilePath);
                }
                else if (GUILayout.Button("Build Mod"))
                {
                    SaveModFile(true);
                    BuildMod();
                }
            });
        }
Ejemplo n.º 9
0
        void OnGUI()
        {
            GUILayout.Label("Select source files to compile");

            string path = "";

            if (GUILayout.Button("Add File", GUILayout.Width(500)))
            {
                path = EditorUtility.OpenFilePanelWithFilters("", Application.dataPath, new string[] { "CSharp", "cs" });
                if (filesToCompile.Contains(path))
                {
                    Debug.Log("This file is already selected");
                    return;
                }
                else if (File.Exists(path))
                {
                    filesToCompile.Add(path);
                }
                else
                {
                    Debug.Log("Please select a valid file");
                }
            }

            EditorGUILayout.Space();


            if (filesToCompile != null && filesToCompile.Count > 0)
            {
                if (GUILayout.Button("Compile"))
                {
                    try
                    {
                        System.Reflection.Assembly assembly = Compiler.CompileSource(filesToCompile.ToArray(), false, false);
                        Debug.Log(string.Format("Assembly {0} created", assembly.GetName().Name));
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex.Message);
                    }
                }
            }

            EditorGUILayout.Space();

            showFilesFoldout = GUILayoutHelper.Foldout(showFilesFoldout, new GUIContent("Files"), () =>
            {
                scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
                {
                    for (int i = 0; i < filesToCompile.Count; i++)
                    {
                        EditorGUILayout.Space();

                        GUILayoutHelper.Horizontal(() =>
                        {
                            EditorGUI.indentLevel++;

                            Vector2 textDimensions = GUI.skin.label.CalcSize(new GUIContent(filesToCompile[i]));
                            EditorGUILayout.LabelField(new GUIContent(filesToCompile[i]), GUILayout.Width(textDimensions[0])); //EditorGUILayout.SelectableLabel(filesToCompile[i]);

                            EditorGUI.indentLevel++;

                            if (GUILayout.Button("Remove", GUILayout.MinWidth(10), GUILayout.Width(60)))
                            {
                                RemoveFileFromList(i);
                                EditorGUILayout.Space();
                            }

                            EditorGUI.indentLevel--;
                            EditorGUI.indentLevel--;
                        });
                    }
                });
            });
        }
Ejemplo n.º 10
0
        void OnGUI()
        {
            bool outputPathIsSet = !string.IsNullOrEmpty(outputPath);

            selectedCompiler = GUILayout.SelectionGrid(selectedCompiler, compilers, 2);

            GUILayout.Label("Select source files to compile");

            string path = "";

            if (GUILayout.Button("Add File"))
            {
                path = EditorUtility.OpenFilePanelWithFilters("", Application.dataPath, new string[] { "CSharp", "cs" });
                if (filesToCompile.Contains(path))
                {
                    Debug.Log("This file is already selected");
                    return;
                }
                else if (File.Exists(path))
                {
                    filesToCompile.Add(path);
                }
                else
                {
                    Debug.Log("Please select a valid file");
                }
            }

            EditorGUILayout.Space();

            if (selectedCompiler == 1)
            {
                EditorGUILayout.LabelField("Output Path:");
                if (GUILayout.Button(outputPathIsSet ? outputPath : "<select>"))
                {
                    outputPath = EditorUtility.SaveFilePanel("Output Path", Application.dataPath, "Assembly", "dll");
                }

                EditorGUILayout.Space();
            }

            bool enabled = filesToCompile != null && filesToCompile.Count > 0 && (selectedCompiler == 0 || outputPathIsSet);

            EditorGUI.BeginDisabledGroup(!enabled);

            if (GUILayout.Button("Compile"))
            {
                try
                {
                    if (selectedCompiler == 0)
                    {
                        Assembly assembly = Compiler.CompileSource(filesToCompile.ToArray(), false, false);
                        Debug.Log(string.Format("Assembly {0} created", assembly.GetName().Name));
                    }
                    else
                    {
                        ModAssemblyBuilder.Compile(outputPath, filesToCompile.ToArray());
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.Space();

            showFilesFoldout = GUILayoutHelper.Foldout(showFilesFoldout, new GUIContent("Files"), () =>
            {
                scrollPos = GUILayoutHelper.ScrollView(scrollPos, () =>
                {
                    for (int i = 0; i < filesToCompile.Count; i++)
                    {
                        EditorGUILayout.Space();

                        GUILayoutHelper.Horizontal(() =>
                        {
                            EditorGUI.indentLevel++;

                            Vector2 textDimensions = GUI.skin.label.CalcSize(new GUIContent(filesToCompile[i]));
                            EditorGUILayout.LabelField(new GUIContent(filesToCompile[i]), GUILayout.Width(textDimensions[0])); //EditorGUILayout.SelectableLabel(filesToCompile[i]);

                            EditorGUI.indentLevel++;

                            if (GUILayout.Button("Remove", GUILayout.MinWidth(10), GUILayout.Width(60)))
                            {
                                RemoveFileFromList(i);
                                EditorGUILayout.Space();
                            }

                            EditorGUI.indentLevel--;
                            EditorGUI.indentLevel--;
                        });
                    }
                });
            });
        }