Exemplo n.º 1
0
        private void OpenDatabase()
        {
            RaycastCover.SetActive(true);

            string file;

            try
            {
                file = StandaloneFileBrowser.OpenFilePanel("Open Database", "~/", "", false)[0];
            }
            catch
            {
                RaycastCover.SetActive(false);
                return;
            }

            if (string.IsNullOrWhiteSpace(file))
            {
                RaycastCover.SetActive(false);
                return;
            }

            _file = file;

            RecurseFolder = Path.GetDirectoryName(_file);

            DatabaseLoading.SetActive(true);

            LoadingTitle.text = "Loading Database";
            var threadStart = new ThreadStart(LoadDatabase);
            var thread      = new Thread(threadStart);

            _loadingThread = thread;
            thread.Start();
        }
Exemplo n.º 2
0
        private void Awake()
        {
            OpenButton.onClick.AddListener(() =>
            {
                ObjectInput.SetActive(true);
                RaycastCover.SetActive(true);
            });

            SubmitObjectIdButton.onClick.AddListener(() => { LoadMission(int.Parse(ObjectIdInput.text)); });

            SeekRowButton.onClick.AddListener(() =>
            {
                if (MissionTable == default)
                {
                    MissionTable = FdbEditor.Database.Tables.First(t => t.Name == "Missions");
                }

                FdbEditor.Singleton.SeekRow(MissionTable,
                                            MissionTable.Rows.First(m => (int)m.Fields[0].Value == MissionId));
                FdbEditor.Singleton.Activate();
            });

            NewButton.onClick.AddListener(() =>
            {
                if (NpcTable == default)
                {
                    NpcTable = FdbEditor.Database.Tables.First(t => t.Name == "MissionNPCComponent");
                }
                if (MissionTable == default)
                {
                    MissionTable = FdbEditor.Database.Tables.First(t => t.Name == "Missions");
                }

                var newLot = MissionTable.Rows.Select(r => new Missions(r).id).Max() + 1;

                var row = new Missions(NewRow(MissionTable))
                {
                    id = newLot
                };

                LoadMission(row.id);
            });

            _localeEntries = gameObject.GetComponentsInChildren <TMP_InputField>().Where(
                t => t.name.StartsWith("Locale Entry")
                ).ToArray();

            foreach (var entry in _localeEntries)
            {
                entry.interactable = false;
            }
        }
Exemplo n.º 3
0
        public void LoadMission(int missionId)
        {
            ApplicationTitle.text = $"Mission Editor - {missionId}";

            MissionId = missionId;

            var texts = (MissionTextType[])Enum.GetValues(typeof(MissionTextType));

            for (var index = 0; index < _localeEntries.Length; index++)
            {
                var localeEntry = _localeEntries[index];
                var textType    = texts[index];

                var value = LocaleEditor.GetMissionText(missionId, textType);

                localeEntry.text         = value;
                localeEntry.interactable = true;

                foreach (var text in localeEntry.GetComponentsInChildren <TextMeshProUGUI>())
                {
                    switch (text.name)
                    {
                    case "Name":
                        text.text = value;
                        break;

                    case "Id":
                        text.text = textType.ToString();
                        break;
                    }
                }

                localeEntry.onEndEdit.RemoveAllListeners();

                localeEntry.onEndEdit.AddListener(s =>
                {
                    LocaleEditor.SetMissionText(missionId, textType, s);
                    LocaleEditor.SetMissionText(missionId, textType, s, Locale.Germany);
                    LocaleEditor.SetMissionText(missionId, textType, s, Locale.GreatBritain);
                });
            }

            RaycastCover.SetActive(false);
            ObjectInput.SetActive(false);
        }
