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

ZIndex for objects #15228

Open
wants to merge 22 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a40393e
zIndex and DCE
superEVILFACE Aug 2, 2024
48996f8
yea
superEVILFACE Aug 2, 2024
cf52595
change lua order functions
superEVILFACE Aug 2, 2024
c27c528
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 2, 2024
5d9966e
Update FunkinLua.hx
superEVILFACE Aug 2, 2024
9fa61c5
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 3, 2024
773e604
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 3, 2024
e4a2892
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 3, 2024
b6246fd
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 3, 2024
2b95710
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 3, 2024
f145df3
Merge branch 'experimental' into experimental
superEVILFACE Aug 4, 2024
28b673e
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 4, 2024
12b14f1
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 4, 2024
f11ea59
tankman bg
superEVILFACE Aug 5, 2024
2a70e75
spooky bg
superEVILFACE Aug 5, 2024
77b2770
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 5, 2024
a24f2ee
moved sort function to coolutil, and enabled dce
superEVILFACE Aug 5, 2024
629bd3e
Merge branch 'ShadowMario:experimental' into experimental
superEVILFACE Aug 5, 2024
9f2b8fb
gulp
superEVILFACE Aug 5, 2024
b4fa93e
gulp part 2
superEVILFACE Aug 5, 2024
c174ce2
mall bg
superEVILFACE Aug 6, 2024
92d0845
school
superEVILFACE Aug 6, 2024
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
3 changes: 3 additions & 0 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
<haxeflag name="--macro" value="allowPackage('flash')" />
<haxeflag name="--macro" value="include('my.pack')" />

<!-- zIndex field -->
<haxeflag name="--macro" value="addMetadata('@:build(macro.FlxMacro.buildFlxBasic())', 'flixel.FlxBasic')" />

<!-- _________________________________ Custom _______________________________ -->

<assets path='art/iconOG.png' rename='icon.png' if="linux" />
Expand Down
12 changes: 12 additions & 0 deletions source/backend/CoolUtil.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package backend;

import flixel.FlxBasic;
import flixel.util.FlxSort;
import openfl.utils.Assets;
import lime.utils.Assets as LimeAssets;

Expand Down Expand Up @@ -155,4 +157,14 @@ class CoolUtil
text.borderStyle = NONE;
}
}

/**
* Utility functions related to sorting.
*/

public static inline function byZIndex(order:Int, a:FlxBasic, b:FlxBasic):Int
{
if (a == null || b == null) return 0;
return FlxSort.byValues(order, a.zIndex, b.zIndex);
}
}
10 changes: 10 additions & 0 deletions source/backend/MusicBeatState.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package backend;

import flixel.FlxState;
import flixel.util.FlxSort;
import backend.PsychCamera;
import backend.CoolUtil;

class MusicBeatState extends FlxState
{
Expand Down Expand Up @@ -199,6 +201,14 @@ class MusicBeatState extends FlxState
});
}

/**
* Refreshes the stage, by redoing the render order of all props.
* It does this based on the `zIndex` of each prop.
*/
public function refresh() {
sort(CoolUtil.byZIndex, FlxSort.ASCENDING);
}

