Beispiel #1
0
 public override void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     //todo
     if (from.Type == Packet_InventoryPositionTypeEnum.MainArea &&
         to.Type == Packet_InventoryPositionTypeEnum.MaterialSelector &&
         d_Inventory.RightHand[to.MaterialId] == null &&
         d_Items.CanWear(WearPlace_.RightHand, d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)]))
     {
         d_Inventory.RightHand[to.MaterialId] = d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)];
         d_Inventory.Items.Remove(new ProtoPoint(from.AreaX, from.AreaY));
     }
 }
Beispiel #2
0
    public static Packet_Client MoveToInventory(Packet_InventoryPosition from)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = from;
        p.Action = Packet_InventoryActionTypeEnum.MoveToInventory;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
Beispiel #3
0
    public static Packet_Client InventoryClick(Packet_InventoryPosition pos)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = pos;
        p.Action = Packet_InventoryActionTypeEnum.Click;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
Beispiel #4
0
    public static Packet_Client WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = from;
        p.B      = to;
        p.Action = Packet_InventoryActionTypeEnum.WearItem;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
Beispiel #5
0
        public override void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
        {
            //TODO: what to do here?
            ProtoPoint originPoint = new ProtoPoint(from.AreaX, from.AreaY);

            if (from.Type == Packet_InventoryPositionTypeEnum.MainArea &&
                to.Type == Packet_InventoryPositionTypeEnum.MaterialSelector &&
                d_Inventory.RightHand[to.MaterialId] == null &&
                d_Inventory.Items.ContainsKey(originPoint) &&
                d_Items.CanWear(WearPlace_.RightHand, d_Inventory.Items[originPoint]))
            {
                d_Inventory.RightHand[to.MaterialId] = d_Inventory.Items[originPoint];
                d_Inventory.Items.Remove(originPoint);
            }
        }
Beispiel #6
0
        public override void MoveToInventory(Packet_InventoryPosition from)
        {
            //TODO: what to do here?
            if (from.Type == Packet_InventoryPositionTypeEnum.MaterialSelector)
            {
                //duplicate code with GrabItem().

                Item item = d_Inventory.RightHand[from.MaterialId];
                if (item == null)
                {
                    return;
                }
                //grab to main area - stacking
                for (int x = 0; x < d_InventoryUtil.CellCountX; x++)
                {
                    for (int y = 0; y < d_InventoryUtil.CellCountY; y++)
                    {
                        IntRef     pCount = new IntRef();
                        PointRef[] p      = d_InventoryUtil.ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                        if (p != null && pCount.value == 1)
                        {
                            var stacked = d_Items.Stack(d_Inventory.Items[new ProtoPoint(p[0].X, p[0].Y)], item);
                            if (stacked != null)
                            {
                                d_Inventory.Items[new ProtoPoint(x, y)] = stacked;
                                d_Inventory.RightHand[from.MaterialId]  = null;
                                return;
                            }
                        }
                    }
                }
                //grab to main area - adding
                for (int x = 0; x < d_InventoryUtil.CellCountX; x++)
                {
                    for (int y = 0; y < d_InventoryUtil.CellCountY; y++)
                    {
                        IntRef     pCount = new IntRef();
                        PointRef[] p      = d_InventoryUtil.ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                        if (p != null && pCount.value == 0)
                        {
                            d_Inventory.Items[new ProtoPoint(x, y)] = item;
                            d_Inventory.RightHand[from.MaterialId]  = null;
                            return;
                        }
                    }
                }
            }
        }
 public abstract void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to);
Beispiel #8
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();
     }
 }
Beispiel #9
0
 internal void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     SendPacketClient(ClientPackets.WearItem(from, to));
 }
Beispiel #10
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();
     }
 }
Beispiel #11
0
 internal Packet_InventoryPosition InventoryPositionMaterialSelector(int materialId)
 {
     Packet_InventoryPosition pos = new Packet_InventoryPosition();
     pos.Type = Packet_InventoryPositionTypeEnum.MaterialSelector;
     pos.MaterialId = materialId;
     return pos;
 }
