private void Start(OptionsMenuBehaviour optionsMenu, GameObject parent) { //Get original components var oBackgroundComponent = Utils.GetChildComponentByName <Component>(optionsMenu, "Background"); var oCloseButton = Utils.GetChildComponentByName <Component>(optionsMenu, "CloseButton"); var oControlText = Utils.GetChildComponentByName <Component>(optionsMenu, "ControlText"); //Create component and add it to the parent holder = new GameObject(name); //Set button parent holder.transform.parent = parent == null ? optionsMenu.transform : parent.transform; //Configure holder and his components holder.layer = 5; //UI holder.transform.localScale = new Vector3(1f, 1f, 1f); holder.transform.localPosition = Vector3.back * 20f; //clone original sub components _backgroundComponent = Object.Instantiate(oBackgroundComponent, holder.transform); if (oCloseButton != null) { _closeButton = Object.Instantiate(oCloseButton, holder.transform); } _controlText = Object.Instantiate(oControlText, holder.transform); //Configure background size _backgroundComponent.transform.localPosition = new Vector3(_backgroundComponent.transform.localPosition.x, _backgroundComponent.transform.localPosition.y, 9f); var renderer = _backgroundComponent.gameObject.GetComponent <SpriteRenderer>(); renderer.size = size; var collider = _backgroundComponent.gameObject.GetComponent <BoxCollider2D>(); collider.size = size; //Configure close button if (_closeButton != null) { _closeButton.transform.localPosition = new Vector3(pos.x, pos.y); var button = _closeButton.gameObject.GetComponent <PassiveButton>(); Object.Destroy(button); button = _closeButton.gameObject.AddComponent <PassiveButton>(); button.OnClick.AddListener((UnityAction)OnClose); button.OnMouseOver = new UnityEvent(); button.OnMouseOut = new UnityEvent(); } //Configure title title _textRenderer = _controlText.gameObject.GetComponent <TextRenderer>(); _textRenderer.Centered = true; _controlText.transform.localPosition = new Vector3(/*-(size.x / 2) * 0.90f */ 0f, size.y / 2 * 0.92f); //Enable the button holder.gameObject.SetActive(false); }
public PopUpWindow(OptionsMenuBehaviour optionsMenu, string name, string title, Vector2 size, Vector2 pos, GameObject parent = null) { this.name = name; this.title = title; this.size = size; this.pos = pos; Windows.Add(this); Start(optionsMenu, parent); }
public static bool Prefix(OptionsMenuBehaviour __instance) { if (KeySelector.canEscape) { return(true); } if (Input.GetKeyUp(KeyCode.Escape)) { KeySelector.canEscape = true; } return(false); }
public OptionsMenuButton(OptionsMenuBehaviour optionsMenu, string name, string text, Action action, Vector2 pos, Vector2 size, GameObject parent = null) { this.text = text; this.pos = pos; this.name = name; this.action = action; this.size = size; Buttons.Add(this); Start(optionsMenu, parent); }
//Setup key listener public KeySelector(OptionsMenuBehaviour optionsMenu, string name, string label, KeyAction key, Vector2 labelPos, Vector2 buttonPos, GameObject parent = null) { this.name = name; this.label = label; this.key = key; this.labelPos = labelPos; this.buttonPos = buttonPos; Selectors.Add(this); Start(optionsMenu, parent); }
private void Start(OptionsMenuBehaviour optionsMenu, GameObject parent) { //Get original components var oControlGroup = Utils.GetChildComponentByName <Component>(optionsMenu, "ControlGroup"); var oControlText = Utils.GetChildComponentByName <Component>(oControlGroup, "ControlText"); var oIgnoreClose = Utils.GetChildComponentByName <Component>(optionsMenu, "IgnoreClose"); if (oIgnoreClose == null) { oIgnoreClose = Utils.GetChildComponentByName <Component>(optionsMenu, "CloseBackground"); } //Create component and add it to the parent _holder = new GameObject(name); //Set button parent _holder.transform.parent = parent == null ? optionsMenu.transform : parent.transform; //Configure holder and his components _holder.layer = 5; //UI _holder.transform.localScale = new Vector3(1f, 1f, 1f); _holder.transform.localPosition = Vector3.zero; //clone original sub components _label = Object.Instantiate(oControlText, _holder.transform); _ignoreClose = Object.Instantiate(oIgnoreClose, _holder.transform); //Configure label _textRenderer = _label.gameObject.GetComponent <TextRenderer>(); _label.transform.localPosition = new Vector3(labelPos.x, labelPos.y); //Create button _button = new OptionsMenuButton(optionsMenu, key + "Button", ConfigManager.keyBinds[key].ToString(), OnClick, buttonPos + new Vector2(0f, -0.2f) /* Centered vertical anchor */, new Vector2(1.0f, 0.4f), _holder); _button.SetOnMouseOut(OnMouseOut); _button.SetOnMouseOver(OnMouseOver); //Configure ignoreClose _ignoreClose.gameObject.SetActive(false); _ignoreClose.transform.localPosition = new Vector3(_ignoreClose.transform.localPosition.x, _ignoreClose.transform.localPosition.y, _ignoreClose.transform.localPosition.z - 1000f); var collider = _ignoreClose.gameObject.GetComponent <BoxCollider2D>(); collider.size = new Vector2(Screen.width, Screen.height); }
private void Start(OptionsMenuBehaviour optionsMenu, GameObject parent) { //Get original components var joyStickButtonComponent = Utils.GetChildComponentByName <Component>(optionsMenu, "JoystickModeButton"); var oBackgroundComponent = Utils.GetChildComponentByName <Component>(joyStickButtonComponent, "Background"); var oTextComponent = Utils.GetChildComponentByName <TextRenderer>(joyStickButtonComponent, "Text"); //Create component and add it to the parent holder = new GameObject(name); //Set button parent holder.transform.parent = parent == null ? joyStickButtonComponent.transform.parent.transform : parent.transform; //Configure holder and his components holder.layer = 5; //UI holder.transform.localScale = new Vector3(1f, 1f, 1f); //holder.transform.localPosition = new Vector3(holder.transform.localPosition.x, holder.transform.localPosition.y, holder.transform.localPosition.z - 100f); var collider = holder.gameObject.AddComponent <BoxCollider2D>(); collider.size = size; //clone original sub components backgroundComponent = Object.Instantiate(oBackgroundComponent, holder.transform); textComponent = Object.Instantiate(oTextComponent, holder.transform); //Configure background size var renderer = backgroundComponent.gameObject.GetComponent <SpriteRenderer>(); renderer.size = size; //Add PassiveButton component button = holder.gameObject.AddComponent <PassiveButton>(); button.OnClick.AddListener(action); button.OnMouseOut = new UnityEvent(); button.OnMouseOut.AddListener((UnityAction)OnOut); button.OnMouseOver = new UnityEvent(); button.OnMouseOver.AddListener((UnityAction)OnOver); //Enable the button OnOut(); holder.gameObject.SetActive(true); textComponent.Text = text; holder.transform.localPosition = new Vector3(pos.x, pos.y); }
private void Start(OptionsMenuBehaviour optionsMenu) { //Setup separator separator = new GameObject("Separator"); separator.transform.parent = holder.transform; var start = new Vector3(0f, size.y / 2 * 0.75f, holder.transform.position.z - 21f); separator.transform.position = start; var lr = separator.AddComponent <LineRenderer>(); lr.material = new Material(Shader.Find("Unlit/ColoredVertices")); lr.SetColors(Color.white, Color.white); lr.SetWidth(0.05f, 0.05f); lr.SetPosition(0, start); lr.SetPosition(1, new Vector3(0f, -size.y / 2 * 0.9f, holder.transform.position.z - 21f)); //Create child elements var i = 0; foreach (KeyAction action in Enum.GetValues(typeof(KeyAction))) { const int numRows = 5; var column = i / numRows; var row = i % numRows; const float topPercent = 0.70f; const float botPercent = 0.90f; var selectorPos = new Vector2(-size.x / 2 * botPercent + column * (size.x / 2), size.y / 2 * topPercent - row * (size.y * (topPercent + botPercent) / 2 / numRows)); content.Add(new KeySelector(optionsMenu, action.ToString(), action.ToString(), action, selectorPos, selectorPos + new Vector2(size.x / 3, 0f), holder)); i++; } }
public static void Postfix(OptionsMenuBehaviour __instance) { new OptionsMenuButton(__instance, "OpenKeyBindMenuButton", "KeyBinds", OpenKeyBindMenu, new Vector2(0f, -0.9f)); _keyBindsPopUp = new SettingsWindow(__instance); }
public OptionsMenuButton(OptionsMenuBehaviour optionsMenu, string name, string text, Action action, Vector2 pos, GameObject parent = null) : this(optionsMenu, name, text, action, pos, new Vector2(2.0f, 0.4f), parent) { }
public SettingsWindow(OptionsMenuBehaviour optionsMenu) : base(optionsMenu, "KeyBindPopUp", "Keybinds", new Vector2(5.5f, 4f), new Vector2(-3f, 1.75f)) { SetButtonListener(OnClose); Start(optionsMenu); }