you can maximize windows now + messageboxes

This commit is contained in:
Yoshman29
2022-10-28 00:36:19 +02:00
parent 2398a44ed8
commit 0aba35ccf3
17 changed files with 250 additions and 61 deletions
+1 -3
View File
@@ -3,13 +3,11 @@
<captionActive path="caption" textColor="255,255,255" left="5" top="30" right="5" bottom="5" />
<captionInactive path="captionInactive" textColor="216,228,248" left="5" top="30" right="5" bottom="5" />
<captionButtons path="captionButtons" size="21,21" margin="2,0" offset="4,6" />
<window color="#ECE9D8" textColor="0,0,0" font="file://C:/Windows/fonts/tahoma.ttf" fontSize="11"/>
<!-- BUTTONS !-->
<normalButton path="button" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<hoverButton path="buttonHover" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<pressedButton path="buttonPressed" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<disabledButton path="buttonDisabled" textColor="128,128,128" left="4" top="4" right="4" bottom="4" />
<!-- TEXT !-->
<text font="%WinDir%/fonts/tahoma.ttf" size="11"/>
</theme>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 19 KiB

+1 -1
View File
@@ -1 +1 @@
779
807
@@ -3,13 +3,11 @@
<captionActive path="caption" textColor="255,255,255" left="5" top="30" right="5" bottom="5" />
<captionInactive path="captionInactive" textColor="216,228,248" left="5" top="30" right="5" bottom="5" />
<captionButtons path="captionButtons" size="21,21" margin="2,0" offset="4,6" />
<window color="#ECE9D8" textColor="0,0,0" font="file://C:/Windows/fonts/tahoma.ttf" fontSize="11"/>
<!-- BUTTONS !-->
<normalButton path="button" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<hoverButton path="buttonHover" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<pressedButton path="buttonPressed" textColor="0,0,0" left="4" top="4" right="4" bottom="4" />
<disabledButton path="buttonDisabled" textColor="128,128,128" left="4" top="4" right="4" bottom="4" />
<!-- TEXT !-->
<text font="%WinDir%/fonts/tahoma.ttf" size="11"/>
</theme>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 19 KiB

