Esempio n. 1
0
 private void DrawHeldItem(Graphics g)
 {
     if (this.HeldItem != null)
     {
         float slotSize = StorageGui.GetSlotSize(this.ClientSize);
         this.HeldItem.Paint(g, new PointF(this.CursorLocation.X - (slotSize - slotSize / 4) / 2, this.CursorLocation.Y - (slotSize - slotSize / 4) / 2), slotSize - slotSize / 4);
     }
 }
Esempio n. 2
0
        private void DrawInventory(Graphics g)
        {
            float slotSize = StorageGui.GetSlotSize(this.ClientSize);
            float upSide   = this.ClientSize.Height / (float)2 - slotSize * 4;

            g.FillRectangle(Brushes.Khaki, 0, upSide - slotSize / 8, slotSize + slotSize / 8, slotSize * 8 + slotSize / 4);
            g.FillRectangle(Brushes.White, 0, upSide, slotSize, slotSize * 8);
            for (int i = 0; i < 8; i++)
            {
                g.FillRectangle(Brushes.Green, slotSize / 16, upSide + i * slotSize + slotSize / 16, slotSize - slotSize / 8, slotSize - slotSize / 8);
                if (this.Inventory[i] != null)
                {
                    this.Inventory[i].Paint(g, new PointF(slotSize / 8, upSide + i * slotSize + slotSize / 8), slotSize - slotSize / 4);
                }
            }
        }
Esempio n. 3
0
        private void MainForm_MouseClick(object sender, MouseEventArgs e)
        {
            float slotSize        = StorageGui.GetSlotSize(this.ClientSize);
            float inventoryUpSide = this.ClientSize.Height / 2 - slotSize * 4;

            if (new Rectangle(0, (int)(inventoryUpSide - slotSize / 16), (int)(slotSize + slotSize / 16), (int)(slotSize * 8 + slotSize / 8)).Contains(e.Location))
            {
                if (e.X >= slotSize / 16 && e.X < slotSize - slotSize / 16 && e.Y >= inventoryUpSide && e.Y < this.ClientSize.Height + slotSize * 4)
                {
                    float inSlotLocationY = (e.Y - inventoryUpSide) % slotSize;
                    if (inSlotLocationY >= slotSize / 16 && inSlotLocationY < slotSize - slotSize / 16)
                    {
                        int  slotIndex   = (int)Math.Floor((e.Y - inventoryUpSide) / slotSize);
                        Item oldHeldItem = this.HeldItem;
                        this.HeldItem             = this.Inventory[slotIndex];
                        this.Inventory[slotIndex] = oldHeldItem;
                    }
                }
            }
            else
            {
                if (this.CurrentGui != null)
                {
                    this.CurrentGui.Click(this, e);
                }
                else
                {
                    float objectPreferredLeftEdge = ToScreenSize(544);
                    if (e.X >= objectPreferredLeftEdge && e.X < this.ToScreenSize(736))
                    {
                        float gameSizeYLocation = this.ViewPosition + ToGameSize(e.Y);
                        float pixelsReached     = 128;
                        for (int i = 0; i < this.RoadObjects.Count; i++)
                        {
                            pixelsReached += this.RoadObjects[i].GetHeight(192);
                            if (pixelsReached > gameSizeYLocation)
                            {
                                this.RoadObjects[i].Click(this, e, new Point((int)objectPreferredLeftEdge, (int)this.ToScreenSize(pixelsReached - this.RoadObjects[i].GetHeight(192) - this.ViewPosition)), this.ToScreenSize(192));
                                break;
                            }
                        }
                    }
                    else if (e.X >= this.ClientSize.Width * 3 / (float)4)
                    {
                        int  catchableItemX = (int)Math.Floor((e.X - this.ClientSize.Width * 3 / (float)4) / (this.ClientSize.Width / (float)16));
                        int  catchableItemY = (int)Math.Floor((this.ViewPosition + this.ToGameSize(e.Y) + 64 - this.CatchableItemsState) / 64);
                        bool found          = false;
                        for (int i = 0; i < this.CatchableItems.Count; i++)
                        {
                            if (this.CatchableItems[i].PositionX == catchableItemX && this.CatchableItems[i].PositionY == catchableItemY)
                            {
                                Item oldHeldItem = this.HeldItem;
                                this.HeldItem = this.CatchableItems[i].Item;
                                if (oldHeldItem != null)
                                {
                                    CatchableItem newCatchableItem = new CatchableItem(oldHeldItem, (byte)catchableItemX, catchableItemY);
                                    this.CatchableItems[i] = newCatchableItem;
                                }
                                else
                                {
                                    this.CatchableItems.RemoveAt(i);
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found && this.HeldItem != null)
                        {
                            CatchableItem newCatchableItem = new CatchableItem(this.HeldItem, (byte)catchableItemX, catchableItemY);
                            this.CatchableItems.Add(newCatchableItem);
                            this.HeldItem = null;
                        }
                    }
                }
            }
        }