void SetupProductionGroupButton(OrderManager orderManager, ProductionTypeButtonWidget button) { if (button == null) { return; } // Classic production queues are initialized at game start, and then never change. var queues = world.LocalPlayer.PlayerActor.TraitsImplementing <ProductionQueue>() .Where(q => (q.Info.Group ?? q.Info.Type) == button.ProductionGroup) .ToArray(); Action <bool> selectTab = reverse => { palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled); // When a tab is selected, scroll to the top because the current row position may be invalid for the new tab palette.ScrollToTop(); // Attempt to pick up a completed building (if there is one) so it can be placed palette.PickUpCompletedBuilding(); }; button.IsDisabled = () => !queues.Any(q => q.BuildableItems().Any()); button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); button.OnClick = () => selectTab(false); button.IsHighlighted = () => queues.Contains(palette.CurrentQueue); var chromeName = button.ProductionGroup.ToLowerInvariant(); var icon = button.Get <ImageWidget>("ICON"); icon.GetImageName = () => button.IsDisabled() ? chromeName + "-disabled" : queues.Any(q => q.AllQueued().Any(i => i.Done)) ? chromeName + "-alert" : chromeName; }
void SetupProductionGroupButton(OrderManager orderManager, ProductionTypeButtonWidget button) { if (button == null) { return; } // Classic production queues are initialized at game start, and then never change. var queues = world.LocalPlayer.PlayerActor.TraitsImplementing <ProductionQueue>() .Where(q => q.Info.Type == button.ProductionGroup) .ToArray(); Action <bool> selectTab = reverse => { palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled); // When a tab is selected, scroll to the top because the current row position may be invalid for the new tab palette.ScrollToTop(); }; Func <ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid; if (!string.IsNullOrEmpty(button.HotkeyName)) { var ks = Game.Settings.Keys; var field = ks.GetType().GetField(button.HotkeyName); if (field != null) { getKey = _ => (Hotkey)field.GetValue(ks); } } button.IsDisabled = () => !queues.Any(q => q.BuildableItems().Any()); button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); button.OnClick = () => selectTab(false); button.IsHighlighted = () => queues.Contains(palette.CurrentQueue); button.GetKey = getKey; var chromeName = button.ProductionGroup.ToLowerInvariant(); var icon = button.Get <ImageWidget>("ICON"); icon.GetImageName = () => button.IsDisabled() ? chromeName + "-disabled" : queues.Any(q => q.CurrentDone) ? chromeName + "-alert" : chromeName; }