/// <summary> /// Collects the coordinates of the cells of the target-set. /// </summary> /// <param name="target">The target of the changeset.</param> /// <returns>The collected coordinates.</returns> protected virtual RCSet <RCIntVector> CollectTargetSet(ICellDataChangeSetTarget target) { RCSet <RCIntVector> targetset = new RCSet <RCIntVector>(); for (int x = 0; x < target.CellSize.X; x++) { for (int y = 0; y < target.CellSize.Y; y++) { RCIntVector index = new RCIntVector(x, y); if (target.GetCell(index) != null) { targetset.Add(index); } } } return(targetset); }
/// <summary> /// Invalidates the absolute pixel scaling of this UIObject and all of it's children. /// </summary> private void InvalidateAbsPixelScaling() { /// Invalidate the cache and raise the appropriate event if necessary. RCIntVector prevAbsPixelScaling = this.absPixelScalingCache.Value; this.absPixelScalingCache.Invalidate(); if (this.AbsolutePixelScalingChanged != null && prevAbsPixelScaling != this.absPixelScalingCache.Value) { this.AbsolutePixelScalingChanged(this, prevAbsPixelScaling, this.absPixelScalingCache.Value); } /// Call this method recursively on all children. foreach (UIObject child in this.children) { child.InvalidateAbsPixelScaling(); } }
/// <see cref="CellDataChangeSetBase.CollectTargetSet"/> protected override RCSet <RCIntVector> CollectTargetSet(ICellDataChangeSetTarget target) { RCSet <RCIntVector> targetset = new RCSet <RCIntVector>(); for (int x = this.targetRect.X; x < this.targetRect.Right; x++) { for (int y = this.targetRect.Y; y < this.targetRect.Bottom; y++) { RCIntVector index = new RCIntVector(x, y); if (target.GetCell(index) != null) { targetset.Add(index); } } } return(targetset); }
/// <see cref="IMapTerrainView.GetWalkableCells"/> public List <RCIntRectangle> GetWalkableCells() { List <RCIntRectangle> retList = new List <RCIntRectangle>(); for (int row = this.MapWindowBC.AttachedWindow.CellWindow.Top; row < this.MapWindowBC.AttachedWindow.CellWindow.Bottom; row++) { for (int col = this.MapWindowBC.AttachedWindow.CellWindow.Left; col < this.MapWindowBC.AttachedWindow.CellWindow.Right; col++) { RCIntVector cellCoords = new RCIntVector(col, row); if (this.Map.GetCell(cellCoords).IsBuildable) { retList.Add(this.MapWindowBC.AttachedWindow.CellToWindowRect(new RCIntRectangle(cellCoords, new RCIntVector(1, 1)))); } } } return(retList); }
/// <see cref="RCMapDisplayExtension.GetMousePointer_i"/> protected override UIPointer GetMousePointer_i(RCIntVector localPosition) { if (this.MouseHandler != null) { if (this.MouseHandler.SelectionBox != RCIntRectangle.Undefined) { return(this.selectionBoxPointer); } else if (this.MouseHandler.DisplayCrosshairs) { return(this.crosshairsPointer); } /// TODO: display scrolling pointers if scroll is in progress! } return(null); }
/// <see cref="IIsoTile.GetCellMapCoords"/> public RCIntVector GetCellMapCoords(RCIntVector index) { if (this.referenceCell == null) { throw new InvalidOperationException("Reference cell doesn't exist!"); } if (index == RCIntVector.Undefined) { throw new ArgumentNullException("index"); } if (index.X < 0 || index.Y < 0 || index.X >= MapStructure.QUAD_PER_ISO_VERT * MapStructure.NAVCELL_PER_QUAD || index.Y >= MapStructure.QUAD_PER_ISO_HORZ * MapStructure.NAVCELL_PER_QUAD) { throw new ArgumentOutOfRangeException("index"); } return(this.referenceCell.MapCoords + index - this.referenceCell.IsoIndices); }
/// <see cref="IMapEditorService.PlaceTerrainObject"/> public bool PlaceTerrainObject(RCIntVector position, string terrainObject) { if (this.scenarioManager.ActiveScenario == null) { throw new InvalidOperationException("No active scenario!"); } if (position == RCIntVector.Undefined) { throw new ArgumentNullException("position"); } if (terrainObject == null) { throw new ArgumentNullException("terrainObject"); } ITerrainObjectType terrainObjType = this.scenarioManager.ActiveScenario.Map.Tileset.GetTerrainObjectType(terrainObject); RCIntVector navCellCoords = this.mapWindowBC.AttachedWindow.WindowToMapCoords(position).Round(); IQuadTile quadTileAtPos = this.scenarioManager.ActiveScenario.Map.GetCell(navCellCoords).ParentQuadTile; RCIntVector topLeftQuadCoords = quadTileAtPos.MapCoords - terrainObjType.QuadraticSize / 2; ITerrainObject placedTerrainObject = null; if (topLeftQuadCoords.X >= 0 && topLeftQuadCoords.Y >= 0 && topLeftQuadCoords.X < this.scenarioManager.ActiveScenario.Map.Size.X && topLeftQuadCoords.Y < this.scenarioManager.ActiveScenario.Map.Size.Y) { IQuadTile targetQuadTile = this.scenarioManager.ActiveScenario.Map.GetQuadTile(topLeftQuadCoords); placedTerrainObject = this.mapEditor.PlaceTerrainObject(this.scenarioManager.ActiveScenario.Map, targetQuadTile, terrainObjType); } if (placedTerrainObject != null) { RCNumRectangle terrObjRect = new RCNumRectangle(this.scenarioManager.ActiveScenario.Map.GetQuadTile(placedTerrainObject.MapCoords).GetCell(new RCIntVector(0, 0)).MapCoords, placedTerrainObject.CellSize) - new RCNumVector(1, 1) / 2; foreach (Entity affectedEntity in this.scenarioManager.ActiveScenario.GetElementsOnMap <Entity>(terrObjRect, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects)) { if (affectedEntity.CheckPlacementConstraints(affectedEntity.MapObject.QuadraticPosition.Location, new RCSet <Entity>()).Count != 0) { affectedEntity.DetachFromMap(); this.scenarioManager.ActiveScenario.RemoveElementFromScenario(affectedEntity); affectedEntity.Dispose(); } } } return(placedTerrainObject != null); }
/// <summary> /// Constructs a TerrainObjectType instance. /// </summary> /// <param name="name">The name of the TerrainObjectType.</param> /// <param name="imageData">The byte sequence that contains the image data of the TerrainObjectType.</param> /// <param name="quadraticSize">The size of the TerrainObjectType in quadratic tiles.</param> /// <param name="transparentColor">The transparent color of this TerrainObjectType.</param> /// <param name="tileset">Reference to the tileset that this TerrainObjectType belongs to.</param> public TerrainObjectType(string name, byte[] imageData, RCIntVector quadraticSize, RCColor transparentColor, TileSet tileset) { if (name == null) { throw new ArgumentNullException("name"); } if (imageData == null || imageData.Length == 0) { throw new ArgumentNullException("imageData"); } if (quadraticSize == RCIntVector.Undefined) { throw new ArgumentNullException("quadraticSize"); } if (transparentColor == RCColor.Undefined) { throw new ArgumentNullException("transparentColor"); } if (tileset == null) { throw new ArgumentNullException("tileset"); } if (quadraticSize.X <= 0 || quadraticSize.Y <= 0) { throw new ArgumentOutOfRangeException("quadraticSize", "Quadratic size cannot be 0 in any direction!"); } this.name = name; this.imageData = imageData; this.quadraticSize = quadraticSize; this.transparentColor = transparentColor; this.tileset = tileset; this.areaCanBeExcluded = true; this.constraints = new List <ITerrainObjectConstraint>(); this.cellDataChangesets = new List <ICellDataChangeSet>(); this.includedQuadCoords = new RCSet <RCIntVector>(); for (int x = 0; x < quadraticSize.X; x++) { for (int y = 0; y < quadraticSize.Y; y++) { this.includedQuadCoords.Add(new RCIntVector(x, y)); } } }
/// <summary> /// Get the list of the UISensitiveObjects that are visible at the given position. The position has to be given /// in the local coordinate-system of the SensitiveRoot. /// </summary> /// <param name="sensitivePosition">The position to check.</param> /// <returns> /// The list of the visible UISensitiveObjects starting from SensitiveRoot down into the sensitive-tree. /// </returns> /// <remarks>You can call this method on any UISensitiveObject in the sensitive-tree.</remarks> public List <UISensitiveObject> GetObjectsVisibleAt(RCIntVector sensitivePosition) { if (this.sensitiveParent == null) { /// If this is the root of the sensitive-tree, start the algorythm. List <UISensitiveObject> visibleObjects = new List <UISensitiveObject>(); if (this.AbsoluteSensitiveRange.Contains(sensitivePosition)) { this.GetObjectsVisibleAt(sensitivePosition, ref visibleObjects); } return(visibleObjects); } else { /// Otherwise call the same method for the root object. return(this.SensitiveRoot.GetObjectsVisibleAt(sensitivePosition)); } }
/// <summary> /// This recursive method collects the UISensitiveObjects that are visible at a given point in /// the coordinate-system of the sensitive-root. /// </summary> /// <param name="sensitivePosition">The position to check the visibility from.</param> /// <param name="collectedObjects">The collected objects.</param> private void GetObjectsVisibleAt(RCIntVector sensitivePosition, ref List <UISensitiveObject> collectedObjects) { collectedObjects.Add(this); if (this.AbsoluteSensitiveClip != RCIntRectangle.Undefined ? this.AbsoluteSensitiveClip.Contains(sensitivePosition) : this.AbsoluteSensitiveRange.Contains(sensitivePosition)) { /// Continue the recursion with the first visible sensitive child. foreach (UISensitiveObject child in this.sensitiveChildren) { if (child.AbsoluteSensitiveRange.Contains(sensitivePosition)) { child.GetObjectsVisibleAt(sensitivePosition, ref collectedObjects); break; } } } }
/// <summary> /// Checks whether placing an entity of this type to the given scenario at the given quadratic position remains inside the boundaries of /// the map and collects all the quadratic coordinates relative to the given position that violates this condition. /// </summary> /// <param name="scenario">Reference to the given scenario.</param> /// <param name="position">The position to be checked.</param> /// <param name="violatingQuadCoords">The target list in which to collect the violating quadratic coordinates.</param> private void CheckMapBorderIntersections(Scenario scenario, RCIntVector position, ref RCSet <RCIntVector> violatingQuadCoords) { RCIntVector quadSize = scenario.Map.CellToQuadSize(this.Area.Read().Size); for (int quadX = 0; quadX < quadSize.X; quadX++) { for (int quadY = 0; quadY < quadSize.Y; quadY++) { RCIntVector relQuadCoords = new RCIntVector(quadX, quadY); RCIntVector absQuadCoords = position + relQuadCoords; if (absQuadCoords.X < 0 || absQuadCoords.X >= scenario.Map.Size.X || absQuadCoords.Y < 0 || absQuadCoords.Y >= scenario.Map.Size.Y) { violatingQuadCoords.Add(relQuadCoords); } } } }
/// <summary> /// Calculates the current selection box in the coordinate-system of the map control. /// </summary> /// <returns> /// The calculated selection box or RCIntRectangle.Undefined if there is no active selection box. /// </returns> private RCIntRectangle CalculateSelectionBox() { if (this.selectionBoxStartPosition != RCIntVector.Undefined && this.selectionBoxCurrPosition != RCIntVector.Undefined) { RCIntVector topLeftCorner = new RCIntVector(Math.Min(this.selectionBoxStartPosition.X, this.selectionBoxCurrPosition.X), Math.Min(this.selectionBoxStartPosition.Y, this.selectionBoxCurrPosition.Y)); RCIntVector bottomRightCorner = new RCIntVector(Math.Max(this.selectionBoxStartPosition.X, this.selectionBoxCurrPosition.X), Math.Max(this.selectionBoxStartPosition.Y, this.selectionBoxCurrPosition.Y)); return(new RCIntRectangle(topLeftCorner.X, topLeftCorner.Y, bottomRightCorner.X - topLeftCorner.X + 1, bottomRightCorner.Y - topLeftCorner.Y + 1)); } else { return(RCIntRectangle.Undefined); } }
/// <see cref="IMapWindowBC.AttachWindow"/> public void AttachWindow(RCIntVector windowPixelSize) { if (windowPixelSize == RCIntVector.Undefined) { throw new ArgumentNullException("windowPixelSize"); } if (this.ActiveScenario == null) { throw new InvalidOperationException("There is no active scenario!"); } if (this.attachedWindow != null) { throw new InvalidOperationException("Window already attached!"); } this.attachedWindow = new PartialMapWindow(this.ActiveScenario, this.desiredCenterPositionOfAttachedWindow, windowPixelSize); this.desiredCenterPositionOfAttachedWindow = RCNumVector.Undefined; }
/// <summary> /// Constructs a construction progress display control at the given position with the given size. /// </summary> /// <param name="position">The position of the construction progress display control.</param> /// <param name="size">The size of the construction progress display control.</param> public RCConstructionProgressDisplay(RCIntVector position, RCIntVector size) : base(position, size) { IViewService viewService = ComponentManager.GetInterface <IViewService>(); this.productionDetailsView = viewService.CreateView <IProductionDetailsView>(); this.progressBarSprite = UIResourceManager.GetResource <UISprite>("RC.App.Sprites.ProductionProgressBar"); this.progressBarBrush = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(RCColor.Green, new RCIntVector(1, 1), UIWorkspace.Instance.PixelScaling); this.progressBarBrush.Upload(); UIFont textFont = UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font5"); this.underConstructionText = new UIString("Under Construction", textFont, UIWorkspace.Instance.PixelScaling, RCColor.White); this.textPosition = new RCIntVector( (PROGRESSBAR_INNER_RECT.Left + PROGRESSBAR_INNER_RECT.Right - this.underConstructionText.Width) / 2, PROGRESSBAR_SPRITE_POS.Y - this.underConstructionText.Font.CharBottomMaximum - 1); }
/// <summary> /// Converts a rectangle of cells to a rectangle of quadratic tiles. /// </summary> /// <param name="cellRect">The cell rectangle to convert.</param> /// <returns>The quadratic rectangle.</returns> public RCIntRectangle CellToQuadRect(RCIntRectangle cellRect) { if (cellRect == RCIntRectangle.Undefined) { throw new ArgumentNullException("cellRect"); } RCIntVector topLeftNavCellCoords = new RCIntVector(Math.Min(this.CellSize.X - 1, Math.Max(0, cellRect.Left)), Math.Min(this.CellSize.Y - 1, Math.Max(0, cellRect.Top))); RCIntVector bottomRightNavCellCoords = new RCIntVector(Math.Min(this.CellSize.X - 1, Math.Max(0, cellRect.Right - 1)), Math.Min(this.CellSize.Y - 1, Math.Max(0, cellRect.Bottom - 1))); IQuadTile topLeftQuadTile = this.GetCell(topLeftNavCellCoords).ParentQuadTile; IQuadTile bottomRightQuadTile = this.GetCell(bottomRightNavCellCoords).ParentQuadTile; RCIntRectangle quadTileWindow = new RCIntRectangle( topLeftQuadTile.MapCoords.X, topLeftQuadTile.MapCoords.Y, bottomRightQuadTile.MapCoords.X - topLeftQuadTile.MapCoords.X + 1, bottomRightQuadTile.MapCoords.Y - topLeftQuadTile.MapCoords.Y + 1); return(quadTileWindow); }
/// <summary> /// Creates a vertical or horizontal scrollbar with custom settings. /// </summary> /// <param name="position">The position of the upper-left corner of the scrollbar.</param> /// <param name="length">The length of the scrollbar.</param> /// <param name="settings">The settings of the scrollbar.</param> public RCScrollBar(RCIntVector position, int length, Settings settings) : base(position, settings.Alignment == Alignment.Horizontal ? new RCIntVector(length, RCScrollBar.WIDTH) : new RCIntVector(RCScrollBar.WIDTH, length), new UIScrollBar.Settings() { Alignment = settings.Alignment == Alignment.Horizontal ? UIScrollBar.Alignment.Horizontal : UIScrollBar.Alignment.Vertical, ButtonExtension = RCScrollBar.BUTTON_SIZE, IntervalLength = settings.IntervalLength, SliderButtonRadius = RCScrollBar.WIDTH / 2, StepValueChange = settings.StepValueChange, TimeBetweenSteps = settings.TimeBetweenSteps, TrackingValueChange = settings.TrackingValueChange, TimeBetweenTrackings = settings.TimeBetweenTrackings }) { this.controlSprite = UIResourceManager.GetResource <UISprite>(settings.Alignment == Alignment.Horizontal ? "RC.App.Sprites.ScrollbarHorz" : "RC.App.Sprites.ScrollbarVert"); this.alignment = settings.Alignment; this.sliderTrackLength = length - 2 * RCScrollBar.BUTTON_SIZE; }
/// <summary> /// Reduces this flood with the amount of the last enlargement. /// </summary> public void Reduce() { if (this.enlargements.Count == 0) { throw new InvalidOperationException("FloodArea area has reached its minimum size!"); } /// Remove the last enlargement. int amount = this.enlargements[this.enlargements.Count - 1]; this.enlargements.RemoveAt(this.enlargements.Count - 1); this.currentRadius -= amount; this.tmpFloodItems = null; /// Calculate the corners. RCIntVector northCorner = new RCIntVector(-(this.enlargements.Count + 2), -(this.enlargements.Count + 2)); RCIntVector eastCorner = new RCIntVector((this.enlargements.Count + 2), -(this.enlargements.Count + 2)); RCIntVector westCorner = new RCIntVector(-(this.enlargements.Count + 2), (this.enlargements.Count + 2)); RCIntVector southCorner = new RCIntVector((this.enlargements.Count + 2), (this.enlargements.Count + 2)); /// Remove the old vertical borders. this.RemoveVertical(-(this.currentRadius + amount), northCorner.Y, northCorner.X); this.RemoveVertical(-(this.currentRadius + amount), eastCorner.Y, eastCorner.X); this.RemoveVertical(westCorner.Y, this.currentRadius + amount, westCorner.X); this.RemoveVertical(southCorner.Y, this.currentRadius + amount, southCorner.X); /// Remove the old horizontal borders. this.RemoveHorizontal(-(this.currentRadius + amount), northCorner.X, northCorner.Y); this.RemoveHorizontal(-(this.currentRadius + amount), westCorner.X, westCorner.Y); this.RemoveHorizontal(eastCorner.X, this.currentRadius + amount, eastCorner.Y); this.RemoveHorizontal(southCorner.X, this.currentRadius + amount, southCorner.Y); /// Remove the old internal areas. this.RemoveArea(new RCIntRectangle(northCorner.X + 1, -(this.currentRadius + amount), eastCorner.X - northCorner.X - 1, amount)); this.RemoveArea(new RCIntRectangle(westCorner.X + 1, this.currentRadius + 1, southCorner.X - westCorner.X - 1, amount)); this.RemoveArea(new RCIntRectangle(-(this.currentRadius + amount), northCorner.Y + 1, amount, westCorner.Y - northCorner.Y - 1)); this.RemoveArea(new RCIntRectangle(this.currentRadius + 1, eastCorner.Y + 1, amount, southCorner.Y - eastCorner.Y - 1)); this.northCorner = new RCIntVector(-(this.enlargements.Count + 1), -(this.enlargements.Count + 1)); this.eastCorner = new RCIntVector((this.enlargements.Count + 1), -(this.enlargements.Count + 1)); this.westCorner = new RCIntVector(-(this.enlargements.Count + 1), (this.enlargements.Count + 1)); this.southCorner = new RCIntVector((this.enlargements.Count + 1), (this.enlargements.Count + 1)); }
/// <summary> /// Computes the minimum size of a quadratic rectangle that can cover an area on the map with the given size. /// </summary> /// <param name="cellSize">The size of the area in cells.</param> /// <returns>The minimum size of a covering quadratic rectangle.</returns> public RCIntVector CellToQuadSize(RCNumVector cellSize) { if (cellSize == RCNumVector.Undefined) { throw new ArgumentNullException("cellSize"); } if (cellSize.X <= 0 || cellSize.Y <= 0) { throw new ArgumentOutOfRangeException("cellSize", "Both component of cellSize must be positive!"); } RCIntVector cellSizeInt = (RCIntVector)cellSize; if (cellSizeInt.X != cellSize.X && cellSizeInt.Y != cellSize.Y) { cellSizeInt += new RCIntVector(1, 1); } else if (cellSizeInt.X != cellSize.X && cellSizeInt.Y == cellSize.Y) { cellSizeInt += new RCIntVector(1, 0); } else if (cellSizeInt.X == cellSize.X && cellSizeInt.Y != cellSize.Y) { cellSizeInt += new RCIntVector(0, 1); } RCIntVector quadSize = cellSizeInt / MapStructure.NAVCELL_PER_QUAD; if (cellSizeInt.X % MapStructure.NAVCELL_PER_QUAD != 0 && cellSizeInt.Y % MapStructure.NAVCELL_PER_QUAD != 0) { quadSize += new RCIntVector(1, 1); } else if (cellSizeInt.X % MapStructure.NAVCELL_PER_QUAD != 0 && cellSizeInt.Y % MapStructure.NAVCELL_PER_QUAD == 0) { quadSize += new RCIntVector(1, 0); } else if (cellSizeInt.X % MapStructure.NAVCELL_PER_QUAD == 0 && cellSizeInt.Y % MapStructure.NAVCELL_PER_QUAD != 0) { quadSize += new RCIntVector(0, 1); } return(quadSize); }
/// <summary> /// Gets the scenario elements of the given type that are attached to at least one of the given layers of the map inside the search area /// around the given position. /// </summary> /// <typeparam name="T">The type of the scenario elements to get.</typeparam> /// <param name="position">The given position.</param> /// <param name="searchRadius">The radius of the search area given in quadratic tiles.</param> /// <param name="firstLayer">The first layer to search in.</param> /// <param name="furtherLayers">List of the further layers to search in.</param> /// <returns> /// A list that contains the scenario elements of the given type that are attached to at least one of the given layers of the map inside /// the search area. /// </returns> public RCSet <T> GetElementsOnMap <T>(RCNumVector position, int searchRadius, MapObjectLayerEnum firstLayer, params MapObjectLayerEnum[] furtherLayers) where T : ScenarioElement { if (position == RCNumVector.Undefined) { throw new ArgumentNullException("position"); } if (searchRadius <= 0) { throw new ArgumentOutOfRangeException("searchRadius", "The radius of the search area shall be greater than 0!"); } if (furtherLayers == null) { throw new ArgumentNullException("furtherLayers"); } RCIntVector quadCoordAtPosition = this.Map.GetCell(position.Round()).ParentQuadTile.MapCoords; RCIntVector topLeftQuadCoord = quadCoordAtPosition - new RCIntVector(searchRadius - 1, searchRadius - 1); RCIntVector bottomRightQuadCoord = quadCoordAtPosition + new RCIntVector(searchRadius - 1, searchRadius - 1); RCIntRectangle quadRect = new RCIntRectangle(topLeftQuadCoord, bottomRightQuadCoord - topLeftQuadCoord + new RCIntVector(1, 1)); RCSet <T> retList = new RCSet <T>(); foreach (MapObject mapObj in this.mapObjects[firstLayer].GetContents((RCNumRectangle)this.Map.QuadToCellRect(quadRect) - new RCNumVector(1, 1) / 2)) { T elementAsT = mapObj.Owner as T; if (elementAsT != null) { retList.Add(elementAsT); } } foreach (MapObjectLayerEnum furtherLayer in furtherLayers) { foreach (MapObject mapObj in this.mapObjects[furtherLayer].GetContents((RCNumRectangle)this.Map.QuadToCellRect(quadRect) - new RCNumVector(1, 1) / 2)) { T elementAsT = mapObj.Owner as T; if (elementAsT != null) { retList.Add(elementAsT); } } } return(retList); }
/// <see cref="ITargetPositionListener.SelectTargetPosition"/> public void SelectTargetPosition(RCNumVector targetPosition) { if (this.placeSelectedBuilding) { /// A position for the current selection is being selected. int[] currentSelection = this.selectionManagerBC.CurrentSelection.ToArray(); if (currentSelection.Length != 1) { throw new InvalidOperationException("The number of the currently selected entities must be 1!"); } Building selectedBuilding = this.scenarioManagerBC.ActiveScenario.GetElement <Building>(currentSelection[0]); if (selectedBuilding == null) { throw new InvalidOperationException("The currently selected entity doesn't exist or is not a building!"); } IQuadTile quadTileAtPos = this.scenarioManagerBC.ActiveScenario.Map.GetCell(targetPosition.Round()).ParentQuadTile; RCIntVector objQuadSize = this.scenarioManagerBC.ActiveScenario.Map.CellToQuadSize(selectedBuilding.ElementType.Area.Read().Size); RCIntVector topLeftQuadCoords = quadTileAtPos.MapCoords - objQuadSize / 2; this.CommandBuilder.TargetPosition = topLeftQuadCoords; } else if (this.buildingTypeName != null) { /// A position for a building type is being selected. IBuildingType buildingType = this.scenarioManagerBC.Metadata.GetBuildingType(this.buildingTypeName); if (buildingType == null) { throw new InvalidOperationException(string.Format("Building type '{0}' is not defined in the metadata!", this.buildingTypeName)); } IQuadTile quadTileAtPos = this.scenarioManagerBC.ActiveScenario.Map.GetCell(targetPosition.Round()).ParentQuadTile; RCIntVector objQuadSize = this.scenarioManagerBC.ActiveScenario.Map.CellToQuadSize(buildingType.Area.Read().Size); RCIntVector topLeftQuadCoords = quadTileAtPos.MapCoords - objQuadSize / 2; this.CommandBuilder.TargetPosition = topLeftQuadCoords; } else { /// A point on the map is being selected. this.CommandBuilder.TargetPosition = targetPosition; } }
/// <see cref="CellDataChangeSetBase.CollectTargetSet"/> protected override RCSet<RCIntVector> CollectTargetSet(ICellDataChangeSetTarget target) { RCSet<RCIntVector> targetset = new RCSet<RCIntVector>(); for (int x = 0; x < target.CellSize.X; x++) { for (int y = 0; y < target.CellSize.Y; y++) { RCNumVector cellIsoCoordsDbl = MapStructure.NavCellIsoTransform.TransformAB(new RCNumVector(x, y)) * 2; bool isCellInQuarter = false; if (this.targetQuarter == MapDirection.North) { isCellInQuarter = cellIsoCoordsDbl.X >= -1 && cellIsoCoordsDbl.X < 0 && cellIsoCoordsDbl.Y >= -1 && cellIsoCoordsDbl.Y < 0; } else if (this.targetQuarter == MapDirection.East) { isCellInQuarter = cellIsoCoordsDbl.X >= 0 && cellIsoCoordsDbl.X < 1 && cellIsoCoordsDbl.Y >= -1 && cellIsoCoordsDbl.Y < 0; } else if (this.targetQuarter == MapDirection.South) { isCellInQuarter = cellIsoCoordsDbl.X >= 0 && cellIsoCoordsDbl.X < 1 && cellIsoCoordsDbl.Y >= 0 && cellIsoCoordsDbl.Y < 1; } else if (this.targetQuarter == MapDirection.West) { isCellInQuarter = cellIsoCoordsDbl.X >= -1 && cellIsoCoordsDbl.X < 0 && cellIsoCoordsDbl.Y >= 0 && cellIsoCoordsDbl.Y < 1; } else { throw new MapException("Unexpected quarter!"); } if (isCellInQuarter) { RCIntVector index = new RCIntVector(x, y); if (target.GetCell(index) != null) { targetset.Add(index); } } } } return targetset; }
/// <summary> /// Constructs a command button at the given rectangular area inside the command panel. /// </summary> /// <param name="slotCoords">The coordinates of the slot of this button on the command panel (row; col).</param> /// <param name="commandButtonSprites"> /// List of the command button sprite groups mapped by the appropriate button state. /// </param> public RCCommandButton(RCIntVector slotCoords, Dictionary <CommandButtonStateEnum, ISpriteGroup> cmdButtonSprites) : base(BUTTON_POSITIONS[slotCoords.X, slotCoords.Y].Location, BUTTON_POSITIONS[slotCoords.X, slotCoords.Y].Size) { if (slotCoords == RCIntVector.Undefined) { throw new ArgumentNullException("slotCoords"); } if (cmdButtonSprites == null) { throw new ArgumentNullException("cmdButtonSprites"); } this.slotCoords = slotCoords; this.commandButtonSprites = cmdButtonSprites; IViewService viewService = ComponentManager.GetInterface <IViewService>(); this.commandPanelView = viewService.CreateView <ICommandView>(); this.commandService = ComponentManager.GetInterface <ICommandService>(); this.Pressed += this.OnButtonPressed; }
/// <see cref="IAgent.MoveTo"/> public void MoveTo(RCIntVector targetPosition) { if (targetPosition == RCIntVector.Undefined) { throw new ArgumentNullException("targetPosition"); } if (this.movingSize == -1) { throw new NotSupportedException("This agent is not supported to move!"); } this.stepBuffer = 0; this.stoppedStateTimer = -1; this.deadlockTimer = -1; this.MovingStatus = AgentMovingStatusEnum.Moving; targetPosition = new RCIntVector(Math.Max(targetPosition.X, 0), Math.Max(targetPosition.Y, 0)); this.currentPath = new Path(this.grid[this.agentArea.Location.X, this.agentArea.Location.Y], this.grid[targetPosition.X, targetPosition.Y], this); this.currentStepIndex = 0; this.agentsWaitingFor.Clear(); }
/// <see cref="IBuildingTypeInternal.GetRelativeAddonPosition"/> public RCIntVector GetRelativeAddonPosition(IMapAccess map, IAddonTypeInternal addonType) { if (map == null) { throw new ArgumentNullException("map"); } if (addonType == null) { throw new ArgumentNullException("addonType"); } if (!this.HasAddonType(addonType.Name)) { throw new ArgumentException(string.Format("Building type '{0}' is not defined as the main building for addon type '{1}'!", this.Name, addonType.Name)); } RCIntVector buildingQuadSize = map.CellToQuadSize(this.Area.Read().Size); int addonQuadHeight = map.CellToQuadSize(addonType.Area.Read().Size).Y; return(new RCIntVector(buildingQuadSize.X, buildingQuadSize.Y - addonQuadHeight)); }
/// <summary> /// Raises the mouse button events on the appropriate sensor. /// </summary> private void RaiseMouseButtonEvents(RCSet <UIMouseButton> buttons, RCIntVector newPointerPos, UIMouseSensor targetSensor) { foreach (UIMouseButton btn in this.pressedButtons) { if (!buttons.Contains(btn)) { targetSensor.OnButtonUp(newPointerPos, btn); } } foreach (UIMouseButton btn in buttons) { if (!this.pressedButtons.Contains(btn)) { targetSensor.OnButtonDown(newPointerPos, btn); } } }
/// <summary> /// Calculates the quadratic coordinates currently visible by the owner entity. /// </summary> /// <returns>The quadratic coordinates currently visible by the owner entity.</returns> private RCSet <RCIntVector> CalculateVisibleQuadCoords() { IQuadTile currentQuadTile = this.owner.Read().Scenario.Map.GetCell(this.owner.Read().MotionControl.PositionVector.Read().Round()).ParentQuadTile; RCSet <RCIntVector> retList = new RCSet <RCIntVector>(); foreach (RCIntVector relativeQuadCoord in this.owner.Read().ElementType.RelativeQuadCoordsInSight) { RCIntVector otherQuadCoords = currentQuadTile.MapCoords + relativeQuadCoord; if (otherQuadCoords.X >= 0 && otherQuadCoords.X < this.owner.Read().Scenario.Map.Size.X&& otherQuadCoords.Y >= 0 && otherQuadCoords.Y < this.owner.Read().Scenario.Map.Size.Y) { IQuadTile otherQuadTile = this.owner.Read().Scenario.Map.GetQuadTile(otherQuadCoords); if (this.owner.Read().MotionControl.IsFlying || currentQuadTile.GroundLevel >= otherQuadTile.GroundLevel) { retList.Add(otherQuadTile.MapCoords); } } } return(retList); }
/// <see cref="ICommandManagerBC.PressCommandButton"/> public void PressCommandButton(RCIntVector panelPosition) { if (panelPosition == RCIntVector.Undefined) { throw new ArgumentNullException("panelPosition"); } CommandPanelSlot slot = this.commandPanelSlots[panelPosition.X, panelPosition.Y]; if (slot == null) { throw new InvalidOperationException(string.Format("There is no command button on the command panel at {0}!", panelPosition)); } if (slot.ButtonState == CommandButtonStateEnum.Disabled) { throw new InvalidOperationException(string.Format("The command button at {0} is disabled!", panelPosition)); } this.CompleteListener(slot.Listener); }
/// <summary> /// Constructs a RCResourceAmountDisplay control at the given position with the given size. /// </summary> /// <param name="position">The position of the control.</param> /// <param name="size">The size of the control.</param> public RCResourceAmountDisplay(RCIntVector position, RCIntVector size) : base(position, size) { IViewService viewService = ComponentManager.GetInterface <IViewService>(); this.mapObjectDetailsView = viewService.CreateView <IMapObjectDetailsView>(); this.selectionDetailsView = viewService.CreateView <ISelectionDetailsView>(); UIFont textFont = UIResourceManager.GetResource <UIFont>("RC.App.Fonts.Font5"); this.mineralsText = new List <UIString> { new UIString("Minerals: {0}", textFont, UIWorkspace.Instance.PixelScaling, RCColor.White) }; this.vespeneGasText = new List <UIString> { new UIString("Vespene Gas: {0}", textFont, UIWorkspace.Instance.PixelScaling, RCColor.White) }; this.depletedText = new List <UIString> { new UIString("Depleted", textFont, UIWorkspace.Instance.PixelScaling, RCColor.White) }; }
/// <summary> /// Gets the actual Fog Of War at the given quadratic tile. /// </summary> /// <param name="quadCoords">The coordinates of the quadratic tile.</param> /// <returns>The type of the Fog Of War at the given quadratic tile.</returns> public FOWTypeEnum GetFogOfWar(RCIntVector quadCoords) { if (quadCoords == RCIntVector.Undefined) { throw new ArgumentNullException("quadCoords"); } if (quadCoords.X < 0 || quadCoords.X >= this.owner.Scenario.Map.Size.X || quadCoords.Y < 0 || quadCoords.Y >= this.owner.Scenario.Map.Size.Y) { throw new ArgumentOutOfRangeException("quadCoords"); } if (this.fowExpirationTimes[quadCoords.X, quadCoords.Y] == -1) { return(FOWTypeEnum.Full); } return(this.owner.Scenario.CurrentFrameIndex > this.fowExpirationTimes[quadCoords.X, quadCoords.Y] ? FOWTypeEnum.Partial : FOWTypeEnum.None); }
/// <summary> /// Enlarges this flood with the given amount. /// </summary> /// <param name="amount">The amount to enlarge with.</param> public void Enlarge(int amount) { if (amount <= 0) { throw new ArgumentOutOfRangeException("amount", "Amount of flood area enlargement must be greater than 0!"); } /// Calculate the corners. RCIntVector northCorner = new RCIntVector(-(this.enlargements.Count + 2), -(this.enlargements.Count + 2)); RCIntVector eastCorner = new RCIntVector((this.enlargements.Count + 2), -(this.enlargements.Count + 2)); RCIntVector westCorner = new RCIntVector(-(this.enlargements.Count + 2), (this.enlargements.Count + 2)); RCIntVector southCorner = new RCIntVector((this.enlargements.Count + 2), (this.enlargements.Count + 2)); /// Add the new vertical borders. this.AddVertical(-(this.currentRadius + amount), northCorner.Y, northCorner.X); this.AddVertical(-(this.currentRadius + amount), eastCorner.Y, eastCorner.X); this.AddVertical(westCorner.Y, this.currentRadius + amount, westCorner.X); this.AddVertical(southCorner.Y, this.currentRadius + amount, southCorner.X); /// Add the new horizontal borders. this.AddHorizontal(-(this.currentRadius + amount), northCorner.X, northCorner.Y); this.AddHorizontal(-(this.currentRadius + amount), westCorner.X, westCorner.Y); this.AddHorizontal(eastCorner.X, this.currentRadius + amount, eastCorner.Y); this.AddHorizontal(southCorner.X, this.currentRadius + amount, southCorner.Y); /// Add the new internal areas. this.AddArea(new RCIntRectangle(northCorner.X + 1, -(this.currentRadius + amount), eastCorner.X - northCorner.X - 1, amount)); this.AddArea(new RCIntRectangle(westCorner.X + 1, this.currentRadius + 1, southCorner.X - westCorner.X - 1, amount)); this.AddArea(new RCIntRectangle(-(this.currentRadius + amount), northCorner.Y + 1, amount, westCorner.Y - northCorner.Y - 1)); this.AddArea(new RCIntRectangle(this.currentRadius + 1, eastCorner.Y + 1, amount, southCorner.Y - eastCorner.Y - 1)); /// Save this enlargement and the corners. this.enlargements.Add(amount); this.currentRadius += amount; this.tmpFloodItems = null; this.northCorner = northCorner; this.eastCorner = eastCorner; this.westCorner = westCorner; this.southCorner = southCorner; }