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; } } } } }
public override void OnUpdate() { WorldSide localSide = World_AIW2.Instance.GetLocalSide(); if (localSide == null) { return; } ArcenUI_ButtonSet elementAsType = (ArcenUI_ButtonSet)Element; Window_InGameBuildMenu windowController = (Window_InGameBuildMenu)Element.Window.Controller; if (windowController.MenuIndexChangedSinceLastButtonSetUpdate) { elementAsType.ClearButtons(); GameEntity entity = World_AIW2.Instance.GetEntityByID(windowController.EntityID); if (entity != null && entity.TypeData.BuildMenus.Count > 0) { if (windowController.LastMenuIndex >= entity.TypeData.BuildMenus.Count) { windowController.LastMenuIndex = 0; } BuildMenu menu = entity.TypeData.BuildMenus[windowController.LastMenuIndex]; if (menu != null) { int shownColumnCount = 0; for (int x = 0; x < menu.Columns.Count; x++) { bool haveShownAnythingInThisColumn = false; List <BuildMenuItem> column = menu.Columns[x]; for (int y = 0; y < column.Count; y++) { BuildMenuItem item = column[y]; if (item.EntityDataOrNull != null && localSide.GetCanBuildAtAll(item.EntityDataOrNull) != ArcenRejectionReason.Unknown) { continue; } haveShownAnythingInThisColumn = true; bBuildItem newButtonController = new bBuildItem(entity.TypeData, item); newButtonController.ItemMenuIndex = windowController.LastMenuIndex; newButtonController.ItemColumnIndex = x; newButtonController.ItemIndex = y; Vector2 offset; offset.x = shownColumnCount * elementAsType.ButtonWidth; offset.y = y * elementAsType.ButtonHeight; Vector2 size; size.x = elementAsType.ButtonWidth; size.y = elementAsType.ButtonHeight; elementAsType.AddButton(newButtonController, size, offset); } if (haveShownAnythingInThisColumn) { shownColumnCount++; } } } } elementAsType.ActuallyPutItemsBackInPoolThatAreStillCleared(); windowController.MenuIndexChangedSinceLastButtonSetUpdate = false; } }