AlinaEVE
Topic Author
Posts: 5
Joined: 06 Jul 2023, 08:49

NotifyArrayChanged in UE Question

08 Sep 2023, 08:27

Hello, I'd like to ask a question about using NotifyArrayChanged in UE.

I have an Array (PlayBulletBars) as the itemsSource of an ItemsControl. PlayBulletBars is an array of UBulletVisible class.The class UBulletVisible has a FString property named BulletVisible.

And, within the ContentControl that is bound in the ItemTemplate, I bind the Visibility of an image to a property "BulletVisible". Additionally, I added a behavior to this ContentControl that plays an animation when Visibility == {x:Static Visibility.Visible}.

When I modify a specific UBulletVisible in PlayBulletBars within the ViewModel code, I call Noesis::NotifyArrayChanged(this, "PlayBulletBars").

However, the actual behavior is that every time I modify the Visibility of one item(Gain Bullet), all bullet items play the animation.

ItemsControl code
	<ItemsControl x:Name="bar" ItemsSource="{Binding PlayBulletBars}">
		<ItemsControl.ItemsPanel>
			<ItemsPanelTemplate>
				<StackPanel Orientation="Horizontal"/>
			</ItemsPanelTemplate>
		</ItemsControl.ItemsPanel>
		<ItemsControl.ItemTemplate>
			<DataTemplate>
				<ContentControl Content="{Binding}" Style="{StaticResource Style.BulletBarSlot}">
				</ContentControl>
			</DataTemplate>
		</ItemsControl.ItemTemplate>
		
	</ItemsControl>
	
ContentControl Code
	<ControlTemplate x:Key="BulletBarSlot" TargetType="{x:Type ContentControl}">
		<ControlTemplate.Resources>
			<Storyboard x:Key="GainBulletStoryboard">
				<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="bullet">
					<EasingDoubleKeyFrame KeyTime="0" Value="-120">
						<EasingDoubleKeyFrame.EasingFunction>
							<BackEase EasingMode="EaseOut"/>
						</EasingDoubleKeyFrame.EasingFunction>
					</EasingDoubleKeyFrame>
					<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
						<EasingDoubleKeyFrame.EasingFunction>
							<BackEase EasingMode="EaseOut"/>
						</EasingDoubleKeyFrame.EasingFunction>
					</EasingDoubleKeyFrame>
				</DoubleAnimationUsingKeyFrames>
			</Storyboard>
		</ControlTemplate.Resources>
		<Grid Width="58" Height="103">
			<Image x:Name="bg" HorizontalAlignment="Center" Source="{StaticResource Game/CombatHUD/T_UI_Bullet_Bg}"/>
			<Image x:Name="bullet" HorizontalAlignment="Center" Source="{StaticResource Game/CombatHUD/T_UI_Bullet}" Visibility="{Binding BulletVisible}" RenderTransformOrigin="0.5,0.5">
				<b:Interaction.Triggers>
					<b:DataTrigger Binding="{Binding Visibility, ElementName=bullet}" Value="{x:Static Visibility.Visible}">
						<b:ControlStoryboardAction Storyboard="{StaticResource GainBulletStoryboard}"/>
					</b:DataTrigger>
				</b:Interaction.Triggers>
				<Image.RenderTransform>
					<TransformGroup>
						<ScaleTransform/>
						<SkewTransform/>
						<RotateTransform/>
						<TranslateTransform/>
					</TransformGroup>
				</Image.RenderTransform>
			</Image>
		</Grid>
	</ControlTemplate>
	<Style x:Key="Style.BulletBarSlot" TargetType="{x:Type ContentControl}">
		<Setter Property="Template" Value="{StaticResource BulletBarSlot}"/>
	</Style>
ViewModel Code(I use AngleScript)
UFUNCTION()
	void DebugGainBulletBar()
	{
		for (int Index = 0, Num = PlayBulletBars.Num(); Index < Num; ++Index)
		{
			UBulletVisible CurBar = PlayBulletBars[Index];
			if (CurBar.BulletVisible != "Visible"){
				CurBar.BulletVisible = "Visible";
				break;
			}
		}
		Noesis::NotifyArrayChanged(this, n"PlayBulletBars");

	}

Image
When Click GainBullet .
Image

So, is it because NotifyArray always updates all items every time? Is there a better way to achieve playing animation only for the item that has its status changed?
 
User avatar
hcpizzi
Site Admin
Posts: 321
Joined: 09 Feb 2012, 12:40

Re: NotifyArrayChanged in UE Question

10 Sep 2023, 15:58

Hi!

Instead of notifying the array has changed, could you try notifying the element of the object has changed like this:

Noesis::NotifyChanged(CurBar, “BulletVisible”);
 
AlinaEVE
Topic Author
Posts: 5
Joined: 06 Jul 2023, 08:49

Re: NotifyArrayChanged in UE Question

11 Sep 2023, 04:02

Thank you!

Who is online

Users browsing this forum: No registered users and 5 guests