Skip to content

Commit

Permalink
Show JEI config button when ingredient list is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed May 13, 2018
1 parent 817025d commit 737ba40
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 87 deletions.
11 changes: 8 additions & 3 deletions src/main/java/mezz/jei/config/Config.java
Expand Up @@ -37,6 +37,10 @@ public final class Config {
public static final String CATEGORY_ADVANCED = "advanced";
public static final String CATEGORY_SEARCH_COLORS = "searchColors";

public static final String defaultModNameFormatFriendly = "blue italic";
public static final int smallestNumColumns = 4;
public static final int largestNumColumns = 100;

@Nullable
private static LocalizedConfiguration config;
@Nullable
Expand All @@ -60,7 +64,8 @@ private Config() {
}

public static boolean isOverlayEnabled() {
return values.overlayEnabled;
return values.overlayEnabled ||
KeyBindings.toggleOverlay.getKeyCode() == 0; // if there is no key binding to enable it, don't allow the overlay to be disabled
}

public static void toggleOverlayEnabled() {
Expand Down Expand Up @@ -337,7 +342,7 @@ private static boolean syncConfig() {

values.giveMode = config.getEnum("giveMode", CATEGORY_ADVANCED, defaultValues.giveMode, GiveMode.values());

values.maxColumns = config.getInt("maxColumns", CATEGORY_ADVANCED, defaultValues.maxColumns, 3, 100);
values.maxColumns = config.getInt("maxColumns", CATEGORY_ADVANCED, defaultValues.maxColumns, smallestNumColumns, largestNumColumns);

updateModNameFormat(config);

Expand All @@ -363,7 +368,7 @@ private static void updateModNameFormat(LocalizedConfiguration config) {
validValues[i] = formatting.getFriendlyName().toLowerCase(Locale.ENGLISH);
i++;
}
Property property = config.getString("modNameFormat", CATEGORY_ADVANCED, defaultValues.modNameFormatFriendly, validValues);
Property property = config.getString("modNameFormat", CATEGORY_ADVANCED, defaultModNameFormatFriendly, validValues);
boolean showInGui = !isModNameFormatOverrideActive();
property.setShowInGui(showInGui);
String modNameFormatFriendly = property.getString();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mezz/jei/config/ConfigValues.java
Expand Up @@ -7,8 +7,7 @@ public class ConfigValues {
public boolean debugModeEnabled = false;
public boolean centerSearchBarEnabled = false;
public GiveMode giveMode = GiveMode.MOUSE_PICKUP;
public final String modNameFormatFriendly = "blue italic";
public String modNameFormat = Config.parseFriendlyModNameFormat(modNameFormatFriendly);
public String modNameFormat = Config.parseFriendlyModNameFormat(Config.defaultModNameFormatFriendly);
public int maxColumns = 100;

// search
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/config/Constants.java
Expand Up @@ -23,7 +23,7 @@ public final class Constants {
public static final ResourceLocation RECIPE_BACKGROUND = new ResourceLocation(RESOURCE_DOMAIN, TEXTURE_RECIPE_BACKGROUND_PATH);
public static final ResourceLocation RECIPE_BACKGROUND_TALL = new ResourceLocation(RESOURCE_DOMAIN, TEXTURE_RECIPE_BACKGROUND_TALL_PATH);

public static final int MAX_TOOLTIP_WIDTH = 125;
public static final int MAX_TOOLTIP_WIDTH = 150;

public static final String UNIVERSAL_RECIPE_TRANSFER_UID = "universal recipe transfer handler";

Expand Down
33 changes: 22 additions & 11 deletions src/main/java/mezz/jei/gui/overlay/ConfigButton.java
@@ -1,20 +1,22 @@
package mezz.jei.gui.overlay;

import java.awt.Rectangle;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import mezz.jei.Internal;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.config.Config;
import mezz.jei.config.Constants;
import mezz.jei.config.JEIModConfigGui;
import mezz.jei.config.KeyBindings;
import mezz.jei.gui.GuiHelper;
import mezz.jei.gui.TooltipRenderer;
import mezz.jei.util.Translator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.config.HoverChecker;
Expand Down Expand Up @@ -55,23 +57,32 @@ public boolean isMouseOver(int mouseX, int mouseY) {
return this.configButtonHoverChecker.checkHover(mouseX, mouseY);
}

public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) {
public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY, boolean hasRoom) {
if (isMouseOver(mouseX, mouseY)) {
String configString = Translator.translateToLocal("jei.tooltip.config");
List<String> tooltip = new ArrayList<>();
tooltip.add(Translator.translateToLocal("jei.tooltip.config"));
if (!Config.isOverlayEnabled()) {
tooltip.add(TextFormatting.GOLD + Translator.translateToLocal("jei.tooltip.ingredient.list.disabled"));
tooltip.add(TextFormatting.GOLD + Translator.translateToLocalFormatted("jei.tooltip.ingredient.list.disabled.how.to.fix", KeyBindings.toggleOverlay.getDisplayName()));
} else if (!hasRoom) {
tooltip.add(TextFormatting.GOLD + Translator.translateToLocal("jei.tooltip.not.enough.space"));
}
if (Config.isCheatItemsEnabled()) {
List<String> tooltip = Arrays.asList(
configString,
TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode")
);
TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY);
} else {
TooltipRenderer.drawHoveringText(minecraft, configString, mouseX, mouseY);
tooltip.add(TextFormatting.RED + Translator.translateToLocal("jei.tooltip.cheat.mode"));
KeyBinding toggleCheatMode = KeyBindings.toggleCheatMode;
if (toggleCheatMode.getKeyCode() != 0) {
tooltip.add(TextFormatting.RED + Translator.translateToLocalFormatted("jei.tooltip.cheat.mode.how.to.disable.hotkey", toggleCheatMode.getDisplayName()));
} else {
String ctrlKeyName = Minecraft.IS_RUNNING_ON_MAC ? "CMD" : "CTRL";
tooltip.add(TextFormatting.RED + Translator.translateToLocalFormatted("jei.tooltip.cheat.mode.how.to.disable.no.hotkey", ctrlKeyName));
}
}
TooltipRenderer.drawHoveringText(minecraft, tooltip, mouseX, mouseY, Constants.MAX_TOOLTIP_WIDTH);
}
}

public boolean handleMouseClick(Minecraft minecraft, int mouseX, int mouseY) {
if (configButton.mousePressed(minecraft, mouseX, mouseY)) {
if (Config.isOverlayEnabled() && configButton.mousePressed(minecraft, mouseX, mouseY)) {
configButton.playPressSound(minecraft.getSoundHandler());
if (Keyboard.getEventKeyState() && (Keyboard.getEventKey() == Keyboard.KEY_LCONTROL || Keyboard.getEventKey() == Keyboard.KEY_RCONTROL)) {
Config.toggleCheatItemsEnabled();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/gui/overlay/IngredientGrid.java
Expand Up @@ -37,8 +37,8 @@
*/
public abstract class IngredientGrid implements IShowsRecipeFocuses, IPaged {
private static final int INGREDIENT_PADDING = 1;
private static final int INGREDIENT_WIDTH = GuiItemStackGroup.getWidth(INGREDIENT_PADDING);
private static final int INGREDIENT_HEIGHT = GuiItemStackGroup.getHeight(INGREDIENT_PADDING);
public static final int INGREDIENT_WIDTH = GuiItemStackGroup.getWidth(INGREDIENT_PADDING);
public static final int INGREDIENT_HEIGHT = GuiItemStackGroup.getHeight(INGREDIENT_PADDING);

private Rectangle area = new Rectangle();
protected final IngredientListBatchRenderer guiIngredientSlots;
Expand Down
143 changes: 81 additions & 62 deletions src/main/java/mezz/jei/gui/overlay/IngredientListOverlay.java
Expand Up @@ -51,7 +51,9 @@ public class IngredientListOverlay implements IItemListOverlay, IIngredientListO
* @return true if this can be displayed next to the gui with the given guiProperties
*/
private static boolean hasRoom(IGuiProperties guiProperties) {
return guiProperties.getScreenWidth() - (guiProperties.getGuiLeft() + guiProperties.getGuiXSize()) >= 72;
Rectangle displayArea = getDisplayArea(guiProperties);
final int availableColumns = displayArea.width / IngredientGrid.INGREDIENT_WIDTH;
return availableColumns >= Config.smallestNumColumns;
}

private static boolean isSearchBarCentered(IGuiProperties guiProperties) {
Expand Down Expand Up @@ -118,6 +120,10 @@ public void highlightStacks(Collection<ItemStack> stacks) {
}

public boolean isEnabled() {
return this.guiProperties != null;
}

public boolean isListDisplayed() {
return Config.isOverlayEnabled() && this.guiProperties != null && hasRoom(this.guiProperties);
}

Expand All @@ -129,6 +135,14 @@ private static boolean areGuiPropertiesEqual(IGuiProperties guiProperties1, IGui
guiProperties1.getScreenHeight() == guiProperties2.getScreenHeight();
}

private static Rectangle getDisplayArea(IGuiProperties guiProperties) {
final int x = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + BORDER_PADDING;
final int y = BORDER_PADDING;
final int width = guiProperties.getScreenWidth() - x - (2 * BORDER_PADDING);
final int height = guiProperties.getScreenHeight() - y - (2 * BORDER_PADDING);
return new Rectangle(x, y, width, height);
}

public void updateScreen(@Nullable GuiScreen guiScreen) {
JeiRuntime runtime = Internal.getRuntime();
if (runtime == null) {
Expand All @@ -140,12 +154,7 @@ public void updateScreen(@Nullable GuiScreen guiScreen) {
setKeyboardFocus(false);
} else if (this.guiProperties == null || !areGuiPropertiesEqual(this.guiProperties, guiProperties)) {
this.guiProperties = guiProperties;

final int x = guiProperties.getGuiLeft() + guiProperties.getGuiXSize() + BORDER_PADDING;
final int y = BORDER_PADDING;
final int width = guiProperties.getScreenWidth() - x - (2 * BORDER_PADDING);
final int height = guiProperties.getScreenHeight() - y - (2 * BORDER_PADDING);
displayArea = new Rectangle(x, y, width, height);
this.displayArea = getDisplayArea(guiProperties);

final boolean searchBarCentered = isSearchBarCentered(guiProperties);
final int searchHeight = searchBarCentered ? 0 : SEARCH_HEIGHT + 4;
Expand Down Expand Up @@ -194,9 +203,11 @@ public void drawScreen(Minecraft minecraft, int mouseX, int mouseY, float partia

GlStateManager.disableLighting();

this.navigation.draw(minecraft, mouseX, mouseY, partialTicks);
this.searchField.drawTextBox();
this.contents.draw(minecraft, mouseX, mouseY);
if (isListDisplayed()) {
this.navigation.draw(minecraft, mouseX, mouseY, partialTicks);
this.searchField.drawTextBox();
this.contents.draw(minecraft, mouseX, mouseY);
}
this.configButton.draw(minecraft, mouseX, mouseY, partialTicks);
}

Expand All @@ -210,9 +221,14 @@ public boolean updateGuiExclusionAreas() {
}

public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) {
this.contents.drawTooltips(minecraft, mouseX, mouseY);
this.configButton.drawTooltips(minecraft, mouseX, mouseY);
this.ghostIngredientDragManager.drawTooltips(minecraft, mouseX, mouseY);
if (this.guiProperties != null) {
boolean hasRoom = hasRoom(this.guiProperties);
this.configButton.drawTooltips(minecraft, mouseX, mouseY, hasRoom);
this.ghostIngredientDragManager.drawTooltips(minecraft, mouseX, mouseY);
if (Config.isOverlayEnabled() && hasRoom) {
this.contents.drawTooltips(minecraft, mouseX, mouseY);
}
}
}

public void drawOnForeground(Minecraft minecraft, int mouseX, int mouseY) {
Expand Down Expand Up @@ -262,7 +278,7 @@ public boolean isMouseOver(int mouseX, int mouseY) {
@Override
@Nullable
public IClickedIngredient<?> getIngredientUnderMouse(int mouseX, int mouseY) {
if (this.isEnabled()) {
if (isListDisplayed()) {
IClickedIngredient<?> clicked = this.contents.getIngredientUnderMouse(mouseX, mouseY);
if (clicked != null) {
clicked.setOnClickHandler(() -> setKeyboardFocus(false));
Expand All @@ -274,7 +290,7 @@ public IClickedIngredient<?> getIngredientUnderMouse(int mouseX, int mouseY) {

@Override
public boolean canSetFocusWithMouse() {
return this.isEnabled() && this.contents.canSetFocusWithMouse();
return this.isListDisplayed() && this.contents.canSetFocusWithMouse();
}

@Override
Expand All @@ -283,52 +299,53 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {
return true;
} // if the ghost ingredient drag failed, fall through to let the click be handled by something else

if (!isMouseOver(mouseX, mouseY)) {
setKeyboardFocus(false);
return false;
}

if (this.contents.handleMouseClicked(mouseX, mouseY)) {
setKeyboardFocus(false);
if (this.configButton.handleMouseClick(Minecraft.getMinecraft(), mouseX, mouseY)) {
return true;
}

if (this.navigation.handleMouseClickedButtons(mouseX, mouseY)) {
setKeyboardFocus(false);
return true;
}
if (isListDisplayed()) {
if (!isMouseOver(mouseX, mouseY)) {
setKeyboardFocus(false);
return false;
}

boolean searchClicked = this.searchField.isMouseOver(mouseX, mouseY);
setKeyboardFocus(searchClicked);
if (searchClicked) {
final boolean updated = this.searchField.handleMouseClicked(mouseX, mouseY, mouseButton);
if (updated) {
updateLayout();
if (this.contents.handleMouseClicked(mouseX, mouseY)) {
setKeyboardFocus(false);
return true;
}
return true;
}

if (this.configButton.handleMouseClick(Minecraft.getMinecraft(), mouseX, mouseY)) {
return true;
}
if (this.navigation.handleMouseClickedButtons(mouseX, mouseY)) {
setKeyboardFocus(false);
return true;
}

Minecraft minecraft = Minecraft.getMinecraft();
GuiScreen currentScreen = minecraft.currentScreen;
if (currentScreen != null && !(currentScreen instanceof RecipesGui) &&
(mouseButton == 0 || mouseButton == 1 || minecraft.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100)))
{
IClickedIngredient<?> clicked = getIngredientUnderMouse(mouseX, mouseY);
if (clicked != null) {
if (Config.isCheatItemsEnabled()) {
ItemStack itemStack = clicked.getCheatItemStack();
if (!itemStack.isEmpty()) {
CommandUtil.giveStack(itemStack, mouseButton);
}
clicked.onClickHandled();
return true;
boolean searchClicked = this.searchField.isMouseOver(mouseX, mouseY);
setKeyboardFocus(searchClicked);
if (searchClicked) {
final boolean updated = this.searchField.handleMouseClicked(mouseX, mouseY, mouseButton);
if (updated) {
updateLayout();
}
if (this.ghostIngredientDragManager.handleClickGhostIngredient(currentScreen, clicked)) {
return true;
return true;
}

Minecraft minecraft = Minecraft.getMinecraft();
GuiScreen currentScreen = minecraft.currentScreen;
if (currentScreen != null && !(currentScreen instanceof RecipesGui) &&
(mouseButton == 0 || mouseButton == 1 || minecraft.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100))) {
IClickedIngredient<?> clicked = getIngredientUnderMouse(mouseX, mouseY);
if (clicked != null) {
if (Config.isCheatItemsEnabled()) {
ItemStack itemStack = clicked.getCheatItemStack();
if (!itemStack.isEmpty()) {
CommandUtil.giveStack(itemStack, mouseButton);
}
clicked.onClickHandled();
return true;
}
if (this.ghostIngredientDragManager.handleClickGhostIngredient(currentScreen, clicked)) {
return true;
}
}
}
}
Expand All @@ -337,15 +354,14 @@ public boolean handleMouseClicked(int mouseX, int mouseY, int mouseButton) {

@Override
public boolean handleMouseScrolled(int mouseX, int mouseY, int scrollDelta) {
if (!isMouseOver(mouseX, mouseY)) {
return false;
}
if (scrollDelta < 0) {
nextPage();
return true;
} else if (scrollDelta > 0) {
previousPage();
return true;
if (isListDisplayed() && isMouseOver(mouseX, mouseY)) {
if (scrollDelta < 0) {
nextPage();
return true;
} else if (scrollDelta > 0) {
previousPage();
return true;
}
}
return false;
}
Expand All @@ -360,6 +376,9 @@ public void setKeyboardFocus(boolean keyboardFocus) {
}

public boolean onKeyPressed(char typedChar, int keyCode) {
if (!isListDisplayed()) {
return false;
}
if (hasKeyboardFocus() &&
searchField.textboxKeyTyped(typedChar, keyCode)) {
boolean changed = Config.setFilterText(searchField.getText());
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/mezz/jei/input/InputHandler.java
Expand Up @@ -66,15 +66,15 @@ public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) {
}

private boolean handleMouseScroll(int dWheel, int mouseX, int mouseY) {
return ingredientListOverlay.isEnabled() && ingredientListOverlay.handleMouseScrolled(mouseX, mouseY, dWheel);
return ingredientListOverlay.handleMouseScrolled(mouseX, mouseY, dWheel);
}

private boolean handleMouseClick(GuiScreen guiScreen, int mouseButton, int mouseX, int mouseY) {
IClickedIngredient<?> clicked = getFocusUnderMouseForClick(mouseX, mouseY);
if (Config.isEditModeEnabled() && clicked != null && handleClickEdit(mouseButton, clicked)) {
return true;
}
if (ingredientListOverlay.isEnabled() && ingredientListOverlay.handleMouseClicked(mouseX, mouseY, mouseButton)) {
if (ingredientListOverlay.handleMouseClicked(mouseX, mouseY, mouseButton)) {
return true;
}

Expand Down Expand Up @@ -201,9 +201,7 @@ private boolean handleKeyDown(char typedChar, int eventKey) {
return true;
}
if (ingredientListOverlay.isEnabled()) {
if (ingredientListOverlay.onKeyPressed(typedChar, eventKey)) {
return true;
}
return ingredientListOverlay.onKeyPressed(typedChar, eventKey);
}
return false;
}
Expand Down

0 comments on commit 737ba40

Please sign in to comment.