Exemplo n.º 1
0
        public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button)
        {
            PendingClose = false;
            if (button != MouseButton.Left)
            {
                return(false);
            }

            if (scroll.HandlesMouseClick(mouseX, mouseY, button))
            {
                return(true);
            }
            else if (SelectedIndex != -1)
            {
                game.Inventory.Selected = Elements[SelectedIndex];
                PendingClose            = true;
                return(true);
            }
            else if (Contains(TableX, TableY, TableWidth, TableHeight, mouseX, mouseY))
            {
                return(true);
            }
            return(false);
        }
        public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button)
        {
            PendingClose = false;
            if (button == MouseButton.Right)
            {
                if (!CraftingSelected)
                {
                    if (SelectedIndex == -1)
                    {
                        return(false);
                    }
                    Item item;
                    if (itemList[SelectedIndex] != null &&
                        cursorItem != null &&
                        itemList[SelectedIndex].id == cursorItem.id &&
                        itemList[SelectedIndex].Count < 64)
                    {
                        itemList[SelectedIndex].Count += 1;
                        cursorItem.Count -= 1;
                        if (cursorItem.Count == 0)
                        {
                            cursorItem = null;
                        }
                        return(true);
                    }
                    else if (itemList[SelectedIndex] == null &&
                             cursorItem != null)
                    {
                        itemList[SelectedIndex] = new Item(1, cursorItem.id);
                        cursorItem.Count       -= 1;
                        if (cursorItem.Count == 0)
                        {
                            cursorItem = null;
                        }
                        return(true);
                    }
                    if (itemList[SelectedIndex] != null && cursorItem == null)
                    {
                        item       = new Item(1, itemList[SelectedIndex].id);
                        cursorItem = item;
                        itemList[SelectedIndex].Count -= 1;
                        if (itemList[SelectedIndex].Count == 0)
                        {
                            itemList[SelectedIndex] = null;
                        }
                        return(true);
                    }            /* else if (game.SurvInv.ItemList[SelectedIndex] == null && cursorItem != null) {
                                  *     game.SurvInv.ItemList[SelectedIndex] = cursorItem;
                                  *     cursorItem = null;
                                  * } else {
                                  *     item = cursorItem;
                                  *     cursorItem = game.SurvInv.ItemList[SelectedIndex];
                                  *     game.SurvInv.ItemList[SelectedIndex] = item;
                                  * }*/
                }
                else if (CraftingSelected)
                {
                    if (SelectedIndex == -1)
                    {
                        return(false);
                    }
                    Item item;
                    if (CraftingItems[SelectedIndex] != null &&
                        cursorItem != null &&
                        CraftingItems[SelectedIndex].id == cursorItem.id &&
                        CraftingItems[SelectedIndex].Count < 64)
                    {
                        CraftingItems[SelectedIndex].Count += 1;
                        cursorItem.Count -= 1;
                        if (cursorItem.Count == 0)
                        {
                            cursorItem = null;
                        }
                        RecalcRecipe();
                        return(true);
                    }
                    else if (CraftingItems[SelectedIndex] == null &&
                             cursorItem != null)
                    {
                        CraftingItems[SelectedIndex] = new Item(1, cursorItem.id);
                        cursorItem.Count            -= 1;
                        if (cursorItem.Count == 0)
                        {
                            cursorItem = null;
                        }
                        RecalcRecipe();
                        return(true);
                    }
                    if (CraftingItems[SelectedIndex] != null && cursorItem == null)
                    {
                        item       = new Item(1, CraftingItems[SelectedIndex].id);
                        cursorItem = item;
                        CraftingItems[SelectedIndex].Count -= 1;
                        if (CraftingItems[SelectedIndex].Count == 0)
                        {
                            CraftingItems[SelectedIndex] = null;
                        }
                        RecalcRecipe();
                        return(true);
                    }            /* else if (CraftingItems[SelectedIndex] == null && cursorItem != null) {
                                  *     CraftingItems[SelectedIndex] = cursorItem;
                                  *     cursorItem = null;
                                  * } else {
                                  *     item = cursorItem;
                                  *     cursorItem = CraftingItems[SelectedIndex];
                                  *     CraftingItems[SelectedIndex] = item;
                                  * }*/
                }
                return(false);
            }
            else if (button != MouseButton.Left)
            {
                return(false);
            }

            if (scroll.HandlesMouseClick(mouseX, mouseY, button))
            {
                return(true);
            }
            else if (SelectedIndex != -1)
            {
                //game.Inventory.Selected = Elements[SelectedIndex];
                //PendingClose = true;
                if (!CraftingSelected && !CraftedSelected)
                {
                    if (itemList[SelectedIndex] != null &&
                        cursorItem != null &&
                        itemList[SelectedIndex].id == cursorItem.id &&
                        itemList[SelectedIndex].Count < 64)
                    {
                        if (itemList[SelectedIndex].Count + cursorItem.Count > 64)
                        {
                            cursorItem.Count = (sbyte)((itemList[SelectedIndex].Count + cursorItem.Count) - 64);
                            itemList[SelectedIndex].Count = 64;
                            return(true);
                        }
                        else if (itemList[SelectedIndex].Count + cursorItem.Count <= 64)
                        {
                            itemList[SelectedIndex].Count += cursorItem.Count;
                            cursorItem = null;
                            return(true);
                        }
                    }
                    if (itemList[SelectedIndex] != null && cursorItem == null)
                    {
                        cursorItem = NewItem(itemList[SelectedIndex]);
                        itemList[SelectedIndex] = null;
                    }
                    else if (itemList[SelectedIndex] == null && cursorItem != null)
                    {
                        itemList[SelectedIndex] = cursorItem;
                        cursorItem = null;
                    }
                    else if (itemList[SelectedIndex] != null && cursorItem != null)
                    {
                        Item item = cursorItem;
                        cursorItem = NewItem(itemList[SelectedIndex]);
                        itemList[SelectedIndex] = item;
                    }
                }
                else if (CraftingSelected)
                {
                    if (CraftingItems[SelectedIndex] != null &&
                        cursorItem != null &&
                        CraftingItems[SelectedIndex].id == cursorItem.id &&
                        CraftingItems[SelectedIndex].Count < 64)
                    {
                        if (CraftingItems[SelectedIndex].Count + cursorItem.Count > 64)
                        {
                            cursorItem.Count = (sbyte)((CraftingItems[SelectedIndex].Count + cursorItem.Count) - 64);
                            CraftingItems[SelectedIndex].Count = 64;
                            RecalcRecipe();
                            return(true);
                        }
                        else if (CraftingItems[SelectedIndex].Count + cursorItem.Count <= 64)
                        {
                            CraftingItems[SelectedIndex].Count += cursorItem.Count;
                            cursorItem = null;
                            RecalcRecipe();
                            return(true);
                        }
                    }
                    if (CraftingItems[SelectedIndex] != null && cursorItem == null)
                    {
                        cursorItem = NewItem(CraftingItems[SelectedIndex]);
                        CraftingItems[SelectedIndex] = null;
                        RecalcRecipe();
                    }
                    else if (CraftingItems[SelectedIndex] == null && cursorItem != null)
                    {
                        CraftingItems[SelectedIndex] = cursorItem;
                        cursorItem = null;
                        RecalcRecipe();
                    }
                    else if (CraftingItems[SelectedIndex] != null && cursorItem != null)
                    {
                        Item item = cursorItem;
                        cursorItem = NewItem(CraftingItems[SelectedIndex]);
                        CraftingItems[SelectedIndex] = item;
                        RecalcRecipe();
                    }
                }
                else if (CraftedSelected)
                {
                    if (CraftedItem != null &&
                        cursorItem != null &&
                        CraftedItem.id == cursorItem.id &&
                        cursorItem.Count < 64)
                    {
                        if (CraftedItem.Count + cursorItem.Count <= 64)
                        {
                            cursorItem.Count += CraftedItem.Count;
                            CraftedItem       = null;
                            SubtractRecipe(game.RecipeList[RecipeIndex]);
                            RecalcRecipe();
                            return(true);
                        }
                    }
                    if (CraftedItem != null && cursorItem == null)
                    {
                        cursorItem  = NewItem(CraftedItem);
                        CraftedItem = null;
                        SubtractRecipe(game.RecipeList[RecipeIndex]);
                        RecalcRecipe();
                    }
                }
                return(true);
            }
            else if (Contains(TableX, TableY, TableWidth, TableHeight, mouseX, mouseY))
            {
                return(true);
            }
            return(false);
        }