Пример #1
0
        public void Update()
        {
            if (IsHovered && Input.GetKeyDown(KeyCode.G))
            {
                if (SlotsObject.Slots[Y, X] != null)
                {
                    Debug.Log("DROP");
                    // TODO: Item can bug into other blogs when dropped right next to them, because position is absolute
                    Vector3 newPos = new Vector3(SlotsObject.Owner.transform.position.x + 0.5f,
                                                 SlotsObject.Owner.transform.position.y + 0.5f);
                    GameObject current = Instantiate(InventoryItem.ItemDefinition.Prefab, newPos, Quaternion.identity);
                    current.transform.parent = PrefabRepository.Instance.Map.transform.GetChild(2);
                    ItemInstance itemInstance = new ItemInstance(InventoryItem.ItemDefinition.ItemType, current);
                    current.GetComponent <ItemBehaviour>().Instance = itemInstance;
                    PrefabRepository.Instance.World.Items.Add(itemInstance);
                    if (SlotsObject.Slots[Y, X].Count - 1 < 1)
                    {
                        SlotsObject.Slots[Y, X] = null;
                    }
                    else
                    {
                        SlotsObject.Slots[Y, X].Count--;
                    }
                    Destroy(gameObject);

                    SaveChangesInventoryItemBar(SlotsObject.Owner);

                    SlotsObject.DeleteGui();
                    SlotsObject.DrawUi();
                }
            }
        }
Пример #2
0
        public static GameObject DrawItemSlotWithSpriteAndDetails(
            int y,
            int x,
            string mainPrefix,
            InventoryItem currentInventoryItem,
            Transform parent,
            SlotsObject slotsObject,
            float leftPadding,
            float bottomPadding,
            bool isSelected,
            GameObject[,] gameObjectSlots)
        {
            // create basic slot
            GameObject    slot          = CreateBasicEmptySlot(y, x, mainPrefix + "Slot", parent, leftPadding, bottomPadding);
            InventorySlot inventorySlot = slot.AddComponent <InventorySlot>();

            inventorySlot.InventoryItem = currentInventoryItem;
            inventorySlot.SlotsObject   = slotsObject;
            inventorySlot.X             = x;
            inventorySlot.Y             = y;
            inventorySlot.IsSelected    = isSelected;
            gameObjectSlots[y, x]       = slot;
            if (currentInventoryItem != null)
            {
                // create image for sprite
                GameObject slotItem = CreateBasicEmptySlot(y, x, mainPrefix + "Item", parent, leftPadding, bottomPadding);
                Image      image    = slotItem.GetComponent <Image>();
                image.sprite = currentInventoryItem.ItemDefinition.Sprite;
                image.rectTransform.sizeDelta = new Vector2(SlotSize * 0.9f, SlotSize * 0.9f);
                slotItem.transform.SetParent(slot.transform);

                //create image for count
                GameObject prefab     = PrefabRepository.Instance.InventoryCountText;
                GameObject slotCount  = GameObject.Instantiate(prefab, new Vector3(), Quaternion.identity);
                Text       imageCount = slotCount.GetComponent <Text>();
                imageCount.text = currentInventoryItem.Count.ToString();
                slotCount.transform.position =
                    new Vector3(leftPadding + x * (SlotSize + SlotMargin) + (SlotSize) / 4,
                                bottomPadding - y * (SlotSize + SlotMargin) - (SlotSize) / 4);
                slotCount.transform.SetParent(slot.transform);
            }
            return(slot);
        }
