Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Menu Page History Fix #2993

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Deque;
import java.util.LinkedList;
import java.util.Objects;
Mooy1 marked this conversation as resolved.
Show resolved Hide resolved

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -28,6 +29,7 @@ public class GuideHistory {

private final PlayerProfile profile;
private final Deque<GuideEntry<?>> queue = new LinkedList<>();
private int mainMenuPage = 1;

/**
* This creates a new {@link GuideHistory} for the given {@link PlayerProfile}
Expand All @@ -47,6 +49,27 @@ public void clear() {
queue.clear();
}

/**
* This method sets the page of the main menu of this {@link GuideHistory}
*
* @param page
* The current page of the main menu that should be stored
*/
public void setMainMenuPage(int page) {
Validate.isTrue(page >= 1, "page must be greater than 0!");

mainMenuPage = page;
}

/**
* This returns the current main menu page of this {@link GuideHistory}
*
* @return The main menu page of this {@link GuideHistory}
*/
public int getMainMenuPage() {
return mainMenuPage;
}

/**
* This method adds a {@link Category} to this {@link GuideHistory}.
* Should the {@link Category} already be the last element in this {@link GuideHistory},
Expand Down Expand Up @@ -165,7 +188,7 @@ public void goBack(@Nonnull SlimefunGuideImplementation guide) {

private <T> void open(@Nonnull SlimefunGuideImplementation guide, @Nullable GuideEntry<T> entry) {
if (entry == null) {
guide.openMainMenu(profile, 1);
guide.openMainMenu(profile, mainMenuPage);
} else if (entry.getIndexedObject() instanceof Category) {
guide.openCategory(profile, (Category) entry.getIndexedObject(), entry.getPage());
} else if (entry.getIndexedObject() instanceof SlimefunItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void openMainMenu(PlayerProfile profile, int page) {
if (isSurvivalMode()) {
profile.getGuideHistory().clear();
}
profile.getGuideHistory().setMainMenuPage(page);
Mooy1 marked this conversation as resolved.
Show resolved Hide resolved

ChestMenu menu = create(p);
List<Category> categories = getVisibleCategories(p, profile);
Expand Down Expand Up @@ -602,7 +603,7 @@ private void addBackButton(ChestMenu menu, int slot, Player p, PlayerProfile pro

menu.addMenuClickHandler(slot, (pl, s, is, action) -> {
if (action.isShiftClicked()) {
openMainMenu(profile, 1);
openMainMenu(profile, profile.getGuideHistory().getMainMenuPage());
} else {
history.goBack(this);
}
Expand All @@ -612,7 +613,7 @@ private void addBackButton(ChestMenu menu, int slot, Player p, PlayerProfile pro
} else {
menu.addItem(slot, new CustomItem(ChestMenuUtils.getBackButton(p, "", ChatColor.GRAY + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide"))));
menu.addMenuClickHandler(slot, (pl, s, is, action) -> {
openMainMenu(profile, 1);
openMainMenu(profile, profile.getGuideHistory().getMainMenuPage());
return false;
});
}
Expand Down