Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            var hasItem = _itemContainer?.Item != null;

            if (_moveItem && IsEnabled && CanContain(_moveItem.Id) && (!hasItem || (_moveItemContainer && _moveItemContainer.CanContain(_itemContainer.Item.Value))))
            {
                var newScale = transform.localScale.x + ((_moveHighlightGrow ? Time.smoothDeltaTime : -Time.smoothDeltaTime) * 0.25f);
                if (newScale < 0.95f)
                {
                    newScale           = 0.95f;
                    _moveHighlightGrow = true;
                }
                if (newScale > 1.05f)
                {
                    newScale           = 1.05f;
                    _moveHighlightGrow = false;
                }
                transform.localScale = Vector3.one * newScale;
                if (TryGetItem(out var item))
                {
                    item.transform.localScale = Vector3.one * newScale;
                }
            }

            if (hasItem)
            {
                Transition(ContainerState.HasItem);
            }
            else if (IsEnabled)
            {
                Transition(ContainerState.Empty);
            }
            else
            {
                Transition(ContainerState.Disabled);
            }

            if (_selectionOptions && _selectionOptions.activeSelf && !IsInvoking("OptionsDelay") && !IsInvoking(nameof(ResetOptions)) && !IsInvoking("EnableOptions"))
            {
                if (hasItem || Input.GetMouseButtonUp(0) || Director.Player.CurrentLocationEntity.EntityBehaviour.Entity.CreatedFromArchetype == nameof(ConnectionNode))
                {
                    var optionAnim = _selectionOptions.GetComponent <Animation>();
                    var clipName   = _currentAnim;
                    optionAnim[clipName].time  = optionAnim[clipName].length;
                    optionAnim[clipName].speed = -1;
                    optionAnim.Play(clipName);
                    Invoke(nameof(ResetOptions), 0.34f);
                    Invoke("OptionsDelay", Time.smoothDeltaTime * 2);
                }
            }
        }