class ScoreboardWindow {
private browserWindow: RenderWindow | null = null;
private overrides: InputOverrides;
private boundMouseDown = this.onMouseDown.bind(this);
public constructor() {
this.browserWindow = overlay.windows.createInGameWindow({
// ...
});
// Setup our input scope, this makes input blocking multi-window compatibile.
this.overrides = overlay.input.scope("ScoreboardWindow");
}
private onScoreboardWindowShow() {
// Block the game from receiving middle mouse clicks
this.overrides.setKeyInputBlock(0x04, true);
// Make sure the cursor does not appear over the window
this.overrides.setGlobalCursorOverride(false);
// Listen to mouse down events while the window is open
overlay.windows.on("mouseDown", this.boundMouseDown);
}
private onScoreboardWindowHide() {
overlay.windows.off("mouseDown", this.boundMouseDown);
this.resetOverrides();
}
private onMouseDown(event: MouseButtonEvent) {
if (!this.browserWindow?.isVisible()) {
return;
}
// If they click mouse1 and its not on the window
// aka if they click outside the window
// we should hide the window
if (event.key === 0x01 && !event.window) {
this.browserWindow?.hide();
return;
}
// If they didn't click middle mouse button
if (event.key !== 0x04) {
return;
}
// Show the cursor
this.overrides.setGlobalCursorOverride(true);
// Block mouse input to the game
this.overrides.setGlobalMouseBlock(true);
// Allow interacting with the browser window
this.browserWindow?.setCursorOverride(true);
}
// Its important to make sure to reset all blocks when appropraite
private resetOverrides() {
this.overrides.setKeyInputBlock(0x04, false);
this.overrides.setGlobalCursorOverride(false);
this.overrides.setGlobalMouseBlock(false);
this.browserWindow?.setCursorOverride(false);
}
}