function stagesFunc(func:BaseStage->Void)
{
for (stage in stages)
Expand Down
10 changes: 10 additions & 0 deletions source/backend/MusicBeatSubstate.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package backend;

import flixel.FlxSubState;
import flixel.util.FlxSort;
import backend.CoolUtil;

class MusicBeatSubstate extends FlxSubState
{
Expand Down Expand Up @@ -114,6 +116,14 @@ class MusicBeatSubstate extends FlxSubState
{
//yep, you guessed it, nothing again, dumbass
}

/**
* Refreshes the stage, by redoing the render order of all props.
* It does this based on the `zIndex` of each prop.
*/
public function refresh() {
sort(CoolUtil.byZIndex, FlxSort.ASCENDING);
}

function getBeatsOnSection()
{
Expand Down
35 changes: 35 additions & 0 deletions source/macro/FlxMacro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package macro;

#if macro
class FlxMacro
{
/**
* A macro to be called targeting the `FlxBasic` class.
* @return An array of fields that the class contains.
*/
public static macro function buildFlxBasic():Array<haxe.macro.Expr.Field>
{
var pos:haxe.macro.Expr.Position = haxe.macro.Context.currentPos();
// The FlxBasic class. We can add new properties to this class.
var cls:haxe.macro.Type.ClassType = haxe.macro.Context.getLocalClass().get();
// The fields of the FlxClass.
var fields:Array<haxe.macro.Expr.Field> = haxe.macro.Context.getBuildFields();

// haxe.macro.Context.info('[INFO] ${cls.name}: Adding zIndex attribute...', pos);

// Here, we add the zIndex attribute to all FlxBasic objects.
// This has no functional code tied to it, but it can be used as a target value
// for the FlxTypedGroup.sort method, to rearrange the objects in the scene.
fields = fields.concat([
{
name: "zIndex", // Field name.
access: [haxe.macro.Expr.Access.APublic], // Access level
kind: haxe.macro.Expr.FieldType.FVar(macro :Int, macro $v{0}), // Variable type and default value
pos: pos, // The field's position in code.
}
]);

return fields;
}
}
#end
12 changes: 6 additions & 6 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,8 @@ class FunkinLua {
}

if(leObj != null)
{
return LuaUtils.getTargetInstance().members.indexOf(leObj);
}
return leObj.zIndex;

luaTrace("getObjectOrder: Object " + obj + " doesn't exist!", false, false, FlxColor.RED);
return -1;
});
Expand All @@ -516,10 +515,11 @@ class FunkinLua {
}

if(leObj != null) {
LuaUtils.getTargetInstance().remove(leObj, true);
LuaUtils.getTargetInstance().insert(position, leObj);
leObj.zIndex = position;
cast(LuaUtils.getTargetInstance(), MusicBeatState).refresh();
return;
}

luaTrace("setObjectOrder: Object " + obj + " doesn't exist!", false, false, FlxColor.RED);
});

Expand Down Expand Up @@ -1838,4 +1838,4 @@ class FunkinLua {
return false;
}
}
#end
#end
5 changes: 5 additions & 0 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ class PlayState extends MusicBeatState
girlfriendCameraOffset = [0, 0];

boyfriendGroup = new FlxSpriteGroup(BF_X, BF_Y);
boyfriendGroup.zIndex = 300;
dadGroup = new FlxSpriteGroup(DAD_X, DAD_Y);
dadGroup.zIndex = 200;
gfGroup = new FlxSpriteGroup(GF_X, GF_Y);
gfGroup.zIndex = 100;

switch (curStage)
{
Expand Down Expand Up @@ -620,6 +623,8 @@ class PlayState extends MusicBeatState
cachePopUpScore();

if(eventNotes.length < 1) checkEventNote();

refresh();
}

function set_songSpeed(value:Float):Float
Expand Down
8 changes: 8 additions & 0 deletions source/states/stages/Mall.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@ class Mall extends BaseStage
var bg:BGSprite = new BGSprite('christmas/bgWalls', -1000, -500, 0.2, 0.2);
bg.setGraphicSize(Std.int(bg.width * 0.8));
bg.updateHitbox();
bg.zIndex = 10;
add(bg);

if(!ClientPrefs.data.lowQuality) {
upperBoppers = new BGSprite('christmas/upperBop', -240, -90, 0.33, 0.33, ['Upper Crowd Bob']);
upperBoppers.setGraphicSize(Std.int(upperBoppers.width * 0.85));
upperBoppers.updateHitbox();
upperBoppers.zIndex = 20;
add(upperBoppers);

var bgEscalator:BGSprite = new BGSprite('christmas/bgEscalator', -1100, -600, 0.3, 0.3);
bgEscalator.setGraphicSize(Std.int(bgEscalator.width * 0.9));
bgEscalator.updateHitbox();
bgEscalator.zIndex = 30;
add(bgEscalator);
}

var tree:BGSprite = new BGSprite('christmas/christmasTree', 370, -250, 0.40, 0.40);
tree.zIndex = 40;
add(tree);

