selection box

This commit is contained in:
Yoshman29
2023-03-21 14:17:19 +01:00
parent fef21a0d2d
commit 8bf522444b
9 changed files with 151 additions and 40 deletions
Binary file not shown.
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="button.png">
<!-- Created without animate lol i wrote this-->
<SubTexture name="normal-topleft" x="0" y="0" width="4" height="4"/>
<SubTexture name="normal-top" x="4" y="0" width="8" height="4"/>
<SubTexture name="normal-topright" x="12" y="0" width="4" height="4"/>
<SubTexture name="normal-middleleft" x="0" y="4" width="4" height="8"/>
<SubTexture name="normal-middle" x="4" y="4" width="8" height="8"/>
<SubTexture name="normal-middleright" x="12" y="4" width="4" height="8"/>
<SubTexture name="normal-bottomleft" x="0" y="12" width="4" height="4"/>
<SubTexture name="normal-bottom" x="4" y="12" width="8" height="4"/>
<SubTexture name="normal-bottomright" x="12" y="12" width="4" height="4"/>
</TextureAtlas>
+1 -1
View File
@@ -1 +1 @@
2678
2687
+74 -11
View File
@@ -1,5 +1,6 @@
package funkin.editors.charter;
import flixel.math.FlxPoint;
import funkin.editors.charter.CharterBackdrop.CharterBackdropDummy;
import funkin.system.Conductor;
import funkin.chart.*;
@@ -45,6 +46,8 @@ class Charter extends UIState {
public var charterCamera:FlxCamera;
// camera for the ui
public var uiCamera:FlxCamera;
// selection box for the ui
public var selectionBox:UISliceSprite;
public var selection:Array<CharterNote> = [];
@@ -150,10 +153,16 @@ class Charter extends UIState {
gridBackdrop = new CharterBackdrop();
notesGroup.cameras = gridBackdrop.cameras = [charterCamera];
add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrop));
selectionBox = new UISliceSprite(0, 0, 2, 2, 'editors/ui/selection');
selectionBox.visible = false;
selectionBox.scrollFactor.set(1, 1);
selectionBox.incorporeal = true;
selectionBox.cameras = notesGroup.cameras = gridBackdrop.cameras = [charterCamera];
topMenuSpr = new UITopMenu(topMenu);
topMenuSpr.cameras = uiGroup.cameras = [uiCamera];
@@ -162,6 +171,7 @@ class Charter extends UIState {
// adds grid and notes so that they're ALWAYS behind the UI
add(gridBackdrop);
add(notesGroup);
add(selectionBox);
// add the ui group
add(uiGroup);
// add the top menu last OUT of the ui group so that it stays on top
@@ -184,11 +194,17 @@ class Charter extends UIState {
}
}
public override function update(elapsed:Float) {
// TODO: do optimization like NoteGroup
notesGroup.forEach(function(n) {
/**
* NOTE AND CHARTER GRID LOGIC HERE
*/
#if REGION
var selectionBoxEnabled:Bool = false;
var dragStartPos:FlxPoint = new FlxPoint();
public function updateNoteLogic(elapsed:Float) {
notesGroup.forEach(function(n) {
n.selected = false;
if (n.hovered) {
if (n.hovered && !selectionBoxEnabled) {
if (FlxG.mouse.justReleased) {
if (FlxG.keys.pressed.CONTROL)
selection.push(n);
@@ -205,8 +221,55 @@ class Charter extends UIState {
for(n in selection)
n.selected = true;
if (gridBackdropDummy.hovered && FlxG.mouse.justReleasedRight)
openContextMenu(topMenu[2].childs);
if (gridBackdropDummy.hovered || (selectionBoxEnabled && gridBackdropDummy.hoveredByChild)) {
var mousePos = FlxG.mouse.getWorldPosition(charterCamera);
if (FlxG.mouse.justPressed) {
selectionBoxEnabled = false;
FlxG.mouse.getWorldPosition(charterCamera, dragStartPos);
}
if (FlxG.mouse.pressed) {
if (Math.abs(mousePos.x - dragStartPos.x) > 20 || Math.abs(mousePos.y - dragStartPos.y) > 20) {
selectionBoxEnabled = true;
}
if (selectionBoxEnabled) {
selectionBox.x = Math.min(mousePos.x, dragStartPos.x);
selectionBox.y = Math.min(mousePos.y, dragStartPos.y);
selectionBox.bWidth = Std.int(Math.abs(mousePos.x - dragStartPos.x));
selectionBox.bHeight = Std.int(Math.abs(mousePos.y - dragStartPos.y));
}
}
if (FlxG.mouse.justReleased) {
if (selectionBoxEnabled) {
var minX = Std.int(Math.round(selectionBox.x / 40));
var minY = Math.round(selectionBox.y / 40) - 1;
var maxX = Std.int(Math.round((selectionBox.x + selectionBox.bWidth) / 40));
var maxY = Math.round((selectionBox.y + selectionBox.bHeight) / 40);
selection = [];
notesGroup.forEach(function(n) {
if (n.id >= minX && n.id <= maxX && n.step >= minY && n.step <= maxY)
selection.push(n);
});
selectionBoxEnabled = false;
} else {
// place note
var note = new CharterNote();
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Std.int(mousePos.y / 40), Std.int(mousePos.x / 40), 0, 0);
notesGroup.add(note);
selection = [note];
}
}
if (FlxG.mouse.justReleasedRight)
openContextMenu(topMenu[2].childs);
}
selectionBox.visible = selectionBoxEnabled;
}
#end
public override function update(elapsed:Float) {
// TODO: do optimization like NoteGroup
updateNoteLogic(elapsed);
super.update(elapsed);
@@ -215,13 +278,13 @@ class Charter extends UIState {
// TODO: canTypeText in case an ui input element is focused
if (true) {
if (controls.LEFT)
FlxG.camera.scroll.x -= 100 * elapsed;
FlxG.camera.scroll.x -= 250 * elapsed;
if (controls.RIGHT)
FlxG.camera.scroll.x += 100 * elapsed;
FlxG.camera.scroll.x += 250 * elapsed;
if (controls.UP)
FlxG.camera.scroll.y -= 100 * elapsed;
FlxG.camera.scroll.y -= 250 * elapsed;
if (controls.DOWN)
FlxG.camera.scroll.y += 100 * elapsed;
FlxG.camera.scroll.y += 250 * elapsed;
if (FlxG.keys.justPressed.DELETE)
_edit_delete();
@@ -36,6 +36,7 @@ class CharterBackdropDummy extends UISprite {
super();
this.parent = parent;
cameras = parent.cameras;
scrollFactor.set(1, 0);
}
public override function updateButton() {
+13 -1
View File
@@ -22,7 +22,18 @@ class CharterNote extends UISprite {
cursor = BUTTON;
}
public var step:Float;
public var id:Int;
public var susLength:Float;
public var type:Int;
public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0) {
this.step = step;
this.id = id;
this.susLength = susLength;
this.type = type;
x = id * 40;
y = step * 40;
@@ -42,6 +53,7 @@ class CharterNote extends UISprite {
public override function update(elapsed:Float) {
super.update(elapsed);
colorTransform.redMultiplier = colorTransform.greenMultiplier = colorTransform.blueMultiplier = selected ? 0.75 : 1;
colorTransform.redOffset = colorTransform.greenOffset = colorTransform.blueOffset = selected ? 96 : 0;
colorTransform.redOffset = colorTransform.greenOffset = selected ? 96 : 0;
colorTransform.blueOffset = selected ? 168 : 0;
}
}
+7 -1
View File
@@ -67,6 +67,12 @@ class UIContextMenu extends MusicBeatSubstate {
}
bg.bWidth = maxW + 8;
bg.bHeight = Std.int(lastY - bg.y + 4);
if (bg.y + bg.bHeight > FlxG.height) {
bg.y -= bg.bHeight;
for(o in contextMenuOptions)
o.y -= bg.bHeight;
}
}
public function select(option:UIContextMenuOption) {
@@ -123,7 +129,7 @@ class UIContextMenuOptionSpr extends UISliceSprite {
public override function draw() {
alpha = hovered ? 1 : 0;
label.follow(this, 20, 0);
label.follow(this, 20, 2);
super.draw();
}
+36 -25
View File
@@ -7,6 +7,8 @@ class UISliceSprite extends UISprite {
public var bHeight:Int = 20;
public var framesOffset:Int = 0;
public var incorporeal:Bool = false;
public function new(x:Float, y:Float, w:Int, h:Int, path:String) {
super(x, y);
@@ -15,6 +17,7 @@ class UISliceSprite extends UISprite {
}
public override function updateButton() {
if (incorporeal) return;
__rect.x = x;
__rect.y = y;
__rect.width = bWidth;
@@ -41,7 +44,7 @@ class UISliceSprite extends UISprite {
var bottom:FlxFrame = frames.frames[framesOffset + 7];
var bottomright:FlxFrame = frames.frames[framesOffset + 8];
@:privateAccess {
@:privateAccess if (visible) {
// TOP LEFT
frame = topleft;
setPosition(x, y);
@@ -49,10 +52,12 @@ class UISliceSprite extends UISprite {
super.drawSuper();
// TOP
frame = top;
setPosition(x + topleft.frame.width, y);
__setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height);
super.drawSuper();
if (bWidth > topleft.frame.width + topright.frame.width) {
frame = top;
setPosition(x + topleft.frame.width, y);
__setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height);
super.drawSuper();
}
// TOP RIGHT
frame = topright;
@@ -61,22 +66,26 @@ class UISliceSprite extends UISprite {
super.drawSuper();
// MIDDLE LEFT
frame = middleleft;
setPosition(x, y + top.frame.height);
__setSize(middleleft.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
// MIDDLE
frame = middle;
setPosition(x + topleft.frame.width, y + top.frame.height);
__setSize(bWidth - middleleft.frame.width - middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
if (bHeight > top.frame.height + bottom.frame.height) {
frame = middleleft;
setPosition(x, y + top.frame.height);
__setSize(middleleft.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
if (bWidth > middleleft.frame.width + middleright.frame.width) {
// MIDDLE
frame = middle;
setPosition(x + topleft.frame.width, y + top.frame.height);
__setSize(bWidth - middleleft.frame.width - middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
}
// MIDDLE RIGHT
frame = middleright;
setPosition(x + bWidth - topright.frame.width, y + top.frame.height);
__setSize(middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
// MIDDLE RIGHT
frame = middleright;
setPosition(x + bWidth - topright.frame.width, y + top.frame.height);
__setSize(middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
super.drawSuper();
}
// BOTTOM LEFT
frame = bottomleft;
@@ -84,11 +93,13 @@ class UISliceSprite extends UISprite {
__setSize(bottomleft.frame.width, bottomleft.frame.height);
super.drawSuper();
// BOTTOM
frame = bottom;
setPosition(x + bottomleft.frame.width, y + bHeight - bottom.frame.height);
__setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height);
super.drawSuper();
if (bWidth > bottomleft.frame.width + bottomright.frame.width) {
// BOTTOM
frame = bottom;
setPosition(x + bottomleft.frame.width, y + bHeight - bottom.frame.height);
__setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height);
super.drawSuper();
}
// BOTTOM RIGHT
frame = bottomright;
+4 -1
View File
@@ -1,5 +1,6 @@
package funkin.options;
import flixel.FlxState;
import funkin.ui.FunkinText;
import flixel.tweens.FlxTween;
import funkin.menus.MainMenuState;
@@ -16,6 +17,8 @@ class TreeMenu extends MusicBeatState {
public var pathDesc:FunkinText;
public var pathBG:FlxSprite;
public var lastState:Class<FlxState> = Type.getClass(FlxG.state);
public function new() {
super();
}
@@ -76,7 +79,7 @@ class TreeMenu extends MusicBeatState {
}
public function exit() {
FlxG.switchState(new MainMenuState());
FlxG.switchState((lastState != null) ? Type.createInstance(lastState, []) : new MainMenuState());
}
public function onMenuClose(m:OptionsScreen) {