public WordTranslationUIRequestEventArgs(GameObject menuParent, PhraseSequenceElement word, RectTransform target, Action successCallback, Action failureCallback) : base(menuParent) { Word = word; Target = target; SuccessCallback = successCallback; FailureCallback = failureCallback; }
public PhraseSequence(string text) : this() { var pe = new PhraseSequenceElement(PhraseSequenceElementType.Text, text); Add(pe); Translation = text; }
public void UpdateAt(int index, PhraseSequenceElement element) { PhraseElements.RemoveAt(index); PhraseElements.Insert(index, element); }
public bool ContainsWord(PhraseSequenceElement word, bool enforceForm = false) { foreach (var w in PhraseElements) { if (PhraseSequenceElement.IsEqual(word, w, enforceForm)) { return true; } } return false; }
public void Add(PhraseSequenceElement element) { PhraseElements.Add(element); }
public PhraseClickedEventArgs(PhraseSequenceElement word, string destination) { this.Phrase = new PhraseSequence(word); this.Destination = destination; }
public static PhraseSequenceElement[] GetVerbForms(DictionaryDataEntry entry) { var forms = GetVerbForms(); var arr = new PhraseSequenceElement[forms.Length]; for (int i = 0; i < forms.Length; i++) { arr[i] = new PhraseSequenceElement(entry.ID, forms[i]); } return arr; }
public bool AddFoundWord(PhraseSequenceElement word) { return AddFoundWord(word.WordID); }
//managing response to keyboard entries about inputs void ListenToTyping(KeyCode key) { //deleting text if (key == KeyCode.Backspace || key == KeyCode.Delete) { //if no imetext, delete the entry in front of cursor if(imeText == "" && cursorPosition != 0){ setCursorPosition(cursorPosition - 1); phraseSequence.RemoveAt(cursorPosition); } //if there is imetext, delete one letter from it else{ onConjugate = false; toConjugate = null; imeText = imeText.Substring(0, Mathf.Max(0, imeText.Length - 1)); } } //entering letters into imeText if(IsText(key)){//key.ToString().Length == 1 && IsAlphabet(key.ToString()[0])){ //set onConjugate and toConjugate as such for every action that will change imeText onConjugate = false; toConjugate = null; imeText += GetText(key); } /** Potential key strokes that can be used for entering into text ***/ //TODO maybe enable punctuations /********************************************************************/ /** selection key strokes *****/ int index; //conjugate words selection when modifying existing verbs if (IsNumeric (key.ToString (), out index) && onConjugate && selected < phraseSequence.PhraseElements.Count && phraseSequence.PhraseElements [selected].IsDictionaryWord) { if(index >= 0 && index < conjugateDisplay.Length && conjugateDisplay[index] != null){ phraseSequence.UpdateAt(selected, conjugateDisplay[index]); } } else if(IsNumeric(key.ToString(), out index) && imeText != ""){ //conjugate words selection for newly typed words if(onConjugate){ if(index >= 0 && index < conjugateDisplay.Length && conjugateDisplay[index] != null){ phraseSequence.PhraseElements.Insert (cursorPosition, conjugateDisplay[index]); imeText = ""; toConjugate = null; onConjugate = false; setCursorPosition(cursorPosition + 1); } } //Japanese word selection else{ if(index >= 0 && index < OnDisplay.Length && OnDisplay[index] != null){ if(hasConjugate(OnDisplay[index])){ toConjugate = OnDisplay[index]; //Debug.Log (toConjugate); onConjugate = true; } else{ phraseSequence.PhraseElements.Insert (cursorPosition, new PhraseSequenceElement(OnDisplay[index].ID, 0)); imeText = ""; setCursorPosition(cursorPosition + 1); } } } } /** HotKeys for selection when imeText isn't empty ********************/ //TODO maybe change hotkey to ctrl else if (key == KeyCode.Tab && imeText != "") { var element = new PhraseSequenceElement (PhraseSequenceElementType.Text, imeText); //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText)); imeText = ""; phraseSequence.PhraseElements.Insert (cursorPosition, element); setCursorPosition(cursorPosition + 1); } else if (key == KeyCode.LeftControl && imeText != "") { var element = new PhraseSequenceElement (PhraseSequenceElementType.ContextSlot, imeText); //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText)); imeText = ""; phraseSequence.PhraseElements.Insert (cursorPosition, element); setCursorPosition(cursorPosition + 1); } else if (key == KeyCode.Tab && imeText == "") { var element = new PhraseSequenceElement (PhraseSequenceElementType.Wildcard, ""); //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText)); imeText = ""; phraseSequence.PhraseElements.Insert (cursorPosition, element); setCursorPosition(cursorPosition + 1); } }
//void DrawSlotEditor(int wordIndex){ // var tag = DrawTags (phraseSequence.PhraseElements [wordIndex].Tags); // if (tag != null) { // phraseSequence.PhraseElements[wordIndex].AddTag(tag); // } //} //string DrawTags(List<string> tags){ // var selectionStrings = new string[GameData.Instance.PhraseClassData.Tags.Count + 1]; // selectionStrings [0] = "None"; // System.Array.Copy (GameData.Instance.PhraseClassData.Tags.ToArray (), 0, selectionStrings, 1, GameData.Instance.PhraseClassData.Tags.Count); // foreach(var e in tags){ // if(GUILayout.Button (e)){ // tags.Remove(e); // break; // } // } // var selected = EditorGUILayout.Popup(0, selectionStrings); // if(selected != 0){ // return selectionStrings[selected]; // } // return null; //} /** tentative method to draw words * draw ten words on the screen * Pre: PhraseSquence phrase, int offset, the index of the first element to be drawn (starting at 0) */ void DrawTenFileterWords(PhraseSequence phrase, int offset) { int prevCount = phrase.PhraseElements.Count; if (imeText != "") { PhraseSequenceElement element = null; if (imeText [0] == '*') { if (GUILayout.Button ("Add slot...")) { element = new PhraseSequenceElement (0, 0); imeText = ""; //phrase.Add (new PhraseSequenceElement(0, 0)); } } else { currentList = DictionaryData.Instance.FilterEntriesFromRomaji (imeText).ToArray (); if (offset + displayLines >= currentList.Length) offset = Mathf.Max (0, currentList.Length - displayLines); if (offset < 0) offset = 0; for (int i = 0; i < displayLines; i++) { if (offset + i >= currentList.Length || offset + i < 0) OnDisplay[i] = null; else{ var e = currentList [offset + i]; string label = string.Format ("{0}: [{1}] {2} ({3}) {4}", i + 1, e.ID, e.Kanji, e.Kana, e.EnglishSummary); GUIStyle buttonStyle = new GUIStyle(); buttonStyle.alignment = TextAnchor.LowerLeft; if (GUILayout.Button (label, buttonStyle)) { element = new PhraseSequenceElement (e.ID, 0); //phrase.Add (new PhraseSequenceElement(e.ID, 0)); imeText = ""; break; } OnDisplay [i] = e; } } string buttonLabel = string.Format("{0} [Hotkey: {1}]", "Add as plain text", ","); if (GUILayout.Button (buttonLabel)) { element = new PhraseSequenceElement (PhraseSequenceElementType.Text, imeText); //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.Text, imeText)); imeText = ""; } buttonLabel = string.Format("{0} [Hotkey: {1}]", "Add as context data", "."); if (GUILayout.Button (buttonLabel)) { element = new PhraseSequenceElement (PhraseSequenceElementType.ContextSlot, imeText); //phrase.Add (new PhraseSequenceElement(PhraseSequenceElementType.ContextSlot, imeText)); imeText = ""; } // if (GUILayout.Button ("Add as tag")) { // element = new PhraseSequenceElement (PhraseSequenceElementType.TaggedSlot, imeText); // //phrase.Add(new PhraseSequenceElement(PhraseSequenceElementType.TaggedSlot, imeText)); // imeText = ""; // } buttonLabel = string.Format("{0} [Hotkey: {1}]", "Add as wildcard", "/"); if (GUILayout.Button (buttonLabel)) { element = new PhraseSequenceElement (PhraseSequenceElementType.Wildcard, imeText); //phrase.Add(new PhraseSequenceElement(PhraseSequenceElementType.Wildcard, imeText)); imeText = ""; } if (element != null) { phrase.PhraseElements.Insert (cursorPosition, element); } if (GUILayout.Button ("Search...")) { var searchResultList = DictionaryData.SearchDictionaryWithStartingRomaji (imeText); DictionaryEntrySelectionWindow.Open (searchResultList); } } } if (prevCount != phrase.PhraseElements.Count) { setCursorPosition(cursorPosition + 1); } }
public static bool WildcardCompare(PhraseSequenceElement e1, PhraseSequenceElement e2) { if (e1.ElementType == PhraseSequenceElementType.Wildcard) { return true; } if (e2.ElementType == PhraseSequenceElementType.Wildcard) { return true; } return StrictCompare(e1, e2); }
public static bool StrictCompare(PhraseSequenceElement e1, PhraseSequenceElement e2) { if (!e1.Comparable) { return false; } if (!e2.Comparable) { return false; } if (e1.ElementType != e2.ElementType) { return false; } switch (e1.ElementType) { case PhraseSequenceElementType.FixedWord: return e1.WordID == e2.WordID; case PhraseSequenceElementType.ContextSlot: case PhraseSequenceElementType.TaggedSlot: return e1.Text == e2.Text; case PhraseSequenceElementType.Wildcard: return e2.ElementType == PhraseSequenceElementType.Wildcard; } return false; }
public static bool IsEqual(PhraseSequenceElement e1, PhraseSequenceElement e2, bool enforceForm = false) { if (e1 == null || e2 == null) { return e1 == e2; } if (e1.WordID >= 1000000) { if (enforceForm) { return e1.WordID == e2.WordID && e1.FormID == e2.FormID; } else { return e1.WordID == e2.WordID; } } else { return e1.ElementType == e2.ElementType && e1.Text == e2.Text; } }
public PhraseEventArgs(PhraseSequenceElement word) { Phrase = new PhraseSequence(); Phrase.Add(word); }
public PhraseSequence(PhraseSequenceElement word) : this() { Add(word); Translation = word.GetTranslation(); }
public bool ContainsFoundWord(PhraseSequenceElement word) { return ContainsFoundWord(word.WordID); }
public static PhraseSequenceElement[] GetForms(DictionaryDataEntry entry) { if (additionalForms.ContainsKey(entry.Kanji)) { var forms = new PhraseSequenceElement[additionalForms[entry.Kanji].Count]; for (int i = 0; i < forms.Length; i++) { forms[i] = new PhraseSequenceElement(entry.ID, i); } return forms; } switch (entry.GetPartOfSpeech()) { case PartOfSpeech.GodanVerb: case PartOfSpeech.IchidanVerb: case PartOfSpeech.Copula: case PartOfSpeech.SuruVerb: return GetVerbForms(entry); case PartOfSpeech.Adjective: return GetAdjectiveForms(entry); default: return new PhraseSequenceElement[] { new PhraseSequenceElement(entry.ID, 0) }; } }