Esempio n. 1
0
    protected virtual GameObject MakePopupGameObject(TextButton templateButton,
                                                     string selected = null)
    {
        // create popup menu
        GameObject popupGameObject = gameObject.MakeUiObject("Popup");

        // create blocker
        ClickBlocker clickBlocker = ClickBlocker.MakeClickBlocker(popupGameObject, gameObject);

        // create menu
        _gameObjectMenu = popupGameObject.MakeUiObject("Menu");

        // create background
        GameObject gameObjectBackground = _gameObjectMenu.MakeUiObject("Background");
        Image      backgroundImage      = gameObjectBackground.AddComponent <Image>();

        backgroundImage.sprite = popupBgSprite;
        float btnWidth  = popupTextButton.GetWidth() + padding * 2;
        float btnHeight = popupTextButton.GetHeight() + padding * 2;
        float bgHeight  = (btnHeight - padding) * _menuItems.Length + padding;

        backgroundImage.SetSize(btnWidth, bgHeight);
        backgroundImage.SetY(backgroundImage.GetHeight() / 2 - btnHeight / 2);

        // set selected, this will move the background
        Selected = selected;

        // check if popup in within display region
        if (!UtilsRect.AinsideB(backgroundImage, clickBlocker))
        {
            // if not, then reverse menuItem order
            //  causing menu to build in the opposite direction
            Array.Reverse(_menuItems);
            Selected = selected;
        }

        // create selection buttons
        float yLoc    = 0;
        int   counter = 0;

        _menuButtons = new ClickButton[_menuItems.Length];
        foreach (string menuItem in _menuItems)
        {
            int         index       = counter++;
            TextButton  textButton  = MakeTextButton(templateButton, menuItem);
            ClickButton clickButton = textButton.ClickButton;
            clickButton.SetY(yLoc);
            clickButton.onClickEvent.AddListener(delegate { MenuButtonClicked(new PopupMenuEventArgs(menuItem, index)); });
            clickButton.OnRolloverEvent += delegate { MenuButtonRolled(menuItem, index); };
            yLoc += clickButton.GetHeight() + padding;
            if (index == _selectedIndex)
            {
                clickButton.Selected = true;
                clickButton.Enabled  = false;
            }
            _menuButtons[index] = clickButton;
        }

        return(popupGameObject);
    }
Esempio n. 2
0
    protected override GameObject MakePopupGameObject(TextButton templateButton,
                                                      string selected = null)
    {
        // TODO: not this. Messy manipulation of popupTextButton
        // ensure popupTextButton in position
        popupTextButton.SetX(0);

        // create popup menu
        GameObject popupGameObject = gameObject.MakeUiObject("Hamberger");

        // create blocker
        ClickBlocker clickBlocker = ClickBlocker.MakeClickBlocker(popupGameObject, gameObject);

        // create menu
        _gameObjectMenu = popupGameObject.MakeUiObject("Menu");

        // create background
        GameObject gameObjectBackground = _gameObjectMenu.MakeUiObject("Background");
        Image      backgroundImage      = gameObjectBackground.AddComponent <Image>();

        backgroundImage.sprite = popupBgSprite;
        float btnWidth  = popupTextButton.GetWidth() + padding * 2;
        float btnHeight = popupTextButton.GetHeight() + padding * 2;
        float bgHeight  = (btnHeight - padding) * _menuItems.Length + padding;

        backgroundImage.SetSize(btnWidth, bgHeight);
        backgroundImage.SetY(backgroundImage.GetHeight() / 2 - padding);
        backgroundImage.SetX(backgroundImage.GetWidth() / 2 - padding);

        // set selected, this will move the background
        Selected = selected;

        // create selection buttons
        float yLoc = 0;

        for (int i = 0; i < _menuItems.Length; ++i)
        {
            int         index       = _menuItems.Length - i - 1;
            string      menuItem    = _menuItems[index];
            TextButton  textButton  = MakeTextButton(templateButton, menuItem);
            ClickButton clickButton = textButton.ClickButton;
            clickButton.SetY(yLoc);
            clickButton.onClickEvent.AddListener(delegate { MenuButtonClicked(new PopupMenuEventArgs(menuItem, index)); });
            clickButton.OnRolloverEvent += delegate { MenuButtonRolled(menuItem, index); };
            yLoc += clickButton.GetHeight() + padding;
            if (index == _selectedIndex)
            {
                clickButton.Selected = true;
                clickButton.Enabled  = false;
            }
        }

        // TODO: not this. Messy manipulation of popupTextButton
        // move popupTextButton offscreen.  Can't hide it as factory it won't duplicate it when hidden.
        popupTextButton.SetX(-10000);

        return(popupGameObject);
    }