Пример #3
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            Debug.Log("Drag-start event triggered");
            SlotsObject.CurrentDraggingItem = null;
            if (SlotsObject.CurrentDraggingImageItem != null)
            {
                GameObject.Destroy(SlotsObject.CurrentDraggingImageItem);
                SlotsObject.CurrentDraggingImageItem = null;
            }
            if (SlotsObject.Slots[Y, X] != null)
            {
                Debug.Log("START DRAG - " + Y + "/" + X);
                if (Input.GetMouseButton(0) && Input.GetKey(KeyCode.LeftControl))
                {
                    if (SlotsObject.Slots[Y, X] != null)
                    {
                        int cnt = SlotsObject.Slots[Y, X].Count;
                        cnt /= 2;
                        if (cnt <= 0)
                        {
                            cnt = SlotsObject.Slots[Y, X].Count;
                        }

                        SlotsObject.CurrentDraggingItem =
                            new InventoryItem(SlotsObject.Slots[Y, X].ItemDefinition, cnt);
                        if (SlotsObject.Slots[Y, X].Count - cnt <= 0)
                        {
                            SlotsObject.Slots[Y, X] = null;
                        }
                        else
                        {
                            SlotsObject.Slots[Y, X].Count -= cnt;
                        }
                    }
                }
                else if (Input.GetMouseButton(0))
                {
                    if (SlotsObject.Slots[Y, X] != null)
                    {
                        SlotsObject.CurrentDraggingItem = SlotsObject.Slots[Y, X];
                        SlotsObject.Slots[Y, X]         = null;
                    }
                }
                else if (Input.GetMouseButton(1))
                {
                    if (SlotsObject.Slots[Y, X] != null)
                    {
                        SlotsObject.CurrentDraggingItem = new InventoryItem(SlotsObject.Slots[Y, X].ItemDefinition, 1);
                        SlotsObject.Slots[Y, X].Count--;
                        if (SlotsObject.Slots[Y, X].Count <= 0)
                        {
                            SlotsObject.Slots[Y, X] = null;
                        }
                    }
                }
                SlotsObject.DraggingStartPosition = new Vector2Int(X, Y);
                SlotsObject.DeleteGuiSlotAtPosition(X, Y);
                SlotsObject.DrawGuiSlotAtPosition(X, Y, IsSelected);

                SlotsObject.CurrentDraggingImageItem = new GameObject("CurrentDraggingImageItem");
                Image image = SlotsObject.CurrentDraggingImageItem.AddComponent <Image>();
                image.sprite = PrefabRepository.Instance
                               .ItemDefinitions[SlotsObject.CurrentDraggingItem.ItemDefinition.ItemType].Sprite;
                image.transform.position      = Input.mousePosition + new Vector3(20, -20);
                image.rectTransform.sizeDelta =
                    new Vector2(SlotController.SlotSize * 0.6f, SlotController.SlotSize * 0.6f);
                image.transform.SetParent(PrefabRepository.Instance.GuiInventory.transform);

                GameObject prefab     = PrefabRepository.Instance.InventoryCountText;
                GameObject slotCount  = Instantiate(prefab, new Vector3(), Quaternion.identity);
                Text       imageCount = slotCount.GetComponent <Text>();
                imageCount.text = SlotsObject.CurrentDraggingItem.Count.ToString();
                imageCount.transform.SetParent(image.transform);
                imageCount.transform.position = Input.mousePosition + new Vector3(30, -30);
            }
        }
