From 9132120608f34c8133031e9cc0009873cfa1c180 Mon Sep 17 00:00:00 2001
From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com>
Date: Thu, 23 Mar 2023 23:56:12 +0100
Subject: [PATCH] beta zoom
---
assets/data/characters/monster-christmas.xml | 4 +-
assets/data/characters/monster.xml | 4 +-
source/funkin/editors/charter/Charter.hx | 124 ++++++++++++++-----
source/funkin/editors/charter/CharterNote.hx | 5 +-
source/funkin/editors/ui/UIContextMenu.hx | 4 +
source/funkin/editors/ui/UIState.hx | 9 +-
6 files changed, 111 insertions(+), 39 deletions(-)
diff --git a/assets/data/characters/monster-christmas.xml b/assets/data/characters/monster-christmas.xml
index 653db19f..de78dda7 100644
--- a/assets/data/characters/monster-christmas.xml
+++ b/assets/data/characters/monster-christmas.xml
@@ -2,7 +2,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/assets/data/characters/monster.xml b/assets/data/characters/monster.xml
index fe093de0..ed0da307 100644
--- a/assets/data/characters/monster.xml
+++ b/assets/data/characters/monster.xml
@@ -2,7 +2,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx
index 6d2330d9..9bb0e0eb 100644
--- a/source/funkin/editors/charter/Charter.hx
+++ b/source/funkin/editors/charter/Charter.hx
@@ -22,6 +22,11 @@ class Charter extends UIState {
private function get_chart()
return PlayState.SONG;
+ public static var instance(get, null):Charter;
+
+ private static inline function get_instance()
+ return FlxG.state is Charter ? cast FlxG.state : null;
+
/**
* CONFIG & UI (might make this customizable later)
*/
@@ -44,7 +49,7 @@ class Charter extends UIState {
/**
* ACTUAL CHART DATA
*/
- public var strumLines:Array = [];
+ public var strumLines:Array = [];
public var notesGroup:CharterNoteGroup = new CharterNoteGroup();
/**
@@ -140,6 +145,22 @@ class Charter extends UIState {
keybind: "Ctrl+Shift+Enter"
},
null,
+ {
+ label: "Zoom in",
+ keybind: "Ctrl+[+]",
+ onSelect: _chart_zoomin
+ },
+ {
+ label: "Zoom out",
+ keybind: "Ctrl+[-]",
+ onSelect: _chart_zoomout
+ },
+ {
+ label: "Reset zoom",
+ keybind: "Ctrl+[0]",
+ onSelect: _chart_zoomreset
+ },
+ null,
{
label: "Edit metadata information"
}
@@ -244,13 +265,20 @@ class Charter extends UIState {
n.updatePos(Conductor.getStepForTime(note.time), (strID * 4) + note.id, note.sLen, note.type);
notesGroup.add(n);
}
+
+ strumLines.push({
+ strumLine: strL,
+ hitsounds: true
+ });
}
}
public override function beatHit(curBeat:Int) {
super.beatHit(curBeat);
- if (Options.charterMetronomeEnabled)
- metronome.replay();
+ if (FlxG.sound.music.playing) {
+ if (Options.charterMetronomeEnabled)
+ metronome.replay();
+ }
}
/**
@@ -402,7 +430,7 @@ class Charter extends UIState {
FlxG.sound.music.pause();
vocals.pause();
} else {
- FlxG.sound.music.time = vocals.time = Conductor.songPosition;
+ vocals.time = FlxG.sound.music.time = Conductor.songPosition;
FlxG.sound.music.play();
vocals.play();
}
@@ -448,34 +476,14 @@ class Charter extends UIState {
super.update(elapsed);
- gridBackdrop.strumlinesAmount = 3;
+ if (gridBackdrop.strumlinesAmount != (gridBackdrop.strumlinesAmount = strumLines.length)) {
+ conductorFollowerSpr.scale.set(gridBackdrop.strumlinesAmount * 4 * 40, 4);
+ conductorFollowerSpr.updateHitbox();
+ }
// TODO: canTypeText in case an ui input element is focused
if (true) {
- if (FlxG.keys.justPressed.DELETE)
- _edit_delete(null);
-
- if (FlxG.keys.pressed.CONTROL) {
- if (FlxG.keys.justPressed.Y || (FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.Z)) // CTRL+Y or CTRL+SHIFT+Z
- _edit_redo(null);
- else if (FlxG.keys.justPressed.Z) // CTRL+Z
- _edit_undo(null);
- }
-
- if (FlxG.keys.justPressed.SPACE) // SPACE
- _playback_play(null);
-
- __crochet = ((60 / Conductor.bpm) * 1000);
- Conductor.songPosition -= __crochet * FlxG.mouse.wheel;
-
- if (FlxG.keys.justPressed.D)
- _playback_forward(null);
- if (FlxG.keys.justPressed.A)
- _playback_back(null);
- if (FlxG.keys.justPressed.HOME)
- _playback_start(null);
- if (FlxG.keys.justPressed.END)
- _playback_end(null);
+ handleShortcuts();
}
Conductor.songPosition = FlxMath.bound(Conductor.songPosition, 0, FlxG.sound.music.length);
@@ -485,9 +493,45 @@ class Charter extends UIState {
} else {
conductorFollowerSpr.y = lerp(conductorFollowerSpr.y, curStepFloat * 40, 1/3);
}
- charterCamera.scroll.set(conductorFollowerSpr.x + conductorFollowerSpr.scale.x - (FlxG.width / 2), conductorFollowerSpr.y - (FlxG.height * 0.5));
+ charterCamera.scroll.set(conductorFollowerSpr.x + ((conductorFollowerSpr.scale.x - FlxG.width) / 2), conductorFollowerSpr.y - (FlxG.height * 0.5));
+ charterCamera.zoom = lerp(charterCamera.zoom, __camZoom, 0.125);
}
+ public function handleShortcuts() {
+ if (FlxG.keys.justPressed.DELETE) // DELETE
+ _edit_delete(null);
+
+ if (FlxG.keys.pressed.CONTROL) {
+ if (FlxG.keys.justPressed.Y || (FlxG.keys.pressed.SHIFT && FlxG.keys.justPressed.Z)) // CTRL+Y or CTRL+SHIFT+Z
+ _edit_redo(null);
+ else if (FlxG.keys.justPressed.Z) // CTRL+Z
+ _edit_undo(null);
+ else if (FlxG.keys.justPressed.NUMPADPLUS) // CTRL+[+]
+ _chart_zoomin(null);
+ else if (FlxG.keys.justPressed.NUMPADMINUS) // CTRL+[-]
+ _chart_zoomout(null);
+ else if (FlxG.keys.justPressed.NUMPADZERO) // CTRL+[0]
+ _chart_zoomreset(null);
+ }
+
+ if (FlxG.keys.justPressed.SPACE) // SPACE
+ _playback_play(null);
+
+ __crochet = ((60 / Conductor.bpm) * 1000);
+ Conductor.songPosition -= __crochet * FlxG.mouse.wheel;
+
+ if (FlxG.keys.justPressed.D)
+ _playback_forward(null);
+ if (FlxG.keys.justPressed.A)
+ _playback_back(null);
+ if (FlxG.keys.justPressed.HOME)
+ _playback_start(null);
+ if (FlxG.keys.justPressed.END)
+ _playback_end(null);
+ }
+
+ var zoom:Float = 0;
+ var __camZoom:Float = 1;
// TOP MENU OPTIONS
#if REGION
@@ -514,11 +558,31 @@ class Charter extends UIState {
if (FlxG.sound.music.playing) return;
Conductor.songPosition = FlxG.sound.music.length;
}
+ function _chart_zoomin(_) {
+ zoom += 0.25;
+ __camZoom = Math.pow(2, zoom);
+ }
+ function _chart_zoomout(_) {
+ zoom -= 0.25;
+ __camZoom = Math.pow(2, zoom);
+ }
+ function _chart_zoomreset(_) {
+ zoom = 0;
+ __camZoom = Math.pow(2, zoom);
+ }
#end
+
+ public inline function hitsoundsEnabled(id:Int)
+ return strumLines[Std.int(id / 4)] != null && strumLines[Std.int(id / 4)].hitsounds;
}
enum CharterChange {
CPlaceNote(note:CharterNote);
CCreateNotes(notes:Array);
CDeleteNotes(notes:Array);
+}
+
+typedef CharterStrumline = {
+ var strumLine:ChartStrumLine;
+ var hitsounds:Bool;
}
\ No newline at end of file
diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx
index 6aa5ed60..a3c2d47b 100644
--- a/source/funkin/editors/charter/CharterNote.hx
+++ b/source/funkin/editors/charter/CharterNote.hx
@@ -81,9 +81,8 @@ class CharterNote extends UISprite {
if (__passed != (__passed = step < Conductor.curStepFloat)) {
alpha = __passed ? 0.6 : 1;
- if (__passed && FlxG.sound.music.playing) {
-
- }
+ if (__passed && FlxG.sound.music.playing && Charter.instance.hitsoundsEnabled(id))
+ Charter.instance.hitsound.replay();
}
colorTransform.redMultiplier = colorTransform.greenMultiplier = colorTransform.blueMultiplier = selected ? 0.75 : 1;
diff --git a/source/funkin/editors/ui/UIContextMenu.hx b/source/funkin/editors/ui/UIContextMenu.hx
index df2cb1f5..1f571364 100644
--- a/source/funkin/editors/ui/UIContextMenu.hx
+++ b/source/funkin/editors/ui/UIContextMenu.hx
@@ -35,6 +35,7 @@ class UIContextMenu extends MusicBeatSubstate {
FlxG.cameras.add(contextCam, false);
bg = new UISliceSprite(x, y, 100, 100, 'editors/ui/context-bg');
+ bg.cameras = [contextCam];
add(bg);
var lastY:Float = bg.y + 4;
@@ -48,6 +49,7 @@ class UIContextMenu extends MusicBeatSubstate {
continue;
}
var spr = new UIContextMenuOptionSpr(bg.x + 4, lastY, o, this);
+ spr.cameras = [contextCam];
lastY = spr.y + spr.bHeight;
contextMenuOptions.push(spr);
add(spr);
@@ -72,6 +74,8 @@ class UIContextMenu extends MusicBeatSubstate {
bg.y -= bg.bHeight;
for(o in contextMenuOptions)
o.y -= bg.bHeight;
+ for(o in separators)
+ o.y -= bg.bHeight;
}
}
diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx
index 8b5b8435..1bb6e6dc 100644
--- a/source/funkin/editors/ui/UIState.hx
+++ b/source/funkin/editors/ui/UIState.hx
@@ -36,9 +36,10 @@ class UIState extends MusicBeatState {
}
public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) {
- FlxG.mouse.getScreenPosition(camera, __mousePos);
+
for(camera in spr.__lastDrawCameras) {
+ var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get());
__rect.x = rect.x;
__rect.y = rect.y;
__rect.width = rect.width;
@@ -47,16 +48,20 @@ class UIState extends MusicBeatState {
__rect.x -= camera.scroll.x * spr.scrollFactor.x;
__rect.y -= camera.scroll.y * spr.scrollFactor.y;
- if (((__mousePos.x > __rect.x) && (__mousePos.x < __rect.x + rect.width)) && ((__mousePos.y > __rect.y) && (__mousePos.y < __rect.y + __rect.height))) {
+ if (((pos.x > __rect.x) && (pos.x < __rect.x + rect.width)) && ((pos.y > __rect.y) && (pos.y < __rect.y + __rect.height))) {
spr.hoveredByChild = true;
this.hoveredSprite = spr;
this.buttonHandler = buttonHandler;
+ pos.put();
return;
}
+ pos.put();
}
}
public override function tryUpdate(elapsed:Float) {
+ FlxG.mouse.getScreenPosition(FlxG.camera, __mousePos);
+
super.tryUpdate(elapsed);
if (buttonHandler != null) {