public static void LoadData() { m_sunHudParams = new MyHudEntityParams(MyTextsWrapper.Get(MyTextsWrapperEnum.Sun), null, 0f, MyHudIndicatorFlagsEnum.SHOW_TEXT | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_ICON); m_sunHudParams.Icon = MyHudTexturesEnum.Sun; m_sunHudParams.IconColor = Color.White; m_sunHudParams.IconOffset = new Vector2(-0.02f, 0f); m_sunHudParams.IconSize = new Vector2(MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 6f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 6f); if (MySession.Static != null) { m_madelynHudParams = new MyHudEntityParams(MySession.Static.MotherShipPosition.Name, MyGuitargetMode.Friend, 0, MyHudIndicatorFlagsEnum.SHOW_TEXT | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_HEALTH_BARS | MyHudIndicatorFlagsEnum.SHOW_DISTANCE | MyHudIndicatorFlagsEnum.SHOW_MISSION_MARKER); } m_oreHudParams = new MyHudEntityParams(null, MyGuitargetMode.Neutral, 2000f, MyHudIndicatorFlagsEnum.SHOW_DISTANCE | MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS | MyHudIndicatorFlagsEnum.SHOW_TEXT); m_hudAlphaCorrection[(int)MyGuitargetMode.Friend] = new MyHudAlphaCorrection(MyHudConstants.HUD_MIN_DISTANCE_TO_ALPHA_CORRECT, MyHudConstants.HUD_MAX_DISTANCE_TO_ALPHA_CORRECT_NORMAL, MyHudConstants.HUD_MIN_DISTANCE_ALPHA, MyHudConstants.HUD_MAX_DISTANCE_ALPHA); m_hudAlphaCorrection[(int)MyGuitargetMode.Neutral] = new MyHudAlphaCorrection(MyHudConstants.HUD_MIN_DISTANCE_TO_ALPHA_CORRECT, MyHudConstants.HUD_MAX_DISTANCE_TO_ALPHA_CORRECT_NORMAL, MyHudConstants.HUD_MIN_DISTANCE_ALPHA, MyHudConstants.HUD_MAX_DISTANCE_ALPHA); m_hudAlphaCorrection[(int)MyGuitargetMode.Enemy] = new MyHudAlphaCorrection(MyHudConstants.HUD_MIN_DISTANCE_TO_ALPHA_CORRECT, MyHudConstants.HUD_MAX_DISTANCE_TO_ALPHA_CORRECT_ENEMIES, MyHudConstants.HUD_MIN_DISTANCE_ALPHA, MyHudConstants.HUD_MAX_DISTANCE_ALPHA); m_hudAlphaCorrection[(int)MyGuitargetMode.Objective] = null; m_hudAlphaCorrection[(int)MyGuitargetMode.ObjectiveOptional] = null; m_hudAlphaCorrection[(int)MyGuitargetMode.CargoBox] = null; m_oreHudSetting = new MyHudSetting(MyGuiManager.GetFontMinerWarsWhite(), MyHudTexturesEnum.DirectionIndicator_white, MyHudTexturesEnum.HudOre, MyHudTexturesEnum.Unpowered_white, Color.White); m_hudSettings[(int)MyGuitargetMode.Friend] = new MyHudSetting(MyHudConstants.FRIEND_FONT, MyHudTexturesEnum.DirectionIndicator_green, MyHudTexturesEnum.TargetGreen, MyHudTexturesEnum.Unpowered_green, MyHudConstants.FRIEND_MARKER_COLOR); m_hudSettings[(int)MyGuitargetMode.Neutral] = new MyHudSetting(MyHudConstants.NEUTRAL_FONT, MyHudTexturesEnum.DirectionIndicator_white, MyHudTexturesEnum.Target, MyHudTexturesEnum.Unpowered_white, MyHudConstants.NEUTRAL_MARKER_COLOR); m_hudSettings[(int)MyGuitargetMode.Enemy] = new MyHudSetting(MyHudConstants.ENEMY_FONT, MyHudTexturesEnum.DirectionIndicator_red, MyHudTexturesEnum.TargetRed, MyHudTexturesEnum.Unpowered_red, MyHudConstants.BOT_MARKER_COLOR); m_hudSettings[(int)MyGuitargetMode.Objective] = new MyHudSetting(MyHudConstants.MISSION_FONT, MyHudTexturesEnum.DirectionIndicator_blue, MyHudTexturesEnum.TargetBlue, MyHudTexturesEnum.Unpowered_blue, MyHudConstants.MISSION_MARKER_COLOR_BLUE); m_hudSettings[(int)MyGuitargetMode.ObjectiveOptional] = new MyHudSetting(MyHudConstants.MISSION_FONT, MyHudTexturesEnum.DirectionIndicator_blue, MyHudTexturesEnum.TargetBlue, MyHudTexturesEnum.Unpowered_blue, MyHudConstants.MISSION_MARKER_COLOR_BLUE); m_hudSettings[(int)MyGuitargetMode.CargoBox] = new MyHudSetting(MyHudConstants.NEUTRAL_FONT, MyHudTexturesEnum.DirectionIndicator_white, MyHudTexturesEnum.CargoBoxIndicator, MyHudTexturesEnum.Unpowered_white, MyHudConstants.NEUTRAL_MARKER_COLOR, 0.75f, 1.5f); }
/// <summary> /// Adds direction indicator and returns distance from screen center /// </summary> /// <returns></returns> private static float? AddDirectionIndicator(MyHudSetting hudSetting, Vector3 position, MyHudEntityParams hudParams, float targetDamageRatio, float targetArmorRatio, Color hudColor, MyHudAlphaCorrection alphaCorrection = null, bool displayUnpowered = false, float alphaMultiplifier = 1f, bool showNameInWithoutOffset = false, bool drawFocusMark = true) { float? distanceFromScreenCenter = null; float distance = Vector3.Distance(position, MyGuiScreenGamePlay.Static.ControlledEntity.WorldMatrix.Translation); if (showNameInWithoutOffset && distance > 100 * MyMwcSectorConstants.SECTOR_SIZE) return null; bool isAlphaCorrectionEnabled = alphaCorrection != null && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.ALPHA_CORRECTION_BY_DISTANCE) != 0; float maxDistance = hudParams.MaxDistance; if (hudParams.MaxDistanceMultiplerType != null) { maxDistance *= HudMaxDistanceMultiplers[(int)hudParams.MaxDistanceMultiplerType]; } if (isAlphaCorrectionEnabled && distance >= alphaCorrection.MaxDistance || (maxDistance > 0) && (distance > maxDistance) || distance < 1f || Vector3.DistanceSquared(position, MyCamera.Position) <= 1) return distanceFromScreenCenter; byte colorAlphaInByte; if (isAlphaCorrectionEnabled) { colorAlphaInByte = alphaCorrection.GetAlphaByDistance(distance); } else { colorAlphaInByte = 255;// hudParams.Color.A; } hudColor.A = (byte)(colorAlphaInByte * alphaMultiplifier); // Transform point to camera space, so Z = -1 is always forward and then do projective transformation Vector3 transformedPoint = Vector3.Transform(position, MyCamera.ViewMatrix); Vector4 projectedPoint = Vector4.Transform(transformedPoint, MyCamera.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 null; } // Calculate centered coordinates in range <0..1> Vector2 projectedPoint2D = new Vector2(projectedPoint.X / projectedPoint.W / 2.0f + 0.5f, -projectedPoint.Y / projectedPoint.W / 2.0f + 0.5f); if (MyVideoModeManager.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)) { distanceFromScreenCenter = direction.LengthSquared() + MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE; if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS) == 0) // this code doesn't allocate anything { return distanceFromScreenCenter; } if (direction.LengthSquared() > MyMwcMathConstants.EPSILON_SQUARED) { direction = MyMwcUtils.Normalize(direction); } 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(hudSetting.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); if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_LOCKED_TARGET) > 0) { AddTexturedQuad(hudSetting.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 2.0f, direction, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f); AddTexturedQuad(hudSetting.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, direction, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f); } else if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_LOCKED_SIDE_TARGET) > 0) { AddTexturedQuad(hudSetting.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 2.0f, direction, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f); AddTexturedQuad(hudSetting.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.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; distanceFromScreenCenter = direction.LengthSquared(); Color rectangleColor = Color.White;// hudParams.Color; rectangleColor.A = colorAlphaInByte; if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_LOCKED_TARGET) > 0) { if (displayUnpowered) { //if (hudParams.DisplayFactionRelation.Enemy) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_red, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else if (hudParams.DisplayFactionRelation.Friend) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_green, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else if (hudParams.DisplayFactionRelation.Neutral) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_white, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else // AddTexturedQuad(MyHudTexturesEnum.Unpowered_blue, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); AddTexturedQuad(hudSetting.TextureUnpowered, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); } else { AddTexturedQuad(MyHudTexturesEnum.Crosshair_locked, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE); } } else if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_LOCKED_SIDE_TARGET) > 0) { if (displayUnpowered) { //if (hudParams.DisplayFactionRelation.Enemy) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_red, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else if (hudParams.DisplayFactionRelation.Friend) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_green, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else if (hudParams.DisplayFactionRelation.Neutral) // AddTexturedQuad(MyHudTexturesEnum.Unpowered_white, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); //else // AddTexturedQuad(MyHudTexturesEnum.Unpowered_blue, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); AddTexturedQuad(hudSetting.TextureUnpowered, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); } else { AddTexturedQuad(MyHudTexturesEnum.Crosshair_side_locked, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE); } } else { if (drawFocusMark) { //X = value.X * (int)Math.Cos(this.Rotation); //Y = value.Y * (int)Math.Cos(this.Rotation); Vector2 upVector = new Vector2(0, -1); if (hudSetting.TextureTargetRotationSpeed != 0) { upVector = new Vector2((float)Math.Cos(MyMinerGame.TotalGamePlayTimeInMilliseconds / 1000f * hudSetting.TextureTargetRotationSpeed * MathHelper.Pi), (float)Math.Sin(MyMinerGame.TotalGamePlayTimeInMilliseconds / 1000f * hudSetting.TextureTargetRotationSpeed * MathHelper.Pi)); } if (displayUnpowered) { AddTexturedQuad(hudSetting.TextureUnpowered, projectedPoint2D, new Vector2(0, -1), Color.White, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.5f); } else { AddTexturedQuad(hudSetting.TextureTarget, projectedPoint2D, upVector, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * hudSetting.TextureTargetScale, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * hudSetting.TextureTargetScale); } } } //if (hudParams.FlagsEnum.IsFlagSet(MyHudIndicatorFlagsEnum.SHOW_HEALTH_BARS)) if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_HEALTH_BARS) != 0) { if (targetDamageRatio > -1.0f && targetDamageRatio < 0.99f) { //color of halth bar is same as color of target icon ! AddLine2D(projectedPoint2D - new Vector2(MyHudConstants.HUD_TEXTS_OFFSET, MyHudConstants.HUD_TEXTS_OFFSET), projectedPoint2D + new Vector2(2.0f * (1.0f - targetDamageRatio) * MyHudConstants.HUD_TEXTS_OFFSET - MyHudConstants.HUD_TEXTS_OFFSET, -MyHudConstants.HUD_TEXTS_OFFSET), hudSetting.Color, hudSetting.Color, 0.006f); } } objectNameYOffset = -MyHudConstants.HUD_TEXTS_OFFSET * 1.75f; } if (displayUnpowered) { objectNameYOffset -= MyHudConstants.HUD_UNPOWERED_OFFSET; } //if (hudParams.Text != null && hudParams.Text.Length > 0 && (hudParams.FlagsEnum.IsFlagSet(MyHudIndicatorFlagsEnum.SHOW_TEXT))) if (hudParams.Text != null && hudParams.Text.Length > 0 && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_TEXT) != 0 && MyFakes.SHOW_HUD_NAMES) { // Add object's name MyHudText objectName = m_texts.Allocate(); if (objectName != null) { objectName.Start(hudSetting.Font, projectedPoint2D + new Vector2(0, showNameInWithoutOffset ? 0 : objectNameYOffset), hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); objectName.Append(hudParams.Text); //if (target is MyPhysObjectBot) //{ // MyPhysObjectBot bot = (MyPhysObjectBot)target; // objectName.Append(bot.HudLabelText); //} //else //{ // objectName.Append(MyTextsWrapper.Get(MyTextsWrapperEnum.Object)); //} } } // display hud icon if (hudParams.Icon != null && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_ICON) != 0) { Color iconColor = hudParams.IconColor.Value; 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 (displayUnpowered) { // Add object's name MyHudText objectName = m_texts.Allocate(); if (objectName != null) { objectName.Start(hudSetting.Font, projectedPoint2D + new Vector2(0, objectNameYOffset + MyHudConstants.HUD_UNPOWERED_OFFSET), hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); //objectName.Append(MyTextsWrapper.Get(MyTextsWrapperEnum.HudUnpowered)); } } if (MyFakes.SHOW_HUD_DISTANCES && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_DISTANCE) != 0) { // Add distance to object MyHudText objectDistance = m_texts.Allocate(); if (objectDistance != null) { objectDistance.Start(hudSetting.Font, projectedPoint2D + new Vector2(0, MyHudConstants.HUD_TEXTS_OFFSET * 1.75f), 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(MyTextsWrapper.Get(MyTextsWrapperEnum.MetersShort)); } } return distanceFromScreenCenter; }