Beispiel #1
0
        private void OpenFile_Impl()
        {
            if (ConfirmSaveChanges() == ConfirmSaveResult.Cancel)
            {
                return;
            }

            string filename = services.OpenFileDialog("Open File", "Showlight XML files|*.xml");

            if (filename is not null)
            {
                try
                {
                    var showlightFile = ShowLights.Load(filename);

                    Showlights.Clear();

                    foreach (var sl in showlightFile)
                    {
                        // Old versions of Toolkit have generated undefined notes
                        if (sl.GetShowLightType() != ShowLightType.Undefined)
                        {
                            Showlights.AddOrUpdate(new ShowLightViewModel(sl));
                        }
                    }

                    ResetEditor(filename, clearShowlights: false);
                }
                catch (Exception ex)
                {
                    services.ShowError("Opening the file failed:" + Environment.NewLine + ex.Message);
                }
            }
        }
Beispiel #2
0
        public MainWindowViewModel(IPlatformSpecificServices services)
        {
            this.services  = services;
            GenerationVM   = new GenerationViewModel(services);
            TimeShiftVM    = new TimeShifterViewModel();
            ReplaceVM      = new ReplaceViewModel();
            StrobeEffectVM = new StrobeEffectViewModel();
            LaserLightsVM  = new LaserLightsViewModel();

            UndoManager = new UndoManager <ShowLightViewModel>();

            // Bind collection to UI
            Showlights.Connect()
            .AutoRefresh()
            .Sort(SortExpressionComparer <ShowLightViewModel> .Ascending(s => s.Time))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Bind(out var list)
            .Subscribe();

            ObservableShowlights = list;

            // Subscribe to changes in the collection to set FileDirty
            Showlights.Connect()
            .AutoRefresh()
            .Subscribe(_ =>
            {
                if (!FileDirty)
                {
                    FileDirty = true;
                }
            });

            CreateReactiveCommands();

            UndoManager.FileIsClean
            .Subscribe(_ => FileDirty = false);

            this.WhenAnyValue(x => x.OpenFileName, x => x.FileDirty)
            .Subscribe(UpdateWindowTitle);

            // Update active colors when selected item changes or is edited
            this.WhenAnyValue(x => x.SelectedItem, x => x.SelectedItem.Note, (selected, _) => selected)
            .Where(selected => selected is not null)
            .Subscribe(sl =>
            {
                MoveToTime = sl.Time / 1000f;
                InsertTime = sl.Time / 1000f;

                UpdateActiveColors(sl);
            });

            this.WhenAnyValue(x => x.ActiveFogColor, x => x.ActiveBeamColor,
                              (fog, beam) => $"Fog: {(fog == default ? "N/A" : fog.ToString())}\nBeam: {(beam == default ? "N/A" : beam.ToString())}")
            .ToPropertyEx(this, x => x.PreviewTooltip);
        }
Beispiel #3
0
        private void ResetEditor(string filename = null, bool clearShowlights = true)
        {
            if (clearShowlights)
            {
                Showlights.Clear();
            }

            UndoManager.Clear();
            FileDirty = false;

            OpenFileName = filename;
        }
Beispiel #4
0
        // Design time data
        public MainWindowViewModel() : this(null)
        {
            var sl1 = new ShowLightViewModel(ShowLight.FogMax, 10_000);
            var sl2 = new ShowLightViewModel(ShowLight.BeamMin, 11_000);
            var sl3 = new ShowLightViewModel(ShowLight.LasersOn, 12_000);
            Showlights.AddOrUpdate(sl1);
            Showlights.AddOrUpdate(sl2);
            Showlights.AddOrUpdate(sl3);

            ActiveFogColor  = sl1.Note;
            ActiveBeamColor = sl2.Note;
        }
        /// <summary>
        /// Fixes missing and updates showlights to current standards
        /// </summary>
        private static void UpdateShowlights(string songDirectory, Platform targetPlatform)
        {
            bool hasShowlights = true;
            // TODO: provide some pb feedback for long process
            var info              = DLCPackageData.LoadFromFolder(songDirectory, targetPlatform);
            var showlightsArr     = info.Arrangements.Where(x => x.ArrangementType == ArrangementType.ShowLight).FirstOrDefault();
            var showlightFilePath = showlightsArr.SongXml.File;

            if (String.IsNullOrEmpty(showlightFilePath))
            {
                var xmlFilePath = info.Arrangements[0].SongXml.File;
                var xmlName     = Path.GetFileNameWithoutExtension(xmlFilePath);
                showlightFilePath = Path.Combine(Path.GetDirectoryName(xmlFilePath), xmlName.Split('_')[0] + "_showlights.xml");
                hasShowlights     = false;
            }

            // Generate Showlights
            var showlight = new Showlights();

            showlight.CreateShowlights(info);
            // need at least two showlight elements to be valid
            if (showlight.ShowlightList.Count > 1)
            {
                var showlightStream = new MemoryStream();
                showlight.Serialize(showlightStream);

                using (FileStream file = new FileStream(showlightFilePath, FileMode.Create, FileAccess.Write))
                    showlightStream.WriteTo(file);

                // write xml comments
                Song2014.WriteXmlComments(showlightFilePath);
            }
            else
            {
                // insufficient showlight changes may crash game
                throw new InvalidOperationException("Detected insufficient showlight changes: " + showlight.ShowlightList.Count);
            }

            if (!hasShowlights)
            {
                UpdateAggegrateGraph(songDirectory, targetPlatform, info);
            }
        }
Beispiel #6
0
        private void Insert_Impl()
        {
            var newNote = new ShowLightViewModel(InsertColor, (int)(InsertTime * 1000f));

            UndoManager.AddDelegateUndo(
                "Insert",
                undoAction: () =>
            {
                Showlights.Remove(newNote);
                return(newNote);
            },
                redoAction: () =>
            {
                Showlights.AddOrUpdate(newNote);
                return(newNote);
            },
                FileDirty);

            Showlights.AddOrUpdate(newNote);

            SelectedItem = newNote;
            scrollIntoView.OnNext(newNote);
        }