void IWorldUIPointerClickHandler.OnPointerClick()
    {
        if (!Cache.LocalPawnAlive)
        {
            return;
        }

        fix2 entityPosition = SimWorld.GetComponent <FixTranslation>(SimEntity);
        fix2 pawnPosition   = Cache.LocalPawnPosition;

        if (fixMath.distancemanhattan(entityPosition, pawnPosition) > SimulationGameConstants.InteractibleMaxDistanceManhattan)
        {
            PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Trop loin", Color.white);
            return;
        }

        switch (_clickAction)
        {
        case ClickAction.OpenChest:
            if (InteractableInventoryDisplaySystem.Instance != null)
            {
                InteractableInventoryDisplaySystem.Instance.SetupDisplayForInventory(SimEntity);
            }
            break;

        case ClickAction.TriggerSignal:
            PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Click", Color.white);
            SimWorld.SubmitInput(new SimPlayerInputClickSignalEmitter(SimEntity));
            break;
        }
    }
    protected override void OnGamePresentationUpdate()
    {
        PhysicsVelocity velocity = SimWorld.GetComponent <PhysicsVelocity>(SimEntity);

        bool spriteLookingRight = _spriteLookingRight;

        if (SimWorld.HasComponent <DoodleStartDirection>(SimEntity))
        {
            spriteLookingRight = SimWorld.GetComponent <DoodleStartDirection>(SimEntity).IsLookingRight;
        }

        int lookDir = 0;

        if (velocity.Linear.x > (fix)0.05f)
        {
            lookDir = 1;
        }
        else if (velocity.Linear.x < -(fix)0.05f)
        {
            lookDir = -1;
        }

        if (lookDir != 0)
        {
            Quaternion rot         = _bone.localRotation;
            Vector3    eulerAngles = rot.eulerAngles;

            eulerAngles.y = (lookDir == 1 ^ spriteLookingRight) ? 180f : 0f;

            rot.eulerAngles     = eulerAngles;
            _bone.localRotation = rot;
        }
    }
 private void UpdateData()
 {
     _displayedMessage.Set(null);
     if (Cache.PointerInWorld && Cache.LocalPawn != Entity.Null)
     {
         if (distance(Cache.DEPRECATED_LocalPawnTile, Cache.PointedTile) <= _readRange)
         {
             foreach (var tileActor in Cache.PointedBodies)
             {
                 if (SimWorld.TryGetComponent(tileActor, out Message message))
                 {
                     _displayedMessage.Set(message);
                     _messagePosition.Set((Vector2)(fix2)SimWorld.GetComponent <FixTranslation>(tileActor));
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
    public override void OnEnter()
    {
        _surveyStateMachine.Blackboard = _surveySMBlackboard;
        _surveySMBlackboard.Cache      = Cache;
        _surveySMBlackboard.ResultParameters.Clear();
        _surveySMBlackboard.IsDebug = false;

        CursorOverlayService.Instance.ResetCursorToDefault();

        if (InputParameter != null && InputParameter.ActionInstigator != Entity.Null && InputParameter.ActionPrefab != Entity.Null)
        {
            if (SimWorld.TryGetComponent(InputParameter.ActionPrefab, out SimAssetId objectSimAssetID))
            {
                _surveySMBlackboard.ActionAuth = PresentationHelpers.FindActionAuth(objectSimAssetID);
            }

            if (_surveySMBlackboard.ActionAuth == null)
            {
                StateMachine.TransitionTo(UIStateType.Gameplay);
                return;
            }

            // Init process of parameter selection
            GameActionId actionId         = SimWorld.GetComponent <GameActionId>(InputParameter.ActionPrefab);
            GameAction   objectGameAction = GameActionBank.GetAction(actionId);

            _surveySMBlackboard.UseContext             = CommonReads.GetActionContext(SimWorld, InputParameter.ActionInstigator, InputParameter.ActionPrefab);
            _surveySMBlackboard.ParametersDescriptions = objectGameAction.GetExecutionContract(SimWorld, InputParameter.ActionPrefab).ParameterTypes;
        }
        else
        {
            _surveySMBlackboard.IsDebug = true;
        }

        _surveyStateMachine.TransitionTo(new SurveyState());
    }
    private void UpdateInventorySlots()
    {
        if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory))
        {
            List <DisplayedItemData> displayedInventory = ListPool <DisplayedItemData> .Take();

            // gather all items to display
            for (int i = 0; i < inventory.Length; i++)
            {
                Entity item = inventory[i].ItemEntity;

                if (SimWorld.TryGetComponent(item, out SimAssetId itemAssetId))
                {
                    ItemAuth itemGameActionAuth = PresentationHelpers.FindItemAuth(itemAssetId);
                    if (itemGameActionAuth != null && !itemGameActionAuth.HideInInventory)
                    {
                        displayedInventory.Add(new DisplayedItemData()
                        {
                            ItemAuth = itemGameActionAuth,
                            ItemRef  = inventory[i],
                            Index    = i
                        });
                    }
                }
            }

            // Ajust Slot amount accordiwdng to inventory max size
            InventoryCapacity inventoryCapacity = SimWorld.GetComponent <InventoryCapacity>(Cache.LocalPawn);

            _gridLayoutGroup.constraintCount = min(_maxCollumns, inventoryCapacity);

            PresentationHelpers.ResizeGameObjectList(_slotVisuals, max(min(_maxCollumns, inventoryCapacity), displayedInventory.Count), _inventorySlotPrefab, _slotsContainer);

            for (int i = 0; i < _slotVisuals.Count; i++)
            {
                if (i < displayedInventory.Count)
                {
                    Entity item   = displayedInventory[i].ItemRef.ItemEntity;
                    int    stacks = displayedInventory[i].ItemRef.Stacks;

                    if (stacks == 1 && !SimWorld.GetComponent <StackableFlag>(item))
                    {
                        stacks = -1; // used in display to hide stacks
                    }
                    _slotVisuals[i].UpdateCurrentInventorySlot(displayedInventory[i].ItemAuth,
                                                               displayedInventory[i].Index,
                                                               GetSlotShotcut(i),
                                                               OnIntentionToUsePrimaryActionOnItem,
                                                               OnIntentionToUseSecondaryActionOnItem,
                                                               stacks);

                    if (!CommonReads.CanUseItem(SimWorld, Cache.LocalPawn, item))
                    {
                        _slotVisuals[i].UpdateDisplayAsUnavailable(item);
                    }
                }
                else
                {
                    _slotVisuals[i].UpdateCurrentInventorySlot(null, i, GetSlotShotcut(i), null, null);
                }
            }

            ListPool <DisplayedItemData> .Release(displayedInventory);
        }
    }