mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
Made GuiNpcButtons with multiple displays i.e ("Hair","Eyes","Fur")
right clickable to select in reverse
This commit is contained in:
1 parent
ddee62f2ce
commit
93e6a92b59
5 files changed
+91
-3
No files matched your search
@@ -61,6 +61,8 @@ public class GuiButtonBiDirectional extends GuiNpcButton {
|
||||
boolean bo = super.mousePressed(minecraft, mouseX, mouseY);
|
||||
if (bo && display != null && display.length != 0) {
|
||||
boolean hoverL = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + 11 && mouseY < this.yPosition + this.height;
|
||||
if (rightClicked.get())
|
||||
hoverL = true;
|
||||
|
||||
boolean hoverR = !hoverL && mouseX >= this.xPosition + 11 && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import noppes.npcs.client.ClientEventHandler;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.TextBlockClient;
|
||||
@@ -24,6 +26,7 @@ import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class GuiNPCInterface extends GuiScreen {
|
||||
public EntityClientPlayerMP player;
|
||||
@@ -165,10 +168,40 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
}
|
||||
}
|
||||
mouseEvent(i, j, k);
|
||||
super.mouseClicked(i, j, k);
|
||||
vanillaMouseClicked(i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
protected void vanillaMouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 || mouseButton == 1) {
|
||||
for (int l = 0; l < this.buttonList.size(); ++l) {
|
||||
GuiButton guibutton = (GuiButton) this.buttonList.get(l);
|
||||
|
||||
AtomicBoolean rightClicked = null;
|
||||
if (mouseButton == 1) {
|
||||
if (guibutton instanceof GuiNpcButton && ((GuiNpcButton) guibutton).rightClickable) {
|
||||
rightClicked = ((GuiNpcButton) guibutton).rightClicked;
|
||||
rightClicked.set(true);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guibutton.mousePressed(this.mc, mouseX, mouseY)) {
|
||||
GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
break;
|
||||
this.selectedButton = event.button;
|
||||
event.button.func_146113_a(this.mc.getSoundHandler());
|
||||
this.actionPerformed(event.button);
|
||||
if (this.equals(this.mc.currentScreen))
|
||||
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList));
|
||||
}
|
||||
|
||||
if (rightClicked != null)
|
||||
rightClicked.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (subgui != null) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.lwjgl.opengl.GL12;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class GuiNpcButton extends GuiButton {
|
||||
|
||||
@@ -31,6 +32,8 @@ public class GuiNpcButton extends GuiButton {
|
||||
protected int iconPosX = 0;
|
||||
protected int iconPosY = 0;
|
||||
|
||||
public boolean rightClickable;
|
||||
|
||||
public GuiNpcButton(int i, int j, int k, String s) {
|
||||
super(i, j, k, StatCollector.translateToLocal(s));
|
||||
id = i;
|
||||
@@ -40,6 +43,9 @@ public class GuiNpcButton extends GuiButton {
|
||||
this(i, j, k, display[val]);
|
||||
this.display = display;
|
||||
this.displayValue = val;
|
||||
|
||||
if (display.length > 1)
|
||||
rightClickable = true;
|
||||
}
|
||||
|
||||
public GuiNpcButton(int i, int j, int k, int l, int m, String string) {
|
||||
@@ -51,6 +57,9 @@ public class GuiNpcButton extends GuiButton {
|
||||
this(i, j, k, l, m, display.length == 0 ? "" : display[val % display.length]);
|
||||
this.display = display;
|
||||
this.displayValue = display.length == 0 ? 0 : val % display.length;
|
||||
|
||||
if (display.length > 1)
|
||||
rightClickable = true;
|
||||
}
|
||||
|
||||
public GuiNpcButton(int i, int j, int k, int l, int m, Enum<?>[] displayEnums, int val) {
|
||||
@@ -61,6 +70,9 @@ public class GuiNpcButton extends GuiButton {
|
||||
}
|
||||
this.display = strings.toArray(new String[0]);
|
||||
this.displayValue = display.length == 0 ? 0 : val % display.length;
|
||||
|
||||
if (display.length > 1)
|
||||
rightClickable = true;
|
||||
}
|
||||
|
||||
public void setDisplayText(String text) {
|
||||
@@ -113,11 +125,17 @@ public class GuiNpcButton extends GuiButton {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AtomicBoolean rightClicked = new AtomicBoolean();
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft minecraft, int i, int j) {
|
||||
boolean bo = super.mousePressed(minecraft, i, j);
|
||||
if (bo && display != null && display.length != 0) {
|
||||
displayValue = (displayValue + 1) % display.length;
|
||||
if (rightClicked.get()) {
|
||||
if (displayValue <= 0)
|
||||
displayValue = display.length;
|
||||
displayValue--;
|
||||
} else
|
||||
displayValue = (displayValue + 1) % display.length;
|
||||
this.setDisplayText(display[displayValue]);
|
||||
}
|
||||
return bo;
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -12,6 +14,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, ICustomScrollListener, GuiYesNoCallback {
|
||||
public static final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/misc.png");
|
||||
@@ -107,9 +110,39 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
||||
}
|
||||
}
|
||||
mouseEvent(i, j, k);
|
||||
super.mouseClicked(i, j, k);
|
||||
vanillaMouseClicked(i, j, k);
|
||||
}
|
||||
|
||||
protected void vanillaMouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 || mouseButton == 1) {
|
||||
for (int l = 0; l < this.buttonList.size(); ++l) {
|
||||
GuiButton guibutton = (GuiButton) this.buttonList.get(l);
|
||||
|
||||
AtomicBoolean rightClicked = null;
|
||||
if (mouseButton == 1) {
|
||||
if (guibutton instanceof GuiNpcButton && ((GuiNpcButton) guibutton).rightClickable) {
|
||||
rightClicked = ((GuiNpcButton) guibutton).rightClicked;
|
||||
rightClicked.set(true);
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guibutton.mousePressed(this.mc, mouseX, mouseY)) {
|
||||
GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
break;
|
||||
this.selectedButton = event.button;
|
||||
event.button.func_146113_a(this.mc.getSoundHandler());
|
||||
this.actionPerformed(event.button);
|
||||
if (this.equals(this.mc.currentScreen))
|
||||
MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList));
|
||||
}
|
||||
|
||||
if (rightClicked != null)
|
||||
rightClicked.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void mouseEvent(int i, int j, int k) {
|
||||
}
|
||||
|
||||
|
||||
@@ -22,3 +22,5 @@ public net.minecraft.entity.EntityLivingBase field_70703_bu # isJumping
|
||||
public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker
|
||||
# MusicTicker
|
||||
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
||||
#GuiScreen
|
||||
public net.minecraft.client.gui.GuiScreen field_146290_a # selectedButton
|
||||
Reference in new issue
Block a user