From 01eb05469a559670de1c4bf5804ddcd58f2fd0ad Mon Sep 17 00:00:00 2001 From: Opaque02 <66582645+Opaque02@users.noreply.github.com> Date: Fri, 6 Sep 2024 00:00:19 +1000 Subject: [PATCH] [QoL] Username finder (#4040) * Added the ability to potentially get username from login screen * Accidentally made dev login enforced :) * Updated image --- public/images/ui/legacy/settings_icon.png | Bin 0 -> 261 bytes public/images/ui/settings_icon.png | Bin 0 -> 261 bytes src/loading-scene.ts | 1 + src/ui/login-form-ui-handler.ts | 99 ++++++++++++++++++---- 4 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 public/images/ui/legacy/settings_icon.png create mode 100644 public/images/ui/settings_icon.png diff --git a/public/images/ui/legacy/settings_icon.png b/public/images/ui/legacy/settings_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..21680cce7fcdc15309a67cc2465c6e5ee921cd56 GIT binary patch literal 261 zcmeAS@N?(olHy`uVBq!ia0vp^;vmey3?#3AQJDm!7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h2Ka=yM#aRKnOgvPWpUylqnJyA{DS}gXSjZf7pRtjv%n*=n1O-sFbFdq z&tH)OQtIjA7@`q8x8G6dfC3NG+W++>lUrB3?3rE^5Mi=5d79fPJ0b5i2{Rw1tSB!m z3NO07uGwDm_Y=JXp$790MX=uY-Mle>j`Jgt-2z5oiPL@^w*Q>}UwC;Gh1;^xF5?nCq9p#v3_#E=aWDeFnGH9xvXk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h2Ka=yM#aRKnOgvPWpUylqnJyA{DS}gXSjZf7pRtjv%n*=n1O-sFbFdq z&tH)OQtIjA7@`q8x8G6dfC3NG+W++>lUrB3?3rE^5Mi=5d79fPJ0b5i2{Rw1tSB!m z3NO07uGwDm_Y=JXp$790MX=uY-Mle>j`Jgt-2z5oiPL@^w*Q>}UwC;Gh1;^xF5?nCq9p#v3_#E=aWDeFnGH9xvX { - const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/google/callback`); - const googleId = import.meta.env.VITE_GOOGLE_CLIENT_ID; - const googleUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${googleId}&redirect_uri=${redirectUri}&response_type=code&scope=openid`; - window.open(googleUrl, "_self"); - }); this.googleImage = googleImage; const discordImage = this.scene.add.image(20, 0, "discord"); @@ -46,12 +46,7 @@ export default class LoginFormUiHandler extends FormModalUiHandler { discordImage.setScale(0.07); discordImage.setInteractive(); discordImage.setName("discord-icon"); - discordImage.on("pointerdown", () => { - const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/discord/callback`); - const discordId = import.meta.env.VITE_DISCORD_CLIENT_ID; - const discordUrl = `https://discord.com/api/oauth2/authorize?client_id=${discordId}&redirect_uri=${redirectUri}&response_type=code&scope=identify&prompt=none`; - window.open(discordUrl, "_self"); - }); + this.discordImage = discordImage; this.externalPartyContainer.add(this.googleImage); @@ -60,6 +55,17 @@ export default class LoginFormUiHandler extends FormModalUiHandler { this.externalPartyContainer.add(this.googleImage); this.externalPartyContainer.add(this.discordImage); this.externalPartyContainer.setVisible(false); + + const usernameInfoImage = this.scene.add.image(20, 0, "settings_icon"); + usernameInfoImage.setOrigin(0, 0); + usernameInfoImage.setScale(0.5); + usernameInfoImage.setInteractive(); + usernameInfoImage.setName("username-info-icon"); + this.usernameInfoImage = usernameInfoImage; + + this.infoContainer.add(this.usernameInfoImage); + this.getUi().add(this.infoContainer); + this.infoContainer.setVisible(false); } getModalTitle(config?: ModalConfig): string { @@ -104,9 +110,8 @@ export default class LoginFormUiHandler extends FormModalUiHandler { show(args: any[]): boolean { if (super.show(args)) { - this.processExternalProvider(); - const config = args[0] as ModalConfig; + this.processExternalProvider(config); const originalLoginAction = this.submitAction; this.submitAction = (_) => { // Prevent overlapping overrides on action modification @@ -146,22 +151,73 @@ export default class LoginFormUiHandler extends FormModalUiHandler { clear() { super.clear(); this.externalPartyContainer.setVisible(false); + this.infoContainer.setVisible(false); this.discordImage.off("pointerdown"); this.googleImage.off("pointerdown"); + this.usernameInfoImage.off("pointerdown"); } - processExternalProvider() : void { + processExternalProvider(config: ModalConfig) : void { this.externalPartyTitle.setText(i18next.t("menu:orUse") ?? ""); this.externalPartyTitle.setX(20+this.externalPartyTitle.text.length); this.externalPartyTitle.setVisible(true); this.externalPartyContainer.setPositionRelative(this.modalContainer, 175, 0); this.externalPartyContainer.setVisible(true); - this.externalPartyBg.setSize(this.externalPartyTitle.text.length+50, this.modalBg.height); + this.externalPartyBg.setSize(this.externalPartyTitle.text.length + 50, this.modalBg.height); this.getUi().moveTo(this.externalPartyContainer, this.getUi().length - 1); this.googleImage.setPosition(this.externalPartyBg.width/3.1, this.externalPartyBg.height-60); this.discordImage.setPosition(this.externalPartyBg.width/3.1, this.externalPartyBg.height-40); + this.infoContainer.setPosition(5, -76); + this.infoContainer.setVisible(true); + this.getUi().moveTo(this.infoContainer, this.getUi().length - 1); + this.usernameInfoImage.setPositionRelative(this.infoContainer, 0, 0); + + this.discordImage.on("pointerdown", () => { + const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/discord/callback`); + const discordId = import.meta.env.VITE_DISCORD_CLIENT_ID; + const discordUrl = `https://discord.com/api/oauth2/authorize?client_id=${discordId}&redirect_uri=${redirectUri}&response_type=code&scope=identify&prompt=none`; + window.open(discordUrl, "_self"); + }); + + this.googleImage.on("pointerdown", () => { + const redirectUri = encodeURIComponent(`${import.meta.env.VITE_SERVER_URL}/auth/google/callback`); + const googleId = import.meta.env.VITE_GOOGLE_CLIENT_ID; + const googleUrl = `https://accounts.google.com/o/oauth2/auth?client_id=${googleId}&redirect_uri=${redirectUri}&response_type=code&scope=openid`; + window.open(googleUrl, "_self"); + }); + + const onFail = error => { + this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); + this.scene.ui.setModeForceTransition(Mode.LOGIN_FORM, Object.assign(config, { errorMessage: error?.trim() })); + this.scene.ui.playError(); + }; + + this.usernameInfoImage.on("pointerdown", () => { + const localStorageKeys = Object.keys(localStorage); // this gets the keys for localStorage + const keyToFind = "data_"; + const dataKeys = localStorageKeys.filter(ls => ls.indexOf(keyToFind) >= 0); + if (dataKeys.length > 0 && dataKeys.length <= 2) { + const options: OptionSelectItem[] = []; + for (let i = 0; i < dataKeys.length; i++) { + options.push({ + label: dataKeys[i].replace(keyToFind, ""), + handler: () => { + this.scene.ui.revertMode(); + return true; + } + }); + } + this.scene.ui.setOverlayMode(Mode.OPTION_SELECT, { + options: options, + delay: 1000 + }); + } else { + return onFail("You have too many save files to use this"); + } + }); + this.externalPartyContainer.setAlpha(0); this.scene.tweens.add({ targets: this.externalPartyContainer, @@ -170,5 +226,14 @@ export default class LoginFormUiHandler extends FormModalUiHandler { y: "-=24", alpha: 1 }); + + this.infoContainer.setAlpha(0); + this.scene.tweens.add({ + targets: this.infoContainer, + duration: Utils.fixedInt(1000), + ease: "Sine.easeInOut", + y: "-=24", + alpha: 1 + }); } }