bottomBoppers = new MallCrowd(-300, 140);
bottomBoppers.zIndex = 50;
add(bottomBoppers);

var fgSnow:BGSprite = new BGSprite('christmas/fgSnow', -600, 700);
fgSnow.zIndex = 60;
add(fgSnow);

santa = new BGSprite('christmas/santa', -840, 150, 1, 1, ['santa idle in fear']);
santa.zIndex = 210;
add(santa);
Paths.sound('Lights_Shut_off');
setDefaultGF('gf-christmas');
Expand Down Expand Up @@ -87,6 +94,7 @@ class Mall extends BaseStage
var blackShit:FlxSprite = new FlxSprite(-FlxG.width * FlxG.camera.zoom,
-FlxG.height * FlxG.camera.zoom).makeGraphic(FlxG.width * 3, FlxG.height * 3, FlxColor.BLACK);
blackShit.scrollFactor.set();
blackShit.zIndex = 1000;
add(blackShit);
camHUD.visible = false;

Expand Down
4 changes: 4 additions & 0 deletions source/states/stages/MallEvil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class MallEvil extends BaseStage
var bg:BGSprite = new BGSprite('christmas/evilBG', -400, -500, 0.2, 0.2);
bg.setGraphicSize(Std.int(bg.width * 0.8));
bg.updateHitbox();
bg.zIndex = 10;
add(bg);

var evilTree:BGSprite = new BGSprite('christmas/evilTree', 300, -300, 0.2, 0.2);
evilTree.zIndex = 20;
add(evilTree);

var evilSnow:BGSprite = new BGSprite('christmas/evilSnow', -200, 700);
evilSnow.zIndex = 20;
add(evilSnow);
setDefaultGF('gf-christmas');

Expand All @@ -41,6 +44,7 @@ class MallEvil extends BaseStage
// blackout at the start
var blackScreen:FlxSprite = new FlxSprite().makeGraphic(Std.int(FlxG.width * 2), Std.int(FlxG.height * 2), FlxColor.BLACK);
blackScreen.scrollFactor.set();
blackScreen.zIndex = 1000;
add(blackScreen);

FlxTween.tween(blackScreen, {alpha: 0}, 0.7, {
Expand Down
8 changes: 8 additions & 0 deletions source/states/stages/School.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ class School extends BaseStage
if(_song.gameOverChar == null || _song.gameOverChar.trim().length < 1) GameOverSubstate.characterName = 'bf-pixel-dead';

var bgSky:BGSprite = new BGSprite('weeb/weebSky', 0, 0, 0.1, 0.1);
bgSky.zIndex = 10;
add(bgSky);
bgSky.antialiasing = false;

var repositionShit = -200;

var bgSchool:BGSprite = new BGSprite('weeb/weebSchool', repositionShit, 0, 0.6, 0.90);
bgSchool.zIndex = 20;
add(bgSchool);
bgSchool.antialiasing = false;

var bgStreet:BGSprite = new BGSprite('weeb/weebStreet', repositionShit, 0, 0.95, 0.95);
bgStreet.zIndex = 30;
add(bgStreet);
bgStreet.antialiasing = false;

Expand All @@ -36,6 +39,7 @@ class School extends BaseStage
var fgTrees:BGSprite = new BGSprite('weeb/weebTreesBack', repositionShit + 170, 130, 0.9, 0.9);
fgTrees.setGraphicSize(Std.int(widShit * 0.8));
fgTrees.updateHitbox();
fgTrees.zIndex = 40;
add(fgTrees);
fgTrees.antialiasing = false;
}
Expand All @@ -45,13 +49,15 @@ class School extends BaseStage
bgTrees.animation.add('treeLoop', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], 12);
bgTrees.animation.play('treeLoop');
bgTrees.scrollFactor.set(0.85, 0.85);
bgTrees.zIndex = 60;
add(bgTrees);
bgTrees.antialiasing = false;

