예제 #1
0
    protected override void InitComponents()
    {
        FindWidget <Text>("textAvatarname").text = URemoteData.AvatarName;
        FindWidget <Text>("textLevel").text      = URemoteData.AvatarLevel;

        expProgress  = FindWidget <Image>("expProgress");
        textExp      = FindWidget <Text>("textExp");
        textExp.text = "";

        inputAnswer = FindWidget <InputField>("inputAnswer");

        btnGetQuestion = FindWidget <Button>("btnGetQuestion");
        btnGetQuestion.onClick.AddListener(() =>
        {
            btnGetQuestion.gameObject.SetActive(false);
            UStaticWebRequests.OnWebRequest("Question/GetOne", "username="******"&token=" + UILogin.token, jobj =>
            {
                ShowWidget("question", true);
                FindWidget <Text>("textQuestion").text = jobj["q"].ToString();
            },
                                            jfail =>
            {
                ShowWidget("question", false);
                btnGetQuestion.gameObject.SetActive(true);
            });
        });

        ShowWidget("question", false);
        btnAnswer = FindWidget <Button>("btnAnswer");
        btnAnswer.onClick.AddListener(() =>
        {
            if (string.IsNullOrEmpty(inputAnswer.text))
            {
                return;
            }
            UStaticWebRequests.OnWebRequest("Question/Answer", "username="******"&token=" + UILogin.token + "&answer=" + inputAnswer.text, jobj =>
            {
                if (jobj.ContainsKey("avatar"))
                {
                    ShowWidget("question", false);
                    URemoteData.OnReceiveAvatarData(jobj["avatar"].ToString());
                    UIAlert.Show("回答正确!");
                    btnGetQuestion.gameObject.SetActive(true);
                }
                else
                {
                    UIAlert.Show("回答错误,再好好想想吧。");
                }
            },
                                            jfail =>
            {
                UIAlert.Show("回答错误,再好好想想吧。");
            });
        });

        URemoteData.ListeningParam(InfoNameDefs.CurExp, ShowCurExp);
        URemoteData.ListeningParam(InfoNameDefs.MaxExp, ShowCurExp);
        ShowCurExp();
    }
예제 #2
0
    protected override void InitComponents()
    {
        expProgress  = FindWidget <Image>("expProgress");
        textExp      = FindWidget <Text>("textExp");
        textExp.text = "";

        URemoteData.ListeningParam(InfoNameDefs.CurExp, ShowCurExp);
        URemoteData.ListeningParam(InfoNameDefs.MaxExp, ShowCurExp);

        RefreshUI();

        gameObj.AddComponent <UOnDestroy>().actionOnDestroy = () =>
        {
            URemoteData.CancelListeningParam(InfoNameDefs.CurExp, ShowCurExp);
            URemoteData.CancelListeningParam(InfoNameDefs.MaxExp, ShowCurExp);
        };
    }
