Improve chat input
This commit is contained in:
@@ -45,6 +45,7 @@ export class GuiChat extends GuiScreen {
|
||||
this.client.chat.render(true, y - 8);
|
||||
draw_rect(0, y, canvas.width, canvas.height, [0, 0, 0, 0.4]);
|
||||
|
||||
this.input.draw_selection(0, y + 4, INPUT_HEIGHT - 4, SCALE);
|
||||
draw_text(this.input.value, 0, y, SCALE, [1, 1, 1]);
|
||||
draw_rect(this.input.caret_x(0, SCALE), y + 4, 1, INPUT_HEIGHT - 4);
|
||||
|
||||
@@ -53,6 +54,8 @@ export class GuiChat extends GuiScreen {
|
||||
|
||||
override on_tick(_delta: number): void {
|
||||
this.#handle_suggestion_keys();
|
||||
const y = canvas.height - INPUT_HEIGHT;
|
||||
this.input.handle_mouse({ x: 0, y, width: canvas.width, height: INPUT_HEIGHT }, 0, SCALE);
|
||||
this.input.handle_keys();
|
||||
this.#ask_for_suggestions();
|
||||
if (InputManager.is_key_pressed("Enter")) {
|
||||
@@ -112,7 +115,7 @@ export class GuiChat extends GuiScreen {
|
||||
const caret = this.input.caret;
|
||||
const start = Math.min(this.suggestions_start, caret);
|
||||
this.input.value = (value.slice(0, start) + suggestion.text + value.slice(caret)).slice(0, MAX_CHAT_LENGTH);
|
||||
this.input.caret = Math.min(start + suggestion.text.length, this.input.value.length);
|
||||
this.input.move_caret(start + suggestion.text.length);
|
||||
// the list stays for tabbing through, it's asked for again once they type
|
||||
this.#asked = this.input.value.slice(0, this.input.caret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user