Skip to content

Commit

Permalink
Fixes for live-updating gui exclusion areas
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 3, 2018
1 parent 2d10205 commit a885035
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/main/java/mezz/jei/gui/GuiEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

public class GuiEventHandler {
private final IngredientListOverlay ingredientListOverlay;
private final GuiScreenHelper guiScreenHelper;
private final LeftAreaDispatcher leftAreaDispatcher;
private final RecipeRegistry recipeRegistry;
private boolean drawnOnBackground = false;

public GuiEventHandler(LeftAreaDispatcher leftAreaDispatcher, IngredientListOverlay ingredientListOverlay, RecipeRegistry recipeRegistry) {
public GuiEventHandler(GuiScreenHelper guiScreenHelper, LeftAreaDispatcher leftAreaDispatcher, IngredientListOverlay ingredientListOverlay, RecipeRegistry recipeRegistry) {
this.guiScreenHelper = guiScreenHelper;
this.leftAreaDispatcher = leftAreaDispatcher;
this.ingredientListOverlay = ingredientListOverlay;
this.recipeRegistry = recipeRegistry;
Expand All @@ -31,28 +33,29 @@ public GuiEventHandler(LeftAreaDispatcher leftAreaDispatcher, IngredientListOver
public void onOverlayToggle(OverlayToggleEvent event) {
GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
ingredientListOverlay.updateScreen(currentScreen, true);
leftAreaDispatcher.updateScreen(currentScreen);
leftAreaDispatcher.updateScreen(currentScreen, false);
}

@SubscribeEvent
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
GuiScreen gui = event.getGui();
ingredientListOverlay.updateScreen(gui, false);
leftAreaDispatcher.updateScreen(gui);
leftAreaDispatcher.updateScreen(gui, false);
}

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
GuiScreen gui = event.getGui();
ingredientListOverlay.updateScreen(gui, false);
leftAreaDispatcher.updateScreen(gui);
leftAreaDispatcher.updateScreen(gui, false);
}

@SubscribeEvent
public void onDrawBackgroundEventPost(GuiScreenEvent.BackgroundDrawnEvent event) {
GuiScreen gui = event.getGui();
ingredientListOverlay.updateScreen(gui, false);
leftAreaDispatcher.updateScreen(gui);
boolean exclusionAreasChanged = guiScreenHelper.updateGuiExclusionAreas();
ingredientListOverlay.updateScreen(gui, exclusionAreasChanged);
leftAreaDispatcher.updateScreen(gui, exclusionAreasChanged);

drawnOnBackground = true;
ingredientListOverlay.drawScreen(gui.mc, event.getMouseX(), event.getMouseY(), gui.mc.getRenderPartialTicks());
Expand All @@ -74,7 +77,7 @@ public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event) {
GuiScreen gui = event.getGui();

ingredientListOverlay.updateScreen(gui, false);
leftAreaDispatcher.updateScreen(gui);
leftAreaDispatcher.updateScreen(gui, false);

if (!drawnOnBackground) {
ingredientListOverlay.drawScreen(gui.mc, event.getMouseX(), event.getMouseY(), gui.mc.getRenderPartialTicks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public void updateScreen(@Nullable GuiScreen guiScreen, boolean forceUpdate) {
this.ghostIngredientDragManager.stopDrag();
}
} else {
boolean exclusionAreasChanged = guiScreenHelper.updateGuiExclusionAreas();
if (exclusionAreasChanged || this.guiProperties == null || !GuiProperties.areEqual(this.guiProperties, guiProperties) || forceUpdate) {
if (forceUpdate || this.guiProperties == null || !GuiProperties.areEqual(this.guiProperties, guiProperties)) {
this.guiProperties = guiProperties;
this.displayArea = getDisplayArea(guiProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ public void drawTooltips(Minecraft minecraft, int mouseX, int mouseY) {
}
}

public void updateScreen(@Nullable GuiScreen guiScreen) {
public void updateScreen(@Nullable GuiScreen guiScreen, boolean forceUpdate) {
canShow = false;
if (hasContent()) {
IGuiProperties currentGuiProperties = guiScreenHelper.getGuiProperties(guiScreen);
if (currentGuiProperties == null) {
guiProperties = null;
} else {
ILeftAreaContent content = contents.get(current);
boolean exclusionAreasChanged = guiScreenHelper.updateGuiExclusionAreas();
if (exclusionAreasChanged || !GuiProperties.areEqual(guiProperties, currentGuiProperties)) {
if (forceUpdate || !GuiProperties.areEqual(guiProperties, currentGuiProperties)) {
Set<Rectangle> guiExclusionAreas = guiScreenHelper.getGuiExclusionAreas();
guiProperties = currentGuiProperties;
makeDisplayArea(guiProperties);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/startup/JeiStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void start(List<IModPlugin> plugins) {
LeftAreaDispatcher leftAreaDispatcher = new LeftAreaDispatcher(guiScreenHelper);
leftAreaDispatcher.addContent(bookmarkOverlay);

GuiEventHandler guiEventHandler = new GuiEventHandler(leftAreaDispatcher, ingredientListOverlay, recipeRegistry);
GuiEventHandler guiEventHandler = new GuiEventHandler(guiScreenHelper, leftAreaDispatcher, ingredientListOverlay, recipeRegistry);
Internal.setGuiEventHandler(guiEventHandler);
InputHandler inputHandler = new InputHandler(jeiRuntime, ingredientRegistry, ingredientListOverlay, guiScreenHelper, leftAreaDispatcher, bookmarkList);
Internal.setInputHandler(inputHandler);
Expand Down

0 comments on commit a885035

Please sign in to comment.