예제 #3
0
    protected override void InitComponents()
    {
        mycard = FindWidget <RawImage>("mycard");
        mycard.gameObject.SetActive(false);
        var btn = mycard.gameObject.AddComponent <Button>();

        btn.onClick.AddListener(() =>
        {
            if (whosTurn != UILogin.CachedUsername)
            {
                UICommonTips.AddTip("还没轮到你出牌。");
                return;
            }
            mycard.color = Color.grey;
            WebSocketConnector.Instance.OnRemoteCall("roomOp", "");
        });
        othercard = FindWidget <RawImage>("othercard");
        othercard.gameObject.SetActive(false);
        var bgpath = new string[] { "Images/Pai/bg1", "Images/Pai/bg2" };

        UHotAssetBundleLoader.Instance.OnDownloadResources(() =>
        {
            mycard.texture    = UHotAssetBundleLoader.Instance.OnLoadAsset <Texture2D>(bgpath[random.Next(bgpath.Length)]);
            othercard.texture = UHotAssetBundleLoader.Instance.OnLoadAsset <Texture2D>(bgpath[random.Next(bgpath.Length)]);
        }, bgpath);

        textMyCardCount      = FindWidget <Text>("textMyCardCount");
        textMyCardCount.text = "0";

        textMyAvatarname      = FindWidget <Text>("textMyAvatarname");
        textMyAvatarname.text = URemoteData.AvatarName;

        textMyLevel = FindWidget <Text>("textMyLevel");
        ShowLevel();

        textOtherCardCount      = FindWidget <Text>("textOtherCardCount");
        textOtherCardCount.text = "0";

        textOtherLevel      = FindWidget <Text>("textOtherLevel");
        textOtherAvatarname = FindWidget <Text>("textOtherAvatarname");

        RegisterReturnButton();

        btnJoinRoom = FindWidget <Button>("btnJoinRoom");
        btnJoinRoom.onClick.AddListener(() =>
        {
            WebSocketConnector.Instance.OnRemoteCall("joinRoom", "老牛赶大车");
        });

        cardcell = FindWidget <Transform>("cardcell");
        cardcell.gameObject.SetActive(false);

        otherinfo = FindWidget <Transform>("otherinfo");
        otherinfo.gameObject.SetActive(false);
        URemoteData.ListeningParam(InfoNameDefs.AvatarLevel, ShowLevel);

        UICommonWait.Show();
        WebSocketConnector.Instance.OnInit(Utils.WebSocketURL + UILogin.CachedUsernameAndTokenArguments, evt =>
        {
            UICommonWait.Hide();
        }, msgEvt =>
        {
        }, errEvt =>
        {
        }, closeEvt =>
        {
        });

        WebSocketConnector.Instance.OnRegisterResponse("enter", OnJoinRoomCB);
        WebSocketConnector.Instance.OnRegisterResponse("cardsync", OnCardsSync);
        WebSocketConnector.Instance.OnRegisterResponse("result", OnResult);
        WebSocketConnector.Instance.OnRegisterResponse("dismissed", OnDismissed);
    }
예제 #4
0
    protected override void InitComponents()
    {
        Cave0 = FindWidget <Transform>("Cave0");
        var actionHandler = new ActionHandler(Cave0.gameObject);

        actionHandler.AddAction(new ActionRun(actionHandler.handler));
        addUpdateAction(() =>
        {
            if (Input.GetMouseButtonDown(0))
            {
                actionHandler.Do <ActionRun>().Play();
            }
            if (Input.GetMouseButtonUp(0))
            {
                actionHandler.Do <ActionRun>().Stop();
            }
            return(false);
        });

        var tr = FindWidget <Transform>("expBg");

        expSlider = new WExpSlider();
        expSlider.SetGameObj(tr.gameObject);

        FindWidget <Text>("textAvatarname").text = URemoteData.AvatarName;
        ShowLevel();

        inputAnswer = FindWidget <InputField>("inputAnswer");

        btnReturn = FindWidget <Button>("btnReturn");
        btnReturn.onClick.AddListener(() =>
        {
            OnUnloadThis();

            LoadAnotherUI <UIMain>();
        });

        btnGetQuestion = FindWidget <Button>("btnGetQuestion");
        btnGetQuestion.onClick.AddListener(() =>
        {
            btnGetQuestion.gameObject.SetActive(false);
            UStaticWebRequests.OnWebRequest("Question/GetOne", "username="******"&token=" + UILogin.token, jobj =>
            {
                ShowWidget("question", true);
                FindWidget <Text>("textQuestion").text = jobj["q"].ToString();
            },
                                            jfail =>
            {
                ShowWidget("question", false);
                btnGetQuestion.gameObject.SetActive(true);
            });
        });

        ShowWidget("question", false);
        btnAnswer = FindWidget <Button>("btnAnswer");
        btnAnswer.onClick.AddListener(() =>
        {
            if (string.IsNullOrEmpty(inputAnswer.text))
            {
                return;
            }
            UStaticWebRequests.OnWebRequest("Question/Answer", "username="******"&token=" + UILogin.token + "&answer=" + inputAnswer.text, jobj =>
            {
                if (jobj.ContainsKey("avatar"))
                {
                    ShowWidget("question", false);
                    URemoteData.OnReceiveAvatarData(jobj["avatar"].ToString());
                    UIAlert.Show("回答正确!");
                    btnGetQuestion.gameObject.SetActive(true);
                }
                else
                {
                    UIAlert.Show("回答错误,再好好想想吧。");
                }
            },
                                            jfail =>
            {
                UIAlert.Show("回答错误,再好好想想吧。");
            });
        });


        URemoteData.ListeningParam(InfoNameDefs.AvatarLevel, ShowLevel);
    }
