Пример #1
0
 /// <summary>
 /// Opens the default modal window with the specified settings
 /// </summary>
 /// <param name="settings">The settings for the modal window</param>
 public void ShowModalWindow(ModalWindowSettings settings)
 {
     if (_modalWindows.Count > 0)
     {
         ShowModalWindow(settings, _modalWindows[0].name);
     }
 }
Пример #2
0
        protected virtual void InitModalWindow(ModalWindowSettings settings)
        {
            //set the title
            if (titleText != null)
            {
                titleText.text = settings.title;
            }

            //set the message
            if (messageText != null)
            {
                messageText.text = settings.message;
            }

            //set the image
            if (imageComponent != null)
            {
                imageComponent.gameObject.SetActive(true);

                if (settings.image == null)
                {
                    imageComponent.sprite = null;
                    imageComponent.gameObject.SetActive(false);
                }
                else
                {
                    imageComponent.sprite = Sprite.Create(settings.image, new Rect(0, 0, settings.image.width, settings.image.height), new Vector2(0.5f, 0.5f));
                    imageComponent.gameObject.SetActive(true);
                }
            }

            //set the buttons
            if (buttons != null)
            {
                foreach (var item in buttons)
                {
                    item.gameObject.SetActive(false);
                }

                if (settings.buttons != null && settings.buttons.Length > 0)
                {
                    for (int i = 0; i < Mathf.Min(settings.buttons.Length, buttons.Count); i++)
                    {
                        buttons[i].gameObject.SetActive(true);
                        buttons[i].name = settings.buttons[i];
                        buttons[i].GetComponentInChildren <Text>().text = settings.buttons[i];
                    }
                }
                else if (buttons.Count > 0)
                {
                    buttons[0].gameObject.SetActive(true);
                    buttons[0].name = "Close";
                    buttons[0].GetComponentInChildren <Text>().text = "Close";
                }
            }

            //set the modal window handler
            _handler = settings.handler;
        }
Пример #3
0
        /// <summary>
        /// Initializes the modal window with the given settings and opens it
        /// </summary>
        /// <param name="settings">The modal window settings</param>
        public void OpenModalWindow(ModalWindowSettings settings)
        {
            if (settings != null)
            {
                gameObject.SetActive(true);

                InitModalWindow(settings);
            }
        }
Пример #4
0
        /// <summary>
        /// Shows the default modal window with the given parameters
        /// </summary>
        /// <param name="title">The title of the modal window</param>
        /// <param name="message">The message to display in the modal window</param>
        /// <param name="buttons">Array of strings to disply on buttons in the modal window</param>
        /// <param name="callback">Delegate called when closing the modal window</param>
        /// <param name="texture">Optional texture to display along with the text</param>
        public void ShowModalWindow(string title, string message, string[] buttons, Action <string> callback, Texture2D texture = null)
        {
            ModalWindowSettings settings = new ModalWindowSettings()
            {
                title   = title,
                message = message,
                image   = texture,

                buttons = buttons,
                handler = callback,
            };

            ShowModalWindow(settings);
        }
Пример #5
0
 /// <summary>
 /// Opens the modal window specified by name with the specified settings
 /// </summary>
 /// <param name="settings">The settings for the modal window</param>
 /// <param name="windowName">The name of the modal window to use (Prefab name)</param>
 public void ShowModalWindow(ModalWindowSettings settings, string windowName)
 {
     if (_activeModalWindow == null || !_activeModalWindow.gameObject.activeInHierarchy || settings.overrideActiveModalWindow)  //make sure there isn't already a modal window
     {
         UIModalWindow w = _modalWindows.FirstOrDefault(x => x.name == windowName);
         if (w != null)
         {
             CloseActiveModalWindow();
             ShowModalWindow(settings, w);
         }
         else
         {
             Debug.LogWarning("Cannot find modal window with name '" + windowName + "'");
         }
     }
     else
     {
         Debug.LogWarning("There already is an active modal window.");
     }
 }
Пример #6
0
 private void ShowModalWindow(ModalWindowSettings settings, UIModalWindow window)
 {
     _activeModalWindow = window;
     window.OpenModalWindow(settings);
     HideTooltip();
 }
Пример #7
0
        /// <summary>
        /// Initializes the modal window with the given settings and opens it
        /// </summary>
        /// <param name="settings">The modal window settings</param>
        public void OpenModalWindow( ModalWindowSettings settings )
        {
            if ( settings != null )
            {
                gameObject.SetActive( true );

                InitModalWindow( settings );
            }
        }
Пример #8
0
        protected virtual void InitModalWindow( ModalWindowSettings settings )
        {
            //set the title
            if ( titleText != null )
                titleText.text = settings.title;

            //set the message
            if ( messageText != null )
                messageText.text = settings.message;

            //set the image
            if ( imageComponent != null )
            {
                imageComponent.gameObject.SetActive( true );

                if ( settings.image == null )
                {
                    imageComponent.sprite = null;
                    imageComponent.gameObject.SetActive( false );
                }
                else
                {
                    imageComponent.sprite = Sprite.Create( settings.image, new Rect( 0, 0, settings.image.width, settings.image.height ), new Vector2( 0.5f, 0.5f ) );
                    imageComponent.gameObject.SetActive( true );
                }
            }

            //set the buttons
            if ( buttons != null )
            {
                foreach ( var item in buttons )
                    item.gameObject.SetActive( false );

                if ( settings.buttons != null && settings.buttons.Length > 0 )
                {
                    for ( int i = 0; i < Mathf.Min( settings.buttons.Length, buttons.Count ); i++ )
                    {
                        buttons[i].gameObject.SetActive( true );
                        buttons[i].name = settings.buttons[i];
                        buttons[i].GetComponentInChildren<Text>().text = settings.buttons[i];
                    }
                }
                else if ( buttons.Count > 0 )
                {
                    buttons[0].gameObject.SetActive( true );
                    buttons[0].name = "Close";
                    buttons[0].GetComponentInChildren<Text>().text = "Close";
                }
            }

            //set the modal window handler
            _handler = settings.handler;
        }