Exemplo n.º 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();
    }
Exemplo n.º 2
0
    private void OnGetTop(int curTopIndex)
    {
        textTitle.text = topsTitle[curTopIndex];
        foreach (var lc in lCells)
        {
            GameObject.Destroy(lc.gameObject);
        }
        lCells.Clear();

        UStaticWebRequests.OnWebRequest("Rank/" + tops[curTopIndex], "count=10", res =>
        {
            var jarray = res["r"] as JArray;
            foreach (var ja in jarray)
            {
                var obj = GameObject.Instantiate(rankcell, rankcell.parent);
                lCells.Add(obj);
                obj.gameObject.SetActive(true);

                FindWidget <Text>(obj, "avatarName").text  = ja["name"].ToString();
                FindWidget <Text>(obj, "avatarValue").text = ja["value"].ToString();
                FindWidget <Text>(obj, "textRankTag").text = topsRankTag[curTopIndex];
            }
        });
    }
Exemplo n.º 3
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);
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    protected override void InitComponents()
    {
        var inputUsername = FindWidget <InputField>("inputUsername");

        if (!string.IsNullOrEmpty(CachedUsername))
        {
            inputUsername.text = CachedUsername;
        }

        var inputPassword = FindWidget <InputField>("inputPassword");
        var btnLogin      = FindWidget <Button>("btnLogin");

        btnLogin.onClick.AddListener(() =>
        {
            if (string.IsNullOrEmpty(inputUsername.text))
            {
                return;
            }
            if (string.IsNullOrEmpty(inputPassword.text))
            {
                return;
            }
            btnLogin.enabled = false;
            var username     = inputUsername.text;
            var password     = inputPassword.text;

            UStaticWebRequests.DoLogin(username, Utils.MD5Hash(password),
                                       (jres) =>
            {
                btnLogin.enabled = true;
                CachedUsername   = username;
                token            = jres["token"].ToString();

                OnSelectAvatar();
            }
                                       , (err) =>
            {
                btnLogin.enabled = true;
                UIAlert.Show("登录失败," + err);
            }
                                       , (error) =>
            {
                btnLogin.enabled = true;
                UIAlert.Show("登录失败,网络错误:" + error);
            });
        });
        var btnRegister = FindWidget <Button>("btnRegister");

        btnRegister.onClick.AddListener(() =>
        {
            OnUnloadThis();

            LoadAnotherUI <UIRegister>();
        });

        if (!string.IsNullOrEmpty(token))
        {
            inputPassword.text = "******";
            btnLogin.enabled   = false;
            UStaticWebRequests.OnWebRequest("Login/CheckToken", "username="******"&token=" + token, jobj =>
            {
                OnSelectAvatar();
            },
                                            jfail =>
            {
                btnLogin.enabled   = true;
                inputPassword.text = "";
                token = "";
            });
        }
    }
Exemplo n.º 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);
    }
Exemplo n.º 7
0
    protected override void InitComponents()
    {
        UICommonWait.Show();
        Task.Run(async() =>
        {
            if (!LibClient.AClientApp.bConnected)
            {
                await LibClient.AClientApp.StartClient();
            }
            UWebSender.Instance.AddProducingAction(() =>
            {
                UICommonWait.Hide();
            });
        });

        inputUsername = FindWidget <InputField>("inputUsername");
        if (!string.IsNullOrEmpty(CachedUsername))
        {
            inputUsername.text = CachedUsername;
        }

        inputPassword = FindWidget <InputField>("inputPassword");
        var btnLogin = FindWidget <Button>("btnLogin");

        btnLogin.onClick.AddListener(() =>
        {
            Task.Run(async() =>
            {
                if (!LibClient.AClientApp.bConnected)
                {
                    await LibClient.AClientApp.StartClient();
                }

                if (!LibClient.AClientApp.bConnected)
                {
                    AOutput.Log($"连接失败!");
                    return;
                }

                UWebSender.Instance.AddProducingAction(OnLogin);
            });
            btnLogin.enabled = false;
        });
        var btnRegister = FindWidget <Button>("btnRegister");

        btnRegister.onClick.AddListener(() =>
        {
            OnUnloadThis();

            LoadAnotherUI <UIRegister>();
        });

        if (!string.IsNullOrEmpty(token))
        {
            inputPassword.text = "******";
            btnLogin.enabled   = false;
            UStaticWebRequests.OnWebRequest("Login/CheckToken", "username="******"&token=" + token, jobj =>
            {
                OnSelectAvatar();
            },
                                            jfail =>
            {
                btnLogin.enabled   = true;
                inputPassword.text = "";
                token = "";
            });
        }
    }