예제 #5
0
    protected override void InitComponents()
    {
        var textUsername = FindWidget <Text>("textUsername");

        textUsername.text = URemoteData.AvatarName;
        textGold          = FindWidget <Text>("textGold");
        RefreshGold();

        var menuCell = FindWidget <Button>("menuCell");

        menuCell.gameObject.SetActive(false);

        var btnRank = FindWidget <Button>("btnRank");

        btnRank.onClick.AddListener(() =>
        {
            LoadAnotherUI <UIRank>();
        });

        var btnCheck = FindWidget <Button>("btnCheck");

        btnCheck.onClick.AddListener(() =>
        {
            UStaticWebRequests.OnWebRequest("Avatar/DailyCheck", $"username={UILogin.CachedUsername}&token={UILogin.token}", jobj =>
            {
                URemoteData.OnReceiveAvatarData(jobj["avatar"]);
            });
        });

        var btnLogout = FindWidget <Button>("btnLogout");

        btnLogout.onClick.AddListener(() =>
        {
            UStaticWebRequests.DoLogout(UILogin.CachedUsername, UILogin.token
                                        , (jres) =>
            {
                OnUnloadThis();
                LoadAnotherUI <UILogin>();
            }, (err) =>
            {
                UIAlert.Show("注销失败:" + Utils.ErrorFormat(err));
            }, (err) =>
            {
                UIAlert.Show("web error:" + err);
            });
        });

        foreach (var g in dGames)
        {
            var menu = GameObject.Instantiate(menuCell, menuCell.transform.parent);
            menu.gameObject.SetActive(true);
            menu.GetComponentInChildren <Text>().text = g.Key;
            menu.onClick.AddListener(() =>
            {
                OnUnloadThis();
                g.Value();
            });
        }

        URemoteData.ListeningParam(InfoNameDefs.AvatarGold, RefreshGold);
    }
예제 #6
0
    protected override void InitComponents()
    {
        textAvatarname      = FindWidget <Text>("textAvatarname");
        textAvatarname.text = URemoteData.AvatarName;

        textGold = FindWidget <Text>("textGold");
        ShowGold();

        btnReturn = FindWidget <Button>("btnReturn");
        btnReturn.onClick.AddListener((UnityEngine.Events.UnityAction)(() =>
        {
            base.OnUnloadThis();

            AHotBase.LoadUI <UIMain>();
        }));

        var bbig       = false;
        var bsmall     = false;
        var bigorsmall = FindWidget <Transform>("bigorsmall");
        var big        = FindWidget <Toggle>(bigorsmall.transform, "big");

        big.onValueChanged.AddListener(value => { bbig = value; });
        var small = FindWidget <Toggle>(bigorsmall.transform, "small");

        small.onValueChanged.AddListener(value => { bsmall = value; });

        var multis   = FindWidget <Transform>("multis");
        var curMulti = 0;

        foreach (var w in ClientValueDefs.CaiDaXiaoMultis)
        {
            var t  = FindWidget <Toggle>(multis, $"m{w}");
            var tw = w;
            t.onValueChanged.AddListener((value) =>
            {
                if (value)
                {
                    curMulti = tw;
                }
                else if (curMulti == tw)
                {
                    curMulti = 0;
                }
            });
        }

        var btnConfirm = FindWidget <Button>("btnConfirm");

        btnConfirm.onClick.AddListener(() =>
        {
            if (!bbig && !bsmall)
            {
                return;
            }
            if (curMulti == 0)
            {
                return;
            }
            UStaticWebRequests.OnWebRequest("Avatar/CaiDaXiao", $"{UILogin.CachedUsernameAndTokenArguments}&multi={curMulti}&isBig={(bbig ? "1" : "0")}", jobj =>
            {
                var res = jobj["res"].ToString();
                UIAlert.Show($"猜大小结果:{res}");
            });
        });

        URemoteData.ListeningParam(InfoNameDefs.AvatarGold, ShowGold);
    }