Ejemplo n.º 1
0
 public static Item getItemFromObject(object o)
 {
     if (o == null)
     {
         return(null);
     }
     if (o is string)
     {
         return(ARareItemSwapJPANs.getItemFromTag(o as string));
     }
     else if (o is Item)
     {
         return(o as Item);
     }
     else if (o is ModItem)
     {
         return((o as ModItem).item);
     }
     else if (o is int)
     {
         Item itm = new Item();
         itm.SetDefaults((int)o);
         return(itm);
     }
     return(null);
 }
Ejemplo n.º 2
0
 public override int CompareTo(object obj)
 {
     if (obj == null || obj as PartItemSlot == null)
     {
         return(1);
     }
     return(ARareItemSwapJPANs.getItemFromTag(partTag).Name.CompareTo(ARareItemSwapJPANs.getItemFromTag((obj as PartItemSlot).partTag).Name));
 }
Ejemplo n.º 3
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (item == null)
            {
                item = ARareItemSwapJPANs.getItemFromTag(partTag);
            }

            if (amountIsPlayerTotal)
            {
                amount = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>().getPartAmount(partTag);
            }

            if (item != null && !item.IsAir)
            {
                long total = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>().getPartAmount(partTag);
                if (IsMouseHovering)
                {
                    whileMouseHovering();
                    total              = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>().getPartAmount(partTag);
                    Main.HoverItem     = item.Clone();
                    Main.hoverItemName = item.Name + " (" + total + ")";
                }

                CalculatedStyle dimensions  = base.GetInnerDimensions();
                Rectangle       rectangle   = dimensions.ToRectangle();
                Texture2D       itemTexture = Main.itemTexture[this.item.type];
                Rectangle       rectangle2;
                if (Main.itemAnimations[item.type] != null)
                {
                    rectangle2 = Main.itemAnimations[item.type].GetFrame(itemTexture);
                }
                else
                {
                    rectangle2 = itemTexture.Frame(1, 1, 0, 0);
                }

                Color newColor   = Color.White;
                float pulseScale = 1f;
                ItemSlot.GetItemLight(ref newColor, ref pulseScale, item, false);
                int   height         = rectangle2.Height;
                int   width          = rectangle2.Width;
                float drawScale      = 1f;
                float availableWidth = (float)Main.inventoryBack9Texture.Width * scale;
                if (width > availableWidth || height > availableWidth)
                {
                    if (width > height)
                    {
                        drawScale = availableWidth / width;
                    }
                    else
                    {
                        drawScale = availableWidth / height;
                    }
                }
                drawScale *= scale;
                Vector2 vector    = Main.inventoryBack9Texture.Size() * scale;
                Vector2 position2 = dimensions.Position() + vector / 2f - rectangle2.Size() * drawScale / 2f;
                Vector2 origin    = rectangle2.Size() * (pulseScale / 2f - 0.5f);

                if (ItemLoader.PreDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
                                                  item.GetColor(Color.White), origin, drawScale * pulseScale))
                {
                    spriteBatch.Draw(itemTexture, position2, new Rectangle?(rectangle2), item.GetAlpha(newColor), 0f, origin, drawScale * pulseScale, SpriteEffects.None, 0f);
                    if (item.color != Color.Transparent)
                    {
                        spriteBatch.Draw(itemTexture, position2, new Rectangle?(rectangle2), item.GetColor(Color.White), 0f, origin, drawScale * pulseScale, SpriteEffects.None, 0f);
                    }
                }
                ItemLoader.PostDrawInInventory(item, spriteBatch, position2, rectangle2, item.GetAlpha(newColor),
                                               item.GetColor(Color.White), origin, drawScale * pulseScale);



                ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontItemStack, "" + formattedAmount(), dimensions.Position() + new Vector2(0f, 32f) * scale, total > amount ? Color.White : total == amount ? Color.Yellow : Color.Red, 0f, Vector2.Zero, new Vector2(scale), -1f, scale);
            }
        }
