Forum rules - please read before posting.

Inventory Drag'n'drop and click working simultaneously

Hi.
Is it possible to make Drag'n'drop and click methods working simultaneously? 

Comments

  • I can't really picture how that would work - once you let go in drag-and-drop mode, that deselects the item before a click is possible.  Can you elaborate on what it is exactly you're after?

    It is certainly possible to change between the two modes at any time through script.
  • Hi, Chris

    When a player clicks on the inventory item it should become selected and ready to use wherever on the scene through click&click mode.
    But if a player starts to drag the item from the inventory it should glue to the cursor and be ready for implementation on the scene through drag&drop mode.

    We are trying to switch between the two modes through the script, but no luck.

    This technique works great in our casual adventures. 
  • Indeed, it'd be very difficult to do by modifying the code - but I think you should have luck using custom events.

    With events, you can enable drag-and-drop when you first hover over the inventory, and then - if the player combines an item with itself (i.e. single clicks an item), disable dnd and force-select the item.

    Try this:
    http://pasteall.org/953919/csharp
  • Hi

    Hope it's okay to resurrect an old thread like this.
    Would it be possible to re-post this code?

    And now we're at it - I've found several interesting code bits from the past on this forum that I wanted to explore, but they're all from Pasteall and these links don't work anymore.

    It would be great to have these updated so the code-bits were accessible again.
    There's probably a lot of goodies there that people searching the forum now cannot access...

  • I don't have it to hand, but I've tried to re-write what it likely was here:

    using UnityEngine;
    using AC;
    
    public class MenuEventTest : MonoBehaviour
    {
    
        private bool canSelect;
    
    
        private void OnEnable ()
        {
            EventManager.OnMouseOverMenu += OnMouseOverMenu;
            EventManager.OnInventoryCombine_Alt += OnInventoryCombine;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnMouseOverMenu -= OnMouseOverMenu;
            EventManager.OnInventoryCombine_Alt -= OnInventoryCombine;
        }
    
    
        private void OnMouseOverMenu (Menu menu, MenuElement element, int slot)
        {
            if (element == null) return;
    
            MenuInventoryBox inventoryBox = element as MenuInventoryBox;
            if (inventoryBox is MenuInventoryBox)
            {
                if (KickStarter.runtimeInventory.SelectedItem == null)
                {
                    KickStarter.settingsManager.inventoryDragDrop = true;
                    canSelect = true;
                }
                else if (canSelect)
                {
                    InvItem hoverItem = inventoryBox.GetItem (slot);
                    if (hoverItem == null || hoverItem.id != KickStarter.runtimeInventory.SelectedItem.id)
                    {
                        canSelect = false;
                    }
                }
            }
        }
    
    
        private void OnInventoryCombine (InvInstance invInstanceA, InvInstance invInstanceB)
        {
            if (invInstanceA == invInstanceB && canSelect)
            {
                KickStarter.settingsManager.inventoryDragDrop = false;
                invInstanceA.Select ();
            }
        }
    
    }
    

    For a repository of handy scripts, check the wiki: https://adventure-creator.fandom.com/wiki/Category:General

  • Hi Chris
    Thanks for such a quick reply on a holy Sunday :-)
    Yes, the wiki is a great place for scipting clues - I go there often!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.