示例#1
0
        private Boolean ClickAction(Theme.ButtonActions action, string[] objects, bool noLoop)
        {
            logger.Trace("ClickAction: Action {0} objects {1}", action, String.Join(" , ", objects));
            bool retVal = false;
            for (int j = 0; j < objects.Length; j++)
            {
                string[] split = objects[j].Split('-');
                switch (action)
                {
                    case Theme.ButtonActions.camera:
                        int camera = -1;
                        foreach (CameraGroup cam in SharedData.Camera.Groups)
                        {
                            if (cam.Name.ToLower() == objects[j].ToLower())
                                camera = cam.Id;
                        }
                        if (camera >= 0)
                        {
                            int driver = Controls.padCarNum(SharedData.Sessions.CurrentSession.FollowedDriver.Driver.NumberPlate);
                            simulationAPI.SwitchCamera(driver, camera);

                            iRTVOConnection.BroadcastMessage("SWITCH", driver, camera);

                            SharedData.updateControls = true;
                        }
                        break;
                    case Theme.ButtonActions.replay:
                        int replay = -1;
                        bool result = Int32.TryParse(objects[j], out replay);
                        if (result)
                        {
                            if (replay == 0) // live
                            {
                                Thread.Sleep(16);
                                simulationAPI.ReplaySearch(ReplaySearchModeTypes.ToEnd, 0);
                                simulationAPI.Play();
                                SharedData.updateControls = true;
                                SharedData.triggers.Push(TriggerTypes.live);

                                iRTVOConnection.BroadcastMessage("LIVE");
                            }
                            else // replay
                            {
                                Thread.Sleep(16);
                                int numFrames = (int)((Int32)simulationAPI.GetData("ReplayFrameNum") - (replay * 60));
                                simulationAPI.ReplaySetPlayPosition(ReplayPositionModeTypes.Begin, numFrames);
                                simulationAPI.Play();
                                SharedData.triggers.Push(TriggerTypes.replay);

                                iRTVOConnection.BroadcastMessage("REWIND", numFrames, 1);

                            }
                        }
                        break;
                    case Theme.ButtonActions.playspeed:
                        Int32 playspeed = Int32.Parse(objects[j]);
                        Int32 slowmo = 0;
                        if (playspeed < 0)
                        {
                            playspeed = Math.Abs(playspeed) - 1;
                            slowmo = 1;
                        }

                        Thread.Sleep(16);
                        simulationAPI.ReplaySetPlaySpeed(playspeed, slowmo);
                        break;
                    default:
                        switch (split[0])
                        {
                            case "Overlay": // overlays
                                for (int k = 0; k < SharedData.theme.objects.Length; k++)
                                {
                                    if (SharedData.theme.objects[k].name == split[1])
                                    {
                                        if (noLoop)
                                        {
                                            SharedData.theme.objects[k].visible = setObjectVisibility(SharedData.theme.objects[k].visible, action);
                                            return false;
                                        }
                                        Boolean isStandings = SharedData.theme.objects[k].dataset == DataSets.standing || SharedData.theme.objects[k].dataset == DataSets.points;

                                        if ((action == Theme.ButtonActions.show) || (action == Theme.ButtonActions.toggle && SharedData.theme.objects[k].visible == false))
                                        {
                                            if (isStandings)
                                                SharedData.theme.objects[k].page++;
                                            else
                                                SharedData.theme.objects[k].page = 0;
                                        }

                                        if (SharedData.lastPage[k] == true && isStandings && action == Theme.ButtonActions.show)
                                        {
                                            //SharedData.theme.objects[k].visible = setObjectVisibility(SharedData.theme.objects[k].visible, Theme.ButtonActions.hide);
                                            ClickAction(Theme.ButtonActions.hide, objects, true);
                                            action = Theme.ButtonActions.hide;
                                            SharedData.theme.objects[k].page = -1;
                                            SharedData.lastPage[k] = false;

                                            retVal = true;
                                        }
                                        else
                                        {

                                            SharedData.theme.objects[k].visible = setObjectVisibility(SharedData.theme.objects[k].visible, action);
                                            if ((action == Theme.ButtonActions.toggle) && (SharedData.theme.objects[k].visible == false))
                                                retVal = true;
                                        }
                                        logger.Trace("Overlay-{0} vis is now {1} act {2}", split[1], SharedData.theme.objects[k].visible, action);
                                    }
                                }
                                break;
                            case "Image": // images
                                for (int k = 0; k < SharedData.theme.images.Length; k++)
                                {
                                    if (SharedData.theme.images[k].name == split[1])
                                    {
                                        SharedData.theme.images[k].visible = setObjectVisibility(SharedData.theme.images[k].visible, action);
                                        logger.Trace("Image-{0} vis is now {1} act {2}", split[1], SharedData.theme.images[k].visible, action);
                                    }
                                }
                                break;
                            case "Ticker": // tickers
                                for (int k = 0; k < SharedData.theme.tickers.Length; k++)
                                {
                                    if (SharedData.theme.tickers[k].name == split[1])
                                    {
                                        SharedData.theme.tickers[k].visible = setObjectVisibility(SharedData.theme.tickers[k].visible, action);
                                    }
                                }
                                break;
                            case "Video": // video
                                for (int k = 0; k < SharedData.theme.videos.Length; k++)
                                {
                                    if (SharedData.theme.videos[k].name == split[1])
                                    {
                                        SharedData.theme.videos[k].visible = setObjectVisibility(SharedData.theme.videos[k].visible, action);
                                    }
                                }
                                break;
                            case "Sound": // sound
                                for (int k = 0; k < SharedData.theme.sounds.Length; k++)
                                {
                                    if (SharedData.theme.sounds[k].name == split[1])
                                    {
                                        SharedData.theme.sounds[k].playing = setObjectVisibility(SharedData.theme.sounds[k].playing, action);
                                    }
                                }
                                break;
                            case "Trigger": // triggers
                                switch (split[1])
                                {
                                    case "flags":
                                        if (SharedData.Sessions.CurrentSession.Flag == SessionFlags.white)
                                            SharedData.triggers.Push(TriggerTypes.flagWhite);
                                        else if (SharedData.Sessions.CurrentSession.Flag == SessionFlags.checkered)
                                            SharedData.triggers.Push(TriggerTypes.flagCheckered);
                                        else if (SharedData.Sessions.CurrentSession.Flag == SessionFlags.yellow)
                                            SharedData.triggers.Push(TriggerTypes.flagYellow);
                                        else
                                            SharedData.triggers.Push(TriggerTypes.flagGreen);
                                        break;
                                    case "lights":
                                        if (SharedData.Sessions.CurrentSession.StartLight == SessionStartLights.ready)
                                            SharedData.triggers.Push(TriggerTypes.lightsReady);
                                        else if (SharedData.Sessions.CurrentSession.StartLight == SessionStartLights.set)
                                            SharedData.triggers.Push(TriggerTypes.lightsSet);
                                        else if (SharedData.Sessions.CurrentSession.StartLight == SessionStartLights.go)
                                            SharedData.triggers.Push(TriggerTypes.lightsGo);
                                        else
                                            SharedData.triggers.Push(TriggerTypes.lightsOff);
                                        break;
                                    default:
                                        break;
                                }
                                break;
                            case "Click":
                                {
                                    for (int i = 0; i < SharedData.theme.buttons.Length; i++)
                                    {
                                        if (SharedData.theme.buttons[i].name == split[1])
                                        {
                                            Button dummyButton = new Button();
                                            dummyButton.Name = "customButton" + i.ToString();
                                            dummyButton.Content = "";
                                            this.HandleClick(dummyButton, new RoutedEventArgs());
                                            break;
                                        }
                                    }
                                    break;
                                }
                            case "Push":
                                {
                                    TriggerTypes x = (TriggerTypes)Enum.Parse(typeof(TriggerTypes), split[1], true);
                                    SharedData.triggers.Push(x);

                                    break;
                                }
                            default: // script or not
                                if (SharedData.scripting.Scripts.Contains(split[0]))
                                {
                                    SharedData.scripting.PressButton(split[0], split[1]);
                                }
                                break;
                        }
                        break;
                }
            }
            return retVal;
        }
