Skip to content

Commit

Permalink
feat: Added a search player bar on the :privatechat command (#1594)
Browse files Browse the repository at this point in the history
* Added a search player bar on the `:privatechat` command.

This is useful on servers that has hundreds of players. Was also requested by a community member.

* removed unusual link
  • Loading branch information
24rr authored Sep 8, 2024
1 parent ce792a9 commit 825f7a4
Showing 1 changed file with 59 additions and 37 deletions.
96 changes: 59 additions & 37 deletions MainModule/Client/UI/Default/PrivateChat.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,82 @@ return function(data, env)
if env then
setfenv(1, env)
end

local Owner = data.FromPlayer;
local SessionKey = data.SessionKey;
local SessionName = data.SessionName;
local CanManageUsers = data.CanManageUsers;

local debounce = false
local gTable
local newMessage
local debounce, gTable, selectedPlayer = false, nil, nil
local peerList, messageObjs = {}, {}

local window, chatlog, reply, playerList, send, layout, sessionEvent;
local peerList = {};
local messageObjs = {};

local selectedPlayer = nil;

local function sendIt()
local text = service.Trim(reply.Text)

if text ~= "" then
client.Remote.Send("Session", SessionKey, "SendMessage", text)
end
end

local function promptAddUser()
local list = {}
for _,v in service.Players:GetPlayers() do
local good = true;
for _, peer in peerList do
if peer.UserId == v.UserId then
good = false;
break;
end
end
local searchBar, playerList

if good then
table.insert(list, {
Text = service.FormatPlayer(v);
Data = service.UnWrap(v);
})
end
end

local answer = client.UI.Make("SelectionPrompt", {
local window = client.UI.Make("Window", {
Name = "Add User";
Options = list;
});
Title = "Add User";
Size = {300, 400};
})

searchBar = window:Add("TextBox", {
Size = UDim2.new(1, -10, 0, 30);
Position = UDim2.new(0, 5, 0, 5);
Text = "";
PlaceholderText = "Search player...";
ClearTextOnFocus = false;
})

playerList = window:Add("ScrollingFrame", {
Size = UDim2.new(1, -10, 1, -45);
Position = UDim2.new(0, 5, 0, 40);
BackgroundTransparency = 0.9;
})

if answer then
client.Remote.Send("Session", SessionKey, "AddPlayerToSession", answer)
local function updateList()
playerList:ClearAllChildren()
local searchText = searchBar.Text:lower()
local yPos = 0
for _, v in service.Players:GetPlayers() do
local good = true
for _, peer in peerList do
if peer.UserId == v.UserId then
good = false
break
end
end
if good and (searchText == "" or v.Name:lower():find(searchText) or v.DisplayName:lower():find(searchText)) then
local button = playerList:Add("TextButton", {
Text = service.FormatPlayer(v);
Size = UDim2.new(1, 0, 0, 30);
Position = UDim2.new(0, 0, 0, yPos);
BackgroundTransparency = 0.5;
})
button.MouseButton1Click:Connect(function()
window:Close()
client.Remote.Send("Session", SessionKey, "AddPlayerToSession", service.UnWrap(v))
end)
yPos = yPos + 35
end
end
playerList.CanvasSize = UDim2.new(0, 0, 0, yPos)
end
end;

searchBar:GetPropertyChangedSignal("Text"):Connect(updateList)
updateList()

window:Ready()
end

local function updatePeerList(peers)
playerList:ClearAllChildren()
peerList = peers
Expand Down Expand Up @@ -206,7 +229,6 @@ return function(data, env)
table.remove(messageObjs, 1)
end
end

local function systemMessage(msg)
newMessage({
PlayerName = "* SYSTEM *";
Expand Down Expand Up @@ -237,15 +259,15 @@ return function(data, env)
Size = UDim2.new(1, -105, 1, -45);
CanvasSize = UDim2.new(0, 0, 0, 0);
BackgroundTransparency = 0.9;
--AutomaticCanvasSize = "Y";
AutomaticCanvasSize = "Y";
})

reply = window:Add("TextBox", {
Text = ""; --"Enter reply";
Text = "";
PlaceholderText = "";
Size = UDim2.new(1, -70, 0, 30);
Position = UDim2.new(0, 5, 1, -35);
ClearTextOnFocus = false;--true;
ClearTextOnFocus = false;
TextScaled = true;
})

Expand Down Expand Up @@ -324,7 +346,7 @@ return function(data, env)
PlayerName = p.Name;
PlayerDisplayName = p.DisplayName;
Message = data.Message;
Icon = p.Icon or 0; --// replace with user avatar later
Icon = p.Icon or 0;
});
end
end
Expand All @@ -335,8 +357,8 @@ return function(data, env)
if cmd == "PlayerSentMessage" then
local p = vargs[1]
local message = vargs[2]

if newMessage then
print('sdf')
newMessage({
PlayerName = p.Name;
PlayerDisplayName = p.DisplayName;
Expand Down

0 comments on commit 825f7a4

Please sign in to comment.