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

[BUGFIX] Fix the Stage Editor removing the object's sprite upon hovering with mouse (+some other stuff) #3974

Open
wants to merge 2 commits into
base: develop
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
22 changes: 13 additions & 9 deletions source/funkin/ui/debug/stageeditor/StageEditorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class StageEditorState extends UIState

function set_selectedSprite(value:StageEditorObject)
{
selectedSprite?.selectedShader.setAmount(0);
this.selectedSprite = value;
updateDialog(StageEditorDialogType.OBJECT);

Expand Down Expand Up @@ -617,17 +618,19 @@ class StageEditorState extends UIState

if (moveMode == "assets")
{
for (spr in spriteArray)
if (selectedSprite != null && !FlxG.mouse.overlaps(selectedSprite) && FlxG.mouse.justPressed && !isCursorOverHaxeUI)
{
spr.active = spr.isOnScreen();
selectedSprite = null;
}

if (spr.pixelsOverlapPoint(FlxG.mouse.getWorldPosition()))
for (spr in spriteArray)
{
if (FlxG.mouse.overlaps(spr))
{
if (spr.visible && !FlxG.keys.pressed.SHIFT) nameTxt.text = spr.name;

if (FlxG.mouse.justPressed && allowInput && spr.visible && !FlxG.keys.pressed.SHIFT && !isCursorOverHaxeUI)
{
selectedSprite.selectedShader.setAmount(0);
selectedSprite = spr;
updateDialog(StageEditorDialogType.OBJECT);
}
Expand Down Expand Up @@ -1138,8 +1141,6 @@ class StageEditorState extends UIState
currentFile = path;
}, null, stageName + "." + FileUtil.FILE_EXTENSION_INFO_FNFS.extension);

bitmaps.clear();

case "save stage":
if (currentFile == "")
{
Expand All @@ -1159,8 +1160,7 @@ class StageEditorState extends UIState

saved = true;

updateRecentFiles();
bitmaps.clear();
reloadRecentFiles();

case "open stage":
if (!saved)
Expand Down Expand Up @@ -1212,7 +1212,10 @@ class StageEditorState extends UIState
FlxG.sound.music.stop();

case "switch mode":
if (!testingMode) moveMode = (moveMode == "assets" ? "chars" : "assets");
if (testingMode) return;
moveMode = (moveMode == "assets" ? "chars" : "assets");

selectedSprite?.selectedShader.setAmount((moveMode == "assets" ? 1 : 0));

case "switch focus":
if (testingMode)
Expand Down Expand Up @@ -1288,6 +1291,7 @@ class StageEditorState extends UIState

if (!testingMode) menubarItemWindowObject.selected = menubarItemWindowCharacter.selected = menubarItemWindowStage.selected = false;

selectedSprite?.selectedShader.setAmount((testingMode ? (moveMode == "assets" ? 1 : 0) : 0));
testingMode = !testingMode;

case "clear assets":
Expand Down
34 changes: 30 additions & 4 deletions source/funkin/ui/debug/stageeditor/handlers/AssetDataHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AssetDataHandler
startingAnimation: obj.startingAnimation,
animType: "sparrow", // automatically making sparrow atlases yeah
angle: obj.angle,
flipX: obj.flipX,
flipY: obj.flipY,
blend: obj.blend == null ? "" : Std.string(obj.blend),
color: obj.color.toWebString(),
xmlData: obj.generateXML()
Expand Down Expand Up @@ -81,8 +83,20 @@ class AssetDataHandler
{
if (data.bitmap != null)
{
var bitToLoad = state.addBitmap(data.bitmap.clone());
object.loadGraphic(state.bitmaps[bitToLoad]);
if (data.animations != null && data.animations.length > 0)
{
var bitToLoad = state.addBitmap(data.bitmap.clone());
object.frames = flixel.graphics.frames.FlxAtlasFrames.fromSparrow(state.bitmaps[bitToLoad], data.xmlData);
}
else if (areTheseBitmapsEqual(data.bitmap, getDefaultGraphic()))
{
object.loadGraphic(getDefaultGraphic());
}
else
{
var bitToLoad = state.addBitmap(data.bitmap.clone());
object.loadGraphic(state.bitmaps[bitToLoad]);
}
}
else
{
Expand Down Expand Up @@ -168,10 +182,22 @@ class AssetDataHandler
// the last check is for if the only frame is the standard graphic frame
if (obj == null || obj.frames.frames.length == 0 || obj.frames.frames[0].name == null) return "";

var bitmapName = "";
for (name => bitmap in state.bitmaps)
{
if (areTheseBitmapsEqual(bitmap, obj.pixels))
{
bitmapName = name;
break;
}
}

if (bitmapName == "") return "";

var xml = [
"<!--This XML File was automatically generated by StageEditorEngine, in order to make Funkin' be able to load it.-->",
"<!--This XML File was automatically generated by the Stage Editor.-->",
'<?xml version="1.0" encoding="UTF-8"?>',
'<TextureAtlas imagePath="${obj.toData(false).assetPath}.png" width="${obj.pixels.width}" height="${obj.pixels.height}">'
'<TextureAtlas imagePath="${haxe.io.Path.withoutDirectory(bitmapName)}.png" width="${obj.pixels.width}" height="${obj.pixels.height}">'
].join("\n");

for (daFrame in obj.frames.frames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class StageDataHandler
animations: data.animations,
startingAnimation: data.startingAnimation,
animType: data.animType,
flipX: data.flipX,
flipY: data.flipY,
angle: data.angle,
blend: data.blend,
color: data.assetPath.startsWith("#") ? "#FFFFFF" : data.color
Expand Down Expand Up @@ -210,6 +212,8 @@ class StageDataHandler
scroll: objData.scroll.copy(),
color: objData.color,
blend: objData.blend,
flipX: objData.flipX,
flipY: objData.flipY,
startingAnimation: objData.startingAnimation,
xmlData: xmls[objData.assetPath] ?? ""
});
Expand Down Expand Up @@ -309,6 +313,8 @@ class StageDataHandler
scroll: objData.scroll.copy(),
color: objData.color,
blend: objData.blend,
flipX: objData.flipX,
flipY: objData.flipY,
startingAnimation: objData.startingAnimation,
xmlData: Assets.exists(Paths.file("images/" + objData.assetPath + ".xml")) ? Assets.getText(Paths.file("images/" + objData.assetPath + ".xml")) : ""
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
var objectImagePreview:Image;
var objectLoadImageButton:Button;
var objectLoadInternetButton:Button;
var objectDownloadImageButton:Button;
var objectResetImageButton:Button;
var objectZIdxStepper:NumberStepper;
var objectZIdxReset:Button;
Expand Down Expand Up @@ -86,6 +85,8 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox

var objectMiscAntialias:CheckBox;
var objectMiscAntialiasReset:Button;
var objectMiscFlipX:CheckBox;
var objectMiscFlipY:CheckBox;
var objectMiscFlipReset:Button;
var objectMiscBlendDrop:DropDown;
var objectMiscBlendReset:Button;
Expand Down Expand Up @@ -138,13 +139,6 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
});
}

objectDownloadImageButton.onClick = function(_) {
if (linkedObject == null) return;

FileUtil.saveFile(linkedObject.pixels.image.encode(PNG), [FileUtil.FILE_FILTER_PNG], null, null,
linkedObject.name + "-graphic.png"); // i'on need any callbacks
}

objectZIdxStepper.max = StageEditorState.MAX_Z_INDEX;
objectZIdxStepper.onChange = function(_) {
if (linkedObject != null)
Expand Down Expand Up @@ -404,6 +398,14 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
if (linkedObject != null) linkedObject.antialiasing = objectMiscAntialias.selected;
}

objectMiscFlipX.onChange = function(_) {
if (linkedObject != null) linkedObject.flipX = objectMiscFlipX.selected;
}

objectMiscFlipY.onChange = function(_) {
if (linkedObject != null) linkedObject.flipY = objectMiscFlipY.selected;
}

objectMiscBlendDrop.onChange = function(_) {
if (linkedObject != null)
linkedObject.blend = objectMiscBlendDrop.selectedItem.text == "NONE" ? null : AssetDataHandler.blendFromString(objectMiscBlendDrop.selectedItem.text);
Expand Down Expand Up @@ -453,6 +455,7 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
if (linkedObject != null)
{
linkedObject.scale.set(1, 1);
linkedObject.updateHitbox();
refresh(); // refreshes like multiple shit
}
}
Expand All @@ -474,6 +477,10 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
if (linkedObject != null) objectMiscAntialias.selected = true;
}

