Beispiel #1
0
 public ModalPanelDetail(string Question, Sprite Icon, Sprite Background, EventButtonDetail ButtonYesDetail)
 {
     this.Question             = Question;
     this.IconImage            = Icon;
     this.PanelBackgroundImage = Background;
     MessageType    = ModalMessageType.YesNo;
     button1Details = ButtonYesDetail;
 }
Beispiel #2
0
 public QueuedModalInfo(Sprite iconPic, string title, string question, UnityAction yesEvent, UnityAction noEvent, UnityAction cancelEvent,
                        UnityAction okEvent, bool iconActive, ModalMessageType messageType)
 {
     this.iconPic     = iconPic;
     this.title       = title;
     this.question    = question;
     this.yesEvent    = yesEvent;
     this.noEvent     = noEvent;
     this.cancelEvent = cancelEvent;
     this.okEvent     = okEvent;
     this.iconActive  = iconActive;
     this.messageType = messageType;
 }
Beispiel #3
0
    public void MessageBox(Sprite IconPic, string Title, string Question, UnityAction YesEvent, UnityAction NoEvent, UnityAction CancelEvent, UnityAction OkEvent, bool IconActive, ModalMessageType MessageType)
    {
        //if the panel is already open, we queue a new opening with the desired info.
        //the new panel will open as soon as the current one is closed
        if (ModalPanelObject.activeSelf)
        {
            queuedModals.Add(new QueuedModalInfo(IconPic, Title, Question, YesEvent, NoEvent, CancelEvent, OkEvent, IconActive, MessageType));
            return;
        }
        ModalPanelObject.SetActive(true);  //Activate the Panel; its default is "off" in the Inspector

        Button1.onClick.RemoveAllListeners();
        Button2.onClick.RemoveAllListeners();
        Button3.onClick.RemoveAllListeners();

        switch (MessageType)
        {
        case ModalMessageType.YesNoCancel:
            //Button1 is on the far left; Button2 is in the center and Button3 is on the right
            //Each can be activated and labeled individually
            if (YesEvent != null)
            {
                Button1.onClick.AddListener(YesEvent);
            }
            Button1.onClick.AddListener(ClosePanel);
            Button1.GetComponentInChildren <Text>().text = "Yes";

            if (NoEvent != null)
            {
                Button2.onClick.AddListener(NoEvent);
            }
            Button2.onClick.AddListener(ClosePanel);
            Button2.GetComponentInChildren <Text>().text = "No";

            if (CancelEvent != null)
            {
                Button3.onClick.AddListener(CancelEvent);
            }
            Button3.onClick.AddListener(ClosePanel);
            Button3.GetComponentInChildren <Text>().text = "Cancel";

            Button1.gameObject.SetActive(true);     //We always turn on ONLY the buttons we need, and leave the rest off
            Button2.gameObject.SetActive(true);
            Button3.gameObject.SetActive(true);
            break;

        case ModalMessageType.YesNo:
            if (YesEvent != null)
            {
                Button1.onClick.AddListener(YesEvent);
            }
            Button1.onClick.AddListener(ClosePanel);
            Button1.GetComponentInChildren <Text>().text = "Yes";

            if (NoEvent != null)
            {
                Button3.onClick.AddListener(NoEvent);
            }
            Button3.onClick.AddListener(ClosePanel);
            Button3.GetComponentInChildren <Text>().text = "No";

            Button1.gameObject.SetActive(true);
            Button2.gameObject.SetActive(false);
            Button3.gameObject.SetActive(true);
            break;

        case ModalMessageType.Ok:
            if (OkEvent != null)
            {
                Button2.onClick.AddListener(OkEvent);
            }
            Button2.onClick.AddListener(ClosePanel);
            Button2.GetComponentInChildren <Text>().text = "OK";

            Button1.gameObject.SetActive(false);
            Button2.gameObject.SetActive(true);
            Button3.gameObject.SetActive(false);
            break;
        }

        this.Title.text    = Title;               //Fill in the Title part of the Message Box
        this.Question.text = Question;            //Fill in the Question/statement part of the Messsage Box
        if (IconActive)                           //If the Icon is active (true)...
        {
            IconImage.gameObject.SetActive(true); //Turn on the icon,
            IconImage.sprite = IconPic;           //and assign the picture.
        }
        else
        {
            IconImage.gameObject.SetActive(false); //Turn off the icon.
        }
    }