Inheritance: System.Windows.Forms.Control
Example #1
0
        private void InventoryItem_DragDrop(object sender, DragEventArgs e)
        {
            InventoryItemControl old  = this;
            InventoryItemControl derp = (InventoryItemControl)e.Data.GetData(typeof(InventoryItemControl));

            _Name       = derp.MyName;
            Item.ID     = derp.MyType;
            Item.Damage = derp.Damage;
            Item.Count  = derp.Count;

            Block b = Blocks.Get(0x00);

            try
            {
                b = Blocks.Get(Item.ID);
            }
            catch (Exception) { }

            Img   = b.Image;
            _Name = b.Name;

            Render();

            Refresh();
            Console.WriteLine("Received data, copying.");
        }
Example #2
0
        void inv_Click(object sender, EventArgs e)
        {
            InventoryItemControl inv = (InventoryItemControl)sender;

            inv.Selected = !inv.Selected;
            inv.Render();
            inv.Refresh();
            cmbType.SelectedItem = Blocks.Get(inv.MyType);
            numCount.Value       = inv.Count;
            numDamage.Value      = inv.Damage;
        }
Example #3
0
 public ChestEditor(TileEntity e)
 {
     Chest = (Chest)e;
     InitializeComponent();
     for (byte i = 0; i < 54; i++)
     {
         InvControls[i]          = new InventoryItemControl(i, ref Chest.Inventory);
         InvControls[i].Click   += new EventHandler(inv_Click);
         InvControls[i].Changed += new InventoryItemControl.ChangedHandler(ChestEditor_Changed);
     }
     DoLayout();
     cmbType.DrawMode  = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     cmbType.DrawItem += new DrawItemEventHandler(cmbType_DrawItem);
     cmbType.Items.Clear();
     cmbType.ValueMember   = "ID";
     cmbType.DisplayMember = "Name";
     foreach (KeyValuePair <short, Block> k in Blocks.BlockList)
     {
         cmbType.Items.Add(k.Value);
     }
 }
Example #4
0
 public ChestEditor(TileEntity e)
 {
     Chest = (Chest)e;
     InitializeComponent();
     for(byte i=0;i<54;i++)
     {
         InvControls[i] = new InventoryItemControl(i,ref Chest.Inventory);
         InvControls[i].Click += new EventHandler(inv_Click);
         InvControls[i].Changed += new InventoryItemControl.ChangedHandler(ChestEditor_Changed);
     }
     DoLayout();
     cmbType.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     cmbType.DrawItem +=new DrawItemEventHandler(cmbType_DrawItem);
     cmbType.Items.Clear();
     cmbType.ValueMember = "ID";
     cmbType.DisplayMember = "Name";
     foreach (KeyValuePair<short, Block> k in Blocks.BlockList)
     {
         cmbType.Items.Add(k.Value);
     }
 }
Example #5
0
        public void Save()
        {
            if (_Map == null)
            {
                return;
            }

            _Map.ClearInventory();
            for (int i = 0; i < Stuff.Count; i++)
            {
                InventoryItemControl item = Stuff[i];
                if (item.MyType > 0 && item.Count > 0)
                {
                    if (i > Map.InventoryCapacity - 1)
                    {
                        _Map.SetArmor((Enum.GetValues(typeof(ArmorType)) as ArmorType[])[i - ArmorOffset], item.MyType, item.Damage, item.Count);
                    }
                    else
                    {
                        _Map.SetInventory(i, item.MyType, item.Damage, item.Count);
                    }
                }
            }
        }