Exemplo n.º 4
0
        private void Update()
        {
            SaveButton.interactable = Database != default;
            OpenButton.interactable = Database == default;

            RowsAddButton.interactable = _activeTable != default;

            DatabaseLoadingBar.fillAmount = (float)(_currentCount / (double)_tableCount);

            LoadingText.text = !_saving
                ? $"{_currentCount} / {_tableCount} tables..."
                : $"Writing struct {_currentCount} / {_tableCount}";

            if (_currentCount < _tableCount - 1)
            {
                return;
            }

            _tableCount = 0;

            RaycastCover.SetActive(false);

            DatabaseLoading.SetActive(false);

            var path = Path.GetDirectoryName(_file)?.Replace("\\", "/").Split('/');

            ApplicationTitle.text = $"Database Editor - {(path != default ? path[path.Length - 1] : "")}/{Path.GetFileName(_file)}";

            _loadingThread.Join();
            _loadingThread.Abort();

            if (!_saving)
            {
                SetupTables();
            }
        }
Exemplo n.º 5
0
        private void SaveDatabase()
        {
            /*
             * if (!Directory.Exists("./Structures")) Directory.CreateDirectory("./Structures");
             *
             * foreach (var table in Database.Tables)
             * {
             *  var fileName = table.Name.Replace(" ", "");
             *
             *  if (!File.Exists($"./Structures/{fileName}.cs")) File.Create($"./Structures/{fileName}.cs").Dispose();
             *
             *  var strBuild = new StringBuilder();
             *
             *  strBuild.AppendLine("using NiEditorApplication.Fdb;");
             *  strBuild.AppendLine("using System.Linq;");
             *  strBuild.AppendLine();
             *  strBuild.AppendLine("namespace Fdb.Database");
             *  strBuild.AppendLine("{");
             *  strBuild.AppendLine($"\tclass {fileName}");
             *  strBuild.AppendLine("\t{");
             *  strBuild.AppendLine("\t\tpublic Row DatabaseRow { get; set; }");
             *  strBuild.AppendLine("\t\tpublic Table DatabaseTable { get; set; }");
             *  strBuild.AppendLine();
             *
             *  for (var index = 0; index < table.Structure.Length; index++)
             *  {
             *      var info = table.Structure[index];
             *      var structName = info.Name.Replace(" ", "");
             *      if (structName == fileName) structName = $"{structName}Field";
             *      strBuild.AppendLine($"\t\tpublic {_cSharpType[info.Type]} {structName}");
             *      strBuild.AppendLine("\t\t{");
             *      strBuild.AppendLine($"\t\t\tget => ({_cSharpType[info.Type]}) DatabaseRow.Fields[{index}].Value;");
             *      strBuild.AppendLine("\t\t\tset");
             *      strBuild.AppendLine("\t\t\t{");
             *      strBuild.AppendLine($"\t\t\t\tDatabaseRow.Fields[{index}].Value = value;");
             *      strBuild.AppendLine($"\t\t\t\tDatabaseTable.UpdateRow(DatabaseRow);");
             *      strBuild.AppendLine("\t\t\t}");
             *      strBuild.AppendLine("\t\t}");
             *      strBuild.AppendLine();
             *  }
             *
             *  strBuild.AppendLine($"\t\tpublic {fileName}(Row databaseRow)");
             *  strBuild.AppendLine("\t\t{");
             *  strBuild.AppendLine("\t\t\tDatabaseRow = databaseRow;");
             *  strBuild.AppendLine($"\t\t\tDatabaseTable = FdbEditor.Database.Tables.First(t => t.Name == \"{table.Name}\");");
             *  strBuild.AppendLine("\t\t}");
             *  strBuild.AppendLine("\t}");
             *  strBuild.AppendLine("}");
             *
             *  File.WriteAllText($"./Structures/{fileName}.cs", strBuild.ToString());
             * }
             *
             * return;
             */

            LoadingTitle.text = "Writing Database";
            LoadingText.text  = "";
            RaycastCover.SetActive(true);
            DatabaseLoading.SetActive(true);

            _saving = true;

            Task.Run(() =>
            {
                var threadStart = new ThreadStart(WriteDatabase);
                var thread      = new Thread(threadStart);
                _loadingThread  = thread;
                thread.Start();
            });
        }
