Ejemplo n.º 1
0
 public void Draw(ref string mouseTip)
 {
     if (!display || (Codable.RunSpecifiedMethod("Predraw interface " + name, code, "PreDraw", Interface.main.spriteBatch) && !(bool)Codable.customMethodReturn))
     {
         return;
     }
     for (int i = 0; i < buttonCount; i++)
     {
         DrawText(i);
     }
     for (int j = 0; j < slotCount; j++)
     {
         float inventoryScale = Main.inventoryScale;
         if (Codable.RunSpecifiedMethod("Predraw interface slot " + name, code, "PreDrawSlot", Interface.main.spriteBatch, j))
         {
             if ((bool)Codable.customMethodReturn)
             {
                 DrawItemSlot((int)slotLocation[j].X, (int)slotLocation[j].Y, j, ref mouseTip);
             }
         }
         else
         {
             DrawItemSlot((int)slotLocation[j].X, (int)slotLocation[j].Y, j, ref mouseTip);
         }
         Codable.RunSpecifiedMethod("Postdraw interface slot " + name, code, "PostDrawSlot", Interface.main.spriteBatch, j);
         Main.inventoryScale = inventoryScale;
     }
     Codable.RunSpecifiedMethod("Postdraw interface " + name, code, "PostDraw", Interface.main.spriteBatch);
 }
Ejemplo n.º 2
0
            public void Register <T>(ref T method, object subclass, string methodName) where T : class
            {
                T del = Codable.GetDel <T>(subclass, methodName);

                if (del != null)
                {
                    Delegate @delegate = Delegate.Combine(method as Delegate, del as Delegate);
                    delegates[methodName] = @delegate;
                    method = (@delegate as T);
                }
                else
                {
                    delegates[methodName] = (method as Delegate);
                }
            }
Ejemplo n.º 3
0
 public static void InitTile(Vector2 pos, int type)
 {
     if (Config.tileDefs.height[type] > 1 || Config.tileDefs.width[type] > 1)
     {
         pos = GetPos(pos);
     }
     if (!Config.tileDefs.code.ContainsKey(pos))
     {
         Codable codable = new Codable();
         codable.name      = Main.tileName[type];
         codable.className = "Tile";
         codable.Init();
         if (codable.subclass != null)
         {
             codable.RunMethod("Initialize", (int)pos.X, (int)pos.Y);
             Config.tileDefs.code[pos] = codable;
             WorldGen.TileUpdate      += (Action)GetDelegate(codable.subclass, "Update", typeof(Action));
         }
     }
 }
