Skip to content

Commit

Permalink
trying a thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Jun 8, 2024
1 parent 36a990e commit 4409caf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 82 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[HIGH PRIORITY]
- Localization Support (basically done, but need to add data for languages)
- Add option for camera movement idk
- Backport stuff from FNF 0.3.X

[LOW PRIORITY]
Expand Down
13 changes: 13 additions & 0 deletions source/meta/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class CoolUtil
return FileSystem.readDirectory(FileSystem.absolutePath(path));
#end

inline public static function colorFromArray(colors:Array<Int>, ?defColors:Array<Int>):FlxColor {
colors = fixRGBColorArray(colors, defColors);
return FlxColor.fromRGB(colors[0], colors[1], colors[2], colors[3]);
}

inline public static function colorFromString(color:String):FlxColor
{
var hideChars = ~/[\t\n\r]/;
Expand All @@ -95,6 +100,14 @@ class CoolUtil
if(colorNum == null) colorNum = FlxColor.fromString('#$color');
return colorNum != null ? colorNum : FlxColor.WHITE;
}

public static function getColor(value:Dynamic, ?defValue:Array<Int>):FlxColor {
if (value == null) return FlxColor.WHITE;
if (value is Int) return value;
if (value is String) return colorFromString(value);
if (value is Array) return colorFromArray(value, defValue);
return FlxColor.WHITE;
}

inline public static function listFromString(string:String):Array<String>
return string.trim().split('\n').map(str -> str.trim());
Expand Down
25 changes: 10 additions & 15 deletions source/meta/state/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ class PlayState extends MusicBeatState
if(ClientPrefs.downScroll) timeTxt.y = FlxG.height - 44;
if(ClientPrefs.timeBarType == 'Song Name') timeTxt.text = SONG.song;

timeBar = new Bar(0, timeTxt.y + (timeTxt.height / 4), 'timeBar', function() return songPercent, 0, 1);
timeBar = new Bar(0, timeTxt.y + (timeTxt.height / 4), 'timeBar', () -> return songPercent, 0, 1);
timeBar.scrollFactor.set();
timeBar.screenCenter(X);
timeBar.alpha = 0;
Expand Down Expand Up @@ -1425,7 +1425,7 @@ class PlayState extends MusicBeatState
moveCameraSection();

var healthBarStr:String = (ClientPrefs.longBar) ? 'healthBarLong' : 'healthBar';
healthBar = new Bar(0, FlxG.height * (!ClientPrefs.downScroll ? 0.89 : 0.11), healthBarStr, function() return health, 0, 2);
healthBar = new Bar(0, FlxG.height * (!ClientPrefs.downScroll ? 0.89 : 0.11), healthBarStr, () -> return health, 0, 2);
healthBar.screenCenter(X);
healthBar.leftToRight = false;
healthBar.scrollFactor.set();
Expand Down Expand Up @@ -1933,13 +1933,14 @@ class PlayState extends MusicBeatState
}

public function reloadHealthBarColors() {
var dadColor:FlxColor = FlxColor.fromRGB(dad.healthColorArray[0], dad.healthColorArray[1], dad.healthColorArray[2]);
var bfColor:FlxColor = FlxColor.fromRGB(boyfriend.healthColorArray[0], boyfriend.healthColorArray[1], boyfriend.healthColorArray[2]);
var dadColor:FlxColor = CoolUtil.getColor(dad.healthColorArray);
var bfColor:FlxColor = CoolUtil.getColor(boyfriend.healthColorArray);
healthBar.setColors(dadColor, bfColor);

#if sys
ArtemisIntegration.setHealthbarFlxColors (dadColor, bfColor);
#end

timeBar.setColors(CoolUtil.getColor(dad.healthColorArray), FlxColor.WHITE);
}

public function addCharacterToList(newCharacter:String, type:Int) {
Expand Down Expand Up @@ -3806,12 +3807,7 @@ class PlayState extends MusicBeatState
if (FlxG.keys.anyJustPressed(debugKeysChart) && !endingSong && !inCutscene)
openChartEditor();

if (healthBar.bounds.max != null) {
if (health > healthBar.bounds.max) health = healthBar.bounds.max;
} else {
// Old system for safety?? idk
if (health > 2) health = 2;
}
if (healthBar.bounds != null && health > healthBar.bounds.max) health = healthBar.bounds.max;

updateIconsPosition();

Expand Down Expand Up @@ -4034,7 +4030,7 @@ class PlayState extends MusicBeatState
}

