mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 11:44:25 +00:00
Merge branch 'dev' into janino-scripts
This commit is contained in:
commit
3f8373d76f
48 files changed
+3333
-2035
No files matched your search
@@ -144,20 +144,20 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
// TOP TABS using GuiMenuTopButton
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
GuiMenuTopButton generalTab = new GuiMenuTopButton(90, guiLeft + 4, guiTop - 17, "ability.tab.general");
|
||||
GuiMenuTopButton generalTab = new GuiMenuTopButton(90, guiLeft + 4, guiTop - 17, "menu.general");
|
||||
generalTab.active = (activeTab == TAB_GENERAL);
|
||||
addTopButton(generalTab);
|
||||
|
||||
GuiMenuTopButton lastTab = generalTab;
|
||||
|
||||
if (hasTypeSettings) {
|
||||
GuiMenuTopButton typeTab = new GuiMenuTopButton(91, lastTab, "ability.tab.type");
|
||||
GuiMenuTopButton typeTab = new GuiMenuTopButton(91, lastTab, "gui.type");
|
||||
typeTab.active = (activeTab == TAB_TYPE);
|
||||
addTopButton(typeTab);
|
||||
lastTab = typeTab;
|
||||
}
|
||||
|
||||
GuiMenuTopButton targetTab = new GuiMenuTopButton(92, lastTab, "ability.tab.target");
|
||||
GuiMenuTopButton targetTab = new GuiMenuTopButton(92, lastTab, "script.target");
|
||||
targetTab.active = (activeTab == TAB_TARGET);
|
||||
addTopButton(targetTab);
|
||||
lastTab = targetTab;
|
||||
@@ -435,7 +435,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
// SOUNDS SECTION
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
addLabel(new GuiNpcLabel(30, "ability.sounds", col1LabelX, y));
|
||||
addLabel(new GuiNpcLabel(30, "advanced.sounds", col1LabelX, y));
|
||||
y += 14;
|
||||
|
||||
// Wind Up Sound
|
||||
@@ -455,7 +455,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
// ANIMATIONS SECTION
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
addLabel(new GuiNpcLabel(33, "ability.animations", col1LabelX, y));
|
||||
addLabel(new GuiNpcLabel(33, "menu.animations", col1LabelX, y));
|
||||
y += 14;
|
||||
|
||||
// Wind Up Animation
|
||||
@@ -486,7 +486,8 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// Telegraph Type (separate column)
|
||||
String typeKey = ability.getTelegraphType().name().toLowerCase();
|
||||
addLabel(new GuiNpcLabel(42, "ability.telegraphType", guiLeft + 200, y + 5));
|
||||
addLabel(new GuiNpcLabel(43, "ability.telegraph." + typeKey, guiLeft + 280, y + 5));
|
||||
String telegraphLangKey = typeKey.equals("none") ? "gui.none" : "telegraph." + typeKey;
|
||||
addLabel(new GuiNpcLabel(43, telegraphLangKey, guiLeft + 280, y + 5));
|
||||
|
||||
y += 24;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SubGuiAbilityBeam extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Damage Interval
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, beam.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.dmgInterval", col2LabelX, y + 5));
|
||||
|
||||
@@ -27,10 +27,10 @@ public class SubGuiAbilityCharge extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Speed
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, charge.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.speed", col2LabelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(101, "stats.speed", col2LabelX, y + 5));
|
||||
addTextField(createFloatField(101, col2FieldX, y, 50, charge.getChargeSpeed()));
|
||||
|
||||
y += 24;
|
||||
|
||||
@@ -28,10 +28,10 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Range
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, cutter.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.range", col2LabelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(101, "gui.range", col2LabelX, y + 5));
|
||||
addTextField(createFloatField(101, col2FieldX, y, 50, cutter.getRange()));
|
||||
|
||||
y += 24;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SubGuiAbilityDash extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Dash Mode
|
||||
addLabel(new GuiNpcLabel(100, "ability.dashMode", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "ability.mode", labelX, y + 5));
|
||||
String[] dashModes = {"Aggressive", "Defensive"};
|
||||
addButton(new GuiNpcButton(100, fieldX, y, 80, 20, dashModes, dash.getDashMode().ordinal()));
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig {
|
||||
addLabel(new GuiNpcLabel(102, "ability.healRadius", labelX, y + 5));
|
||||
addTextField(createFloatField(102, fieldX, y, 50, heal.getHealRadius()));
|
||||
|
||||
addLabel(new GuiNpcLabel(103, "ability.instant", col2LabelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(103, "dialog.instant", col2LabelX, y + 5));
|
||||
addButton(new GuiNpcButton(103, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isInstantHeal() ? 1 : 0));
|
||||
|
||||
y += 24;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SubGuiAbilityHeavyHit extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Potion Time
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, heavyHit.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.potionTime", col2LabelX, y + 5));
|
||||
|
||||
@@ -28,16 +28,16 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Speed
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, orb.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.speed", col2LabelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(101, "stats.speed", col2LabelX, y + 5));
|
||||
addTextField(createFloatField(101, col2FieldX, y, 50, orb.getOrbSpeed()));
|
||||
|
||||
y += 24;
|
||||
|
||||
// Row 2: Orb Size + Max Distance
|
||||
addLabel(new GuiNpcLabel(102, "ability.orbSize", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(102, "stats.size", labelX, y + 5));
|
||||
addTextField(createFloatField(102, fieldX, y, 50, orb.getOrbSize()));
|
||||
|
||||
addLabel(new GuiNpcLabel(103, "ability.maxDist", col2LabelX, y + 5));
|
||||
|
||||
@@ -28,10 +28,10 @@ public class SubGuiAbilityProjectile extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Speed
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, projectile.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.speed", col2LabelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(101, "stats.speed", col2LabelX, y + 5));
|
||||
addTextField(createFloatField(101, col2FieldX, y, 50, projectile.getSpeed()));
|
||||
|
||||
y += 24;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SubGuiAbilityShockwave extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Push Radius
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, shockwave.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.pushRadius", col2LabelX, y + 5));
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SubGuiAbilitySlam extends SubGuiAbilityConfig {
|
||||
int col2FieldX = guiLeft + 205;
|
||||
|
||||
// Row 1: Damage + Radius
|
||||
addLabel(new GuiNpcLabel(100, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(100, fieldX, y, 50, slam.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(101, "ability.radius", col2LabelX, y + 5));
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig {
|
||||
}
|
||||
|
||||
// Damage + Damage Radius
|
||||
addLabel(new GuiNpcLabel(106, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(106, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(106, fieldX, y, 50, teleport.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(107, "ability.dmgRadius", col2LabelX, y + 5));
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig {
|
||||
y += 24;
|
||||
|
||||
// Row 2: Damage + Damage Radius
|
||||
addLabel(new GuiNpcLabel(102, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(102, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(102, fieldX, y, 50, trap.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(103, "ability.dmgRadius", col2LabelX, y + 5));
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig {
|
||||
y += 24;
|
||||
|
||||
// Row 2: Damage + Knockback
|
||||
addLabel(new GuiNpcLabel(102, "ability.damage", labelX, y + 5));
|
||||
addLabel(new GuiNpcLabel(102, "enchantment.damage", labelX, y + 5));
|
||||
addTextField(createFloatField(102, fieldX, y, 50, vortex.getDamage()));
|
||||
|
||||
addLabel(new GuiNpcLabel(103, "ability.knockback", col2LabelX, y + 5));
|
||||
|
||||
@@ -49,7 +49,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
super.initGui();
|
||||
int y = guiTop + 10;
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, y, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y, 155, 20, new String[]{"role.none", "role.trader", "role.follower", "role.bank", "role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)"), "role.mount"}, npc.advanced.role.ordinal()));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y, 155, 20, new String[]{"role.none", "role.trader", "role.follower", "role.bank", "role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)"), "role.mount", "role.auctioneer"}, npc.advanced.role.ordinal()));
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
|
||||
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += 22, 52, 20, "selectServer.edit"));
|
||||
|
||||
@@ -1,136 +1,335 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.GetTraderData;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.containers.ContainerNPCTrader;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public class GuiNPCTrader extends GuiContainerNPCInterface {
|
||||
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/trader.png");
|
||||
public class GuiNPCTrader extends GuiContainerNPCInterface implements IGuiData {
|
||||
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/tradersetup.png");
|
||||
private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png");
|
||||
private RoleTrader role;
|
||||
private ContainerNPCTrader container;
|
||||
|
||||
// Layout constants matching ContainerNPCTrader
|
||||
private static final int COLUMN_WIDTH = ContainerNPCTrader.COLUMN_WIDTH;
|
||||
private static final int COLUMN_START_X = ContainerNPCTrader.COLUMN_START_X;
|
||||
private static final int ROW_HEIGHT = ContainerNPCTrader.ROW_HEIGHT;
|
||||
private static final int ROW_START_Y = ContainerNPCTrader.ROW_START_Y;
|
||||
private static final int CURRENCY1_OFFSET = ContainerNPCTrader.CURRENCY1_OFFSET;
|
||||
private static final int CURRENCY2_OFFSET = ContainerNPCTrader.CURRENCY2_OFFSET;
|
||||
private static final int OUTPUT_OFFSET = ContainerNPCTrader.OUTPUT_OFFSET;
|
||||
|
||||
// Data received from server via IGuiData
|
||||
private long playerBalance = 0;
|
||||
private int[] availableStock = new int[18];
|
||||
private long[] currencyCost = new long[18];
|
||||
private boolean stockEnabled = false;
|
||||
|
||||
// Client-side countdown: target time when stock resets (System.currentTimeMillis())
|
||||
private long resetTargetTime = -1;
|
||||
|
||||
// Current hover status for bottom display
|
||||
private String statusMessage = "";
|
||||
private int statusColor = 0xFFFFFF;
|
||||
|
||||
public GuiNPCTrader(EntityNPCInterface npc, ContainerNPCTrader container) {
|
||||
super(npc, container);
|
||||
this.container = container;
|
||||
role = (RoleTrader) npc.roleInterface;
|
||||
closeOnEsc = true;
|
||||
ySize = 224;
|
||||
xSize = 223;
|
||||
this.title = "role.trader";
|
||||
ySize = 216;
|
||||
xSize = 256;
|
||||
this.title = "";
|
||||
|
||||
// Initialize stock to unlimited
|
||||
for (int i = 0; i < 18; i++) {
|
||||
availableStock[i] = Integer.MAX_VALUE;
|
||||
currencyCost[i] = 0;
|
||||
}
|
||||
|
||||
// Request trader data from server (balance, stock, currency costs)
|
||||
PacketClient.sendClient(new GetTraderData());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
playerBalance = compound.getLong("Balance");
|
||||
stockEnabled = compound.getBoolean("StockEnabled");
|
||||
|
||||
// Calculate target time for client-side countdown
|
||||
long remainingMillis = compound.getLong("ResetTimeMillis");
|
||||
if (remainingMillis > 0) {
|
||||
resetTargetTime = System.currentTimeMillis() + remainingMillis;
|
||||
} else {
|
||||
resetTargetTime = -1;
|
||||
}
|
||||
|
||||
int[] stock = compound.getIntArray("Stock");
|
||||
if (stock != null && stock.length == 18) {
|
||||
availableStock = stock;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
currencyCost[i] = compound.getLong("Cost" + i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
// Reset status each frame
|
||||
statusMessage = "";
|
||||
statusColor = 0xFFFFFF;
|
||||
|
||||
this.drawWorldBackground(0);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.bindTexture(resource);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
// Draw "Trader" label in TOP LEFT (above the GUI)
|
||||
String traderLabel = StatCollector.translateToLocal("role.trader");
|
||||
fontRendererObj.drawString(traderLabel, guiLeft + 4, guiTop - 8, 0xFFFFFF);
|
||||
|
||||
// Draw reset timer in TOP RIGHT (above the GUI)
|
||||
if (stockEnabled && resetTargetTime > 0) {
|
||||
String timerText = getResetCountdownText();
|
||||
int timerWidth = fontRendererObj.getStringWidth(timerText);
|
||||
int timerColor = timerText.equals(StatCollector.translateToLocal("trader.reopentrader")) ? 0xFFAA00 : 0xFFFFFF;
|
||||
fontRendererObj.drawString(timerText, guiLeft + xSize - timerWidth - 4, guiTop - 8, timerColor);
|
||||
}
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
mc.renderEngine.bindTexture(slot);
|
||||
for (int slot = 0; slot < 18; slot++) {
|
||||
int x = guiLeft + slot % 3 * 72 + 10;
|
||||
int y = guiTop + slot / 3 * 21 + 6;
|
||||
// Draw trade slots (3 columns x 6 rows, 80px column width)
|
||||
for (int slotIdx = 0; slotIdx < 18; slotIdx++) {
|
||||
int col = slotIdx % 3;
|
||||
int row = slotIdx / 3;
|
||||
int x = guiLeft + COLUMN_START_X + col * COLUMN_WIDTH;
|
||||
int y = guiTop + ROW_START_Y + row * ROW_HEIGHT;
|
||||
|
||||
ItemStack item = role.inventoryCurrency.items.get(slot);
|
||||
ItemStack item2 = role.inventoryCurrency.items.get(slot + 18);
|
||||
// Get item currencies
|
||||
ItemStack item = role.inventoryCurrency.items.get(slotIdx);
|
||||
ItemStack item2 = role.inventoryCurrency.items.get(slotIdx + 18);
|
||||
if (item == null) {
|
||||
item = item2;
|
||||
item2 = null;
|
||||
}
|
||||
if (NoppesUtilPlayer.compareItems(item, item2, false, false)) {
|
||||
if (item != null && item2 != null && NoppesUtilPlayer.compareItems(item, item2, role.ignoreDamage, role.ignoreNBT)) {
|
||||
item = item.copy();
|
||||
item.stackSize += item2.stackSize;
|
||||
item2 = null;
|
||||
}
|
||||
|
||||
ItemStack sold = role.inventorySold.items.get(slot);
|
||||
ItemStack sold = role.inventorySold.items.get(slotIdx);
|
||||
|
||||
// Draw slot backgrounds (18x18 each)
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
mc.renderEngine.bindTexture(this.slot);
|
||||
drawTexturedModalRect(x + 42, y, 0, 0, 18, 18);
|
||||
if (item != null && sold != null) {
|
||||
|
||||
// Currency slot 1
|
||||
drawTexturedModalRect(x + CURRENCY1_OFFSET, y, 0, 0, 18, 18);
|
||||
// Currency slot 2
|
||||
drawTexturedModalRect(x + CURRENCY2_OFFSET, y, 0, 0, 18, 18);
|
||||
// Output slot
|
||||
drawTexturedModalRect(x + OUTPUT_OFFSET, y, 0, 0, 18, 18);
|
||||
|
||||
// "=" sign between currency and output
|
||||
fontRendererObj.drawString("=", x + 40, y + 5, CustomNpcResourceListener.DefaultTextColor);
|
||||
|
||||
// Draw currency items (centered: +1 offset for 16x16 item in 18x18 slot)
|
||||
if (sold != null) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
// Draw secondary currency (slot 1)
|
||||
if (item2 != null) {
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item2, x, y + 1);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item2, x, y + 1);
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item2, x + CURRENCY1_OFFSET + 1, y + 1);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item2, x + CURRENCY1_OFFSET + 1, y + 1);
|
||||
}
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item, x + 18, y + 1);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item, x + 18, y + 1);
|
||||
|
||||
// Draw primary currency (slot 2)
|
||||
if (item != null) {
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item, x + CURRENCY2_OFFSET + 1, y + 1);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item, x + CURRENCY2_OFFSET + 1, y + 1);
|
||||
}
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
fontRendererObj.drawString("=", x + 36, y + 5, CustomNpcResourceListener.DefaultTextColor);
|
||||
// Draw stock count to the RIGHT of the trade (after output slot)
|
||||
if (stockEnabled && availableStock[slotIdx] < Integer.MAX_VALUE) {
|
||||
String stockText = String.valueOf(availableStock[slotIdx]);
|
||||
int stockColor = availableStock[slotIdx] > 0 ? 0x00AA00 : 0xAA0000;
|
||||
fontRendererObj.drawString(stockText, x + OUTPUT_OFFSET + 20, y + 5, stockColor);
|
||||
}
|
||||
|
||||
// Draw dark overlay for out of stock items
|
||||
if (stockEnabled && availableStock[slotIdx] <= 0) {
|
||||
drawGradientRect(x + OUTPUT_OFFSET + 1, y + 1, x + OUTPUT_OFFSET + 17, y + 17, 0xC0101010, 0xC0101010);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
super.drawGuiContainerBackgroundLayer(f, i, j);
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
// Draw player balance (BOTTOM RIGHT, below GUI)
|
||||
int infoY = guiTop + ySize + 2;
|
||||
String balanceText = StatCollector.translateToLocal("trader.balance") + ": $" + formatCurrency(playerBalance);
|
||||
int balanceWidth = fontRendererObj.getStringWidth(balanceText);
|
||||
fontRendererObj.drawString(balanceText, guiLeft + xSize - balanceWidth - 4, infoY, 0x36e82a);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||
for (int slot = 0; slot < 18; slot++) {
|
||||
int x = slot % 3 * 72 + 10;
|
||||
int y = slot / 3 * 21 + 6;
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
for (int slotIdx = 0; slotIdx < 18; slotIdx++) {
|
||||
int col = slotIdx % 3;
|
||||
int row = slotIdx / 3;
|
||||
int x = COLUMN_START_X + col * COLUMN_WIDTH;
|
||||
int y = ROW_START_Y + row * ROW_HEIGHT;
|
||||
|
||||
ItemStack item = role.inventoryCurrency.items.get(slot);
|
||||
ItemStack item2 = role.inventoryCurrency.items.get(slot + 18);
|
||||
ItemStack item = role.inventoryCurrency.items.get(slotIdx);
|
||||
ItemStack item2 = role.inventoryCurrency.items.get(slotIdx + 18);
|
||||
if (item == null) {
|
||||
item = item2;
|
||||
item2 = null;
|
||||
}
|
||||
if (NoppesUtilPlayer.compareItems(item, item2, role.ignoreDamage, role.ignoreNBT)) {
|
||||
if (item != null && item2 != null && NoppesUtilPlayer.compareItems(item, item2, role.ignoreDamage, role.ignoreNBT)) {
|
||||
item = item.copy();
|
||||
item.stackSize += item2.stackSize;
|
||||
item2 = null;
|
||||
}
|
||||
ItemStack sold = role.inventorySold.items.get(slot);
|
||||
if (item == null || sold == null)
|
||||
|
||||
ItemStack sold = role.inventorySold.items.get(slotIdx);
|
||||
if (sold == null) {
|
||||
continue;
|
||||
|
||||
if (this.func_146978_c(x + 43, y + 1, 16, 16, par1, par2)) {
|
||||
if (!container.canBuy(slot, player)) {
|
||||
GL11.glTranslatef(0, 0, 300);
|
||||
if (item != null && !NoppesUtilPlayer.compareItems(player, item, role.ignoreDamage, role.ignoreNBT))
|
||||
this.drawGradientRect(x + 17, y, x + 35, y + 18, 0x70771010, 0x70771010);
|
||||
if (item2 != null && !NoppesUtilPlayer.compareItems(player, item2, role.ignoreDamage, role.ignoreNBT))
|
||||
this.drawGradientRect(x - 1, y, x + 17, y + 18, 0x70771010, 0x70771010);
|
||||
|
||||
String title = StatCollector.translateToLocal("trader.insufficient");
|
||||
this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 131, 0xDD0000);
|
||||
GL11.glTranslatef(0, 0, -300);
|
||||
} else if (!container.isSlotEnabled(slot, player)) {
|
||||
String title = StatCollector.translateToLocal("trader.slotdisabled");
|
||||
this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 131, 0xFF4000);
|
||||
} else {
|
||||
String title = StatCollector.translateToLocal("trader.sufficient");
|
||||
this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 131, 0x00DD00);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.func_146978_c(x, y, 16, 16, par1, par2) && item2 != null) {
|
||||
this.renderToolTip(item2, par1 - guiLeft, par2 - guiTop);
|
||||
// Check if hovering over output slot (18x18 area)
|
||||
if (this.func_146978_c(x + OUTPUT_OFFSET, y, 18, 18, mouseX, mouseY)) {
|
||||
updateSlotStatus(slotIdx, item, item2, x, y);
|
||||
}
|
||||
if (this.func_146978_c(x + 18, y, 16, 16, par1, par2)) {
|
||||
this.renderToolTip(item, par1 - guiLeft, par2 - guiTop);
|
||||
|
||||
// Tooltips for currency items
|
||||
if (this.func_146978_c(x + CURRENCY1_OFFSET, y, 18, 18, mouseX, mouseY) && item2 != null) {
|
||||
this.renderToolTip(item2, mouseX - guiLeft, mouseY - guiTop);
|
||||
}
|
||||
if (this.func_146978_c(x + CURRENCY2_OFFSET, y, 18, 18, mouseX, mouseY) && item != null) {
|
||||
this.renderToolTip(item, mouseX - guiLeft, mouseY - guiTop);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw status message in BOTTOM LEFT (in foreground coordinates)
|
||||
if (!statusMessage.isEmpty()) {
|
||||
fontRendererObj.drawString(statusMessage, 4, ySize + 4, statusColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update status message when hovering over a trade slot
|
||||
*/
|
||||
private void updateSlotStatus(int slotIdx, ItemStack item, ItemStack item2, int x, int y) {
|
||||
long cost = currencyCost[slotIdx];
|
||||
String costSuffix = cost > 0 ? " ($" + formatCurrency(cost) + ")" : "";
|
||||
|
||||
// Check conditions in order of priority
|
||||
if (stockEnabled && availableStock[slotIdx] <= 0) {
|
||||
// Out of stock
|
||||
statusMessage = StatCollector.translateToLocal("trader.outofstock") + costSuffix;
|
||||
statusColor = 0xDD0000;
|
||||
} else if (cost > 0 && playerBalance < cost) {
|
||||
// Can't afford currency cost
|
||||
statusMessage = StatCollector.translateToLocal("trader.insufficient.currency") + costSuffix;
|
||||
statusColor = 0xDD0000;
|
||||
} else if (!container.canBuy(slotIdx, player)) {
|
||||
// Missing item currency - highlight which ones
|
||||
GL11.glTranslatef(0, 0, 300);
|
||||
if (item != null && !NoppesUtilPlayer.compareItems(player, item, role.ignoreDamage, role.ignoreNBT)) {
|
||||
this.drawGradientRect(x + CURRENCY2_OFFSET, y, x + CURRENCY2_OFFSET + 18, y + 18, 0x70771010, 0x70771010);
|
||||
}
|
||||
if (item2 != null && !NoppesUtilPlayer.compareItems(player, item2, role.ignoreDamage, role.ignoreNBT)) {
|
||||
this.drawGradientRect(x + CURRENCY1_OFFSET, y, x + CURRENCY1_OFFSET + 18, y + 18, 0x70771010, 0x70771010);
|
||||
}
|
||||
GL11.glTranslatef(0, 0, -300);
|
||||
statusMessage = StatCollector.translateToLocal("trader.unavailable") + costSuffix;
|
||||
statusColor = 0xDD0000;
|
||||
} else if (!container.isSlotEnabled(slotIdx, player)) {
|
||||
// Slot disabled
|
||||
statusMessage = StatCollector.translateToLocal("trader.slotdisabled") + costSuffix;
|
||||
statusColor = 0xFF4000;
|
||||
} else {
|
||||
// Can buy!
|
||||
statusMessage = StatCollector.translateToLocal("trader.available") + costSuffix;
|
||||
statusColor = 0x00DD00;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the countdown text for stock reset timer.
|
||||
* Calculated client-side each frame for smooth countdown.
|
||||
*/
|
||||
private String getResetCountdownText() {
|
||||
if (resetTargetTime <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
long remaining = resetTargetTime - System.currentTimeMillis();
|
||||
if (remaining <= 0) {
|
||||
return StatCollector.translateToLocal("trader.reopentrader");
|
||||
}
|
||||
|
||||
// Format as HH:MM:SS or D days HH:MM:SS
|
||||
long seconds = (remaining / 1000) % 60;
|
||||
long minutes = (remaining / 60000) % 60;
|
||||
long hours = (remaining / 3600000) % 24;
|
||||
long days = remaining / 86400000;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StatCollector.translateToLocal("trader.restock")).append(": ");
|
||||
|
||||
if (days > 0) {
|
||||
sb.append(days).append("d ");
|
||||
}
|
||||
sb.append(String.format("%02d:%02d:%02d", hours, minutes, seconds));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format currency for display (e.g., 1000 -> "1,000")
|
||||
*/
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) {
|
||||
return String.valueOf(amount);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = String.valueOf(amount);
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) {
|
||||
sb.insert(0, ',');
|
||||
}
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.gui.util.GuiContainerNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
@@ -22,6 +22,9 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png");
|
||||
private RoleTrader role;
|
||||
|
||||
// Currency cost textfield IDs start at 100 (100-117 for slots 0-17)
|
||||
private static final int CURRENCY_FIELD_ID_START = 100;
|
||||
|
||||
public GuiNpcTraderSetup(EntityNPCInterface npc, ContainerNPCTraderSetup container) {
|
||||
super(npc, container);
|
||||
ySize = 220;
|
||||
@@ -34,17 +37,30 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
super.initGui();
|
||||
buttonList.clear();
|
||||
setBackground("tradersetup.png");
|
||||
|
||||
// Linked Market name
|
||||
addLabel(new GuiNpcLabel(0, "role.marketname", guiLeft + 214, guiTop + 150));
|
||||
addTextField(new GuiNpcTextField(0, this, guiLeft + 214, guiTop + 160, 180, 20, role.marketName));
|
||||
|
||||
addLabel(new GuiNpcLabel(1, "gui.ignoreDamage", guiLeft + 260, guiTop + 29));
|
||||
addButton(new GuiNpcButtonYesNo(1, guiLeft + 340, guiTop + 24, role.ignoreDamage));
|
||||
// Settings button (opens SubGuiNpcTraderSettings)
|
||||
addButton(new GuiNpcButton(1, guiLeft + 214, guiTop + 184, 88, 20, "gui.settings"));
|
||||
getButton(1).setHoverText("gui.settings.hover");
|
||||
|
||||
addLabel(new GuiNpcLabel(2, "gui.ignoreNBT", guiLeft + 260, guiTop + 51));
|
||||
addButton(new GuiNpcButtonYesNo(2, guiLeft + 340, guiTop + 46, role.ignoreNBT));
|
||||
// Stock Options button (opens SubGuiNpcTraderStock)
|
||||
addButton(new GuiNpcButton(2, guiLeft + 306, guiTop + 184, 88, 20, "stock.options"));
|
||||
getButton(2).setHoverText("stock.options.hover");
|
||||
|
||||
addLabel(new GuiNpcLabel(3, "gui.recordHistory", guiLeft + 260, guiTop + 73));
|
||||
addButton(new GuiNpcButtonYesNo(3, guiLeft + 340, guiTop + 68, role.recordHistory));
|
||||
// Currency cost textfields for each slot (FIRST - before item slots)
|
||||
// Column width: 130px for better spacing
|
||||
for (int i = 0; i < 18; i++) {
|
||||
int x = guiLeft + i % 3 * 130 + 15; // First position after "$" label
|
||||
int y = guiTop + i / 3 * 22 + 14;
|
||||
long cost = role.getCurrencyCost(i);
|
||||
GuiNpcTextField field = new GuiNpcTextField(CURRENCY_FIELD_ID_START + i, this, x, y, 36, 16, cost > 0 ? String.valueOf(cost) : "");
|
||||
field.setMaxStringLength(8);
|
||||
field.setIntegersOnly();
|
||||
addTextField(field);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,13 +73,12 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guibutton) {
|
||||
if (guibutton.id == 1) {
|
||||
role.ignoreDamage = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
// Open Settings SubGui
|
||||
setSubGui(new SubGuiNpcTraderSettings(role));
|
||||
}
|
||||
if (guibutton.id == 2) {
|
||||
role.ignoreNBT = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
}
|
||||
if (guibutton.id == 3) {
|
||||
role.recordHistory = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
// Open Stock Options SubGui
|
||||
setSubGui(new SubGuiNpcTraderStock(role));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,19 +86,31 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
|
||||
super.drawGuiContainerBackgroundLayer(f, i, j);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
// Column width: 130px for better spacing
|
||||
for (int slot = 0; slot < 18; slot++) {
|
||||
int x = guiLeft + slot % 3 * 94 + 7;
|
||||
int x = guiLeft + slot % 3 * 130 + 7;
|
||||
int y = guiTop + slot / 3 * 22 + 4;
|
||||
|
||||
mc.renderEngine.bindTexture(this.slot);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(x - 1, y, 0, 0, 18, 18);
|
||||
drawTexturedModalRect(x + 17, y, 0, 0, 18, 18);
|
||||
// "$" label for currency cost
|
||||
fontRendererObj.drawString("$", x, y + 5, CustomNpcResourceListener.DefaultTextColor);
|
||||
|
||||
fontRendererObj.drawString("=", x + 36, y + 5, CustomNpcResourceListener.DefaultTextColor);
|
||||
// Currency textfield is at x + 8 (drawn by textfield system)
|
||||
|
||||
// Item Cost 1 slot
|
||||
mc.renderEngine.bindTexture(this.slot);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(x + 42, y, 0, 0, 18, 18);
|
||||
drawTexturedModalRect(x + 50, y, 0, 0, 18, 18);
|
||||
|
||||
// Item Cost 2 slot
|
||||
drawTexturedModalRect(x + 68, y, 0, 0, 18, 18);
|
||||
|
||||
// "=" sign
|
||||
fontRendererObj.drawString("=", x + 88, y + 5, CustomNpcResourceListener.DefaultTextColor);
|
||||
|
||||
// Output slot
|
||||
mc.renderEngine.bindTexture(this.slot);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(x + 104, y, 0, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,10 +122,23 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField guiNpcTextField) {
|
||||
String name = guiNpcTextField.getText();
|
||||
if (!name.equalsIgnoreCase(role.marketName)) {
|
||||
role.marketName = name;
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true));
|
||||
int id = guiNpcTextField.id;
|
||||
|
||||
// Handle market name field
|
||||
if (id == 0) {
|
||||
String name = guiNpcTextField.getText();
|
||||
if (!name.equalsIgnoreCase(role.marketName)) {
|
||||
role.marketName = name;
|
||||
PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle currency cost fields (IDs 100-117)
|
||||
if (id >= CURRENCY_FIELD_ID_START && id < CURRENCY_FIELD_ID_START + 18) {
|
||||
int slot = id - CURRENCY_FIELD_ID_START;
|
||||
long cost = guiNpcTextField.getInteger();
|
||||
role.setCurrencyCost(slot, cost);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
/**
|
||||
* Confirmation dialog for resetting trader stock cooldown.
|
||||
*/
|
||||
public class SubGuiNpcTraderCooldownReset extends SubGuiInterface {
|
||||
|
||||
private final RoleTrader role;
|
||||
public boolean confirmed = false;
|
||||
|
||||
public SubGuiNpcTraderCooldownReset(RoleTrader role) {
|
||||
this.role = role;
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 100;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 15;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "stock.cooldown.confirm", guiLeft + 10, y));
|
||||
y += 12;
|
||||
addLabel(new GuiNpcLabel(1, "stock.cooldown.warning", guiLeft + 10, y));
|
||||
|
||||
y += 35;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
// Reset the cooldown
|
||||
role.resetCooldown();
|
||||
confirmed = true;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
public class SubGuiNpcTraderSettings extends SubGuiInterface {
|
||||
|
||||
private final RoleTrader role;
|
||||
|
||||
public SubGuiNpcTraderSettings(RoleTrader role) {
|
||||
this.role = role;
|
||||
setBackground("menubg.png");
|
||||
xSize = 176;
|
||||
ySize = 136;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 14;
|
||||
|
||||
addLabel(new GuiNpcLabel(1, "gui.ignoreDamage", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(1, guiLeft + 120, y, role.ignoreDamage));
|
||||
getButton(1).setHoverText("gui.ignoreDamage.hover");
|
||||
|
||||
y += 28;
|
||||
|
||||
addLabel(new GuiNpcLabel(2, "gui.ignoreNBT", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(2, guiLeft + 120, y, role.ignoreNBT));
|
||||
getButton(2).setHoverText("gui.ignoreNBT.hover");
|
||||
|
||||
y += 28;
|
||||
|
||||
addLabel(new GuiNpcLabel(3, "gui.recordHistory", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(3, guiLeft + 120, y, role.recordHistory));
|
||||
getButton(3).setHoverText("gui.recordHistory.hover");
|
||||
|
||||
y += 34;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + (xSize - 60) / 2, y, 60, 20, "gui.done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case 0:
|
||||
close();
|
||||
break;
|
||||
case 1:
|
||||
role.ignoreDamage = ((GuiNpcButtonYesNo) button).getBoolean();
|
||||
break;
|
||||
case 2:
|
||||
role.ignoreNBT = ((GuiNpcButtonYesNo) button).getBoolean();
|
||||
break;
|
||||
case 3:
|
||||
role.recordHistory = ((GuiNpcButtonYesNo) button).getBoolean();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.client.gui.util.SubGuiNpcCooldownPicker;
|
||||
import noppes.npcs.constants.EnumStockReset;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
public class SubGuiNpcTraderStock extends SubGuiInterface implements ISubGuiListener, ITextfieldListener {
|
||||
|
||||
private final RoleTrader role;
|
||||
|
||||
public SubGuiNpcTraderStock(RoleTrader role) {
|
||||
this.role = role;
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 220;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
// Enable Stock
|
||||
addLabel(new GuiNpcLabel(1, "stock.enable", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(1, guiLeft + 140, y, role.stock.enableStock));
|
||||
getButton(1).setHoverText("stock.enable.hover");
|
||||
|
||||
y += 24;
|
||||
|
||||
// Per-Player Stock
|
||||
addLabel(new GuiNpcLabel(2, "stock.perplayer", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(2, guiLeft + 140, y, role.stock.perPlayer));
|
||||
getButton(2).setHoverText("stock.perplayer.hover");
|
||||
|
||||
y += 24;
|
||||
|
||||
// Reset Type
|
||||
addLabel(new GuiNpcLabel(3, "stock.resettype", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButton(3, guiLeft + 90, y, 120, 20, EnumStockReset.getDisplayNames(), role.stock.resetType.ordinal()));
|
||||
getButton(3).setHoverText("stock.resettype.hover");
|
||||
|
||||
y += 24;
|
||||
|
||||
// Custom Time button (only visible for custom types)
|
||||
EnumStockReset resetType = role.stock.resetType;
|
||||
if (resetType == EnumStockReset.MCCUSTOM || resetType == EnumStockReset.RLCUSTOM) {
|
||||
addLabel(new GuiNpcLabel(4, "stock.customtime", guiLeft + 10, y + 5));
|
||||
addButton(new GuiNpcButton(4, guiLeft + 90, y, 120, 20, "gui.edit"));
|
||||
getButton(4).setHoverText("stock.customtime.hover");
|
||||
y += 24;
|
||||
}
|
||||
|
||||
// Default Max Stock (applies to all slots as default)
|
||||
addLabel(new GuiNpcLabel(5, "stock.defaultmax", guiLeft + 10, y + 5));
|
||||
GuiNpcTextField defaultStock = new GuiNpcTextField(5, this, fontRendererObj, guiLeft + 140, y, 60, 20, getDefaultStockString());
|
||||
defaultStock.setIntegersOnly();
|
||||
defaultStock.setMinMaxDefault(-1, Integer.MAX_VALUE, -1);
|
||||
addTextField(defaultStock);
|
||||
|
||||
y += 26;
|
||||
|
||||
// Per-Slot Stock button
|
||||
addButton(new GuiNpcButton(5, guiLeft + 10, y, 95, 20, "stock.perslot"));
|
||||
getButton(5).setHoverText("stock.perslot.hover");
|
||||
|
||||
// Reset Stock button
|
||||
addButton(new GuiNpcButton(6, guiLeft + 115, y, 95, 20, "stock.reset"));
|
||||
getButton(6).setHoverText("stock.reset.hover");
|
||||
|
||||
y += 24;
|
||||
|
||||
// Reset Cooldown button
|
||||
addButton(new GuiNpcButton(7, guiLeft + 10, y, 200, 20, "stock.resetcooldown"));
|
||||
getButton(7).setHoverText("stock.resetcooldown.hover");
|
||||
|
||||
// Done button
|
||||
addButton(new GuiNpcButton(0, guiLeft + (xSize - 60) / 2, guiTop + ySize - 40, 60, 20, "gui.done"));
|
||||
}
|
||||
|
||||
private String getDefaultStockString() {
|
||||
// Check if all stocks are the same, if so return that value
|
||||
int first = role.stock.maxStock[0];
|
||||
for (int i = 1; i < 18; i++) {
|
||||
if (role.stock.maxStock[i] != first) {
|
||||
return "-1"; // Mixed values, return unlimited
|
||||
}
|
||||
}
|
||||
return String.valueOf(first);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case 0: // Done
|
||||
close();
|
||||
break;
|
||||
case 1: // Enable Stock
|
||||
role.stock.enableStock = ((GuiNpcButtonYesNo) button).getBoolean();
|
||||
break;
|
||||
case 2: // Per-Player
|
||||
role.stock.perPlayer = ((GuiNpcButtonYesNo) button).getBoolean();
|
||||
break;
|
||||
case 3: // Reset Type
|
||||
int value = ((GuiNpcButton) button).getValue();
|
||||
role.stock.resetType = EnumStockReset.values()[value];
|
||||
initGui(); // Refresh to show/hide custom time button
|
||||
break;
|
||||
case 4: // Custom Time
|
||||
boolean isMC = role.stock.resetType == EnumStockReset.MCCUSTOM;
|
||||
setSubGui(new SubGuiNpcCooldownPicker(isMC, role.stock.customResetTime));
|
||||
break;
|
||||
case 5: // Per-Slot Stock
|
||||
setSubGui(new SubGuiNpcTraderStockSlots(role));
|
||||
break;
|
||||
case 6: // Reset Stock
|
||||
setSubGui(new SubGuiNpcTraderStockReset(role));
|
||||
break;
|
||||
case 7: // Reset Cooldown
|
||||
setSubGui(new SubGuiNpcTraderCooldownReset(role));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subGui) {
|
||||
if (subGui instanceof SubGuiNpcCooldownPicker) {
|
||||
long value = ((SubGuiNpcCooldownPicker) subGui).cooldownValue;
|
||||
// Validate minimum: 1 tick for MC time, 1000ms (1 second) for real time
|
||||
boolean isMC = role.stock.resetType == EnumStockReset.MCCUSTOM;
|
||||
long minimum = isMC ? 1 : 1000;
|
||||
role.stock.customResetTime = Math.max(minimum, value);
|
||||
}
|
||||
// Refresh after per-slot editing
|
||||
if (subGui instanceof SubGuiNpcTraderStockSlots) {
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
if (textField.id == 5) {
|
||||
int value = textField.getInteger();
|
||||
// Apply to all slots
|
||||
for (int i = 0; i < 18; i++) {
|
||||
role.stock.setMaxStock(i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
/**
|
||||
* Confirmation dialog for resetting trader stock.
|
||||
*/
|
||||
public class SubGuiNpcTraderStockReset extends SubGuiInterface {
|
||||
|
||||
private final RoleTrader role;
|
||||
public boolean confirmed = false;
|
||||
|
||||
public SubGuiNpcTraderStockReset(RoleTrader role) {
|
||||
this.role = role;
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 100;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 15;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "stock.reset.confirm", guiLeft + 10, y));
|
||||
y += 12;
|
||||
addLabel(new GuiNpcLabel(1, "stock.reset.warning", guiLeft + 10, y));
|
||||
|
||||
y += 35;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
// Reset the stock
|
||||
long currentTime = role.stock.resetType.isRealTime()
|
||||
? System.currentTimeMillis()
|
||||
: (role.npc != null && role.npc.worldObj != null ? role.npc.worldObj.getTotalWorldTime() : 0);
|
||||
role.stock.resetStock(currentTime);
|
||||
confirmed = true;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
|
||||
/**
|
||||
* Per-slot stock management dialog.
|
||||
* Shows all 18 slots with their max stock values.
|
||||
*/
|
||||
public class SubGuiNpcTraderStockSlots extends SubGuiInterface implements ITextfieldListener {
|
||||
|
||||
private final RoleTrader role;
|
||||
|
||||
public SubGuiNpcTraderStockSlots(RoleTrader role) {
|
||||
this.role = role;
|
||||
setBackground("menubg.png");
|
||||
xSize = 256;
|
||||
ySize = 216;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, "stock.perslot.title", guiLeft + 10, guiTop + 6));
|
||||
|
||||
// 18 slots in 3 columns x 6 rows
|
||||
int startY = guiTop + 22;
|
||||
int colWidth = 80;
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
int col = i % 3;
|
||||
int row = i / 3;
|
||||
|
||||
int x = guiLeft + 10 + col * colWidth;
|
||||
int y = startY + row * 28;
|
||||
|
||||
// Slot label
|
||||
addLabel(new GuiNpcLabel(i + 1, "Slot " + (i + 1) + ":", x, y + 5));
|
||||
|
||||
// Max stock textfield
|
||||
int maxStock = role.stock.maxStock[i];
|
||||
String value = maxStock < 0 ? "-1" : String.valueOf(maxStock);
|
||||
GuiNpcTextField field = new GuiNpcTextField(i, this, fontRendererObj, x + 42, y, 32, 18, value);
|
||||
field.setIntegersOnly();
|
||||
field.setMinMaxDefault(-1, Integer.MAX_VALUE, -1);
|
||||
addTextField(field);
|
||||
}
|
||||
|
||||
// Done button
|
||||
addButton(new GuiNpcButton(0, guiLeft + (xSize - 60) / 2, guiTop + ySize - 26, 60, 20, "gui.done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button) {
|
||||
if (button.id == 0) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
int slot = textField.id;
|
||||
if (slot >= 0 && slot < 18) {
|
||||
int value = textField.getInteger();
|
||||
role.stock.setMaxStock(slot, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class GuiAnimationSelection extends SubGuiInterface implements ICustomScr
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.addLabel(new GuiNpcLabel(0, "gui.animations", guiLeft + 8, guiTop + 4));
|
||||
this.addLabel(new GuiNpcLabel(0, "menu.animations", guiLeft + 8, guiTop + 4));
|
||||
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 50, 20, "gui.clear"));
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done"));
|
||||
|
||||
@@ -224,6 +224,15 @@ public abstract class GuiContainerNPCInterface extends GuiContainer {
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
subgui.drawScreen(i, j, f);
|
||||
}
|
||||
|
||||
// Draw hover text for buttons
|
||||
boolean subGui = hasSubGui();
|
||||
for (GuiCustomScroll scroll : new ArrayList<GuiCustomScroll>(scrolls.values())) {
|
||||
scroll.drawHover(i, j);
|
||||
}
|
||||
for (GuiNpcButton button : buttons.values()) {
|
||||
button.drawHover(i, j, subGui);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,9 +61,9 @@ public abstract class GuiContainerNPCInterface2 extends GuiContainerNPCInterface
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.bindTexture(defaultBackground2);
|
||||
if (this instanceof GuiNpcTraderSetup)
|
||||
drawTexturedModalRect(guiLeft + xSize - 210, guiTop, 46, 0, 256, 220);
|
||||
drawTexturedModalRect(guiLeft + xSize - 210, guiTop, 46, 0, 210, 220);
|
||||
else
|
||||
drawTexturedModalRect(guiLeft + xSize - 230, guiTop, 26, 0, 256, 220);
|
||||
drawTexturedModalRect(guiLeft + xSize - 230, guiTop, 26, 0, 230, 220);
|
||||
|
||||
menu.drawElements(fontRendererObj, i, j, mc, f);
|
||||
|
||||
|
||||
@@ -421,10 +421,23 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
GL11.glScalef(bgScale * bgScaleX, bgScale * bgScaleY, bgScale * bgScaleZ);
|
||||
mc.renderEngine.bindTexture(background);
|
||||
if (xSize > 256) {
|
||||
// GUI wider than texture: draw left portion, then right portion from texture edge
|
||||
drawTexturedModalRect(0, 0, 0, 0, 250, ySize);
|
||||
drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize);
|
||||
} else
|
||||
} else if (xSize < 256) {
|
||||
// GUI narrower than texture: stitch left and right edges together
|
||||
// Left portion (first half of GUI)
|
||||
int leftWidth = xSize / 2;
|
||||
// Right portion width (remaining)
|
||||
int rightWidth = xSize - leftWidth;
|
||||
// Draw left side from texture start
|
||||
drawTexturedModalRect(0, 0, 0, 0, leftWidth, ySize);
|
||||
// Draw right side from texture end (256 - rightWidth)
|
||||
drawTexturedModalRect(leftWidth, 0, 256 - rightWidth, 0, rightWidth, ySize);
|
||||
} else {
|
||||
// GUI exactly 256px: draw full texture
|
||||
drawTexturedModalRect(0, 0, 0, 0, xSize, ySize);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user