Exemple #1
0
    void OnServerFound(int clientJoinRequestId, int serverJoinRequestId, string ipAddress, int port)
    {
        if (m_MessageBox == null || m_MessageBox.IsVisible == false)
        {
            return;
        }

        m_MessageBox.SetText(TextDatabase.instance[0109054]);
        m_MessageBox = null;

        System.Net.IPAddress serverAddress = null;
        System.Net.IPAddress.TryParse(ipAddress, out serverAddress);

        System.Net.IPEndPoint serverEndpoint = new System.Net.IPEndPoint(serverAddress, port);

        Game.Instance.StartNewMultiplayerGame(serverEndpoint, serverJoinRequestId);
    }
    void ShowMessage(int textId, bool canClose)
    {
        if (m_MessageBox == null || m_MessageBox.IsVisible == false)
        {
            m_MessageBox = Owner.ShowPopup("MessageBox", "", "") as GuiPopupMessageBox;
        }

        if (m_MessageBox != null)
        {
            m_MessageBox.SetCaption(TextDatabase.instance[MESSAGE_CAPTION]);
            m_MessageBox.SetText(TextDatabase.instance[textId]);
            m_MessageBox.SetButtonVisible(canClose);
        }
    }
    IEnumerator BuyPremiumAccount_Coroutine(int acctType)
    {
        int idx   = acctType - 1;
        int gold  = ShopDataBridge.Instance.PlayerGold;
        int price = m_Accounts[idx].RealPrice;

        string acctTypeID = m_Accounts[idx].Id;

        CloudUser user = CloudUser.instance;

        // not enough golds
        if (price > gold)
        {
            ShopItemId itemId = ShopDataBridge.Instance.GetPremiumAcct(acctTypeID);
            if (itemId == ShopItemId.EmptyId)
            {
                // ...
                yield break;
            }

            int  fundsNeeded = price - gold;
            bool buySucceed  = true;

            ShopItemId reqIAP = ShopDataBridge.Instance.FindFundsItem(fundsNeeded, true);

            if (reqIAP.IsEmpty())
            {
                yield break;
            }

            GuiShopNotFundsPopup.Instance.AddFundsID = reqIAP;
            GuiPopup popup = Owner.ShowPopup("NotFundsPopup",
                                             "",
                                             "",
                                             (inPopup, inResult) =>
            {
                switch (inResult)
                {
                case E_PopupResultCode.Cancel:
                    buySucceed = false;
                    break;

                case E_PopupResultCode.Failed:
                    buySucceed = false;
                    break;
                }
            });

            //Debug.Log("Popup Visible:" + popup.IsVisible);
            while (popup.IsVisible == true)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (buySucceed == false)
            {
                yield break;
            }

            //Debug.Log("IAP success:" + buySucceed);
        }

        // store current status of premium account
        bool hadPremiumAccount = user.isPremiumAccountActive;

        // create cloud action
        BaseCloudAction action = new BuyPremiumAccountAndFetchPPI(user.authenticatedUserID, acctTypeID);

        GameCloudManager.AddAction(action);

        // show message box
        GuiPopupMessageBox msgBox =
            (GuiPopupMessageBox)Owner.ShowPopup("MessageBox",
                                                TextDatabase.instance[01140017],
                                                TextDatabase.instance[01140018],
                                                (popup, result) =>
        {
            if (action.isSucceeded == true)
            {
                Owner.Back();
                SendResult(E_PopupResultCode.Ok);
            }
        });

        msgBox.SetButtonVisible(false);
        msgBox.SetButtonEnabled(false);

        // wait for async action...
        while (action.isDone == false)
        {
            yield return(new WaitForEndOfFrame());
        }

        // update message box
        int textId = 01140021;

        if (action.isSucceeded == true)
        {
            textId = hadPremiumAccount == true ? 01140020 : 01140019;
        }

        msgBox.SetText(TextDatabase.instance[textId]);
        msgBox.SetButtonVisible(true);
        msgBox.SetButtonEnabled(true);
    }
    IEnumerator UpdateProfile_Coroutine()
    {
        // show message box with some info
        GuiPopupMessageBox msgbox =
            Owner.ShowPopup("MessageBox", TextDatabase.instance[0107000], TextDatabase.instance[0107022]) as GuiPopupMessageBox;

        msgbox.SetButtonVisible(false);

        // update profile
        UpdateMFAccountAndFetchPPI action = CloudUser.instance.UpdateUser(m_Password1Hash,
                                                                          GuiBaseUtils.FixNickname(m_Nickname, CloudUser.instance.userName_TODO),
                                                                          null,
                                                                          m_ReceiveNews,
                                                                          m_Region);

        while (action.isDone == false)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        if (action.isSucceeded == true)
        {
            // update cloud user with actual informations
            string username   = "";
            string nickname   = "";
            string password   = "";
            int    pwdLength  = 0;
            bool   rememberMe = true;
            bool   autoLogin  = true;
            CloudUser.instance.GetLoginData(ref nickname, ref username, ref password, ref pwdLength, ref rememberMe, ref autoLogin);
            CloudUser.instance.SetLoginData(CloudUser.instance.primaryKey,
                                            m_Nickname,
                                            username,
                                            m_Password1Hash,
                                            m_PasswordLength,
                                            rememberMe,
                                            autoLogin);
            CloudUser.instance.receiveNews = m_ReceiveNews;
            CloudUser.instance.region      = m_Region;

            PlayerPersistantInfo ppi = PPIManager.Instance.GetLocalPPI();
            if (ppi != null)
            {
                ppi.Name = m_Nickname;
                PPIManager.Instance.NotifyLocalPPIChanged();
            }

            // connect to correct lobby
            LobbyClient.ConnectToLobby(m_Region);

            // inform user that we are done
            msgbox.SetText(TextDatabase.instance[0107020]);
            msgbox.SetHandler((popup, result) => { Owner.Back(); });
        }
        else
        {
            // inform user that there were a problem with updating
            msgbox.SetText(TextDatabase.instance[0107021]);
        }

        // let user press 'OK'
        msgbox.SetButtonText(TextDatabase.instance[0107024]);
        msgbox.SetButtonVisible(true);
    }