示例#2
0
 private Boolean setObjectVisibility(Boolean currentValue, Theme.ButtonActions action)
 {
     if (action == Theme.ButtonActions.hide)
         return false;
     else if (action == Theme.ButtonActions.show)
         return true;
     else if (action == Theme.ButtonActions.toggle)
     {
         if (currentValue == true)
             return false;
         else
             return true;
     }
     else
         return true;
 }
示例#3
0
 private Boolean ClickAction(Theme.ButtonActions action, string[] objects)
 {
     return ClickAction(action, objects, false);
 }
示例#4
0
        private Label DrawLabel(Theme.LabelProperties prop)
        {
            Label label = new Label();
            label.Width = prop.width;
            label.Height = prop.height;
            label.Foreground = prop.fontColor;
            label.Margin = new Thickness(prop.left, prop.top, 0, 0);
            label.FontSize = prop.fontSize;
            label.FontFamily = prop.font;
            label.VerticalContentAlignment = System.Windows.VerticalAlignment.Top;

            label.FontWeight = prop.fontBold;
            label.FontStyle = prop.fontItalic;

            label.HorizontalContentAlignment = prop.textAlign;

            label.Padding = new Thickness(0);

            //Canvas.SetZIndex(label, 100);

            if (SharedData.settings.OverlayShowBorders)
            {
                label.BorderBrush = System.Windows.Media.Brushes.Yellow;
                label.BorderThickness = new Thickness(1);
                //label.Margin = new Thickness(label.Margin.Left - 1, label.Margin.Top - 1, 0, 0);
                //label.Padding = new Thickness(-1);
            }

            if (prop.backgroundImage != null)
            {
                try
                {
                    string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.backgroundImage;
                    if (File.Exists(filename))
                    {
                        Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                        label.Background = bg;
                    }
                    else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultBackgroundImage))
                    {
                        Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultBackgroundImage)));
                        label.Background = bg;
                    }
                    else if (prop.dynamic == false)
                    {
                        MessageBox.Show("Unable to load image:\n" + filename);
                    }
                }
                catch // silently ignore load faults
                {

                }
            }
            else 
            {
                label.Background = prop.backgroundColor;
            }

            label.Padding = new Thickness(prop.padding[0], prop.padding[1], prop.padding[2], prop.padding[3]);

            return label;
        }
