Skip to content

Commit

Permalink
Fix keybinds in component GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
boq committed Sep 16, 2018
1 parent a8c86f6 commit 5ce0a1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/openmods/gui/BaseGuiContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String machineName = TranslationUtils.translateToLocal(name);
int x = this.xSize / 2 - (fontRenderer.getStringWidth(machineName) / 2);
fontRenderer.drawString(machineName, x, 6, 4210752);
fontRenderer.drawString(machineName, x, 6, 0x404040);
String translatedName = TranslationUtils.translateToLocal("container.inventory");
fontRenderer.drawString(translatedName, 8, this.ySize - 96 + 2, 4210752);
fontRenderer.drawString(translatedName, 8, this.ySize - 96 + 2, 0x404040);
}

public void sendButtonClick(int buttonId) {
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/openmods/gui/ComponentGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import openmods.gui.component.BaseComposite;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

public abstract class ComponentGui extends GuiContainer {
Expand Down Expand Up @@ -88,6 +89,13 @@ public void bindTexture(ResourceLocation texture) {
public void initGui() {
super.initGui();
root.init(createParent());
Keyboard.enableRepeatEvents(true);
}

@Override
public void onGuiClosed() {
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
}

protected abstract BaseComposite createRoot();
Expand Down Expand Up @@ -120,9 +128,13 @@ protected void mouseClickMove(int x, int y, int button, long time) {
}

@Override
protected void keyTyped(char par1, int par2) throws IOException {
super.keyTyped(par1, par2);
root.keyTyped(par1, par2);
protected void keyTyped(char typedChar, int keyCode) {
// no super call!
if (keyCode == Keyboard.KEY_ESCAPE) {
this.mc.player.closeScreen();
} else {
root.keyTyped(typedChar, keyCode);
}
}

public void preRender(float mouseX, float mouseY) {}
Expand Down

0 comments on commit 5ce0a1c

Please sign in to comment.