예제 #1
0
    public ModGuiInventory()
    {
        //indexed by enum WearPlace
        wearPlaceStart = new PointRef[5];
        {
            //new Point(282,85), //LeftHand,
            wearPlaceStart[0] = PointRef.Create(34, 100);  //RightHand,
            wearPlaceStart[1] = PointRef.Create(74, 100);  //MainArmor,
            wearPlaceStart[2] = PointRef.Create(194, 100); //Boots,
            wearPlaceStart[3] = PointRef.Create(114, 100); //Helmet,
            wearPlaceStart[4] = PointRef.Create(154, 100); //Gauntlet,
        }

        //indexed by enum WearPlace
        wearPlaceCells = new PointRef[5];
        {
            //new Point(2,4), //LeftHand,
            wearPlaceCells[0] = PointRef.Create(1, 1); //RightHand,
            wearPlaceCells[1] = PointRef.Create(1, 1); //MainArmor,
            wearPlaceCells[2] = PointRef.Create(1, 1); //Boots,
            wearPlaceCells[3] = PointRef.Create(1, 1); //Helmet,
            wearPlaceCells[4] = PointRef.Create(1, 1); //Gauntlet,
        }
        CellCountInPageX = 12;
        CellCountInPageY = 7;
        CellCountTotalX  = 12;
        CellCountTotalY  = 7 * 6;
        CellDrawSize     = 40;
    }
예제 #2
0
        public IEnumerable <PointRef> ItemCells(PointRef p)
        {
            Item item = d_Inventory.Items[new ProtoPoint(p.X, p.Y)];

            for (int x = 0; x < d_Items.ItemSizeX(item); x++)
            {
                for (int y = 0; y < d_Items.ItemSizeY(item); y++)
                {
                    yield return(PointRef.Create(p.X + x, p.Y + y));
                }
            }
        }
예제 #3
0
    PointRef SelectedCell(PointRef scaledMouse)
    {
        if (scaledMouse.X < CellsStartX() || scaledMouse.Y < CellsStartY() ||
            scaledMouse.X > CellsStartX() + CellCountInPageX * CellDrawSize ||
            scaledMouse.Y > CellsStartY() + CellCountInPageY * CellDrawSize)
        {
            return(null);
        }
        PointRef cell = PointRef.Create((scaledMouse.X - CellsStartX()) / CellDrawSize,
                                        (scaledMouse.Y - CellsStartY()) / CellDrawSize);

        return(cell);
    }
예제 #4
0
 public PointRef ItemAtCell(PointRef p)
 {
     foreach (var k in d_Inventory.Items)
     {
         foreach (var pp in ItemCells(PointRef.Create(k.Key.X, k.Key.Y)))
         {
             if (p.X == pp.X && p.Y == pp.Y)
             {
                 return(PointRef.Create(k.Key.X, k.Key.Y));
             }
         }
     }
     return(null);
 }
예제 #5
0
 internal PointRef ItemAtCell(PointRef p)
 {
     for (int i = 0; i < d_Inventory.ItemsCount; i++)
     {
         Packet_PositionItem k    = d_Inventory.Items[i];
         Packet_Item         item = k.Value_;
         for (int x = 0; x < d_Items.ItemSizeX(item); x++)
         {
             for (int y = 0; y < d_Items.ItemSizeY(item); y++)
             {
                 int px = k.X + x;
                 int py = k.Y + y;
                 if (p.X == px && p.Y == py)
                 {
                     return(PointRef.Create(k.X, k.Y));
                 }
             }
         }
     }
     return(null);
 }
예제 #6
0
    internal PointRef[] ItemsAtArea(int pX, int pY, int sizeX, int sizeY, IntRef retCount)
    {
        PointRef[] itemsAtArea      = new PointRef[256];
        int        itemsAtAreaCount = 0;

        for (int xx = 0; xx < sizeX; xx++)
        {
            for (int yy = 0; yy < sizeY; yy++)
            {
                PointRef cell = PointRef.Create(pX + xx, pY + yy);
                if (!IsValidCell(cell))
                {
                    return(null);
                }
                if (ItemAtCell(cell) != null)
                {
                    bool contains = false;
                    for (int i = 0; i < itemsAtAreaCount; i++)
                    {
                        if (itemsAtArea[i] == null)
                        {
                            continue;
                        }
                        if (itemsAtArea[i].X == ItemAtCell(cell).X &&
                            itemsAtArea[i].Y == ItemAtCell(cell).Y)
                        {
                            contains = true;
                        }
                    }
                    if (!contains)
                    {
                        itemsAtArea[itemsAtAreaCount++] = ItemAtCell(cell);
                    }
                }
            }
        }
        retCount.value = itemsAtAreaCount;
        return(itemsAtArea);
    }
