<Page xmlns:local="clr-namespace:ForzaUI"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      x:Class="ForzaUI.A_PreRaceTeamRevealPanel"
      mc:Ignorable="d"
      x:Name="Page"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Page.Resources>
        <Size x:Key="A_Size_PostRace_GamerPicSizeParams">424,424</Size>

        <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_PostRace_Gamerpic"
                                           Saturation="0.5" />

        <ImageBrush x:Key="A_Brush_GamerpicOpacity"
                    ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Gamerpic_Mask.png" />

        <Style x:Key="A_Style_FZTextBlock_PostRace_TotalText"
               BasedOn="{StaticResource A_Style_FZTextBlock_PostRace_TotalText}"
               TargetType="local:FZTextBlock">
            <Setter Property="CapHeight"
                    Value="57" />
            <Setter Property="Text"
                    Value="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
        </Style>

        <Style x:Key="A_Style_Control_PostRace_TotalLabelBlock"
               TargetType="Control"
               BasedOn="{StaticResource A_Style_FrameworkElement_PostRace_TotalLabelBlock}">
            <Setter Property="Tag"
                    Value="" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Left" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <local:FZTextBlock Style="{DynamicResource A_Style_FZTextBlock_PostRace_TotalText}"
                                           CapHeight="43"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="local:ZPanel.Transform">
                <Setter.Value>
                    <Transform3DGroup>
                        <RotateTransform3D />
                        <TranslateTransform3D OffsetZ="0" />
                    </Transform3DGroup>
                </Setter.Value>
            </Setter>
        </Style>

        <System:Double x:Key="A_Double_TeamNameLabelCapHeight">134</System:Double>

        <Style x:Key="A_Style_Control_PostRace_TeamNameBlock"
               TargetType="Control"
               BasedOn="{StaticResource A_Style_Control_PostRace_TotalLabelBlock}">
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Viewbox Stretch="Uniform"
                                 HorizontalAlignment="Left"
                                 StretchDirection="DownOnly">
                            <Grid>
                                <StackPanel Orientation="Horizontal">
                                    <!--The additive presets in here only work when you null the motionblur effect on the control root.  This is used by impact bloom on the total values-->
                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PostRace_TotalText}"
                                                       Preset="{StaticResource A_FZMaterialPresetAdditive}"
                                                       CapHeight="{DynamicResource A_Double_TeamNameLabelCapHeight}"
                                                       x:Name="TickerValue"
                                                       Text="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"
                                                       VerticalAlignment="Center" />

                                </StackPanel>
                            </Grid>
                        </Viewbox>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <local:OffsetKeyTime x:Key="A_KeyTime_TeamScore_Begin"
                             KeyTime="0:0:0" />

        <local:OffsetKeyTime x:Key="A_KeyTime_TeamScore_EventWinner_Begin"
                             KeyTime="{StaticResource A_KeyTime_TeamScore_Begin}" />
        <local:OffsetKeyTime x:Key="A_KeyTime_TeamScore_EventWinner_Gamerpic_In"
                             KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                             Offset="0:0:0.3" />
        <local:OffsetKeyTime x:Key="A_KeyTime_TeamScore_EventWinner_End"
                             KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                             Offset="0:0:4" />

        <local:UIStoryboard x:Key="A_Storyboard_GamerpicIn"
                            DurationOverride="{StaticResource A_Duration_Transition_ElementIn}">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(local:ZPanel.Transform).(Transform3DGroup.Children)[1].(TranslateTransform3D.OffsetX)"
                                           Storyboard.TargetName="{x:Null}">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="-1000" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.43"
                                      Value="0"
                                      EasingFunction="{local:ExponentialEasing EasingMode=EaseIn}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                           Storyboard.TargetName="{x:Null}">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                        Value="0" />
                <LinearDoubleKeyFrame KeyTime="0:0:0.129"
                                      Value="1" />
            </DoubleAnimationUsingKeyFrames>
        </local:UIStoryboard>

        <local:UIStoryboard x:Key="A_Storyboard_PostRace_TeamScore">
            <local:UIStoryboard.TriggerAnimation>
                <local:BeginUIStoryboard local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Gamerpic_In}"
                                         Storyboard.TargetName="Gamerpic"
                                         Storyboard="{StaticResource A_Storyboard_GamerpicIn}" />
                <local:BeginUIStoryboard local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                                         Storyboard.TargetName="TotalLabel"
                                         Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromLeft_Slide}" />
                <local:BeginUIStoryboard local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                                         Storyboard.TargetName="TotalValue"
                                         Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromLeft}" />
                <local:AudioEventFireTrigger local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                                             AudioEvent="/Master/UI/PostRace/HZ2_SFX_HUD_PostRace_CashRewardsTotalOn_01" />
                <local:BeginUIStoryboard local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_Begin}"
                                         Storyboard.TargetName="BalanceValue"
                                         Storyboard="{StaticResource A_Storyboard_PostRace_WhooshInFromRight_Slide}" />
                <local:RaiseFzEvent EventName="dummy"
                                    local:TriggerAnimation.KeyTime="{StaticResource A_KeyTime_TeamScore_EventWinner_End}" />
            </local:UIStoryboard.TriggerAnimation>
        </local:UIStoryboard>

        <Color x:Key="A_Colour_Red1">#e9002d</Color>
        <Color x:Key="A_Colour_Red2">#df2f90</Color>
        <Color x:Key="A_Colour_Blue1">#1aaade</Color>
        <Color x:Key="A_Colour_Blue2">#0864cb</Color>
        <System:Int32 x:Key="A_Team0">0</System:Int32>
        <System:Int32 x:Key="A_Team1">1</System:Int32>

        <local:MappingConverter x:Key="A_Converter_TeamColour1">
            <local:MappingConverterEntry Key="{StaticResource A_Team0}"
                                         Value="{StaticResource A_Colour_Red1}" />
            <local:MappingConverterEntry Key="{StaticResource A_Team1}"
                                         Value="{StaticResource A_Colour_Blue1}" />
        </local:MappingConverter>
        <local:MappingConverter x:Key="A_Converter_TeamColour2">
            <local:MappingConverterEntry Key="{StaticResource A_Team0}"
                                         Value="{StaticResource A_Colour_Red2}" />
            <local:MappingConverterEntry Key="{StaticResource A_Team1}"
                                         Value="{StaticResource A_Colour_Blue2}" />
        </local:MappingConverter>
    </Page.Resources>
    <Grid Height="540"
          Width="1920">

        <local:FZMaterial>
            <local:FZMaterial.Preset>
                <local:FZMaterialPresetRoundtangle GradientAngle="90"
                                                   GradientColorA="{Binding TeamID, Converter={StaticResource A_Converter_TeamColour1}}"
                                                   GradientColorB="{Binding TeamID, Converter={StaticResource A_Converter_TeamColour2}}" />
            </local:FZMaterial.Preset>
        </local:FZMaterial>


        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRace_Hatching}" />

        <!-- Content -->
        <Grid Width="878"
              Height="540"
              Margin="80,0,0,0"
              HorizontalAlignment="Left"
              x:Name="Gamerpic"
              Style="{StaticResource A_Style_FrameworkElement_PostRace_SmallAnimatedBlock}"
              local:UIPageTransitionManager.TransitionIndex="0">
            <Grid.Resources>
                <DataTemplate x:Key="A_Template_TeamGamerPics">
                    <Grid>
                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_PostRace_Gamerpic}"
                                          Height="270.25"
                                          Width="270"
                                          ClipToBounds="True"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Center"
                                          x:Name="Pic"
                                          Margin="0,0,-0.5,-0.5"
                                          GreedyMeasure="True"
                                          ImageSource="{Binding Converter={StaticResource A_GamerPicOrTeamProfileConverter}, ConverterParameter={StaticResource A_Size_PostRace_GamerPicSizeParams}}"
                                          Stretch="UniformToFill" />
                    </Grid>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding ItemsSource.Count, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
                                     Value="1">
                            <Setter TargetName="Pic"
                                    Property="Height"
                                    Value="878" />
                            <Setter TargetName="Pic"
                                    Property="Width"
                                    Value="878" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>

                <ItemsPanelTemplate x:Key="A_Template_GamerPicsPanel">
                    <WrapPanel IsItemsHost="True"
                               Orientation="Vertical" />
                </ItemsPanelTemplate>

                <Style TargetType="ItemsControl"
                       x:Key="A_Style_GamerPics">
                    <Setter Property="ItemTemplate"
                            Value="{StaticResource A_Template_TeamGamerPics}" />
                    <Setter Property="ItemsPanel"
                            Value="{StaticResource A_Template_GamerPicsPanel}" />
                    <Setter Property="Tag">
                        <Setter.Value>
                            <TranslateTransform X="0" />
                        </Setter.Value>
                    </Setter>
                    <Setter Property="UIElement.RenderTransform"
                            Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />

                    <Style.Triggers>
                        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                            <local:BeginUIStoryboard>
                                <local:UIStoryboard RepeatBehavior="Forever">
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Tag).(TranslateTransform.X)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0"
                                                                Value="0" />
                                        <EasingDoubleKeyFrame KeyTime="0:0:6"
                                                              Value="-540"
                                                              EasingFunction="{local:LinearEasing}" />
                                    </DoubleAnimationUsingKeyFrames>
                                </local:UIStoryboard>
                            </local:BeginUIStoryboard>
                        </EventTrigger>
                        <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}"
                                     Value="1">
                            <Setter Property="UIElement.RenderTransform">
                                <Setter.Value>
                                    <!-- This unbinds the render transform from Tag, stopping it from animating when only 1 player -->
                                    <TranslateTransform X="0" />
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Resources>
            <local:FZMaterial OpacityMask="{StaticResource A_Brush_GamerpicOpacity}">
                <Grid>
                    <Grid Height="540"
                          Width="878"
                          ClipToBounds="True">
                        <ItemsControl Style="{StaticResource A_Style_GamerPics}"
                                      ItemsSource="{Binding LoopTeamProfiles}">
                        </ItemsControl>
                    </Grid>
                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/PostRace/Gamerpic_Vignette.png" />
                </Grid>
            </local:FZMaterial>
        </Grid>

        <Decorator HorizontalAlignment="Right"
                   VerticalAlignment="Center"
                   Margin="0,50,0,0"
                   Width="1000">
            <local:ZPanel.Transform>
                <local:ZRotation Angle="-6" />
            </local:ZPanel.Transform>
            <StackPanel Orientation="Vertical"
                        MaxWidth="900"
                        HorizontalAlignment="Center"
                        RenderTransform="{StaticResource A_Transform_Italic}">
                <Control x:Name="TotalLabel"
                         Margin="50,0,0,0"
                         Style="{StaticResource A_Style_Control_PostRace_TotalLabelBlock}"
                         MinHeight="43"
                         Tag="{Binding TeamHeader, Converter={StaticResource A_StringToUpper}}">
                    <Control.Resources>

                        <Style x:Key="A_Style_FZTextBlock_PostRace_TotalText"
                               TargetType="local:FZTextBlock"
                               BasedOn="{StaticResource A_Style_FZTextBlock_PostRace_TotalText}">
                            <Setter Property="FontFamily"
                                    Value="Horizon_B" />
                        </Style>

                    </Control.Resources>
                </Control>

                <Decorator Height="22" />

                <Control x:Name="TotalValue"
                         Style="{StaticResource A_Style_Control_PostRace_TeamNameBlock}"
                         Tag="{Binding TeamName, Converter={StaticResource A_StringToUpper}}" />

                <Decorator Height="22" />

                <Control x:Name="BalanceValue"
                         Margin="0,0,40,0"
                         HorizontalAlignment="Right"
                         Style="{StaticResource A_Style_Control_PostRace_TotalLabelBlock}">
                    <Control.Resources>
                        <Style TargetType="local:FZRun"
                               x:Key="A_Style_Rating_Bold">
                            <Setter Property="FontFamily"
                                    Value="Horizon_A" />
                        </Style>
                        <Style x:Key="A_Style_FZTextBlock_PostRace_TotalText"
                               BasedOn="{StaticResource A_Style_FZTextBlock_PostRace_TotalText}"
                               TargetType="local:FZTextBlock">
                            <Setter Property="CapHeight"
                                    Value="57" />
                            <Setter Property="FontFamily"
                                    Value="Horizon_B" />
                            <Setter Property="Text"
                                    Value="{x:Null}" />

                            <Setter Property="local:TextBlockInlineMarkup.Markup"
                                    Value="{Binding TeamRating}" />
                            <Setter Property="local:TextBlockInlineMarkup.ResourceBaseName"
                                    Value="A_Style_Rating_" />
                        </Style>
                    </Control.Resources>
                </Control>
            </StackPanel>
        </Decorator>

        <Decorator local:ZPanel.TransformOrigin="0.5,0.5">
            <local:ZPanel.Transform>
                <local:ZRotation Angle="-6" />
            </local:ZPanel.Transform>

            <StackPanel VerticalAlignment="Center"
                        HorizontalAlignment="Center">
                <Decorator RenderTransform="{StaticResource A_Transform_Italic}">
                    <Control x:Name="TeamScore_Team"
                             Style="{StaticResource A_Style_Control_PostRace_TotalLabelBlock}"
                             MinHeight="43"
                             HorizontalContentAlignment="Center"
                             Tag="{local:Loc InGame.IDS_PostRace_TeamScoreLine1}">
                        <Control.Resources>

                            <Style x:Key="A_Style_FZTextBlock_PostRace_TotalText"
                                   TargetType="local:FZTextBlock"
                                   BasedOn="{StaticResource A_Style_FZTextBlock_PostRace_TotalText}">
                                <Setter Property="FontFamily"
                                        Value="Horizon_B" />
                            </Style>

                        </Control.Resources>
                    </Control>
                </Decorator>

                <Decorator Height="8" />

                <Decorator RenderTransform="{StaticResource A_Transform_Italic}">
                    <Control x:Name="TeamScore_Score"
                             Margin="0,0,40,0"
                             HorizontalContentAlignment="Center"
                             Style="{StaticResource A_Style_Control_PostRace_TotalLabelBlock}"
                             Tag="{local:Loc InGame.IDS_PostRace_TeamScoreLine2}" />
                </Decorator>
            </StackPanel>

        </Decorator>

        <local:FZMaterial Color="#000000"
                          Opacity="0.3"
                          Height="27"
                          VerticalAlignment="Bottom" />
        <local:FZMaterial Color="#000000"
                          Opacity="0.3"
                          Height="27"
                          VerticalAlignment="Top" />

        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_PostRacePanel_Vignette}" />

        <local:EventFire x:Name="EventFire" />

    </Grid>
    <Page.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <local:BeginUIStoryboard Storyboard="{StaticResource A_Storyboard_PostRace_TeamScore}" />
        </EventTrigger>
    </Page.Triggers>
</Page>
