Fixed TopMenu, Less Laggy Blur

Crash Handler should hopefully catch more now
Close Button in metadata screen
Improved System Info
This commit is contained in:
NeeEoo
2023-05-29 20:25:31 +02:00
parent e060ee3ddb
commit f2624c5e5c
15 changed files with 172 additions and 45 deletions
+4 -4
View File
@@ -1,9 +1,9 @@
#pragma header
vec3 hsvToRgb(vec3 hsv){ //hsv.x = hue, hsv.y = saturation, hsv.z = value
vec3 col = vec3(hsv.x, hsv.x + 2.0/3.0, hsv.x + 4.0/3.0); //inputs for r, g, and b
col = clamp(abs(mod(col*2.0, 2.0)-1.0)*3.0 - 1.0, 0.0, 1.0)*hsv.z*hsv.y + hsv.z - hsv.z*hsv.y; //hue function (graph it on desmos)
return col;
vec3 hsvToRgb(vec3 c) { //hsv.x = hue, hsv.y = saturation, hsv.z = value
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
uniform float hue;
+48
View File
@@ -0,0 +1,48 @@
#pragma header
float uBlur = 0.075;
float uBrightness = 0.9;
vec4 getColor(vec2 pos) {
if (pos.x < 0) pos.x = 0;
else if (pos.x > 1.0 - (1.0 / openfl_TextureSize.x)) pos.x = 1.0 - (1.0 / openfl_TextureSize.x);
if (pos.y < 0) pos.y = 0;
else if (pos.y > 1.0 - (1.0 / openfl_TextureSize.y)) pos.y = 1.0 - (1.0 / openfl_TextureSize.y);
// return textureCam(bitmap, pos);
return flixel_texture2D(bitmap, pos);
}
vec2 fixvec2(float x, float y) { // makes an uv the same across sizes
vec2 val = vec2(x, y);
val.xy *= vec2(1280.0, 720.0);
val.xy /= openfl_TextureSize.xy;
return val;
}
vec2 fixvec2(vec2 uv) { // makes an uv the same across sizes
vec2 val = uv;
val.xy *= vec2(1280.0, 720.0);
val.xy /= openfl_TextureSize.xy;
return val;
}
vec2 random(vec2 p) {
p = vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3)));
return fract(sin(p)*4375.5);
}
void main() {
// vec2 camPos = getCamPos(openfl_TextureCoordv);
vec2 camPos = openfl_TextureCoordv;
if (camPos.x < 0 || camPos.x > 1 || camPos.y < 0 || camPos.y > 1)
return;
//vec4 color = getColor(camPos);
vec2 blur = vec2(uBlur) * vec2(1.0, openfl_TextureSize.x / openfl_TextureSize.y);
vec4 a = getColor(camPos+fixvec2(random(camPos)*blur - blur / 2.0)) * uBrightness;
a += getColor(camPos+fixvec2(random(camPos+0.1)*blur - blur / 2.0)) * uBrightness;
a += getColor(camPos+fixvec2(random(camPos+0.2)*blur - blur / 2.0)) * uBrightness;
//a += getColor(camPos+fixvec2(random(camPos+0.3)*blur - blur / 2.0)) * uBrightness;
gl_FragColor = a / 4.0;
}
@@ -14,6 +14,8 @@ import hscript.IHScriptCustomBehaviour;
* To access the shader's uniform variables, use `shader.variable`
*/
class CustomShader extends FunkinShader {
public var path:String = "";
/**
* Creates a new custom shader
* @param name Name of the frag and vert files.
@@ -25,6 +27,8 @@ class CustomShader extends FunkinShader {
var fragCode = Assets.exists(fragShaderPath) ? Assets.getText(fragShaderPath) : null;
var vertCode = Assets.exists(vertShaderPath) ? Assets.getText(vertShaderPath) : null;
path = fragShaderPath+vertShaderPath;
if (fragCode == null && vertCode == null)
Logs.trace('Shader "$name" couldn\'t be found.', ERROR);
+3 -2
View File
@@ -63,6 +63,8 @@ class Main extends Sprite
public function new()
{
super();
CrashHandler.init();
addChild(game = new FunkinGame(gameWidth, gameHeight, MainState, Options.framerate, Options.framerate, skipSplash, startFullscreen));
#if !mobile
@@ -114,7 +116,6 @@ class Main extends Sprite
#if UPDATE_CHECKING
funkin.backend.system.updating.UpdateUtil.init();
#end
CrashHandler.init();
Logs.init();
Paths.init();
ModsFolder.init();
@@ -158,7 +159,7 @@ class Main extends Sprite
#if MOD_SUPPORT
ModsFolder.switchMod(modToLoad.getDefault(Options.lastLoadedMod));
#end
initTransition();
}
@@ -13,22 +13,27 @@ class SystemInfo extends FramerateCategory {
public static var cpuName:String = "Unknown";
public static var totalMem:String = "Unknown";
public static var memType:String = "Unknown";
public static var gpuMaxSize:String = "Unknown";
static var __formattedSysText:String = "";
public static inline function init() {
if (lime.system.System.platformLabel != null && lime.system.System.platformLabel != "" && lime.system.System.platformVersion != null && lime.system.System.platformVersion != "")
osInfo = '${lime.system.System.platformLabel.replace(lime.system.System.platformVersion, "").trim()} ${lime.system.System.platformVersion}';
else
else
Logs.trace('Unable to grab OS Label', ERROR, RED);
try {
#if windows
var process = new HiddenProcess("wmic", ["cpu", "get", "name"]);
if (process.exitCode() == 0) cpuName = process.stdout.readAll().toString().trim().split("\n")[1].trim();
if (process.exitCode() != 0) throw 'Could not fetch CPU information';
cpuName = process.stdout.readAll().toString().trim().split("\n")[1].trim();
#elseif mac
var process = new HiddenProcess("sysctl -a | grep brand_string");
if (process.exitCode() == 0) cpuName = process.stdout.readAll().toString().trim().split(":")[1].trim();
var process = new HiddenProcess("sysctl -a | grep brand_string"); // Somehow this isnt able to use the args but it still works
if (process.exitCode() != 0) throw 'Could not fetch CPU information';
cpuName = process.stdout.readAll().toString().trim().split(":")[1].trim();
#elseif linux
var process = new HiddenProcess("cat", ["/proc/cpuinfo"]);
if (process.exitCode() != 0) throw 'Could not fetch CPU information';
@@ -44,23 +49,28 @@ class SystemInfo extends FramerateCategory {
Logs.trace('Unable to grab CPU Name: $e', ERROR, RED);
}
@:privateAccess {
if (flixel.FlxG.stage.context3D != null && flixel.FlxG.stage.context3D.gl != null) {
gpuName = Std.string(flixel.FlxG.stage.context3D.gl.getParameter(flixel.FlxG.stage.context3D.gl.RENDERER)).split("/")[0].trim();
#if !flash
var size = FlxG.bitmap.maxTextureSize;
gpuMaxSize = size+"x"+size;
#end
var vRAMBytes:UInt = cast(flixel.FlxG.stage.context3D.gl.getParameter(openfl.display3D.Context3D.__glMemoryTotalAvailable), UInt);
if (vRAMBytes == 1000 || vRAMBytes <= 0)
Logs.trace('Unable to grab GPU VRAM', ERROR, RED);
else
vRAM = CoolUtil.getSizeString(vRAMBytes * 1000);
} else
if(openfl.display3D.Context3D.__glMemoryTotalAvailable != -1) {
var vRAMBytes:UInt = cast(flixel.FlxG.stage.context3D.gl.getParameter(openfl.display3D.Context3D.__glMemoryTotalAvailable), UInt);
if (vRAMBytes == 1000 || vRAMBytes == 1 || vRAMBytes <= 0)
Logs.trace('Unable to grab GPU VRAM', ERROR, RED);
else
vRAM = CoolUtil.getSizeString(vRAMBytes * 1000);
}
} else
Logs.trace('Unable to grab GPU Info', ERROR, RED);
}
#if cpp
totalMem = Std.string(MemoryUtil.getTotalMem() / 1024) + " GB";
#else
#else
Logs.trace('Unable to grab RAM Amount', ERROR, RED);
#end
@@ -74,9 +84,19 @@ class SystemInfo extends FramerateCategory {
static function formatSysInfo() {
if (osInfo != "Unknown") __formattedSysText = 'System: $osInfo';
if (cpuName != "Unknown") __formattedSysText += '\nCPU: ${cpuName} ${openfl.system.Capabilities.cpuArchitecture} ${(openfl.system.Capabilities.supports64BitProcesses ? '64-Bit' : '32-Bit')}';
if (gpuName != cpuName && (gpuName != "Unknown" && vRAM != "Unknown")) __formattedSysText += '\nGPU: ${gpuName} | VRAM: ${vRAM}'; // 1000 bytes of vram (apus)
if (totalMem != "Unknown" && memType != "Unknown") __formattedSysText += '\nTotal MEM: ${totalMem} $memType';
if (cpuName != "Unknown") __formattedSysText += '\nCPU: $cpuName ${openfl.system.Capabilities.cpuArchitecture} ${(openfl.system.Capabilities.supports64BitProcesses ? '64-Bit' : '32-Bit')}';
if (gpuName != cpuName || vRAM != "Unknown") {
var gpuNameKnown = gpuName != "Unknown" && gpuName != cpuName;
var vramKnown = vRAM != "Unknown";
if(gpuNameKnown || vramKnown) __formattedSysText += "\n";
if(gpuNameKnown) __formattedSysText += 'GPU: $gpuName';
if(gpuNameKnown && vramKnown) __formattedSysText += " | ";
if(vramKnown) __formattedSysText += 'VRAM: $vRAM'; // 1000 bytes of vram (apus)
}
//if (gpuMaxSize != "Unknown") __formattedSysText += '\nMax Bitmap Size: $gpuMaxSize';
if (totalMem != "Unknown" && memType != "Unknown") __formattedSysText += '\nTotal MEM: $totalMem $memType';
}
public function new() {
+1 -1
View File
@@ -18,7 +18,7 @@ class EditorTreeMenu extends TreeMenu {
bg.antialiasing = true;
add(bg);
}
public override function exit() {
FlxG.switchState(new MainMenuState());
}
@@ -8,6 +8,7 @@ using StringTools;
class MetaDataScreen extends UISubstateWindow {
public var metadata:ChartMetaData;
public var saveButton:UIButton;
public var closeButton:UIButton;
public var songNameTextBox:UITextBox;
public var bpmStepper:UINumericStepper;
@@ -92,7 +93,7 @@ class MetaDataScreen extends UISubstateWindow {
add(difficulitesTextBox);
addLabelOn(difficulitesTextBox, "Difficulties");
for (checkbox in [opponentModeCheckbox, coopAllowedCheckbox])
for (checkbox in [opponentModeCheckbox, coopAllowedCheckbox])
{checkbox.y += 6; checkbox.x += 4;}
saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20, colorWheel.y + 32 + 197 + 26, "Save & Close", function() {
@@ -101,6 +102,13 @@ class MetaDataScreen extends UISubstateWindow {
}, 125);
saveButton.x -= saveButton.bWidth;
saveButton.y -= saveButton.bHeight;
closeButton = new UIButton(saveButton.x - 20, saveButton.y, "Close", function() {
close();
}, 125);
closeButton.x -= closeButton.bWidth;
//closeButton.y -= closeButton.bHeight;
add(closeButton);
add(saveButton);
}
+4 -4
View File
@@ -13,7 +13,7 @@ class UIColorwheel extends UISliceSprite {
var colorSlider:FlxSprite;
var colorSliderSelector:UIColorWheelSelector;
var colorHexTextBox:UITextBox;
var rgbNumSteppers:Array<UINumericStepper> = []; // r,g,b
@@ -46,7 +46,7 @@ class UIColorwheel extends UISliceSprite {
colorSlider.pixels.lock();
for (pixely in 0...Std.int(colorSlider.height)) {
var color:Int = FlxColor.fromHSB(pixely / (colorSlider.height-1) * 360, 1, 1);
for (pixelx in 0...Std.int(colorSlider.width))
for (pixelx in 0...Std.int(colorSlider.width))
if (colorSlider.pixels.getPixel32(pixelx, pixely) != FlxColor.TRANSPARENT) colorSlider.pixels.setPixel32(pixelx, pixely, color);
}
colorSlider.pixels.unlock();
@@ -90,11 +90,11 @@ class UIColorwheel extends UISliceSprite {
updateWheel();
}
inline function updateColorPickerSelector()
inline function updateColorPickerSelector()
colorPickerSelector.selector.setPosition(colorPicker.x + (colorPicker.width *saturation) - 8, colorPicker.y + (colorPicker.height + (colorPicker.height * -brightness))- 8);
inline function updateColorPickerMouse(mousePos:FlxPoint) {
saturation = mousePos.x/colorPicker.width; brightness = 1 + -(mousePos.y/colorPicker.height);
saturation = mousePos.x/colorPicker.width; brightness = 1 + -(mousePos.y/colorPicker.height);
}
inline function updateColorSliderPickerSelector()
+1 -2
View File
@@ -62,7 +62,6 @@ class UIContextMenu extends MusicBeatSubstate {
if (o.bWidth > maxW)
maxW = o.bWidth;
for(o in contextMenuOptions)
o.bWidth = maxW;
for(o in separators) {
@@ -91,7 +90,7 @@ class UIContextMenu extends MusicBeatSubstate {
}
public override function update(elapsed:Float) {
if (__oobDeletion && FlxG.mouse.pressed && !bg.hoveredByChild)
if (__oobDeletion && FlxG.mouse.justPressed && !bg.hoveredByChild)
close();
__oobDeletion = true;
+1 -2
View File
@@ -44,7 +44,7 @@ class UIDropDown extends UISliceSprite {
}
super.update(elapsed);
label.follow(this, 4, Std.int((bHeight - label.height) / 2));
dropButton.follow(this, bWidth - bHeight, 0);
}
@@ -60,5 +60,4 @@ class UIDropDown extends UISliceSprite {
setOption(i);
}, screenPos.x, screenPos.y + bHeight);
}
}
+3 -3
View File
@@ -54,7 +54,7 @@ class UISprite extends FlxSprite {
FlxCamera._defaultCameras = __oldDefCams;
}
}
public override function draw() {
@@ -74,11 +74,11 @@ class UISprite extends FlxSprite {
for(m in members)
m.draw();
FlxCamera._defaultCameras = __oldDefCams;
}
}
public override function destroy() {
super.destroy();
members = FlxDestroyUtil.destroyArray(members);
+11 -5
View File
@@ -60,7 +60,7 @@ class UIState extends MusicBeatState {
updateRectButtonHandler(spr, spr.__rect, buttonHandler);
}
public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) {
public function isOverlapping(spr:UISprite, rect:FlxRect) {
for(camera in spr.__lastDrawCameras) {
var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get());
__rect.x = rect.x;
@@ -72,14 +72,20 @@ class UIState extends MusicBeatState {
__rect.y -= camera.scroll.y * spr.scrollFactor.y;
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;
return true;
}
pos.put();
}
return false;
}
public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) {
if(isOverlapping(spr, rect)) {
spr.hoveredByChild = true;
this.hoveredSprite = spr;
this.buttonHandler = buttonHandler;
}
}
public override function tryUpdate(elapsed:Float) {
+21 -1
View File
@@ -1,12 +1,13 @@
package funkin.editors.ui;
import openfl.filters.ShaderFilter;
import flixel.tweens.FlxTween;
import funkin.backend.shaders.CustomShader;
// TODO: make UIWarningSubstate extend this
class UISubstateWindow extends MusicBeatSubstate {
var camShaders:Array<FlxCamera> = [];
var blurShader:CustomShader = new CustomShader("engine/editorBlur");
var blurShader:CustomShader = new CustomShader("engine/editorBlurFast");
var titleSpr:UIText;
var messageSpr:UIText;
@@ -29,6 +30,24 @@ class UISubstateWindow extends MusicBeatSubstate {
super.create();
for(c in FlxG.cameras.list) {
@:privateAccess if(c._filters != null) {
var shouldSkip = false;
for(filter in c._filters) {
if(filter is ShaderFilter) {
var filter:ShaderFilter = cast filter;
if(filter.shader is CustomShader) {
var shader:CustomShader = cast filter.shader;
if(shader.path == blurShader.path) {
shouldSkip = true;
break;
}
}
}
}
if(shouldSkip)
continue;
}
camShaders.push(c);
c.addShader(blurShader);
}
@@ -54,6 +73,7 @@ class UISubstateWindow extends MusicBeatSubstate {
for(e in camShaders)
e.removeShader(blurShader);
blurShader = null;
FlxTween.cancelTweensOf(subCam);
FlxG.cameras.remove(subCam);
}
+26 -3
View File
@@ -51,27 +51,50 @@ class UITopMenuButton extends UISliceSprite {
members.push(this.label);
}
var justClosed:Int = 0;
public override function update(elapsed:Float) {
label.follow(this, 0, Std.int((bHeight - label.height) / 2));
super.update(elapsed);
var opened = curMenu.contextMenuOpened();
if(FlxG.mouse.released) {
if(justClosed > 0)
justClosed -= 1;
}
var opened = curMenu != null ? curMenu.contextMenuOpened() : false;
if(opened && FlxG.mouse.justPressed) {
__rect.x = x;
__rect.y = y;
__rect.width = bWidth;
__rect.height = bHeight;
if(UIState.state.isOverlapping(this, __rect)) {
curMenu.close();
justClosed = 2;
opened = false;
}
}
alpha = (hovered || opened) ? 1 : 0;
framesOffset = opened ? 9 : 0;
}
public override function onHovered() {
super.onHovered();
if (curMenu.contextMenuOpened()) {
if (curMenu != null && curMenu.contextMenuOpened()) {
UIState.state.curContextMenu.preventOutOfBoxClickDeletion();
} else {
if ((parent != null && parent.anyMenuOpened) || FlxG.mouse.justReleased) {
if (/*(parent != null && !parent.anyMenuOpened) || */FlxG.mouse.justReleased && justClosed == 0) {
openContextMenu();
}
}
}
public function openContextMenu() {
//if(UIState.state.curContextMenu != null) {
// UIState.state.curContextMenu.close();
//}
var screenPos = getScreenPosition(null, __lastDrawCameras[0] == null ? FlxG.camera : __lastDrawCameras[0]);
curMenu = UIState.state.openContextMenu(contextMenu, null, screenPos.x, screenPos.y + bHeight);
}
+1 -2
View File
@@ -10,7 +10,6 @@ import funkin.options.type.OptionType;
import funkin.options.categories.*;
class TreeMenu extends MusicBeatState {
public var main:OptionsScreen;
public var optionsTree:OptionsTree;
public var pathLabel:FunkinText;
@@ -40,7 +39,7 @@ class TreeMenu extends MusicBeatState {
pathBG.updateHitbox();
pathBG.alpha = 0.25;
pathBG.scrollFactor.set();
optionsTree = new OptionsTree();
optionsTree.onMenuChange = onMenuChange;
optionsTree.onMenuClose = onMenuClose;