Add trash button to delete sheet

This commit is contained in:
dylan 2023-05-06 15:01:01 -07:00
parent 64c889e16a
commit 9f67a59033
2 changed files with 31 additions and 2 deletions

View File

@ -6,8 +6,8 @@ import { COLOR } from "./colors.ts";
import { mouseClick, mousePos } from "./mouse.ts"; import { mouseClick, mousePos } from "./mouse.ts";
import { drawIcon } from "./builtins.ts"; import { drawIcon } from "./builtins.ts";
import { inRect } from "./util.ts"; import { inRect } from "./util.ts";
import { sheetsIcon } from "./icons.ts"; import { sheetsIcon, trashIcon } from "./icons.ts";
import { SheetType } from "./sheet.ts"; import { SheetType, setSheet } from "./sheet.ts";
import { nonetab } from "./nonetab.ts"; import { nonetab } from "./nonetab.ts";
type TabName = SheetType; // "code" | "sprite" | "map" | "sfx" | "music" | "sheet"; type TabName = SheetType; // "code" | "sprite" | "map" | "sfx" | "music" | "sheet";
@ -29,9 +29,27 @@ const makeTabButton = (tabname: TabName | "sheet", x: number, y: number, icon: A
}) })
} }
const makeTrashButton = (x: number, y: number, icon: Array<number>) => {
buttons.push({
update() {
if (mouseClick()) {
const {x: mouseX, y: mouseY} = mousePos();
if (inRect(mouseX, mouseY, x, y, 8, 8)) {
setSheet(page.activeSheet, "none", null);
page.tab = "sheet";
}
}
},
draw() {
drawIcon(x, y, icon, COLOR.BLACK);
}
})
}
// makeTabButton("code", 88, 0, codeIcon); // makeTabButton("code", 88, 0, codeIcon);
// makeTabButton("sprite", 88+8, 0, spriteIcon); // makeTabButton("sprite", 88+8, 0, spriteIcon);
makeTabButton("sheet", 120, 0, sheetsIcon); makeTabButton("sheet", 120, 0, sheetsIcon);
makeTrashButton(0, 0, trashIcon);
const update = () => { const update = () => {
buttons.forEach(button => button.update()); buttons.forEach(button => button.update());

View File

@ -30,3 +30,14 @@ export const sheetsIcon = [
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]; ];
export const trashIcon = [
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
];