@@ -280,6 +280,44 @@ function Create.Embed( url, panel )
280
280
return table.concat ( lines , " \n " )
281
281
end
282
282
283
+ --- Returns JS code that creates gradient text
284
+ function Create .Gradient ( text , font , colorA , colorB , elementName )
285
+ elementName = elementName or " elGradient"
286
+
287
+ -- Gradient container
288
+ local lines = { Create .Element ( " span" , elementName ) }
289
+ Append ( lines , " %s.className = 'gradient-container';" , elementName )
290
+
291
+ if IsStringValid ( font ) then
292
+ Append ( lines , " %s.style.fontFamily = '%s';" , font , elementName )
293
+ end
294
+
295
+ -- Gradient background/glow
296
+ Append ( lines , Create .Element ( " span" , " elGradientGlow" , elementName ) )
297
+ Append ( lines , " elGradientGlow.className = 'gradient-bg';" )
298
+ Append ( lines , " elGradientGlow.textContent = '%s';" , text )
299
+
300
+ -- Use the combined colors for the glow effect
301
+ local h , s , l = ColorToHSL ( Color (
302
+ ( colorA .r + colorB .r ) * 0.5 ,
303
+ ( colorA .g + colorB .g ) * 0.5 ,
304
+ ( colorA .b + colorB .b ) * 0.5
305
+ ) )
306
+
307
+ local colorGlow = ColorToRGB ( HSLToColor ( h , s , l * 0.5 ) )
308
+
309
+ Append ( lines , " elGradientGlow.style.color = '%s';" , colorGlow )
310
+ Append ( lines , " elGradientGlow.style.textShadow = '0px 0px 0.2em %s';" , colorGlow )
311
+
312
+ -- Gradient foreground/text
313
+ Append ( lines , Create .Element ( " span" , " elGradientText" , elementName ) )
314
+ Append ( lines , " elGradientText.className = 'gradient-fg';" )
315
+ Append ( lines , " elGradientText.textContent = '%s';" , text )
316
+ Append ( lines , " elGradientText.style.backgroundImage = '-webkit-linear-gradient(left, %s, %s)';" , ColorToRGB ( colorA ), ColorToRGB ( colorB ) )
317
+
318
+ return table.concat ( lines , " \n " )
319
+ end
320
+
283
321
--[[
284
322
Steam avatar fetcher
285
323
]]
@@ -431,77 +469,67 @@ blocks["string"] = function( value, ctx )
431
469
end
432
470
433
471
blocks [" player" ] = function ( value , ctx )
434
- local lines = {}
435
-
436
- if not value .isBot and ctx .panel .displayAvatars then
437
- lines [# lines + 1 ] = Create .Image ( CustomChat .FetchUserAvatarURL ( value .id64 , ctx .panel ), nil , " avatar ply-" .. value .id64 )
438
- end
439
-
440
- lines [# lines + 1 ] = Create .Element ( " span" , " elPlayer" )
441
- Append ( lines , " elPlayer.textContent = '%s';" , SafeString ( value .name ) )
442
-
443
- if not value .isBot then
444
- Append ( lines , " elPlayer._playerData = '%s';" , util .TableToJSON ( {
445
- steamId = value .id ,
446
- steamId64 = value .id64
447
- } ) )
448
-
449
- Append ( lines , " elPlayer.style.cursor = 'pointer';" )
450
- Append ( lines , " elPlayer.clickableText = true;" )
451
- end
452
-
453
- if IsStringValid ( ctx .font ) then
454
- Append ( lines , " elPlayer.style.fontFamily = '%s';" , ctx .font )
455
- end
456
-
457
- local color = ctx .color
458
- local gradientColors = nil
472
+ local colors = { ctx .color }
459
473
474
+ -- Get the player name color(s)
460
475
if IsValid ( value .ply ) then
461
476
if CustomChat .USE_TAGS then
462
477
local nameColor = CustomChat .Tags :GetNameColor ( value .ply )
463
- if nameColor then color = nameColor end
478
+ if nameColor then colors [ 1 ] = nameColor end
464
479
465
480
elseif value .ply .getChatTag then
466
481
-- aTags support
467
482
local _ , _ , nameColor = value .ply :getChatTag ()
468
- if nameColor then color = nameColor end
483
+ if nameColor then colors [ 1 ] = nameColor end
469
484
end
470
485
471
486
local colorA , colorB = hook .Run ( " OverrideCustomChatPlayerColor" , value .ply )
472
487
473
488
if IsColor ( colorA ) then
489
+ colors [1 ] = colorA
490
+
474
491
if IsColor ( colorB ) then
475
- gradientColors = { colorA , colorB }
476
- else
477
- color = colorA
492
+ colors [2 ] = colorB
478
493
end
479
494
end
480
495
end
481
496
482
- if gradientColors then
483
- local colorGlow = Color (
484
- ( gradientColors [1 ].r + gradientColors [2 ].r ) * 0.5 ,
485
- ( gradientColors [1 ].g + gradientColors [2 ].g ) * 0.5 ,
486
- ( gradientColors [1 ].b + gradientColors [2 ].b ) * 0.5
487
- )
497
+ local lines = {}
488
498
489
- Append ( lines , " elPlayer.className = 'gradient';" )
490
- Append ( lines , " elPlayer.style.textShadow = '0px 0px 0.2em %s';" , ColorToRGB ( colorGlow ) )
491
- Append ( lines , " elPlayer.style.backgroundImage = '-webkit-linear-gradient(left, %s, %s)';" ,
492
- ColorToRGB ( gradientColors [1 ] ), ColorToRGB ( gradientColors [2 ] ) )
493
- end
499
+ -- Create avatar image
500
+ if not value .isBot and ctx .panel .displayAvatars then
501
+ lines [# lines + 1 ] = Create .Image ( CustomChat .FetchUserAvatarURL ( value .id64 , ctx .panel ), nil , " avatar ply-" .. value .id64 )
494
502
495
- if color then
496
- if gradientColors == nil then
497
- Append ( lines , " elPlayer.style.color = '%s';" , ColorToRGB ( color ) )
503
+ if colors [1 ] then
504
+ Append ( lines , " elImg.style['border-color'] = '%s';" , ColorToRGB ( colors [1 ] ) )
498
505
end
506
+ end
507
+
508
+ local name = SafeString ( value .name )
499
509
500
- if ctx .panel .displayAvatars then
501
- Append ( lines , " elImg.style['border-color'] = '%s';" , ColorToRGB ( color ) )
510
+ if # colors > 1 then
511
+ -- If we have more than one color, create a gradient
512
+ lines [# lines + 1 ] = Create .Gradient ( name , ctx .font , colors [1 ], colors [2 ], " elPlayer" )
513
+ else
514
+ -- Otherwise create a regular text element
515
+ lines [# lines + 1 ] = Create .Element ( " span" , " elPlayer" )
516
+ Append ( lines , " elPlayer.textContent = '%s';" , name )
517
+
518
+ if IsStringValid ( ctx .font ) then
519
+ Append ( lines , " elPlayer.style.fontFamily = '%s';" , ctx .font )
502
520
end
503
521
end
504
522
523
+ if not value .isBot then
524
+ Append ( lines , " elPlayer._playerData = '%s';" , util .TableToJSON ( {
525
+ steamId = value .id ,
526
+ steamId64 = value .id64
527
+ } ) )
528
+
529
+ Append ( lines , " elPlayer.style.cursor = 'pointer';" )
530
+ Append ( lines , " elPlayer.clickableText = true;" )
531
+ end
532
+
505
533
return table.concat ( lines , " \n " )
506
534
end
507
535
@@ -612,24 +640,10 @@ blocks["gradient"] = function( value, ctx )
612
640
local text = ChopEnds ( string.match ( value , " %([^%c]+%)" ), 2 )
613
641
614
642
components = string .Explode ( " ," , components , false )
643
+ text = SafeString ( text )
615
644
616
645
local colorA = Color ( ParseComponent ( components [1 ] ), ParseComponent ( components [2 ] ), ParseComponent ( components [3 ] ) )
617
646
local colorB = Color ( ParseComponent ( components [4 ] ), ParseComponent ( components [5 ] ), ParseComponent ( components [6 ] ) )
618
647
619
- local colorGlow = Color (
620
- ( colorA .r + colorB .r ) * 0.5 ,
621
- ( colorA .g + colorB .g ) * 0.5 ,
622
- ( colorA .b + colorB .b ) * 0.5
623
- )
624
-
625
- local code = [[ %s
626
- elText.style.backgroundImage = '-webkit-linear-gradient(left, %s, %s)';
627
- elText.style.textShadow = '0px 0px 0.2em %s';]]
628
-
629
- return code :format (
630
- Create .Text ( text , ctx .font , nil , nil , nil , " gradient" ),
631
- ColorToRGB ( colorA ),
632
- ColorToRGB ( colorB ),
633
- ColorToRGB ( colorGlow )
634
- )
648
+ return Create .Gradient ( text , ctx .font , colorA , colorB )
635
649
end
0 commit comments