private void cbCreatures_SelectedIndexChanged(object sender, EventArgs e) { if (Heroes3Master.Master != null && CreatureManager.Loaded) { var creature = CreatureManager.Get(cbCastles.SelectedIndex, cbCreatures.SelectedIndex); LoadCreatureInfo(creature); string allCreatures = Properties.Resources.creatures; string defName = allCreatures.Split(new[] { "\r\n" }, StringSplitOptions.None)[creature.CreatureIndex].Split(';')[2] + ".def"; var lodFile = Heroes3Master.Master.Resolve(defName); if (creatureAnimation != null) { pbCreature.Image = null; creatureAnimation.Dispose(); } var def = lodFile[defName].GetDefFile(); if (def != null) { creatureAnimation = new CreatureAnimationLoop(creature.CreatureIndex, def); creatureAnimation.TimerTick += creatureAnimation_TimerTick; creatureAnimation.Enabled = true; } } }
private void cbCreatures_DrawItem(object sender, DrawItemEventArgs e) { if (Heroes3Master.Master != null && e.Index >= 0) { int castleIndex = selectedCastle; var clr = Town.AllColors[castleIndex]; if (!cacheOther) { e.Graphics.FillRectangle(new SolidBrush(clr), e.Bounds); var creature = CreatureManager.Get(castleIndex, e.Index); e.Graphics.DrawImage(CreatureManager.GetSmallImage(Heroes3Master.Master, creature.CreatureIndex), e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString(creature.Name, e.Font, Brushes.Black, e.Bounds.X + 46, e.Bounds.Y + 9); } else { if (BitmapCache.DrawItemCreaturesOtherComboBox == null) { otherCreatures = CreatureManager.OnlyActiveCreatures.Where(c => c.TownIndex == 9 && c.CreatureIndex != 149).ToArray(); BitmapCache.DrawItemCreaturesOtherComboBox = new Bitmap[otherCreatures.Length]; } Bitmap cached; if (BitmapCache.DrawItemCreaturesOtherComboBox[e.Index] == null) { cached = new Bitmap(e.Bounds.Width, e.Bounds.Height); using (var g = Graphics.FromImage(cached)) { g.FillRectangle(new SolidBrush(clr), new Rectangle(Point.Empty, e.Bounds.Size)); var creature = CreatureManager.Get(castleIndex, e.Index); g.DrawImage(CreatureManager.GetSmallImage(Heroes3Master.Master, creature.CreatureIndex), Point.Empty); g.DrawString(creature.Name.ToString(), e.Font, Brushes.Black, 46, 9); } BitmapCache.DrawItemCreaturesOtherComboBox[e.Index] = cached; } else { cached = BitmapCache.DrawItemCreaturesOtherComboBox[e.Index]; } e.Graphics.DrawImage(cached, e.Bounds.Location); } } }