Beispiel #1
0
        public static bool ConfirmSaveLoadPatch_pagination(ref CtrlSaveLoad __instance)
        {
            Heluo.Logger.LogError("ConfirmSaveLoadPatch_pagination start");
            UISaveLoad view = Traverse.Create(__instance).Field("view").GetValue <UISaveLoad>();

            int saveIndex = Traverse.Create(__instance).Field("saveIndex").GetValue <int>();
            //获取存读档文件时需要转换成真实index
            int trueSaveIndex = saveIndex;

            if (pagination.Value)
            {
                trueSaveIndex += (currentPage - 1) * countPerPage.Value;
            }
            //存档
            if (__instance.isSave)
            {
                string filename = string.Format("PathOfWuxia_{0:00}.{1}", trueSaveIndex, "save");
                view.HideBlur();
                Game.SaveAsync(filename, new Action(__instance.OnSaveFinish));
                view.ShowBlur();
                Heluo.Logger.LogError("ConfirmSaveLoadPatch_pagination end");
                return(false);
            }
            Game.UI.HideTeamMemeberUI();
            Game.UI.Open <UILoading>();
            int categoryIndex = Traverse.Create(__instance).Field("categoryIndex").GetValue <int>();

            //读档
            if (categoryIndex == 0)
            {
                List <PathOfWuxiaSaveHeader> saves = Traverse.Create(__instance).Field("saves").GetValue <List <PathOfWuxiaSaveHeader> >();
                if (!saves[saveIndex].HasData)
                {
                    return(false);
                }
                Game.LoadAsync(string.Format("PathOfWuxia_{0:00}.{1}", trueSaveIndex, "save"), null);
                view.Hide();
                Heluo.Logger.LogError("ConfirmSaveLoadPatch_pagination end");
                return(false);
            }
            //读自动存档
            else
            {
                List <PathOfWuxiaSaveHeader> autosaves = Traverse.Create(__instance).Field("autosaves").GetValue <List <PathOfWuxiaSaveHeader> >();
                if (!autosaves[saveIndex].HasData)
                {
                    return(false);
                }
                Game.LoadAsync(string.Format("PathOfWuxia_{0:00}.{1}", trueSaveIndex, "autosave"), null);
                view.Hide();
                Heluo.Logger.LogError("ConfirmSaveLoadPatch_pagination end");
                return(false);
            }
        }
Beispiel #2
0
        public static void showPatch_pagination(ref UISaveLoad __instance)
        {
            Heluo.Logger.LogError("showPatch_pagination start");
            //创建主挂载对象,这个对象是不会删除的
            GameObject  obj;
            WGTabScroll saveload = Traverse.Create(__instance).Field("saveload").GetValue <WGTabScroll>();
            var         trans    = saveload.transform.Find("pageBar");

            if (trans == null)
            {
                GameObject pageBar = new GameObject("pageBar");
                Image      bg      = pageBar.AddComponent <Image>();
                bg.sprite = Game.Resource.Load <Sprite>("Image/UI/UICharacter/Info_HotKey_bg.png");

                HorizontalLayoutGroup layout = pageBar.AddComponent <HorizontalLayoutGroup>();
                layout.childControlHeight     = true;
                layout.childControlWidth      = true;
                layout.childForceExpandHeight = true;
                layout.childForceExpandWidth  = true;

                pageBar.transform.SetParent(saveload.transform, false);
                pageBar.transform.position = new Vector3(pageBar.transform.position.x, pageBar.transform.position.y - Screen.height / 2 + 50, 0);
                pageBar.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, 100);

                //controller:刷新用
                CtrlSaveLoad controller = Traverse.Create(__instance).Field("controller").GetValue <CtrlSaveLoad>();
                obj = createPageBar(pageBar, controller);
            }
            else
            {
                obj = trans.gameObject;
            }
            if (pagination.Value)
            {
                obj.SetActive(true);
            }
            else
            {
                obj.SetActive(false);
            }
            Heluo.Logger.LogError("showPatch_pagination end");
        }