Example #6
0
        private void ReadFromMap()
        {
            if (_Map == null) return;
            cmbType.Items.Clear();
            cmbType.ValueMember = "ID";
            cmbType.DisplayMember = "Name";
            foreach(KeyValuePair<short,Block> k in Blocks.BlockList)
            {
                cmbType.Items.Add(k.Value);
            }
            this.splitInv.SplitterDistance= (Columns * 32) + 47;
            Console.WriteLine("Inventory set to ({0},{1}).",Width,Height);
            Stuff.Clear();
            for (int i = 0; i < Map.InventoryCapacity; i++)
            {
                short id;
                short dmg;
                byte count;
                string failreason;
                if (_Map.GetInventory(i, out id, out dmg, out count, out failreason))
                {
                    InventoryItemControl inv = new InventoryItemControl(id, dmg, count);
                    inv.Render();
                    inv.Click += new EventHandler(inv_Click);
                    this.splitInv.Panel1.Controls.Add(inv);
                    Console.WriteLine("[Inventory] Adding #{0} - {1} {2} @ {3} damage", i, inv.Count, inv.Name, inv.Damage);
                    Stuff.Add(i, inv);
                }
                else
                {
                    InventoryItemControl inv = new InventoryItemControl(0, 0, 1);
                    inv.Render();
                    inv.Click += new EventHandler(inv_Click);
                    this.splitInv.Panel1.Controls.Add(inv);
                    Stuff.Add(i, inv);
                    Console.WriteLine("[Inventory] Failed to add #{0} - {1}", i, failreason);
                }
            }
            int invc =ArmorOffset= Stuff.Count;
            for (int i = 0; i < 4; i++)
            {
                short id;
                short dmg;
                byte count;
                string failreason;
                ArmorType at = (Enum.GetValues(typeof(ArmorType)) as ArmorType[])[i];
                if (_Map.GetArmor(at, out id, out dmg, out count, out failreason))
                {
                    InventoryItemControl inv = new InventoryItemControl(id, dmg, count);
                    inv.Render();
                    inv.Click += new EventHandler(inv_Click);
                    inv.MouseDown += new MouseEventHandler(inv_MouseDown);
                    inv.MouseUp += new MouseEventHandler(inv_MouseUp);
                    inv.MouseLeave += new EventHandler(inv_MouseLeave);
                    this.splitInv.Panel1.Controls.Add(inv);
                    Console.WriteLine("[Inventory] Adding #{0} - {1} {2} @ {3} damage", i, inv.Count, inv.Name, inv.Damage);
                    Stuff.Add(invc+i, inv);
                }
                else
                {
                    InventoryItemControl inv = new InventoryItemControl(0, 0, 1);
                    inv.Render();
                    inv.Click += new EventHandler(inv_Click);
                    inv.MouseDown += new MouseEventHandler(inv_MouseDown);
                    inv.MouseUp += new MouseEventHandler(inv_MouseUp);
                    inv.MouseLeave += new EventHandler(inv_MouseLeave);
                    this.splitInv.Panel1.Controls.Add(inv);
                    Stuff.Add(invc+i, inv);
                    Console.WriteLine("[Inventory] Failed to add #{0} - {1}", i, failreason);
                }
            }

            DoLayout();
            Refresh();
        }
Example #7
0
        private void ReadFromMap()
        {
            if (this.InvokeRequired)
            {
                MethodInvoker del = delegate { ReadFromMap(); };
                Invoke(del);
                return;
            }
            if (_Map == null)
            {
                return;
            }
            cmbType.Items.Clear();
            cmbType.ValueMember   = "ID";
            cmbType.DisplayMember = "Name";
            foreach (KeyValuePair <short, Block> k in Blocks.BlockList)
            {
                cmbType.Items.Add(k.Value);
            }
            this.splitInv.SplitterDistance = (Columns * 32) + 47;
            Console.WriteLine("Inventory set to ({0},{1}).", Width, Height);
            Stuff.Clear();
            for (int i = 0; i < Map.InventoryCapacity; i++)
            {
                short  id;
                short  dmg;
                byte   count;
                string failreason;
                if (_Map.GetInventory(i, out id, out dmg, out count, out failreason))
                {
                    InventoryItemControl inv = new InventoryItemControl(id, dmg, count);
                    inv.Render();
                    inv.Click           += new EventHandler(inv_Click);
                    inv.ContextMenuStrip = cmnuItem;
                    this.splitInv.Panel1.Controls.Add(inv);
                    //Console.WriteLine("[Inventory] Adding #{0} - {1} {2} @ {3} damage", i, inv.Count, inv.Name, inv.Damage);
                    Stuff.Add(i, inv);
                }
                else
                {
                    InventoryItemControl inv = new InventoryItemControl(0, 0, 1);
                    inv.Render();
                    inv.Click           += new EventHandler(inv_Click);
                    inv.ContextMenuStrip = cmnuItem;
                    this.splitInv.Panel1.Controls.Add(inv);
                    Stuff.Add(i, inv);
                    //Console.WriteLine("[Inventory] Failed to add #{0} - {1}", i, failreason);
                }
            }
            int invc = ArmorOffset = Stuff.Count;

            for (int i = 0; i < 4; i++)
            {
                short     id;
                short     dmg;
                byte      count;
                string    failreason;
                ArmorType at = (Enum.GetValues(typeof(ArmorType)) as ArmorType[])[i];
                if (_Map.GetArmor(at, out id, out dmg, out count, out failreason))
                {
                    InventoryItemControl inv = new InventoryItemControl(id, dmg, count);
                    inv.Render();
                    inv.Click           += new EventHandler(inv_Click);
                    inv.ContextMenuStrip = cmnuItem;
                    this.splitInv.Panel1.Controls.Add(inv);
                    //Console.WriteLine("[Inventory] Adding #{0} - {1} {2} @ {3} damage", i, inv.Count, inv.Name, inv.Damage);
                    Stuff.Add(invc + i, inv);
                }
                else
                {
                    InventoryItemControl inv = new InventoryItemControl(0, 0, 1);
                    inv.Render();
                    inv.Click           += new EventHandler(inv_Click);
                    inv.ContextMenuStrip = cmnuItem;
                    this.splitInv.Panel1.Controls.Add(inv);
                    Stuff.Add(invc + i, inv);
                    //Console.WriteLine("[Inventory] Failed to add #{0} - {1}", i, failreason);
                }
            }

            DoLayout();
            Invalidate();
        }