Exemplo n.º 1
0
    public override void _Process(float delta)
    {
        // https://github.com/Revolutionary-Games/Thrive/issues/1976
        if (delta <= 0)
        {
            return;
        }

        cloudSystem.GetAllAvailableAt(camera.CursorWorldPos, currentHoveredCompounds);

        if (camera.CursorWorldPos != lastCursorWorldPos)
        {
            HoveredCompounds.Clear();
            lastCursorWorldPos = camera.CursorWorldPos;
        }

        foreach (var compound in cloudCompounds)
        {
            HoveredCompounds.TryGetValue(compound, out float oldAmount);
            currentHoveredCompounds.TryGetValue(compound, out float newAmount);

            // Delay removing of label to reduce flickering.
            if (newAmount == 0f && oldAmount > 0f)
            {
                compoundDelayTimer.TryGetValue(compound, out float delayDelta);
                delayDelta += delta;
                if (delayDelta > Constants.COMPOUND_HOVER_INFO_REMOVE_DELAY)
                {
                    compoundDelayTimer.Remove(compound);
                    HoveredCompounds[compound] = 0f;
                    continue;
                }

                compoundDelayTimer[compound] = delayDelta;
                continue;
            }

            // Ignore small changes to reduce flickering.
            if (Mathf.Abs(newAmount - oldAmount) >= Constants.COMPOUND_HOVER_INFO_THRESHOLD)
            {
                HoveredCompounds[compound] = newAmount;
            }
        }

        currentHoveredCompounds.Clear();

        var allMicrobes = GetTree().GetNodesInGroup(Constants.AI_TAG_MICROBE);

        foreach (var hoveredMicrobe in HoveredMicrobes)
        {
            hoveredMicrobe.IsHoveredOver = false;
        }

        HoveredMicrobes.Clear();

        foreach (Microbe microbe in allMicrobes)
        {
            var distanceSquared = (microbe.GlobalTransform.origin - camera.CursorWorldPos).LengthSquared();

            // Find only cells that have the mouse position within their membrane
            if (distanceSquared > microbe.RadiusSquared + Constants.MICROBE_HOVER_DETECTION_EXTRA_RADIUS_SQUARED)
            {
                continue;
            }

            microbe.IsHoveredOver = true;
            HoveredMicrobes.Add(microbe);
        }
    }