[Bug] resolve issue with input text persisting in top left of game screen in certain cases (#1982)

* resolve issue with input text persisting in top left of game screen in certain cases

* Clean up ui logic for fix
This commit is contained in:
SquillWall 2024-06-10 12:41:01 -04:00 committed by GitHub
parent 29d9ac7038
commit f672ecc8ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 73 additions and 16 deletions

View File

@ -193,8 +193,21 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
private pokemonHatchedIcon : Phaser.GameObjects.Sprite; private pokemonHatchedIcon : Phaser.GameObjects.Sprite;
private pokemonHatchedCountText: Phaser.GameObjects.Text; private pokemonHatchedCountText: Phaser.GameObjects.Text;
private genOptionsText: Phaser.GameObjects.Text; private genOptionsText: Phaser.GameObjects.Text;
private instructionsContainer: Phaser.GameObjects.Container; private instructionsContainer: Phaser.GameObjects.Container;
private instructionsText: Phaser.GameObjects.Text; private shinyIconElement: Phaser.GameObjects.Sprite;
private formIconElement: Phaser.GameObjects.Sprite;
private abilityIconElement: Phaser.GameObjects.Sprite;
private genderIconElement: Phaser.GameObjects.Sprite;
private natureIconElement: Phaser.GameObjects.Sprite;
private variantIconElement: Phaser.GameObjects.Sprite;
private shinyLabel: Phaser.GameObjects.Text;
private formLabel: Phaser.GameObjects.Text;
private genderLabel: Phaser.GameObjects.Text;
private abilityLabel: Phaser.GameObjects.Text;
private natureLabel: Phaser.GameObjects.Text;
private variantLabel: Phaser.GameObjects.Text;
private starterSelectMessageBox: Phaser.GameObjects.NineSlice; private starterSelectMessageBox: Phaser.GameObjects.NineSlice;
private starterSelectMessageBoxContainer: Phaser.GameObjects.Container; private starterSelectMessageBoxContainer: Phaser.GameObjects.Container;
private statsContainer: StatsContainer; private statsContainer: StatsContainer;
@ -656,10 +669,43 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.starterSelectContainer.add(this.pokemonEggMovesContainer); this.starterSelectContainer.add(this.pokemonEggMovesContainer);
// The font size should be set per language // The font size should be set per language
const instructionTextSize = textSettings.instructionTextSize;
this.instructionsContainer = this.scene.add.container(4, 156); this.instructionsContainer = this.scene.add.container(4, 156);
this.instructionsContainer.setVisible(true); this.instructionsContainer.setVisible(true);
this.starterSelectContainer.add(this.instructionsContainer); this.starterSelectContainer.add(this.instructionsContainer);
// instruction rows that will be pushed into the container dynamically based on need
this.shinyIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "R.png");
this.shinyIconElement.setScale(0.675);
this.shinyIconElement.setOrigin(0.0, 0.0);
this.shinyLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleShiny"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.formIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "F.png");
this.formIconElement.setScale(0.675);
this.formIconElement.setOrigin(0.0, 0.0);
this.formLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleForm"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.genderIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "G.png");
this.genderIconElement.setScale(0.675);
this.genderIconElement.setOrigin(0.0, 0.0);
this.genderLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleGender"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.abilityIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "E.png");
this.abilityIconElement.setScale(0.675);
this.abilityIconElement.setOrigin(0.0, 0.0);
this.abilityLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleAbility"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.natureIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "N.png");
this.natureIconElement.setScale(0.675);
this.natureIconElement.setOrigin(0.0, 0.0);
this.natureLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleNature"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.variantIconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, "keyboard", "V.png");
this.variantIconElement.setScale(0.675);
this.variantIconElement.setOrigin(0.0, 0.0);
this.variantLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("starterSelectUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize });
this.starterSelectMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); this.starterSelectMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6);
this.starterSelectMessageBoxContainer.setVisible(false); this.starterSelectMessageBoxContainer.setVisible(false);
this.starterSelectContainer.add(this.starterSelectMessageBoxContainer); this.starterSelectContainer.add(this.starterSelectMessageBoxContainer);
@ -1494,7 +1540,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
this.setSpeciesDetails(this.lastSpecies, undefined, undefined, undefined, undefined, undefined, undefined, false); this.setSpeciesDetails(this.lastSpecies, undefined, undefined, undefined, undefined, undefined, undefined, false);
} }
createButtonFromIconText(iconSetting, gamepadType, translatedText, instructionTextSize): void { updateButtonIcon(iconSetting, gamepadType, iconElement, controlLabel): void {
let iconPath; let iconPath;
// touch controls cannot be rebound as is, and are just emulating a keyboard event. // touch controls cannot be rebound as is, and are just emulating a keyboard event.
// Additionally, since keyboard controls can be rebound (and will be displayed when they are), we need to have special handling for the touch controls // Additionally, since keyboard controls can be rebound (and will be displayed when they are), we need to have special handling for the touch controls
@ -1525,10 +1571,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
} else { } else {
iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting);
} }
const iconElement = this.scene.add.sprite(this.instructionRowX, this.instructionRowY, gamepadType, iconPath); iconElement.setTexture(gamepadType, iconPath);
iconElement.setScale(0.675); iconElement.setPosition(this.instructionRowX, this.instructionRowY);
iconElement.setOrigin(0.0, 0.0); controlLabel.setPosition(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY);
const controlLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, translatedText, TextStyle.PARTY, { fontSize: instructionTextSize });
this.instructionsContainer.add([iconElement, controlLabel]); this.instructionsContainer.add([iconElement, controlLabel]);
this.instructionRowY += 8; this.instructionRowY += 8;
if (this.instructionRowY >= 24) { if (this.instructionRowY >= 24) {
@ -1538,10 +1583,6 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
} }
updateInstructions(): void { updateInstructions(): void {
const currentLanguage = i18next.resolvedLanguage;
const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang));
const textSettings = languageSettings[langSettingKey];
const instructionTextSize = textSettings.instructionTextSize;
this.instructionRowX = 0; this.instructionRowX = 0;
this.instructionRowY = 0; this.instructionRowY = 0;
this.instructionsContainer.removeAll(); this.instructionsContainer.removeAll();
@ -1554,22 +1595,22 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (this.speciesStarterDexEntry?.caughtAttr) { if (this.speciesStarterDexEntry?.caughtAttr) {
if (this.canCycleShiny) { if (this.canCycleShiny) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Shiny, gamepadType, i18next.t("starterSelectUiHandler:cycleShiny"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Shiny, gamepadType, this.shinyIconElement, this.shinyLabel);
} }
if (this.canCycleForm) { if (this.canCycleForm) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Form, gamepadType, i18next.t("starterSelectUiHandler:cycleForm"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Form, gamepadType, this.formIconElement, this.formLabel);
} }
if (this.canCycleGender) { if (this.canCycleGender) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Gender, gamepadType, i18next.t("starterSelectUiHandler:cycleGender"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Gender, gamepadType, this.genderIconElement, this.genderLabel);
} }
if (this.canCycleAbility) { if (this.canCycleAbility) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Ability, gamepadType, i18next.t("starterSelectUiHandler:cycleAbility"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Ability, gamepadType, this.abilityIconElement, this.abilityLabel);
} }
if (this.canCycleNature) { if (this.canCycleNature) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Nature, gamepadType, i18next.t("starterSelectUiHandler:cycleNature"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Nature, gamepadType, this.natureIconElement, this.natureLabel);
} }
if (this.canCycleVariant) { if (this.canCycleVariant) {
this.createButtonFromIconText(SettingKeyboard.Button_Cycle_Variant, gamepadType, i18next.t("starterSelectUiHandler:cycleVariant"), instructionTextSize); this.updateButtonIcon(SettingKeyboard.Button_Cycle_Variant, gamepadType, this.variantIconElement, this.variantLabel);
} }
} }
} }
@ -2341,9 +2382,25 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
super.clearText(); super.clearText();
} }
hideInstructions(): void {
this.shinyIconElement.setVisible(false);
this.shinyLabel.setVisible(false);
this.formIconElement.setVisible(false);
this.formLabel.setVisible(false);
this.genderIconElement.setVisible(false);
this.genderLabel.setVisible(false);
this.abilityIconElement.setVisible(false);
this.abilityLabel.setVisible(false);
this.natureIconElement.setVisible(false);
this.natureLabel.setVisible(false);
this.variantIconElement.setVisible(false);
this.variantLabel.setVisible(false);
}
clear(): void { clear(): void {
super.clear(); super.clear();
this.cursor = -1; this.cursor = -1;
this.hideInstructions();
this.starterSelectContainer.setVisible(false); this.starterSelectContainer.setVisible(false);
this.blockInput = false; this.blockInput = false;