예제 #1
0
        public void InsertOneNormalServerItem(GameObject parent, GameObject obj, ServerInfo serverInfo)
        {
            GameObject item = GameObject.Instantiate(obj);

            item.SetActive(true);
            item.name = "Server_" + serverInfo.ServerId;
            Transform itemTrans = item.transform;

            itemTrans.SetParent(parent.transform);
            itemTrans.localScale    = Vector3.one;
            itemTrans.localPosition = Vector3.zero;

            // 名字
            Text nameText = itemTrans.Find("NameText").GetComponent <Text>();

            nameText.text = serverInfo.Name;

            // 状态
            Image stateImage = itemTrans.Find("StateImage").GetComponent <Image>();

            stateImage.sprite = GetSpriteByState(serverInfo.State);

            // 类型
            GameObject tag = itemTrans.Find("Tag").gameObject;

            if (serverInfo.Type == EServerType.New || serverInfo.Type == EServerType.RecommendAndNew)
            {
                tag.SetActive(true);
            }
            else
            {
                tag.SetActive(false);
            }

            // 角色数量
            Text roleNumText = itemTrans.Find("Role").Find("Text").GetComponent <Text>();

            if (serverInfo.RoleList == null || serverInfo.RoleList.Count == 0)
            {
                roleNumText.text = "x0";
                roleNumText.transform.parent.gameObject.SetActive(false);
            }
            else
            {
                roleNumText.text = "x" + serverInfo.RoleList.Count;
                roleNumText.transform.parent.gameObject.SetActive(true);
            }

            // cd
            Text cdText = itemTrans.Find("CDText").GetComponent <Text>();

            if ((serverInfo.State == EServerState.WillOpen || serverInfo.State == EServerState.Maintaining) && serverInfo.CountDownTime > 0)
            {
                cdText.gameObject.SetActive(true);

                Utils.DecimalTimer timer = new Utils.DecimalTimer((decimal)(serverInfo.CountDownTime) * 1000, false, 1000, (decimal remainTime, Utils.DecimalTimer t) =>
                {
                    if (remainTime <= 0)
                    {
                        cdText.text = "";
                        // 维护倒计时完毕就默认为畅通吧
                        stateImage.sprite = GetSpriteByState(EServerState.Smooth);

                        t.Destroy();
                        mMaintainingServerTimers.Remove(t);
                    }
                    else
                    {
                        cdText.text = DBConstText.GetText("MAINTAINING_REMAIN_TIME") + TimeTraslateHMS.GetFMTTime(remainTime);
                    }
                }, null);
                mMaintainingServerTimers.Add(timer);
            }
            else
            {
                cdText.gameObject.SetActive(false);
            }

            // 按钮
            Button button = itemTrans.GetComponent <Button>();

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() =>
            {
                if (ServerListHelper.Instance.CheckServerState(serverInfo, false) == true)
                {
                    SetSelectedServerInfo(serverInfo);
                    OnClickCloseServerListPanelButton();
                }
                else
                {
                    ServerListHelper.GetInstance().CheckServerStateAndEnter(serverInfo, (ServerInfo retServerInfo, bool canEnter) =>
                    {
                        if (canEnter == true)
                        {
                            SetSelectedServerInfo(serverInfo);
                            OnClickCloseServerListPanelButton();
                        }
                        else
                        {
                            ServerListHelper.Instance.CheckServerState(serverInfo, false);

                            // 推荐别的服务器需要关闭服务器列表界面
                            if (serverInfo != null && serverInfo.State == EServerState.NotRecomm)
                            {
                                OnClickCloseServerListPanelButton();
                            }
                        }
                    }, false);
                }
            });
        }
예제 #2
0
        public void InsertOneWillOpenServerItem(ServerInfo serverInfo)
        {
            GameObject item = GameObject.Instantiate(mWillOpenServerItem);

            item.SetActive(true);
            item.name = "Server_" + serverInfo.ServerId;
            Transform itemTrans = item.transform;

            itemTrans.SetParent(mWillOpenServerListContent.transform);
            itemTrans.localScale    = Vector3.one;
            itemTrans.localPosition = Vector3.zero;

            // 名字
            Text nameText = itemTrans.Find("NameText").GetComponent <Text>();

            nameText.text = serverInfo.Name;

            // 时间
            Text timeText = itemTrans.Find("TimeText").GetComponent <Text>();

            if (serverInfo.CountDownTime > 0)
            {
                Utils.DecimalTimer timer = new Utils.DecimalTimer((decimal)(serverInfo.CountDownTime) * 1000, false, 1000, (decimal remainTime, Utils.DecimalTimer t) =>
                {
                    if (remainTime <= 0)
                    {
                        timeText.text = "";
                        t.Destroy();
                        mMaintainingServerTimers.Remove(t);

                        GameObject.DestroyImmediate(item);
                    }
                    else
                    {
                        timeText.text = DBConstText.GetText("MAINTAINING_REMAIN_TIME") + TimeTraslateHMS.GetFMTTime(remainTime);
                    }
                }, null);
                mMaintainingServerTimers.Add(timer);
            }
            else
            {
                timeText.text = "";
            }

            // 状态
            Image stateImage = itemTrans.Find("StateImage").GetComponent <Image>();

            stateImage.sprite = GetSpriteByState(serverInfo.State);

            // 按钮
            Button button = itemTrans.GetComponent <Button>();

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() =>
            {
                if (ServerListHelper.Instance.CheckServerState(serverInfo, false) == true)
                {
                    SetSelectedServerInfo(serverInfo);
                    OnClickCloseServerListPanelButton();
                }
                else
                {
                    ServerListHelper.GetInstance().CheckServerStateAndEnter(serverInfo, (ServerInfo retServerInfo, bool canEnter) =>
                    {
                        if (canEnter == true)
                        {
                            SetSelectedServerInfo(serverInfo);
                            OnClickCloseServerListPanelButton();
                        }
                        else
                        {
                            ServerListHelper.Instance.CheckServerState(serverInfo, false);

                            // 推荐别的服务器需要关闭服务器列表界面
                            if (serverInfo != null && serverInfo.State == EServerState.NotRecomm)
                            {
                                OnClickCloseServerListPanelButton();
                            }
                        }
                    }, false);
                }
            });
        }