File diff suppressed because one or more lines are too long
+12
View File
@@ -70,9 +70,16 @@ class DesktopMain extends MusicBeatState {
windows.add(new Window(new CharacterEditor('dad')));
}
public function openWindow(content:WindowContent) {
return windows.add(new Window(content));
}
public function updateScreenRes() {
// update wallpaper
wallpaper.setUnstretchedGraphicSize(FlxG.width, FlxG.height);
for(e in windows) {
e.onDesktopSizeChange(FlxG.width, FlxG.height);
}
}
public override function destroy() {
@@ -130,6 +137,11 @@ class MouseInput {
public function overlapsRect(spr:FlxBasic, rect:Rectangle, ?camera:FlxCamera) {
if (__cancelled) return false;
if (camera == null) camera = FlxG.camera;
if (spr is FlxObject) {
var obj = cast(spr, FlxObject);
rect.x -= camera.scroll.x * obj.scrollFactor.x;
rect.y -= camera.scroll.y * obj.scrollFactor.y;
}
var pos = FlxG.mouse.getScreenPosition(camera);
return ((pos.x > rect.x) && (pos.x < rect.x + rect.width)) && ((pos.y > rect.y) && (pos.y < rect.y + rect.height));
+4 -8
View File
@@ -3,7 +3,6 @@ package funkin.desktop.editors;
import flixel.util.FlxDestroyUtil.IFlxDestroyable;
import flixel.addons.ui.FlxUIText;
import flixel.FlxG;
import funkin.desktop.sprites.*;
class HelloWorld extends WindowContent {
public override function new() {
@@ -13,26 +12,23 @@ class HelloWorld extends WindowContent {
public override function create() {
super.create();
var helloWorldText = new FlxUIText(0, 0, 0, "Hello, World!");
helloWorldText.color = 0xFF000000;
var helloWorldText = new WindowText(0, 0, 0, "Hello, World!");
helloWorldText.scrollFactor.set(0.5, 0.5);
helloWorldText.cameraCenter(camera);
add(helloWorldText);
var t = new FlxUIText(0, 0, 0, "Bottom right text!");
t.color = 0xFF000000;
var t = new WindowText(0, 0, 0, "Bottom right text!");
t.setPosition(630 - t.width, 470 - t.height);
t.scrollFactor.set(1, 1);
add(t);
var t = new FlxUIText(0, 0, 0, "Top right text!");
t.color = 0xFF000000;
var t = new WindowText(0, 0, 0, "Top right text!");
t.setPosition(630 - t.width, 10);
t.scrollFactor.set(1, 0);
add(t);
var butt = new Button(10, 10, "Test", function() {
trace("help");
parent.showMessage("Test", "Test", ERROR);
});
butt.scrollFactor.set();
add(butt);
@@ -0,0 +1,73 @@
package funkin.desktop.editors;
import flixel.util.typeLimit.OneOfTwo;
import flixel.util.FlxDestroyUtil.IFlxDestroyable;
import flixel.addons.ui.FlxUIText;
import flixel.FlxG;
class MessageBox extends WindowContent {
public var caption:String;
public var message:String;
public var msgIcon:MessageBoxIcon;
public var callback:Int->Void = null;
private var __buttons:Array<OneOfTwo<String, Butt>> = null;
public override function new(caption:String, message:String, icon:MessageBoxIcon, ?buttons:Array<OneOfTwo<String, Butt>>, ?callback:Int->Void) {
super(caption, 100, 100, 500, 500);
this.caption = caption;
this.message = message;
this.msgIcon = icon;
this.callback = callback;
this.__buttons = buttons;
}
public override function create() {
super.create();
parent.canMinimize = parent.resizeable = false;
var text = new WindowText(10, 10, 0, message);
if (text.width > 500)
text.fieldWidth = 500;
add(text);
setSize(Std.int(Math.max(text.width + 20, 240)), Std.int(text.height + 20));
if (__buttons == null) __buttons = ["OK"];
else if (__buttons.length <= 0) __buttons.push("OK");
var firstButt:Button = null;
for(k=>b in __buttons) {
var label:String = null;
var callback:Void->Void = null;
if (b is String) {
label = cast(b, String);
} else if (b is Dynamic) {
label = Reflect.field(b, "label");
callback = Reflect.field(b, "callback");
}
var button = new Button(490, 490, label, function() {
parent.close();
if (callback != null) callback();
if (this.callback != null) this.callback(k);
});
button.x -= button.width;
button.y -= button.height;
add(button);
if (firstButt == null) firstButt = button;
}
setSize(Std.int(width), Std.int(height + firstButt.height + 10));
}
}
@:enum
abstract MessageBoxIcon(Int) {
var ERROR = 0;
var ALERT = 1;
var INFORMATION = 2;
var QUESTION = 3;
}
// HAHA BUTT!! *minion laugh*
typedef Butt = {
var label:String;
@:optional var callback:Void->Void;
}
+2 -1
View File
@@ -1,3 +1,4 @@
package funkin.desktop.editors;
import funkin.desktop.windows.*;
import funkin.desktop.windows.*;
import funkin.desktop.sprites.*;
+15 -3
View File
@@ -1,5 +1,6 @@
package funkin.desktop.sprites;
import funkin.desktop.theme.Theme;
import flixel.FlxObject;
import flixel.addons.ui.FlxUIText;
import flixel.FlxSprite;
@@ -18,7 +19,15 @@ class Button extends FlxObject {
public var pressedSprite:SpliceSprite;
public var disabledSprite:SpliceSprite;
public var label:FlxUIText;
public var label:WindowText;
private override function get_width() {
return normalSprite.width;
}
private override function get_height() {
return normalSprite.height;
}
public function new(x:Float, y:Float, text:String = "", callback:Void->Void) {
super();
@@ -38,7 +47,8 @@ class Button extends FlxObject {
pressedSprite = new SpliceSprite(Paths.image(pressedButton.sprite), x, y, 75, 24, pressedButton.left, pressedButton.top, pressedButton.bottom, pressedButton.right);
disabledSprite = new SpliceSprite(Paths.image(disabledButton.sprite), x, y, 75, 24, disabledButton.left, disabledButton.top, disabledButton.bottom, disabledButton.right);
label = new FlxUIText(0, 0, 75, text);
label = new WindowText(0, 0, 75, text);
label.alignment = CENTER;
}
public override function update(elapsed:Float) {
@@ -97,7 +107,9 @@ class Button extends FlxObject {
sprite.cameras = cameras;
sprite.setPosition(x, y);
sprite.scrollFactor.set(scrollFactor.x, scrollFactor.y);
sprite.draw();
}
spr.draw();
label.y += (height - label.height) / 2;
label.draw();
}
}
@@ -0,0 +1,25 @@
package funkin.desktop.sprites;
import flixel.text.FlxText;
import flixel.addons.ui.FlxUIText;
import funkin.desktop.theme.Theme.ThemeData;
class WindowText extends FlxText {
// TODO: VISUAL STYLES SHIT
public function new(x:Float, y:Float, w:Float, t:String) {
super(x, y, w, t);
color = 0xFF000000;
scrollFactor.set();
applyFontSettings(DesktopMain.theme.window);
// setFormat(Paths.font(.font))
}
public function applyFontSettings(data:ThemeData) {
var fontPath = Paths.font(data.font);
if (data.font.startsWith("file://")) {
fontPath = data.font.substr(7);
while(fontPath.charAt(0) == "/") fontPath = fontPath.substr(1);
}
setFormat(fontPath, Std.int(data.fontSize), data.textColor);
}
}
+10 -2
View File
@@ -24,8 +24,9 @@ class Theme {
}
/**
* CAPTION
* CAPTION & WINDOW
*/
public var window:ThemeData = new ThemeData();
public var captionActive:ThemeData = new ThemeData();
public var captionInactive:ThemeData = new ThemeData();
public var captionButtons:ThemeData = new ThemeData();
@@ -52,6 +53,9 @@ class Theme {
if (element.has.path) data.sprite = '$prefix${element.att.path.trim()}';
if (element.has.textColor) data.textColor = element.att.textColor.getColorFromDynamic();
if (element.has.font) data.font = element.att.font;
if (element.has.color) data.color = element.att.color.getColorFromDynamic();
if (element.has.fontSize) data.fontSize = Std.parseFloat(element.att.fontSize).getDefault(0);
if (element.has.left) data.left = Std.parseFloat(element.att.left).getDefault(0);
if (element.has.right) data.right = Std.parseFloat(element.att.right).getDefault(0);
if (element.has.top) data.top = Std.parseFloat(element.att.top).getDefault(0);
@@ -86,7 +90,11 @@ class Theme {
class ThemeData implements IFlxDestroyable {
public var sprite:String = "";
public var textColor:FlxColor = FlxColor.WHITE;
public var font:String = "";
public var fontSize:Float = 12;
public var textColor:FlxColor = FlxColor.BLACK;
public var color:FlxColor = FlxColor.WHITE;
public var left:Float = 4;
public var bottom:Float = 4;
+55 -5
View File
@@ -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) {
}
}
+4 -4
View File
@@ -767,14 +767,14 @@ class PlayState extends MusicBeatState
var iconOffset:Int = 26;
iconP1.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01) - iconOffset);
iconP2.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)) - (iconP2.width - iconOffset);
iconP1.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 1, 0)) - iconOffset);
iconP2.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 1, 0))) - (iconP2.width - iconOffset);
if (health > 2)
health = 2;
iconP1.health = healthBar.percent;
iconP2.health = 1 - (healthBar.percent);
iconP1.health = healthBar.percent / 100;
iconP2.health = 1 - (healthBar.percent / 100);
/* if (FlxG.keys.justPressed.NINE)
FlxG.switchState(new Charting()); */