Ejemplo n.º 1
0
    /// <summary>
    ///   Updates the mouse hover indicator box with stuff.
    /// </summary>
    private void UpdateHoverInfo(float delta)
    {
        hoverInfoTimeElapsed += delta;

        if (hoverInfoTimeElapsed < Constants.HOVER_PANEL_UPDATE_INTERVAL)
        {
            return;
        }

        hoverInfoTimeElapsed = 0;

        // Refresh compounds list

        // Using QueueFree leaves a gap at the bottom of the panel
        hoveredCompoundsContainer.FreeChildren();

        // Refresh cells list
        hoveredCellsContainer.FreeChildren();

        if (mouseHoverPanel.RectSize != new Vector2(240, 80))
        {
            mouseHoverPanel.RectSize = new Vector2(240, 80);
        }

        if (mouseHoverPanel.MarginLeft != -240)
        {
            mouseHoverPanel.MarginLeft = -240;
        }
        if (mouseHoverPanel.MarginRight != 0)
        {
            mouseHoverPanel.MarginRight = 0;
        }

        var compounds = stage.Clouds.GetAllAvailableAt(stage.Camera.CursorWorldPos);

        var container     = mouseHoverPanel.GetNode("PanelContainer/MarginContainer/VBoxContainer");
        var mousePosLabel = container.GetNode <Label>("MousePos");
        var nothingHere   = container.GetNode <MarginContainer>("NothingHere");

        if (showMouseCoordinates)
        {
            mousePosLabel.Text = string.Format(CultureInfo.CurrentCulture, TranslationServer.Translate("STUFF_AT"),
                                               stage.Camera.CursorWorldPos.x, stage.Camera.CursorWorldPos.z) + "\n";
        }

        if (compounds.Count == 0)
        {
            hoveredCompoundsContainer.GetParent <VBoxContainer>().Visible = false;
        }
        else
        {
            hoveredCompoundsContainer.GetParent <VBoxContainer>().Visible = true;

            // Create for each compound the information in GUI
            foreach (var entry in compounds)
            {
                // It is not useful to show trace amounts of a compound, so those are skipped
                if (entry.Value < 0.1)
                {
                    continue;
                }

                var hBox          = new HBoxContainer();
                var compoundName  = new Label();
                var compoundValue = new Label();

                var compoundIcon = GUICommon.Instance.CreateCompoundIcon(entry.Key.InternalName, 20, 20);

                compoundName.SizeFlagsHorizontal = (int)Control.SizeFlags.ExpandFill;
                compoundName.Text = entry.Key.Name;

                compoundValue.Text = string.Format(CultureInfo.CurrentCulture, "{0:F1}", entry.Value);

                hBox.AddChild(compoundIcon);
                hBox.AddChild(compoundName);
                hBox.AddChild(compoundValue);
                hoveredCompoundsContainer.AddChild(hBox);
            }
        }

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

        // Show the species name of hovered cells
        foreach (Microbe entry in allMicrobes)
        {
            var distance = (entry.Translation - stage.Camera.CursorWorldPos).Length();

            // Find only cells that have the mouse
            // position within their membrane
            if (distance > entry.Radius + Constants.MICROBE_HOVER_DETECTION_EXTRA_RADIUS)
            {
                continue;
            }

            // TODO: Combine cells of same species within mouse over
            // into a single line with total number of them

            var microbeText = new Label();
            microbeText.Valign = Label.VAlign.Center;
            hoveredCellsContainer.AddChild(microbeText);

            microbeText.Text = entry.Species.FormattedName;

            if (entry.IsPlayerMicrobe)
            {
                microbeText.Text += " (" + TranslationServer.Translate("PLAYER_CELL") + ")";
            }
        }

        hoveredCellsSeparator.Visible = hoveredCellsContainer.GetChildCount() > 0 &&
                                        hoveredCompoundsContainer.GetChildCount() > 0;

        hoveredCellsContainer.GetParent <VBoxContainer>().Visible = hoveredCellsContainer.GetChildCount() > 0;

        if (compounds.Count > 0 || hoveredCellsContainer.GetChildCount() > 0)
        {
            nothingHere.Hide();
        }
        else
        {
            nothingHere.Show();
        }
    }