/// <summary> /// Draws location marker on screen. /// </summary> public void DrawLocationMarker(int styleHandle, Vector3D position, MyHudEntityParams hudParams, float targetDamageRatio, float targetArmorRatio, float alphaMultiplifier = 1f) { if (MySession.ControlledEntity == null) { return; } // Transform point to camera space, so Z = -1 is always forward and then do projective transformation Vector3D transformedPoint = Vector3D.Transform(position, MySector.MainCamera.ViewMatrix); Vector4D projectedPoint = Vector4D.Transform(transformedPoint, MySector.MainCamera.ProjectionMatrix); // If point is behind camera we swap X and Y (this is mirror-like transformation) if (transformedPoint.Z > 0) { projectedPoint.X *= -1; projectedPoint.Y *= -1; } if (projectedPoint.W == 0) { return; } MyMarkerStyle markerStyle = m_markerStyles[styleHandle]; double distance = Vector3D.Distance(position, MySession.ControlledEntity.Entity.WorldMatrix.Translation); float maxDistance = hudParams.MaxDistance; byte colorAlphaInByte = 255; var hudColor = MyFakes.SHOW_FACTIONS_GUI ? markerStyle.Color : Color.White; hudColor.A = (byte)(colorAlphaInByte * alphaMultiplifier); // Calculate centered coordinates in range <0..1> Vector2 projectedPoint2D = new Vector2((float)(projectedPoint.X / projectedPoint.W / 2.0f) + 0.5f, (float)(-projectedPoint.Y / projectedPoint.W) / 2.0f + 0.5f); if (MyVideoSettingsManager.IsTripleHead()) { projectedPoint2D.X = (projectedPoint2D.X - (1.0f / 3.0f)) / (1.0f / 3.0f); } float objectNameYOffset = 0.0f; //offset to direction indicator // This will bound the rectangle in circle, although it isn't real circle because we work in [1,1] dimensions, // but number of horizontal pixels is bigger, so at the end it's more elypse // It must be done when point is out of circle or behind the camera Vector2 direction = projectedPoint2D - MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER; if ((direction.Length() > MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE) || (transformedPoint.Z > 0)) { if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS) == 0) { return; } if (direction.LengthSquared() > MyMathConstants.EPSILON_SQUARED) { direction.Normalize(); } else { direction = new Vector2(1f, 0f); } projectedPoint2D = MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER + direction * MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE; // Fix vertical scale projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y; AddTexturedQuad(markerStyle.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 2.5f, direction, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f); } else { // Fix vertical scale projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y; Color rectangleColor = Color.White; rectangleColor.A = colorAlphaInByte; if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_FOCUS_MARK) > 0) { Vector2 upVector = new Vector2(0, -1); if (markerStyle.TextureTargetRotationSpeed != 0) { upVector = new Vector2((float)Math.Cos(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi), (float)Math.Sin(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi)); } AddTexturedQuad(markerStyle.TextureTarget, projectedPoint2D, upVector, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale); } objectNameYOffset = -MyHudConstants.HUD_TEXTS_OFFSET; } if (hudParams.Text != null && hudParams.Text.Length > 0 && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_TEXT) != 0) { // Add object's name MyHudText objectName = m_hudScreen.AllocateText(); if (objectName != null) { objectName.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, hudParams.OffsetText ? objectNameYOffset : 0), hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); objectName.Append(hudParams.Text); } } // display hud icon if (hudParams.Icon != null && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_ICON) != 0) { Color iconColor = hudParams.IconColor.HasValue && MyFakes.SHOW_FACTIONS_GUI ? hudParams.IconColor.Value : Color.White; iconColor.A = (byte)(colorAlphaInByte * alphaMultiplifier); AddTexturedQuad(hudParams.Icon.Value, projectedPoint2D + hudParams.IconOffset, new Vector2(0, -1), iconColor, hudParams.IconSize.X / 2f, hudParams.IconSize.Y / 2f); } if (MyFakes.SHOW_HUD_DISTANCES && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_DISTANCE) != 0) { // Add distance to object MyHudText objectDistance = m_hudScreen.AllocateText(); if (objectDistance != null) { objectDistance.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, MyHudConstants.HUD_TEXTS_OFFSET), hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); // Create string builder with distance in metres, e.g. "123m" objectDistance.AppendInt32((int)Math.Round(distance)); objectDistance.Append("m"); } } }
public void Draw(MyHudMarkerRender renderer, float alphaMultiplierMarker = 1f, float alphaMultiplierText = 1f, float scale = 1f, bool drawBox = true) { Vector2 projectedPoint2D = Vector2.Zero; bool isBehind = false; if (!EnergySignature.TryComputeScreenPoint(this.WorldPosition, out projectedPoint2D, out isBehind)) { return; } Vector2 vector2_1 = new Vector2(screenWidth, screenHeight); Vector2 hudSize = new Vector2(1f, screenHeight / screenWidth); Vector2 hudSizeHalf = hudSize / 2f; float num1 = vector2_1.Y / 1080f; Vector2 vector2_2 = projectedPoint2D * hudSize; Color white1 = Color.White; Color fontColor = Color.White; string font = "White"; this.GetPOIColorAndFontInformation(out white1, out fontColor, out font); Vector2 upVector = vector2_2 - hudSizeHalf; Vector3D vector3D = Vector3D.Transform(this.WorldPosition, MyAPIGateway.Session.Camera.ViewMatrix); float num2 = 0.04f; if ((double)vector2_2.X < (double)num2 || (double)vector2_2.X > (double)hudSize.X - (double)num2 || ((double)vector2_2.Y < (double)num2 || (double)vector2_2.Y > (double)hudSize.Y - (double)num2) || vector3D.Z > 0.0) { Vector2 vector2_3 = Vector2.Normalize(upVector); Vector2 position = hudSizeHalf + hudSizeHalf * vector2_3 * 0.77f; upVector = position - hudSizeHalf; if ((double)upVector.LengthSquared() > 9.99999943962493E-11) { upVector.Normalize(); } else { upVector = new Vector2(1f, 0.0f); } float num3 = 0.0053336f / num1 / num1; renderer.AddTexturedQuad("HudAtlas0.dds_DirectionIndicator", position, upVector, white1, num3, num3); vector2_2 = position - upVector * 0.006667f * 2f; } else { float num3 = scale * 0.006667f / num1 / num1; if (drawBox) { renderer.AddTexturedQuad("HudAtlas0.dds_Target_neutral", vector2_2, -Vector2.UnitY, white1, num3, num3); } } float num4 = 0.03f; float num5 = 0.07f; float num6 = 0.15f; float num7 = upVector.Length(); float val; float num8; int num9; if ((double)num7 <= (double)num4) { val = 1f; num8 = 1f; num9 = 0; } else if ((double)num7 > (double)num4 && (double)num7 < (double)num5) { float num3 = num6 - num4; float num10 = (float)(1.0 - ((double)num7 - (double)num4) / (double)num3); val = num10 * num10; float num11 = num5 - num4; float num12 = (float)(1.0 - ((double)num7 - (double)num4) / (double)num11); num8 = num12 * num12; num9 = 1; } else if ((double)num7 >= (double)num5 && (double)num7 < (double)num6) { float num3 = num6 - num4; float num10 = (float)(1.0 - ((double)num7 - (double)num4) / (double)num3); val = num10 * num10; float num11 = num6 - num5; float num12 = (float)(1.0 - ((double)num7 - (double)num5) / (double)num11); num8 = num12 * num12; num9 = 2; } else { val = 0.0f; num8 = 0.0f; num9 = 2; } float num13 = MathHelper.Clamp((float)(((double)num7 - 0.200000002980232) / 0.5), 0.0f, 1f); float num14 = MyMath.Clamp(val, 0.0f, 1f); //if (MyHudMarkerRender.m_disableFading || MyHudMarkerRender.SignalDisplayMode == MyHudMarkerRender.SignalMode.FullDisplay || this.AlwaysVisible) { num14 = 1f; num8 = 1f; num13 = 1f; num9 = 0; } Vector2 vector2_4 = new Vector2(0.0f, (float)((double)scale * (double)num1 * 24.0) / (float)screenWidth); //if ((MyHudMarkerRender.SignalDisplayMode != MyHudMarkerRender.SignalMode.NoNames || this.POIType == EnergySignatureType.ButtonMarker || (MyHudMarkerRender.m_disableFading || this.AlwaysVisible)) && ((double)num14 > 1.40129846432482E-45 && this.Text.Length > 0)) if ((double)num14 > 1.40129846432482E-45 && this.Text.Length > 0) { MyHudText myHudText = renderer.m_hudScreen.AllocateText(); if (myHudText != null) { fontColor.A = (byte)((double)byte.MaxValue * (double)alphaMultiplierText * (double)num14); myHudText.Start(font, vector2_2 - vector2_4, fontColor, 0.7f / num1, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); myHudText.Append(this.Text); } } if (this.POIType != EnergySignatureType.Group) { byte a = white1.A; white1.A = (byte)((double)byte.MaxValue * (double)alphaMultiplierMarker * (double)num13); EnergySignature.DrawIcon(renderer, this.POIType, this.Relationship, vector2_2, white1, scale); white1.A = a; MyHudText myHudText1 = renderer.m_hudScreen.AllocateText(); if (myHudText1 != null) { StringBuilder stringBuilder = new StringBuilder(); MyHudMarkerRender.AppendDistance(stringBuilder, this.Distance); fontColor.A = (byte)((double)alphaMultiplierText * (double)byte.MaxValue); myHudText1.Start(font, vector2_2 + vector2_4 * (float)(0.699999988079071 + 0.300000011920929 * (double)num14), fontColor, (float)(0.5 + 0.200000002980232 * (double)num14) / num1, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); myHudText1.Append(stringBuilder); } if (string.IsNullOrEmpty(this.ContainerRemainingTime)) { return; } MyHudText myHudText2 = renderer.m_hudScreen.AllocateText(); myHudText2.Start(font, vector2_2 + vector2_4 * (float)(1.60000002384186 + 0.300000011920929 * (double)num14), fontColor, (float)(0.5 + 0.200000002980232 * (double)num14) / num1, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); myHudText2.Append(this.ContainerRemainingTime); } else { Dictionary <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> > significantGroupPoIs = this.GetSignificantGroupPOIs(); Vector2[] vector2Array1 = new Vector2[5] { new Vector2(-6f, -4f), new Vector2(6f, -4f), new Vector2(-6f, 4f), new Vector2(6f, 4f), new Vector2(0.0f, 12f) }; Vector2[] vector2Array2 = new Vector2[5] { new Vector2(16f, -4f), new Vector2(16f, 4f), new Vector2(16f, 12f), new Vector2(16f, 20f), new Vector2(16f, 28f) }; for (int index = 0; index < vector2Array1.Length; ++index) { float num3 = num9 < 2 ? 1f : num8; float y1 = vector2Array1[index].Y; vector2Array1[index].X = (vector2Array1[index].X + 22f * num3) / (float)screenWidth; vector2Array1[index].Y = y1 / 1080f / num1; //can't support triplehead //if (MyVideoSettingsManager.IsTripleHead()) // vector2Array1[index].X /= 0.33f; if ((double)vector2Array1[index].Y <= 1.40129846432482E-45) { vector2Array1[index].Y = y1 / 1080f; } float y2 = vector2Array2[index].Y; vector2Array2[index].X = vector2Array2[index].X / (float)screenWidth / num1; vector2Array2[index].Y = y2 / 1080f / num1; //can't support triplehead //if (MyVideoSettingsManager.IsTripleHead()) // vector2Array2[index].X /= 0.33f; if ((double)vector2Array2[index].Y <= 1.40129846432482E-45) { vector2Array2[index].Y = y2 / 1080f; } } int index1 = 0; if (significantGroupPoIs.Count > 1) { MyRelationsBetweenPlayerAndBlock[] betweenPlayerAndBlockArray = new MyRelationsBetweenPlayerAndBlock[4] { MyRelationsBetweenPlayerAndBlock.Owner, MyRelationsBetweenPlayerAndBlock.FactionShare, MyRelationsBetweenPlayerAndBlock.Neutral, MyRelationsBetweenPlayerAndBlock.Enemies }; foreach (MyRelationsBetweenPlayerAndBlock index2 in betweenPlayerAndBlockArray) { if (significantGroupPoIs.ContainsKey(index2)) { List <EnergySignature> pointOfInterestList = significantGroupPoIs[index2]; if (pointOfInterestList.Count != 0) { EnergySignature poi = pointOfInterestList[0]; if (poi != null) { this.GetColorAndFontForRelationship(index2, out white1, out fontColor, out font); float amount = num9 == 0 ? 1f : num8; if (num9 >= 2) { amount = 0.0f; } Vector2 vector2_3 = Vector2.Lerp(vector2Array1[index1], vector2Array2[index1], amount); string iconForRelationship = EnergySignature.GetIconForRelationship(index2); white1.A = (byte)((double)alphaMultiplierMarker * (double)white1.A); EnergySignature.DrawIcon(renderer, iconForRelationship, vector2_2 + vector2_3, white1, 0.75f / num1); if (this.IsPoiAtHighAlert(poi)) { Color white2 = Color.White; white2.A = (byte)((double)alphaMultiplierMarker * (double)byte.MaxValue); EnergySignature.DrawIcon(renderer, "Textures\\HUD\\marker_alert.dds", vector2_2 + vector2_3, white2, 0.75f / num1); } //if ((MyHudMarkerRender.SignalDisplayMode != MyHudMarkerRender.SignalMode.NoNames || MyHudMarkerRender.m_disableFading || this.AlwaysVisible) && poi.Text.Length > 0) if (poi.Text.Length > 0) { MyHudText myHudText = renderer.m_hudScreen.AllocateText(); if (myHudText != null) { float num3 = 1f; if (num9 == 1) { num3 = num8; } else if (num9 > 1) { num3 = 0.0f; } fontColor.A = (byte)((double)byte.MaxValue * (double)alphaMultiplierText * (double)num3); Vector2 vector2_5 = new Vector2(8f / (float)screenWidth, 0.0f); vector2_5.X /= num1; myHudText.Start(font, vector2_2 + vector2_3 + vector2_5, fontColor, 0.55f / num1, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER); myHudText.Append(poi.Text); } } ++index1; } } } } } else { using (Dictionary <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> > .Enumerator enumerator = significantGroupPoIs.GetEnumerator()) { label_86: while (enumerator.MoveNext()) { KeyValuePair <MyRelationsBetweenPlayerAndBlock, List <EnergySignature> > current = enumerator.Current; MyRelationsBetweenPlayerAndBlock key = current.Key; if (significantGroupPoIs.ContainsKey(key)) { List <EnergySignature> pointOfInterestList = current.Value; int index2 = 0; while (true) { if (index2 < 4 && index2 < pointOfInterestList.Count) { EnergySignature poi = pointOfInterestList[index2]; if (poi != null) { this.GetColorAndFontForRelationship(key, out white1, out fontColor, out font); float amount = num9 == 0 ? 1f : num8; if (num9 >= 2) { amount = 0.0f; } Vector2 vector2_3 = Vector2.Lerp(vector2Array1[index1], vector2Array2[index1], amount); string centerIconSprite = EnergySignature.GetIconForRelationship(key); white1.A = (byte)((double)alphaMultiplierMarker * (double)white1.A); EnergySignature.DrawIcon(renderer, centerIconSprite, vector2_2 + vector2_3, white1, 0.75f / num1); if (this.ShouldDrawHighAlertMark(poi)) { Color white2 = Color.White; white2.A = (byte)((double)alphaMultiplierMarker * (double)byte.MaxValue); EnergySignature.DrawIcon(renderer, "Textures\\HUD\\marker_alert.dds", vector2_2 + vector2_3, white2, 0.75f / num1); } //if ((MyHudMarkerRender.SignalDisplayMode != MyHudMarkerRender.SignalMode.NoNames || MyHudMarkerRender.m_disableFading || this.AlwaysVisible) && poi.Text.Length > 0) if (poi.Text.Length > 0) { MyHudText myHudText = renderer.m_hudScreen.AllocateText(); if (myHudText != null) { float num3 = 1f; if (num9 == 1) { num3 = num8; } else if (num9 > 1) { num3 = 0.0f; } fontColor.A = (byte)((double)byte.MaxValue * (double)alphaMultiplierText * (double)num3); Vector2 vector2_5 = new Vector2(8f / (float)screenWidth, 0.0f); vector2_5.X /= num1; myHudText.Start(font, vector2_2 + vector2_3 + vector2_5, fontColor, 0.55f / num1, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER); myHudText.Append(poi.Text); } } ++index1; } ++index2; } else { goto label_86; } } } } } } this.GetPOIColorAndFontInformation(out white1, out fontColor, out font); float amount1 = num9 == 0 ? 1f : num8; if (num9 >= 2) { amount1 = 0.0f; } Vector2 vector2_6 = Vector2.Lerp(vector2Array1[4], vector2Array2[index1], amount1); Vector2 vector2_7 = Vector2.Lerp(Vector2.Zero, new Vector2(0.02222222f / num1, 1f / 270f / num1), amount1); MyHudText myHudText1 = renderer.m_hudScreen.AllocateText(); if (myHudText1 == null) { return; } StringBuilder stringBuilder = new StringBuilder(); MyHudMarkerRender.AppendDistance(stringBuilder, this.Distance); fontColor.A = (byte)((double)alphaMultiplierText * (double)byte.MaxValue); myHudText1.Start(font, vector2_2 + vector2_6 + vector2_7, fontColor, (float)(0.5 + 0.200000002980232 * (double)num14) / num1, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); myHudText1.Append(stringBuilder); } }