if(!ClientPrefs.data.lowQuality) {
var treeLeaves:BGSprite = new BGSprite('weeb/petals', repositionShit, -40, 0.85, 0.85, ['PETALS ALL'], true);
treeLeaves.setGraphicSize(widShit);
treeLeaves.updateHitbox();
treeLeaves.zIndex = 70;
add(treeLeaves);
treeLeaves.antialiasing = false;
}
Expand All @@ -69,6 +75,7 @@ class School extends BaseStage
if(!ClientPrefs.data.lowQuality) {
bgGirls = new BackgroundGirls(-100, 190);
bgGirls.scrollFactor.set(0.9, 0.9);
bgGirls.zIndex = 80;
add(bgGirls);
}
setDefaultGF('gf-pixel');
Expand Down Expand Up @@ -140,6 +147,7 @@ class School extends BaseStage
inCutscene = true;
var black:FlxSprite = new FlxSprite(-100, -100).makeGraphic(FlxG.width * 2, FlxG.height * 2, FlxColor.BLACK);
black.scrollFactor.set();
black.zIndex = 1000;
if(songName == 'senpai') add(black);

new FlxTimer().start(0.3, function(tmr:FlxTimer)
Expand Down
15 changes: 7 additions & 8 deletions source/states/stages/Spooky.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class Spooky extends BaseStage
}
add(halloweenBG);

halloweenWhite = new BGSprite(null, -800, -400, 0, 0);
halloweenWhite.makeGraphic(Std.int(FlxG.width * 2), Std.int(FlxG.height * 2), FlxColor.WHITE);
halloweenWhite.alpha = 0;
halloweenWhite.blend = ADD;
add(halloweenWhite);

//PRECACHE SOUNDS
Paths.sound('thunder_1');
Paths.sound('thunder_2');
Expand All @@ -27,14 +33,6 @@ class Spooky extends BaseStage
}
}
}
override function createPost()
{
halloweenWhite = new BGSprite(null, -800, -400, 0, 0);
halloweenWhite.makeGraphic(Std.int(FlxG.width * 2), Std.int(FlxG.height * 2), FlxColor.WHITE);
halloweenWhite.alpha = 0;
halloweenWhite.blend = ADD;
add(halloweenWhite);
}

var lightningStrikeBeat:Int = 0;
var lightningOffset:Int = 8;
Expand Down Expand Up @@ -96,6 +94,7 @@ class Spooky extends BaseStage
var whiteScreen:FlxSprite = new FlxSprite().makeGraphic(Std.int(FlxG.width * 2), Std.int(FlxG.height * 2), FlxColor.WHITE);
whiteScreen.scrollFactor.set();
whiteScreen.blend = ADD;
whiteScreen.zIndex = 1000;
add(whiteScreen);
FlxTween.tween(whiteScreen, {alpha: 0}, 1, {
startDelay: 0.1,
Expand Down
5 changes: 5 additions & 0 deletions source/states/stages/StageWeek1.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ class StageWeek1 extends BaseStage
override function create()
{
var bg:BGSprite = new BGSprite('stageback', -600, -200, 0.9, 0.9);
bg.zIndex = 10;
add(bg);

var stageFront:BGSprite = new BGSprite('stagefront', -650, 600, 0.9, 0.9);
stageFront.setGraphicSize(Std.int(stageFront.width * 1.1));
stageFront.updateHitbox();
stageFront.zIndex = 20;
add(stageFront);
if(!ClientPrefs.data.lowQuality) {
var stageLight:BGSprite = new BGSprite('stage_light', -125, -100, 0.9, 0.9);
stageLight.setGraphicSize(Std.int(stageLight.width * 1.1));
stageLight.updateHitbox();
stageLight.zIndex = 30;
add(stageLight);
var stageLight:BGSprite = new BGSprite('stage_light', 1225, -100, 0.9, 0.9);
stageLight.setGraphicSize(Std.int(stageLight.width * 1.1));
stageLight.updateHitbox();
stageLight.flipX = true;
stageLight.zIndex = 30;
add(stageLight);

var stageCurtains:BGSprite = new BGSprite('stagecurtains', -500, -300, 1.3, 1.3);
stageCurtains.setGraphicSize(Std.int(stageCurtains.width * 0.9));
stageCurtains.updateHitbox();
stageCurtains.zIndex = 30;
add(stageCurtains);
}
}
Expand Down
Loading