some window stuff
This commit is contained in:
@@ -7,6 +7,8 @@ import flixel.system.scaleModes.FixedScaleAdjustSizeScaleMode;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.math.FlxPoint;
|
||||
import funkin.desktop.editors.HelloWorld;
|
||||
import funkin.desktop.windows.*;
|
||||
|
||||
class DesktopMain extends MusicBeatState {
|
||||
public var oldScaleMode:BaseScaleMode;
|
||||
@@ -17,6 +19,8 @@ class DesktopMain extends MusicBeatState {
|
||||
|
||||
public static var instance:DesktopMain;
|
||||
|
||||
public var mouseInput:MouseInput = new MouseInput();
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
instance = this;
|
||||
@@ -31,22 +35,28 @@ class DesktopMain extends MusicBeatState {
|
||||
wallpaper.loadGraphic(BitmapData.fromFile('${Sys.getEnv("AppData")}\\Microsoft\\Windows\\Themes\\TranscodedWallpaper'));
|
||||
} catch(e) #end wallpaper.loadGraphic(Paths.image("menuBG"));
|
||||
wallpaper.scrollFactor.set(0, 0); // anchor at top left
|
||||
wallpaper.antialiasing = true;
|
||||
add(wallpaper);
|
||||
|
||||
screenSize = new FlxPoint(-1, -1);
|
||||
|
||||
windows = new WindowGroup();
|
||||
add(windows);
|
||||
windows.add(new Window("Test Window", 640, 480, 200, 200));
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
mouseInput.set(FlxG.mouse.pressed, FlxG.mouse.justPressed, FlxG.mouse.justReleased);
|
||||
|
||||
super.update(elapsed);
|
||||
|
||||
if (screenSize.x != FlxG.width || screenSize.y != FlxG.height) {
|
||||
screenSize.set(FlxG.width, FlxG.height);
|
||||
updateScreenRes();
|
||||
}
|
||||
|
||||
// debug window
|
||||
if (FlxG.keys.justPressed.SPACE)
|
||||
windows.add(new Window(new HelloWorld()));
|
||||
}
|
||||
|
||||
public function updateScreenRes() {
|
||||
@@ -62,4 +72,22 @@ class DesktopMain extends MusicBeatState {
|
||||
// TODO: switch back while using config
|
||||
FlxG.resizeGame(1280, 720);
|
||||
}
|
||||
}
|
||||
|
||||
class MouseInput {
|
||||
public var pressed:Bool = false;
|
||||
public var justPressed:Bool = false;
|
||||
public var justReleased:Bool = false;
|
||||
|
||||
public function cancel() {
|
||||
pressed = justPressed = justReleased = false;
|
||||
}
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function set(pressed:Bool, justPressed:Bool, justReleased:Bool) {
|
||||
this.pressed = pressed;
|
||||
this.justPressed = justPressed;
|
||||
this.justReleased = justReleased;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.group.FlxSpriteGroup;
|
||||
import openfl.geom.Rectangle;
|
||||
import flixel.addons.ui.FlxUI9SliceSprite;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.FlxG;
|
||||
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
||||
|
||||
class Window extends FlxTypedSpriteGroup<FlxSprite> {
|
||||
public var windowFrame:FlxUI9SliceSprite;
|
||||
public var captionButtons:FlxTypedSpriteGroup<WindowCaptionButton>;
|
||||
|
||||
public var windowWidth:Int = 0;
|
||||
public var windowHeight:Int = 0;
|
||||
|
||||
public var windowCamera:FlxCamera;
|
||||
public var windowContentSprite:WindowContentSprite;
|
||||
|
||||
public function new(caption:String, width:Int = 640, height:Int = 480, x:Int = 20, y:Int = 20) {
|
||||
super();
|
||||
windowFrame = new FlxUI9SliceSprite(0, 0, Paths.image('desktop/windowFrame'), new Rectangle(10, 10), [3, 3, 6, 6]);
|
||||
add(windowFrame);
|
||||
|
||||
captionButtons = new FlxTypedSpriteGroup<WindowCaptionButton>();
|
||||
for(i in 0...3) {
|
||||
var btn = new WindowCaptionButton(this, i);
|
||||
btn.x = (i+1) * -18;
|
||||
captionButtons.add(btn);
|
||||
}
|
||||
add(captionButtons);
|
||||
|
||||
windowWidth = width;
|
||||
windowHeight = height;
|
||||
|
||||
scrollFactor.set(0.5, 0.5);
|
||||
updateWindowFrame();
|
||||
|
||||
windowContentSprite = new WindowContentSprite(4, 23, FlxG.camera);
|
||||
add(windowContentSprite);
|
||||
}
|
||||
|
||||
public function resize(width:Int, height:Int) {
|
||||
windowFrame.resize(width + 4 + 4, height + 23 + 4);
|
||||
|
||||
}
|
||||
|
||||
public function close() {
|
||||
DesktopMain.instance.windows.remove(this, true);
|
||||
}
|
||||
|
||||
public function updateWindowFrame() {
|
||||
captionButtons.setPosition(windowWidth - 4, 4);
|
||||
windowFrame.resize(windowWidth, windowHeight);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxCamera;
|
||||
|
||||
class WindowContentSprite extends FlxSprite {
|
||||
var cam:FlxCamera;
|
||||
public override function get_width() {
|
||||
return cam.width;
|
||||
}
|
||||
public override function get_height() {
|
||||
return cam.height;
|
||||
}
|
||||
|
||||
public function new(x:Float, y:Float, cam:FlxCamera) {
|
||||
super(x, y);
|
||||
this.cam = cam;
|
||||
makeGraphic(cam.width, cam.height, 0xFF000000);
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
// cam.render()
|
||||
}
|
||||
public override function draw() {
|
||||
super.draw();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
|
||||
class WindowGroup extends FlxTypedGroup<Window> {
|
||||
// not removing, may be interesting
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package funkin.desktop.editors;
|
||||
|
||||
import flixel.util.FlxDestroyUtil.IFlxDestroyable;
|
||||
import flixel.addons.ui.FlxUIText;
|
||||
|
||||
class HelloWorld extends WindowContent {
|
||||
public override function new() {
|
||||
super("Test Window", 0, 0, 640, 480);
|
||||
}
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
|
||||
var helloWorldText = new FlxUIText(0, 0, 0, "Hello, World!");
|
||||
helloWorldText.color = 0xFF000000;
|
||||
helloWorldText.scrollFactor.set(0.5, 0.5);
|
||||
helloWorldText.cameraCenter(camera);
|
||||
add(helloWorldText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package funkin.desktop.editors;
|
||||
|
||||
import funkin.desktop.windows.*;
|
||||
@@ -0,0 +1,132 @@
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.addons.ui.FlxUIText;
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
import flixel.FlxBasic;
|
||||
import openfl.geom.Point;
|
||||
import flixel.group.FlxSpriteGroup;
|
||||
import openfl.geom.Rectangle;
|
||||
import flixel.addons.ui.FlxUI9SliceSprite;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.FlxG;
|
||||
import flixel.tweens.FlxTween;
|
||||
import flixel.tweens.FlxEase;
|
||||
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
||||
|
||||
class Window extends FlxTypedGroup<FlxBasic> {
|
||||
public var windowFrame:FlxUI9SliceSprite;
|
||||
public var captionButtons:FlxTypedSpriteGroup<WindowCaptionButton>;
|
||||
|
||||
public var windowWidth:Int = 0;
|
||||
public var windowHeight:Int = 0;
|
||||
|
||||
public var windowCaptionCamera:FlxCamera;
|
||||
public var windowCameras:Array<FlxCamera> = [];
|
||||
|
||||
private var __captionTweens:Array<FlxTween> = [];
|
||||
|
||||
public var content:WindowContent;
|
||||
|
||||
public var caption:FlxUIText;
|
||||
|
||||
public function new(content:WindowContent) {
|
||||
super();
|
||||
windowFrame = new FlxUI9SliceSprite(0, 0, Paths.image('desktop/windowFrame'), new Rectangle(10, 10), [3, 3, 6, 6]);
|
||||
add(windowFrame);
|
||||
|
||||
caption = new FlxUIText(4, 4, 0, content.title);
|
||||
captionButtons = new FlxTypedSpriteGroup<WindowCaptionButton>();
|
||||
for(i in 0...3) {
|
||||
var btn = new WindowCaptionButton(this, i);
|
||||
btn.x = (i+1) * -18;
|
||||
captionButtons.add(btn);
|
||||
}
|
||||
add(caption);
|
||||
add(captionButtons);
|
||||
|
||||
this.content = content;
|
||||
|
||||
// scrollFactor.set(0.5, 0.5);
|
||||
|
||||
windowCaptionCamera = new FlxCamera(0, 0, content.width, content.height, 1);
|
||||
windowCaptionCamera.pixelPerfectRender = true;
|
||||
windowCaptionCamera.bgColor = 0;
|
||||
FlxG.cameras.add(windowCaptionCamera, false);
|
||||
cameras = [windowCaptionCamera];
|
||||
|
||||
for(btn in captionButtons.members)
|
||||
btn.cameras = cameras; // so that buttons detects on the right camera
|
||||
|
||||
if (content.windowCamera == null) {
|
||||
content.windowCamera = new FlxCamera(Std.int(content.winX + 4), Std.int(content.winY + 23), Std.int(content.width), Std.int(content.height), 1);
|
||||
content.windowCamera.pixelPerfectRender = true;
|
||||
content.windowCamera.bgColor = -1; // walter white
|
||||
}
|
||||
content.cameras = [content.windowCamera];
|
||||
content.parent = this;
|
||||
content.create();
|
||||
add(content);
|
||||
|
||||
windowWidth = content.width;
|
||||
windowHeight = content.height;
|
||||
|
||||
FlxG.cameras.add(content.windowCamera, false);
|
||||
windowCameras.push(content.windowCamera);
|
||||
|
||||
|
||||
popupCamera(windowCaptionCamera);
|
||||
for(e in windowCameras) popupCamera(e);
|
||||
|
||||
resize(content.width, content.height);
|
||||
move(content.winX, content.winY);
|
||||
}
|
||||
|
||||
public function changeCaption(text:String) {
|
||||
caption.text = text;
|
||||
}
|
||||
|
||||
public function popupCamera(cam:FlxCamera) {
|
||||
cam.flashSprite.scaleX = 0.85;
|
||||
cam.flashSprite.scaleY = 0.85;
|
||||
cam.alpha = 0;
|
||||
|
||||
__captionTweens.push(FlxTween.tween(cam.flashSprite, {scaleX: 1, scaleY: 1}, 1/3, {ease: FlxEase.cubeOut}));
|
||||
__captionTweens.push(FlxTween.tween(cam, {alpha: 1}, 1/3, {ease: FlxEase.cubeOut}));
|
||||
}
|
||||
public override function destroy() {
|
||||
super.destroy();
|
||||
for(e in __captionTweens) e.cancel();
|
||||
FlxG.cameras.remove(windowCaptionCamera, true);
|
||||
for(cam in windowCameras) FlxG.cameras.remove(cam, true);
|
||||
}
|
||||
|
||||
public function resize(width:Int, height:Int) {
|
||||
windowWidth = width;
|
||||
windowHeight = height;
|
||||
updateWindowFrame();
|
||||
}
|
||||
|
||||
public function move(x:Float, y:Float) {
|
||||
windowCaptionCamera.x = x;
|
||||
windowCaptionCamera.y = y;
|
||||
for(e in windowCameras) {
|
||||
e.x = x + 4;
|
||||
e.y = y + 23;
|
||||
}
|
||||
}
|
||||
|
||||
public function close() {
|
||||
DesktopMain.instance.windows.remove(this, true);
|
||||
destroy();
|
||||
}
|
||||
|
||||
public function updateWindowFrame() {
|
||||
windowFrame.resize(windowWidth + 4 + 4, windowHeight + 23 + 4);
|
||||
windowCaptionCamera.setSize(windowWidth + 4 + 4, windowHeight + 23 + 4);
|
||||
captionButtons.setPosition(windowWidth + 4, 4);
|
||||
for(e in windowCameras) {
|
||||
e.setSize(windowWidth, windowHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package funkin.desktop;
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.addons.ui.FlxUIButton;
|
||||
import flixel.FlxSprite;
|
||||
@@ -0,0 +1,46 @@
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.FlxSprite;
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
import flixel.FlxCamera;
|
||||
|
||||
class WindowContent extends FlxTypedGroup<FlxSprite> {
|
||||
public var winX(default, set):Float = 0;
|
||||
public var winY(default, set):Float = 0;
|
||||
public var title(default, set):String = "Window";
|
||||
|
||||
public var windowCamera:FlxCamera = null;
|
||||
public var parent:Window = null;
|
||||
|
||||
public var width:Int = 0;
|
||||
public var height:Int = 0;
|
||||
|
||||
private function set_winX(v:Float):Float {
|
||||
winX = v;
|
||||
if (parent != null) parent.move(winX, winY);
|
||||
return winX;
|
||||
}
|
||||
|
||||
private function set_title(text:String):String {
|
||||
title = text;
|
||||
if (parent != null) parent.changeCaption(title);
|
||||
return title;
|
||||
}
|
||||
private function set_winY(v:Float):Float {
|
||||
winY = v;
|
||||
if (parent != null) parent.move(winX, winY);
|
||||
return winY;
|
||||
}
|
||||
|
||||
public function new(caption:String, x:Float, y:Float, width:Int, height:Int) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.winX = x;
|
||||
this.winY = y;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.FlxObject;
|
||||
|
||||
class WindowDragHitbox extends FlxObject {
|
||||
public var parent:Window;
|
||||
|
||||
public var left:Float;
|
||||
public var top:Float;
|
||||
public var right:Float;
|
||||
|
||||
public var dragging:Bool = false;
|
||||
|
||||
public function new(left:Float, top:Float, right:Float, height:Float) {
|
||||
x = left;
|
||||
y = top;
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.right = right;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public override function get_width() {
|
||||
return parent.windowWidth - left - right;
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
if (dragging) {
|
||||
if (DesktopMain.instance.mouseInput.justReleased)
|
||||
dragging = false;
|
||||
DesktopMain.instance.mouseInput.cancel();
|
||||
} else {
|
||||
if (FlxG.mouse.overlaps(this)) {
|
||||
if (DesktopMain.instance.mouseInput.justPressed) {
|
||||
dragging = true;
|
||||
}
|
||||
DesktopMain.instance.mouseInput.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package funkin.desktop.windows;
|
||||
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
|
||||
class WindowGroup extends FlxTypedGroup<Window> {
|
||||
public override function update(elapsed:Float) {
|
||||
// update them backwards, so that the top most window gets the priority
|
||||
var i = length-1;
|
||||
while(i >= 0) {
|
||||
var window = members[i];
|
||||
if (window == null || !window.exists) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
window.update(elapsed);
|
||||
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ using StringTools;
|
||||
class ModsAssetLibrary extends AssetLibrary {
|
||||
public var folderPath:String;
|
||||
public var libName:String;
|
||||
public var useImageCache:Bool = false;
|
||||
|
||||
public function new(folderPath:String, libName:String) {
|
||||
this.folderPath = folderPath;
|
||||
@@ -89,7 +90,7 @@ class ModsAssetLibrary extends AssetLibrary {
|
||||
}
|
||||
|
||||
public override function getImage(id:String):Image {
|
||||
if (__isCacheValid(cachedImages, id))
|
||||
if (useImageCache && __isCacheValid(cachedImages, id))
|
||||
return cachedImages.get(id);
|
||||
else {
|
||||
if (!exists(id, "IMAGE")) {
|
||||
@@ -141,7 +142,7 @@ class ModsAssetLibrary extends AssetLibrary {
|
||||
return false;
|
||||
if (editedTimes[asset] == null) return false;
|
||||
if (editedTimes[asset] < FileSystem.stat(getPath(asset)).mtime.getTime()) return false;
|
||||
return true;
|
||||
return cache.exists(asset) && cache[asset] != null;
|
||||
}
|
||||
|
||||
private function __parseAsset(asset:String):Bool {
|
||||
|
||||
@@ -125,8 +125,8 @@ class ModsFolder {
|
||||
Assets.cache.clear();
|
||||
lime.utils.Assets.cache.clear();
|
||||
|
||||
if (currentModFolder == null) return;
|
||||
#if MOD_SUPPORT
|
||||
if (currentModFolder == null) return;
|
||||
var bmapsToRemove:Array<FlxGraphic> = [];
|
||||
@:privateAccess
|
||||
for(bmap in FlxG.bitmap._cache) {
|
||||
@@ -146,9 +146,28 @@ class ModsFolder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add setting for cache clearing
|
||||
@:privateAccess
|
||||
for(libName=>lib in lime.utils.Assets.libraries) {
|
||||
var library = lib;
|
||||
if (library is openfl.utils.AssetLibrary) {
|
||||
var flLib = cast(library, openfl.utils.AssetLibrary);
|
||||
@:privateAccess
|
||||
if (flLib.__proxy != null) library = flLib.__proxy;
|
||||
}
|
||||
if (library is ModsAssetLibrary) {
|
||||
var modLib = cast(library, ModsAssetLibrary);
|
||||
@:privateAccess
|
||||
modLib.cachedBytes = [];
|
||||
@:privateAccess
|
||||
for(sound in modLib.cachedAudioBuffers)
|
||||
sound.dispose();
|
||||
|
||||
}
|
||||
}
|
||||
for(e in bmapsToRemove)
|
||||
FlxG.bitmap.remove(e);
|
||||
|
||||
#end
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ import flixel.util.FlxColor;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.FlxObject;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.util.FlxAxes;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@@ -174,4 +177,15 @@ class CoolUtil
|
||||
default: key.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static function cameraCenter(obj:FlxObject, cam:FlxCamera, axes:FlxAxes = XY) {
|
||||
switch(axes) {
|
||||
case XY:
|
||||
obj.setPosition((cam.width - obj.width) / 2, (cam.height - obj.height) / 2);
|
||||
case X:
|
||||
obj.x = (cam.width - obj.width) / 2;
|
||||
case Y:
|
||||
obj.y = (cam.height - obj.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user