neofunkin/src/screens/mainmenu.ts

63 lines
No EOL
2.4 KiB
TypeScript

import { app } from "electron";
import { easeOutCirc, easeOutQuart, easeOutQuint } from "../lib/animations";
import { screenSize, toP, wait } from "../lib/utils";
import wm, {WindowData, wdata} from "../lib/windowManager";
export async function displayMainMenu() {
await app.whenReady();
const mw = wm.create({
w: 20,
h: 20,
whp: true,
onCreate: (win: WindowData) => { win.win.loadURL(`http://localhost:${process.nfenv.serverPort}/screens/mainmenu/`) },
onClose: () => { process.exit(0) }
});
wm.move({ id: mw, x: 50, y: 50, p: true, fromCenter: true });
await wait(500);
wm.resize({ id: mw, w: 40, h: 40, smooth: true, p: true, ease: easeOutQuart });
await wait(500);
const { height: csh, y: csy, width: csw, x: csx } = wdata[mw].win.getBounds();
const { height: sh, width: sw } = screenSize();
const pb = wm.create({
w: 10,
h: 5,
whp: true,
noBorder: true,
noBackground: true,
onCreate: (win: WindowData) => { win.win.loadURL(`http://localhost:${process.nfenv.serverPort}/buttons/openscreen.html?screen=Play`) },
onMaximize: (win: WindowData) => { win.win.restore() },
onResize: (win: WindowData) => { win.win.setSize(win.conf.w, win.conf.h) },
customProps: { maximizable: false }
});
wm.move({ id: pb, y: csy + toP(csh, 60), x: csx - toP(sw, -1.5), fromCenter: true });
wm.follow.start(pb, mw);
const eb = wm.create({
w: 10,
h: 5,
whp: true,
noBorder: true,
noBackground: true,
onCreate: (win: WindowData) => { win.win.loadURL(`http://localhost:${process.nfenv.serverPort}/buttons/exit.html`) },
onMaximize: (win: WindowData) => { win.win.restore() },
onResize: (win: WindowData) => { win.win.setSize(win.conf.w, win.conf.h) },
customProps: { maximizable: false }
});
wm.move({ id: eb, y: csy + toP(csh, 75), x: csx - toP(sw, -1.5), fromCenter: true });
wm.follow.start(eb, mw);
const ob = wm.create({
w: 10,
h: 5,
whp: true,
noBorder: true,
noBackground: true,
onCreate: (win: WindowData) => { win.win.loadURL(`http://localhost:${process.nfenv.serverPort}/buttons/openscreen.html?screen=Options`) },
onMaximize: (win: WindowData) => { win.win.restore() },
onResize: (win: WindowData) => { win.win.setSize(win.conf.w, win.conf.h) },
customProps: { maximizable: false }
});
wm.move({ id: ob, y: csy + toP(csh, 90), x: csx - toP(sw, -1.5), fromCenter: true });
wm.follow.start(ob, mw);
};