Esempio n. 3
0
    private IBlockResolver _iBlockResolver;                     // whatever instance that deals with the blocker pointer events

    public static ClickBlocker MakeClickBlocker(GameObject parentGameObject, GameObject focusGameObject)
    {
        GameObject   clickBlockerGameObject = parentGameObject.MakeUiObject("Click Blocker");
        ClickBlocker clickBlocker           = clickBlockerGameObject.AddComponent <ClickBlocker>();

        clickBlocker.Initialize(focusGameObject);

        return(clickBlocker);
    }
Esempio n. 4
0
    public void HideDialogs()
    {
        // remove click blocker
        if (_clickBlocker != default)
        {
            Object.Destroy(_clickBlocker.GetGameObject());
            _clickBlocker = default;
        }

        // hide all dialogs
        HideDialog(dialog);
        HideDialog(settingsDialog);
    }
Esempio n. 5
0
    public void ShowDialog(DialogBase dialog)
    {
        GameObject dialogGameObject = dialog.gameObject;

        // add the clock blocker
        if (_clickBlocker == default)
        {
            _clickBlocker = ClickBlocker.MakeClickBlocker(gameObject, dialogGameObject);
        }

        // move dialog to top and show
        dialogGameObject.MoveToTop();
        dialogGameObject.SetActive(true);
    }
Esempio n. 6
0
    protected override GameObject MakePopupGameObject(TextButton templateButton,
                                                      string selected = null)
    {
        // create popup menu
        GameObject popupGameObject = gameObject.MakeUiObject("DropDown");

        // create blocker
        ClickBlocker clickBlocker = ClickBlocker.MakeClickBlocker(popupGameObject, gameObject);

        // create menu
        _gameObjectMenu = popupGameObject.MakeUiObject("Menu");

        // create background
        GameObject gameObjectBackground = _gameObjectMenu.MakeUiObject("Background");
        Image      backgroundImage      = gameObjectBackground.AddComponent <Image>();

        backgroundImage.sprite = popupBgSprite;
        float btnWidth  = popupTextButton.GetWidth() + padding * 2;
        float btnHeight = popupTextButton.GetHeight() + padding * 2;
        float bgHeight  = (btnHeight - padding) * (_menuItems.Length + 1) + padding * 1.5f;

        backgroundImage.SetSize(btnWidth, bgHeight);
        backgroundImage.SetY(backgroundImage.GetHeight() / 2 - btnHeight / 2);

        // set selected, this will move the background
        Selected = selected;

        // create selection buttons
        float yLoc = 0;

        for (int i = 0; i < _menuItems.Length; ++i)
        {
            int         index       = _menuItems.Length - i - 1;
            string      menuItem    = _menuItems[index];
            TextButton  textButton  = MakeTextButton(templateButton, menuItem);
            ClickButton clickButton = textButton.ClickButton;
            clickButton.SetY(yLoc);
            clickButton.onClickEvent.AddListener(delegate { MenuButtonClicked(new PopupMenuEventArgs(menuItem, index)); });
            clickButton.OnRolloverEvent += delegate { MenuButtonRolled(menuItem, index); };
            yLoc += clickButton.GetHeight() + padding;
        }

        return(popupGameObject);
    }