Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using { /Fortnite.com/Devices }
- using { /Fortnite.com/UI }
- using { /UnrealEngine.com/Temporary/Diagnostics }
- using { /UnrealEngine.com/Temporary/UI }
- using { /Verse.org/Colors/NamedColors }
- using { /Verse.org/Simulation }
- Item_Counter_Device := class(creative_device):
- var Bool: logic = false
- UpdateValue<localizes>(Str:string):message="{Str}"
- #Create an array of player spawners to loop through and initialize the map.
- @editable
- SpawnerArray : []player_spawner_device = array{}
- @editable
- ButtonCounter : conditional_button_device = conditional_button_device{}
- @editable
- ToggleButton: button_device = button_device {}
- #Map with an agent object reference as the key and the HUD (a text block) as the value!
- var AgentTextMap : [agent] ?text_block = map{}
- TextBlockWidget: text_block= text_block {DefaultTextColor:= Red}
- var OverlayPanel: overlay = overlay{}
- OnBegin<override>()<suspends>:void=
- for(SpawnerDevice:SpawnerArray):
- SpawnerDevice.SpawnedEvent.Subscribe(PlayerSpawned)
- ToggleButton.InteractedWithEvent.Subscribe(ToggleViz)
- PlayerSpawned(Agent:agent):void=
- Print("A player has spawned.", ?Duration:=10.0)
- # Querying a map with its key to see if it has a value. If no value (text block), it fails and moves to else.
- if( TextBlock:text_block = AgentTextMap[Agent]?){}
- # Otherwise, begin HUD initialization and creation process.
- # This calls InitializeUI, which in turn calls both UpdateUI and MakeHUD.
- else:
- InitializeUI(Agent)
- InitializeUI(Agent:agent):void=
- set OverlayPanel = MakeHUD(Agent)
- if:
- #Cast from agent to player, so we can get the player's UI.
- InPlayer:= player[Agent]
- PlayerUI:= GetPlayerUI[InPlayer]
- then:
- PlayerUI.AddWidget(OverlayPanel)
- #Calling to an async function that repeatedly checks in with the Conditional Button.
- spawn{UpdateUI(Agent)}
- UpdateUI(Agent:agent)<suspends>:void=
- if(TextBlock := AgentTextMap[Agent]?):
- loop:
- Sleep(1.0)
- CurrentCount := ButtonCounter.GetItemCount(Agent,0)
- TextBlock.SetText(UpdateValue("Item Count: {CurrentCount}"))
- # Creates the HUD
- MakeHUD(Agent:agent):overlay=
- # Add player with UI (HUD) to the map.
- if(set AgentTextMap[Agent] = option{TextBlockWidget}){}
- MyOverlay:=overlay:
- Slots:=array:
- overlay_slot:
- Widget:=TextBlockWidget
- HorizontalAlignment :=horizontal_alignment.Center
- VerticalAlignment := vertical_alignment.Top
- Padding:=margin{Top:=100.0}
- Print("UI created for player and map updated.")
- return MyOverlay
- ToggleViz(Agent: agent): void =
- if (Bool = false):
- set Bool = true
- OverlayPanel.SetVisibility(widget_visibility.Hidden)
- else:
- set Bool = false
- OverlayPanel.SetVisibility(widget_visibility.Visible)
Add Comment
Please, Sign In to add comment