private void CleanData() { // Make sure we have an ID, if not, generate it. if (string.IsNullOrEmpty(loadedTranslateData.ID)) { loadedTranslateData.ID = Guid.NewGuid().ToString(); } // Remove all empty data from the loaded TranslateData. for (int s = 0; s < loadedTranslateData.TranslateSheets.Count; s++) { TranslateSheetData sheet = loadedTranslateData.TranslateSheets[s]; if (sheet.TranslateHashes.Count == 0) { loadedTranslateData.TranslateSheets.Remove(sheet); s--; } else { for (int h = 0; h < sheet.TranslateHashes.Count; h++) { TranslateHashData hash = sheet.TranslateHashes[h]; if (string.IsNullOrEmpty(hash.Input) || string.IsNullOrEmpty(hash.Output)) { sheet.TranslateHashes.Remove(hash); h--; } } } } }
private void OnRequestDeleteTranslateHashEvent(TranslateHashData hashData) { Destroy(spawnedHashes[hashData].gameObject); spawnedHashes.Remove(hashData); sheetData.TranslateHashes.Remove(hashData); TranslateDataChangedEvent?.Invoke(this); }
/// <summary> /// Creates a new <see cref="Translator"/> object. /// </summary> /// <param name="sheet">The data which will be used to translate the given input.</param> public Translator(TranslateSheetData sheet) { // We convert the translate sheet to a dictionary for easy access. table = new Dictionary <string, List <TranslateHashData> >(); for (int i = 0; i < sheet.TranslateHashes.Count; i++) { TranslateHashData hash = sheet.TranslateHashes[i]; if (!hash.Enabled || IsEmpty(hash.Output) || IsEmpty(hash.Input)) { continue; } if (!table.ContainsKey(hash.Input)) { table.Add(hash.Input, new List <TranslateHashData>()); } table[hash.Input].Add(sheet.TranslateHashes[i]); // We store the longest available hash to get the max-check-length. if (hash.Input.Length > longestHash) { longestHash = sheet.TranslateHashes[i].Input.Length; } } }
private void AddTranslateHashUIElement(TranslateHashData hashData) { TranslateHashUIElement element = Instantiate(translateHashUIElementPrefab, hashParent); element.Initialize(hashData); spawnedHashes.Add(hashData, element); element.TranslateDataChangedEvent += OnTranslateHashDataChangedEvent; element.RequestDeleteEvent += OnRequestDeleteTranslateHashEvent; }
public void Initialize(TranslateHashData hashData) { CleanUp(); this.hashData = hashData; // Set up bindings. disposables.Add(new ToggleBinding( enabledToggle, () => hashData.Enabled, delegate(bool v) { hashData.Enabled = v; OnDataChange(); })); disposables.Add(new InputFieldBinding( inputField, () => hashData.Input, delegate(string t) { hashData.Input = t; OnDataChange(); })); disposables.Add(new InputFieldBinding( outputField, () => hashData.Output, delegate(string t) { hashData.Output = t; OnDataChange(); })); disposables.Add(new ButtonBinding(deleteHashButton, () => RequestDeleteEvent?.Invoke(hashData))); // Fill the dropdown with all available TranslateHashTypes. hashTypeDropdown.options = new List <TMP_Dropdown.OptionData>(((TranslateHashType[])Enum.GetValues(typeof(TranslateHashType))).Select((x) => new TMP_Dropdown.OptionData(x.ToString()))); hashTypeDropdown.value = (int)hashData.HashType; hashTypeDropdown.onValueChanged.AddListener(OnHashTypeChanged); }
public void Initialize(TranslateSheetData sheetData) { CleanUp(); this.sheetData = sheetData; // Set up bindings. disposables.Add(new ToggleBinding(enabledToggle, () => sheetData.Enabled, delegate(bool v) { sheetData.Enabled = v; TranslateDataChangedEvent?.Invoke(this); })); disposables.Add(new InputFieldBinding(sheetNameField, () => sheetData.Name, delegate(string t) { sheetData.Name = t; TranslateDataChangedEvent?.Invoke(this); })); disposables.Add(new ButtonBinding(deleteSheetButton, () => RequestDeleteEvent?.Invoke(sheetData))); disposables.Add(new ButtonBinding(addHashButton, delegate { TranslateHashData hash = new TranslateHashData(); sheetData.TranslateHashes.Add(hash); AddTranslateHashUIElement(hash); })); disposables.Add(new ButtonBinding(sortByInputButton, delegate { List <TranslateHashData> orderedList = sheetData.TranslateHashes.OrderBy((x) => x.Input).ToList(); SortHashes(orderedList); })); disposables.Add(new ButtonBinding(sortByOutputButton, delegate { List <TranslateHashData> orderedList = sheetData.TranslateHashes.OrderBy((x) => x.Output).ToList(); SortHashes(orderedList); })); disposables.Add(new ButtonBinding(sortByHashTypeButton, delegate { List <TranslateHashData> orderedList = sheetData.TranslateHashes.OrderBy((x) => x.HashType.ToString()).ToList(); SortHashes(orderedList); })); // Create child translate hash UI elements. RebuildUI(); }