Verse UI - How to keep widgets on first players screen without second player removing them?

Here’s my current fix that @Twin01 helped me with. It appears to work. :slight_smile: I created a class called dialog_widget, and created a class object per player which is stored in a map using player as the key. Thanks so much, Twin!

I think there are probably more ways than one to accomplish multiplayer UI though. Has anyone else handled this differently? Does this seem like the best option?

using { /Fortnite.com/Devices }                 
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Simulation }

ui_dialog_simple1 := class(creative_device):

    @editable 
    ButtonUIAdd : button_device = button_device {} 

    @editable 
    Title : string = "Title"

    @editable
    TextRow1: []string = array:
        "Row 1 Part 1"
        "Row 1 Part 2"
        "Row 1 Part 3"
    
    var DisplayMap: [player]?dialog_widget = map{}

    OnBegin<override>()<suspends>:void=
        Print("UI Popup NextExit Device Began")
        ButtonUIAdd.InteractedWithEvent.Subscribe(HandleButtonUIAddInteraction)

    HandleButtonUIAddInteraction(Agent:agent):void=
        Print("Button Device Interacted With")
        if (Player := player[Agent]):
            DialogWidgetInstance := dialog_widget:
                VerseDevice := Self
                InstancePlayer := option{Player} 
                DialogTitle := Title 
                DialogRow1 := TextRow1 
            if (set DisplayMap[Player] = option{DialogWidgetInstance}):
                DialogWidgetInstance.Init()
                DialogWidgetInstance.CreateMyUI()
                DialogWidgetInstance.AddCanvas(Agent)
                DialogWidgetInstance.UpdateText(DialogWidgetInstance.currentTextPart)
            else:
                Print("Error")

    #===== Dialog Widget Class ==========================================================

dialog_widget := class<concrete>():

    StringToMessage<localizes>(value:string) : message = "{value}"

    var VerseDevice : ui_dialog_simple1 = ui_dialog_simple1{}
    InstancePlayer: ?player = false ###

    WidgetRow1:text_block = text_block {}
    WidgetUIButton:button_regular = button_regular {} 

    var MaybeMyUIPerPlayer : [player]?canvas = map{}
    var currentTextPart : int = 0 

    DialogTitle : string = ""
    DialogRow1: []string = array{}

    Init():void= 
        WidgetUIButton.OnClick().Subscribe(HandleUIButtonClick)

    HandleUIButtonClick(Message: widget_message):void= 
        Print("UI Button Clicked")
        if (currentTextPart = DialogRow1.Length):
            RemoveCanvas(Message)
            set currentTextPart = 0
  
        else:  
            if (currentTextPart <= DialogRow1.Length - 1):
                if (currentTextPart = DialogRow1.Length - 1):
                    UpdateText(currentTextPart)
                else:
                    UpdateText(currentTextPart)   
                    
    UpdateText(Index:int):void= 
        Print("Update Text")
        if(currentStr := DialogRow1[Index]):
            WidgetRow1.SetText(StringToMessage(currentStr))
        set currentTextPart += 1 

    AddCanvas(Agent:agent):void=
        Print("Add Canvas")
        if (InPlayer := player[Agent], PlayerUI := GetPlayerUI[InPlayer]):
            if (MyUI := MaybeMyUIPerPlayer[InPlayer]?):
                PlayerUI.RemoveWidget(MyUI)
                if (set MaybeMyUIPerPlayer[InPlayer] = false) {}
            else:
                NewUI := CreateMyUI()
                PlayerUI.AddWidget(NewUI, player_ui_slot{InputMode := ui_input_mode.All})
                if (set MaybeMyUIPerPlayer[InPlayer] = option{NewUI}) {}

    CreateMyUI():canvas=
        Print("Create UI")
        Print("subscribe")
        WidgetTitle:text_block = text_block:    
            DefaultText := {StringToMessage(DialogTitle)}

        NewCanvas := canvas:
            Slots := array:
                canvas_slot:
                    Anchors := anchors:
                        Minimum := vector2{X := 0.5, Y := 0.25}
                        Maximum := vector2{X := 0.5, Y := 0.25}
                    Alignment := vector2{X := 0.5, Y := 0.5}
                    SizeToContent := true
                    Widget := stack_box:
                        Orientation := orientation.Vertical
                        Slots := array:
                            stack_box_slot:
                                Widget := WidgetTitle
                            stack_box_slot: 
                                Widget := WidgetRow1 
                            stack_box_slot:
                                Widget := WidgetUIButton

        return NewCanvas
        
    RemoveCanvas(Message: widget_message):void=
        if (PlayerUI := GetPlayerUI[Message.Player], MyUI := MaybeMyUIPerPlayer[Message.Player]?, SelectedButton := text_button_base[Message.Source]):
            Print("Remove Canvas")
            PlayerUI.RemoveWidget(MyUI)
            if (set MaybeMyUIPerPlayer[Message.Player] = false) {}
3 Likes