diff --git a/src/frontend/src/UIElements/PlayerNameInput.ts b/src/frontend/src/UIElements/PlayerNameInput.ts index 5e06157..64ef49d 100644 --- a/src/frontend/src/UIElements/PlayerNameInput.ts +++ b/src/frontend/src/UIElements/PlayerNameInput.ts @@ -51,13 +51,9 @@ export class PlayerNameInput extends ex.ScreenElement { anchor: ex.vec(0.5, 0), onClick: () => this._rejoinCallback(rejoinClient.id), }); - - this.addChild(this._rejoinButton); } - this._nameInput.on(TextInputEvents.Textchanged, () => - this._updateJoinButtonDisabled(), - ); + this._nameInput.on(TextInputEvents.Textchanged, () => this._update()); let y = 0; this._nameLabel.pos = ex.vec(0, y); @@ -90,19 +86,29 @@ export class PlayerNameInput extends ex.ScreenElement { clear(): void { this._nameInput.text = ""; - this._updateJoinButtonDisabled(); + this._update(); } private _onConnect(): void { - this._updateJoinButtonDisabled(); + this._update(); } private _onDisconnect(): void { - this._updateJoinButtonDisabled(); + this._update(); } - private _updateJoinButtonDisabled(): void { - const disabled = !this._connection.connected || this._nameInput.text === ""; - this._joinButton.disabled = disabled; + private _update(): void { + const joinDisabled = + !this._connection.connected || this._nameInput.text === ""; + this._joinButton.disabled = joinDisabled; + + if (this._rejoinButton != null) { + const rejoinVisible = this._connection.connected; + if (rejoinVisible) { + this.addChild(this._rejoinButton); + } else { + this.removeChild(this._rejoinButton); + } + } } }