diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 7c3f87bba..28a3d6d93 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -16,6 +16,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; + public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo, ICustomScrollListener { //////////////////////////////////////////////////////////////////////////////// @@ -121,11 +123,17 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo // Create top buttons. private void setupTopButtons() { - GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); - GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); - GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); - GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); - GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); + + GuiMenuTopButton playerTab = new GuiMenuTopButton(-10, guiLeft + 4, guiTop - 10, playerName); + playerTab.active = false; + playerTab.enabled = false; + playerTab.packedFGColour = CustomNpcResourceListener.DefaultTextColor; + + GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, playerTab.xPosition + playerTab.getButtonWidth(), guiTop - 10, "quest.quests"); + GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, "dialog.dialogs"); + GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, "global.transport"); + GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, "global.banks"); + GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, "menu.factions"); // Close button. GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); @@ -135,6 +143,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo btnBank.active = (currentTab == 13); btnFaction.active = (currentTab == 14); + addTopButton(playerTab); addTopButton(btnQuest); addTopButton(btnDialog); addTopButton(btnTransport); @@ -177,10 +186,10 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo super.initGui(); setupTopButtons(); - // Mode toggle button (50px wide) if (currentTab == 10 || currentTab == 11 || currentTab == 12) { - String modeText = viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"); - addButton(new GuiNpcButton(20, guiLeft + xSize - 60, guiTop + 10, 50, 20, modeText)); + addButton(new GuiToggleButton(20, guiLeft + xSize - 102, guiTop + 10, viewMode == 0)); + ((GuiToggleButton) getButton(20)).setTextureOff(specialIcons).setTextureOffPos( 16, 0); + ((GuiToggleButton) getButton(20)).setIconTexture(specialIcons).setIconPos( 16, 16, 16, 0 ); } guiTop += 7; @@ -201,7 +210,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo break; } // Delete button. - addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + ySize - 30, 50, 20, StatCollector.translateToLocal("button.delete"))); + addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + 10 - 7, 50, 20, "gui.remove")); } // ----- Quest Tab Initialization ----- diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java index e3c5cc9d8..4e423ae3b 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -44,9 +44,9 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("All Players"), guiLeft + 10, guiTop + 6)); - addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10, 98, 20, StatCollector.translateToLocal("button.delete"))); - addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32, 98, 20, StatCollector.translateToLocal("button.view"))); - addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54, 98, 20, StatCollector.translateToLocal("button.regenPlayerMap"))); + addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10, 98, 20, "gui.remove")); + addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32, 98, 20, "gui.view")); + addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54, 98, 20, "gui.playerMap")); addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 193, 303, 20, search)); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java index 48ad1b389..33604c02c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java @@ -40,6 +40,9 @@ public class GuiMenuTopButton extends GuiNpcButton public int getHoverState(boolean flag) { byte byte0 = 1; + if(!enabled) + return byte0; + if (active) { byte0 = 0; @@ -57,7 +60,7 @@ public class GuiMenuTopButton extends GuiNpcButton if (!getVisible()) { return; - } + } GL11.glPushMatrix(); minecraft.renderEngine.bindTexture(resource); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -74,7 +77,7 @@ public class GuiMenuTopButton extends GuiNpcButton { drawCenteredString(fontrenderer, displayString, xPosition + getWidth() / 2, yPosition + (height - 8) / 2, 0xffffa0); } - else if (hover) + else if (hover && enabled) { drawCenteredString(fontrenderer, displayString, xPosition + getWidth() / 2, yPosition + (height - 8) / 2, 0xffffa0); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java new file mode 100644 index 000000000..14b5970b9 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java @@ -0,0 +1,173 @@ +package noppes.npcs.client.gui.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +public class GuiToggleButton extends GuiNpcButton { + + // Fixed dimensions: 40x20 (even if other values are passed) + private static final int FIXED_WIDTH = 40; + private static final int FIXED_HEIGHT = 20; + + private boolean toggled; + // Animation progress: 0.0 = OFF (knob left), 1.0 = ON (knob right) + private float animProgress; + + // Optional off icon (if not set, the super class icon is used) + private ResourceLocation textureOff = null; + private int textureOffPosX = 0; + private int textureOffPosY = 0; + // Off icon always 16x16 + private static final int ICON_SIZE = 16; + + /** + * Basic constructor. Uses the super class’s icon as the ON texture. + * Note: The button is fixed at 40×20. + */ + public GuiToggleButton(int id, int x, int y, boolean initialState) { + super(id, x, y, FIXED_WIDTH, FIXED_HEIGHT, ""); + this.toggled = initialState; + this.animProgress = initialState ? 1.0f : 0.0f; + } + + /** + * Constructor with both an ON and OFF icon. + * The ON icon is taken from the super class’s icon. + */ + public GuiToggleButton(int id, int x, int y, boolean initialState, + ResourceLocation textureOn, ResourceLocation textureOff) { + super(id, x, y, FIXED_WIDTH, FIXED_HEIGHT, ""); + this.setIconTexture(textureOn); + this.toggled = initialState; + this.animProgress = initialState ? 1.0f : 0.0f; + this.textureOff = textureOff; + } + + // Off icon setters + public GuiToggleButton setTextureOff(ResourceLocation texture) { + this.textureOff = texture; + return this; + } + + public GuiToggleButton setTextureOffPos(int posX, int posY) { + this.textureOffPosX = posX; + this.textureOffPosY = posY; + return this; + } + + @Override + public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { + boolean pressed = super.mousePressed(mc, mouseX, mouseY); + if (pressed) { + toggled = !toggled; + } + return pressed; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (!this.visible) + return; + + FontRenderer fontrenderer = mc.fontRenderer; + // Bind vanilla button texture. + mc.getTextureManager().bindTexture(buttonTextures); + GL11.glColor4f(1F, 1F, 1F, 1F); + + // Determine hover state (vanilla style) + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && + mouseX < this.xPosition + FIXED_WIDTH && mouseY < this.yPosition + FIXED_HEIGHT; + int k = this.getHoverState(this.field_146123_n); + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + // Update animation progress smoothly toward the target state. + float target = toggled ? 1.0f : 0.0f; + animProgress += (target - animProgress) * 0.2f; + if (Math.abs(target - animProgress) < 0.01f) + animProgress = target; + + // Draw the two halves using the vanilla button drawing code. + // Left half: + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, FIXED_WIDTH / 2, FIXED_HEIGHT); + // Right half: + this.drawTexturedModalRect(this.xPosition + FIXED_WIDTH / 2, this.yPosition, 200 - FIXED_WIDTH / 2, 46 + k * 20, FIXED_WIDTH / 2, FIXED_HEIGHT); + + // Determine which half is the non-head (static background) area. + // When toggled ON, the knob (head) is on the right so non-head is the left half. + // When toggled OFF, the knob is on the left so non-head is the right half. + int nonHeadX, nonHeadWidth; + if (animProgress > 0.5f) { + // ON: knob on right, non-head = left half. + nonHeadX = this.xPosition; + nonHeadWidth = FIXED_WIDTH / 2; + } else { + // OFF: knob on left, non-head = right half. + nonHeadX = this.xPosition + FIXED_WIDTH / 2; + nonHeadWidth = FIXED_WIDTH / 2; + } + + // Tint the non-head area darker. + GL11.glColor4f(0.6f, 0.6f, 0.6f, 1.0F); + // Redraw that half to simulate a darker tone. + this.drawTexturedModalRect(nonHeadX, this.yPosition, 0, 46 + k * 20, nonHeadWidth, FIXED_HEIGHT); + + // Now draw the knob ("head") that slides. + // Knob width equals half of the button (20 pixels). + int knobWidth = FIXED_WIDTH / 2; + // The knob slides from xPosition (OFF) to xPosition + (FIXED_WIDTH - knobWidth) (ON). + int knobX = this.xPosition + (int)((FIXED_WIDTH - knobWidth) * animProgress); + int knobY = this.yPosition; + + // Draw the knob with no tint. + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(knobX, knobY, 0, 46 + k * 20, knobWidth / 2, FIXED_HEIGHT); + this.drawTexturedModalRect(knobX + knobWidth / 2, knobY, 200 - knobWidth / 2, 46 + k * 20, knobWidth / 2, FIXED_HEIGHT); + + // Draw the icon on the knob (always 16×16, centered on the knob). + int iconX = knobX + (knobWidth - ICON_SIZE) / 2; + int iconY = knobY + (FIXED_HEIGHT - ICON_SIZE) / 2; + ResourceLocation iconTex; + int texX, texY; + // When ON, use the super class icon; when OFF, use textureOff if provided. + if (toggled) { + iconTex = this.iconTexture; + texX = this.iconPosX; + texY = this.iconPosY; + } else { + if (this.textureOff != null) { + iconTex = this.textureOff; + texX = this.textureOffPosX; + texY = this.textureOffPosY; + } else { + iconTex = this.iconTexture; + texX = this.iconPosX; + texY = this.iconPosY; + } + } + if (iconTex != null) { + mc.getTextureManager().bindTexture(iconTex); + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(iconX, iconY, texX, texY, ICON_SIZE, ICON_SIZE); + } + + // Optionally, draw the centered display string (if needed). + int textColor = 14737632; + if (packedFGColour != 0) { + textColor = packedFGColour; + } else if (!this.enabled) { + textColor = 10526880; + } else if (this.field_146123_n) { + textColor = 16777120; + } + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + FIXED_WIDTH / 2, + this.yPosition + (FIXED_HEIGHT - 8) / 2, textColor); + } +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 2e827cb94..5b5d71dc4 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -58,6 +58,7 @@ tile.npcScripted.name=Scripted Block gui.delete=Are you sure you want to delete this? gui.add=Add +gui.view=View gui.remove=Remove gui.save=Save gui.name=Name @@ -151,6 +152,7 @@ gui.npcs=NPCs gui.change=Change gui.create=Create gui.rename=Rename +gui.playerMap=Regen PlayerMap party.accept=Accept party.allowParty=Allow Partying