Charter drag fixed when pressing shift

This commit is contained in:
lunarcleint
2023-08-20 01:13:42 -07:00
parent e0e646a3d0
commit 9737070854
5 changed files with 27 additions and 9 deletions
+23 -7
View File
@@ -594,21 +594,31 @@ class Charter extends UIState {
});
currentCursor = HAND;
} else {
var hoverOffset:FlxPoint = FlxPoint.get();
for (s in selection)
if (s.hovered) {
hoverOffset.set(mousePos.x - s.x, mousePos.y - s.y);
break;
}
dragStartPos.set(Std.int(dragStartPos.x / 40) * 40, Std.int(dragStartPos.y / 40) * 40);
var verticalChange:Float = (mousePos.y - dragStartPos.y) / 40;
if (!FlxG.keys.pressed.SHIFT)
verticalChange = CoolUtil.floorInt(verticalChange);
var verticalChange:Float =
FlxG.keys.pressed.SHIFT ? ((mousePos.y - hoverOffset.y) - dragStartPos.y) / 40
: CoolUtil.floorInt((mousePos.y - dragStartPos.y) / 40);
var horizontalChange:Int = CoolUtil.floorInt((mousePos.x - dragStartPos.x) / 40);
var changePoint:FlxPoint = FlxPoint.get(verticalChange, horizontalChange);
trace(dragStartPos, hoverOffset,changePoint);
for (s in selection) {
if (!s.draggable) continue;
s.handleDrag(changePoint);
if (s is UISprite) cast(s, UISprite).cursor = BUTTON;
}
sortNotes();
addToUndo(CSelectionDrag(selection, changePoint.clone()));
changePoint.put();
hoverOffset.put();
gridActionType = NONE;
currentCursor = ARROW;
@@ -633,6 +643,7 @@ class Charter extends UIState {
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0);
notesGroup.add(note);
selection = [note];
sortNotes();
addToUndo(CCreateSelection([note]));
}
}
@@ -641,10 +652,12 @@ class Charter extends UIState {
// TODO: NOTE DRAGGING
if (FlxG.mouse.pressed && (Math.abs(mousePos.x - dragStartPos.x) > 5 || Math.abs(mousePos.y - dragStartPos.y) > 5)) {
var noteHovered:Bool = false;
for(n in selection) if (n.hovered) {
noteHovered = true;
break;
}
for(n in selection)
if (n.hovered) {
noteHovered = true;
break;
}
gridActionType = noteHovered ? DRAG : INVALID_DRAG;
}
}
@@ -694,6 +707,7 @@ class Charter extends UIState {
eventsGroup.remove(event, true);
event.kill();
}
sortNotes();
if (addToUndo)
this.addToUndo(CDeleteSelection([selected]));
@@ -1347,6 +1361,8 @@ typedef NoteSustainChange = {
}
interface ICharterSelectable {
public var x(default, set):Float;
public var y(default, set):Float;
public var step:Float;
public var selected:Bool;
@@ -104,6 +104,7 @@ class CharterSelection extends EditorTreeMenu {
#end
// Add to List
freeplayList.songs.insert(0, creation.meta);
main.members.insert(1, new IconOption(creation.meta.name, "Press ACCEPT to choose a difficulty to edit.", creation.meta.icon, function() {
var list:Array<OptionType> = [
for(d in creation.meta.difficulties)
@@ -201,7 +201,7 @@ class SongCreationScreen extends UISubstateWindow {
} else
saveButton.selectable = true;
saveButton.alpha = saveButton.field.alpha = saveButton.selectable ? 1 : 0.4;
super.update(elapsed);
}
@@ -123,7 +123,9 @@ class UIAudioPlayer extends UIButton {
}
}
}
spritePos.put();
}
mousePos.put();
if (FlxG.mouse.released) {
if (draggingObj == timeBar && wasPlaying)
-1
View File
@@ -39,7 +39,6 @@ class UIButton extends UISliceSprite {
public override function update(elapsed:Float) {
field.follow(this, 0, (bHeight - field.height) / 2);
if (!hovered && hasBeenPressed && FlxG.mouse.justReleased) hasBeenPressed = false;
alpha = field.alpha = selectable ? 1 : 0.4;
super.update(elapsed);
}