-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move pattern grid rendering per type to different classes
- Loading branch information
1 parent
4aee1da
commit 949c334
Showing
14 changed files
with
1,081 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
.../java/com/refinedmods/refinedstorage/common/autocrafting/CraftingPatternGridRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.refinedmods.refinedstorage.common.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.common.support.widget.CustomCheckboxWidget; | ||
|
||
import java.util.function.Consumer; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.client.gui.components.Tooltip; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import static com.refinedmods.refinedstorage.common.autocrafting.PatternGridScreen.INSET_PADDING; | ||
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; | ||
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; | ||
|
||
class CraftingPatternGridRenderer implements PatternGridRenderer { | ||
private static final ResourceLocation CRAFTING = createIdentifier("pattern_grid/crafting"); | ||
private static final MutableComponent FUZZY_MODE = createTranslation("gui", "pattern_grid.fuzzy_mode"); | ||
private static final MutableComponent FUZZY_MODE_ON_HELP = | ||
createTranslation("gui", "pattern_grid.fuzzy_mode.on.help"); | ||
private static final MutableComponent FUZZY_MODE_OFF_HELP = | ||
createTranslation("gui", "pattern_grid.fuzzy_mode.off.help"); | ||
|
||
@Nullable | ||
private CustomCheckboxWidget fuzzyModeCheckbox; | ||
|
||
private final PatternGridContainerMenu menu; | ||
private final int leftPos; | ||
private final int x; | ||
private final int y; | ||
|
||
CraftingPatternGridRenderer(final PatternGridContainerMenu menu, final int leftPos, final int x, final int y) { | ||
this.menu = menu; | ||
this.leftPos = leftPos; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public void addWidgets(final Consumer<AbstractWidget> widgets, final Consumer<AbstractWidget> renderables) { | ||
this.fuzzyModeCheckbox = createFuzzyModeCheckbox(); | ||
renderables.accept(fuzzyModeCheckbox); | ||
} | ||
|
||
private CustomCheckboxWidget createFuzzyModeCheckbox() { | ||
final CustomCheckboxWidget checkbox = new CustomCheckboxWidget( | ||
x + INSET_PADDING, | ||
y + INSET_PADDING + 54 + INSET_PADDING - 2, | ||
FUZZY_MODE, | ||
Minecraft.getInstance().font, | ||
menu.isFuzzyMode(), | ||
CustomCheckboxWidget.Size.SMALL | ||
); | ||
checkbox.setOnPressed((c, selected) -> menu.setFuzzyMode(selected)); | ||
checkbox.setTooltip(getFuzzyModeTooltip(menu.isFuzzyMode())); | ||
checkbox.visible = isFuzzyModeCheckboxVisible(); | ||
return checkbox; | ||
} | ||
|
||
private static Tooltip getFuzzyModeTooltip(final boolean fuzzyMode) { | ||
return fuzzyMode ? Tooltip.create(FUZZY_MODE_ON_HELP) : Tooltip.create(FUZZY_MODE_OFF_HELP); | ||
} | ||
|
||
@Override | ||
public int getClearButtonX() { | ||
return leftPos + 68; | ||
} | ||
|
||
@Override | ||
public int getClearButtonY() { | ||
return y + INSET_PADDING; | ||
} | ||
|
||
@Override | ||
public void patternTypeChanged(final PatternType newPatternType) { | ||
if (fuzzyModeCheckbox != null) { | ||
fuzzyModeCheckbox.visible = isFuzzyModeCheckboxVisible(); | ||
} | ||
} | ||
|
||
private boolean isFuzzyModeCheckboxVisible() { | ||
return menu.getPatternType() == PatternType.CRAFTING; | ||
} | ||
|
||
@Override | ||
public void fuzzyModeChanged(final boolean newFuzzyMode) { | ||
if (fuzzyModeCheckbox == null) { | ||
return; | ||
} | ||
fuzzyModeCheckbox.setSelected(newFuzzyMode); | ||
fuzzyModeCheckbox.setTooltip(getFuzzyModeTooltip(newFuzzyMode)); | ||
} | ||
|
||
@Override | ||
public void renderBackground(final GuiGraphics graphics, | ||
final float partialTicks, | ||
final int mouseX, | ||
final int mouseY) { | ||
graphics.blitSprite(CRAFTING, x + INSET_PADDING, y + INSET_PADDING, 130, 54); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...src/main/java/com/refinedmods/refinedstorage/common/autocrafting/PatternGridRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.refinedmods.refinedstorage.common.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.common.support.containermenu.ResourceSlot; | ||
|
||
import java.util.function.Consumer; | ||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.world.inventory.Slot; | ||
|
||
interface PatternGridRenderer { | ||
default void addWidgets(Consumer<AbstractWidget> widgets, | ||
Consumer<AbstractWidget> renderables) { | ||
// no op | ||
} | ||
|
||
default void tick() { | ||
// no op | ||
} | ||
|
||
default void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { | ||
// no op | ||
} | ||
|
||
int getClearButtonX(); | ||
|
||
int getClearButtonY(); | ||
|
||
void renderBackground(GuiGraphics graphics, | ||
float partialTicks, | ||
int mouseX, | ||
int mouseY); | ||
|
||
default void renderTooltip(Font font, | ||
@Nullable Slot hoveredSlot, | ||
GuiGraphics graphics, | ||
int mouseX, | ||
int mouseY) { | ||
// no op | ||
} | ||
|
||
default void renderLabels(GuiGraphics graphics, Font font, int mouseX, int mouseY) { | ||
// no op | ||
} | ||
|
||
default boolean mouseClicked(double mouseX, double mouseY, int clickedButton) { | ||
return false; | ||
} | ||
|
||
default void mouseMoved(double mouseX, double mouseY) { | ||
// no op | ||
} | ||
|
||
default boolean mouseReleased(double mouseX, double mouseY, int button) { | ||
return false; | ||
} | ||
|
||
default boolean mouseScrolled(double mouseX, double mouseY, double mouseZ, double delta) { | ||
return false; | ||
} | ||
|
||
default void patternTypeChanged(PatternType newPatternType) { | ||
// no op | ||
} | ||
|
||
default void fuzzyModeChanged(boolean newFuzzyMode) { | ||
// no op | ||
} | ||
|
||
default boolean canInteractWithResourceSlot(ResourceSlot resourceSlot, | ||
double mouseX, | ||
double mouseY) { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.