コード例 #1
0
    /// <summary>
    /// Update the offset of the selected diff
    /// If there's no selected diff this just goes into oblivion
    /// </summary>
    public void UpdateOffset()
    {
        if (selected == null || !diffs.ContainsKey(selected.Name))
        {
            return;
        }

        var diff = diffs[selected.Name];

        if (float.TryParse(songBeatOffsetField.text, out float temp2))
        {
            diff.NoteJumpStartBeatOffset = temp2;
        }

        selected.ShowDirtyObjects(diff);
    }
コード例 #2
0
    /// <summary>
    /// Save the diff
    /// </summary>
    /// <param name="row">UI row that was clicked on</param>
    private void SaveDiff(DifficultyRow row)
    {
        var localDiff = diffs[row.Name];
        var firstSave = localDiff.ForceDirty;

        localDiff.Commit();
        row.ShowDirtyObjects(false, true);

        var Song = BeatSaberSongContainer.Instance.song;
        var diff = localDiff.DifficultyBeatmap;

        if (!Song.difficultyBeatmapSets.Contains(currentCharacteristic))
        {
            Song.difficultyBeatmapSets.Add(currentCharacteristic);
        }
        if (!currentCharacteristic.difficultyBeatmaps.Contains(diff))
        {
            currentCharacteristic.difficultyBeatmaps.Add(diff);
        }

        BeatSaberMap map = TryGetExistingMapFromDiff(diff) ?? new BeatSaberMap
        {
            mainNode = new JSONObject()
        };
        string oldPath = map?.directoryAndFile;

        diff.UpdateName();
        map.directoryAndFile = Path.Combine(Song.directory, diff.beatmapFilename);
        if (File.Exists(oldPath) && oldPath != map.directoryAndFile && !File.Exists(map.directoryAndFile))
        {
            if (firstSave)
            {
                File.Copy(oldPath, map.directoryAndFile);
            }
            else
            {
                File.Move(oldPath, map.directoryAndFile); //This should properly "convert" difficulties just fine
            }
        }
        else
        {
            map.Save();
        }

        diff.RefreshRequirementsAndWarnings(map);

        Song.SaveSong();
        characteristicSelect.Recalculate();

        Debug.Log("Saved " + row.Name);
    }
コード例 #3
0
    /// <summary>
    /// Revert the diff to the saved version
    /// </summary>
    /// <param name="obj">UI row that was clicked on</param>
    private void Revertdiff(DifficultyRow row)
    {
        var localDiff = diffs[row.Name];

        localDiff.Revert();

        row.NameInput.text = localDiff.CustomName;

        if (row == selected)
        {
            njsField.text            = localDiff.NoteJumpMovementSpeed.ToString();
            songBeatOffsetField.text = localDiff.NoteJumpStartBeatOffset.ToString();
            envRemoval.UpdateFromDiff(localDiff.envRemoval);
        }

        row.ShowDirtyObjects(localDiff);
    }
コード例 #4
0
    /// <summary>
    /// Handle deleting a difficulty that was previously saved
    /// </summary>
    /// <param name="row">UI row that was clicked on</param>
    /// <param name="r">Confirmation from the user</param>
    private void HandleDeleteDifficulty(DifficultyRow row, int r)
    {
        if (r == 1) // User canceled out
        {
            row.Toggle.isOn = true;
            return;
        }

        var diff = diffs[row.Name].DifficultyBeatmap;

        string fileToDelete = Song.GetMapFromDifficultyBeatmap(diff)?.directoryAndFile;

        if (File.Exists(fileToDelete))
        {
            FileOperationAPIWrapper.MoveToRecycleBin(fileToDelete);
        }

        // Remove status effects if present
        if (copySource != null && row == copySource.Obj && currentCharacteristic == copySource.Characteristic)
        {
            CancelCopy();
        }
        if (row == selected)
        {
            DeselectDiff();
        }

        currentCharacteristic.difficultyBeatmaps.Remove(diffs[row.Name].DifficultyBeatmap);
        if (currentCharacteristic.difficultyBeatmaps.Count == 0)
        {
            Song.difficultyBeatmapSets.Remove(currentCharacteristic);
        }

        diffs.Remove(row.Name);
        Song.SaveSong();

        row.SetInteractable(false);
        row.NameInput.text = "";
        row.ShowDirtyObjects(false, false);
        characteristicSelect.Recalculate();
    }
コード例 #5
0
    /// <summary>
    /// Handle changes to the difficulty label
    /// </summary>
    /// <param name="row">UI row that was updated</param>
    /// <param name="difficultyLabel">New label value</param>
    private void OnValueChanged(DifficultyRow row, string difficultyLabel)
    {
        if (!diffs.ContainsKey(row.Name))
        {
            return;
        }

        var diff = diffs[row.Name];

        // Expert+ is special as the only difficulty that is different in JSON
        string defaultName = row.Name == "ExpertPlus" ? "Expert+" : row.Name;

        if (difficultyLabel != "" && difficultyLabel != defaultName)
        {
            diff.CustomName = difficultyLabel;
        }
        else
        {
            diff.CustomName = null;
        }

        row.ShowDirtyObjects(diff);
    }
コード例 #6
0
    /// <summary>
    /// Handle adding and deleting difficulties, they aren't added to the
    /// song being edited until they are saved so this method stages them
    /// </summary>
    /// <param name="row">UI row that was clicked on</param>
    /// <param name="val">True if the diff is being added</param>
    private void OnChange(DifficultyRow row, bool val)
    {
        if (!val && diffs.ContainsKey(row.Name)) // Delete if exists
        {
            // ForceDirty = has never been saved, don't ask for permission
            if (diffs[row.Name].ForceDirty)
            {
                if (row == selected)
                {
                    DeselectDiff();
                }

                diffs.Remove(row.Name);
                row.SetInteractable(false);
                row.NameInput.text = "";
                row.ShowDirtyObjects(false, false);
                return;
            }

            // This diff has previously been saved, confirm deletion
            PersistentUI.Instance.ShowDialogBox("SongEditMenu", "deletediff.dialog",
                                                (r) => HandleDeleteDifficulty(row, r), PersistentUI.DialogBoxPresetType.YesNo, new object[] { diffs[row.Name].DifficultyBeatmap.difficulty });
        }
        else if (val && !diffs.ContainsKey(row.Name)) // Create if does not exist
        {
            DifficultyBeatmap map = new DifficultyBeatmap(currentCharacteristic)
            {
                difficulty     = row.Name,
                difficultyRank = diffRankLookup[row.Name]
            };

            map.UpdateName();

            if (copySource != null)
            {
                var fromDiff = copySource.DifficultySettings;

                CancelCopy();

                if (fromDiff != null)
                {
                    map.noteJumpMovementSpeed   = fromDiff.DifficultyBeatmap.noteJumpMovementSpeed;
                    map.noteJumpStartBeatOffset = fromDiff.DifficultyBeatmap.noteJumpStartBeatOffset;

                    map.customData = fromDiff.DifficultyBeatmap.customData?.Clone();

                    // This sets the current filename as the filename for another diff and will trigger the copy on save
                    map.UpdateName(fromDiff.DifficultyBeatmap.beatmapFilename);
                }
            }

            diffs[row.Name] = new DifficultySettings(map, true);

            row.ShowDirtyObjects(diffs[row.Name]);
            row.SetInteractable(true);
            OnClick(row);
        }
        else if (val) // Create, but already exists
        {
            // I don't know how this would happen anymore
            row.ShowDirtyObjects(diffs[row.Name]);
            row.SetInteractable(true);
            if (!loading)
            {
                OnClick(row);
            }
        }
    }