2024-03-13 06:01:33 +00:00
|
|
|
import { el } from "../../etc";
|
|
|
|
import { u2 } from "../../num";
|
|
|
|
import { UiEventHandler, UiEvent } from "../../events";
|
|
|
|
import UiComponent from "../uiComponent";
|
|
|
|
|
|
|
|
export default class BankSelector implements UiComponent {
|
|
|
|
container: HTMLElement;
|
|
|
|
events: UiEventHandler;
|
2024-03-26 03:03:20 +00:00
|
|
|
bank_buttons: Array<HTMLButtonElement>;
|
2024-03-13 06:01:33 +00:00
|
|
|
constructor(element: HTMLElement, events: UiEventHandler) {
|
|
|
|
this.container = element;
|
|
|
|
this.events = events;
|
|
|
|
|
|
|
|
const bank_boxes = el("div").id("bank_boxes").fin();
|
|
|
|
this.bank_buttons = [];
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
const button = el("button").cl("nostyle").fin();
|
|
|
|
bank_boxes.appendChild(button);
|
|
|
|
button.addEventListener("click", () => {
|
|
|
|
for (const b of this.bank_buttons) b.classList.remove("selected");
|
|
|
|
button.classList.add("selected");
|
|
|
|
this.events.dispatch(UiEvent.ChangeViewBank, { bank: i as u2 });
|
|
|
|
});
|
|
|
|
button.textContent = i.toString();
|
|
|
|
this.bank_buttons.push(button);
|
|
|
|
}
|
|
|
|
this.bank_buttons[0].classList.add("selected");
|
|
|
|
|
|
|
|
this.container.appendChild(bank_boxes);
|
|
|
|
}
|
2024-03-26 03:03:20 +00:00
|
|
|
|
2024-03-13 06:01:33 +00:00
|
|
|
reset(): void {
|
|
|
|
for (const b of this.bank_buttons) b.classList.remove("selected");
|
|
|
|
this.bank_buttons[0].classList.add("selected");
|
|
|
|
}
|
2024-03-26 03:03:20 +00:00
|
|
|
|
|
|
|
softReset(): void {
|
|
|
|
this.reset();
|
|
|
|
}
|
2024-03-13 06:01:33 +00:00
|
|
|
}
|