示例#5
0
        private Label DrawLabel(Canvas canvas, Theme.LabelProperties prop)
        {
            Label label = new Label();
            label.Width = prop.width;
            label.Height = prop.height;
            label.Foreground = prop.fontColor;
            label.Margin = new Thickness(prop.left, prop.top, 0, 0);
            label.FontSize = prop.fontSize;
            label.FontFamily = prop.font;
            label.VerticalContentAlignment = System.Windows.VerticalAlignment.Top;

            label.FontWeight = prop.fontBold;
            label.FontStyle = prop.fontItalic;

            label.HorizontalContentAlignment = prop.textAlign;

            label.Padding = new Thickness(0);

            Canvas.SetZIndex(label, 100);

            if (prop.backgroundImage != null)
            {
                string filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.backgroundImage;
                if (File.Exists(filename))
                {
                    Brush bg = new ImageBrush(new BitmapImage(new Uri(filename)));
                    label.Background = bg;
                }
                else if (File.Exists(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultBackgroundImage))
                {
                    Brush bg = new ImageBrush(new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultBackgroundImage)));
                    label.Background = bg;
                }
                else if(prop.dynamic == false)
                {
                    MessageBox.Show("Unable to load image:\n" + filename);
                }
            }
            else
            {
                label.Background = prop.backgroundColor;
            }

            return label;
        }
示例#6
0
        private void loadImage(Image img, Theme.ImageProperties prop)
        {
            string filename;
            logger.Trace("Loadimage {0}", prop.filename);
            if (prop.dynamic && SharedData.apiConnected == true)
            {
                if (SharedData.Sessions.SessionList.Count >= SharedData.OverlaySession)
                {
                    Theme.LabelProperties label = new Theme.LabelProperties();
                    label.text = prop.filename;

                    filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + SharedData.theme.formatFollowedText(
                        label,
                        SharedData.Sessions.SessionList[SharedData.OverlaySession].FollowedDriver,
                        SharedData.Sessions.SessionList[SharedData.OverlaySession]
                    );
                }
                else 
                    filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultFile;
            }
            else
            {
                filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.filename;
            }

            if (!File.Exists(filename) && prop.dynamic) {
                filename = Directory.GetCurrentDirectory() + "\\" + SharedData.theme.path + "\\" + prop.defaultFile;
            }

            if (File.Exists(filename))
            {
                img.Source = new BitmapImage(new Uri(filename));
                if (prop.width != 0 && prop.height != 0)
                {
                    img.Width = prop.width;// / SharedData.theme.width * 1280;
                    img.Height = prop.height;// / SharedData.theme.height * 720;
                }
                else
                {
                    img.Width = SharedData.theme.width;
                    img.Height = SharedData.theme.height;
                }
                img.Margin = new Thickness(prop.left, prop.top, 0, 0);
                ImageBehavior.SetAnimatedSource(img,img.Source);
                ImageBehavior.SetRepeatBehavior(img, RepeatBehavior.Forever);
                ImageBehavior.SetAutoStart(img,false);                
            }
        }