Beispiel #12
0
 internal void MoveToInventory(Packet_InventoryPosition from)
 {
     SendPacketClient(ClientPackets.MoveToInventory(from));
 }
    public override void OnMouseDown(Game game_, MouseEventArgs args)
    {
        if (game.guistate != GuiState.Inventory)
        {
            return;
        }
        PointRef scaledMouse = PointRef.Create(args.GetX(), args.GetY());

        //material selector
        if (SelectedMaterialSelectorSlot(scaledMouse) != null)
        {
            //int oldActiveMaterial = ActiveMaterial.ActiveMaterial;
            game.ActiveMaterial = SelectedMaterialSelectorSlot(scaledMouse).value;
            //if (oldActiveMaterial == ActiveMaterial.ActiveMaterial)
            {
                Packet_InventoryPosition p = new Packet_InventoryPosition();
                p.Type = Packet_InventoryPositionTypeEnum.MaterialSelector;
                p.MaterialId = game.ActiveMaterial;
                controller.InventoryClick(p);
            }
            args.SetHandled(true);
            return;
        }

        if (game.guistate != GuiState.Inventory)
        {
            return;
        }

        //main inventory
        PointRef cellInPage = SelectedCell(scaledMouse);
        //grab from inventory
        if (cellInPage != null)
        {
            if (args.GetButton() == MouseButtonEnum.Left)
            {
                Packet_InventoryPosition p = new Packet_InventoryPosition();
                p.Type = Packet_InventoryPositionTypeEnum.MainArea;
                p.AreaX = cellInPage.X;
                p.AreaY = cellInPage.Y + ScrollLine;
                controller.InventoryClick(p);
                args.SetHandled(true);
                return;
            }
            else
            {
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type = Packet_InventoryPositionTypeEnum.MainArea;
                    p.AreaX = cellInPage.X;
                    p.AreaY = cellInPage.Y + ScrollLine;
                    controller.InventoryClick(p);
                }
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type = Packet_InventoryPositionTypeEnum.WearPlace;
                    p.WearPlace = WearPlace_.RightHand;
                    p.ActiveMaterial = game.ActiveMaterial;
                    controller.InventoryClick(p);
                }
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type = Packet_InventoryPositionTypeEnum.MainArea;
                    p.AreaX = cellInPage.X;
                    p.AreaY = cellInPage.Y + ScrollLine;
                    controller.InventoryClick(p);
                }
            }
            if (game.guistate == GuiState.Inventory)
            {
                args.SetHandled(true);
                return;
            }
        }
        // //drop items on ground
        //if (scaledMouse.X < CellsStartX() && scaledMouse.Y < MaterialSelectorStartY())
        //{
        //    int posx = game.SelectedBlockPositionX;
        //    int posy = game.SelectedBlockPositionY;
        //    int posz = game.SelectedBlockPositionZ;
        //    Packet_InventoryPosition p = new Packet_InventoryPosition();
        //    {
        //        p.Type = Packet_InventoryPositionTypeEnum.Ground;
        //        p.GroundPositionX = posx;
        //        p.GroundPositionY = posy;
        //        p.GroundPositionZ = posz;
        //    }
        //    controller.InventoryClick(p);
        //}
        if (SelectedWearPlace(scaledMouse) != null)
        {
            Packet_InventoryPosition p = new Packet_InventoryPosition();
            p.Type = Packet_InventoryPositionTypeEnum.WearPlace;
            p.WearPlace = (SelectedWearPlace(scaledMouse).value);
            p.ActiveMaterial = game.ActiveMaterial;
            controller.InventoryClick(p);
            args.SetHandled(true);
            return;
        }
        if (scaledMouse.X >= ScrollUpButtonX() && scaledMouse.X < ScrollUpButtonX() + ScrollButtonSize()
            && scaledMouse.Y >= ScrollUpButtonY() && scaledMouse.Y < ScrollUpButtonY() + ScrollButtonSize())
        {
            ScrollUp();
            ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            args.SetHandled(true);
            return;
        }
        if (scaledMouse.X >= ScrollDownButtonX() && scaledMouse.X < ScrollDownButtonX() + ScrollButtonSize()
            && scaledMouse.Y >= ScrollDownButtonY() && scaledMouse.Y < ScrollDownButtonY() + ScrollButtonSize())
        {
            ScrollDown();
            ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            args.SetHandled(true);
            return;
        }
        game.GuiStateBackToGame();
        return;
    }
