예제 #1
0
            public override void OnUpdate()
            {
                WorldSide localSide = World_AIW2.Instance.GetLocalPlayerSide();

                if (localSide == null)
                {
                    return;
                }
                ArcenUI_ImageButtonSet elementAsType = (ArcenUI_ImageButtonSet)Element;

                if (Window_InGameBuildTabMenu.Instance.EntityChangedSinceLastButtonSetUpdate_Queue)
                {
                    elementAsType.ClearButtons();

                    GameEntity entity = World_AIW2.Instance.GetEntityByID(Window_InGameBuildTabMenu.Instance.EntityID);
                    if (entity != null)
                    {
                        float aspectRatioAdjustedButtonWidth  = this.Element.ButtonWidth;
                        float aspectRatioAdjustedButtonHeight = this.Element.ButtonHeight;
                        if (ArcenUI.Instance.PixelsPerPercent_X != ArcenUI.Instance.PixelsPerPercent_Y)
                        {
                            aspectRatioAdjustedButtonWidth *= ArcenUI.Instance.PixelsPerPercent_Y / ArcenUI.Instance.PixelsPerPercent_X;
                        }

                        float runningX = 0;
                        if (entity.BuildQueue != null)
                        {
                            List <BuildQueueItem> items = entity.BuildQueue.Items;
                            for (int x = 0; x < items.Count; x++)
                            {
                                BuildQueueItem item = items[x];
                                bQueueItem     newButtonController = new bQueueItem(entity.TypeData, item, x);
                                Vector2        offset;
                                offset.x = runningX;
                                offset.y = 0;
                                Vector2 size;
                                size.x = aspectRatioAdjustedButtonWidth;
                                size.y = aspectRatioAdjustedButtonHeight;
                                elementAsType.AddImageButton(newButtonController, size, offset);
                                runningX += size.x;
                            }
                        }
                    }

                    elementAsType.ActuallyPutItemsBackInPoolThatAreStillCleared();

                    Window_InGameBuildTabMenu.Instance.EntityChangedSinceLastButtonSetUpdate_Queue = false;
                    Window_InGameBuildTabMenu.Instance.MenuIndexChangedSinceLastButtonSetUpdate    = true;
                }
            }
            public override void OnUpdate()
            {
                WorldSide localSide = World_AIW2.Instance.GetLocalSide();

                if (localSide == null)
                {
                    return;
                }

                Planet planet = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed();

                if (!planet.HumansHaveBasicIntel)
                {
                    return;
                }

                float columnWidth   = 32 / ArcenUI.Instance.PixelsPerPercent_X;
                float rowHeight     = 32 / ArcenUI.Instance.PixelsPerPercent_Y;
                float iconWidth     = columnWidth * 0.9f;
                float iconHeight    = rowHeight * 0.9f;
                int   currentRow    = 0;
                int   currentColumn = 0;
                int   totalColumns  = Mathf.FloorToInt(this.Element.Width / columnWidth);

                groups.Clear();

                planet.Combat.DoForEntities(GameEntityCategory.Ship, delegate(GameEntity entity)
                {
                    EntityGroup group;
                    EntityGroupSideType sideType = (entity.Side.WorldSide.GetIsLocalSide() ? EntityGroupSideType.Mine :
                                                    entity.Side.WorldSide.GetIsFriendlyToLocalSide() ? EntityGroupSideType.Allied : EntityGroupSideType.Enemy);
                    for (int i = groups.Count - 1; i >= 0; i--)
                    {
                        group = groups[i];
                        if (group.TypeData == entity.TypeData && group.Side == sideType && group.EntityCount < MAX_ENTITIES_PER_ICON)
                        {
                            group.EntityCount++;
                            group.ActualEntities.Add(entity);
                            return(DelReturn.Continue);
                        }
                    }
                    group             = EntityGroup.GetNextFromPool();
                    group.TypeData    = entity.TypeData;
                    group.Side        = sideType;
                    group.EntityCount = 1;
                    group.ActualEntities.Add(entity);
                    groups.Add(group);

                    return(DelReturn.Continue);
                });

                groups.Sort(delegate(EntityGroup Left, EntityGroup Right)
                {
                    if (Left.Side != Right.Side)
                    {
                        if (Left.Side < Right.Side)
                        {
                            return(PREFER_LEFT);
                        }
                        else
                        {
                            return(PREFER_RIGHT);
                        }
                    }

                    if (Left.TypeData != Right.TypeData && Left.TypeData.BalanceStats.StrengthPerShip != Right.TypeData.BalanceStats.StrengthPerShip)
                    {
                        if (Left.TypeData.BalanceStats.StrengthPerShip.RawValue != Right.TypeData.BalanceStats.StrengthPerShip.RawValue)
                        {
                            if (Left.TypeData.BalanceStats.StrengthPerShip.RawValue < Right.TypeData.BalanceStats.StrengthPerShip.RawValue)
                            {
                                return(PREFER_RIGHT);
                            }
                            else
                            {
                                return(PREFER_LEFT);
                            }
                        }
                    }

                    if (Left.TypeData.CopiedFrom != Right.TypeData.CopiedFrom)
                    {
                        if (Left.TypeData.CopiedFrom.RowIndex < Right.TypeData.CopiedFrom.RowIndex)
                        {
                            return(PREFER_LEFT);
                        }
                        else
                        {
                            return(PREFER_RIGHT);
                        }
                    }

                    if (Left.TypeData != Right.TypeData)
                    {
                        if (Left.TypeData.RowIndex < Right.TypeData.RowIndex)
                        {
                            return(PREFER_LEFT);
                        }
                        else
                        {
                            return(PREFER_RIGHT);
                        }
                    }

                    return(PREFER_NEITHER);
                });

                int currentImageListIndex        = 0;
                EntityGroupSideType lastSideType = EntityGroupSideType.Unknown;
                bOutlineItem        item         = null;

                for (int groupIndex = groups.Count - 1; groupIndex >= 0; groupIndex--)
                {
                    EntityGroup group = groups[groupIndex];
                    if (currentImageListIndex < this.Element.Images.Count)
                    {
                        item = Element.Images[currentImageListIndex].Controller as bOutlineItem;
                        currentImageListIndex++;
                    }
                    else
                    {
                        item = new bOutlineItem();
                        Vector2 dummy = Mat.V2_Zero;
                        Vector2 size;
                        size.x = iconWidth;
                        size.y = iconHeight;
                        Element.AddImageButton(item, size, dummy);
                    }

                    item.EntityGroup = group;

                    bool getsOwnLine = false;
                    switch (group.TypeData.SpecialType)
                    {
                    case SpecialEntityType.AIKingUnit:
                    case SpecialEntityType.HumanKingUnit:
                        getsOwnLine = true;
                        break;
                    }
                    if (group.TypeData.Tags.Contains("Flagship"))
                    {
                        getsOwnLine = true;
                    }
                    if (lastSideType != EntityGroupSideType.Unknown)
                    {
                        if (lastSideType != group.Side)
                        {
                            currentColumn = 0;
                            currentRow   += 2;
                        }
                        else if (getsOwnLine && currentColumn != 0)
                        {
                            currentColumn = 0;
                            currentRow++;
                        }
                    }
                    lastSideType = group.Side;
                    float x = this.Element.X + (currentColumn * columnWidth);
                    float y = this.Element.Y + (currentRow * rowHeight);
                    if (item.Element.X != x || item.Element.Y != y)
                    {
                        item.Element.X = x;
                        item.Element.Y = y;
                        item.Element.UpdatePositionAndSize();
                    }
                    if (getsOwnLine)
                    {
                        currentColumn = 0;
                        currentRow++;
                    }
                    else
                    {
                        currentColumn++;
                        if (currentColumn >= totalColumns)
                        {
                            currentRow++;
                            currentColumn = 0;
                        }
                    }
                }

                //hide any extras
                for (int i = currentImageListIndex; i < this.Element.Images.Count; i++)
                {
                    item             = this.Element.Images[i].Controller as bOutlineItem;
                    item.EntityGroup = null;
                }
            }
            public override void OnUpdate()
            {
                if (Instance.HeightPerRow <= 0)
                {
                    Instance.HeightPerRow = Element.ButtonHeight;
                }
                WorldSide localSide = World_AIW2.Instance.GetLocalPlayerSide();

                if (localSide == null)
                {
                    return;
                }
                ArcenUI_ImageButtonSet elementAsType = (ArcenUI_ImageButtonSet)Element;

                if (elementAsType != null)
                {
                }                                //prevent compiler warning
                Window_InGameBuildTypeIconMenu windowController = (Window_InGameBuildTypeIconMenu)Element.Window.Controller;

                if (windowController != null)
                {
                }                                   //prevent compiler warning

                if (Instance.LastMenuIndex != Window_InGameBuildTabMenu.Instance.CurrentMenuIndex ||
                    Instance.LastTypeIndex != Instance.CurrentTypeIndex)
                {
                    Instance.LastMenuIndex = Window_InGameBuildTabMenu.Instance.CurrentMenuIndex;
                    Instance.LastTypeIndex = Instance.CurrentTypeIndex;

                    for (int i = 0; i < Instance.LastShownItems.Count; i++)
                    {
                        Instance.LastShownItems[i].Clear();
                    }

                    GameEntity entity = World_AIW2.Instance.GetEntityByID(Window_InGameBuildTabMenu.Instance.EntityID);
                    if (entity != null && entity.TypeData.BuildMenus.Count > 0)
                    {
                        int highestRowReached = 0;
                        if (Instance.LastMenuIndex >= entity.TypeData.BuildMenus.Count)
                        {
                            Instance.LastMenuIndex = 0;
                            Window_InGameBuildTabMenu.Instance.CurrentMenuIndex = 0;
                        }
                        BuildMenu menu = entity.TypeData.BuildMenus[Instance.LastMenuIndex];
                        if (menu != null)
                        {
                            float aspectRatioAdjustedButtonWidth  = this.Element.ButtonWidth;
                            float aspectRatioAdjustedButtonHeight = this.Element.ButtonHeight;
                            if (ArcenUI.Instance.PixelsPerPercent_X != ArcenUI.Instance.PixelsPerPercent_Y)
                            {
                                aspectRatioAdjustedButtonWidth *= ArcenUI.Instance.PixelsPerPercent_Y / ArcenUI.Instance.PixelsPerPercent_X;
                            }
                            //int totalColumns = Mathf.FloorToInt( this.Element.Width / aspectRatioAdjustedButtonWidth );
                            int currentImageListIndex = 0;

                            int shownColumnCount = 0;
                            for (int typeIndex = 0; typeIndex < menu.Columns.Count; typeIndex++)
                            {
                                List <BuildMenuItem> column = menu.Columns[typeIndex];
                                int buttonsInColumn         = 0;
                                for (int markIndex = 0; markIndex < column.Count; markIndex++)
                                {
                                    BuildMenuItem menuItem = column[markIndex];
                                    if (menuItem.EntityDataOrNull == null)
                                    {
                                        continue;
                                    }
                                    if (localSide.GetCanBuildAtAll(menuItem.EntityDataOrNull) != ArcenRejectionReason.Unknown)
                                    {
                                        continue;
                                    }
                                    buttonsInColumn = markIndex + 1;
                                }
                                highestRowReached = Math.Max(highestRowReached, buttonsInColumn);
                            }

                            for (int typeIndex = 0; typeIndex < menu.Columns.Count; typeIndex++)
                            {
                                if (Instance.LastShownItems.Count <= typeIndex)
                                {
                                    Instance.LastShownItems.Add(new List <bItem>());
                                }
                                List <bItem> lastShownItemList = Instance.LastShownItems[typeIndex];

                                bool haveShownAnythingInThisColumn = false;
                                List <BuildMenuItem> column        = menu.Columns[typeIndex];
                                if (column.Count <= 0)
                                {
                                    continue;
                                }
                                for (int markIndex = 0; markIndex < column.Count; markIndex++)
                                {
                                    if (lastShownItemList.Count <= markIndex)
                                    {
                                        lastShownItemList.Add(null);
                                    }

                                    BuildMenuItem menuItem = column[markIndex];
                                    if (menuItem.EntityDataOrNull == null)
                                    {
                                        continue;
                                    }
                                    if (localSide.GetCanBuildAtAll(menuItem.EntityDataOrNull) != ArcenRejectionReason.Unknown)
                                    {
                                        continue;
                                    }
                                    haveShownAnythingInThisColumn = true;

                                    bItem item = null;
                                    if (currentImageListIndex < this.Element.Images.Count)
                                    {
                                        item = Element.Images[currentImageListIndex].Controller as bItem;
                                        currentImageListIndex++;
                                    }
                                    else
                                    {
                                        item = new bItem();
                                        Vector2 dummy = Mat.V2_Zero;
                                        Vector2 size;
                                        size.x = aspectRatioAdjustedButtonWidth;
                                        size.y = aspectRatioAdjustedButtonHeight;
                                        Element.AddImageButton(item, size, dummy);
                                        currentImageListIndex = Element.Images.Count;
                                    }
                                    item.ColumnIndex             = shownColumnCount;
                                    lastShownItemList[markIndex] = item;

                                    float effectiveX = shownColumnCount * aspectRatioAdjustedButtonWidth;
                                    float effectiveY = ((highestRowReached - 1) - markIndex) * aspectRatioAdjustedButtonHeight;

                                    item.TypeDoingTheBuilding = entity.TypeData;
                                    item.SetTypeToBuild(menuItem.EntityDataOrNull);
                                    item.Element.Alignment.XAlignment.Offset = effectiveX;
                                    item.Element.Alignment.YAlignment.Offset = effectiveY;
                                    item.Element.UpdatePositionAndSize();
                                }
                                if (haveShownAnythingInThisColumn)
                                {
                                    shownColumnCount++;
                                }
                            }

                            //hide any extras
                            for (int i = currentImageListIndex; i < this.Element.Images.Count; i++)
                            {
                                bItem item = this.Element.Images[i].Controller as bItem;
                                item.SetTypeToBuild(null);
                                item.TypeDoingTheBuilding = null;
                            }
                        }
                        if (Instance.HeightPerRow > 0)
                        {
                            float currentExpansion = Instance.Window.SubContainer.Height - Instance.HeightPerRow;
                            float targetExpansion  = Instance.HeightPerRow * (highestRowReached - 1);
                            float deltaExpansion   = targetExpansion - currentExpansion;
                            if (deltaExpansion != 0)
                            {
                                Instance.Window.SubContainer.Height = Instance.HeightPerRow * highestRowReached;
                            }
                        }
                    }
                }
            }