Skip to content

Commit

Permalink
extract duplicate escape logic to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
WaitingIdly committed Jul 6, 2024
1 parent 2c5c9bb commit 4788e35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,8 @@ public void handleMouseInput() throws IOException {

@Override
public void keyTyped(char c, int keyCode) {
if (keyCode == 1) {
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
this.mc.displayGuiScreen(null);
if (this.mc.currentScreen == null) this.mc.setIngameFocus();
}

if (keyCode == Keyboard.KEY_ESCAPE) {
confirmVolatileClose();
return;
}

Expand Down Expand Up @@ -314,17 +308,20 @@ public boolean onKeyTyped(char c, int keycode) {
}

if (!used && (BQ_Keybindings.openQuests.getKeyCode() == keycode || mc.gameSettings.keyBindInventory.getKeyCode() == keycode)) {
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
this.mc.displayGuiScreen(null);
if (this.mc.currentScreen == null) this.mc.setIngameFocus();
}
confirmVolatileClose();
}

return used;
}

private void confirmVolatileClose() {
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
confirmClose(0);
}
}

@Override
public List<String> getTooltip(int mx, int my) {
ListIterator<IGuiPanel> pnIter = guiPanels.listIterator(guiPanels.size());
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/betterquesting/api2/client/gui/GuiScreenCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,8 @@ public void handleMouseInput() throws IOException {

@Override
public void keyTyped(char c, int keyCode) {
if (keyCode == 1) // ESCAPE
{
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
this.mc.displayGuiScreen(null);
if (this.mc.currentScreen == null) this.mc.setIngameFocus();
}

if (keyCode == Keyboard.KEY_ESCAPE) {
confirmVolatileClose();
return;
}
if (keyCode == BQ_Keybindings.backPage.getKeyCode()) { // BACKSPACE
Expand Down Expand Up @@ -330,17 +323,20 @@ public boolean onKeyTyped(char c, int keycode) {
}

if (!used && (BQ_Keybindings.openQuests.getKeyCode() == keycode || mc.gameSettings.keyBindInventory.getKeyCode() == keycode)) {
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
this.mc.displayGuiScreen(null);
if (this.mc.currentScreen == null) this.mc.setIngameFocus();
}
confirmVolatileClose();
}

return used;
}

private void confirmVolatileClose() {
if (this.isVolatile || this instanceof IVolatileScreen) {
openPopup(new PopChoice(QuestTranslation.translate("betterquesting.gui.closing_warning") + "\n\n" + QuestTranslation.translate("betterquesting.gui.closing_confirm"), PresetIcon.ICON_NOTICE.getTexture(), this::confirmClose, QuestTranslation.translate("gui.yes"), QuestTranslation.translate("gui.no")));
} else {
confirmClose(0);
}
}

@Override
public List<String> getTooltip(int mx, int my) {
ListIterator<IGuiPanel> pnIter = guiPanels.listIterator(guiPanels.size());
Expand Down

0 comments on commit 4788e35

Please sign in to comment.