bool HandleEvent(BuildSelectIcon icon, MouseButton btn, Modifiers modifiers) { var handled = btn == MouseButton.Left ? HandleLeftClick(icon) : false; if (!handled) { Game.Sound.Play(SoundType.UI, DisabledTabClick); } return(true); }
public void RefreshIcons() { icons = new Dictionary <Rectangle, BuildSelectIcon>(); var producer = CurrentQueue != null?CurrentQueue.MostLikelyProducer() : default(TraitPair <BuilderUnit>); if (CurrentQueue == null || producer.Trait == null) { if (DisplayedIconCount != 0) { OnIconCountChanged(DisplayedIconCount, 0); DisplayedIconCount = 0; } return; } var oldIconCount = DisplayedIconCount; DisplayedIconCount = 0; var rb = RenderBounds; var faction = producer.Trait.Faction; foreach (var item in AllBuildables.Skip(IconRowOffset * Columns).Take(MaxIconRowOffset * Columns)) { var x = DisplayedIconCount % Columns; var y = DisplayedIconCount / Columns; var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y); var rsi = item.TraitInfo <RenderSpritesInfo>(); var icon = new Animation(World, rsi.GetImage(item, World.Map.Rules.Sequences, faction)); var bi = item.TraitInfo <BuildableInfo>(); icon.Play(bi.Icon); var dummyQueue = currentQueue.Actor.Owner.PlayerActor.TraitsImplementing <ProductionQueue>() .First(q => q.Info.Type == "Dummy"); var pi = new BuildSelectIcon() { Actor = item, Name = item.Name, Hotkey = DisplayedIconCount < HotkeyCount ? hotkeys[DisplayedIconCount] : null, Sprite = icon.Image, Palette = worldRenderer.Palette(bi.IconPalette), IconClockPalette = worldRenderer.Palette(ClockPalette), IconDarkenPalette = worldRenderer.Palette(NotBuildablePalette), Pos = new float2(rect.Location), BuilderUnit = currentQueue, ProductionQueue = dummyQueue }; icons.Add(rect, pi); DisplayedIconCount++; } eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty; if (oldIconCount != DisplayedIconCount) { OnIconCountChanged(oldIconCount, DisplayedIconCount); } }
bool HandleLeftClick(BuildSelectIcon icon) { CurrentQueue = icon.BuilderUnit; World.OrderGenerator = new BuilderUnitBuildingOrderGenerator(CurrentQueue, icon.Name, worldRenderer); return(true); }