How do I Show a UI Widget and Update it to Every Player in game

I found it by myself, you have to make an UI class then a Map for that UI Class

var UIManagerMap : [player]UIManager = map {}

UIManager := class():

Player: player
Agent: agent

var Canvas<internal> : canvas = canvas{}

block:
    set Canvas = canvas:
        Slots := array:
            canvas_slot:
                Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.1}, Maximum := vector2{X := 0.5, Y := 0.1}}
                Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
                Alignment := vector2{X := 0.5, Y := 0.5}
                Widget := overlay:
                    Slots := array:
                        overlay_slot:
                            Widget := color_block:
                                DefaultColor := NamedColors.Blue
                                DefaultOpacity := 0.7
                                DefaultDesiredSize := vector2{X := 256.0, Y := 128.0}
                        overlay_slot:
                            Widget := stack_box:
                                Orientation := orientation.Vertical
                                Slots := array:
                                    stack_box_slot:
                                        Widget := JumpTextWidget
                                    stack_box_slot:
                                        Widget := DiamondTextWidget


JumpText<private><localizes>(JText : string) : message = "Gas: {JText}"
DiamondText<private><localizes>(DText : string) : message = "Diamonds: {DText}"   
                                              

JumpTextWidget:text_block = text_block{
    DefaultShadowColor := MakeColorFromHex("#000000")
    DefaultShadowOffset := option{vector2{X:= 0.5, Y:= 0.5}} 
    DefaultTextColor := MakeColorFromHex("#FFFFFF")
}   

DiamondTextWidget:text_block = text_block{
    DefaultShadowColor := MakeColorFromHex("#000000")
    DefaultShadowOffset := option{vector2{X:= 0.5, Y:= 0.5}} 
    DefaultTextColor := MakeColorFromHex("#00FFFF")
} 


UpdateUI(Jump: int, Diamond: int): void=
        #update ui
        JumpTextWidget.SetText(JumpText("{Jump}"))
        DiamondTextWidget.SetText(DiamondText("{Diamond}"))

        #set shadow to text
        JumpTextWidget.SetShadowOpacity(1.0)
        DiamondTextWidget.SetShadowOpacity(1.0)

Then you need to show each UI class to each player

if(MyUIMap := UIManagerMap[Player], PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(MyUIMap.Canvas)
Print(“ADDED CANVAS”)

3 Likes