Charter Bookmarks (1st version)

This commit is contained in:
Furo
2024-11-27 17:28:39 +01:00
parent 204a151170
commit eefbb97d5a
3 changed files with 251 additions and 0 deletions
+6
View File
@@ -10,6 +10,7 @@ typedef ChartData = {
public var stage:String;
public var scrollSpeed:Float;
public var noteTypes:Array<String>;
public var ?bookmarks:Array<ChartBookmark>;
public var ?chartVersion:String;
public var ?fromMods:Bool;
@@ -57,6 +58,11 @@ typedef ChartNote = {
var sLen:Float; // sustain length of the note (ms)
}
typedef ChartBookmark = {
var time:Float;
var name:String;
}
typedef ChartEvent = {
var name:String;
var time:Float;
+150
View File
@@ -40,6 +40,7 @@ class Charter extends UIState {
@:noCompletion private var playbackIndex:Int = 7;
@:noCompletion private var snapIndex:Int = 6;
@:noCompletion private var noteIndex:Int = 5;
@:noCompletion private var songIndex:Int = 4;
public var scrollBar:UIScrollBar;
public var songPosInfo:UIText;
@@ -617,6 +618,7 @@ class Charter extends UIState {
e.refreshEventIcons();
buildNoteTypesUI();
updateBookmarks();
refreshBPMSensitive();
// Just for now until i add event stacking -lunar
@@ -1142,6 +1144,8 @@ class Charter extends UIState {
createSelection(toBeCreated, false);
}
updateBookmarks();
if (addToUndo)
undos.addToUndo(CCreateStrumLine(strumLineID, strL));
}
@@ -1165,6 +1169,8 @@ class Charter extends UIState {
strumLines.refreshStrumlineIDs();
strumLines.snapStrums();
updateBookmarks();
if (addToUndo) {
var newStrL = Reflect.copy(strL);
newStrL.notes = undoNotes;
@@ -1229,6 +1235,16 @@ class Charter extends UIState {
updateNoteLogic(elapsed);
updateAutoSaving(elapsed);
for (bs in __bookmarkObjects)
{
var bars:Array<FlxSprite> = bs[0];
var text:UIText = bs[1];
for (spr in bars)
spr.x = strumLines.members[spr.ID].x;
if (text != null)
text.x = strumLines.members[0].x + 4;
}
if (FlxG.sound.music.playing || __firstFrame) {
gridBackdrops.conductorSprY = curStepFloat * 40;
} else {
@@ -1559,6 +1575,9 @@ class Charter extends UIState {
case CEditNoteTypes(oldArray, newArray):
noteTypes = oldArray;
changeNoteType(null, false);
case CEditBookmarks(oldArray, newArray):
PlayState.SONG.bookmarks = oldArray;
updateBookmarks();
case CEditSpecNotesType(notes, oldTypes, newTypes):
for(i=>note in notes) note.updatePos(note.step, note.id, note.susLength, oldTypes[i]);
case CChangeBundle(changes):
@@ -1614,6 +1633,9 @@ class Charter extends UIState {
case CEditNoteTypes(oldArray, newArray):
noteTypes = newArray;
changeNoteType(null, false);
case CEditBookmarks(oldArray, newArray):
PlayState.SONG.bookmarks = newArray;
updateBookmarks();
case CEditSpecNotesType(notes, oldTypes, newTypes):
for(i=>note in notes) note.updatePos(note.step, note.id, note.susLength, newTypes[i]);
case CChangeBundle(changes):
@@ -1695,6 +1717,133 @@ class Charter extends UIState {
if (FlxG.sound.music.playing) return;
Conductor.songPosition = FlxG.sound.music.length;
}
public function getBookmarkList():Array<ChartBookmark> {
var bookmarks:Array<ChartBookmark> = [];
try {
if (PlayState.SONG.bookmarks != null)
bookmarks = PlayState.SONG.bookmarks;
} catch (e) {}
return bookmarks;
}
function _bookmarks_add(_) {
var currentBookmarks:Array<ChartBookmark> = getBookmarkList();
var newBookmarks:Array<ChartBookmark> = getBookmarkList();
newBookmarks.push({time: curStepFloat, name: "New Bookmark"});
PlayState.SONG.bookmarks = newBookmarks;
updateBookmarks();
undos.addToUndo(CEditBookmarks(currentBookmarks, newBookmarks));
}
function _bookmarks_edit_list(_)
FlxG.state.openSubState(new CharterBookmarkList()); //idk why its FlxG.state but it looks so off lmfao
public var __bookmarkObjects:Array<Dynamic> = [];
public function updateBookmarks()
{
for (bs in __bookmarkObjects)
{
var bars:Array<FlxSprite> = bs[0];
var text:UIText = bs[1];
if (bars != null) {
for (spr in bars) {
if (spr == null) continue;
remove(spr);
spr.kill();
}
}
if (text != null) {
remove(text);
text.kill();
}
}
__bookmarkObjects.clear();
for (b in getBookmarkList())
{
var bookmarkcolor = 0xff911dd9;//PURPLE TO SEE IT BETTER
var sprites = [];
for (str in strumLines.members)
{
var bookmarkspr = new FlxSprite(str.x, (b.time * 40)).makeSolid(1, 1, bookmarkcolor);
bookmarkspr.scale.set(4 * 40, str.keyCount);
bookmarkspr.updateHitbox();
bookmarkspr.camera = charterCamera;
add(bookmarkspr);
bookmarkspr.ID = strumLines.members.indexOf(str);
sprites.push(bookmarkspr);
}
var bookmarkText = new UIText(strumLines.members[0].x + 4, 0, 400, b.name, 15, bookmarkcolor);
bookmarkText.y = sprites[0].y - (bookmarkText.height + 2);
bookmarkText.camera = charterCamera;
add(bookmarkText);
__bookmarkObjects.push([sprites, bookmarkText]);
}
buildSongUI();
}
function buildSongUI():Array<UIContextMenuOption> {
var songTopButton:UITopMenuButton = topMenuSpr == null ? null : cast topMenuSpr.members[songIndex];
var newChilds:Array<UIContextMenuOption> = [
{
label: "Go back to the start",
keybind: [HOME],
onSelect: _song_start
},
{
label: "Go to the end",
keybind: [END],
onSelect: _song_end
},
null,
{
label: "Add Bookmark Here",
onSelect: _bookmarks_add
},
{
label: "Edit Bookmark List",
color: 0xFF959829, icon: 4,
onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2; button.icon.offset.y = -1;},
onSelect: _bookmarks_edit_list
},
null
];
var bookmarks:Array<ChartBookmark> = getBookmarkList();
if (bookmarks.length > 0)
{
for (b in bookmarks)
{
newChilds.push({
label: "Go To \"" + b.name + "\"",
onSelect: function(_) { Conductor.songPosition = Conductor.getTimeForStep(b.time); }
});
}
newChilds.push(null);
}
newChilds.push({
label: "Mute instrumental",
onSelect: _song_muteinst
});
newChilds.push({
label: "Mute voices",
onSelect: _song_mutevoices
});
if (songTopButton != null) songTopButton.contextMenu = newChilds;
return newChilds;
}
function _view_zoomin(_) {
zoom += 0.25;
__camZoom = Math.pow(2, zoom);
@@ -2062,6 +2211,7 @@ enum CharterChange {
CEditEventGroups(events:Array<CharterEvent>);
CEditChartData(oldData:{stage:String, speed:Float}, newData:{stage:String, speed:Float});
CEditNoteTypes(oldArray:Array<String>, newArray:Array<String>);
CEditBookmarks(oldArray:Array<ChartBookmark>, newArray:Array<ChartBookmark>);
CEditSpecNotesType(notes:Array<CharterNote>, oldNoteTypes:Array<Int>, newNoteTypes:Array<Int>);
CChangeBundle(changes:Array<CharterChange>);
@@ -0,0 +1,95 @@
package funkin.editors.charter;
import flixel.math.FlxPoint;
import funkin.backend.chart.ChartData.ChartBookmark;
class CharterBookmarkList extends UISubstateWindow {
public var bookmarkList:UIButtonList<BookmarkButton>;
public var saveButton:UIButton;
public var closeButton:UIButton;
public override function create() {
FlxG.sound.music.pause();
Charter.instance.vocals.pause();
winTitle = 'Bookmark List Editor';
winWidth = 380;
winHeight = 390;
super.create();
var title:UIText;
add(title = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Edit Bookmarks", 28));
bookmarkList = new UIButtonList<BookmarkButton>(20, title.y + title.height + 10, winWidth - 40, 342 - 85 - 16, null, FlxPoint.get(winWidth - 40, (342 - 85 - 16)/4), null, 0);
bookmarkList.cameraSpacing = 0;
for (b in Charter.instance.getBookmarkList())
bookmarkList.add(new BookmarkButton(0, 0, b, bookmarkList));
add(bookmarkList);
bookmarkList.frames = Paths.getFrames('editors/ui/inputbox');
bookmarkList.content.remove(bookmarkList.addButton); //i dont need it
saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() {
saveList();
close();
}, 125);
add(saveButton);
closeButton = new UIButton(saveButton.x - 20, saveButton.y, "Close", function() {
close();
}, 125);
add(closeButton);
closeButton.color = 0xFFFF0000;
closeButton.x -= closeButton.bWidth;
}
public function saveList() {
var oldList:Array<ChartBookmark> = Charter.instance.getBookmarkList();
var newList:Array<ChartBookmark> = [for (btn in bookmarkList.buttons.members) {time: btn.bookmark.time, name: btn.textBox.label.text}];
PlayState.SONG.bookmarks = newList;
Charter.instance.updateBookmarks();
Charter.undos.addToUndo(CEditBookmarks(oldList, newList));
}
}
class BookmarkButton extends UIButton {
public var textBox:UITextBox;
public var deleteButton:UIButton;
public var deleteIcon:FlxSprite;
public var bookmark:ChartBookmark;
public function new(x:Float, y:Float, bookmark:ChartBookmark, parent:UIButtonList<BookmarkButton>) {
super(x, y, '', null, Std.int(parent.buttonSize.x), Std.int(parent.buttonSize.y));
this.bookmark = bookmark;
autoAlpha = false;
members.push(textBox = new UITextBox(10, 10, bookmark.name, 276));
textBox.antialiasing = true;
deleteButton = new UIButton(textBox.x + textBox.label.width + 10, textBox.y, null, function () {
parent.remove(this);
}, 32);
deleteButton.color = 0xFFFF0000;
deleteButton.autoAlpha = false;
members.push(deleteButton);
deleteIcon = new FlxSprite(deleteButton.x + (15/2), deleteButton.y + 8).loadGraphic(Paths.image('editors/delete-button'));
deleteIcon.antialiasing = false;
members.push(deleteIcon);
}
override function update(elapsed:Float) {
textBox.y = (y + bHeight/2) - (textBox.bHeight/2);
deleteButton.x = textBox.x + textBox.bWidth + 14; deleteButton.y = textBox.y;
deleteIcon.x = deleteButton.x + (15/2); deleteIcon.y = deleteButton.y + 8;
deleteButton.selectable = selectable;
deleteButton.shouldPress = shouldPress;
super.update(elapsed);
}
}