Beispiel #14
0
 public abstract void InventoryClick(Packet_InventoryPosition pos);
Beispiel #15
0
 public abstract void MoveToInventory(Packet_InventoryPosition from);
Beispiel #16
0
 public static Packet_Client MoveToInventory(Packet_InventoryPosition from)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = from;
     p.Action = Packet_InventoryActionTypeEnum.MoveToInventory;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
Beispiel #17
0
 public abstract void InventoryClick(Packet_InventoryPosition pos);
Beispiel #18
0
 public override void MoveToInventory(Packet_InventoryPosition from)
 {
     g.MoveToInventory(from);
 }
Beispiel #19
0
 public override void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     g.WearItem(from, to);
 }
Beispiel #20
0
 public override void InventoryClick(Packet_InventoryPosition pos)
 {
     g.InventoryClick(pos);
 }
Beispiel #21
0
 public abstract void MoveToInventory(Packet_InventoryPosition from);
Beispiel #22
0
 public abstract void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to);
Beispiel #23
0
    public override void MoveToInventory(Packet_InventoryPosition from)
    {
        //todo
        if (from.Type == Packet_InventoryPositionTypeEnum.MaterialSelector)
        {
            //duplicate code with GrabItem().

            Item item = d_Inventory.RightHand[from.MaterialId];
            if (item == null)
            {
                return;
            }
            //grab to main area - stacking
            for (int x = 0; x < d_InventoryUtil.CellCountX; x++)
            {
                for (int y = 0; y < d_InventoryUtil.CellCountY; y++)
                {
                    IntRef pCount = new IntRef();
                    PointRef[] p = d_InventoryUtil.ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                    if (p != null && pCount.value == 1)
                    {
                        var stacked = d_Items.Stack(d_Inventory.Items[new ProtoPoint(p[0].X, p[0].Y)], item);
                        if (stacked != null)
                        {
                            d_Inventory.Items[new ProtoPoint(x, y)] = stacked;
                            d_Inventory.RightHand[from.MaterialId] = null;
                            return;
                        }
                    }
                }
            }
            //grab to main area - adding
            for (int x = 0; x < d_InventoryUtil.CellCountX; x++)
            {
                for (int y = 0; y < d_InventoryUtil.CellCountY; y++)
                {
                    IntRef pCount = new IntRef();
                    PointRef[] p = d_InventoryUtil.ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                    if (p != null && pCount.value == 0)
                    {
                        d_Inventory.Items[new ProtoPoint(x, y)] = item;
                        d_Inventory.RightHand[from.MaterialId] = null;
                        return;
                    }
                }
            }
        }
    }
Beispiel #24
0
 public static Packet_Client InventoryClick(Packet_InventoryPosition pos)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = pos;
     p.Action = Packet_InventoryActionTypeEnum.Click;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
Beispiel #25
0
 public override void WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     //todo
     if (from.Type == Packet_InventoryPositionTypeEnum.MainArea
         && to.Type == Packet_InventoryPositionTypeEnum.MaterialSelector
         && d_Inventory.RightHand[to.MaterialId] == null
         && d_Items.CanWear(WearPlace_.RightHand, d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)]))
     {
         d_Inventory.RightHand[to.MaterialId] = d_Inventory.Items[new ProtoPoint(from.AreaX, from.AreaY)];
         d_Inventory.Items.Remove(new ProtoPoint(from.AreaX, from.AreaY));
     }
 }
Beispiel #26
0
 public static Packet_Client WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = from;
     p.B = to;
     p.Action = Packet_InventoryActionTypeEnum.WearItem;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
