Only show rejoin button if connected (#36)
This commit is contained in:
1 parent
84e4fc4e5d
commit
03f970d3e8
1 file changed
+17
-11
@@ -51,13 +51,9 @@ export class PlayerNameInput extends ex.ScreenElement {
|
|||||||
anchor: ex.vec(0.5, 0),
|
anchor: ex.vec(0.5, 0),
|
||||||
onClick: () => this._rejoinCallback(rejoinClient.id),
|
onClick: () => this._rejoinCallback(rejoinClient.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addChild(this._rejoinButton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._nameInput.on(TextInputEvents.Textchanged, () =>
|
this._nameInput.on(TextInputEvents.Textchanged, () => this._update());
|
||||||
this._updateJoinButtonDisabled(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let y = 0;
|
let y = 0;
|
||||||
this._nameLabel.pos = ex.vec(0, y);
|
this._nameLabel.pos = ex.vec(0, y);
|
||||||
@@ -90,19 +86,29 @@ export class PlayerNameInput extends ex.ScreenElement {
|
|||||||
|
|
||||||
clear(): void {
|
clear(): void {
|
||||||
this._nameInput.text = "";
|
this._nameInput.text = "";
|
||||||
this._updateJoinButtonDisabled();
|
this._update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onConnect(): void {
|
private _onConnect(): void {
|
||||||
this._updateJoinButtonDisabled();
|
this._update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onDisconnect(): void {
|
private _onDisconnect(): void {
|
||||||
this._updateJoinButtonDisabled();
|
this._update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _updateJoinButtonDisabled(): void {
|
private _update(): void {
|
||||||
const disabled = !this._connection.connected || this._nameInput.text === "";
|
const joinDisabled =
|
||||||
this._joinButton.disabled = disabled;
|
!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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user