public Toggle AddCheckbox(bool value, string title, UnityAction <bool> save, string audio = "checkBoxClick") { Toggle button = UIElements.CreateCheckBox(panel.transform, title, save).GetComponent <Toggle>(); button.isOn = value; button.onValueChanged.AddListener((pos) => { NAudio.Play(audio); }); return(button); }
public GameObject AddDesc(string title) { GameObject button = Instantiate(UIElements.Get().panelLabelDesc, panel.transform); button.GetComponent <Text>().text = title; return(button); }
public GameObject AddInput(string title, int def, UnityAction <int> save) { GameObject button = Instantiate(UIElements.Get().input, panel.transform); button.transform.GetChild(0).GetComponent <Text>().text = $"Enter {title}..."; button.GetComponent <InputField>().text = def.ToString(); button.GetComponent <InputField>().onValueChanged.AddListener((val) => { save(Int32.Parse(val)); }); return(button); }
public static WindowTabBuilder Create(string title) { title = TextHelper.Cap(title); GameObject act = Instantiate(UIElements.Get().tabWindow, GameObject.Find("WindowsMgmt").transform); act.name = title; act.GetComponent <WindowTabBuilder>().Init(title); return(act.GetComponent <WindowTabBuilder>()); }
public static WindowPanelBuilder Create(string title) { title = TextHelper.Cap(title); GameObject act = Instantiate(UIElements.Get().panelWindow, GameObject.Find("WindowsMgmt").transform); act.name = title; act.transform.GetComponentInChildren <Text>().text = title; act.GetComponent <WindowPanelBuilder>().panel = PanelBuilder.Create(act.transform.GetChild(0).GetChild(2).transform); return(act.GetComponent <WindowPanelBuilder>()); }
public Image AddImage(Sprite icon) { Image act = Instantiate(UIElements.Get().panelImage, panel.transform).GetComponent <Image>(); act.sprite = icon; //TODO dyn 300 int h = (int)(300.0 / icon.texture.width * icon.texture.height); act.GetComponent <RectTransform>().sizeDelta = new Vector2(0, h); return(act); }
public Dropdown AddDropdown(string[] values, string def, string[] titles, UnityAction <string> save) { Dropdown dropdown = Instantiate(UIElements.Get().dropdown.gameObject, panel.transform).GetComponent <Dropdown>(); foreach (string t in titles) { dropdown.options.Add(new Dropdown.OptionData(t)); } dropdown.value = Array.IndexOf(values, def); dropdown.onValueChanged.AddListener((pos) => { save(values[pos]); }); return(dropdown); }
public Text AddLabel(string title) { if (string.IsNullOrEmpty(title)) { return(null); } GameObject button = Instantiate(UIElements.Get().panelLabel, panel.transform); button.name = title.Substring(0, Math.Min(title.Length, 20)); button.GetComponent <Text>().text = TextHelper.Cap(title); button.GetComponent <RectTransform>().sizeDelta = new Vector2(button.GetComponent <RectTransform>().sizeDelta.x, (title.Length / 35 + 1) * 16); return(button.GetComponent <Text>()); }
public InputField AddInputRandom(string title, string def, UnityAction <string> save, Func <string> random) { InputField input = Instantiate(UIElements.Get().inputRandom, panel.transform); input.transform.GetChild(0).GetComponent <Text>().text = $"Enter {title}..."; input.text = def; input.onValueChanged.AddListener(val => { save(val); }); Button button = input.transform.GetChild(2).GetComponent <Button>(); button.onClick.AddListener(() => { NAudio.Play("random"); }); button.onClick.AddListener(() => { input.text = random(); }); return(input); }
public void Finish() { //build tabs foreach (Tab t in _tabs) { UIElements.CreateImageButton(t.Icon(), tabList.transform, () => { ShowTab(t); }); } //show first tab? if (_tabs.Count > 0) { ShowTab(_tabs[0]); } gameObject.SetActive(true); }
public static Button CreateButton(string title, Transform parent, Action action, string sound = "click") { Button act = Instantiate(UIElements.Get().button, parent).GetComponent <Button>(); UpdateButtonText(act, title); //act.transform.Find("Label").GetComponent<Text>().text = TextHelper.Cap(title); act.onClick.AddListener(() => { try { action(); } catch (Exception e) { ExceptionHelper.ShowException(e); } }); UIElements.AddButtonSound(act, sound); return(act); }
public static WindowBuilderSplit Create(string title, string buttonText) { GameObject act = Instantiate(UIElements.Get().splitWindow, GameObject.Find("WindowsMgmt").transform); title = TextHelper.Cap(title); act.name = title; act.transform.GetChild(0).GetChild(1).GetComponent <Text>().text = title; WindowBuilderSplit w = act.GetComponent <WindowBuilderSplit>(); w.elements = new List <SplitElement>(); //has a button? if (buttonText != null) { w.SetButtonText(buttonText); } return(w); }
public static PanelBuilderSplit Create(Transform transform, IWindow window, List <SplitElement> elements, string buttonText = null) { GameObject act = Instantiate(UIElements.Get().panelSplit, transform); PanelBuilderSplit w = act.GetComponent <PanelBuilderSplit>(); w.elements = elements; w.window = window; //build ui foreach (SplitElement ele in elements) { w.AddElement(ele); } w.SetButtonText(buttonText); w.Finish(); return(w); }
public Slider AddSlider(int min, int max, int def, UnityAction <int> save) { Slider slider = Instantiate(UIElements.Get().slider, panel.transform); slider.minValue = min; slider.value = def; slider.maxValue = max; slider.onValueChanged.AddListener((val) => { save((int)val); if (S.Advanced()) { slider.gameObject.GetComponentInChildren <Text>().text = ((int)val).ToString(); } }); if (S.Advanced()) { slider.gameObject.GetComponentInChildren <Text>().text = def.ToString(); } return(slider); }
public static Button CreateImageTextButton(string title, Sprite icon, Transform parent, Action action, string sound = "click") { Button act = Instantiate(UIElements.Get().imageTextButton, parent).GetComponent <Button>(); UpdateButtonText(act, title); //act.name = title; //act.transform.GetChild(0).GetComponent<Text>().text = TextHelper.Cap(title); act.transform.GetChild(1).GetComponent <Image>().sprite = icon; act.onClick.AddListener(() => { try { action(); } catch (Exception e) { ExceptionHelper.ShowException(e); } }); UIElements.AddButtonSound(act, sound); return(act); }
public static PanelBuilder Create(Transform transform) { GameObject p = Instantiate(UIElements.Get().panelBuilder, transform); return(p.GetComponent <PanelBuilder>()); }
public GameObject AddImageLabel(string title, string icon) { return(UIElements.CreateImageLabel(panel.transform, title, icon)); }
public GameObject AddHeaderLabel(string title) { return(UIElements.CreateHeaderLabel(panel.transform, TextHelper.Cap(title))); }