Пример #1
0
        private bool OnHelpHotkey(KeyCombination key)
        {
            if (dialog.IsOpened())
            {
                dialog.TryClose();
            }
            else
            {
                dialog.TryOpen();
                // dunno why
                dialog.ignoreNextKeyPress = true;

                if (capi.World.Player.InventoryManager.CurrentHoveredSlot?.Itemstack != null)
                {
                    ItemStack stack    = capi.World.Player.InventoryManager.CurrentHoveredSlot.Itemstack;
                    string    pageCode = GuiHandbookItemStackPage.PageCodeForStack(stack);

                    if (!dialog.OpenDetailPageFor(pageCode))
                    {
                        dialog.OpenDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(new ItemStack(stack.Collectible)));
                    }
                }

                if (capi.World.Player.Entity.Controls.Sneak && capi.World.Player.CurrentBlockSelection != null)
                {
                    BlockPos  pos   = capi.World.Player.CurrentBlockSelection.Position;
                    ItemStack stack = capi.World.BlockAccessor.GetBlock(pos).OnPickBlock(capi.World, pos);

                    string pageCode = GuiHandbookItemStackPage.PageCodeForStack(stack);

                    if (!dialog.OpenDetailPageFor(pageCode))
                    {
                        dialog.OpenDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(new ItemStack(stack.Collectible)));
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public void InitStackCacheAndStacks()
        {
            List <ItemStack> allstacks = new List <ItemStack>();

            //HashSet<AssetLocation> groupedBlocks = new HashSet<AssetLocation>();
            //HashSet<AssetLocation> groupedItems = new HashSet<AssetLocation>();
            //Dictionary<string, GuiHandbookGroupedItemstackPage> groupedPages = new Dictionary<string, GuiHandbookGroupedItemstackPage>();


            foreach (CollectibleObject obj in capi.World.Collectibles)
            {
                List <ItemStack> stacks = obj.GetHandBookStacks(capi);
                if (stacks == null)
                {
                    continue;
                }


                //string[] groups = obj.Attributes?["handbook"]?["groupBy"]?.AsStringArray(null);
                //string[] groupednames = obj.Attributes?["handbook"]?["groupedName"]?.AsStringArray(null);

                foreach (ItemStack stack in stacks)
                {
                    allstacks.Add(stack);

                    /*if (groups != null && groupednames != null) - don't know how to do this right. The detail page also kind of needs to be a slideshow or multi-page thing? meh. :/
                     * {
                     *  bool alreadyAdded = stack.Class == EnumItemClass.Block ? groupedBlocks.Contains(stack.Collectible.Code) : groupedItems.Contains(stack.Collectible.Code);
                     *
                     *  if (!alreadyAdded)
                     *  {
                     *      GroupedHandbookStacklistElement elem;
                     *      if (groupedPages.TryGetValue(stack.Class + "-" + groups[0], out elem))
                     *      {
                     *          elem.Stacks.Add(stack);
                     *          pageNumberByPageCode[HandbookStacklistElement.PageCodeForCollectible(stack.Collectible)] = elem.PageNumber;
                     *      } else
                     *      {
                     *
                     *          elem = new GroupedHandbookStacklistElement()
                     *          {
                     *              TextCache = groupednames == null || groupednames.Length == 0 ? stack.GetName() : Lang.Get(groupednames[0]),
                     *              Name = groupednames == null || groupednames.Length == 0 ? stack.GetName() : Lang.Get(groupednames[0]),
                     *              Visible = true
                     *          };
                     *
                     *          elem.Stacks.Add(stack);
                     *
                     *          listElements.Add(elem);
                     *          pageNumberByPageCode[HandbookStacklistElement.PageCodeForCollectible(stack.Collectible)] = elem.PageNumber = listElements.Count - 1;
                     *          listedListElements.Add(elem);
                     *
                     *          groupedPages[stack.Class +"-"+ groups[0]] = elem;
                     *      }
                     *
                     *      if (stack.Class == EnumItemClass.Block)
                     *      {
                     *          groupedBlocks.Add(stack.Collectible.Code);
                     *      } else
                     *      {
                     *          groupedItems.Add(stack.Collectible.Code);
                     *      }
                     *  }
                     * }
                     * else*/
                    {
                        GuiHandbookItemStackPage elem = new GuiHandbookItemStackPage(capi, stack)
                        {
                            Visible = true
                        };

                        allHandbookPages.Add(elem);
                        pageNumberByPageCode[elem.PageCode] = elem.PageNumber = allHandbookPages.Count - 1;
                    }
                }
            }

            this.allstacks = allstacks.ToArray();
        }