diff options
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java new file mode 100644 index 000000000..d0a094b49 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/ConfigWidget.java @@ -0,0 +1,108 @@ +package me.shedaniel.rei.gui.widget; + +import com.google.common.collect.Lists; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiEventListener; +import net.minecraft.client.render.GuiLighting; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.Window; + +import java.io.IOException; +import java.util.List; + +public class ConfigWidget extends Gui { + + private List<IWidget> widgets; + private Gui parent; + + public ConfigWidget(Gui parent) { + this.parent = parent; + this.widgets = Lists.newArrayList(); + } + + @Override + public boolean keyPressed(int int_1, int int_2, int int_3) { + if (int_1 == 256 && this.doesEscapeKeyClose()) { + MinecraftClient.getInstance().openGui(parent); + return true; + } else { + return super.keyPressed(int_1, int_2, int_3); + } + } + + @Override + protected void onInitialized() { + super.onInitialized(); + widgets.clear(); + Window window = MinecraftClient.getInstance().window; + widgets.add(new ButtonWidget(window.getScaledWidth() / 2 - 20, 30, 40, 20, "") { + @Override + public void onPressed(int button, double mouseX, double mouseY) { + if (button == 0) + RoughlyEnoughItemsCore.getConfigHelper().setSideSearchField(!RoughlyEnoughItemsCore.getConfigHelper().sideSearchField()); + try { + RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + text = getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().sideSearchField()); + String t = I18n.translate("text.rei.centre_searchbox"); + int width = fontRenderer.getStringWidth(t); + fontRenderer.drawWithShadow(t, this.x - width - 10, this.y + (this.height - 8) / 2, -1); + super.draw(mouseX, mouseY, partialTicks); + } + }); + widgets.add(new ButtonWidget(window.getScaledWidth() / 2 - 20, 60, 40, 20, "") { + @Override + public void onPressed(int button, double mouseX, double mouseY) { + if (button == 0) + RoughlyEnoughItemsCore.getConfigHelper().setShowCraftableOnlyButton(!RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton()); + try { + RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + text = getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().showCraftableOnlyButton()); + String t = I18n.translate("text.rei.enable_craftable_only"); + int width = fontRenderer.getStringWidth(t); + fontRenderer.drawWithShadow(t, this.x - width - 10, this.y + (this.height - 8) / 2, -1); + super.draw(mouseX, mouseY, partialTicks); + } + }); + } + + private String getTrueFalseText(boolean showCraftableOnlyButton) { + return String.format("%s%b", showCraftableOnlyButton ? "§a" : "§c", showCraftableOnlyButton); + } + + @Override + public void draw(int int_1, int int_2, float float_1) { + drawBackground(0); + super.draw(int_1, int_2, float_1); + widgets.forEach(widget -> { + GuiLighting.disable(); + widget.draw(int_1, int_2, float_1); + }); + } + + @Override + public boolean isPauseScreen() { + return false; + } + + @Override + public List<? extends GuiEventListener> getEntries() { + return widgets; + } + +} |