예제 #7
0
    public override void OnNewFrameDraw2d(Game game_, float deltaTime)
    {
        game = game_;
        if (dataItems == null)
        {
            dataItems      = new GameDataItemsClient();
            dataItems.game = game_;
            controller     = ClientInventoryController.Create(game_);
            inventoryUtil  = game.d_InventoryUtil;
        }
        if (game.guistate == GuiState.MapLoading)
        {
            return;
        }
        DrawMaterialSelector();
        if (game.guistate != GuiState.Inventory)
        {
            return;
        }
        if (ScrollingUpTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingUpTimeMilliseconds) > 250)
        {
            ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollUp();
        }
        if (ScrollingDownTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingDownTimeMilliseconds) > 250)
        {
            ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollDown();
        }

        PointRef scaledMouse = PointRef.Create(game.mouseCurrentX, game.mouseCurrentY);

        game.Draw2dBitmapFile("inventory.png", InventoryStartX(), InventoryStartY(), 1024, 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
        for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
        {
            Packet_PositionItem k = game.d_Inventory.Items[i];
            if (k == null)
            {
                continue;
            }
            int screeny = k.Y - ScrollLine;
            if (screeny >= 0 && screeny < CellCountInPageY)
            {
                DrawItem(CellsStartX() + k.X * CellDrawSize, CellsStartY() + screeny * CellDrawSize, k.Value_, 0, 0);
            }
        }

        //draw area selection
        if (game.d_Inventory.DragDropItem != null)
        {
            PointRef selectedInPage = SelectedCell(scaledMouse);
            if (selectedInPage != null)
            {
                int x     = (selectedInPage.X) * CellDrawSize + CellsStartX();
                int y     = (selectedInPage.Y) * CellDrawSize + CellsStartY();
                int sizex = dataItems.ItemSizeX(game.d_Inventory.DragDropItem);
                int sizey = dataItems.ItemSizeY(game.d_Inventory.DragDropItem);
                if (selectedInPage.X + sizex <= CellCountInPageX &&
                    selectedInPage.Y + sizey <= CellCountInPageY)
                {
                    int        c;
                    IntRef     itemsAtAreaCount = new IntRef();
                    PointRef[] itemsAtArea      = inventoryUtil.ItemsAtArea(selectedInPage.X, selectedInPage.Y + ScrollLine, sizex, sizey, itemsAtAreaCount);
                    if (itemsAtArea == null || itemsAtAreaCount.value > 1)
                    {
                        c = Game.ColorFromArgb(100, 255, 0, 0); // red
                    }
                    else //0 or 1
                    {
                        c = Game.ColorFromArgb(100, 0, 255, 0); // green
                    }
                    game.Draw2dTexture(game.WhiteTexture(), x, y,
                                       CellDrawSize * sizex, CellDrawSize * sizey,
                                       null, 0, c, false);
                }
            }
            IntRef selectedWear = SelectedWearPlace(scaledMouse);
            if (selectedWear != null)
            {
                PointRef p    = PointRef.Create(wearPlaceStart[selectedWear.value].X + InventoryStartX(), wearPlaceStart[selectedWear.value].Y + InventoryStartY());
                PointRef size = wearPlaceCells[selectedWear.value];

                int         c;
                Packet_Item itemsAtArea = inventoryUtil.ItemAtWearPlace(selectedWear.value, game.ActiveMaterial);
                if (!dataItems.CanWear(selectedWear.value, game.d_Inventory.DragDropItem))
                {
                    c = Game.ColorFromArgb(100, 255, 0, 0); // red
                }
                else //0 or 1
                {
                    c = Game.ColorFromArgb(100, 0, 255, 0); // green
                }
                game.Draw2dTexture(game.WhiteTexture(), p.X, p.Y,
                                   CellDrawSize * size.X, CellDrawSize * size.Y,
                                   null, 0, c, false);
            }
        }

        //material selector
        DrawMaterialSelector();

        //wear
        //DrawItem(Offset(wearPlaceStart[(int)WearPlace.LeftHand], InventoryStart), inventory.LeftHand[ActiveMaterial.ActiveMaterial], null);
        DrawItem(wearPlaceStart[WearPlace_.RightHand].X + InventoryStartX(), wearPlaceStart[WearPlace_.RightHand].Y + InventoryStartY(), game.d_Inventory.RightHand[game.ActiveMaterial], 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.MainArmor].X + InventoryStartX(), wearPlaceStart[WearPlace_.MainArmor].Y + InventoryStartY(), game.d_Inventory.MainArmor, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Boots].X + InventoryStartX(), wearPlaceStart[WearPlace_.Boots].Y + InventoryStartY(), game.d_Inventory.Boots, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Helmet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Helmet].Y + InventoryStartY(), game.d_Inventory.Helmet, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Gauntlet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Gauntlet].Y + InventoryStartY(), game.d_Inventory.Gauntlet, 0, 0);

        //info
        if (SelectedCell(scaledMouse) != null)
        {
            PointRef selected = SelectedCell(scaledMouse);
            selected.Y += ScrollLine;
            PointRef itemAtCell = inventoryUtil.ItemAtCell(selected);
            if (itemAtCell != null)
            {
                Packet_Item item = GetItem(game.d_Inventory, itemAtCell.X, itemAtCell.Y);
                if (item != null)
                {
                    int x = (selected.X) * CellDrawSize + CellsStartX();
                    int y = (selected.Y) * CellDrawSize + CellsStartY();
                    DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
                }
            }
        }
        if (SelectedWearPlace(scaledMouse) != null)
        {
            int         selected        = SelectedWearPlace(scaledMouse).value;
            Packet_Item itemAtWearPlace = inventoryUtil.ItemAtWearPlace(selected, game.ActiveMaterial);
            if (itemAtWearPlace != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, itemAtWearPlace);
            }
        }
        if (SelectedMaterialSelectorSlot(scaledMouse) != null)
        {
            int         selected = SelectedMaterialSelectorSlot(scaledMouse).value;
            Packet_Item item     = game.d_Inventory.RightHand[selected];
            if (item != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
            }
        }

        if (game.d_Inventory.DragDropItem != null)
        {
            DrawItem(scaledMouse.X, scaledMouse.Y, game.d_Inventory.DragDropItem, 0, 0);
        }
    }
예제 #8
0
    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;
    }