objectMiscFlipReset.onClick = function(_) {
if (linkedObject != null) objectMiscFlipX.selected = objectMiscFlipY.selected = false;
}

objectMiscBlendReset.onClick = function(_) {
if (linkedObject != null) objectMiscBlendDrop.selectedItem = "NORMAL";
}
Expand All @@ -493,7 +500,7 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
refresh();
}

var prevFrames:Array<FlxFrame> = [];
var prevFrames:Array<String> = [];
var prevAnims:Array<String> = [];

override public function refresh()
Expand Down Expand Up @@ -526,9 +533,11 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
if (objectScrollXSlider.pos != linkedObject.scrollFactor.x) objectScrollXSlider.pos = linkedObject.scrollFactor.x;
if (objectScrollYSlider.pos != linkedObject.scrollFactor.y) objectScrollYSlider.pos = linkedObject.scrollFactor.y;
if (objectMiscAntialias.selected != linkedObject.antialiasing) objectMiscAntialias.selected = linkedObject.antialiasing;
if (objectMiscFlipX.selected != linkedObject.flipX) objectMiscFlipX.selected = linkedObject.flipX;
if (objectMiscFlipY.selected != linkedObject.flipY) objectMiscFlipY.selected = linkedObject.flipY;

if (objectMiscColor.currentColor != Color.fromString(linkedObject.color.toHexString() ?? "white"))
objectMiscColor.currentColor = Color.fromString(linkedObject.color.toHexString());
objectMiscColor.currentColor = Color.fromString(linkedObject.color.toHexString() ?? "white");

