private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp) { DataList choices = new DataList(); choices.Text = dataType.ToString(); string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.AddEntries(entries); choices.SelectedOKEvent = () => { if (choices.ChosenEntry > -1) { ElementForm editor = new ElementForm(); int entryNum = choices.ChosenEntry; editor.Text = entries[entryNum]; IEntryData data = entryOp(entryNum); editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum; DataEditor.LoadDataControls(data, editor.ControlPanel); editor.OnOK += (object okSender, EventArgs okE) => { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); data = (IEntryData)obj; DataManager.SaveData(entryNum, dataType.ToString(), data); DataManager.Instance.ClearCache(dataType); IEntryData entryData = ((IEntryData)data); EntrySummary entrySummary = entryData.GenerateEntrySummary(); DataManager.Instance.DataIndices[dataType].Entries[entryNum] = entrySummary; DataManager.Instance.SaveIndex(dataType); choices.ModifyEntry(entryNum, entrySummary.GetLocalString(true)); editor.Close(); }; editor.OnCancel += (object okSender, EventArgs okE) => { editor.Close(); }; editor.Show(); } }; choices.SelectedAddEvent = () => { ElementForm editor = new ElementForm(); int entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count; editor.Text = "New " + dataType.ToString(); IEntryData data = createOp(); editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum; DataEditor.LoadDataControls(data, editor.ControlPanel); editor.OnOK += (object okSender, EventArgs okE) => { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); data = (IEntryData)obj; DataManager.SaveData(entryNum, dataType.ToString(), data); DataManager.Instance.ClearCache(dataType); IEntryData entryData = ((IEntryData)data); EntrySummary entrySummary = entryData.GenerateEntrySummary(); DataManager.Instance.DataIndices[dataType].Entries.Add(entrySummary); DataManager.Instance.SaveIndex(dataType); entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.AddEntry(entrySummary.GetLocalString(true)); editor.Close(); }; editor.OnCancel += (object okSender, EventArgs okE) => { editor.Close(); }; editor.Show(); }; choices.Show(); }
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(); } }