-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathPlayerListApp.lua
More file actions
358 lines (300 loc) · 11.9 KB
/
Copy pathPlayerListApp.lua
File metadata and controls
358 lines (300 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
--!nonstrict
local CorePackages = game:GetService("CorePackages")
local Players = game:GetService("Players")
local Roact = require(CorePackages.Roact)
local RoactRodux = require(CorePackages.RoactRodux)
local Otter = require(CorePackages.Otter)
local AppFonts = require(CorePackages.Workspace.Packages.Style).AppFonts
local CoreGui = game:GetService("CoreGui")
local RobloxGui = CoreGui:WaitForChild("RobloxGui")
local Modules = CoreGui.RobloxGui.Modules
local RobloxTranslator = require(RobloxGui:WaitForChild("Modules"):WaitForChild("RobloxTranslator"))
local TopBarConstants = require(Modules.TopBar.Constants)
local ChromeEnabled = require(Modules.Chrome.Enabled)()
local Presentation = script.Parent
local PlayerList = Presentation.Parent.Parent
local SetPlayerListVisibility = require(PlayerList.Actions.SetPlayerListVisibility)
local PlayerDropDown = require(Presentation.PlayerDropDown)
local PlayerListSorter = require(Presentation.PlayerListSorter)
local VoiceChatShield = require(Presentation.Parent.PresentationCommon.VoiceChatShield)
local Connection = PlayerList.Components.Connection
local EventConnections = require(Connection.EventConnections)
local ContextActionsBinder = require(Connection.ContextActionsBinder)
local TopStatConnector = require(Connection.TopStatConnector)
local LayoutValues = require(Connection.LayoutValues)
local WithLayoutValues = LayoutValues.WithLayoutValues
local FFlagPlayerListFixMobileScrolling = require(PlayerList.Flags.FFlagPlayerListFixMobileScrolling)
local FFlagPlayerListFixBackgroundFlicker = require(PlayerList.Flags.FFlagPlayerListFixBackgroundFlicker)
local GetFFlagPlayerListChromePushdown = require(PlayerList.Flags.GetFFlagPlayerListChromePushdown)
local GetFFlagFixDropDownVisibility = require(PlayerList.Flags.GetFFlagFixDropDownVisibility)
local MOTOR_OPTIONS = {
dampingRatio = 1,
frequency = 4,
}
local OLD_PLAYERLIST_PLAYER_ENTRY_SIZE = 26
local OLD_PLAYERLIST_TEAM_ENTRY_SIZE = 20
local MIN_PLAYERS_HEIGHT_ADJUST = 6
local MAX_PLAYERS_HEIGHT_ADJUST = 12
local HEADER_SIZE_Y = 44
local BORDER_SIZE = 24
local function map(x, inMin, inMax, outMin, outMax)
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
end
local PlayerListApp = Roact.PureComponent:extend("PlayerListApp")
local function playerListSizeFromViewportSize(viewportSize)
-- Turn x/y into min/max to stay independent of aspect ratio
local vMin = math.min(viewportSize.x, viewportSize.y)
local vMax = math.max(viewportSize.x, viewportSize.y)
-- Map the viewport sizes to the frame sizes
-- Min axis: Viewport size 320 -> Frame size 270
-- Min axis: Viewport size 375 -> Frame size 330
local sMin = map(vMin, 320, 375, 270, 330)
-- Max axis: Viewport size 480 -> Frame size 434
-- Max axis: Viewport size 670 -> Frame size 480
local sMax = map(vMax, 480, 670, 434, 480)
-- Clamp the max size to (500, 600)
-- Clamp the min size to 270x434, but always keep a 12px border on the edges
sMin = math.clamp(sMin, math.min(270, vMin - BORDER_SIZE), 500)
sMax = math.clamp(sMax, math.min(434, vMax - BORDER_SIZE), 600)
-- Remap from min/max to x/y
local sX = viewportSize.x > viewportSize.y and sMax or sMin
local sY = viewportSize.y > viewportSize.x and sMax or sMin
-- Increase y-axis border to avoid chrome overlap on landscape
if GetFFlagPlayerListChromePushdown() and ChromeEnabled and viewportSize.y < viewportSize.x then
sY -= (TopBarConstants.TopBarHeight - BORDER_SIZE)
end
return UDim2.fromOffset(sX, sY)
end
local function shouldShowNeutralTeam(players)
for _, player in ipairs(players) do
if player.Team == nil then
return true
end
end
return false
end
local function getTeamCount(teams, players)
local uniqueTeams = {}
local teamCount = 0
for _, team in pairs(teams) do
if not uniqueTeams[team.TeamColor.Number] then
uniqueTeams[team.TeamColor.Number] = true
teamCount = teamCount + 1
end
end
if teamCount > 0 and shouldShowNeutralTeam(players) then
teamCount = teamCount + 1
end
return teamCount
end
function PlayerListApp:init()
self.state = {
visible = false,
}
self.bodyTransparency, self.updateBodyTransparency = Roact.createBinding(0.5)
self.bodyTransparencyMotor = Otter.createSingleMotor(if FFlagPlayerListFixBackgroundFlicker then 1 else 0)
self.bodyTransparencyMotor:onStep(function(transparency)
self.updateBodyTransparency(transparency)
if transparency < 0.5 and self.props.displayOptions.isVisible then
if not self.state.visible then
self:setState({
visible = true,
})
end
elseif self.state.visible then
self:setState({
visible = false,
})
end
self.props.setLayerCollectorEnabled(transparency < 0.99 or self.props.displayOptions.isVisible)
end)
self.bgTransparency, self.updateBgTransparency = Roact.createBinding(0)
self.bgTransparencyMotor = Otter.createSingleMotor(if FFlagPlayerListFixBackgroundFlicker then 1 else 0)
self.bgTransparencyMotor:onStep(self.updateBgTransparency)
self.frameScale, self.updateFrameScale = Roact.createBinding(1)
self.frameScaleMotor = Otter.createSingleMotor(0)
self.frameScaleMotor:onStep(function(scale)
self.updateFrameScale(scale)
end)
self.titleRef = Roact.createRef()
self.closeRef = Roact.createRef()
end
function PlayerListApp:renderBodyChildren(previousSizeBound, childElements)
local contentVisible = self.state.visible
local dropDownVisible = self.props.isDropDownVisible
return {
UIScale = Roact.createElement("UIScale", {
Scale = self.frameScale,
}),
UICorner = Roact.createElement("UICorner", {
CornerRadius = UDim.new(0, 6),
}),
TitleText = Roact.createElement("TextLabel", {
Size = UDim2.new(1, 0, 0, HEADER_SIZE_Y),
Position = UDim2.new(0, 0, 0, 0),
BackgroundTransparency = 1,
Font = AppFonts.default:getBold(),
Visible = contentVisible and not dropDownVisible,
TextSize = 22,
TextColor3 = Color3.fromRGB(240, 240, 240),
TextXAlignment = Enum.TextXAlignment.Center,
TextYAlignment = Enum.TextYAlignment.Center,
Text = RobloxTranslator:FormatByKey("InGame.PlayerList.Leaderboard"),
[Roact.Ref] = self.titleRef,
}),
CloseButton = Roact.createElement("ImageButton", {
Image = "rbxasset://textures/ui/InspectMenu/x.png",
ImageColor3 = Color3.fromRGB(255, 255, 255),
AnchorPoint = Vector2.new(0, 0.5),
Size = UDim2.fromOffset(22, 22),
Position = UDim2.fromOffset(11, 22),
BackgroundTransparency = 1,
Visible = contentVisible and not dropDownVisible,
ZIndex = 0,
[Roact.Ref] = self.closeRef,
[Roact.Event.Activated] = function()
self.props.setPlayerListVisible(false)
end,
}),
ContentFrame = Roact.createElement("Frame", {
Position = UDim2.new(0.5, 0, 1, 0),
AnchorPoint = Vector2.new(0.5, 1),
Size = UDim2.new(1, 0, 1, -HEADER_SIZE_Y),
BackgroundTransparency = 1,
Visible = contentVisible and not dropDownVisible,
AutoLocalize = false,
}, childElements),
}
end
function PlayerListApp:render()
return WithLayoutValues(function(layoutValues)
local entrySize
if layoutValues.IsTenFoot then
entrySize = layoutValues.EntrySizeX
else
entrySize = layoutValues.EntryBaseSizeX + (4 * layoutValues.EntrySizeIncreasePerStat)
local dropDownSpace = layoutValues.PlayerDropDownSizeXMobile + layoutValues.PlayerDropDownOffset
local usedScreenSpace = layoutValues.ContainerPadding * 2 + dropDownSpace
if self.props.screenSizeX - usedScreenSpace < entrySize then
entrySize = self.props.screenSizeX - usedScreenSpace
end
end
local previousSizeBound = math.huge
local doHeightAdjust = Players.MaxPlayers >= MIN_PLAYERS_HEIGHT_ADJUST
and Players.MaxPlayers <= MAX_PLAYERS_HEIGHT_ADJUST
if doHeightAdjust then
previousSizeBound = Players.MaxPlayers * OLD_PLAYERLIST_PLAYER_ENTRY_SIZE
local teamCount = getTeamCount(self.props.teams, self.props.players)
previousSizeBound = previousSizeBound + teamCount * OLD_PLAYERLIST_TEAM_ENTRY_SIZE
end
local childElements = {}
if self.state.visible then
childElements["PlayerScrollList"] = Roact.createElement(PlayerListSorter, {
screenSizeY = self.props.screenSizeY,
entrySize = entrySize,
})
end
childElements["EventConnections"] = Roact.createElement(EventConnections)
childElements["ContextActionsBindings"] = Roact.createElement(ContextActionsBinder)
childElements["TopStatConnector"] = Roact.createElement(TopStatConnector)
if not game:GetEngineFeature("XboxRemoveVoiceChatButton") then
if self.props.displayOptions.hasPermissionToVoiceChat then
childElements["VoiceChatShield"] = Roact.createElement(VoiceChatShield)
end
end
return Roact.createElement("ImageButton", {
Active = self.props.displayOptions.isVisible,
Size = UDim2.new(1, 0, 1, 0),
Position = UDim2.new(0, 0, 0, 0),
BackgroundColor3 = Color3.fromRGB(17, 18, 20),
BackgroundTransparency = self.bgTransparency,
BorderColor3 = Color3.fromRGB(0, 0, 0),
BorderSizePixel = 0,
AutoLocalize = false,
AutoButtonColor = false,
Selectable = not FFlagPlayerListFixMobileScrolling,
Image = "",
[Roact.Event.Activated] = function()
self.props.setPlayerListVisible(false)
end,
}, {
PlayerDropDown = Roact.createElement(PlayerDropDown, {
contentsVisible = true,
selectedPlayer = self.props.dropDownPlayer,
}),
-- Push menu down when chrome enabled to below topbarheight
BodyPadding = if GetFFlagPlayerListChromePushdown() and ChromeEnabled and self.props.screenSizeY < self.props.screenSizeX then Roact.createElement("UIPadding", {
PaddingTop = UDim.new(0, TopBarConstants.TopBarHeight)
}) else nil,
BodyBackground = Roact.createElement("Frame", {
Size = playerListSizeFromViewportSize(Vector2.new(self.props.screenSizeX, self.props.screenSizeY)),
AnchorPoint = Vector2.new(0.5, 0.5),
Position = UDim2.new(0.5, 0, 0.5, 0),
BackgroundColor3 = Color3.fromRGB(17, 18, 20),
BackgroundTransparency = self.bodyTransparency,
BorderColor3 = Color3.fromRGB(0, 0, 0),
BorderSizePixel = 0,
}, self:renderBodyChildren(previousSizeBound, childElements)),
})
end)
end
function PlayerListApp:didMount()
self.props.setLayerCollectorEnabled(false)
self:setState({
visible = self.props.displayOptions.isVisible,
})
end
function PlayerListApp:willUnmount()
self.props.setLayerCollectorEnabled(true)
end
function PlayerListApp:didUpdate(previousProps, previousState)
local isVisible = self.props.displayOptions.isVisible
local isDropDownVisible = self.props.isDropDownVisible
if isVisible ~= previousProps.displayOptions.isVisible and not isVisible then
self:setState({
visible = isVisible,
})
end
local backgroundTransparency = (isDropDownVisible or isVisible) and 0.7 or 1
self.bgTransparencyMotor:setGoal(Otter.spring(backgroundTransparency, MOTOR_OPTIONS))
local isDropDownEnabled = if GetFFlagFixDropDownVisibility
then isDropDownVisible and isVisible
else isDropDownVisible
local bodyScale = 1.25
if isDropDownEnabled then
bodyScale = 0.95
elseif isVisible then
bodyScale = 1
end
self.frameScaleMotor:setGoal(Otter.spring(bodyScale, MOTOR_OPTIONS))
local bodyTransparency = 1
if isDropDownEnabled then
bodyTransparency = 0.8 * self.props.preferredTransparency
elseif isVisible then
bodyTransparency = 0.2 * self.props.preferredTransparency
end
self.bodyTransparencyMotor:setGoal(Otter.spring(bodyTransparency, MOTOR_OPTIONS))
end
local function mapStateToProps(state)
return {
isDropDownVisible = state.playerDropDown.isVisible,
screenSizeX = state.screenSize.X,
screenSizeY = state.screenSize.Y,
preferredTransparency = state.settings.preferredTransparency,
displayOptions = state.displayOptions,
players = state.players,
playerStats = state.playerStats,
playerIconInfo = state.playerIconInfo,
playerRelationship = state.playerRelationship,
gameStats = state.gameStats,
teams = state.teams,
}
end
local function mapDispatchToProps(dispatch)
return {
setPlayerListVisible = function(visible)
return dispatch(SetPlayerListVisibility(visible))
end,
}
end
return RoactRodux.connect(mapStateToProps, mapDispatchToProps)(PlayerListApp)