public static void Helper_FindAndPlaceCoreUnit(ControlGroup Group, ArcenPoint MoveOrderPoint, out ArcenSparseLookup <GameEntity, ArcenPoint> _entitiesToPlace, out GameEntity coreUnit, out int shieldCoverageRadiusOrEquivalent, out int paddingAroundEachUnit, out ArcenRectangle firstUnitRect) { Planet localPlanet = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed(); ArcenSparseLookup <GameEntity, ArcenPoint> entitiesToPlace = _entitiesToPlace = new ArcenSparseLookup <GameEntity, ArcenPoint>(); Group.DoForEntities(delegate(GameEntity entity) { if (entity.Combat.Planet != localPlanet) { return(DelReturn.Continue); } entitiesToPlace[entity] = ArcenPoint.OutOfRange; return(DelReturn.Continue); }); coreUnit = null; GameEntity backupCoreUnit = null; for (int i = 0; i < entitiesToPlace.GetPairCount(); i++) { GameEntity entity = entitiesToPlace.GetPairByIndex(i).Key; if (entity.TypeData.ShieldRadius <= 0) { if (coreUnit == null) { if (backupCoreUnit != null) { if (entity.TypeData.BalanceStats.StrengthPerSquad <= backupCoreUnit.TypeData.BalanceStats.StrengthPerSquad) { continue; } } backupCoreUnit = entity; } continue; } if (coreUnit != null) { if (entity.TypeData.ShieldRadius < coreUnit.TypeData.ShieldRadius) { continue; } if (entity.TypeData.ShieldRadius == coreUnit.TypeData.ShieldRadius && entity.TypeData.BalanceStats.ShieldPoints <= coreUnit.TypeData.BalanceStats.ShieldPoints) { continue; } } coreUnit = entity; } if (coreUnit == null) { backupCoreUnit = coreUnit; } int initialCoreRadius = 4; shieldCoverageRadiusOrEquivalent = initialCoreRadius; if (coreUnit != null) { entitiesToPlace[coreUnit] = MoveOrderPoint; initialCoreRadius = coreUnit.TypeData.Radius; shieldCoverageRadiusOrEquivalent = Math.Max(initialCoreRadius, coreUnit.GetCurrentShieldRadius()); } paddingAroundEachUnit = 20; firstUnitRect.Width = initialCoreRadius + initialCoreRadius + paddingAroundEachUnit; firstUnitRect.Height = firstUnitRect.Width; firstUnitRect.X = MoveOrderPoint.X - initialCoreRadius; firstUnitRect.Y = MoveOrderPoint.Y - initialCoreRadius; }
private static void Helper_DoPlacementWithinProjectedZone(List <GameEntity> entitiesToPlaceWithinZone, ArcenSparseLookup <GameEntity, ArcenPoint> overallEntitySet, bool isQueuedCommand, int paddingAroundEachUnit, bool quadrantExpandsOnXAxis, bool quadrantExpandsInPositiveDirection, int quadrantMainAxisStart, int quadrantOtherAxisStart, int quadrantOtherAxisEnd) { ArcenPoint workingPoint; if (quadrantExpandsOnXAxis) { workingPoint.X = quadrantMainAxisStart; workingPoint.Y = quadrantOtherAxisStart; } else { workingPoint.X = quadrantOtherAxisStart; workingPoint.Y = quadrantMainAxisStart; } int furthestPointAlongMainAxis = quadrantExpandsOnXAxis ? workingPoint.X : workingPoint.Y; for (int i = 0; i < entitiesToPlaceWithinZone.Count; i++) { GameEntity entity = entitiesToPlaceWithinZone[i]; ArcenRectangle placementRect = ArcenRectangle.AllZerosInstance; placementRect.Width = entity.TypeData.Radius + entity.TypeData.Radius + paddingAroundEachUnit; placementRect.Height = placementRect.Width; placementRect.X = workingPoint.X; placementRect.Y = workingPoint.Y; int placementRectOtherAxisMax = quadrantExpandsOnXAxis ? placementRect.Bottom : placementRect.Right; if (placementRectOtherAxisMax > quadrantOtherAxisEnd) { if (quadrantExpandsOnXAxis) { workingPoint.X = furthestPointAlongMainAxis; workingPoint.Y = quadrantOtherAxisStart; } else { workingPoint.X = quadrantOtherAxisStart; workingPoint.Y = furthestPointAlongMainAxis; } placementRect.X = workingPoint.X; placementRect.Y = workingPoint.Y; // no need to recheck, as by definition there will be room unless there's a single unit that doesn't fit within the other axis } if (quadrantExpandsOnXAxis) { if (!quadrantExpandsInPositiveDirection) { placementRect.X -= placementRect.Width; } } else { if (!quadrantExpandsInPositiveDirection) { placementRect.Y -= placementRect.Height; } } overallEntitySet[entity] = placementRect.CalculateCenterPoint(); if (quadrantExpandsOnXAxis) { if (quadrantExpandsInPositiveDirection) { furthestPointAlongMainAxis = Math.Max(furthestPointAlongMainAxis, placementRect.Right); } else { furthestPointAlongMainAxis = Math.Min(furthestPointAlongMainAxis, placementRect.Left); } workingPoint.Y += placementRect.Height; } else { if (quadrantExpandsInPositiveDirection) { furthestPointAlongMainAxis = Math.Max(furthestPointAlongMainAxis, placementRect.Bottom); } else { furthestPointAlongMainAxis = Math.Min(furthestPointAlongMainAxis, placementRect.Top); } workingPoint.X += placementRect.Width; } } }
public override void PopulateFreeFormControls(ArcenUI_SetOfCreateElementDirectives Set) { Rect scrollbarRect = ArcenRectangle.CreateUnityRect(mainAreaBounds.x - 2, mainAreaBounds.y + 2, 2, mainAreaBounds.height - 5); AddVerticalSlider(Set, typeof(sScrollbar), 0, scrollbarRect); int rowsToShow = GetMaxRowsToShow(); int rowCount = ArcenSettingTable.Instance.VisibleRows.Count; if (sScrollbar.Instance != null) { int range = rowCount - rowsToShow; if (range <= 0) { startingTableIndex = 0; } else { ArcenUI_Slider slider = (ArcenUI_Slider)sScrollbar.Instance.Element; startingTableIndex = Mathf.FloorToInt(range * slider.ReferenceSlider.value); } } float runningY = 3; Rect headerTextBounds = ArcenRectangle.CreateUnityRect(mainAreaBounds.xMin, runningY, 15, headerRowHeight); AddText(Set, typeof(tHeader), 0, headerTextBounds); Rect closeButtonBounds = ArcenRectangle.CreateUnityRect(headerTextBounds.xMax + 2, runningY, 10, headerRowHeight); AddButton(Set, typeof(bCancel), 0, closeButtonBounds); Rect saveButtonBounds = ArcenRectangle.CreateUnityRect(closeButtonBounds.xMax + 2, runningY, 10, headerRowHeight); AddButton(Set, typeof(bSave), 0, saveButtonBounds); Rect resetButtonBounds = ArcenRectangle.CreateUnityRect(saveButtonBounds.xMax + 2, runningY, 10, headerRowHeight); AddButton(Set, typeof(bReset), 0, resetButtonBounds); runningY += headerRowHeight; int rowsLeft = rowCount - startingTableIndex; rowsToShow = Math.Min(rowsLeft, rowsToShow); for (int i = 0; i < rowsToShow; i++) { ArcenSetting setting = ArcenSettingTable.Instance.VisibleRows[startingTableIndex + i]; Rect nameBounds = ArcenRectangle.CreateUnityRect(mainAreaBounds.xMin, runningY, 50, rowHeight); AddText(Set, typeof(tSettingName), i, nameBounds); Rect valueSettingControlBounds = ArcenRectangle.CreateUnityRect(nameBounds.xMax, runningY, 15, rowHeight); switch (setting.Type) { case ArcenSettingType.BoolToggle: AddButton(Set, typeof(bToggle), i, valueSettingControlBounds); break; case ArcenSettingType.IntTextbox: AddInput(Set, typeof(iIntInput), i, valueSettingControlBounds); break; case ArcenSettingType.FloatSlider: AddHorizontalSlider(Set, typeof(sFloatSlider), i, valueSettingControlBounds); break; case ArcenSettingType.IntDropdown: AddDropdown(Set, typeof(dIntDropdown), i, valueSettingControlBounds); break; } Rect valueDescriptionBounds = ArcenRectangle.CreateUnityRect(valueSettingControlBounds.xMax, runningY, 30, rowHeight); AddText(Set, typeof(tSettingValueDescription), i, valueDescriptionBounds); runningY += rowHeight; } }