sdaifhagf strumlines draggable smoth

This commit is contained in:
lunarcleint
2023-08-26 15:21:21 -07:00
parent cb1c334215
commit 2403517989
7 changed files with 96 additions and 37 deletions
+6 -7
View File
@@ -62,7 +62,7 @@ class Charter extends UIState {
/**
* ACTUAL CHART DATA
*/
public var strumLines:FlxTypedGroup<CharterStrumline> = new FlxTypedGroup<CharterStrumline>();
public var strumLines:CharterStrumLineGroup = new CharterStrumLineGroup();
public var notesGroup:CharterNoteGroup = new CharterNoteGroup();
public var eventsGroup:CharterEventGroup = new CharterEventGroup();
@@ -345,6 +345,7 @@ class Charter extends UIState {
eventsBackdrop = new EventBackdrop();
eventsBackdrop.x = -eventsBackdrop.width;
eventsBackdrop.cameras = [charterCamera];
eventsGroup.eventsBackdrop = eventsBackdrop;
add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrop));
selectionBox = new UISliceSprite(0, 0, 2, 2, 'editors/ui/selection');
@@ -546,7 +547,7 @@ class Charter extends UIState {
if (FlxG.mouse.pressed) {
selection.loop(function (n:CharterNote) {
n.setPosition(n.id * 40 + (mousePos.x - dragStartPos.x), n.step * 40 + (mousePos.y - dragStartPos.y));
n.dragging = true;
n.snappedToStrumline = false;
n.cursor = HAND;
}, function (e:CharterEvent) {
e.y = e.step * 40 + (mousePos.y - dragStartPos.y) - 17;
@@ -571,7 +572,7 @@ class Charter extends UIState {
for (s in selection) {
if (!s.draggable) continue;
s.handleDrag(changePoint);
if (s is CharterNote) cast(s, CharterNote).dragging = false;
if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true;
if (s is UISprite) cast(s, UISprite).cursor = BUTTON;
}
sortNotes();
@@ -598,6 +599,7 @@ class Charter extends UIState {
if (FlxG.mouse.justReleased) {
if (selection.length > 1) {
for (n in selection) n.selected = false;
selection = []; // clear selection
} else {
if (mouseOnGrid) {
@@ -619,7 +621,6 @@ class Charter extends UIState {
noteHovered = true;
break;
}
gridActionType = noteHovered ? DRAG : INVALID_DRAG;
}
}
@@ -630,6 +631,7 @@ class Charter extends UIState {
}
}
addEventSpr.selectable = !selectionBox.visible;
if (gridActionType == NONE && mousePos.x < 0 && mousePos.x > -addEventSpr.bWidth) {
addEventSpr.incorporeal = false;
addEventSpr.sprAlpha = lerp(addEventSpr.sprAlpha, 0.75, 0.25);
@@ -906,9 +908,6 @@ class Charter extends UIState {
updateDisplaySprites();
WindowTitle.prefix = undos.unsaved ? "* " : "";
strumLines.sort(function(o, a, b) return FlxSort.byValues(o, a.x - 80, b.x - 80), -1);
for (it=>i in strumLines.members)
if (!i.dragging) i.x = CoolUtil.fpsLerp(i.x, 160 * it, 0.3);
}
public static var startTime:Float = 0;
@@ -87,7 +87,7 @@ class CharterBackdrop extends FlxBackdrop {
for(_ in 0...strumlinesAmount) {
if (Charter.instance.strumLines.members[_] != null) {
x = Charter.instance.strumLines.members[_].x;
alpha = Charter.instance.strumLines.members[_].strumLine.visible ? 1 : 0.4;
alpha = Charter.instance.strumLines.members[_].strumLine.visible ? 0.9 : 0.4;
} else alpha = 0.9;
sectionSeparator.spacing.y = (10 * Conductor.beatsPerMesure * Conductor.stepsPerBeat) - 1;
@@ -106,8 +106,10 @@ class CharterBackdrop extends FlxBackdrop {
// Draw notes
notesGroup.forEach((n) -> {
if(n.exists && n.visible && (Math.floor(n.id/4) == _))
if(n.exists && n.visible && (Math.floor(n.id/4) == _)) {
n.cameras = cameras;
n.draw();
}
});
topLimit.scale.set(4 * 40, Math.ceil(FlxG.height / cameras[0].zoom));
@@ -3,8 +3,8 @@ package funkin.editors.charter;
import funkin.editors.charter.Charter.ICharterSelectable;
import flixel.math.FlxPoint;
import funkin.game.Character;
import funkin.backend.system.Conductor;
import funkin.game.HealthIcon;
import funkin.editors.charter.CharterBackdrop.EventBackdrop;
import funkin.backend.chart.ChartData.ChartEvent;
class CharterEvent extends UISliceSprite implements ICharterSelectable {
@@ -15,6 +15,9 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable {
public var selected:Bool = false;
public var draggable:Bool = true;
public var eventsBackdrop:EventBackdrop;
public var snappedToGrid:Bool = true;
public function new(step:Float, ?events:Array<ChartEvent>) {
super(-100, (step * 40) - 17, 100, 34, 'editors/charter/event-spr');
this.step = step;
@@ -25,6 +28,10 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable {
public override function update(elapsed:Float) {
super.update(elapsed);
if (snappedToGrid && eventsBackdrop != null)
x = eventsBackdrop.x + eventsBackdrop.width - (bWidth = 37 + (icons.length * 22));
for(k=>i in icons) {
i.follow(this, (k * 22) + 30 - (i.width / 2), (bHeight - i.height) / 2);
}
@@ -100,6 +107,6 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable {
break;
}
x = -(bWidth = 37 + (icons.length * 22));
x = (snappedToGrid && eventsBackdrop != null ? eventsBackdrop.x : 0) - (bWidth = 37 + (icons.length * 22));
}
}
@@ -1,3 +1,15 @@
package funkin.editors.charter;
class CharterEventGroup extends FlxTypedGroup<CharterEvent> {}
import funkin.editors.charter.CharterBackdrop.EventBackdrop;
class CharterEventGroup extends FlxTypedGroup<CharterEvent> {
public var eventsBackdrop:EventBackdrop;
public override function draw() {
for (event in members) {
event.eventsBackdrop = eventsBackdrop;
event.snappedToGrid = true;
}
super.draw();
}
}
+9 -4
View File
@@ -22,8 +22,10 @@ class CharterNote extends UISprite implements ICharterSelectable {
public var selected:Bool = false;
public var draggable:Bool = true;
public var dragging:Bool = false;
public var snappedToStrumline:Bool = true;
public var strumLine:CharterStrumline = null;
public function new() {
super();
antialiasing = true;
@@ -34,8 +36,6 @@ class CharterNote extends UISprite implements ICharterSelectable {
cursor = BUTTON;
//canBeHovered = false;
moves = false;
sustainSpr = new FlxSprite(10, 40);
@@ -60,6 +60,8 @@ class CharterNote extends UISprite implements ICharterSelectable {
@:isVar public var id(get, set):Int;
function set_id(d:Int) {
strumLine = Charter.instance.strumLines.members[Math.floor(d / 4)];
if (strumLine != null)
alpha = strumLine.strumLine.visible ? 1 : 0.4;
realId = d;
return id = d % 4;
}
@@ -125,7 +127,7 @@ class CharterNote extends UISprite implements ICharterSelectable {
var __passed:Bool = false;
public override function update(elapsed:Float) {
super.update(elapsed);
if (!dragging) x = (strumLine != null ? strumLine.button.x : 0) + (id % 4) * 40;
if(sustainSpr.exists)
sustainSpr.follow(this, 15, 20);
@@ -165,6 +167,9 @@ class CharterNote extends UISprite implements ICharterSelectable {
}
public override function draw() {
if (snappedToStrumline)
x = (strumLine != null ? strumLine.button.x : 0) + (id % 4) * 40;
drawMembers();
drawSuper();
}
@@ -0,0 +1,53 @@
package funkin.editors.charter;
import funkin.backend.chart.EventsData;
import flixel.util.FlxSort;
class CharterStrumLineGroup extends FlxTypedGroup<CharterStrumline> {
var __pastStrumlines:Array<CharterStrumline>;
var draggingObj:CharterStrumline = null;
var draggingOffset:Float = 0;
public override function update(elapsed:Float) {
super.update(elapsed);
for (strumLine in members) {
if (FlxG.mouse.overlaps(strumLine.healthIcon) && FlxG.mouse.justPressed) {
draggingObj = strumLine;
strumLine.dragging = true;
draggingOffset = FlxG.mouse.x - strumLine.button.x;
__pastStrumlines = members.copy();
break;
}
}
if (draggingObj != null)
draggingObj.x = FlxG.mouse.x - draggingOffset;
this.sort(function(o, a, b) return FlxSort.byValues(o, a.x, b.x), -1);
for (i=>strum in members)
if (!strum.dragging) strum.x = CoolUtil.fpsLerp(strum.x, 160 * i, 0.3);
Charter.instance.eventsBackdrop.x = members[0].button.x - Charter.instance.eventsBackdrop.width;
if (FlxG.mouse.justReleased && draggingObj != null) {
draggingObj.dragging = false;
draggingObj = null;
// Fix Events that use strumline param
for (i in Charter.instance.eventsGroup.members) {
for (j in i.events) {
var paramTypes:Array<EventParamInfo> = EventsData.getEventParams(j.name);
for (i => param in paramTypes) {
if (param.type != TStrumLine) continue;
j.params[i] = Charter.instance.strumLines.members.indexOf(__pastStrumlines[j.params[i]]);
}
}
}
__pastStrumlines = null;
}
}
}
@@ -1,5 +1,6 @@
package funkin.editors.charter;
import funkin.backend.chart.EventsData;
import funkin.game.Character;
import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
import funkin.editors.ui.UITopMenu.UITopMenuButton;
@@ -38,32 +39,12 @@ class CharterStrumline extends UISprite {
button = new CharterStrumlineButton(this);
members.push(button);
}
var __pastStrumlines:Array<CharterStrumline>;
public override function update(elapsed:Float) {
if (healthIcon != null)
healthIcon.follow(this, ((40 * 4) - healthIcon.width) / 2, 50);
button.follow(this, 0, 95);
super.update(elapsed);
if (FlxG.mouse.overlaps(healthIcon) && FlxG.mouse.justPressed) {
dragging = true;
trace(__pastStrumlines = Charter.instance.strumLines.members.copy());
}
if (dragging) x = FlxG.mouse.x - 80;
if (FlxG.mouse.justReleased && dragging) {
dragging = false;
/*if (FlxG.keys.pressed.ALT) {
for (i in Charter.instance.notesGroup.members) {
trace(i.realId);
}
}*/
for (i in Charter.instance.eventsGroup.members) {
for (j in i.events)
if (j.name == "Camera Movement" && !FlxG.keys.pressed.SHIFT)
j.params[0] = Charter.instance.strumLines.members.indexOf(__pastStrumlines[j.params[0]]);
i.refreshEventIcons();
}
}
}
public function updateInfo() {