Exemplo n.º 6
0
        private void LoadComponents(int objectId)
        {
            if (ObjectTable == default)
            {
                ObjectTable = FdbEditor.Database.Tables.First(t => t.Name == "Objects");
            }

            if (ComponentsTable == default)
            {
                ComponentsTable = FdbEditor.Database.Tables.First(t => t.Name == "ComponentsRegistry");
            }

            if (LootMatrixDbTable == default)
            {
                LootMatrixDbTable = FdbEditor.Database.Tables.First(t => t.Name == "LootMatrix");
            }

            if (LootDbTable == default)
            {
                LootDbTable = FdbEditor.Database.Tables.First(t => t.Name == "LootTable");
            }

            foreach (var reloadComponent in _onReloadComponents)
            {
                Destroy(reloadComponent);
            }

            foreach (var reloadItem in _onReloadItems)
            {
                Destroy(reloadItem);
            }

            _onReloadComponents.Clear();
            _onReloadItems.Clear();

            Object = new FdbObject(objectId);

            ApplicationTitle.text = $"Object Editor - {objectId}";

            var components = ComponentsTable.Rows.Where(r => (int)r.Fields[0].Value == objectId).ToArray();

            ComponentsTitle.text = $"{components.Length} Component" + (components.Length > 1 ? "s" : "");

            var allComponents = Enum.GetValues(typeof(ReplicaComponentsId));

            ComponentParent.sizeDelta =
                new Vector2(0, 20 * (allComponents.Length + 1) + (float)(ComponentParent.sizeDelta.y / 4d));

            int visualIndex = default;

            foreach (var registryComponent in components)
            {
                var id = (ReplicaComponentsId)(int)registryComponent.Fields[1].Value;

                var instance = Instantiate(ComponentPrefab, ComponentParent, true);

                instance.SetActive(true);

                instance.name = id.ToString();

                instance.transform.position -= new Vector3(0, 20, 0) * visualIndex++;

                instance.GetComponentInChildren <TextMeshProUGUI>().text = id.ToString();

                var extendedButton = instance.AddComponent <ExtendedButton>();

                extendedButton.MiddleClick += () =>
                {
                    Object.DeleteComponent(id);
                    LoadComponents(Object.Lot);
                };

                instance.GetComponentsInChildren <Image>().First(c => c.name == "Image").sprite = RemoveImage;

                _onReloadComponents.Add(instance);

                var table = FdbEditor.Database.Tables.FirstOrDefault(t => t.Name == id.ToString());

                Row componentRow = default;

                if (table != default)
                {
                    var component = registryComponent;
                    componentRow = table.Rows.FirstOrDefault(r =>
                                                             (int)r.Fields[0].Value == (int)component.Fields[2].Value
                                                             );

                    extendedButton.LeftClick += () =>
                    {
                        FdbEditor.Singleton.SeekRow(table, componentRow);
                        FdbEditor.Singleton.Activate();
                    };
                }

                var objComp = new ObjectComponent
                {
                    ComponentType = id,
                    RegistryRow   = registryComponent,
                    ComponentRow  = componentRow
                };

                Object.Components.Add(objComp);
            }

            visualIndex++;

            foreach (ReplicaComponentsId comp in allComponents)
            {
                if (Object.Components.Any(c => c.ComponentType == comp))
                {
                    continue;
                }

                var instance = Instantiate(ComponentPrefab, ComponentParent, true);

                instance.SetActive(true);

                instance.name = comp.ToString();

                instance.transform.position -= new Vector3(0, 20, 0) * visualIndex++;

                instance.GetComponentInChildren <TextMeshProUGUI>().text = comp.ToString();

                instance.GetComponentsInChildren <Image>().First(c => c.name == "Image").sprite = AddImage;

                instance.GetComponent <Button>().onClick.AddListener(() =>
                {
                    Object.AddComponent(comp);
                    LoadComponents(Object.Lot);
                });

                _onReloadComponents.Add(instance);
            }

            LoadStats();
            LoadXml();

            RaycastCover.SetActive(false);
            ObjectInput.SetActive(false);
        }
Exemplo n.º 7
0
 private void OpenObject()
 {
     RaycastCover.SetActive(true);
     ObjectInput.SetActive(true);
 }