示例#7
0
        private Boolean ClickAction(Theme.ButtonActions action, string[] objects)
        {
            for (int j = 0; j < objects.Length; j++)
            {
                string[] split = objects[j].Split('-');
                switch (action)
                {
                    case Theme.ButtonActions.camera:
                        int camera = -1;
                        foreach (CameraInfo.CameraGroup cam in SharedData.Camera.Groups)
                        {
                            if (cam.Name.ToLower() == objects[j].ToLower())
                                camera = cam.Id;
                        }
                        if (camera >= 0)
                        {
                            int driver = Controls.padCarNum(SharedData.Sessions.CurrentSession.FollowedDriver.Driver.NumberPlate);
                            irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.CamSwitchNum, driver, camera);
                            if (SharedData.remoteClient != null && SharedData.serverThread.IsAlive)
                            {
                                SharedData.remoteClient.sendMessage("CAMERA;" + camera);
                                SharedData.remoteClient.sendMessage("DRIVER;" + driver);
                            }
                            SharedData.updateControls = true;
                        }
                        break;
                    case Theme.ButtonActions.replay:
                        int replay = -1;
                        bool result = Int32.TryParse(objects[j], out replay);
                        if (result)
                        {
                            if (replay == 0) // live
                            {
                                Thread.Sleep(16);
                                irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySearch, (int)iRSDKSharp.ReplaySearchModeTypes.ToEnd, 0);
                                irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 1, 0);
                                SharedData.updateControls = true;
                                SharedData.triggers.Push(TriggerTypes.live);

                                if (SharedData.remoteClient != null)
                                    SharedData.remoteClient.sendMessage("LIVE;");
                                else if (SharedData.serverThread.IsAlive)
                                    SharedData.serverOutBuffer.Push("LIVE;");
                            }
                            else // replay
                            {
                                Thread.Sleep(16);
                                irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlayPosition, (int)iRSDKSharp.ReplayPositionModeTypes.Begin, (int)((Int32)irAPI.sdk.GetData("ReplayFrameNum") - (replay * 60)));
                                irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 1, 0);
                                SharedData.triggers.Push(TriggerTypes.replay);

                                if (SharedData.remoteClient != null)
                                    SharedData.remoteClient.sendMessage("REWIND;" + ((Int32)irAPI.sdk.GetData("ReplayFrameNum") - (replay * 60)).ToString());
                                else if (SharedData.serverThread.IsAlive)
                                    SharedData.serverOutBuffer.Push("REWIND;" + ((Int32)irAPI.sdk.GetData("ReplayFrameNum") - (replay * 60)).ToString());
                            }
                        }
                        break;
                    case Theme.ButtonActions.playspeed:
                        Int32 playspeed = Int32.Parse(objects[j]);
                        Int32 slowmo = 0;
                        if (playspeed < 0)
                        {
                            playspeed = Math.Abs(playspeed)-1;
                            slowmo = 1;
                        }

                        Thread.Sleep(16);
                        irAPI.sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, playspeed, slowmo);
                        break;
                    default:
                        switch (split[0])
                        {
                            case "Overlay": // overlays
                                for (int k = 0; k < SharedData.theme.objects.Length; k++)
                                {
                                    if (SharedData.theme.objects[k].name == split[1])
                                    {
                                        Boolean isStandings = SharedData.theme.objects[k].dataset == Theme.dataset.standing || SharedData.theme.objects[k].dataset == Theme.dataset.points;

                                        if (isStandings && action == Theme.ButtonActions.show)
                                        {
                                            SharedData.theme.objects[k].page++;
                                        }

                                        if (SharedData.lastPage[k] == true && isStandings && action == Theme.ButtonActions.show)
                                        {
                                            SharedData.theme.objects[k].visible = setObjectVisibility(SharedData.theme.objects[k].visible, Theme.ButtonActions.hide);
                                            SharedData.theme.objects[k].page = -1;
                                            SharedData.lastPage[k] = false;

                                            return true;
                                        }
                                        else
                                        {

                                            SharedData.theme.objects[k].visible = setObjectVisibility(SharedData.theme.objects[k].visible, action);
                                            if ((action == Theme.ButtonActions.toggle) && (SharedData.theme.objects[k].visible == false))
                                                return true;
                                        }
                                    }
                                }
                                break;
                            case "Image": // images
                                for (int k = 0; k < SharedData.theme.images.Length; k++)
                                {
                                    if (SharedData.theme.images[k].name == split[1])
                                    {
                                        SharedData.theme.images[k].visible = setObjectVisibility(SharedData.theme.images[k].visible, action);
                                    }
                                }
                                break;
                            case "Ticker": // tickers
                                for (int k = 0; k < SharedData.theme.tickers.Length; k++)
                                {
                                    if (SharedData.theme.tickers[k].name == split[1])
                                    {
                                        SharedData.theme.tickers[k].visible = setObjectVisibility(SharedData.theme.tickers[k].visible, action);
                                    }
                                }
                                break;
                            case "Video": // video
                                for (int k = 0; k < SharedData.theme.videos.Length; k++)
                                {
                                    if (SharedData.theme.videos[k].name == split[1])
                                    {
                                        SharedData.theme.videos[k].visible = setObjectVisibility(SharedData.theme.videos[k].visible, action);
                                    }
                                }
                                break;
                            case "Sound": // sound
                                for (int k = 0; k < SharedData.theme.sounds.Length; k++)
                                {
                                    if (SharedData.theme.sounds[k].name == split[1])
                                    {
                                        switch (action)
                                        {
                                            case Theme.ButtonActions.hide:
                                                SharedData.theme.sounds[k].playing = false;
                                                break;
                                            default:
                                                SharedData.theme.sounds[k].playing = true;
                                                break;
                                        }
                                    }
                                }
                                break;
                            case "Trigger": // triggers
                                switch (split[1])
                                {
                                    case "flags":
                                        if (SharedData.Sessions.CurrentSession.Flag == Sessions.SessionInfo.sessionFlag.white)
                                            SharedData.triggers.Push(TriggerTypes.flagWhite);
                                        else if (SharedData.Sessions.CurrentSession.Flag == Sessions.SessionInfo.sessionFlag.checkered)
                                            SharedData.triggers.Push(TriggerTypes.flagCheckered);
                                        else if (SharedData.Sessions.CurrentSession.Flag == Sessions.SessionInfo.sessionFlag.yellow)
                                            SharedData.triggers.Push(TriggerTypes.flagYellow);
                                        else
                                            SharedData.triggers.Push(TriggerTypes.flagGreen);
                                        break;
                                    case "lights":
                                        if (SharedData.Sessions.CurrentSession.StartLight == Sessions.SessionInfo.sessionStartLight.ready)
                                            SharedData.triggers.Push(TriggerTypes.lightsReady);
                                        else if (SharedData.Sessions.CurrentSession.StartLight == Sessions.SessionInfo.sessionStartLight.set)
                                            SharedData.triggers.Push(TriggerTypes.lightsSet);
                                        else if (SharedData.Sessions.CurrentSession.StartLight == Sessions.SessionInfo.sessionStartLight.go)
                                            SharedData.triggers.Push(TriggerTypes.lightsGo);
                                        else
                                            SharedData.triggers.Push(TriggerTypes.lightsOff);
                                        break;
                                    default:
                                        break;
                                }
                                break;
                            case "Click":
                                {
                                    for (int i = 0; i < SharedData.theme.buttons.Length; i++)
                                    {
                                        if (SharedData.theme.buttons[i].name == split[1])
                                        {
                                            Button dummyButton = new Button();
                                            dummyButton.Name = "customButton" + i.ToString();
                                            dummyButton.Content = "";
                                            this.HandleClick(dummyButton, new RoutedEventArgs());
                                            break;
                                        }
                                    }
                                    break;
                                }
                            default: // script or not
                                if (SharedData.scripting.Scripts.Contains(split[0]))
                                {
                                    SharedData.scripting.PressButton(split[0], split[1]);
                                }
                                break;
                        }
                        break;
                }
            }
            return false;
        }