Skip to content

Commit

Permalink
Add right-click to PM a user from the online list
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Mar 19, 2022
1 parent 24da002 commit c919c6a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion EndlessClient/HUD/Panels/HudPanelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public StatsPanel CreateStatsPanel()
public OnlineListPanel CreateOnlineListPanel()
{
var chatFont = _contentManagerProvider.Content.Load<SpriteFont>(Constants.FontSize08);
return new OnlineListPanel(_nativeGraphicsManager, chatFont) { DrawOrder = HUD_CONTROL_LAYER };
return new OnlineListPanel(_nativeGraphicsManager, _hudControlProvider, chatFont) { DrawOrder = HUD_CONTROL_LAYER };
}

public PartyPanel CreatePartyPanel()
Expand Down
41 changes: 33 additions & 8 deletions EndlessClient/HUD/Panels/OnlineListPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using EndlessClient.UIControls;
using EndlessClient.ControlSets;
using EndlessClient.HUD.Controls;
using EndlessClient.UIControls;
using EOLib;
using EOLib.Domain.Online;
using EOLib.Extensions;
Expand All @@ -7,6 +9,7 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Optional.Unsafe;
using System;
using System.Collections.Generic;
using System.Linq;
using XNAControls;
Expand All @@ -24,7 +27,11 @@ private enum Filter
Max
}

private const int DRAW_NAME_X = 18,
DRAW_OFFSET_Y = 23;

private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IHudControlProvider _hudControlProvider;
private readonly SpriteFont _chatFont;

private readonly List<OnlinePlayerInfo> _onlineList;
Expand All @@ -39,9 +46,11 @@ private enum Filter
private List<OnlinePlayerInfo> _filteredList;

public OnlineListPanel(INativeGraphicsManager nativeGraphicsManager,
IHudControlProvider hudControlProvider,
SpriteFont chatFont)
{
_nativeGraphicsManager = nativeGraphicsManager;
_hudControlProvider = hudControlProvider;
_chatFont = chatFont;
_onlineList = new List<OnlinePlayerInfo>();

Expand Down Expand Up @@ -96,16 +105,17 @@ public void UpdateOnlinePlayers(IReadOnlyList<OnlinePlayerInfo> onlinePlayers)

_totalNumberOfPlayers.Text = $"{_onlineList.Count}";
_scrollBar.UpdateDimensions(_onlineList.Count);
_scrollBar.ScrollToTop();

// todo: friend/ignore lists
//m_friendList = InteractList.LoadAllFriend();
}

protected override void OnUpdateControl(GameTime gameTime)
{
var curState = Mouse.GetState();

if (_filterClickArea.ContainsPoint(curState.X, curState.Y) && curState.LeftButton == ButtonState.Released && PreviousMouseState.LeftButton == ButtonState.Pressed)
if (_filterClickArea.ContainsPoint(CurrentMouseState.X, CurrentMouseState.Y) &&
CurrentMouseState.LeftButton == ButtonState.Released &&
PreviousMouseState.LeftButton == ButtonState.Pressed)
{
_filter = (Filter)(((int)_filter + 1) % (int)Filter.Max);
_scrollBar.ScrollToTop();
Expand All @@ -118,7 +128,24 @@ protected override void OnUpdateControl(GameTime gameTime)
// todo: implement for party/guild
case Filter.Party: _filteredList.Clear(); break;
case Filter.All:
default: _filteredList = _onlineList; break;
default: _filteredList = new List<OnlinePlayerInfo>(_onlineList); break;
}

_scrollBar.UpdateDimensions(_filteredList.Count);
}
else if (CurrentMouseState.RightButton == ButtonState.Released &&
PreviousMouseState.RightButton == ButtonState.Pressed)
{
var mousePos = CurrentMouseState.Position;
if (mousePos.X >= DrawAreaWithParentOffset.X + DRAW_NAME_X && mousePos.X <= _scrollBar.DrawAreaWithParentOffset.X &&
mousePos.Y >= DrawAreaWithParentOffset.Y + DRAW_OFFSET_Y && mousePos.Y <= DrawAreaWithParentOffset.Y + DrawAreaWithParentOffset.Height)
{
var index = (mousePos.Y - (DrawAreaWithParentOffset.Y + DRAW_OFFSET_Y)) / 13;
if (index >= 0 && index <= _filteredList.Count)
{
var name = _filteredList[_scrollBar.ScrollOffset + index].Name;
_hudControlProvider.GetComponent<ChatTextBox>(HudControlIdentifier.ChatTextBox).Text = $"!{name} ";
}
}
}

Expand All @@ -130,11 +157,9 @@ protected override void OnDrawControl(GameTime gameTime)
base.OnDrawControl(gameTime);

const int DRAW_ICON_X = 4,
DRAW_NAME_X = 18,
DRAW_TITLE_X = 133,
DRAW_GUILD_X = 245,
DRAW_CLASS_X = 359,
DRAW_OFFSET_Y = 23;
DRAW_CLASS_X = 359;


_spriteBatch.Begin();
Expand Down
8 changes: 4 additions & 4 deletions EndlessClient/UIControls/ChatModePictureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void OnUpdateControl(GameTime gameTime)
},
none: () =>
{
if (SingleCharTypedOrDeleted())
if (AtLeastOneCharTypedOrDeleted())
{
UpdateSourceRectangleForMode(_chatModeCalculator.CalculateMode(ChatTextBox.Text));
_lastChat = ChatTextBox.Text;
Expand All @@ -74,11 +74,11 @@ protected override void OnUpdateControl(GameTime gameTime)
base.OnUpdateControl(gameTime);
}

private bool SingleCharTypedOrDeleted()
private bool AtLeastOneCharTypedOrDeleted()
{
return _hudControlProvider.IsInGame &&
((_lastChat.Length == 0 && ChatTextBox.Text.Length == 1) ||
(_lastChat.Length == 1 && ChatTextBox.Text.Length == 0));
((_lastChat.Length == 0 && ChatTextBox.Text.Length > 0) ||
(_lastChat.Length > 0 && ChatTextBox.Text.Length == 0));
}

private void UpdateSourceRectangleForMode(ChatMode mode)
Expand Down

0 comments on commit c919c6a

Please sign in to comment.