Ejemplo n.º 1
0
 private void Take(ItemContainerBehaviour container)
 {
     if (!IsInvoking(nameof(DisableOptions)) && !IsInvoking("EnableOptions"))
     {
         if (GameObjectUtilities.FindGameObject("Game/Canvas/ItemPanel/ItemContainer_Inventory").GetComponent <ItemContainerBehaviour>().TryGetItem(out var inventory))
         {
             PlayerCommands.SwapInventoryItem(Id, container.ContainerIndex, inventory.Id);
         }
         else
         {
             PlayerCommands.PickupItem(Id);
         }
     }
 }
Ejemplo n.º 2
0
 private void Move(ItemContainerBehaviour container, Director director)
 {
     if (!IsInvoking(nameof(DisableOptions)) && !IsInvoking("EnableOptions"))
     {
         Invoke("OptionsDelay", Time.smoothDeltaTime * 2);
         _moveState = true;
         ResetOptions();
         var currentLocation    = director.Player.CurrentLocationEntity;
         var subsystemBehaviour = currentLocation.EntityBehaviour as SubsystemBehaviour;
         if (subsystemBehaviour != null && subsystemBehaviour.ItemStorage != null)
         {
             var containers = subsystemBehaviour.GetComponentsInChildren <ItemContainerBehaviour>().Where(c => c != container).ToList();
             foreach (var systemContainer in containers)
             {
                 systemContainer.Highlight(this, container);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void OnPointerClick(ItemContainerBehaviour container, Director director)
        {
            if (director.Player.CurrentLocationEntity.EntityBehaviour.Entity.CreatedFromArchetype != nameof(ConnectionNode) && !_selectionOptions.activeSelf && CanActivate && !IsInvoking("OptionsDelay") && !IsInvoking(nameof(ResetOptions)) && !IsInvoking("EnableOptions"))
            {
                _leftButton.transform.localScale             = Vector3.one;
                _rightButton.transform.localScale            = Vector3.one;
                _middleButton.transform.localScale           = Vector3.one;
                _descriptionText.transform.parent.localScale = Vector3.one;
                GetComponent <Canvas>().sortingOrder         = 100;
                Invoke("OptionsDelay", Time.smoothDeltaTime * 2);
                Invoke("EnableOptions", 0.34f);
                _selectionOptions.SetActive(true);
                if (container.CanRelease && CanActivate && CurrentLocation.Value != null)
                {
                    var validMoveExists    = true;
                    var currentLocation    = director.Player.CurrentLocationEntity;
                    var subsystemBehaviour = currentLocation.EntityBehaviour as SubsystemBehaviour;
                    if (subsystemBehaviour != null && subsystemBehaviour.ItemStorage != null)
                    {
                        var containers = subsystemBehaviour.GetComponentsInChildren <ItemContainerBehaviour>().Where(c => c != container).ToList();
                        validMoveExists = containers.Any(c => c.CanContain(Id) && c.IsEnabled && (!c.TryGetItem(out var cItem) || container.CanContain(cItem.Id)));
                    }
                    GameObjectUtilities.FindGameObject("Game/Canvas/ItemPanel/ItemContainer_Inventory").GetComponent <ItemContainerBehaviour>().TryGetItem(out var inventory);
                    var canTake = !inventory || container.CanContain(inventory.Id);
                    _leftButton.SetActive(Director.CommandSystem.TryGetHandler(typeof(ActivateItemCommand), out var activateHandler) && activateHandler.Enabled);
                    _leftButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _leftButton.GetComponent <Button>().onClick.AddListener(Use);
                    _leftButton.GetComponentInChildren <Text>().text            = Localization.Get("USE_BUTTON");
                    _leftButton.GetComponentInChildren <TextLocalization>().Key = "USE_BUTTON";
                    _rightButton.SetActive(canTake && Director.CommandSystem.TryGetHandler(typeof(PickupItemCommand), out var pickUpHandler) && pickUpHandler.Enabled && Director.CommandSystem.TryGetHandler(typeof(SwapInventoryItemCommand), out pickUpHandler) && pickUpHandler.Enabled);
                    _rightButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _rightButton.GetComponent <Button>().onClick.AddListener(() => Take(container));
                    _rightButton.GetComponentInChildren <Text>().text            = Localization.Get("TAKE_BUTTON");
                    _rightButton.GetComponentInChildren <TextLocalization>().Key = "TAKE_BUTTON";
                    _middleButton.SetActive(validMoveExists && Director.CommandSystem.TryGetHandler(typeof(MoveItemCommand), out var moveHandler) && moveHandler.Enabled && Director.CommandSystem.TryGetHandler(typeof(SwapSubsystemItemCommand), out moveHandler) && moveHandler.Enabled);
                    _middleButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _middleButton.GetComponent <Button>().onClick.AddListener(() => Move(container, director));
                    _middleButton.GetComponentInChildren <Text>().text            = Localization.Get("MOVE_BUTTON");
                    _middleButton.GetComponentInChildren <TextLocalization>().Key = "MOVE_BUTTON";
                    var bestFitSize = _selectionOptions.GetComponentsInChildren <Button>().BestFit(true, new List <string> {
                        Localization.Get("USE_BUTTON"), Localization.Get("MOVE_BUTTON"), Localization.Get("TAKE_BUTTON")
                    });
                    _descriptionText.fontSize = bestFitSize;
                }
                else if (!container.CanRelease && CanActivate && CurrentLocation.Value != null)
                {
                    _leftButton.SetActive(false);
                    _rightButton.SetActive(false);
                    _middleButton.SetActive(Director.CommandSystem.TryGetHandler(typeof(ActivateItemCommand), out var activateHandler) && activateHandler.Enabled);
                    _leftButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _rightButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _middleButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _middleButton.GetComponent <Button>().onClick.AddListener(Use);
                    _middleButton.GetComponentInChildren <Text>().text            = Localization.Get("USE_BUTTON");
                    _middleButton.GetComponentInChildren <TextLocalization>().Key = "USE_BUTTON";
                    var bestFitSize = _selectionOptions.GetComponentsInChildren <Button>().BestFit(true, new List <string> {
                        Localization.Get("USE_BUTTON"), Localization.Get("MOVE_BUTTON"), Localization.Get("TAKE_BUTTON")
                    });
                    _descriptionText.fontSize = bestFitSize;
                }
                else if (CurrentLocation.Value == null)
                {
                    _leftButton.SetActive(Director.CommandSystem.TryGetHandler(typeof(DropAndActivateItemCommand), out var dropAndActivateHandler) && dropAndActivateHandler.Enabled && Director.CommandSystem.TryGetHandler(typeof(SwapInventoryItemAndActivateCommand), out dropAndActivateHandler) && dropAndActivateHandler.Enabled);
                    _rightButton.SetActive(Director.CommandSystem.TryGetHandler(typeof(DropItemCommand), out var dropHandler) && dropHandler.Enabled && Director.CommandSystem.TryGetHandler(typeof(SwapInventoryItemCommand), out dropHandler) && dropHandler.Enabled);
                    _middleButton.SetActive(false);
                    _middleButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _leftButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _leftButton.RectTransform().anchorMin        = new Vector2(-1.5f, 1f);
                    _leftButton.RectTransform().anchorMax        = new Vector2(0, 1.7f);
                    _leftButton.RectTransform().anchoredPosition = Vector2.zero;
                    _leftButton.RectTransform().sizeDelta        = Vector2.zero;
                    _leftButton.GetComponent <Button>().onClick.AddListener(() => MoveAndUse(container, director));
                    _leftButton.GetComponentInChildren <Text>().text            = Localization.Get("PLACE_AND_USE_BUTTON");
                    _leftButton.GetComponentInChildren <TextLocalization>().Key = "PLACE_AND_USE_BUTTON";

                    _rightButton.GetComponent <Button>().onClick.RemoveAllListeners();
                    _rightButton.RectTransform().anchorMin        = new Vector2(1f, 1f);
                    _rightButton.RectTransform().anchorMax        = new Vector2(2.5f, 1.7f);
                    _rightButton.RectTransform().anchoredPosition = Vector2.zero;
                    _rightButton.RectTransform().sizeDelta        = Vector2.zero;
                    _rightButton.GetComponent <Button>().onClick.AddListener(() => Move(container, director));
                    _rightButton.GetComponentInChildren <Text>().text            = Localization.Get("PLACE_BUTTON");
                    _rightButton.GetComponentInChildren <TextLocalization>().Key = "PLACE_BUTTON";
                    _selectionOptions.GetComponentsInChildren <Button>().BestFit(true, new List <string> {
                        Localization.Get("PLACE_BUTTON"), Localization.Get("PLACE_AND_USE_BUTTON")
                    });
                }
                else
                {
                    _leftButton.SetActive(false);
                    _rightButton.SetActive(false);
                    _middleButton.SetActive(false);
                }
                var optionAnim = _selectionOptions.GetComponent <Animation>();
                var clipName   = CurrentLocation.Value != null ? optionAnim.clip.name : optionAnim.clip.name + "Inventory";
                optionAnim[clipName].time  = 0;
                optionAnim[clipName].speed = 1;
                optionAnim.Play(clipName);
                _selectPos = transform.position;
            }
        }