/// <summary> /// Updates the mouse hover box with stuff. /// </summary> /// <remarks> /// <para> /// This creates and removes GUI elements every frame. /// Supposedly that's quite expensive, but I think that's /// how the old JS code do it anyway. /// </para> /// </remarks> private void UpdateHoverInfo() { foreach (Node children in hoveredItems.GetChildren()) { hoveredItems.RemoveChild(children); // Using QueueFree leaves a gap at // the bottom of the panel children.Free(); } if (mouseHoverPanel.RectSize != new Vector2(270, 130)) { mouseHoverPanel.RectSize = new Vector2(270, 130); } if (mouseHoverPanel.MarginLeft != -280) { mouseHoverPanel.MarginLeft = -280; } if (mouseHoverPanel.MarginRight != -10) { mouseHoverPanel.MarginRight = -10; } var compounds = stage.Clouds.GetAllAvailableAt(stage.Camera.CursorWorldPos); var builder = new StringBuilder(string.Empty, 250); if (showMouseCoordinates) { builder.AppendFormat(CultureInfo.CurrentCulture, "Stuff at {0:F1}, {1:F1}:\n", stage.Camera.CursorWorldPos.x, stage.Camera.CursorWorldPos.z); } var mousePosLabel = hoveredItems.GetParent().GetNode <Label>("MousePos"); if (compounds.Count == 0) { builder.Append("Nothing to eat here"); } else { builder.Append("At cursor:"); bool first = true; // Create for each compound the information in GUI foreach (var entry in compounds) { if (first) { var compoundsLabel = new Label(); compoundsLabel.Valign = Label.VAlign.Center; hoveredItems.AddChild(compoundsLabel); compoundsLabel.AddConstantOverride("line_spacing", -5); compoundsLabel.Text = "Compounds: \n"; } first = false; var hBox = new HBoxContainer(); var compoundText = new Label(); var readableName = entry.Key.Name; var compoundIcon = GUICommon.Instance.CreateCompoundIcon(readableName, 25, 25); var compoundsText = new StringBuilder(readableName, 150); compoundsText.AppendFormat(CultureInfo.CurrentCulture, ": {0:F1}", entry.Value); compoundText.Text = compoundsText.ToString(); hBox.AddChild(compoundIcon); hBox.AddChild(compoundText); hoveredItems.AddChild(hBox); } } var aiMicrobes = GetTree().GetNodesInGroup(Constants.AI_GROUP); // Show the hovered over microbe's species foreach (Microbe entry in aiMicrobes) { var distance = (entry.Translation - stage.Camera.CursorWorldPos).Length(); // Find only cells that have the mouse // position within their membrane if (distance > entry.Radius) { continue; } var microbeText = new Label(); microbeText.Valign = Label.VAlign.Center; hoveredItems.AddChild(microbeText); microbeText.Text = "Cell of species " + entry.Species.FormattedName; } mousePosLabel.Text = builder.ToString(); }
private void ToggleConditionsTab(string tab) { var slideAnimations = patchDetails.GetNode <AnimationPlayer>("SlideAnimations"); if (tab == "physical") { var minusButton = physicalConditionsButton.GetNode <TextureButton>("minusButton"); var plusButton = physicalConditionsButton.GetNode <TextureButton>("plusButton"); if (!physicalConditionsBox.Visible) { slideAnimations.Play("physicalSlideDown"); minusButton.Show(); plusButton.Hide(); } else { slideAnimations.Play("physicalSlideUp"); minusButton.Hide(); plusButton.Show(); } } else if (tab == "atmospheric") { var minusButton = atmosphericConditionsButton.GetNode <TextureButton>("minusButton"); var plusButton = atmosphericConditionsButton.GetNode <TextureButton>("plusButton"); if (!atmosphericConditionsBox.Visible) { slideAnimations.Play("atmosphericSlideDown"); minusButton.Show(); plusButton.Hide(); } else { slideAnimations.Play("atmosphericSlideUp"); minusButton.Hide(); plusButton.Show(); } } else if (tab == "compounds") { var minusButton = compoundsButton.GetNode <TextureButton>("minusButton"); var plusButton = compoundsButton.GetNode <TextureButton>("plusButton"); if (!compoundsBox.Visible) { slideAnimations.Play("compoundsSlideDown"); minusButton.Show(); plusButton.Hide(); } else { slideAnimations.Play("compoundsSlideUp"); minusButton.Hide(); plusButton.Show(); } } else if (tab == "species") { var minusButton = speciesListButton.GetNode <TextureButton>("minusButton"); var plusButton = speciesListButton.GetNode <TextureButton>("plusButton"); var clip = speciesList.GetParent <MarginContainer>(); var tween = clip.GetNode <Tween>("Tween"); if (speciesListIsHidden) { tween.InterpolateProperty(clip, "custom_constants/margin_top", -speciesList.RectSize.y, 20, 0.3f, Tween.TransitionType.Sine, Tween.EaseType.Out); tween.Start(); minusButton.Show(); plusButton.Hide(); speciesListIsHidden = false; } else { tween.InterpolateProperty(clip, "custom_constants/margin_top", 20, -speciesList.RectSize.y, 0.3f, Tween.TransitionType.Sine, Tween.EaseType.Out); tween.Start(); minusButton.Hide(); plusButton.Show(); speciesListIsHidden = true; } } }
/// <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(); } }
/// <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 foreach (Node children in hoveredCompoundsContainer.GetChildren()) { hoveredCompoundsContainer.RemoveChild(children); // Using QueueFree leaves a gap at // the bottom of the panel children.Free(); } // Refresh cells list foreach (Node children in hoveredCellsContainer.GetChildren()) { hoveredCellsContainer.RemoveChild(children); children.Free(); } 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, "Stuff at {0:F1}, {1:F1}:", stage.Camera.CursorWorldPos.x, stage.Camera.CursorWorldPos.z); } 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) { var hBox = new HBoxContainer(); var compoundName = new Label(); var compoundValue = new Label(); var readableName = entry.Key.Name; var compoundIcon = GUICommon.Instance.CreateCompoundIcon(readableName, 20, 20); compoundName.SizeFlagsHorizontal = (int)Control.SizeFlags.ExpandFill; compoundName.Text = readableName; compoundValue.Text = string.Format(CultureInfo.CurrentCulture, "{0:F1}", entry.Value); hBox.AddChild(compoundIcon); hBox.AddChild(compoundName); hBox.AddChild(compoundValue); hoveredCompoundsContainer.AddChild(hBox); } } var aiMicrobes = GetTree().GetNodesInGroup(Constants.AI_GROUP); // Show the species name of hovered cells foreach (Microbe entry in aiMicrobes) { var distance = (entry.Translation - stage.Camera.CursorWorldPos).Length(); // Find only cells that have the mouse // position within their membrane if (distance > entry.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; } 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(); } }