Beispiel #3
0
        //页码按钮事件
        public static void pageClick(GameObject pageBar, CtrlSaveLoad controller, int page)
        {
            Heluo.Logger.LogError("pageClick start");
            //获得当前页码
            if (page < 1)
            {
                page = 1;
            }
            if (page > totalPage)
            {
                page = totalPage;
            }
            Text[] texts = pageBar.GetComponentsInChildren <Text>();
            for (int i = 0; i < texts.Length; i++)
            {
                Text text = texts[i];

                if (text.text.Equals(page + ""))
                {
                    currentPage = page;
                    break;
                }
            }
            //每次点击都重新创建分页栏
            createPageBar(pageBar, controller);

            //然后更新saves和autosaves
            Traverse.Create(controller).Field("saves").SetValue(Game.Platform.ListSaveHeaderFile(GameSaveType.Manual));
            Traverse.Create(controller).Field("autosaves").SetValue(Game.Platform.ListSaveHeaderFile(GameSaveType.Auto));

            //刷新页面
            UISaveLoad view = Traverse.Create(controller).Field("view").GetValue <UISaveLoad>();

            view.UpdateSaveLoad(countPerPage.Value, true, true);

            Heluo.Logger.LogError("pageClick end");
        }
Beispiel #4
0
        //创建分页栏
        public static GameObject createPageBar(GameObject pageBar, CtrlSaveLoad controller)
        {
            Heluo.Logger.LogError("createPageBar start");
            //每次更新都销毁所有页码按钮,重新创建
            for (int i = 0; i < pageBar.transform.childCount; i++)
            {
                UnityEngine.Object.Destroy(pageBar.transform.GetChild(i).gameObject);
            }
            //左侧的<<和<按钮
            GameObject            leftBar    = new GameObject("leftBar");
            HorizontalLayoutGroup leftLayout = leftBar.AddComponent <HorizontalLayoutGroup>();

            leftLayout.childControlHeight     = true;
            leftLayout.childControlWidth      = true;
            leftLayout.childForceExpandHeight = true;
            leftLayout.childForceExpandWidth  = true;

            GameObject firstPage = createPageButton("firstPage", "<<");

            firstPage.AddComponent <Button>().onClick.AddListener(() => pageClick(pageBar, controller, 1));
            firstPage.transform.SetParent(leftBar.transform, false);

            GameObject previousPage = createPageButton("previousPage", "<");

            previousPage.AddComponent <Button>().onClick.AddListener(() => pageClick(pageBar, controller, currentPage - 1));
            previousPage.transform.SetParent(leftBar.transform, false);

            leftBar.GetComponent <RectTransform>().sizeDelta = new Vector2(200, 100);
            leftBar.transform.SetParent(pageBar.transform, false);

            //中间的数字页码按钮
            GameObject            middleBar    = new GameObject("leftBar");
            HorizontalLayoutGroup middleLayout = middleBar.AddComponent <HorizontalLayoutGroup>();

            middleLayout.childControlHeight     = true;
            middleLayout.childControlWidth      = true;
            middleLayout.childForceExpandHeight = true;
            middleLayout.childForceExpandWidth  = true;
            middleBar.GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width - 400, 100);
            middleBar.transform.SetParent(pageBar.transform, false);

            totalPage = (int)Math.Ceiling((float)saveCount.Value / countPerPage.Value);
            //仅展示第1页,最后1页,当前页的±3页,其余省略为…
            for (int i = 1; i <= totalPage; i++)
            {
                if (i != 1 && i < currentPage - 3)
                {
                    GameObject pointPage = createPageButton("page", "…");
                    pointPage.transform.SetParent(middleBar.transform, false);
                    i = currentPage - 4;
                }

                GameObject page = createPageButton(i + "page", i + "");
                page.AddComponent <Button>().onClick.AddListener(() => pageClick(pageBar, controller, int.Parse(page.GetComponent <Text>().text)));
                if (i == currentPage)
                {
                    page.GetComponentInChildren <Text>().color = Color.red;                   //当前页标红
                }
                page.transform.SetParent(middleBar.transform, false);

                if (i != totalPage && i > currentPage + 3)
                {
                    GameObject pointPage = createPageButton("page", "…");
                    pointPage.transform.SetParent(middleBar.transform, false);
                    i = totalPage - 1;
                }
            }

            //右侧的>和>>按钮
            GameObject            rightBar    = new GameObject("rightBar");
            HorizontalLayoutGroup rightLayout = rightBar.AddComponent <HorizontalLayoutGroup>();

            rightLayout.childControlHeight     = true;
            rightLayout.childControlWidth      = true;
            rightLayout.childForceExpandHeight = true;
            rightLayout.childForceExpandWidth  = true;
            rightBar.GetComponent <RectTransform>().sizeDelta = new Vector2(200, 100);
            rightBar.transform.SetParent(pageBar.transform, false);

            GameObject nextPage = createPageButton("nextPage", ">");

            nextPage.AddComponent <Button>().onClick.AddListener(() => pageClick(pageBar, controller, currentPage + 1));
            nextPage.transform.SetParent(rightBar.transform, false);

            GameObject lastPage = createPageButton("lastPage", ">>");

            lastPage.AddComponent <Button>().onClick.AddListener(() => pageClick(pageBar, controller, totalPage));
            lastPage.transform.SetParent(rightBar.transform, false);

            Heluo.Logger.LogError("createPageBar end");
            return(pageBar);
        }
