Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Create a GuiScreen just before the MainMenu, take an Input via GuiTextField, and return to the main Menu

Featured Replies

Posted

Effectively, here is the code I've currently been working with:

 

Main Class:

@SubscribeEvent
public void onGuiScreen(GuiOpenEvent event) {
  InputMenu menu;
  if (event.gui instanceof GuiMainMenu) {
    menu = new InputMenu(event.gui);
    event.gui = menu;
  }
}

 

InputMenu Class:

public class InputMenu extends GuiScreen {
  private GuiTextField inputField;
  private GuiScreen previousScreen;
  public InputMenu(GuiScreen previousScreen) {
    this.previousScreen = previousScreen; // save the main menu to return to later
  }
  
  @Override
  public void initGui() {
    inputField = new GuiTextField(-1, fontRendererObj ...);
  }
  
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    inputField.drawTextBox();
    inputField.setFocused(true);
  }
  
  @Override
  public void updateScreen() {
    inputField.updateCursorCounter();
  }
  
  @Override
  protected void keyTyped(char typedChar, int keyCode) throws IOException {
    if (keyCode == Keyboard.KEY_RETURN) {
      // go back to menu
      HandleInput();
      mc.displayGuiScreen(previousScreen); // doesn't work
    }
    
    inputField.textboxKeyTyped(typedChar, keyCode);
  }
}

This isn't returning to the main menu, but is instead staying on the InputMenu screen, and only resetting the textField to empty characters upon pressing enter. I can't get it to return, even though I have set the mc.displayGuiScreen correctly. What might be the issue?

 

EDIT: SOLVED

The issue was that GuiOpenEvent got called when I tried to go back to the MainMenu, which, according to my old conditionals, would just display the InputMenu again. Adding a boolean fixed this, by checking if the user has already seen this menu before

Edited by Frontear

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.