示例#1
0
 private void CloseSplits()
 {
     if (!WarnUserAboutSplitsSave())
         return;
     if (!WarnUserAboutLayoutSave())
         return;
     var run = new StandardRunFactory().Create(ComparisonGeneratorsFactory);
     Model.Reset();
     SetRun(run);
     Settings.AddToRecentSplits("", null, TimingMethod.RealTime);
     InTimerOnlyMode = true;
     if (Layout.Components.Count() != 1 || Layout.Components.FirstOrDefault().ComponentName != "Timer")
     {
         var layout = new TimerOnlyLayoutFactory().Create(CurrentState);
         layout.Settings = Layout.Settings;
         layout.X = Location.X;
         layout.Y = Location.Y;
         layout.Mode = Layout.Mode;
         SetLayout(layout);
         Settings.AddToRecentLayouts("");
     }
 }
示例#2
0
        private void Init(string splitsPath = null, string layoutPath = null)
        {
            SetWindowTitle();

            SpeedrunCom.Authenticator = new SpeedrunComOAuthForm();

            GlobalCache = new GraphicsCache();
            Invalidator = new Invalidator(this);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            ComponentManager.BasePath = BasePath;

            SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed;
            SpeedRunsLiveAPI.Instance.RefreshRacesListAsync();

            CurrentState = new LiveSplitState(null, this, null, null, null);

            ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory();

            Model = new DoubleTapPrevention(new TimerModel());

            RunFactory = new StandardFormatsRunFactory();
            RunSaver = new XMLRunSaver();
            LayoutSaver = new XMLLayoutSaver();
            SettingsSaver = new XMLSettingsSaver();
            LoadSettings();

            UpdateRecentSplits();
            UpdateRecentLayouts();

            InTimerOnlyMode = false;
            var timerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory);

            IRun run = timerOnlyRun;
            try
            {
                if (!string.IsNullOrEmpty(splitsPath))
                {
                    run = LoadRunFromFile(splitsPath, TimingMethod.RealTime);
                }
                else if (Settings.RecentSplits.Count > 0)
                {
                    var lastSplitFile = Settings.RecentSplits.Last();
                    if (!string.IsNullOrEmpty(lastSplitFile.Path))
                    {
                        run = LoadRunFromFile(lastSplitFile.Path, lastSplitFile.LastTimingMethod);
                        CurrentState.CurrentTimingMethod = lastSplitFile.LastTimingMethod;
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            run.FixSplits();
            CurrentState.Run = run;
            CurrentState.Settings = Settings;

            try
            {
                if (!string.IsNullOrEmpty(layoutPath))
                {
                    Layout = LoadLayoutFromFile(layoutPath);
                }
                else
                {
                    if (Settings.RecentLayouts.Count > 0
                        && !string.IsNullOrEmpty(Settings.RecentLayouts.Last()))
                    {
                        Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last());
                    }
                    else if (run == timerOnlyRun)
                    {
                        Layout = new TimerOnlyLayoutFactory().Create(CurrentState);
                        InTimerOnlyMode = true;
                    }
                    else
                    {
                        Layout = new StandardLayoutFactory().Create(CurrentState);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                Layout = new StandardLayoutFactory().Create(CurrentState);
            }

            CurrentState.LayoutSettings = Layout.Settings;
            CreateAutoSplitter();
            CurrentState.FixTimingMethodFromRuleset();

            SwitchComparisonGenerators();
            SwitchComparison(Settings.LastComparison);
            Model.CurrentState = CurrentState;

            CurrentState.OnReset += CurrentState_OnReset;
            CurrentState.OnStart += CurrentState_OnStart;
            CurrentState.OnSplit += CurrentState_OnSplit;
            CurrentState.OnSkipSplit += CurrentState_OnSkipSplit;
            CurrentState.OnUndoSplit += CurrentState_OnUndoSplit;
            CurrentState.OnPause += CurrentState_OnPause;
            CurrentState.OnResume += CurrentState_OnResume;
            CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious;
            CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext;

            ComponentRenderer = new ComponentRenderer();

            StartPosition = FormStartPosition.Manual;

            SetLayout(Layout);

            RefreshTask = Task.Factory.StartNew(RefreshTimerWorker);

            InvalidationRequired = false;

            Hook = new CompositeHook();
            Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed;
            Settings.RegisterHotkeys(Hook);

            SizeChanged += TimerForm_SizeChanged;

            lock (BackBufferLock)
            {
                BackBuffer = new Bitmap(Width, Height);
#if WITH_XSPLIT
                /*try
                {
                    // Outputs a CosmoWright image every 50ms (20 FPS)
                    XSplit = TimedBroadcasterPlugin.CreateInstance(
                        "livesplit", BackBuffer, 50);

                    if (this.XSplit != null)
                    {
                        // The correct version of XSplit was installed (unless they use OBS), so we can start our output.
                        this.XSplit.StartTimer();
                    }
                }
                catch
                { }*/
#endif
            }

            TopMost = Layout.Settings.AlwaysOnTop;
        }