Exemplo n.º 1
0
        private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp)
        {
            lock (GameBase.lockObj)
            {
                DataListFormViewModel choices = new DataListFormViewModel();
                choices.Name = dataType.ToString();
                string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
                choices.SetEntries(entries);

                choices.SelectedOKEvent += () =>
                {
                    if (choices.SearchList.InternalIndex > -1)
                    {
                        lock (GameBase.lockObj)
                        {
                            int        entryNum = choices.SearchList.InternalIndex;
                            IEntryData data     = entryOp(entryNum);

                            Views.DataEditForm editor = new Views.DataEditForm();
                            editor.Title = DataEditor.GetWindowTitle(String.Format("{0} #{1:D3}", dataType.ToString(), entryNum), data.Name.ToLocal(), data, data.GetType());
                            DataEditor.LoadDataControls(data, editor.ControlPanel);
                            editor.SelectedOKEvent += () =>
                            {
                                lock (GameBase.lockObj)
                                {
                                    object obj = data;
                                    DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                                    DataManager.Instance.ContentChanged(dataType, entryNum, (IEntryData)obj);

                                    string newName = DataManager.Instance.DataIndices[dataType].Entries[entryNum].GetLocalString(true);
                                    choices.ModifyEntry(entryNum, newName);
                                    editor.Close();
                                }
                            };
                            editor.SelectedCancelEvent += () =>
                            {
                                editor.Close();
                            };

                            editor.Show();
                        }
                    }
                };
                choices.SelectedAddEvent += () =>
                {
                    lock (GameBase.lockObj)
                    {
                        int        entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count;
                        IEntryData data     = createOp();

                        Views.DataEditForm editor = new Views.DataEditForm();
                        editor.Title = DataEditor.GetWindowTitle(String.Format("{0} #{1:D3}", dataType.ToString(), entryNum), data.Name.ToLocal(), data, data.GetType()); data.ToString();
                        DataEditor.LoadDataControls(data, editor.ControlPanel);
                        editor.SelectedOKEvent += () =>
                        {
                            lock (GameBase.lockObj)
                            {
                                object obj = data;
                                DataEditor.SaveDataControls(ref obj, editor.ControlPanel);
                                data = (IEntryData)obj;
                                DataManager.Instance.ContentChanged(dataType, entryNum, (IEntryData)obj);

                                string newName = DataManager.Instance.DataIndices[dataType].Entries[entryNum].GetLocalString(true);
                                choices.AddEntry(newName);
                                editor.Close();
                            }
                        };
                        editor.SelectedCancelEvent += () =>
                        {
                            editor.Close();
                        };

                        editor.Show();
                    }
                };

                choices.SelectedReindexEvent += () =>
                {
                    lock (GameBase.lockObj)
                    {
                        DevHelper.RunIndexing(dataType);
                        DevHelper.RunExtraIndexing(dataType);
                        DataManager.Instance.LoadIndex(dataType);
                        DataManager.Instance.LoadUniversalData();
                        DataManager.Instance.ClearCache(dataType);
                        DiagManager.Instance.DevEditor.ReloadData(dataType);
                        string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true);
                        choices.SetEntries(entries);
                    }
                };

                Views.DataListForm dataListForm = new Views.DataListForm
                {
                    DataContext = choices,
                };
                dataListForm.Show();
            }
        }