Пример #4
0
        public void OnEndDrag(PointerEventData eventData)
        {
            Debug.Log("Drag-end event triggered");
            if (SlotsObject.CurrentDraggingItem != null)
            {
                GameObject.Destroy(SlotsObject.CurrentDraggingImageItem);
                SlotsObject.CurrentDraggingImageItem = null;

                SlotsObject curSlotObject = null;
                if (SlotsObject.Owner.Inventory.SelectedSlotPosition != null)
                {
                    curSlotObject = SlotsObject.Owner.Inventory;
                }
                else if (SlotsObject.Owner.ItemBar.SelectedSlotPosition != null)
                {
                    curSlotObject = SlotsObject.Owner.ItemBar;
                }

                if (curSlotObject == null)
                {
                    SlotsObject.Slots[Y, X] = SlotsObject.CurrentDraggingItem;
                    SlotsObject.DeleteGui();
                    SlotsObject.DrawUi();
                    Debug.Log("Reset dragging");
                }
                else
                {
                    InventoryItem help = curSlotObject.Slots[curSlotObject.SelectedSlotPosition.Value.y,
                                                             curSlotObject.SelectedSlotPosition.Value.x];
                    if (help != null &&
                        help.ItemDefinition.ItemType == SlotsObject.CurrentDraggingItem.ItemDefinition.ItemType &&
                        help.Count + SlotsObject.CurrentDraggingItem.Count <= ItemDefinition.MaxItemCount)
                    {
                        curSlotObject.Slots[curSlotObject.SelectedSlotPosition.Value.y,
                                            curSlotObject.SelectedSlotPosition.Value.x].Count +=
                            SlotsObject.CurrentDraggingItem.Count;
                    }
                    else if (help != null)
                    {
                        // help.Count + SlotsObject.CurrentDraggingItem.Count <
                        SlotsObject.Slots[SlotsObject.DraggingStartPosition.y,
                                          SlotsObject.DraggingStartPosition.x] = help;
                        SlotsObject.DeleteGui();
                        SlotsObject.DrawUi();
                        curSlotObject.Slots[curSlotObject.SelectedSlotPosition.Value.y,
                                            curSlotObject.SelectedSlotPosition.Value.x] =
                            SlotsObject.CurrentDraggingItem;
                    }
                    else
                    {
                        curSlotObject.Slots[curSlotObject.SelectedSlotPosition.Value.y,
                                            curSlotObject.SelectedSlotPosition.Value.x] =
                            SlotsObject.CurrentDraggingItem;
                    }
                    curSlotObject.DeleteGui();
                    curSlotObject.DrawUi();

                    var itemBar = curSlotObject as ItemBar;
                    if (itemBar != null)
                    {
                        itemBar.UpdateSelectedItemGameObject();
                    }

                    SaveChangesInventoryItemBar(SlotsObject.Owner);
                    Debug.Log("END DRAG - " + curSlotObject.SelectedSlotPosition.Value.y + "/" +
                              curSlotObject.SelectedSlotPosition.Value.x);
                }
            }
        }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (GameData.instance.atTitleScreen)
        {
            return;
        }
        StartCoroutine(MovementUpdate());
        movingHitbox.transform.position = targetPos;


        disabled = isDisabled;
        playerAnim.SetFloat("walkbikesurfstate", (int)walkSurfBikeState);
        if (viewBio.bioscreen.enabled)
        {
            isDisabled = true;
        }


        if (!isDisabled && !menuActive && !startMenuActive)
        {
            if (Inputs.pressed("start") && !isMoving)
            {
                SoundManager.instance.sfx.PlayOneShot(openStartMenuClip);
                startMenuActive = true;
                mainMenu.gameObject.SetActive(true);
                mainMenu.Initialize();
            }
            top.SetActive(!isDisabled);
            bottom.SetActive(!isDisabled);

            playerAnim.SetInteger("movedirection", (int)direction + 1);

            if (Inputs.released("down") || Inputs.released("right") || Inputs.released("left") || Inputs.released("up"))
            {
                if (!manuallyWalking)
                {
                    holdingDirection = false;
                }
            }
        }


        if (facedObject != null)
        {
            NPC npc = null;
            if (facedObject != null)
            {
                npc = facedObject.GetComponent <NPC>();
            }
            if (!holdingDirection && transform.position == targetPos)
            {
                if (!holdingDirection && !isMoving && !isDisabled && Dialogue.instance.finishedText && !startMenuActive && !menuActive && !inBattle && !ledgejumping)
                {
                    if (Inputs.pressed("a"))
                    {
                        if (npc != null && !npc.isMoving)
                        {
                            npc.FacePlayer();
                            if (npc.isTrainer)
                            {
                                npc.StartEncounter();
                            }
                            else
                            {
                                StartCoroutine(npc.NPCText());
                            }
                            return;
                        }
                        if (facedObject != null)
                        {
                            switch (facedObject.tag) //what tag does the interactable object have?
                            {
                            case "Slots":
                                SlotsObject dialogueSlots = facedObject.GetComponent <SlotsObject>();
                                StartCoroutine(dialogueSlots.PlayDialogue());
                                return;

                            case "Pokeball":
                                Pokeball pokeball = facedObject.GetComponent <Pokeball>();
                                pokeball.GetItem(pokeball.item);
                                return;
                            }
                        }
                    }
                }
            }
        }
        CheckObjectCollision();
    }