예제 #1
0
        public void Draw()
        {
            Point scaledMouse = mouse_current.MouseCurrent;

            the3d.Draw2dBitmapFile("inventory.png", InventoryStart.X, InventoryStart.Y, 512, 1024);

            //the3d.Draw2dTexture(terrain, 50, 50, 50, 50, 0);
            //the3d.Draw2dBitmapFile("inventory_weapon_shovel.png", 100, 100, 60 * 2, 60 * 4);
            //the3d.Draw2dBitmapFile("inventory_gauntlet_gloves.png", 200, 200, 60 * 2, 60 * 2);
            //main inventory
            foreach (var k in inventory.Items)
            {
                DrawItem(new Point(CellsStart.X + k.Key.X * CellDrawSize, CellsStart.Y + k.Key.Y * CellDrawSize), k.Value, null);
            }

            //draw area selection
            if (inventory.DragDropItem != null)
            {
                Point?selected = SelectedCell(scaledMouse);
                if (selected != null)
                {
                    int   x    = (selected.Value.X) * CellDrawSize + CellsStart.X;
                    int   y    = (selected.Value.Y) * CellDrawSize + CellsStart.Y;
                    Point size = dataItems.ItemSize(inventory.DragDropItem);
                    if (selected.Value.X + size.X <= CellCount.X &&
                        selected.Value.Y + size.Y <= CellCount.Y)
                    {
                        Color   c;
                        Point[] itemsAtArea = inventoryUtil.ItemsAtArea(selected.Value, size);
                        if (itemsAtArea == null || itemsAtArea.Length > 1)
                        {
                            c = Color.Red;
                        }
                        else //0 or 1
                        {
                            c = Color.Green;
                        }
                        the3d.Draw2dTexture(the3d.WhiteTexture(), x, y,
                                            CellDrawSize * size.X, CellDrawSize * size.Y,
                                            null, Color.FromArgb(100, c));
                    }
                }
                WearPlace?selectedWear = SelectedWearPlace(scaledMouse);
                if (selectedWear != null)
                {
                    Point p    = Offset(wearPlaceStart[(int)selectedWear], InventoryStart);
                    Point size = wearPlaceCells[(int)selectedWear];

                    Color c;
                    Item  itemsAtArea = inventoryUtil.ItemAtWearPlace(selectedWear.Value, ActiveMaterial.ActiveMaterial);
                    if (!dataItems.CanWear(selectedWear.Value, inventory.DragDropItem))
                    {
                        c = Color.Red;
                    }
                    else //0 or 1
                    {
                        c = Color.Green;
                    }
                    the3d.Draw2dTexture(the3d.WhiteTexture(), p.X, p.Y,
                                        CellDrawSize * size.X, CellDrawSize * size.Y,
                                        null, Color.FromArgb(100, c));
                }
            }

            //material selector
            DrawMaterialSelector();

            //wear
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.LeftHand], InventoryStart), inventory.LeftHand[ActiveMaterial.ActiveMaterial], null);
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.RightHand], InventoryStart), inventory.RightHand[ActiveMaterial.ActiveMaterial], null);
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.MainArmor], InventoryStart), inventory.MainArmor, null);
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.Boots], InventoryStart), inventory.Boots, null);
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.Helmet], InventoryStart), inventory.Helmet, null);
            DrawItem(Offset(wearPlaceStart[(int)WearPlace.Gauntlet], InventoryStart), inventory.Gauntlet, null);

            //info
            if (SelectedCell(scaledMouse) != null)
            {
                Point selected   = SelectedCell(scaledMouse).Value;
                Point?itemAtCell = inventoryUtil.ItemAtCell(selected);
                if (itemAtCell != null)
                {
                    Item item = inventory.Items[new ProtoPoint(itemAtCell.Value)];
                    if (item != null)
                    {
                        int x = (selected.X) * CellDrawSize + CellsStart.X;
                        int y = (selected.Y) * CellDrawSize + CellsStart.Y;
                        DrawItemInfo(new Point(scaledMouse.X, scaledMouse.Y), item);
                    }
                }
            }
            if (SelectedWearPlace(scaledMouse) != null)
            {
                WearPlace selected        = SelectedWearPlace(scaledMouse).Value;
                Item      itemAtWearPlace = inventoryUtil.ItemAtWearPlace(selected, ActiveMaterial.ActiveMaterial);
                if (itemAtWearPlace != null)
                {
                    DrawItemInfo(new Point(scaledMouse.X, scaledMouse.Y), itemAtWearPlace);
                }
            }
            if (SelectedMaterialSelectorSlot(scaledMouse) != null)
            {
                int  selected = SelectedMaterialSelectorSlot(scaledMouse).Value;
                Item item     = inventory.RightHand[selected];
                if (item != null)
                {
                    DrawItemInfo(new Point(scaledMouse.X, scaledMouse.Y), item);
                }
            }

            if (inventory.DragDropItem != null)
            {
                DrawItem(new Point(scaledMouse.X, scaledMouse.Y), inventory.DragDropItem, null);
            }
        }