Ejemplo n.º 4
0
        public static bool SaveCustomData(Codable item, BinaryWriter writer, bool net = false)
        {
            if (net && (item.name == null || item.name == ""))
            {
                return(false);
            }
            bool         flag         = false;
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter binaryWriter = new BinaryWriter(memoryStream);

            if (RunSpecifiedMethod(item.className + " " + item.name, item.subclass, "Save", binaryWriter))
            {
                binaryWriter.Close();
            }
            else if (item.savedata != null)
            {
                binaryWriter.Write(item.savedata);
            }
            writer.Write(memoryStream.ToArray().Length);
            writer.Write(memoryStream.ToArray());
            if (memoryStream.ToArray().Length > 0)
            {
                flag = true;
            }
            ArrayList arrayList = new ArrayList();

            if (item.className == "Item")
            {
                arrayList = Config.itemDefs.globalModname;
            }
            else if (item.className == "NPC")
            {
                arrayList = Config.npcDefs.globalModname;
            }
            else if (item.className == "Projectile")
            {
                arrayList = Config.projDefs.globalModname;
            }
            else if (item.className == "Tile")
            {
                arrayList = Config.tileDefs.globalModname;
            }
            int num  = item.globsubclass.Length;
            int num2 = 0;

            memoryStream = new MemoryStream();
            binaryWriter = new BinaryWriter(memoryStream);
            ArrayList arrayList2 = new ArrayList();

            for (int i = 0; i < num; i++)
            {
                string text = (string)arrayList[i];
                if (!arrayList2.Contains(text))
                {
                    arrayList2.Add(text);
                    MemoryStream memoryStream2 = new MemoryStream();
                    BinaryWriter binaryWriter2 = new BinaryWriter(memoryStream2);
                    try
                    {
                        if (!RunSpecifiedMethod("Global, " + item.className + " " + item.name, item.globsubclass[i], "Save", binaryWriter2) && item.globsavedata[i] != null)
                        {
                            binaryWriter2.Write(item.globsavedata[i]);
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    if (memoryStream2.ToArray().Length > 0)
                    {
                        num2++;
                        binaryWriter.Write(text);
                        binaryWriter.Write(memoryStream2.ToArray().Length);
                        binaryWriter.Write(memoryStream2.ToArray());
                    }
                }
            }
            if (item.unloadedSavedata != null)
            {
                for (int j = 0; j < item.unloadedSavedata.Length; j++)
                {
                    num2++;
                    binaryWriter.Write(item.unloadedSavedata[j]);
                }
            }
            writer.Write(num2);
            writer.Write(memoryStream.ToArray());
            if (memoryStream.ToArray().Length > 0 || flag)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public static void LoadCustomData(Codable item, BinaryReader reader, int version = 3, bool forceItemLoad = false)
        {
            if ((item.name == null || item.name == "") && version >= 2 && !forceItemLoad)
            {
                return;
            }
            int num = reader.ReadInt32();

            if (num > 0)
            {
                MemoryStream memoryStream = new MemoryStream(reader.ReadBytes(num));
                BinaryReader binaryReader = new BinaryReader(memoryStream);
                try
                {
                    if (!RunSpecifiedMethod(item.className + " " + item.name, item.subclass, "Load", binaryReader, Config.GetModVersion(item)))
                    {
                        item.savedata = memoryStream.ToArray();
                    }
                }
                catch (Exception)
                {
                }
            }
            ArrayList arrayList = new ArrayList();

            if (item.className == "Item")
            {
                arrayList = Config.itemDefs.globalModname;
            }
            else if (item.className == "NPC")
            {
                arrayList = Config.npcDefs.globalModname;
            }
            else if (item.className == "Projectile")
            {
                arrayList = Config.projDefs.globalModname;
            }
            else
            {
                if (!(item.className == "Tile"))
                {
                    return;
                }
                arrayList = Config.tileDefs.globalModname;
            }
            if (version < 2)
            {
                return;
            }
            int num2 = 0;
            int num3 = reader.ReadInt32();
            List <MemoryStream> list       = new List <MemoryStream>();
            List <BinaryWriter> list2      = new List <BinaryWriter>();
            ArrayList           arrayList2 = new ArrayList();

            for (int i = 0; i < num3; i++)
            {
                string       text          = reader.ReadString();
                int          num4          = arrayList.IndexOf(text);
                int          count         = reader.ReadInt32();
                MemoryStream memoryStream2 = new MemoryStream(reader.ReadBytes(count));
                BinaryReader binaryReader2 = new BinaryReader(memoryStream2);
                if (!arrayList2.Contains(text))
                {
                    arrayList2.Add(text);
                    if (num4 > -1)
                    {
                        try
                        {
                            RunSpecifiedMethod("Global, " + item.className + " " + item.name, item.globsubclass[num4], "Load", binaryReader2, Config.loadedVersion[text]);
                        }
                        catch (Exception)
                        {
                        }
                        continue;
                    }
                    MemoryStream memoryStream3 = new MemoryStream();
                    list.Add(memoryStream3);
                    list2.Add(new BinaryWriter(memoryStream3));
                    list2[num2].Write(text);
                    list2[num2].Write(memoryStream2.ToArray().Length);
                    list2[num2].Write(memoryStream2.ToArray());
                    num2++;
                }
            }
            if (num2 > 0)
            {
                item.unloadedSavedata = new byte[num2][];
                for (int j = 0; j < num2; j++)
                {
                    item.unloadedSavedata[j] = list[j].ToArray();
                }
            }
        }
Ejemplo n.º 6
0
        public void DrawItemSlot(int x, int y, int slot, ref string mouseTip)
        {
            Texture2D inventoryBack5Texture = Main.inventoryBack5Texture;

            Item[] array = itemSlots;
            if (array[slot].stack == 0)
            {
                array[slot] = new Item();
            }
            new Color(100, 100, 100, 100);
            if (Main.mouseX >= x && (float)Main.mouseX <= (float)x + (float)Main.inventoryBackTexture.Width * Main.inventoryScale && Main.mouseY >= y && (float)Main.mouseY <= (float)y + (float)Main.inventoryBackTexture.Height * Main.inventoryScale)
            {
                Main.player[Main.myPlayer].mouseInterface = true;
                if (Main.mouseLeftRelease && Main.mouseLeft)
                {
                    if (Main.player[Main.myPlayer].itemAnimation <= 0 && code.CanPlaceSlot(slot, Main.mouseItem))
                    {
                        Item mouseItem = Main.mouseItem;
                        Main.mouseItem = array[slot];
                        array[slot]    = mouseItem;
                        if (array[slot].type == 0 || array[slot].stack < 1)
                        {
                            array[slot] = new Item();
                        }
                        if (Main.mouseItem.IsTheSameAs(array[slot]) && array[slot].stack != array[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack)
                        {
                            if (Main.mouseItem.stack + array[slot].stack <= Main.mouseItem.maxStack)
                            {
                                array[slot].stack   += Main.mouseItem.stack;
                                Main.mouseItem.stack = 0;
                            }
                            else
                            {
                                int num = Main.mouseItem.maxStack - array[slot].stack;
                                array[slot].stack    += num;
                                Main.mouseItem.stack -= num;
                            }
                        }
                        if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                        {
                            Main.mouseItem = new Item();
                        }
                        if (Main.mouseItem.type > 0 || array[slot].type > 0)
                        {
                            Recipe.FindRecipes();
                            Main.PlaySound(7);
                        }
                        code.PlaceSlot(slot);
                    }
                }
                else if (!Main.mouseRight || !Codable.RunSpecifiedMethod("Interface right-click", code, "SlotRightClicked", slot))
                {
                    if (Main.mouseRight && Main.mouseRightRelease && array[slot].maxStack == 1)
                    {
                        array[slot] = Main.armorSwap(array[slot]);
                    }
                    else if (Main.stackSplit <= 1 && Main.mouseRight && array[slot].maxStack > 1 && (Main.mouseItem.IsTheSameAs(array[slot]) || Main.mouseItem.type == 0) && (Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0))
                    {
                        if (Main.mouseItem.type == 0)
                        {
                            Main.mouseItem       = (Item)array[slot].Clone();
                            Main.mouseItem.stack = 0;
                        }
                        Main.mouseItem.stack++;
                        array[slot].stack--;
                        if (array[slot].stack <= 0)
                        {
                            array[slot] = new Item();
                        }
                        Recipe.FindRecipes();
                        Main.soundInstanceMenuTick.Stop();
                        Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance();
                        Main.PlaySound(12);
                        if (Main.stackSplit == 0)
                        {
                            Main.stackSplit = 15;
                        }
                        else
                        {
                            Main.stackSplit = Main.stackDelay;
                        }
                    }
                }
                mouseTip     = array[slot].name;
                Main.toolTip = (Item)array[slot].ShallowClone();
                if (array[slot].stack > 1)
                {
                    object obj = mouseTip;
                    mouseTip = string.Concat(obj, " (", array[slot].stack, ")");
                }
            }
            Interface.DrawItem(inventoryBack5Texture, array[slot], x, y);
        }