Exemplo n.º 1
0
    public void ShowErrorMessage(string Message, string Title)
    {
        if (mErrorMessageBox != null)
        {
            GameObject.Destroy(mErrorMessageBox);
        }

        mErrorMessageBox = _ui.CreateElement(mMenuLayer, "ErrorMessage");
        //errorMsg.SetActive(false);
        _ui.AddImage(mErrorMessageBox, _style.TooltipBackground);
        _ui.SetAnchors(mErrorMessageBox, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
        _ui.SetTransform(mErrorMessageBox, 0, 0, 600, 256);
        _ui.AddVerticalLayout(mErrorMessageBox).childForceExpandWidth   = true;
        mErrorMessageBox.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

        GameObject titleBar = _ui.CreateElement(mErrorMessageBox, "TitleBar");

        _ui.AddImage(titleBar, _style.ThemeColorC);
        _ui.SetAnchors(titleBar, new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, 1.0f));
        _ui.AddLayout(titleBar, -1, 30, -1, -1);
        //_ui.SetTransform(optsTitle, 0, 0, 0, 26);

        GameObject titleText = _ui.CreateElement(titleBar);

        _ui.SetAnchors(titleText, new Vector2(0.0f, 0.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, 1.0f));
        _ui.SetTransform(titleText, 5, 0, -10, 0);
        Text optsTitleTextComp = titleText.AddComponent <Text>();

        optsTitleTextComp.text      = Title;
        optsTitleTextComp.font      = _style.FontA;
        optsTitleTextComp.alignment = TextAnchor.MiddleLeft;


        GameObject messageBody = _ui.CreateElement(mErrorMessageBox, "MsgBorder");

        _ui.AddVerticalLayout(messageBody, new RectOffset(10, 10, 10, 10));

        GameObject message = _ui.CreateElement(messageBody);
        //_ui.SetAnchors(optsTitleText, new Vector2(0.0f, 0.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, 1.0f));
        //_ui.SetTransform(optsTitleText, 5, 0, -10, 0);
        Text messageTextComp = message.AddComponent <Text>();

        messageTextComp.text = Message;
        messageTextComp.font = _style.FontA;
        //messageTextComp.alignment = TextAnchor.MiddleLeft;

        // TODO: This message should be removed when session terminated with other game related UI.

        /*
         * GameObject button = _ui.CreateMenuButton(errorMsg, "Exit", () => {
         *      GameObject.Destroy(errorMsg);
         *      CGame.UIManager.PlaySound(CGame.PrimaryResources.AudioClips[15]);
         *      CGame.Game.TerminateGameSession();
         *      CGame.UIManager.AddInterface(new CMainMenuUI());
         * });
         * _ui.SetTransform(button, 50, -100, 256, 50);
         */

        GameObject button = _ui.CreateButton(mErrorMessageBox, "Close", () => {
            GameObject.Destroy(mErrorMessageBox);
            mErrorMessageBox = null;
            CGame.UIManager.PlaySound(CGame.PrimaryResources.AudioClips[15]);
        });

        _ui.AddLayout(button, -1, 20, 1.0f, -1);
    }