// Create window, call event on cancel public void EditText(UnityEngine.Events.UnityAction call) { Destroyer.Dialog(); cancelCall = call; // Border DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-10), 1), new Vector2(20, 6), StringKey.NULL); db.AddBorder(); // Heading db = new DialogBox(new Vector2(UIScaler.GetHCenter(-9.5f), 1), new Vector2(19, 1), title); Game game = Game.Get(); GameObject textObj = new GameObject("textEdit"); GameObject inputObj = new GameObject("textInput"); textObj.tag = Game.DIALOG; inputObj.tag = Game.DIALOG; inputObj.transform.SetParent(game.uICanvas.transform); textObj.transform.SetParent(inputObj.transform); RectTransform transBg = inputObj.AddComponent <RectTransform>(); transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 3 * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit()); transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-9) * UIScaler.GetPixelsPerUnit(), 18 * UIScaler.GetPixelsPerUnit()); RectTransform transTx = textObj.AddComponent <RectTransform>(); transTx.SetParent(transBg); transTx.localScale = transBg.localScale; transTx.sizeDelta = transBg.sizeDelta; inputObj.AddComponent <CanvasRenderer>(); textObj.AddComponent <CanvasRenderer>(); UnityEngine.UI.Text uiText = textObj.AddComponent <UnityEngine.UI.Text>(); uiText.color = Color.white; uiText.font = game.gameType.GetFont(); uiText.material = uiText.font.material; uiText.fontSize = UIScaler.GetSmallFont(); iField = inputObj.AddComponent <PanCancelInputField>(); iField.textComponent = uiText; iField.text = value; TextButton tb = new TextButton(new Vector2(UIScaler.GetHCenter(-8), 5), new Vector2(6, 1), CommonStringKeys.OK, OKButton); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.0f, 0.03f, 0f); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); tb = new TextButton(new Vector2(UIScaler.GetHCenter(2), 5), new Vector2(6, 1), CommonStringKeys.CANCEL, cancelCall); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); }
// Create window, call event on cancel public void EditText(UnityEngine.Events.UnityAction call) { Destroyer.Dialog(); cancelCall = call; // Border UIElement ui = new UIElement(); ui.SetLocation(UIScaler.GetHCenter(-10), 1, 20, 6); new UIElementBorder(ui); // Heading ui = new UIElement(); ui.SetLocation(UIScaler.GetHCenter(-9.5f), 1, 19, 1); ui.SetText(title); // Text background ui = new UIElement(); ui.SetLocation(UIScaler.GetHCenter(-9f), 2.9f, 18, 1); ui.SetBGColor(new Color(0.3f, 0.3f, 0.3f)); Game game = Game.Get(); GameObject textObj = new GameObject("textEdit"); GameObject inputObj = new GameObject("textInput"); textObj.tag = Game.DIALOG; inputObj.tag = Game.DIALOG; inputObj.transform.SetParent(game.uICanvas.transform); textObj.transform.SetParent(inputObj.transform); RectTransform transBg = inputObj.AddComponent <RectTransform>(); transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 3 * UIScaler.GetPixelsPerUnit(), UIScaler.GetPixelsPerUnit()); transBg.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, UIScaler.GetHCenter(-9) * UIScaler.GetPixelsPerUnit(), 18 * UIScaler.GetPixelsPerUnit()); RectTransform transTx = textObj.AddComponent <RectTransform>(); transTx.SetParent(transBg); transTx.localScale = transBg.localScale; transTx.sizeDelta = transBg.sizeDelta; inputObj.AddComponent <CanvasRenderer>(); textObj.AddComponent <CanvasRenderer>(); UnityEngine.UI.Text uiText = textObj.AddComponent <UnityEngine.UI.Text>(); uiText.color = Color.white; uiText.font = game.gameType.GetFont(); uiText.material = uiText.font.material; uiText.fontSize = UIScaler.GetSmallFont(); iField = inputObj.AddComponent <PanCancelInputField>(); iField.textComponent = uiText; iField.text = value; ui = new UIElement(); ui.SetLocation(UIScaler.GetHCenter(-8), 5, 6, 1); ui.SetText(CommonStringKeys.OK); ui.SetBGColor(new Color(0.03f, 0.0f, 0f)); ui.SetButton(OKButton); new UIElementBorder(ui); ui = new UIElement(); ui.SetLocation(UIScaler.GetHCenter(2), 5, 6, 1); ui.SetText(CommonStringKeys.CANCEL); ui.SetBGColor(new Color(0.03f, 0.0f, 0f)); ui.SetButton(cancelCall); new UIElementBorder(ui); }