using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/UI }
using { /Verse.org/Colors }
using { /UnrealEngine.com/Temporary/SpatialMath }
MakeScoreManager<constructor><public>(InPlayer : agent, InScoreManagerDevice : score_manager_device) := score_manager:
MaybePlayer := option{InPlayer}
MaybePlayerUI := option{GetPlayerUI[player[InPlayer]]}
# A Verse-authored creative device that can be placed in a level
score_manager := class(creative_device):
MaybePlayer<internal> : ?agent = false
MaybePlayerUI<internal> :?player_ui = false
ScoreManagerDevice<internal> : score_manager_device = score_manager_device{}
var TotalGameScore<private> : int = 0
var Canvas<internal> : canvas = canvas{}
TotalGameScoreWidget<internal> : text_block = text_block{DefaultTextColor := NamedColors.White}
TotalGameScoreText<private><localizes>(InPoints : int) : message = "Total Points: {InPoints}"
block:
set Canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.0, Y := 0.25}, Maximum := vector2{X := 0.0, Y := 0.25} }
Offsets := margin{Top := 0.0, Left := 25.0, Right := 0.0, Bottom := 0.0}
Alignment := vector2{X := 0.0, Y := 0.0}
SizeToContent := true
Widget := stack_box:
Orientation := orientation.Vertical
Slots := array:
stack_box_slot:
HorizontalAlignment := horizontal_alignment.Left
Widget := TotalGameScoreWidget
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Print("ScoreManager added")
AddScoreManagerToUI<public>() : void =
if (PlayerUI := MaybePlayerUI?):
PlayerUI.AddWidget(Canvas)
UpdateUI()
UpdateUI<private>() : void =
if (PlayerUI := MaybePlayerUI?):
TotalGameScoreWidget.SetText(TotalGameScoreText(TotalGameScore))
UpdateScore<public>(Points: int):void=
set TotalGameScore += Points
UpdateUI()
AwardScore<public>() : void =
ScoreManagerDevice.SetScoreAward(TotalGameScore)
if (AwardedPlayer := MaybePlayer?):
ScoreManagerDevice.Activate(AwardedPlayer)