if (objectAnimDanceBeat.pos != linkedObject.danceEvery) objectAnimDanceBeat.pos = linkedObject.danceEvery;
if (objectAnimStart.text != linkedObject.startingAnimation) objectAnimStart.text = linkedObject.startingAnimation;
Expand All @@ -537,11 +546,11 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
if (objectMiscBlendDrop.selectedItem != objBlend.toUpperCase()) objectMiscBlendDrop.selectedItem = objBlend.toUpperCase();

// ough the max
if (objectFrameImageWidth.max != linkedObject.pixels.width) objectFrameImageWidth.max = linkedObject.graphic.width;
if (objectFrameImageHeight.max != linkedObject.pixels.height) objectFrameImageHeight.max = linkedObject.graphic.height;
if (objectFrameImageWidth.max != linkedObject.pixels.width) objectFrameImageWidth.max = linkedObject.pixels.width;
if (objectFrameImageHeight.max != linkedObject.pixels.height) objectFrameImageHeight.max = linkedObject.pixels.height;

// update some anim shit
if (prevFrames != linkedObject.frames.frames.copy()) updateFrameList();
if (prevFrames != [for (f in linkedObject.frames.frames) f.name]) updateFrameList();
if (prevAnims != linkedObject.animation.getNameList().copy()) updateAnimList();
}

Expand All @@ -556,7 +565,7 @@ class StageEditorObjectToolbox extends StageEditorDefaultToolbox
{
if (fname != null) objectAnimFrameList.dataSource.add({name: fname.name, tooltip: fname.name});

prevFrames.push(fname);
prevFrames.push(fname.name);
}
}

Expand Down
Loading