Beispiel #27
0
 internal void InventoryClick(Packet_InventoryPosition pos)
 {
     SendPacketClient(ClientPackets.InventoryClick(pos));
 }
    public override void OnMouseDown(Game game_, MouseEventArgs args)
    {
        if (game.guistate != GuiState.Inventory)
        {
            return;
        }
        PointRef scaledMouse = PointRef.Create(args.GetX(), args.GetY());

        //material selector
        if (SelectedMaterialSelectorSlot(scaledMouse) != null)
        {
            //int oldActiveMaterial = ActiveMaterial.ActiveMaterial;
            game.ActiveMaterial = SelectedMaterialSelectorSlot(scaledMouse).value;
            //if (oldActiveMaterial == ActiveMaterial.ActiveMaterial)
            {
                Packet_InventoryPosition p = new Packet_InventoryPosition();
                p.Type       = Packet_InventoryPositionTypeEnum.MaterialSelector;
                p.MaterialId = game.ActiveMaterial;
                controller.InventoryClick(p);
            }
            args.SetHandled(true);
            return;
        }

        if (game.guistate != GuiState.Inventory)
        {
            return;
        }

        //main inventory
        PointRef cellInPage = SelectedCell(scaledMouse);

        //grab from inventory
        if (cellInPage != null)
        {
            if (args.GetButton() == MouseButtonEnum.Left)
            {
                Packet_InventoryPosition p = new Packet_InventoryPosition();
                p.Type  = Packet_InventoryPositionTypeEnum.MainArea;
                p.AreaX = cellInPage.X;
                p.AreaY = cellInPage.Y + ScrollLine;
                controller.InventoryClick(p);
                args.SetHandled(true);
                return;
            }
            else
            {
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type  = Packet_InventoryPositionTypeEnum.MainArea;
                    p.AreaX = cellInPage.X;
                    p.AreaY = cellInPage.Y + ScrollLine;
                    controller.InventoryClick(p);
                }
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type           = Packet_InventoryPositionTypeEnum.WearPlace;
                    p.WearPlace      = WearPlace_.RightHand;
                    p.ActiveMaterial = game.ActiveMaterial;
                    controller.InventoryClick(p);
                }
                {
                    Packet_InventoryPosition p = new Packet_InventoryPosition();
                    p.Type  = Packet_InventoryPositionTypeEnum.MainArea;
                    p.AreaX = cellInPage.X;
                    p.AreaY = cellInPage.Y + ScrollLine;
                    controller.InventoryClick(p);
                }
            }
            if (game.guistate == GuiState.Inventory)
            {
                args.SetHandled(true);
                return;
            }
        }
        // //drop items on ground
        //if (scaledMouse.X < CellsStartX() && scaledMouse.Y < MaterialSelectorStartY())
        //{
        //    int posx = game.SelectedBlockPositionX;
        //    int posy = game.SelectedBlockPositionY;
        //    int posz = game.SelectedBlockPositionZ;
        //    Packet_InventoryPosition p = new Packet_InventoryPosition();
        //    {
        //        p.Type = Packet_InventoryPositionTypeEnum.Ground;
        //        p.GroundPositionX = posx;
        //        p.GroundPositionY = posy;
        //        p.GroundPositionZ = posz;
        //    }
        //    controller.InventoryClick(p);
        //}
        if (SelectedWearPlace(scaledMouse) != null)
        {
            Packet_InventoryPosition p = new Packet_InventoryPosition();
            p.Type           = Packet_InventoryPositionTypeEnum.WearPlace;
            p.WearPlace      = (SelectedWearPlace(scaledMouse).value);
            p.ActiveMaterial = game.ActiveMaterial;
            controller.InventoryClick(p);
            args.SetHandled(true);
            return;
        }
        if (scaledMouse.X >= ScrollUpButtonX() && scaledMouse.X < ScrollUpButtonX() + ScrollButtonSize() &&
            scaledMouse.Y >= ScrollUpButtonY() && scaledMouse.Y < ScrollUpButtonY() + ScrollButtonSize())
        {
            ScrollUp();
            ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            args.SetHandled(true);
            return;
        }
        if (scaledMouse.X >= ScrollDownButtonX() && scaledMouse.X < ScrollDownButtonX() + ScrollButtonSize() &&
            scaledMouse.Y >= ScrollDownButtonY() && scaledMouse.Y < ScrollDownButtonY() + ScrollButtonSize())
        {
            ScrollDown();
            ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            args.SetHandled(true);
            return;
        }
        game.GuiStateBackToGame();
        return;
    }
Beispiel #29
0
 internal Packet_InventoryPosition InventoryPositionMainArea(int x, int y)
 {
     Packet_InventoryPosition pos = new Packet_InventoryPosition();
     pos.Type = Packet_InventoryPositionTypeEnum.MainArea;
     pos.AreaX = x;
     pos.AreaY = y;
     return pos;
 }