Change whole gui system

This commit is contained in:
2026-10-01 16:22:02 -03:00
parent 013a4fbb97
commit deba36260e
48 changed files with 1925 additions and 1302 deletions
+30 -11
View File
@@ -11,7 +11,7 @@ import { MultiPlayerGameMode } from "./game_mode.ts";
import { ClientPacketListener } from "./packet_listener.ts";
import { GameRenderer } from "./rendering/game_renderer.ts";
import { ChatComponent } from "./gui/chat_component.ts";
import { GuiInventoryScreen, GuiScreen } from "./gui/gui_screen.ts";
import { GuiMenuScreen, GuiScreen } from "./gui/gui_screen.ts";
import { GuiPlayerInventory } from "./gui/gui_player_inventory.ts";
import { GuiChat } from "./gui/gui_chat.ts";
import { InputManager } from "./input_manager.ts";
@@ -19,6 +19,7 @@ import { Connection } from "./network.ts";
import { PauseScreen } from "./gui/pause_screen.ts";
import { back_to_title } from "./gui/title_screen.ts";
import { TICK_DELTA } from "$/common/constants.ts";
import { PLAYER_MENU } from "$/common/protocol.ts";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import type { EntityJson } from "$/common/mod_data.ts";
@@ -97,8 +98,26 @@ export class Client {
this.screens.push(screen);
}
// the player closed the one on top
pop_screen() {
this.screens.pop()?.on_close();
const screen = this.screens.pop();
screen?.on_close();
screen?.on_removed();
}
// the player closed this one, wherever it is
close_screen(screen: GuiScreen) {
if (!this.screens.includes(screen)) return;
this.screens = this.screens.filter((s) => s !== screen);
screen.on_close();
screen.on_removed();
}
// takes these off without closing them, like when the server opens a menu or closes it
remove_screens(which: (screen: GuiScreen) => boolean) {
const removed = this.screens.filter(which);
this.screens = this.screens.filter((s) => !which(s));
for (const screen of removed) screen.on_removed();
}
// leaving on purpose, from the pause screen
@@ -194,7 +213,7 @@ export class Client {
if (InputManager.is_key_pressed(options.key_inventory)) {
if (!this.screen) {
this.push_screen(new GuiPlayerInventory(player.inventories, (m) => this.connection.send(m)));
} else if (this.screen instanceof GuiInventoryScreen) {
} else if (this.screen instanceof GuiMenuScreen) {
this.pop_screen();
}
}
@@ -212,7 +231,7 @@ export class Client {
const lost_mouse = InputManager.take_lost_pointer_lock();
if (InputManager.is_key_pressed("Escape")) {
if (this.screen) {
this.pop_screen();
if (this.screen.close_on_escape()) this.pop_screen();
} else {
this.push_screen(new PauseScreen(this));
}
@@ -233,15 +252,15 @@ export class Client {
const inventories = this.player.inventories;
const screen = this.screen;
if (!screen) {
this.game_mode.drop_item(inventories.inventory, "inventory", inventories.hotbar_selected, all);
// the hotbar slot of menu 0, they're the same numbers
const slot = inventories.hotbar_selected;
this.game_mode.drop_item(inventories.inventory, slot, PLAYER_MENU, slot, all);
return;
}
const slot = screen instanceof GuiInventoryScreen ? screen.hovering : undefined;
const container = slot && screen instanceof GuiInventoryScreen
? screen.get_container(slot.container)
: undefined;
if (slot && container && !slot.output && !inventories.cursor.item) {
this.game_mode.drop_item(container, slot.container, slot.index, all);
const slot = screen instanceof GuiMenuScreen ? screen.hovering : undefined;
if (screen instanceof GuiMenuScreen && slot && !slot.output && !inventories.cursor.item) {
const index = screen.menu.slots.indexOf(slot);
this.game_mode.drop_item(slot.container, slot.index, screen.menu.id, index, all);
}
}