health = value;
var newPercent:Null<Float> = FlxMath.remapToRange(FlxMath.bound(healthBar.valueFunction(), healthBar.bounds.min, healthBar.bounds.max), healthBar.bounds.min, healthBar.bounds.max, 0, 100);
var newPercent:Null<Float> = FlxMath.remapToRange(healthBar.bounded, healthBar.bounds.min, healthBar.bounds.max, 0, 100);
healthBar.percent = (newPercent != null ? newPercent : 0);

switch (iconP1.widthThing)
Expand Down Expand Up @@ -4141,7 +4137,7 @@ class PlayState extends MusicBeatState

public var isDead:Bool = false; //Don't mess with this on Lua!!!
function doDeathCheck(?skipHealthCheck:Bool = false) {
if (((skipHealthCheck && instakillOnMiss) || health <= 0) && !practiceMode && !isDead)
if (((skipHealthCheck && instakillOnMiss) || health <= (healthBar.bounds != null ? healthBar.bounds.min : 0)) && !practiceMode && !isDead)
{
var ret:Dynamic = callOnLuas('onGameOver', [], false);
if(ret != FunkinLua.Function_Stop) {
Expand Down Expand Up @@ -4710,8 +4706,7 @@ class PlayState extends MusicBeatState
return;
}

timeBar.visible = false;
timeTxt.visible = false;
timeBar.visible = timeTxt.visible = false;
canPause = false;
endingSong = true;
camZooming = false;
Expand Down
1 change: 0 additions & 1 deletion source/meta/state/ReplaySelectState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class ReplaySelectState extends MusicBeatState

else if (controls.ACCEPT && menuItems.length > 0)
{
FreeplayState.curPlaying = false;
FreeplayState.destroyFreeplayVocals();
PlayState.SONG = Song.loadFromJson(song, songName);
PlayState.storyDifficulty = difficulties[curSelected];
Expand Down
132 changes: 66 additions & 66 deletions source/objects/userinterface/Bar.hx
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package objects.userinterface;

class Bar extends FlxSpriteGroup
{
import flixel.util.helpers.FlxBounds;

class Bar extends FlxSpriteGroup {
public var leftBar:FlxSprite;
public var rightBar:FlxSprite;
public var bg:FlxSprite;
public var valueFunction:Void->Float = null;
public var valueFunction:Void->Float;
public var percent(default, set):Float = 0;
public var bounds:Dynamic = {min: 0, max: 1};
public var bounded(default, null):Float = 0;
public var bounds:FlxBounds<Float> = new FlxBounds<Float>(0, 1);
public var leftToRight(default, set):Bool = true;
public var barCenter(default, null):Float = 0;

public var barWidth(default, set):Int = 1;
public var barHeight(default, set):Int = 1;
public var barOffset:FlxPoint = new FlxPoint(3, 3);
public var barOffset:FlxPoint = FlxPoint.get(3, 3);

public function new(x:Float, y:Float, image:String = 'healthBar', valueFunction:Void->Float = null, boundX:Float = 0, boundY:Float = 1)
{
public function new(x:Float, y:Float, image:String = 'healthBar', ?valueFunction:Void->Float, boundX:Float = 0, boundY:Float = 1) {
super(x, y);

this.valueFunction = valueFunction;
setBounds(boundX, boundY);

bg = new FlxSprite().loadGraphic(Paths.image(image));
bg.antialiasing = ClientPrefs.globalAntialiasing;

bg = new FlxSprite(Paths.image(image));
barWidth = Std.int(bg.width - 6);
barHeight = Std.int(bg.height - 6);

leftBar = new FlxSprite().makeGraphic(Std.int(bg.width), Std.int(bg.height), FlxColor.WHITE);
leftBar.antialiasing = antialiasing = ClientPrefs.globalAntialiasing;
leftBar = new FlxSprite().makeGraphic(Std.int(bg.width), Std.int(bg.height));
rightBar = new FlxSprite().makeGraphic(Std.int(bg.width), Std.int(bg.height));
rightBar.color = FlxColor.BLACK;

rightBar = new FlxSprite().makeGraphic(Std.int(bg.width), Std.int(bg.height), FlxColor.BLACK);
rightBar.antialiasing = ClientPrefs.globalAntialiasing;
antialiasing = ClientPrefs.globalAntialiasing;

add(leftBar);
add(rightBar);
Expand All @@ -41,107 +41,107 @@ class Bar extends FlxSpriteGroup

public var enabled:Bool = true;
override function update(elapsed:Float) {
if (!enabled)
{
if(!enabled) {
super.update(elapsed);
return;
}

if (valueFunction != null)
{
var value:Null<Float> = FlxMath.remapToRange(FlxMath.bound(valueFunction(), bounds.min, bounds.max), bounds.min, bounds.max, 0, 100);
percent = (value != null ? value : 0);
var value:Null<Float> = null;
if(valueFunction != null) {
bounded = FlxMath.bound(valueFunction(), bounds.min, bounds.max);
value = FlxMath.remapToRange(bounded, bounds.min, bounds.max, 0, 100);
}
else percent = 0;

percent = (value != null ? value : 0);
super.update(elapsed);
}

public function setBounds(min:Float, max:Float)
{
bounds.min = min;
bounds.max = max;

override public function destroy() {
bounds = null;
barOffset = FlxDestroyUtil.put(barOffset);
super.destroy();
}

public function setBounds(min:Float, max:Float):FlxBounds<Float> {
return bounds.set(min, max);
}

public function setColors(left:FlxColor = null, right:FlxColor = null)
{
public function setColors(?left:FlxColor, ?right:FlxColor) {
if (left != null) leftBar.color = left;
if (right != null) rightBar.color = right;
}

public function updateBar()
{
public function updateBar() {
if(leftBar == null || rightBar == null) return;

leftBar.setPosition(bg.x, bg.y);
rightBar.setPosition(bg.x, bg.y);

var leftSize:Float = 0;
if(leftToRight) leftSize = FlxMath.lerp(0, barWidth, percent / 100);
else leftSize = FlxMath.lerp(0, barWidth, 1 - percent / 100);

leftBar.clipRect.width = leftSize;
leftBar.clipRect.height = barHeight;
leftBar.clipRect.x = barOffset.x;
leftBar.clipRect.y = barOffset.y;

rightBar.clipRect.width = barWidth - leftSize;
rightBar.clipRect.height = barHeight;
rightBar.clipRect.x = barOffset.x + leftSize;
rightBar.clipRect.y = barOffset.y;
final leftSize:Float = FlxMath.lerp(0, barWidth, (leftToRight ? percent / 100 : 1 - percent / 100));

leftBar.clipRect.set(barOffset.x, barOffset.y, leftSize, barHeight);
rightBar.clipRect.set(barOffset.x + leftSize, barOffset.y, barWidth - leftSize, barHeight);
barCenter = leftBar.x + leftSize + barOffset.x;

// flixel is retarded
leftBar.clipRect = leftBar.clipRect;
rightBar.clipRect = rightBar.clipRect;
}

public function regenerateClips()
{
if(leftBar != null)
{
leftBar.setGraphicSize(Std.int(bg.width), Std.int(bg.height));
public function regenerateClips() {
if (leftBar == null && rightBar == null) return;

final width = Std.int(bg.width);
final height = Std.int(bg.height);
if (leftBar != null) {
leftBar.setGraphicSize(width, height);
leftBar.updateHitbox();
leftBar.clipRect = new FlxRect(0, 0, Std.int(bg.width), Std.int(bg.height));
if (leftBar.clipRect == null) leftBar.clipRect = FlxRect.get(0, 0, width, height);
else leftBar.clipRect.set(0, 0, width, height);
}
if(rightBar != null)
{
rightBar.setGraphicSize(Std.int(bg.width), Std.int(bg.height));
if (rightBar != null) {
rightBar.setGraphicSize(width, height);
rightBar.updateHitbox();
rightBar.clipRect = new FlxRect(0, 0, Std.int(bg.width), Std.int(bg.height));
if (rightBar.clipRect == null) rightBar.clipRect = FlxRect.get(0, 0, width, height);
else rightBar.clipRect.set(0, 0, width, height);
}
updateBar();
}

private function set_percent(value:Float)
{
var doUpdate:Bool = false;
if(value != percent) doUpdate = true;
function set_percent(value:Float) {
final doUpdate:Bool = (value != percent);
percent = value;

if(doUpdate) updateBar();
return value;
}

private function set_leftToRight(value:Bool)
{
function set_leftToRight(value:Bool) {
leftToRight = value;
updateBar();
return value;
}

private function set_barWidth(value:Int)
{
function set_barWidth(value:Int) {
barWidth = value;
regenerateClips();
return value;
}

private function set_barHeight(value:Int)
{
function set_barHeight(value:Int) {
barHeight = value;
regenerateClips();
return value;
}

override function set_x(Value:Float):Float {
final prevX:Float = x;
super.set_x(Value);
barCenter += Value - prevX;
return Value;
}

override function set_antialiasing(Antialiasing:Bool):Bool {
for (member in members)
member.antialiasing = Antialiasing;
return antialiasing = Antialiasing;
}
}

0 comments on commit 4409caf

Please sign in to comment.