Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom notes #22

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 77 additions & 7 deletions source/funkin/editors/charter/Charter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Charter extends UIState {

public var clipboard:Array<CharterCopyboardObject> = [];

public var noteTypeDropdown:UIDropDown;

public function new(song:String, diff:String, reload:Bool = true) {
super();
__song = song;
Expand Down Expand Up @@ -225,12 +227,24 @@ class Charter extends UIState {
},
null,
{
label: "(0) Default Note",
keybind: [ZERO]
label: "Switch to default note type",
keybind: [ZERO],
onSelect: _note_defaultnote
},
{
label: "Switch to previous note type",
keybind: [ONE],
onSelect: _note_prevnote
},
{
label: "Switch to next note type",
keybind: [TWO],
onSelect: _note_nextnote
},
{
label: "(1) Hurt Note",
keybind: [ONE]
label: "Edit note types",
keybind: [],
onSelect: _edit_notetype
}
]
},
Expand Down Expand Up @@ -405,6 +419,13 @@ class Charter extends UIState {
addEventSpr.alpha = 0;
addEventSpr.cameras = [charterCamera];

var noteTypes:Array<String> = ['default'];
noteTypeDropdown = new UIDropDown(10,105,200,32,noteTypes);
noteTypeDropdown.onChange = function(n) {
for(note in selection)
note.updatePos(note.step,note.id,note.susLength,n);
}
uiGroup.add(noteTypeDropdown);

// adds grid and notes so that they're ALWAYS behind the UI
add(gridBackdrop);
Expand Down Expand Up @@ -465,6 +486,7 @@ class Charter extends UIState {
for(e in eventsGroup.members)
e.refreshEventIcons();

_reload_notetypes();
refreshBPMSensitive();
}

Expand Down Expand Up @@ -499,6 +521,8 @@ class Charter extends UIState {
selection.remove(n);
else
selection = [n];

noteTypeDropdown.setOption(n.type);
}
if (FlxG.mouse.justReleasedRight) {
if (!selection.contains(n))
Expand Down Expand Up @@ -612,8 +636,9 @@ class Charter extends UIState {
var id = Math.floor(mousePos.x / 40);
if (id >= 0 && id < 4 * gridBackdrop.strumlinesAmount && mousePos.y >= 0) {
var note = new CharterNote();
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0);
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, noteTypeDropdown.index);
notesGroup.add(note);
trace(note.type);
selection = [note];
addToUndo(CPlaceNote(note));
}
Expand Down Expand Up @@ -922,7 +947,8 @@ class Charter extends UIState {
}

function _file_saveas(_) {
openSubState(new SaveSubstate(Json.stringify(Chart.filterChartForSaving(PlayState.SONG, false)), {
buildChart(); // note types are not saved i think
openSubState(new SaveSubstate(Json.stringify(Chart.filterChartForSaving(PlayState.SONG, false), null, "\t"), {
defaultSaveFile: '${__diff.toLowerCase()}.json'
}));
}
Expand Down Expand Up @@ -1161,13 +1187,57 @@ class Charter extends UIState {

#end

function _edit_notetype(t):Void
{
var state = new NoteTypeScreen(PlayState.SONG);
state.closeCallback = function() { _reload_notetypes(); };
state.closeRemoveNoteCallback = function(n) {
_reload_notetypes();
noteTypeDropdown.setOption(0);
notesGroup.forEach(function(note) {
if(note.type == n)
note.updatePos(note.step, note.id, note.susLength, 0);
if(note.type >= n)
note.updatePos(note.step, note.id, note.susLength, note.type-1);
});
};
FlxG.state.openSubState(state);
}

inline function _note_defaultnote(_)
noteTypeDropdown.setOption(0);


inline function _note_prevnote(_) {
if(noteTypeDropdown.index == 0)
noteTypeDropdown.setOption(noteTypeDropdown.options.length - 1);
else
noteTypeDropdown.setOption(noteTypeDropdown.index - 1);
}

inline function _note_nextnote(_) {
if(noteTypeDropdown.index == noteTypeDropdown.options.length - 1)
noteTypeDropdown.setOption(0);
else
noteTypeDropdown.setOption(noteTypeDropdown.index + 1);
}


public function _reload_notetypes()
{
var noteTypes:Array<String> = ['default'];
for(noteType in PlayState.SONG.noteTypes)
noteTypes.push(noteType);
noteTypeDropdown.options = noteTypes;
}

function changeNoteSustain(change:Float) {
if (selection.length <= 0 || change == 0) return;

addToUndo(CSustainChange([
for(n in selection) {
var old:Float = n.susLength;
n.updatePos(n.step, n.id, Math.max(n.susLength + change, 0));
n.updatePos(n.step, n.id, Math.max(n.susLength + change, 0),n.type);

{
before: old,
Expand Down
12 changes: 12 additions & 0 deletions source/funkin/editors/charter/CharterNote.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CharterNote extends UISprite {

public var sustainSpr:FlxSprite;
public var selected:Bool = false;
public var numberLabel:UIText;

var __doAnim:Bool = false;

Expand All @@ -37,6 +38,11 @@ class CharterNote extends UISprite {
sustainSpr = new FlxSprite(10, 40);
sustainSpr.makeGraphic(1, 1, -1);
members.push(sustainSpr);

numberLabel = new UIText(30,20,200,'',24,FlxColor.WHITE);
numberLabel.borderStyle = OUTLINE;
numberLabel.borderSize = 1;
numberLabel.borderColor = FlxColor.BLACK;
}

public override function updateButtonHandler() {
Expand Down Expand Up @@ -75,6 +81,9 @@ class CharterNote extends UISprite {
default: 0; // how is that even possible
};

// 0 is default !
numberLabel.text = type == 0 ? '' : Std.string(this.type);

sustainSpr.color = colors[animation.curAnim.curFrame];

if (!__doAnim) {
Expand Down Expand Up @@ -113,6 +122,7 @@ class CharterNote extends UISprite {
super.update(elapsed);

sustainSpr.follow(this, 15, 20);
numberLabel.follow(this, 19, 15);

if (__passed != (__passed = step < Conductor.curStepFloat)) {
alpha = __passed ? 0.6 : 1;
Expand All @@ -131,5 +141,7 @@ class CharterNote extends UISprite {
public override function draw() {
drawMembers();
drawSuper();
if(type != 0)
numberLabel.draw();
}
}
84 changes: 84 additions & 0 deletions source/funkin/editors/charter/NoteTypeScreen.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package funkin.editors.charter;

import funkin.backend.chart.ChartData;
import flixel.math.FlxPoint;
import funkin.backend.chart.ChartData.ChartMetaData;

using StringTools;

class NoteTypeScreen extends UISubstateWindow {
public var data:ChartData;
public var addButton:UIButton;
public var closeButton:UIButton;
public var removeButton:UIButton;

public var scrollSpeedStepper:UINumericStepper;
public var stageBox:UITextBox;

public var noteTypeDropdown:UIDropDown;

public var noteTypeNameBox:UITextBox;

public var closeRemoveNoteCallback:Int->Void;

public function new(data:ChartData) {
super();
this.data = data;
}

public override function create() {
FlxG.sound.music.pause();
Charter.instance.vocals.pause();

function addLabelOn(ui:UISprite, text:String)
add(new UIText(ui.x, ui.y - 24, 0, text));

winTitle = 'Edit note types';
winWidth = 420; winHeight = 69*4; // guys look, the funny numbers!

super.create();

noteTypeDropdown = new UIDropDown(windowSpr.x + 20, windowSpr.y + 60,200,32,PlayState.SONG.noteTypes);
addLabelOn(noteTypeDropdown, "Note");
add(noteTypeDropdown);

addButton = new UIButton(windowSpr.x + 200 + 40, windowSpr.y + 60 + 32 + 16, "Add new note type", function() {
noteTypeDropdown.visible = false;
noteTypeDropdown.active = false;
removeButton.visible = false;
removeButton.active = false;

addButton.field.text = 'Create note type';
addButton.callback = function() {onSave(); close();}

noteTypeNameBox = new UITextBox(windowSpr.x + 20, windowSpr.y + 60, '');
add(noteTypeNameBox);

}, 125);
add(addButton);

removeButton = new UIButton(windowSpr.x + 200 + 40, windowSpr.y + 60, "Remove note type", function() {
onRemove();
close();
}, 125);
add(removeButton);

closeButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Cancel", function() {
close();
}, 125);
add(closeButton);
closeButton.x -= closeButton.bWidth;
}

public function onSave()
{
PlayState.SONG.noteTypes.push(noteTypeNameBox.label.text);
}

public function onRemove()
{
closeRemoveNoteCallback(noteTypeDropdown.index + 1);
PlayState.SONG.noteTypes.remove(noteTypeDropdown.label.text);
}

}