diff --git a/ccmod.json b/ccmod.json index 5492475..b518b0b 100644 --- a/ccmod.json +++ b/ccmod.json @@ -18,7 +18,7 @@ "open-world": ">=0.5.6", "nax-ccuilib": ">=1.5.1", "tips-and-tricks": ">=0.1.0", - "ccmodmanager": ">=1.0.4", + "ccmodmanager": ">=1.2.1", "font-utils": ">=1.2.0" } } \ No newline at end of file diff --git a/src/patches/gui-misc.ts b/src/patches/gui-misc.ts index 5c66262..7121358 100644 --- a/src/patches/gui-misc.ts +++ b/src/patches/gui-misc.ts @@ -25,6 +25,24 @@ declare global { AP_CONNECTION, } + interface APUpDownInputField extends modmanager.gui.InputField { + tabDirection: "right" | "down"; + maxLength: number; + onEnterPressedCallback?: (this: this) => void; + } + + interface APUpDownInputFieldConstructor extends ImpactClass { + new ( + width: number, + height: number, + type?: modmanager.gui.InputFieldType, + obscure?: boolean, + obscureChar?: string + ): modmanager.gui.InputField; + } + + var APUpDownInputField: APUpDownInputFieldConstructor; + interface APOptionGroup extends ig.GuiElementBase { value: string; buttons: Array, @@ -85,6 +103,37 @@ export function patch(plugin: MwRandomizer) { } }); + sc.APUpDownInputField = modmanager.gui.InputField.extend({ + tabDirection: "down", + maxLength: 100, + processInput(event) { + event.preventDefault(); + if (event.key == "Enter") { + this.onEnterPressedCallback?.(); + } else if (event.key == "ArrowDown") { + this.buttonGroup.stepDown(); + } else if (event.key == "ArrowUp") { + this.buttonGroup.stepUp(); + } else if (event.key == "Tab") { + if (this.tabDirection == 'down') { + if (event.shiftKey) { + this.buttonGroup.stepUp(); + } else { + this.buttonGroup.stepDown(); + } + } else { + if (event.shiftKey) { + this.buttonGroup.stepLeft(); + } else { + this.buttonGroup.stepRight(); + } + } + } else { + this.parent(event); + } + }, + }); + sc.APOptionGroup = ig.GuiElementBase.extend({ buttons: [], value: "", @@ -311,9 +360,9 @@ export function patch(plugin: MwRandomizer) { let inputGui; switch (this.fields[i].type) { case "INPUT": - inputGui = new modmanager.gui.InputField( + inputGui = new sc.APUpDownInputField( 200, - textGui.hook.size.y, + textGui.hook.size.y + 3, modmanager.gui.INPUT_FIELD_TYPE.DEFAULT, this.fields[i].obscure ?? false ); diff --git a/src/patches/text-client.ts b/src/patches/text-client.ts index 0faabbf..af2072d 100644 --- a/src/patches/text-client.ts +++ b/src/patches/text-client.ts @@ -70,8 +70,8 @@ declare global { list: sc.APMessageList; scroll(this: this, amount: number): void; - scrollToBottom(this: this): void; - scrollToTop(this: this): void; + scrollToBottom(this: this, skip?: boolean): void; + scrollToTop(this: this, skip?: boolean): void; addMessage(this: this, message: ap.MessageNode[]): sc.APMessageList.MessageEntry; } @@ -278,6 +278,10 @@ export function patch(plugin: MwRandomizer) { }, recalculateRenderWindow(direction, startIndex) { + if (this.allMessages.length == 0) { + return; + } + if (direction == undefined) { direction = 1; } @@ -355,15 +359,15 @@ export function patch(plugin: MwRandomizer) { this.list.scroll(amount); }, - scrollToBottom() { + scrollToBottom(skip) { let target = this.list.hook.size.y - this.list.viewportHeight; - this.scrollBox.setScrollY(target); + this.scrollBox.setScrollY(target, skip); this.list.viewportPos = target; this.list.recalculateRenderWindow(-1); }, - scrollToTop() { - this.scrollBox.setScrollY(0); + scrollToTop(skip) { + this.scrollBox.setScrollY(0, skip); this.list.viewportPos = 0; this.list.recalculateRenderWindow(1); }, @@ -419,6 +423,7 @@ export function patch(plugin: MwRandomizer) { this.console = new sc.APConsole(400, 260, this.list); this.console.hook.pos.x = 15; this.console.hook.pos.y = 30; + this.console.scrollToBottom(true); this.addChildGui(this.console); this.console.doStateTransition("HIDDEN", true); @@ -504,10 +509,10 @@ export function patch(plugin: MwRandomizer) { this.console.scroll(-this.list.viewportHeight + 10); } else if (ig.input.pressed("pgdn")) { this.console.scroll(this.list.viewportHeight - 10); - } else if (ig.input.pressed("home")) { - this.console.scrollToTop(); - } else if (ig.input.pressed("end")) { - this.console.scrollToBottom(); + } else if (ig.input.pressed("home") || ig.gamepad.isButtonPressed(ig.BUTTONS.LEFT_SHOULDER)) { + this.console.scrollToTop(true); + } else if (ig.input.pressed("end") || ig.gamepad.isButtonPressed(ig.BUTTONS.RIGHT_SHOULDER)) { + this.console.scrollToBottom(true); } if (sc.control.menuScrollUp()) { @@ -516,9 +521,10 @@ export function patch(plugin: MwRandomizer) { this.console.scroll(40); } - let axes = ig.gamepad.getAxesValue(ig.AXES.RIGHT_STICK_Y, true) + let speedup = ig.gamepad.isButtonDown(ig.BUTTONS.RIGHT_TRIGGER); + let axes = ig.gamepad.getAxesValue(ig.AXES.RIGHT_STICK_Y, true); if (Math.abs(axes) != 0) { - this.console.scroll(600 * axes * ig.system.tick); + this.console.scroll(600 * axes * ig.system.tick * (speedup ? 3 : 1)); } },