예제 #2
0
 public override void InventoryClick(Packet_InventoryPosition pos)
 {
     if (pos.Type == Packet_InventoryPositionTypeEnum.MainArea)
     {
         Point?selected = null;
         foreach (var k in d_Inventory.Items)
         {
             if (pos.AreaX >= k.Key.X && pos.AreaY >= k.Key.Y &&
                 pos.AreaX < k.Key.X + d_Items.ItemSizeX(k.Value) &&
                 pos.AreaY < k.Key.Y + d_Items.ItemSizeY(k.Value))
             {
                 selected = new Point(k.Key.X, k.Key.Y);
             }
         }
         //drag
         if (selected != null && d_Inventory.DragDropItem == null)
         {
             d_Inventory.DragDropItem = d_Inventory.Items[new ProtoPoint(selected.Value.X, selected.Value.Y)];
             d_Inventory.Items.Remove(new ProtoPoint(selected.Value.X, selected.Value.Y));
             SendInventory();
         }
         //drop
         else if (d_Inventory.DragDropItem != null)
         {
             //make sure there is nothing blocking drop.
             IntRef     itemsAtAreaCount = new IntRef();
             PointRef[] itemsAtArea      = d_InventoryUtil.ItemsAtArea(pos.AreaX, pos.AreaY,
                                                                       d_Items.ItemSizeX(d_Inventory.DragDropItem), d_Items.ItemSizeY(d_Inventory.DragDropItem), itemsAtAreaCount);
             if (itemsAtArea == null || itemsAtAreaCount.value > 1)
             {
                 //invalid area
                 return;
             }
             if (itemsAtAreaCount.value == 0)
             {
                 d_Inventory.Items.Add(new ProtoPoint(pos.AreaX, pos.AreaY), d_Inventory.DragDropItem);
                 d_Inventory.DragDropItem = null;
             }
             else //1
             {
                 var swapWith = itemsAtArea[0];
                 //try to stack
                 Item stackResult = d_Items.Stack(d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)], d_Inventory.DragDropItem);
                 if (stackResult != null)
                 {
                     d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)] = stackResult;
                     d_Inventory.DragDropItem = null;
                 }
                 else
                 {
                     //try to swap
                     //swap (swapWith, dragdropitem)
                     Item z = d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)];
                     d_Inventory.Items.Remove(new ProtoPoint(swapWith.X, swapWith.Y));
                     d_Inventory.Items[new ProtoPoint(pos.AreaX, pos.AreaY)] = d_Inventory.DragDropItem;
                     d_Inventory.DragDropItem = z;
                 }
             }
             SendInventory();
         }
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.Ground)
     {
         /*
          * if (d_Inventory.DragDropItem != null)
          * {
          *  d_DropItem.DropItem(ref d_Inventory.DragDropItem,
          *      new Vector3i(pos.GroundPositionX, pos.GroundPositionY, pos.GroundPositionZ));
          *  SendInventory();
          * }
          */
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.MaterialSelector)
     {
         if (d_Inventory.DragDropItem == null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             d_Inventory.DragDropItem = d_Inventory.RightHand[pos.MaterialId];
             d_Inventory.RightHand[pos.MaterialId] = null;
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] == null)
         {
             if (d_Items.CanWear(WearPlace_.RightHand, d_Inventory.DragDropItem))
             {
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = null;
             }
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             if (d_Items.CanWear(WearPlace_.RightHand, d_Inventory.DragDropItem))
             {
                 Item oldHand = d_Inventory.RightHand[pos.MaterialId];
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = oldHand;
             }
         }
         SendInventory();
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.WearPlace)
     {
         //just swap.
         Item wear = d_InventoryUtil.ItemAtWearPlace(pos.WearPlace, pos.ActiveMaterial);
         if (d_Items.CanWear(pos.WearPlace, d_Inventory.DragDropItem))
         {
             d_InventoryUtil.SetItemAtWearPlace(pos.WearPlace, pos.ActiveMaterial, d_Inventory.DragDropItem);
             d_Inventory.DragDropItem = wear;
         }
         SendInventory();
     }
     else
     {
         throw new Exception();
     }
 }