public override void Initialize() { EnableStartLocationSelection = true; #if !WINDOWSGL disposeTextures = !UserINISettings.Instance.PreloadMapPreviews; #endif startingLocationIndicators = new PlayerLocationIndicator[MAX_STARTING_LOCATIONS]; Color nameBackgroundColor = AssetLoader.GetRGBAColorFromString( ClientConfiguration.Instance.MapPreviewNameBackgroundColor); Color nameBorderColor = AssetLoader.GetRGBAColorFromString( ClientConfiguration.Instance.MapPreviewNameBorderColor); contextMenu = new XNAContextMenu(WindowManager); contextMenu.Tag = -1; double angularVelocity = gameOptionsIni.GetDoubleValue("General", "StartingLocationAngularVelocity", 0.015); double reservedAngularVelocity = gameOptionsIni.GetDoubleValue("General", "ReservedStartingLocationAngularVelocity", -0.0075); Color hoverRemapColor = AssetLoader.GetRGBAColorFromString(ClientConfiguration.Instance.MapPreviewStartingLocationHoverRemapColor); // Init starting location indicators for (int i = 0; i < MAX_STARTING_LOCATIONS; i++) { PlayerLocationIndicator indicator = new PlayerLocationIndicator(WindowManager, mpColors, nameBackgroundColor, nameBorderColor, contextMenu); indicator.FontIndex = FontIndex; indicator.Visible = false; indicator.Enabled = false; indicator.AngularVelocity = angularVelocity; indicator.HoverRemapColor = hoverRemapColor; indicator.ReversedAngularVelocity = reservedAngularVelocity; indicator.WaypointTexture = AssetLoader.LoadTexture(string.Format("slocindicator{0}.png", i + 1)); indicator.Tag = i; indicator.LeftClick += Indicator_LeftClick; indicator.RightClick += Indicator_RightClick; startingLocationIndicators[i] = indicator; AddChild(indicator); } contextMenu.ClientRectangle = new Rectangle(0, 0, 150, 2); AddChild(contextMenu); contextMenu.Disable(); briefingBox = new CoopBriefingBox(WindowManager); AddChild(briefingBox); briefingBox.Disable(); sndClickSound = new EnhancedSoundEffect("button.wav"); sndDropdownSound = new EnhancedSoundEffect("dropdown.wav"); base.Initialize(); ClientRectangleUpdated += (s, e) => UpdateMap(); }
public void SetFields(List <PlayerInfo> players, List <PlayerInfo> aiPlayers, List <MultiplayerColor> mpColors, string[] sides, IniFile gameOptionsIni) { this.players = players; this.aiPlayers = aiPlayers; this.mpColors = mpColors; this.sides = sides; this.gameOptionsIni = gameOptionsIni; Color nameBackgroundColor = AssetLoader.GetRGBAColorFromString( ClientConfiguration.Instance.MapPreviewNameBackgroundColor); Color nameBorderColor = AssetLoader.GetRGBAColorFromString( ClientConfiguration.Instance.MapPreviewNameBorderColor); double angularVelocity = gameOptionsIni.GetDoubleValue("General", "StartingLocationAngularVelocity", 0.015); double reservedAngularVelocity = gameOptionsIni.GetDoubleValue("General", "ReservedStartingLocationAngularVelocity", -0.0075); Color hoverRemapColor = AssetLoader.GetRGBAColorFromString(ClientConfiguration.Instance.MapPreviewStartingLocationHoverRemapColor); startingLocationIndicators = new PlayerLocationIndicator[MAX_STARTING_LOCATIONS]; // Init starting location indicators for (int i = 0; i < MAX_STARTING_LOCATIONS; i++) { PlayerLocationIndicator indicator = new PlayerLocationIndicator(WindowManager, mpColors, nameBackgroundColor, nameBorderColor, contextMenu); indicator.FontIndex = FontIndex; indicator.Visible = false; indicator.Enabled = false; indicator.AngularVelocity = angularVelocity; indicator.HoverRemapColor = hoverRemapColor; indicator.ReversedAngularVelocity = reservedAngularVelocity; indicator.WaypointTexture = AssetLoader.LoadTexture(string.Format("slocindicator{0}.png", i + 1)); indicator.Tag = i; indicator.LeftClick += Indicator_LeftClick; indicator.RightClick += Indicator_RightClick; startingLocationIndicators[i] = indicator; AddChild(indicator); } briefingBox = new CoopBriefingBox(WindowManager); AddChild(briefingBox); briefingBox.Disable(); ClientRectangleUpdated += (s, e) => UpdateMap(); }
/// <summary> /// Updates the map preview texture's position inside /// this control's display rectangle and the /// starting location indicators' positions. /// </summary> private void UpdateMap() { if (disposeTextures && texture != null && !texture.IsDisposed) { texture.Dispose(); } if (Map == null) { texture = null; briefingBox.Disable(); contextMenu.Disable(); foreach (var indicator in startingLocationIndicators) { indicator.Disable(); } return; } if (Map.PreviewTexture == null) { texture = Map.LoadPreviewTexture(); disposeTextures = true; } else { texture = Map.PreviewTexture; disposeTextures = false; } if (!string.IsNullOrEmpty(Map.Briefing)) { briefingBox.SetText(Map.Briefing); briefingBox.Enable(); if (IsActive) { briefingBox.SetAlpha(0f); } } else { briefingBox.Disable(); } double xRatio = (Width - 2) / (double)texture.Width; double yRatio = (Height - 2) / (double)texture.Height; double ratio; int texturePositionX = 1; int texturePositionY = 1; int textureHeight = 0; int textureWidth = 0; if (xRatio > yRatio) { ratio = yRatio; textureHeight = Height - 2; textureWidth = (int)(texture.Width * ratio); texturePositionX = (int)(Width - 2 - textureWidth) / 2; } else { ratio = xRatio; textureWidth = Width - 2; textureHeight = (int)(texture.Height * ratio); texturePositionY = (Height - 2 - textureHeight) / 2 + 1; } useNearestNeighbour = ratio < 1.0; textureRectangle = new Rectangle(texturePositionX, texturePositionY, textureWidth, textureHeight); List <Point> startingLocations = Map.GetStartingLocationPreviewCoords(new Point(texture.Width, texture.Height)); for (int i = 0; i < startingLocations.Count && i < Map.MaxPlayers; i++) { PlayerLocationIndicator indicator = startingLocationIndicators[i]; Point location = new Point( texturePositionX + (int)(startingLocations[i].X * ratio), texturePositionY + (int)(startingLocations[i].Y * ratio)); indicator.SetPosition(location); indicator.Enabled = true; indicator.Visible = true; } for (int i = startingLocations.Count; i < MAX_STARTING_LOCATIONS; i++) { startingLocationIndicators[i].Disable(); } }
/// <summary> /// Updates the map preview texture's position inside /// this control's display rectangle and the /// starting location indicators' positions. /// </summary> private void UpdateMap() { if (disposeTextures && previewTexture != null && !previewTexture.IsDisposed) { previewTexture.Dispose(); } extraTextures.Clear(); if (Map == null) { previewTexture = null; briefingBox.Disable(); contextMenu.Disable(); foreach (var indicator in startingLocationIndicators) { indicator.Disable(); } return; } if (Map.PreviewTexture == null) { previewTexture = Map.LoadPreviewTexture(); disposeTextures = true; } else { previewTexture = Map.PreviewTexture; disposeTextures = false; } if (!string.IsNullOrEmpty(Map.Briefing)) { briefingBox.SetText(Map.Briefing); briefingBox.Enable(); if (IsActive) { briefingBox.SetAlpha(0f); } } else { briefingBox.Disable(); } double xRatio = (Width - 2) / (double)previewTexture.Width; double yRatio = (Height - 2) / (double)previewTexture.Height; double ratio; int texturePositionX = 1; int texturePositionY = 1; int textureHeight = 0; int textureWidth = 0; if (xRatio > yRatio) { ratio = yRatio; textureHeight = Height - 2; textureWidth = (int)(previewTexture.Width * ratio); texturePositionX = (int)(Width - 2 - textureWidth) / 2; } else { ratio = xRatio; textureWidth = Width - 2; textureHeight = (int)(previewTexture.Height * ratio); texturePositionY = (Height - 2 - textureHeight) / 2 + 1; } useNearestNeighbour = ratio < 1.0; textureRectangle = new Rectangle(texturePositionX, texturePositionY, textureWidth, textureHeight); List <Point> startingLocations = Map.GetStartingLocationPreviewCoords(new Point(previewTexture.Width, previewTexture.Height)); for (int i = 0; i < startingLocations.Count && i < Map.MaxPlayers; i++) { PlayerLocationIndicator indicator = startingLocationIndicators[i]; Point location = new Point( texturePositionX + (int)(startingLocations[i].X * ratio), texturePositionY + (int)(startingLocations[i].Y * ratio)); indicator.SetPosition(location); indicator.Enabled = true; indicator.Visible = true; } for (int i = startingLocations.Count; i < MAX_STARTING_LOCATIONS; i++) { startingLocationIndicators[i].Disable(); } foreach (var mapExtraTexture in Map.GetExtraMapPreviewTextures()) { // LoadTexture makes use of a texture cache // so we don't need to cache the textures manually Texture2D extraTexture = AssetLoader.LoadTexture(mapExtraTexture.TextureName); Point location = PreviewTexturePointToControlAreaPoint( Map.MapPointToMapPreviewPoint(mapExtraTexture.Point, new Point(previewTexture.Width - (extraTexture.Width / 2), previewTexture.Height - (extraTexture.Height / 2)), mapExtraTexture.Level), ratio); extraTextures.Add(new ExtraMapPreviewTexture(extraTexture, location)); } }