/// <summary> /// Makes a choice, like when you have to choose between cinnamon and butterscotch /// </summary> /// <param name="question"></param> /// <param name="varIndex"></param> [CYFEventFunction] public void SetChoice(DynValue choices, string question = "", DynValue forcePosition = null) { // Unfortunately, something weird is happening here // Calling `SetChoice({"Yes", "No"}, nil, true)` fails to pass the final argument if (question != null && forcePosition != null) { PlayerOverworld.instance.UIPos = forcePosition.Type == DataType.Boolean ? (forcePosition.Boolean == true ? 2 : 1) : 0; } else { PlayerOverworld.instance.UIPos = 0; } TextMessage textMsgChoice = new TextMessage("", false, false, true); textMsgChoice.AddToText("[mugshot:null]"); List <string> finalText = new List <string>(); bool[] oneLiners = new bool[2]; List <string[]> preTexts = new List <string[]>(); bool threeLiner = false; //Do not put more than 3 lines and 2 choices //If the 3rd parameter is a string, it has to be a question if (question != "") { textMsgChoice.AddToText("* " + question + "\n"); } for (int i = 0; i < 2; i++) { //If there's no text, just don't print it if (choices.Table.Get(i + 1).String == null) { continue; } preTexts.Add(choices.Table.Get(i + 1).String.Split('\n')); string[] preText = preTexts[preTexts.Count - 1]; oneLiners[i] = preText.Length == 1 && question != ""; if (preText.Length == 3) { threeLiner = true; } if (oneLiners[i]) { string line = preText[0]; preTexts[preTexts.Count - 1] = new string[] { "", line }; } } for (int i = 0; i < 2; i++) { string[] preText = preTexts[i]; for (int j = 0; j < (threeLiner ? 3 : 2); j++) { if (j == finalText.Count) { finalText.Add(""); } finalText[j] += "[charspacing:8] [charspacing:2]" + (j >= preText.Length ? "" : preText[j]) + (i == 0 ? "\t" : "") + "[charspacing:default]"; } } //Add the text to the text to print then the SetChoice function with its parameters for (int i = 0; i < finalText.Count; i++) { if (finalText[i] != "\t") { textMsgChoice.AddToText(finalText[i] + ((i == finalText.Count - 1) ? "" : "\n")); } } textmgr.SetEffect(null); textmgr.SetText(textMsgChoice); textmgr.transform.parent.parent.SetAsLastSibling(); StCoroutine("ISetChoice", new object[] { question != "", oneLiners }, appliedScript.GetVar("_internalScriptName").String); }
/// <summary> /// Makes a choice, like when you have to choose between cinnamon and butterscotch /// </summary> /// <param name="question"></param> /// <param name="varIndex"></param> [CYFEventFunction] public void SetChoice(DynValue choices, string question = null) { bool threeLines = false; TextMessage textMsgChoice = new TextMessage("", false, false, true); textMsgChoice.AddToText("[mugshot:null]"); string[] finalText = new string[3]; //Do not put more than 3 lines and 2 choices //If the 3rd parameter is a string, it has to be a question if (question != null) { textMsgChoice.AddToText(question + "\n"); //int lengthAfter = question.Split('\n').Length; //if (question.Split('\n').Length > lengthAfter) lengthAfter = question.Split('\n').Length; /*if (lengthAfter > 2)*/ //textMsgChoice.addToText("\n"); //else textMsgChoice.addToText("\n\n"); } for (int i = 0; i < choices.Table.Length; i++) { //If there's no text, just don't print it if (i == 2 && question != null) { break; } if (choices.Table.Get(i + 1).String == null) { continue; } string[] preText = choices.Table.Get(i + 1).String.Split('\n'), text = new string[3]; if (preText.Length == 3) { threeLines = true; } for (int j = 0; j < 3; j++) { if (j < preText.Length) { text[j] = preText[j]; } else { text[j] = ""; } } for (int k = 0; k < 3; k++) { if (text[k] != "") { if (k == 0) { text[k] = "* " + text[k]; } else { text[k] = " " + text[k]; } } finalText[k] += text[k] + '\t'; if (k == text.Length - 1) { break; } } } //Add the text to the text to print then the SetChoice function with its parameters if (!threeLines && question != null) { textMsgChoice.AddToText("\n"); } textMsgChoice.AddToText(finalText[0] + "\n" + finalText[1] + "\n" + finalText[2]); textmgr.SetText(textMsgChoice); textmgr.transform.parent.parent.SetAsLastSibling(); StCoroutine("ISetChoice", new object[] { question != null, threeLines }); }