Example #1
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");
        }
Example #2
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");
        }