window stuff imma go sleep now
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 250 B |
Binary file not shown.
|
After Width: | Height: | Size: 182 B |
Binary file not shown.
|
After Width: | Height: | Size: 152 B |
+1
-1
@@ -1 +1 @@
|
||||
534
|
||||
554
|
||||
@@ -0,0 +1,67 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import lime.app.Application;
|
||||
import openfl.display.BitmapData;
|
||||
import flixel.system.scaleModes.BaseScaleMode;
|
||||
import flixel.system.scaleModes.FixedScaleAdjustSizeScaleMode;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
import flixel.math.FlxPoint;
|
||||
|
||||
class DesktopMain extends MusicBeatState {
|
||||
var oldScaleMode:BaseScaleMode;
|
||||
var wallpaper:FlxSprite;
|
||||
var screenSize:FlxPoint;
|
||||
|
||||
var windows:WindowGroup;
|
||||
|
||||
public var instance:DesktopMain;
|
||||
|
||||
public override function create() {
|
||||
super.create();
|
||||
instance = this;
|
||||
|
||||
FlxG.mouse.visible = true;
|
||||
FlxG.mouse.load(Paths.image('desktop/cursor'));
|
||||
oldScaleMode = FlxG.scaleMode;
|
||||
FlxG.scaleMode = new FixedScaleAdjustSizeScaleMode(false, false);
|
||||
|
||||
wallpaper = new FlxSprite();
|
||||
#if windows
|
||||
try {
|
||||
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
|
||||
add(wallpaper);
|
||||
|
||||
screenSize = new FlxPoint(FlxG.width, FlxG.height);
|
||||
|
||||
windows = new WindowGroup();
|
||||
add(windows);
|
||||
windows.add(new Window("Test Window", 640, 480, 200, 200));
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
|
||||
// trace(FlxG.width, FlxG.height);
|
||||
|
||||
if (screenSize.x != FlxG.width || screenSize.y != FlxG.height) {
|
||||
screenSize.set(FlxG.width, FlxG.height);
|
||||
updateScreenRes();
|
||||
}
|
||||
}
|
||||
|
||||
public function updateScreenRes() {
|
||||
// update wallpaper
|
||||
wallpaper.setUnstretchedGraphicSize(FlxG.width, FlxG.height);
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
super.destroy();
|
||||
FlxG.scaleMode = oldScaleMode;
|
||||
|
||||
// TODO: switch back while using config
|
||||
FlxG.resizeGame(1280, 720);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.group.FlxSpriteGroup;
|
||||
import openfl.geom.Rectangle;
|
||||
import flixel.addons.ui.FlxUI9SliceSprite;
|
||||
import flixel.FlxSprite;
|
||||
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 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(width, height), [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();
|
||||
}
|
||||
|
||||
public function updateWindowFrame() {
|
||||
captionButtons.setPosition(windowWidth - 4, 4);
|
||||
windowFrame.resize(windowWidth, windowHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.addons.ui.FlxUIButton;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
class WindowCaptionButton extends FlxUIButton {
|
||||
public var icon:FlxSprite;
|
||||
|
||||
public function new(window:Window, i:Int) {
|
||||
super(0, 0, "", function() {
|
||||
switch(i) {
|
||||
default:
|
||||
trace(i);
|
||||
}
|
||||
});
|
||||
ID = i;
|
||||
resize(18, 18);
|
||||
color = (i > 0) ? 0xFF8888FF : 0xFFFF0000;
|
||||
|
||||
icon = new FlxSprite(0, 0).loadGraphic(Paths.image('desktop/captionButtons'), true, 18, 18);
|
||||
icon.animation.add("button", [switch(i) {
|
||||
case 0: 2;
|
||||
case 1: 1;
|
||||
case 2: 0;
|
||||
default: i;
|
||||
}]);
|
||||
icon.animation.play("button");
|
||||
}
|
||||
|
||||
public override function draw() {
|
||||
super.draw();
|
||||
|
||||
icon.setPosition(x, y);
|
||||
icon.cameras = this.cameras;
|
||||
icon.draw();
|
||||
icon.scrollFactor.set(scrollFactor.x, scrollFactor.y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package funkin.desktop;
|
||||
|
||||
import flixel.group.FlxGroup.FlxTypedGroup;
|
||||
|
||||
class WindowGroup extends FlxTypedGroup<Window> {
|
||||
// not removing, may be interesting
|
||||
}
|
||||
@@ -122,6 +122,9 @@ class MainMenuState extends MusicBeatState
|
||||
|
||||
if (!selectedSomethin)
|
||||
{
|
||||
if (FlxG.keys.justPressed.SEVEN)
|
||||
FlxG.switchState(new funkin.desktop.DesktopMain());
|
||||
|
||||
if (controls.UP_P)
|
||||
{
|
||||
CoolUtil.playMenuSFX(0);
|
||||
|
||||
@@ -6,6 +6,7 @@ import flixel.animation.FlxAnimation;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.math.FlxMath;
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
using StringTools;
|
||||
|
||||
@@ -130,6 +131,13 @@ class CoolUtil
|
||||
anim2.frames = old;
|
||||
}
|
||||
|
||||
public static function setUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true) {
|
||||
sprite.setGraphicSize(width, height);
|
||||
sprite.updateHitbox();
|
||||
var nScale = (fill ? Math.max : Math.min)(sprite.scale.x, sprite.scale.y);
|
||||
sprite.scale.set(nScale, nScale);
|
||||
}
|
||||
|
||||
public static function keyToString(key:Null<FlxKey>):String {
|
||||
return switch(key) {
|
||||
case null | 0 | NONE: "---";
|
||||
|
||||
Reference in New Issue
Block a user