mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 03:49:31 +00:00
Merge pull request #2295 from MatthiasMann/button_right_clicking
better implementation for right clicking on buttons
This commit is contained in:
commit
f67f83febe
4 files changed
+54
-46
No files matched your search
@@ -1,15 +1,10 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.gui.IGuiScreen;
|
||||
@@ -20,8 +15,6 @@ public class ColorButton extends IconButtonEIO {
|
||||
private int colorIndex = 0;
|
||||
|
||||
private String tooltipPrefix = "";
|
||||
|
||||
private boolean rightMouseDown = false;
|
||||
|
||||
public ColorButton(IGuiScreen gui, int id, int x, int y) {
|
||||
super(gui, id, x, y, null);
|
||||
@@ -36,6 +29,15 @@ public class ColorButton extends IconButtonEIO {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if(result) {
|
||||
prevColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTooltipPrefix() {
|
||||
return tooltipPrefix;
|
||||
}
|
||||
@@ -82,19 +84,6 @@ public class ColorButton extends IconButtonEIO {
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if(visible) {
|
||||
|
||||
Rectangle r = new Rectangle(xPosition, yPosition, width, height);
|
||||
if(r.contains(mouseX, mouseY)) {
|
||||
if(rightMouseDown && Mouse.getEventButton() == 1 && !Mouse.getEventButtonState()) {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
prevColor();
|
||||
gui.doActionPerformed(this);
|
||||
}
|
||||
rightMouseDown = Mouse.getEventButton() == 1 && Mouse.getEventButtonState();
|
||||
} else {
|
||||
rightMouseDown = false;
|
||||
}
|
||||
|
||||
Tessellator tes = Tessellator.instance;
|
||||
tes.startDrawingQuads();
|
||||
|
||||
|
||||
@@ -103,6 +103,23 @@ public class IconButtonEIO extends GuiButton {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to handle mouse clicks with other buttons than the left
|
||||
* @param mc The MC instance
|
||||
* @param x X coordinate of mouse click
|
||||
* @param y Y coordinate of mouse click
|
||||
* @param button the mouse button - only called for button >= 1
|
||||
* @return true if the mouse click is handled
|
||||
*/
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkMousePress(Minecraft mc, int x, int y) {
|
||||
// call super here so that we only get the area check
|
||||
return super.mousePressed(mc, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.PacketRedstoneMode;
|
||||
@@ -20,8 +16,6 @@ public class RedstoneModeButton extends IconButtonEIO {
|
||||
|
||||
private IRedstoneModeControlable model;
|
||||
private RedstoneControlMode curMode;
|
||||
|
||||
private boolean rightMouseDown = false;
|
||||
|
||||
private BlockCoord bc;
|
||||
|
||||
@@ -49,6 +43,15 @@ public class RedstoneModeButton extends IconButtonEIO {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressedButton(Minecraft mc, int x, int y, int button) {
|
||||
boolean result = button == 1 && super.checkMousePress(mc, x, y);
|
||||
if(result) {
|
||||
prevMode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getTooltipKey() {
|
||||
return tooltipKey;
|
||||
}
|
||||
@@ -84,21 +87,4 @@ public class RedstoneModeButton extends IconButtonEIO {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketRedstoneMode(model, bc.x, bc.y, bc.z));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
|
||||
Rectangle r = new Rectangle(xPosition, yPosition, width, height);
|
||||
if(r.contains(mouseX, mouseY)) {
|
||||
if(rightMouseDown && Mouse.getEventButton() == 1 && !Mouse.getEventButtonState()) {
|
||||
prevMode();
|
||||
gui.doActionPerformed(this);
|
||||
}
|
||||
rightMouseDown = Mouse.getEventButton() == 1 && Mouse.getEventButtonState();
|
||||
} else {
|
||||
rightMouseDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import crazypants.enderio.gui.IGuiOverlay;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.TextFieldEIO;
|
||||
import crazypants.gui.ToolTipManager.ToolTipRenderer;
|
||||
import crazypants.render.RenderUtil;
|
||||
@@ -151,9 +152,9 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int p_73864_3_) {
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
for (GuiTextField f : textFields) {
|
||||
f.mouseClicked(x, y, p_73864_3_);
|
||||
f.mouseClicked(x, y, button);
|
||||
}
|
||||
if(!ghostSlots.isEmpty()) {
|
||||
GhostSlot slot = getGhostSlot(x, y);
|
||||
@@ -163,7 +164,22 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(x, y, p_73864_3_);
|
||||
if(button >= 1) {
|
||||
for(Object obj : buttonList) {
|
||||
if(obj instanceof IconButtonEIO) {
|
||||
IconButtonEIO btn = (IconButtonEIO) obj;
|
||||
if(btn.mousePressedButton(mc, x, y, button)) {
|
||||
btn.func_146113_a(this.mc.getSoundHandler());
|
||||
actionPerformedButton(btn, button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.mouseClicked(x, y, button);
|
||||
}
|
||||
|
||||
protected void actionPerformedButton(IconButtonEIO btn, int mouseButton) {
|
||||
actionPerformed(btn);
|
||||
}
|
||||
|
||||
public void addOverlay(IGuiOverlay overlay) {
|
||||
|
||||
Reference in new issue
Block a user