public override void Draw(GameTime gameTime) { if (!Visible) { return; } int scrollOff = m_scrollBar.ScrollOffset; SpriteBatch.Begin(); SpriteBatch.Draw(m_filterTextures[(int)m_filter], new Vector2(DrawAreaWithOffset.X + 4, DrawAreaWithOffset.Y + 2), Color.White); List <ClientOnlineEntry> filtered = m_onlineList; if (m_filter != Filter.All) { switch (m_filter) { case Filter.Friends: filtered = m_onlineList.Where(oe => m_friendList.Contains(oe.Name)).ToList(); break; case Filter.Admins: //show admins only for the admins view: other types will be continue'd filtered = m_onlineList.Where(oe => { switch (oe.Icon) { case PaperdollIconType.Normal: case PaperdollIconType.Party: case PaperdollIconType.SLNBot: return(false); } return(true); }).ToList(); break; default: throw new ArgumentOutOfRangeException(); } } for (int i = scrollOff; i < scrollOff + m_scrollBar.LinesToRender && i < filtered.Count; ++i) { int yCoord = DRAW_OFFSET_Y + DrawAreaWithOffset.Y + (i - m_scrollBar.ScrollOffset) * 13; //draw icon SpriteBatch.Draw(ChatTab.GetChatIcon(EOChatRenderer.GetChatTypeFromPaperdollIcon(filtered[i].Icon)), new Vector2(DrawAreaWithOffset.X + DRAW_ICON_X, yCoord), Color.White); //drawtext name SpriteBatch.DrawString(EOGame.Instance.DBGFont, filtered[i].Name, new Vector2(DrawAreaWithOffset.X + DRAW_NAME_X, yCoord), Color.Black); //drawtext title SpriteBatch.DrawString(EOGame.Instance.DBGFont, filtered[i].Title, new Vector2(DrawAreaWithOffset.X + DRAW_TITLE_X, yCoord), Color.Black); //drawtext guild SpriteBatch.DrawString(EOGame.Instance.DBGFont, filtered[i].Guild, new Vector2(DrawAreaWithOffset.X + DRAW_GUILD_X, yCoord), Color.Black); //drawtext class SpriteBatch.DrawString(EOGame.Instance.DBGFont, filtered[i].ClassString, new Vector2(DrawAreaWithOffset.X + DRAW_CLASS_X, yCoord), Color.Black); } SpriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This Constructor should be used for all values in ChatTabs /// </summary> public ChatTab(ChatTabs tab, EOChatRenderer parentRenderer, bool selected = false) : base(null, null, parentRenderer) { WhichTab = tab; tabLabel = new XNALabel(new Rectangle(14, 2, 1, 1), "Microsoft Sans Serif", 8.0f); tabLabel.SetParent(this); switch (WhichTab) { case ChatTabs.Local: tabLabel.Text = "scr"; break; case ChatTabs.Global: tabLabel.Text = "glb"; break; case ChatTabs.Group: tabLabel.Text = "grp"; break; case ChatTabs.System: tabLabel.Text = "sys"; break; case ChatTabs.Private1: case ChatTabs.Private2: tabLabel.Text = "[priv " + ((int)WhichTab + 1) + "]"; break; } _selected = selected; relativeTextPos = new Vector2(20, 3); //enable close button based on which tab was specified switch (WhichTab) { case ChatTabs.Private1: case ChatTabs.Private2: { closeRect = new Rectangle(3, 3, 11, 11); drawArea = new Rectangle(drawArea.X, drawArea.Y, 132, 16); Visible = false; } break; default: { closeRect = null; drawArea = new Rectangle(drawArea.X, drawArea.Y, 43, 16); Visible = true; } break; } //568 331 scrollBar = new EOScrollBar(parent, new Vector2(467, 2), new Vector2(16, 97), EOScrollBar.ScrollColors.LightOnMed) { Visible = selected, LinesToRender = 7 }; scrollBar.IgnoreDialog(typeof(EOPaperdollDialog)); scrollBar.IgnoreDialog(typeof(EOChestDialog)); }
public HUD(Game g, PacketAPI api) : base(g) { if (!api.Initialized) { throw new ArgumentException("Need to initialize connection before the in-game stuff will work"); } m_packetAPI = api; DrawOrder = 5; mainFrame = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 1, true); topLeft = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 21, true); sidebar = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 22, true); topBar = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 23, true); filler = new Texture2D(g.GraphicsDevice, 1, 1); filler.SetData(new[] { Color.FromNonPremultiplied(8, 8, 8, 255) }); Texture2D mainButtonTexture = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 25); mainBtn = new XNAButton[NUM_BTN]; //set up panels Texture2D invBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 44); pnlInventory = new XNAPanel(new Rectangle(102, 330, invBG.Width, invBG.Height)) { BackgroundImage = invBG, Visible = false }; Texture2D spellsBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 62); pnlActiveSpells = new XNAPanel(new Rectangle(102, 330, spellsBG.Width, spellsBG.Height)) { BackgroundImage = spellsBG, Visible = false }; pnlPassiveSpells = new XNAPanel(new Rectangle(102, 330, spellsBG.Width, spellsBG.Height)) { BackgroundImage = spellsBG, Visible = false }; Texture2D chatBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 28); pnlChat = new XNAPanel(new Rectangle(102, 330, chatBG.Width, chatBG.Height)) { BackgroundImage = chatBG, Visible = false }; Texture2D statsBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 34); pnlStats = new XNAPanel(new Rectangle(102, 330, statsBG.Width, statsBG.Height)) { BackgroundImage = statsBG, Visible = false }; Texture2D onlineBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 36); pnlOnline = new XNAPanel(new Rectangle(102, 330, onlineBG.Width, onlineBG.Height)) { BackgroundImage = onlineBG, Visible = false }; Texture2D partyBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 42); pnlParty = new XNAPanel(new Rectangle(102, 330, partyBG.Width, partyBG.Height)) { BackgroundImage = partyBG, Visible = false }; Texture2D settingsBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 47); pnlSettings = new XNAPanel(new Rectangle(102, 330, settingsBG.Width, settingsBG.Height)) { BackgroundImage = settingsBG, Visible = false }; Texture2D helpBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 63); pnlHelp = new XNAPanel(new Rectangle(102, 330, helpBG.Width, helpBG.Height)) { BackgroundImage = helpBG, Visible = false }; Texture2D newsBG = GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 48); pnlNews = new XNAPanel(new Rectangle(102, 330, newsBG.Width, newsBG.Height)) { BackgroundImage = newsBG }; //for easy update of all panels via foreach List <XNAPanel> pnlCollection = new List <XNAPanel>(10) { pnlInventory, pnlActiveSpells, pnlPassiveSpells, pnlChat, pnlStats, pnlOnline, pnlParty, pnlSettings, pnlHelp, pnlNews }; //pnlCollection.Add(pnlMacro); //if this ever happens... pnlCollection.ForEach(_pnl => World.IgnoreDialogs(_pnl)); for (int i = 0; i < NUM_BTN; ++i) { Texture2D _out = new Texture2D(g.GraphicsDevice, mainButtonTexture.Width / 2, mainButtonTexture.Height / NUM_BTN); Texture2D _ovr = new Texture2D(g.GraphicsDevice, mainButtonTexture.Width / 2, mainButtonTexture.Height / NUM_BTN); Rectangle _outRec = new Rectangle(0, i * _out.Height, _out.Width, _out.Height); Rectangle _ovrRec = new Rectangle(_ovr.Width, i * _ovr.Height, _ovr.Width, _ovr.Height); Color[] _outBuf = new Color[_outRec.Width * _outRec.Height]; Color[] _ovrBuf = new Color[_ovrRec.Width * _ovrRec.Height]; mainButtonTexture.GetData(0, _outRec, _outBuf, 0, _outBuf.Length); _out.SetData(_outBuf); mainButtonTexture.GetData(0, _ovrRec, _ovrBuf, 0, _ovrBuf.Length); _ovr.SetData(_ovrBuf); //0-5: left side, starting at 59, 327 with increments of 20 //6-10: right side, starting at 587, 347 Vector2 btnLoc = new Vector2(i < 6 ? 62 : 590, (i < 6 ? 330 : 350) + ((i < 6 ? i : i - 6) * 20)); mainBtn[i] = new XNAButton(new [] { _out, _ovr }, btnLoc); World.IgnoreDialogs(mainBtn[i]); } //left button onclick events mainBtn[0].OnClick += (s, e) => _doStateChange(InGameStates.Inventory); mainBtn[1].OnClick += (s, e) => World.Instance.ActiveMapRenderer.ToggleMapView(); mainBtn[2].OnClick += (s, e) => _doStateChange(InGameStates.Active); mainBtn[3].OnClick += (s, e) => _doStateChange(InGameStates.Passive); mainBtn[4].OnClick += (s, e) => _doStateChange(InGameStates.Chat); mainBtn[5].OnClick += (s, e) => _doStateChange(InGameStates.Stats); //right button onclick events mainBtn[6].OnClick += (s, e) => _doStateChange(InGameStates.Online); mainBtn[7].OnClick += (s, e) => _doStateChange(InGameStates.Party); //mainBtn[8].OnClick += OnViewMacro; //not implemented in EO client mainBtn[9].OnClick += (s, e) => _doStateChange(InGameStates.Settings); mainBtn[10].OnClick += (s, e) => _doStateChange(InGameStates.Help); SpriteBatch = new SpriteBatch(g.GraphicsDevice); state = InGameStates.News; chatRenderer = new EOChatRenderer(); chatRenderer.SetParent(pnlChat); chatRenderer.AddTextToTab(ChatTabs.Global, World.GetString(DATCONST2.STRING_SERVER), World.GetString(DATCONST2.GLOBAL_CHAT_SERVER_MESSAGE_1), ChatType.Note, ChatColor.Server); chatRenderer.AddTextToTab(ChatTabs.Global, World.GetString(DATCONST2.STRING_SERVER), World.GetString(DATCONST2.GLOBAL_CHAT_SERVER_MESSAGE_2), ChatType.Note, ChatColor.Server); newsTab = new ChatTab(pnlNews); chatTextBox = new ChatTextBox(new Rectangle(124, 308, 440, 19), g.Content.Load <Texture2D>("cursor"), "Microsoft Sans Serif", 8.0f) { Selected = true, Visible = true, MaxChars = 140 }; World.IgnoreDialogs(chatTextBox); chatTextBox.OnEnterPressed += _doTalk; chatTextBox.OnClicked += (s, e) => { //make sure clicking on the textarea selects it (this is an annoying problem in the original client) if (((EOGame)g).Dispatcher.Subscriber != null) { ((XNATextBox)(g as EOGame).Dispatcher.Subscriber).Selected = false; } (g as EOGame).Dispatcher.Subscriber = chatTextBox; chatTextBox.Selected = true; }; chatTextBox.OnTextChanged += (s, e) => { if (chatTextBox.Text.Length <= 0) { if (modeTextureLoaded && modeTexture != null) { modeTextureLoaded = false; modeTexture.Dispose(); modeTexture = null; currentChatMode = ChatMode.NoText; } return; } if (chatTextBox.Text.Length == 1 && chatTextBox.Text[0] == '~' && World.Instance.MainPlayer.ActiveCharacter.CurrentMap == World.Instance.JailMap) { chatTextBox.Text = ""; SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_WARNING, DATCONST2.JAIL_WARNING_CANNOT_USE_GLOBAL); return; } switch (chatTextBox.Text[0]) { case '!': currentChatMode = ChatMode.Private; break; case '@': //should show global if admin, otherwise, public/normal chat if (World.Instance.MainPlayer.ActiveCharacter.AdminLevel == AdminLevel.Player) { goto default; } currentChatMode = ChatMode.Global; break; case '~': currentChatMode = ChatMode.Global; break; case '+': { if (World.Instance.MainPlayer.ActiveCharacter.AdminLevel == AdminLevel.Player) { goto default; } currentChatMode = ChatMode.Admin; } break; case '\'': currentChatMode = ChatMode.Group; break; case '&': { if (World.Instance.MainPlayer.ActiveCharacter.GuildName == "") { goto default; } currentChatMode = ChatMode.Guild; } break; default: currentChatMode = ChatMode.Public; break; } }; ((EOGame)g).Dispatcher.Subscriber = chatTextBox; m_muteTimer = new Timer(s => { chatTextBox.IgnoreAllInput = false; currentChatMode = ChatMode.NoText; m_muteTimer.Change(Timeout.Infinite, Timeout.Infinite); }, null, Timeout.Infinite, Timeout.Infinite); statusLabel = new XNALabel(new Rectangle(97, 455, 1, 1), "Microsoft Sans Serif", 7f); clockLabel = new XNALabel(new Rectangle(558, 455, 1, 1), "Microsoft Sans Serif", 7f); StatusBars[0] = new HudElementHP(); StatusBars[1] = new HudElementTP(); StatusBars[2] = new HudElementSP(); StatusBars[3] = new HudElementTNL(); m_whoIsOnline = new EOOnlineList(pnlOnline); m_party = new EOPartyPanel(pnlParty); m_friendList = new XNAButton(GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 27, false, true), new Vector2(592, 312), new Rectangle(0, 260, 17, 15), new Rectangle(0, 276, 17, 15)) { Visible = true, Enabled = true }; m_friendList.OnClick += (o, e) => EOFriendIgnoreListDialog.Show(m_packetAPI, false); m_friendList.OnMouseOver += (o, e) => SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_BUTTON, DATCONST2.STATUS_LABEL_FRIEND_LIST); m_ignoreList = new XNAButton(GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 27, false, true), new Vector2(609, 312), new Rectangle(17, 260, 17, 15), new Rectangle(17, 276, 17, 15)) { Visible = true, Enabled = true }; m_ignoreList.OnClick += (o, e) => EOFriendIgnoreListDialog.Show(m_packetAPI, true); m_ignoreList.OnMouseOver += (o, e) => SetStatusLabel(DATCONST2.STATUS_LABEL_TYPE_BUTTON, DATCONST2.STATUS_LABEL_IGNORE_LIST); m_expInfo = new XNAButton(GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 58), new Vector2(55, 0), new Rectangle(331, 30, 22, 14), new Rectangle(331, 30, 22, 14)); m_expInfo.OnClick += (o, e) => EOSessionExpDialog.Show(); m_questInfo = new XNAButton(GFXLoader.TextureFromResource(GFXTypes.PostLoginUI, 58), new Vector2(77, 0), new Rectangle(353, 30, 22, 14), new Rectangle(353, 30, 22, 14)); //no need to make this a member variable //it does not have any resources to dispose and it is automatically disposed by the framework // ReSharper disable once UnusedVariable EOSettingsPanel settings = new EOSettingsPanel(pnlSettings); }
/// <summary> /// Event for enter keypress of primary textbox. Does the chat /// </summary> private void _doTalk(object sender, EventArgs e) { if (chatTextBox.Text.Length <= 0) { return; } string chatText = chatTextBox.Text, filtered; chatTextBox.Text = ""; switch (chatText[0]) { case '+': //admin talk if (World.Instance.MainPlayer.ActiveCharacter.AdminLevel == AdminLevel.Player) { goto default; } filtered = EOChatRenderer.Filter(chatText.Substring(1), true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.Admin, chatText.Substring(1))) { _returnToLogin(); break; } AddChat(ChatTabs.Group, World.Instance.MainPlayer.ActiveCharacter.Name, filtered, ChatType.HGM, ChatColor.Admin); } break; case '@': //system talk (admin) if (World.Instance.MainPlayer.ActiveCharacter.AdminLevel == AdminLevel.Player) { goto default; } filtered = EOChatRenderer.Filter(chatText.Substring(1), true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.Announce, chatText.Substring(1))) { _returnToLogin(); break; } World.Instance.ActiveMapRenderer.MakeSpeechBubble(null, filtered, false); string name = World.Instance.MainPlayer.ActiveCharacter.Name; AddChat(ChatTabs.Local, name, filtered, ChatType.GlobalAnnounce, ChatColor.ServerGlobal); AddChat(ChatTabs.Global, name, filtered, ChatType.GlobalAnnounce, ChatColor.ServerGlobal); AddChat(ChatTabs.Group, name, filtered, ChatType.GlobalAnnounce, ChatColor.ServerGlobal); } break; case '\'': //group talk if (!m_party.PlayerIsMember((short)World.Instance.MainPlayer.ActiveCharacter.ID)) { break; //not in a party, cancel the talk } filtered = EOChatRenderer.Filter(chatText.Substring(1), true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.Party, chatText.Substring(1))) { _returnToLogin(); break; } World.Instance.ActiveMapRenderer.MakeSpeechBubble(null, filtered, true); AddChat(ChatTabs.Local, World.Instance.MainPlayer.ActiveCharacter.Name, filtered, ChatType.PlayerPartyDark, ChatColor.PM); AddChat(ChatTabs.Group, World.Instance.MainPlayer.ActiveCharacter.Name, filtered, ChatType.PlayerPartyDark); } break; case '&': //guild talk if (World.Instance.MainPlayer.ActiveCharacter.GuildName == "") { goto default; } filtered = EOChatRenderer.Filter(chatText.Substring(1), true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.Guild, chatText.Substring(1))) { _returnToLogin(); break; } //note: more processing of colors/icons is needed here AddChat(ChatTabs.Group, World.Instance.MainPlayer.ActiveCharacter.Name, filtered); } break; case '~': //global talk filtered = EOChatRenderer.Filter(chatText.Substring(1), true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.Global, chatText.Substring(1))) { _returnToLogin(); break; } AddChat(ChatTabs.Global, World.Instance.MainPlayer.ActiveCharacter.Name, filtered); } break; case '!': //private talk { string character, message; if (chatRenderer.SelectedTab.WhichTab == ChatTabs.Private1 || chatRenderer.SelectedTab.WhichTab == ChatTabs.Private2) { character = chatRenderer.SelectedTab.ChatCharacter; message = chatText.Substring(1); } else { int firstSpace = chatText.IndexOf(' '); if (firstSpace < 7) { return; //character names should be 6, leading ! should be 1, 6+1=7 and THAT'S MATH } character = chatText.Substring(1, firstSpace - 1); message = chatText.Substring(firstSpace + 1); } character = character.Substring(0, 1).ToUpper() + character.Substring(1).ToLower(); filtered = EOChatRenderer.Filter(message, true); if (filtered != null) { if (!m_packetAPI.Speak(TalkType.PM, message, character)) { _returnToLogin(); break; } ChatTabs whichPrivateChat = chatRenderer.StartConversation(character); //the other player will have their messages rendered in Color.PM on scr //this player will have their messages rendered in Color.PM on the PM tab if (whichPrivateChat != ChatTabs.None) { AddChat(whichPrivateChat, World.Instance.MainPlayer.ActiveCharacter.Name, filtered, ChatType.Note, ChatColor.PM); } } } break; case '#': //local command { string cmd = chatText.Substring(1).ToLower().Trim(); string[] args = cmd.Split(new[] { ' ' }); if (args.Length == 1 && args[0] == "nowall") { World.Instance.ActiveCharacterRenderer.NoWall = !World.Instance.ActiveCharacterRenderer.NoWall; } else if (args.Length == 2 && args[0] == "find") { if (!m_packetAPI.FindPlayer(args[1])) { ((EOGame)Game).LostConnectionDialog(); } } else if (args.Length == 1 && args[0] == "loc") { string firstPart = World.Instance.DataFiles[World.Instance.Localized2].Data[(int)DATCONST2.STATUS_LABEL_YOUR_LOCATION_IS_AT]; AddChat(ChatTabs.Local, "System", string.Format(firstPart + " {0} x:{1} y:{2}", World.Instance.ActiveMapRenderer.MapRef.MapID, World.Instance.MainPlayer.ActiveCharacter.X, World.Instance.MainPlayer.ActiveCharacter.Y), ChatType.LookingDude); } else if (args.Length == 1 && cmd == "usage") { int usage = World.Instance.MainPlayer.ActiveCharacter.Stats.usage; AddChat(ChatTabs.Local, "System", string.Format("[x] usage: {0}hrs. {1}min.", usage / 60, usage % 60)); } else if (args.Length == 1 && cmd == "ping") { if (!m_packetAPI.PingServer()) { ((EOGame)Game).LostConnectionDialog(); } } } break; default: { filtered = EOChatRenderer.Filter(chatText, true); if (filtered != null) { //send packet to the server if (!m_packetAPI.Speak(TalkType.Local, chatText)) { _returnToLogin(); break; } //do the rendering World.Instance.ActiveMapRenderer.MakeSpeechBubble(null, filtered, false); AddChat(ChatTabs.Local, World.Instance.MainPlayer.ActiveCharacter.Name, filtered); } } break; } }