you can maximize windows now + messageboxes
This commit is contained in:
@@ -14,6 +14,8 @@ import flixel.tweens.FlxTween;
|
||||
import flixel.tweens.FlxEase;
|
||||
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
||||
import funkin.desktop.sprites.*;
|
||||
import funkin.desktop.editors.MessageBox.MessageBoxIcon;
|
||||
import funkin.desktop.editors.MessageBox;
|
||||
|
||||
|
||||
typedef WindowCam = {
|
||||
@@ -44,6 +46,11 @@ class Window extends FlxTypedGroup<FlxBasic> {
|
||||
|
||||
public var moveable:Bool = true;
|
||||
public var resizeable:Bool = true;
|
||||
public var canClose:Bool = true;
|
||||
public var canMinimize:Bool = true;
|
||||
public var canHelp:Bool = false;
|
||||
|
||||
public var maximized:Bool = false;
|
||||
|
||||
public var focused(get, null):Bool;
|
||||
|
||||
@@ -57,6 +64,14 @@ class Window extends FlxTypedGroup<FlxBasic> {
|
||||
return DesktopMain.instance.windows.members.last() == this;
|
||||
}
|
||||
|
||||
public function showMessage(caption:String, message:String, icon:MessageBoxIcon) {
|
||||
var win = DesktopMain.instance.openWindow(new MessageBox(caption, message, icon));
|
||||
curDialog = win;
|
||||
win.move(
|
||||
windowCaptionCamera.x + ((windowCaptionCamera.width - win.windowCaptionCamera.width) / 2),
|
||||
windowCaptionCamera.y + ((windowCaptionCamera.height - win.windowCaptionCamera.height) / 2));
|
||||
}
|
||||
|
||||
public function loadIcon(path:String) {
|
||||
icon.loadGraphic(path);
|
||||
icon.setUnstretchedGraphicSize(16, 16, false);
|
||||
@@ -112,7 +127,7 @@ class Window extends FlxTypedGroup<FlxBasic> {
|
||||
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.windowCamera.bgColor = DesktopMain.theme.window.color;
|
||||
}
|
||||
content.cameras = [content.windowCamera];
|
||||
content.parent = this;
|
||||
@@ -140,6 +155,41 @@ class Window extends FlxTypedGroup<FlxBasic> {
|
||||
});
|
||||
}
|
||||
|
||||
public function onDesktopSizeChange(width:Int, height:Int) {
|
||||
if (maximized) {
|
||||
resize(width, height);
|
||||
}
|
||||
content.onDesktopSizeChange(width, height);
|
||||
}
|
||||
|
||||
public function maximize() {
|
||||
if (maximized != (maximized = true)) {
|
||||
// maximizing!!
|
||||
captionButtons.members[1].animation.play("restore", true);
|
||||
move(-DesktopMain.theme.window.left, -DesktopMain.theme.window.left);
|
||||
resize(FlxG.width, FlxG.height); // TODO: taskbar stuff
|
||||
}
|
||||
}
|
||||
|
||||
public function minimize() {
|
||||
|
||||
}
|
||||
|
||||
public function restore() {
|
||||
if (maximized != (maximized = false)) {
|
||||
// maximizing!!
|
||||
captionButtons.members[1].animation.play("maximize", true);
|
||||
move(100, 100);
|
||||
var w:Int = 320;
|
||||
var h:Int = 320;
|
||||
if (windowCameras[0] != null) {
|
||||
w = windowCameras[0].width;
|
||||
h = windowCameras[0].height;
|
||||
}
|
||||
resize(w, h); // TODO: taskbar stuff
|
||||
}
|
||||
}
|
||||
|
||||
public function changeCaption(text:String) {
|
||||
caption.text = text;
|
||||
}
|
||||
@@ -197,19 +247,19 @@ class Window extends FlxTypedGroup<FlxBasic> {
|
||||
|
||||
var shouldCancel = DesktopMain.instance.mouseInput.overlapsRect(this, new Rectangle(0, 0, windowCaptionCamera.width, windowCaptionCamera.height), windowCaptionCamera);
|
||||
|
||||
if (shouldCancel && DesktopMain.instance.mouseInput.justPressed)
|
||||
DesktopMain.instance.focusWindow(this);
|
||||
|
||||
|
||||
if (curDialog != null && curDialog.exists) {
|
||||
if (shouldCancel) {
|
||||
DesktopMain.instance.mouseInput.cancel();
|
||||
if (DesktopMain.instance.mouseInput.justPressed) {
|
||||
// TODO: sounds
|
||||
DesktopMain.instance.focusWindow(curDialog);
|
||||
}
|
||||
DesktopMain.instance.mouseInput.cancel();
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (shouldCancel && DesktopMain.instance.mouseInput.justPressed)
|
||||
DesktopMain.instance.focusWindow(this);
|
||||
// updates them backwards!!
|
||||
while(i > 0) {
|
||||
i--;
|
||||
|
||||
@@ -6,15 +6,9 @@ class WindowCaptionButton extends FlxSprite {
|
||||
public var icon:FlxSprite;
|
||||
public var window:Window;
|
||||
|
||||
public static var anims:Array<String> = ["minimize", "maximize", "close", "restore", "help"];
|
||||
public static var anims:Array<String> = ["close", "maximize", "minimize", "help", "restore"];
|
||||
|
||||
public function new(window:Window, i:Int) {
|
||||
// super(0, 0, "", function() {
|
||||
// switch(i) {
|
||||
// case 0:
|
||||
// window.close();
|
||||
// }
|
||||
// });
|
||||
super(0, 0);
|
||||
this.window = window;
|
||||
ID = i;
|
||||
@@ -22,12 +16,9 @@ class WindowCaptionButton extends FlxSprite {
|
||||
loadGraphic(Paths.image(DesktopMain.theme.captionButtons.sprite), true, Std.int(DesktopMain.theme.captionButtons.size.x), Std.int(DesktopMain.theme.captionButtons.size.y));
|
||||
|
||||
for(k=>e in anims) {
|
||||
animation.add(e, [for(l in 0...6) k + (l * anims.length)], 0, true);
|
||||
animation.add(e, [for(l in 0...8) k + (l * anims.length)], 0, true);
|
||||
}
|
||||
animation.play(anims[ID]);
|
||||
|
||||
// resize(18, 18);
|
||||
// color = (i > 0) ? 0xFF8888FF : 0xFFFF0000;
|
||||
}
|
||||
|
||||
public override function draw() {
|
||||
@@ -40,26 +31,45 @@ class WindowCaptionButton extends FlxSprite {
|
||||
return;
|
||||
}
|
||||
var mouseInput = DesktopMain.instance.mouseInput;
|
||||
if (DesktopMain.instance.mouseInput.overlaps(this, camera)) {
|
||||
if (mouseInput.justReleased) {
|
||||
switch(ID) {
|
||||
case 0:
|
||||
window.close();
|
||||
case 1:
|
||||
|
||||
|
||||
visible = switch(ID) {
|
||||
case 1 | 2: window.resizeable || window.canMinimize;
|
||||
case 3: window.canHelp;
|
||||
default: true;
|
||||
};
|
||||
|
||||
if(switch(ID) {
|
||||
case 0: window.canClose;
|
||||
case 1: window.resizeable;
|
||||
case 2: window.canMinimize;
|
||||
case 3: window.canHelp;
|
||||
default: true;
|
||||
}) {
|
||||
if (DesktopMain.instance.mouseInput.overlaps(this, camera)) {
|
||||
if (mouseInput.justReleased) {
|
||||
switch(ID) {
|
||||
case 0:
|
||||
if (window.canClose) window.close();
|
||||
case 1:
|
||||
if (window.resizeable) (window.maximized ? window.restore : window.maximize)();
|
||||
case 2:
|
||||
if (window.canMinimize) window.minimize();
|
||||
}
|
||||
mouseInput.cancel();
|
||||
return;
|
||||
}
|
||||
mouseInput.cancel();
|
||||
return;
|
||||
}
|
||||
if (mouseInput.pressed || mouseInput.justPressed) {
|
||||
animation.curAnim.curFrame = 2;
|
||||
} else {
|
||||
animation.curAnim.curFrame = 1;
|
||||
}
|
||||
mouseInput.cancel(); // prevents controls behind this one from updating input
|
||||
} else
|
||||
animation.curAnim.curFrame = 0;
|
||||
if (!window.focused) animation.curAnim.curFrame += 3;
|
||||
if (mouseInput.pressed || mouseInput.justPressed) {
|
||||
animation.curAnim.curFrame = 2;
|
||||
} else {
|
||||
animation.curAnim.curFrame = 1;
|
||||
}
|
||||
mouseInput.cancel(); // prevents controls behind this one from updating input
|
||||
} else
|
||||
animation.curAnim.curFrame = 0;
|
||||
} else {
|
||||
animation.curAnim.curFrame = 3;
|
||||
}
|
||||
if (!window.focused) animation.curAnim.curFrame += 4;
|
||||
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ class WindowContent extends WindowGroup<FlxBasic> {
|
||||
|
||||
public function new(caption:String, x:Float, y:Float, width:Int, height:Int) {
|
||||
super();
|
||||
this.title = caption;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.winX = x;
|
||||
@@ -78,4 +79,9 @@ class WindowContent extends WindowGroup<FlxBasic> {
|
||||
public function create() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function onDesktopSizeChange(width:Int, height:Int) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user