Ejemplo n.º 4
0
        public void whileMouseHovering()
        {
            PartsPlayer p = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>();

            if (Main.mouseLeftRelease && Main.mouseLeft)
            {
                if (Main.mouseItem == null || Main.mouseItem.type == 0)
                {
                    Main.mouseItem = ARareItemSwapJPANs.getItemFromTag(partTag);
                    if (p.getPartAmount(partTag) >= Main.mouseItem.maxStack)
                    {
                        Main.mouseItem.stack = Main.mouseItem.maxStack;
                        p.decreasePart(partTag, Main.mouseItem.maxStack);
                    }
                    else if (p.getPartAmount(partTag) > 0)
                    {
                        Main.mouseItem.stack = (int)p.getPartAmount(partTag);
                        p.decreasePart(partTag, p.getPartAmount(partTag));
                    }
                    else
                    {
                        Main.mouseItem.TurnToAir();
                    }
                }
                else
                {
                    if (p.addPart(Main.mouseItem))
                    {
                        Main.mouseItem.TurnToAir();
                    }
                }
            }
            else if (Main.stackSplit <= 1 && Main.mouseRight)
            {
                if (item.maxStack >= 1 && (Main.mouseItem.IsTheSameAs(item) || Main.mouseItem.type == 0) && (Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0))
                {
                    if (Main.mouseItem.type == 0)
                    {
                        if (p.decreasePart(partTag) != -1)
                        {
                            Main.mouseItem       = ARareItemSwapJPANs.getItemFromTag(partTag);
                            Main.mouseItem.stack = 1;
                        }
                    }
                    else
                    {
                        if (Main.mouseItem.stack <= Main.mouseItem.maxStack && ARareItemSwapJPANs.ItemToTag(Main.mouseItem).Equals(partTag))
                        {
                            if (p.decreasePart(partTag) != -1)
                            {
                                Main.mouseItem.stack++;
                            }
                        }
                    }
                    Recipe.FindRecipes();
                    Main.soundInstanceMenuTick.Stop();
                    Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance();
                    Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    if (Main.stackSplit == 0)
                    {
                        Main.stackSplit = 15;
                    }
                    else
                    {
                        Main.stackSplit = Main.stackDelay;
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public static int orderByID(string x, string y) => ARareItemSwapJPANs.getItemFromTag(x).type.CompareTo(ARareItemSwapJPANs.getItemFromTag(y).type);
Ejemplo n.º 6
0
        public void recreateList()
        {
            internalGrid.Left.Set(0, 0);
            internalGrid.Top.Set(0, 0);
            internalGrid.Width.Set(this.Width.Pixels - 4, 0);
            internalGrid.Height.Set(this.Height.Pixels - 4, 0);

restart:
            changedToList = false;
            internalGrid.Clear();

            if (parent.destroySlot.item != null && parent.destroySlot.item.type != 0 && !ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item)) && PartRecipes.recipesByResult.ContainsKey(ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item)))
            {
                foreach (PartRecipe pr in PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(parent.destroySlot.item)])
                {
                    if (pr.isAvailable())
                    {
                        PurchaseItemSlot pt = new PurchaseItemSlot(pr);
                        if (parent.selectedRecipe == null)
                        {
                            parent.selectedRecipe = pr;
                        }
                        if (pr.Equals(parent.selectedRecipe))
                        {
                            pt.select(true);
                        }
                        internalGrid.Add(pt);
                        if (changedToList)
                        {
                            goto restart;
                        }
                    }
                }
            }
            else if (selected.Equals(changer.availableTree))
            {
                List <PartRecipe> prtList = new List <PartRecipe>();

                prtList.AddRange(PartRecipes.allRecipes);
                prtList.Sort(PartRecipe.orderByResultName);
                for (int i = 0; i < prtList.Count; i++)
                {
                    if (!prtList[i].isAvailable())
                    {
                        prtList.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        if (!Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>().CanCraftRecipe(prtList[i]))
                        {
                            prtList.RemoveAt(i);
                            i--;
                        }
                    }
                    if (changedToList)
                    {
                        goto restart;
                    }
                }

                foreach (PartRecipe pr in prtList)
                {
                    if (search == null || search.Trim().Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower())))
                    {
                        PurchaseItemSlot pt = new PurchaseItemSlot(pr);
                        internalGrid.Add(pt);
                    }
                    if (changedToList)
                    {
                        goto restart;
                    }
                }
            }
            else if (selected.Equals(changer.allTree))
            {
                List <PartRecipe> prtList = new List <PartRecipe>();

                prtList.AddRange(PartRecipes.allRecipes);
                prtList.Sort(PartRecipe.orderByResultName);

                foreach (PartRecipe pr in prtList)
                {
                    if (pr.isAvailable())
                    {
                        if (search == null || search.Trim().Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower())))
                        {
                            PurchaseItemSlot pt = new PurchaseItemSlot(pr);
                            internalGrid.Add(pt);
                        }
                        if (changedToList)
                        {
                            goto restart;
                        }
                    }
                }
            }
            else if (selected.Equals(changer.partsTree))
            {
                PartsPlayer prt = Main.player[Main.myPlayer].GetModPlayer <PartsPlayer>();
                foreach (string s in ARareItemSwapJPANs.tokenList)
                {
                    if (prt.parts.ContainsKey(s))
                    {
                        Item part = ARareItemSwapJPANs.getItemFromTag(s);
                        if (search == null || search.Trim().Length == 0 || part.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(part).ToLower().Contains(search.ToLower())))
                        {
                            PartItemSlot pt = new PartItemSlot(s, -1);
                            internalGrid.Add(pt);
                        }
                        if (changedToList)
                        {
                            goto restart;
                        }
                    }
                }
            }
            else
            {
                if (selected != null && PartRecipes.recipesByCategory.ContainsKey(selected.getFullPath()))
                {
                    List <PartRecipe> prtList = new List <PartRecipe>();
                    prtList.AddRange(PartRecipes.recipesByCategory[selected.getFullPath()]);
                    prtList.Sort(PartRecipe.orderByResultName);
                    foreach (PartRecipe pr in prtList)
                    {
                        if (pr.isAvailable())
                        {
                            if (search == null || search.Length == 0 || pr.result.Name.ToLower().Contains(search.ToLower()) || (tooltipSearch && condensedTooltip(pr.result).ToLower().Contains(search.ToLower())))
                            {
                                PurchaseItemSlot pt = new PurchaseItemSlot(pr);

                                internalGrid.Add(pt);
                            }
                        }
                        if (changedToList)
                        {
                            goto restart;
                        }
                    }
                }
            }
        }