Beispiel #5
0
        public static void UpdateSaveLoadPatch_jumpToLatestSave(ref CtrlSaveLoad __instance)
        {
            Heluo.Logger.LogError("UpdateSaveLoadPatch_jumpToLatestSave start");
            //每次进来先置1,防止中途关闭分页功能后仍然停留在后续页面
            currentPage = 1;
            if (jumpToLatestSave.Value)
            {
                //判断是存档还是自动存档
                int categoryIndex = Traverse.Create(__instance).Field("categoryIndex").GetValue <int>();

                //先暂时取消分页,获取所有存档,以找到最新的一条,然后恢复
                bool paginationTemp = pagination.Value;
                pagination.Value = false;
                List <PathOfWuxiaSaveHeader> saves;
                if (categoryIndex == 0)
                {
                    saves = Game.Platform.ListSaveHeaderFile(GameSaveType.Manual);
                }
                else
                {
                    saves = Game.Platform.ListSaveHeaderFile(GameSaveType.Auto);
                }
                pagination.Value = paginationTemp;

                //获取最新存档的index
                int      num      = -1;
                DateTime saveTime = new DateTime(100L);

                for (int i = 0; i < saves.Count; i++)
                {
                    PathOfWuxiaSaveHeader pathOfWuxiaSaveHeader = saves[i];
                    if (!pathOfWuxiaSaveHeader.HasData)
                    {
                        continue;
                    }
                    if (DateTime.Compare(pathOfWuxiaSaveHeader.SaveTime, saveTime) > 0)
                    {
                        num      = i;
                        saveTime = pathOfWuxiaSaveHeader.SaveTime;
                    }
                }
                int currentIndex = num;
                int totalIndex   = saveCount.Value;

                //重新给saves和autosaves赋值
                if (pagination.Value)
                {
                    currentPage = (num / countPerPage.Value) + 1;

                    //如果是最后一页,有可能出现存档数不足一页的情况,所以以总数量-前面几页的数量计算
                    if (currentPage == totalPage)
                    {
                        totalIndex = saveCount.Value - (currentPage - 1) * countPerPage.Value;
                    }
                    else
                    {
                        totalIndex = countPerPage.Value;
                    }

                    currentIndex = num % countPerPage.Value;
                }
                Traverse.Create(__instance).Field("saves").SetValue(Game.Platform.ListSaveHeaderFile(GameSaveType.Manual));
                Traverse.Create(__instance).Field("autosaves").SetValue(Game.Platform.ListSaveHeaderFile(GameSaveType.Auto));

                //更新界面
                UISaveLoad view = Traverse.Create(__instance).Field("view").GetValue <UISaveLoad>();
                view.UpdateSaveLoad(totalIndex, true, true);

                //更新分页栏
                WGTabScroll saveload = Traverse.Create(view).Field("saveload").GetValue <WGTabScroll>();
                GameObject  pageBar  = saveload.transform.Find("pageBar").gameObject;
                createPageBar(pageBar, __instance);

                //更新滚动条位置
                WGInfiniteScroll loopScroll = Traverse.Create(saveload).Field("loopScroll").GetValue <WGInfiniteScroll>();
                ScrollRect       scrollRect = Traverse.Create(loopScroll).Field("scrollRect").GetValue <ScrollRect>();
                scrollRect.verticalScrollbar.value = ((float)(totalIndex - currentIndex - 1)) / (totalIndex - 1);              //滑动条是反的,不知道为什么
            }
            Heluo.Logger.LogError("UpdateSaveLoadPatch_jumpToLatestSave end");
        }