diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-01-01 13:55:45 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-01-01 13:55:45 +0800 |
| commit | a75a3562b2e36ef6e6463758c3640ad03aa5bac3 (patch) | |
| tree | df687173b054a83afb9d1c5488c5cb5e09c7629e /src/main/java/me/shedaniel/gui/ConfigGui.java | |
| parent | 6b6176dff58866e461172606fafb842fa2ebfa6a (diff) | |
| download | RoughlyEnoughItems-a75a3562b2e36ef6e6463758c3640ad03aa5bac3.tar.gz RoughlyEnoughItems-a75a3562b2e36ef6e6463758c3640ad03aa5bac3.tar.bz2 RoughlyEnoughItems-a75a3562b2e36ef6e6463758c3640ad03aa5bac3.zip | |
1.2 Custom Keybinds
Diffstat (limited to 'src/main/java/me/shedaniel/gui/ConfigGui.java')
| -rw-r--r-- | src/main/java/me/shedaniel/gui/ConfigGui.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/gui/ConfigGui.java b/src/main/java/me/shedaniel/gui/ConfigGui.java new file mode 100644 index 000000000..31a1c3feb --- /dev/null +++ b/src/main/java/me/shedaniel/gui/ConfigGui.java @@ -0,0 +1,74 @@ +package me.shedaniel.gui; + +import me.shedaniel.ClientListener; +import me.shedaniel.Core; +import me.shedaniel.gui.widget.KeyBindButton; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.resource.language.I18n; + +import java.io.IOException; + +public class ConfigGui extends Gui { + + private Gui parent; + + public ConfigGui(Gui parent) { + this.parent = parent; + } + + @Override + protected void onInitialized() { + addButton(new KeyBindButton(997, parent.width / 2 - 20, 30, 80, 20, Core.config.recipeKeyBind, key -> { + Core.config.recipeKeyBind = key; + ClientListener.recipeKeybind.setKey(key); + try { + Core.saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + })); + addButton(new KeyBindButton(997, parent.width / 2 - 20, 60, 80, 20, Core.config.usageKeyBind, key -> { + Core.config.usageKeyBind = key; + ClientListener.useKeybind.setKey(key); + try { + Core.saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + })); + addButton(new KeyBindButton(997, parent.width / 2 - 20, 90, 80, 20, Core.config.hideKeyBind, key -> { + Core.config.hideKeyBind = key; + ClientListener.hideKeybind.setKey(key); + try { + Core.saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + })); + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + drawBackground(); + super.draw(mouseX, mouseY, partialTicks); + String text = I18n.translate("key.rei.recipe") + ": "; + drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 40 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 30 + 6, -1); + text = I18n.translate("key.rei.use") + ": "; + drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 40 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 60 + 6, -1); + text = I18n.translate("key.rei.hide") + ": "; + drawString(MinecraftClient.getInstance().fontRenderer, text, parent.width / 2 - 40 - MinecraftClient.getInstance().fontRenderer.getStringWidth(text), 90 + 6, -1); + } + + @Override + public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { + if (p_keyPressed_1_ == 256 && this.canClose()) { + this.close(); + if (parent != null) + MinecraftClient.getInstance().openGui(parent); + return true; + } else { + return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); + } + } +} |
