Skip to content

Commit

Permalink
Merge pull request #79 from GrantBartlett/friends-online-highlighted
Browse files Browse the repository at this point in the history
Highlight friends in the online list
  • Loading branch information
Rampastring committed Aug 31, 2018
2 parents 84f8df7 + eed61bc commit 9b0cb27
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 29 deletions.
34 changes: 5 additions & 29 deletions DXMainClient/DXGUI/Multiplayer/CnCNet/CnCNetLobby.cs
Expand Up @@ -40,7 +40,7 @@ internal class CnCNetLobby : XNAWindow, ISwitchable

private CnCNetManager connectionManager;

private XNAListBox lbPlayerList;
private PlayerListBox lbPlayerList;
private ChatListBox lbChatMessages;
private GameListBox lbGameList;
private PlayerContextMenu playerContextMenu;
Expand Down Expand Up @@ -139,7 +139,7 @@ public override void Initialize()
lbGameList.DoubleLeftClick += LbGameList_DoubleLeftClick;
lbGameList.AllowMultiLineItems = false;

lbPlayerList = new XNAListBox(WindowManager);
lbPlayerList = new PlayerListBox(WindowManager, gameCollection);
lbPlayerList.Name = "lbPlayerList";
lbPlayerList.ClientRectangle = new Rectangle(ClientRectangle.Width - 202,
20, 190,
Expand Down Expand Up @@ -988,11 +988,13 @@ private void RefreshPlayerList(object sender, EventArgs e)
{
string selectedUserName = lbPlayerList.SelectedItem == null ?
string.Empty : lbPlayerList.SelectedItem.Text;

lbPlayerList.Clear();

foreach (ChannelUser user in currentChatChannel.Users)
{
AddUser(user);
user.IRCUser.IsFriend = pmWindow.IsFriend(user.IRCUser.Name);
lbPlayerList.AddUser(user);
}

if (selectedUserName != string.Empty)
Expand Down Expand Up @@ -1023,32 +1025,6 @@ private void CurrentChatChannel_MessageAdded(object sender, IRCMessageEventArgs
AddMessageToChat(e.Message);
}

private void AddUser(ChannelUser user)
{
XNAListBoxItem item = new XNAListBoxItem();

item.Tag = user;

if (user.IsAdmin)
{
item.Text = user.IRCUser.Name + " (Admin)";
item.TextColor = cAdminNameColor;
item.Texture = adminGameIcon;
}
else
{
item.Text = user.IRCUser.Name;
item.TextColor = UISettings.AltColor;

if (user.IRCUser.GameID < 0 || user.IRCUser.GameID >= gameCollection.GameList.Count)
item.Texture = unknownGameIcon;
else
item.Texture = gameCollection.GameList[user.IRCUser.GameID].Texture;
}

lbPlayerList.AddItem(item);
}

private void GameBroadcastChannel_CTCPReceived(object sender, ChannelCTCPEventArgs e)
{
var channel = (Channel)sender;
Expand Down
160 changes: 160 additions & 0 deletions DXMainClient/DXGUI/Multiplayer/PlayerListBox.cs
@@ -0,0 +1,160 @@
using ClientCore.CnCNet5;
using DTAClient.DXGUI.Multiplayer.CnCNet;
using DTAClient.Online;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTAClient.DXGUI.Multiplayer
{
public class PlayerListBox: XNAListBox
{
public List<ChannelUser> Users;

private Texture2D adminGameIcon;
private Texture2D unknownGameIcon;
private Texture2D badgeGameIcon;
private Texture2D friendIcon;

private XNAScrollBar scrollBar;

private GameCollection gameCollection;

public PlayerListBox(WindowManager windowManager, GameCollection gameCollection) : base(windowManager)
{
this.gameCollection = gameCollection;

Users = new List<ChannelUser>();

adminGameIcon = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.cncneticon);
unknownGameIcon = AssetLoader.TextureFromImage(ClientCore.Properties.Resources.unknownicon);
friendIcon = AssetLoader.LoadTexture("friendicon.png");
badgeGameIcon = AssetLoader.LoadTexture("Badges\\badge.png");

scrollBar = new XNAScrollBar(WindowManager);
}

public void AddUser(ChannelUser user)
{
AddUserToList(user);
}

/// <summary>
/// Refreshes game information in the game list box.
/// </summary>
public void Refresh()
{
Items.Clear();
}

public override void Draw(GameTime gameTime)
{
Rectangle windowRectangle = WindowRectangle();

DrawPanel();

int height = 2;
int margin = 2;

for (int i = TopIndex; i < Items.Count; i++)
{
XNAListBoxItem lbItem = Items[i];
var user = (ChannelUser)lbItem.Tag;

if (height + lbItem.TextLines.Count * LineHeight > ClientRectangle.Height)
break;

int x = TextBorderDistance;

if (i == SelectedIndex)
{
int drawnWidth;

if (DrawSelectionUnderScrollbar || !scrollBar.IsDrawn() || !EnableScrollbar)
{
drawnWidth = windowRectangle.Width - 2;
}
else
{
drawnWidth = windowRectangle.Width - 2 - scrollBar.ClientRectangle.Width;
}

Renderer.FillRectangle(
new Rectangle(windowRectangle.X + 1, windowRectangle.Y + height,
drawnWidth, lbItem.TextLines.Count * LineHeight),
GetColorWithAlpha(FocusColor));
}

Renderer.DrawTexture(lbItem.Texture, new Rectangle(windowRectangle.X + x, windowRectangle.Y + height,
adminGameIcon.Width, adminGameIcon.Height), Color.White);

x += adminGameIcon.Width + margin;

// Friend Icon
if (user.IRCUser.IsFriend)
{
Renderer.DrawTexture(friendIcon,
new Rectangle(windowRectangle.X + x, windowRectangle.Y + height,
friendIcon.Width, friendIcon.Height), Color.White);

x += friendIcon.Width + margin;
}

// Badge Icon - coming soon
/*
Renderer.DrawTexture(badgeGameIcon,
new Rectangle(windowRectangle.X + x, windowRectangle.Y + height,
badgeGameIcon.Width, badgeGameIcon.Height), Color.White);
x += badgeGameIcon.Width + margin;
*/

// Player Name
string name = user.IsAdmin ? user.IRCUser.Name + " (Admin)" : user.IRCUser.Name;
x += lbItem.TextXPadding;

Renderer.DrawStringWithShadow(name, FontIndex,
new Vector2(windowRectangle.X + x, windowRectangle.Y + height),
lbItem.TextColor);

height += LineHeight;
}

if (DrawBorders)
DrawPanelBorders();

DrawChildren(gameTime);
}

private void AddUserToList(ChannelUser user)
{
XNAListBoxItem item = new XNAListBoxItem();

item.Tag = user;

if (user.IsAdmin)
{
item.Text = user.IRCUser.Name + " (Admin)";
item.TextColor = Color.Red;
item.Texture = adminGameIcon;
}
else
{
item.Text = user.IRCUser.Name;
item.TextColor = UISettings.AltColor;

if (user.IRCUser.GameID < 0 || user.IRCUser.GameID >= gameCollection.GameList.Count)
item.Texture = unknownGameIcon;
else
item.Texture = gameCollection.GameList[user.IRCUser.GameID].Texture;
}

AddItem(item);
}
}
}
1 change: 1 addition & 0 deletions DXMainClient/DXMainClient.csproj
Expand Up @@ -314,6 +314,7 @@
<Compile Include="DXGUI\Multiplayer\CnCNet\PrivateMessageNotificationBox.cs" />
<Compile Include="DXGUI\Multiplayer\CnCNet\PrivateMessagingPanel.cs" />
<Compile Include="DXGUI\Multiplayer\CnCNet\PrivateMessagingWindow.cs" />
<Compile Include="DXGUI\Multiplayer\PlayerListBox.cs" />
<Compile Include="Online\ChannelUser.cs" />
<Compile Include="Online\EventArguments\ChannelCTCPEventArgs.cs" />
<Compile Include="Online\EventArguments\PrivateMessageEventArgs.cs" />
Expand Down
2 changes: 2 additions & 0 deletions DXMainClient/Online/IRCUser.cs
Expand Up @@ -36,5 +36,7 @@ public object Clone()
{
return MemberwiseClone();
}

public bool IsFriend { get; set; }
}
}

0 comments on commit 9b0cb27

Please sign in to comment.