List <LetterField> CreateLetterFields(List <char> arr) //Instantiate letter fields and add their scripts to collection { List <LetterField> letterArr = new List <LetterField>(); foreach (char item in arr) { GameObject go = Instantiate(letterFieldPrefab.gameObject, lettersFields); if (item != ' ') { LetterField _this = go.GetComponent <LetterField>(); letterArr.Add(_this); if (DataManager.Instance.RemoveClearButtons) { Button temp = go.AddComponent <Button>(); temp.transition = Selectable.Transition.None; temp.onClick.AddListener(() => StaticBehaviors.Clear(_this)); } } else { go.GetComponent <Image>().enabled = false; } } return(letterArr); }
private void PBOnClick(object sender, EventArgs e) { Field pF = (sender as Button).Tag as Field; if (pF == null) { return; } if (pF is EmptyField) { LetterField pLetterField = new LetterField(pF.X, pF.Y); _schema.Exchange(pF, pLetterField); (sender as Button).Tag = pLetterField; h_RefreshField(false); } else if (pF is LetterField) { EmptyField pEmptyField = new EmptyField(pF.X, pF.Y); _schema.Exchange(pF, pEmptyField); (sender as Button).Tag = pEmptyField; h_RefreshField(false); } }
//Clears letters field public static void Clear(LetterField item) { if (item.isEmpty == false) { item.letterReference.GetComponent <Animation>().Play("FadeIn"); item.text.text = null; item.isEmpty = true; item.letterReference.GetComponent <Button>().interactable = true; item.letterReference = null; item.isLast = false; } }
public Letter(string filename) { components = new List<LetterComponent>(); Fields = new List<LetterField>(); StringType currentType = StringType.Text; string contents = File.ReadAllText(filename); StringBuilder builder = new StringBuilder(); int contlen = contents.Length; int line = 1; for (int c = 0; c < contlen; ++c) { char curr = contents[c]; if (curr == '\n') ++line; switch (curr) { case '\\': if (c != contlen - 1) { char next = contents[++c]; switch (next) { case '<': builder.Append('<'); break; case '>': builder.Append('>'); break; case '\\': builder.Append('\\'); break; default: throw new FormatException("Line " + line.ToString() + ": Unrecognized escape sequence \\" + next.ToString()); } } else { throw new FormatException("Line " + line.ToString() + ": The file ended with" + " an escape character (\\)"); } break; case '<': if (currentType == StringType.Field) { throw new FormatException("Line " + line.ToString() + ": You cannot have a field in a field"); } else { // Add the current text to the letter if(builder.Length > 0) { LetterText text = new LetterText(); text.Text = builder.ToString(); components.Add(text); builder.Length = 0; } currentType = StringType.Field; } break; case '>': if (currentType == StringType.Text) { throw new FormatException("Line " + line.ToString() + ": > found without matching <"); } else { // Add the current field to the letter if (builder.Length > 0) { LetterField field = new LetterField(); field.Name = builder.ToString(); if(field.Name.Contains("\n")) { throw new FormatException("Line " + line.ToString() + ": A field cannot span" + " multiple lines"); } components.Add(field); Fields.Add(field); builder.Length = 0; currentType = StringType.Text; } else { throw new FormatException("Line " + line.ToString() + ": A field cannot be empty."); } } break; default: builder.Append(curr); break; } } // Deal with the last text component if (builder.Length > 0) { if (currentType == StringType.Field) { throw new FormatException("The end of the file was reached" + " without finding the end of the last field"); } else { LetterText text = new LetterText(); text.Text = builder.ToString(); components.Add(text); } } }