public OldNPCRenderer(OldNPC npc) : base(EOGame.Instance) { NPC = npc; _fadeAwayAlpha = 255; _actionStartTime = DateTime.Now; _lastAnimUpdateTime = DateTime.Now; _npcSheet = new NPCSpriteSheet(((EOGame)Game).GFXManager); m_damageCounter = new DamageCounter(this); CreateMouseoverName(); }
/// <summary> /// Construct a character renderer in-game /// </summary> /// <param name="charToRender">The character data that should be wrapped by this renderer</param> public CharacterRenderer(Character charToRender) { //this has been happening when shit gets disconnected due to invalid sequence or internal packet id if (charToRender == null) { EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu(); return; } spriteSheet = new EOSpriteSheet(((EOGame)Game).GFXManager, charToRender); _char = charToRender; _data = charToRender.RenderData; Texture2D tmpSkin = spriteSheet.GetSkin(false, out m_skinSourceRect); if (_char != World.Instance.MainPlayer.ActiveCharacter) { drawArea = new Rectangle( _char.OffsetX + 304 - World.Instance.MainPlayer.ActiveCharacter.OffsetX, _char.OffsetY + 91 - World.Instance.MainPlayer.ActiveCharacter.OffsetY, m_skinSourceRect.Width, m_skinSourceRect.Height); //set based on size of the sprite and location of charToRender } else { drawArea = new Rectangle((618 - m_skinSourceRect.Width) / 2 + 4, (298 - m_skinSourceRect.Height) / 2 - 29, m_skinSourceRect.Width, m_skinSourceRect.Height); noLocUpdate = true; //make sure not to update the drawArea rectangle in the update method } Data.SetUpdate(true); //get the top pixel! Color[] skinData = new Color[m_skinSourceRect.Width * m_skinSourceRect.Height]; tmpSkin.GetData(0, m_skinSourceRect, skinData, 0, skinData.Length); int i = 0; while (i < skinData.Length && skinData[i].A == 0) i++; //account for adjustment in drawing the skin in the draw method TopPixel = (Data.gender == 0 ? 12 : 13) + (i == skinData.Length - 1 ? 0 : i / m_skinSourceRect.Height); m_chatBubble = new EOChatBubble(this); m_damageCounter = new DamageCounter(this); _mouseoverName = new BlinkingLabel(new Rectangle(1, 1, 1, 1), Constants.FontSize08pt75) { Visible = false, Text = Character.Name, ForeColor = Color.White, DrawOrder = (int)ControlDrawLayer.BaseLayer + 3, AutoSize = false }; _mouseoverName.DrawLocation = new Vector2( DrawAreaWithOffset.X + (32 - _mouseoverName.ActualWidth)/2f, DrawAreaWithOffset.Y + TopPixel - _mouseoverName.ActualHeight - 7); _mouseoverName.ResizeBasedOnText(); }
public NPCRenderer(NPC npc) : base(EOGame.Instance) { NPC = npc; _fadeAwayAlpha = 255; _actionStartTime = DateTime.Now; _lastAnimUpdateTime = DateTime.Now; _npcSheet = new EONPCSpriteSheet(((EOGame)Game).GFXManager, this); _chatBubble = new EOChatBubble(this); m_damageCounter = new DamageCounter(this); CreateMouseoverName(); }
public NPC(NPCData data) : base(EOGame.Instance) { ApplyData(data); bool success = true; npcSheet = new EONPCSpriteSheet(((EOGame)Game).GFXManager, this); int tries = 0; do { try { //attempt to get standing frame 1. It will have non-black pixels if it exists. Frame = NPCFrame.StandingFrame1; Texture2D tmp = npcSheet.GetNPCTexture(); Color[] tmpData = new Color[tmp.Width*tmp.Height]; tmp.GetData(tmpData); hasStandFrame1 = tmpData.Any(_c => _c.R != 0 || _c.G != 0 || _c.B != 0); //get the first non-transparent pixel to determine offsets for name labels and damage counters Frame = NPCFrame.Standing; tmp = npcSheet.GetNPCTexture(); tmpData = new Color[tmp.Width*tmp.Height]; tmp.GetData(tmpData); int i = 0; while (i < tmpData.Length && tmpData[i].A == 0) i++; TopPixel = i == tmpData.Length - 1 ? 0 : i/tmp.Height; } //this block throws errors sometimes..no idea why. Keep looping until it works. catch (InvalidOperationException) { success = false; tries++; } } while (!success && tries < 3); if(tries >= 3) throw new InvalidOperationException("Something weird happened initializing this NPC."); m_chatBubble = new EOChatBubble(this); m_damageCounter = new DamageCounter(this); _mouseoverName = new XNALabel(new Rectangle(1, 1, 1, 1), Constants.FontSize08pt75) { Visible = false, Text = Data.Name, ForeColor = Color.White, AutoSize = false, DrawOrder = (int) ControlDrawLayer.BaseLayer + 3 }; _mouseoverName.DrawLocation = new Vector2( DrawArea.X + (DrawArea.Width - _mouseoverName.ActualWidth)/2f, DrawArea.Y + TopPixel - _mouseoverName.ActualHeight - 4); _mouseoverName.ResizeBasedOnText(); }