tcr/java/src/game/gui/GuiCheat.java
2025-03-12 18:13:11 +01:00

625 lines
17 KiB
Java
Executable file

package game.gui;
import java.util.List;
import game.Button;
import game.ExtMath;
import game.collect.Lists;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.InventoryBasic;
import game.inventory.Slot;
import game.item.CheatTab;
import game.item.ItemStack;
import game.packet.CPacketCheat;
import game.renderer.GlState;
public class GuiCheat extends GuiContainer {
// private static final String TAB_TEXTURE = "textures/gui/tabs.png";
private static InventoryBasic tempInventory = new InventoryBasic("tmp", true, 12 * 9);
private static int selectedTabIndex = CheatTab.tabBlocks.getIndex();
private float currentScroll;
private boolean isScrolling;
private boolean wasClicking;
// private TextField searchField;
// private boolean mouseClicked;
public GuiCheat()
{
super(new GuiCheat.ContainerCheating());
// this.allowUserInput = true;
this.ySize = 208;
this.xSize = 249;
}
public void updateScreen()
{
}
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType)
{
// this.mouseClicked = true;
if((clickType == 0 || clickType == 2) && slotIn != null && slotIn.inventory == tempInventory && slotIn.getStack() != null && this.gm.thePlayer != null)
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketCheat(slotIn.getStack(), clickType == 0 ? -1 : clickedButton, this.gm.ctrl()));
}
public void initGui()
{
// this.guiLeft = (this.width - this.xSize) / 2;
// this.guiTop = (this.height - this.ySize) / 2;
// this.buttonList.clear();
// Keyboard.enableRepeatEvents(true);
// this.searchField = new TextField(this.guiLeft + 82, this.guiTop + 6, 142, FontRenderer.FONT_HEIGHT);
// this.searchField.setMaxStringLength(31);
// this.searchField.setEnableBackgroundDrawing(false);
// this.searchField.setVisible(false);
// this.searchField.setTextColor(16777215);
int i = selectedTabIndex;
selectedTabIndex = -1;
this.setCurrentTab(CheatTab.TABS[i]);
// this.addButtons();
}
// public void onGuiClosed()
// {
// Keyboard.enableRepeatEvents(false);
// }
// protected void keyTyped(char typedChar, int keyCode)
// {
// if (selectedTabIndex == CheatTab.tabSearch.getIndex())
// {
//// super.keyTyped(typedChar, keyCode);
//// }
//// else
//// {
// if (this.mouseClicked)
// {
// this.mouseClicked = false;
// this.searchField.setText("");
// }
//
//// if (!this.checkHotbarKeys(keyCode))
//// {
// if (this.searchField.textboxKeyTyped(typedChar, keyCode))
// {
// this.updateSearch();
// }
//// else
//// {
//// super.keyTyped(typedChar, keyCode);
//// }
// }
//// }
// }
// private void updateSearch()
// {
// GuiCheat.ContainerCheating inv = (GuiCheat.ContainerCheating)this.inventorySlots;
// inv.itemList.clear();
//
// for (Item item : ItemRegistry.REGISTRY)
// {
// if (item != null && item.getTab() != null)
// {
// item.getSubItems(item, null, inv.itemList);
// }
// }
//
//// for (Enchantment enchantment : Enchantment.enchantmentsBookList)
//// {
//// if (enchantment != null && enchantment.type != null)
//// {
//// Items.enchanted_book.getAll(enchantment, inv.itemList);
//// }
//// }
//
// Iterator<ItemStack> iterator = inv.itemList.iterator();
// String s1 = this.searchField.getText().toLowerCase();
//
// while (iterator.hasNext())
// {
// ItemStack itemstack = (ItemStack)iterator.next();
// boolean flag = false;
//
// for (String s : itemstack.getTooltip(this.gm.thePlayer))
// {
// if (TextColor.stripCodes(s).toLowerCase().contains(s1))
// {
// flag = true;
// break;
// }
// }
//
// if (!flag)
// {
// iterator.remove();
// }
// }
//
// this.currentScroll = 0.0F;
// inv.scrollTo(0.0F);
// }
public void drawGuiContainerForegroundLayer()
{
CheatTab tab = CheatTab.TABS[selectedTabIndex];
// GlState.disableBlend();
this.drawString(tab.getName(), 8, 6);
this.drawString("Vorsicht: Schummeln wird mit Keule bestraft", 8, 183);
this.drawString("(Halte Strg beim Klick für vollen Stapel)", 8, 183 + 10);
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
// int i = mouseX - this.guiLeft;
// int j = mouseY - this.guiTop;
for (CheatTab tab : CheatTab.TABS)
{
if (this.isInsideTab(tab, mouseX, mouseY))
{
return;
}
}
}
super.mouseClicked(mouseX, mouseY, mouseButton);
}
public void mouseReleased(int mouseX, int mouseY, int state)
{
if (state == 0)
{
// int i = mouseX - this.guiLeft;
// int j = mouseY - this.guiTop;
for (CheatTab tab : CheatTab.TABS)
{
if (this.isInsideTab(tab, mouseX, mouseY))
{
this.setCurrentTab(tab);
return;
}
}
}
super.mouseReleased(mouseX, mouseY, state);
}
public void mouseDragged(int mouseX, int mouseY) {
}
private boolean needsScrollBars()
{
return ((GuiCheat.ContainerCheating)this.inventorySlots).canScroll();
}
private void setCurrentTab(CheatTab tab)
{
if(tab == CheatTab.tabInventory) {
// this.gm.getSoundManager().playSound(new PositionedSound(SoundEvent.CLICK, 1.0F));
this.gm.displayGuiScreen(new GuiInventory(this.gm.thePlayer));
return;
}
selectedTabIndex = tab.getIndex();
GuiCheat.ContainerCheating slots = (GuiCheat.ContainerCheating)this.inventorySlots;
this.dragSplittingSlots.clear();
slots.itemList.clear();
tab.displayAllReleventItems(slots.itemList);
// if (this.searchField != null)
// {
// if (tab == CheatTab.tabSearch)
// {
// this.searchField.setVisible(true);
// this.searchField.setCanLoseFocus(false);
// this.searchField.setFocused(true);
// this.searchField.setText("");
// this.updateSearch();
// }
// else
// {
// this.searchField.setVisible(false);
// this.searchField.setCanLoseFocus(true);
// this.searchField.setFocused(false);
// }
// }
this.currentScroll = 0.0F;
slots.scrollTo(0.0F);
}
public void scroll(int scr_x, int scr_y, int x, int y, boolean ctrl, boolean shift) {
super.scroll(scr_x, scr_y, x, y, ctrl, shift);
// public void scroll(int dir) {
if(scr_y != 0 && this.needsScrollBars()) {
int len = ((GuiCheat.ContainerCheating)this.inventorySlots).itemList.size() / 12 - 5;
this.currentScroll = (float)((double)this.currentScroll - (double)scr_y / (double)len);
this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F);
((GuiCheat.ContainerCheating)this.inventorySlots).scrollTo(this.currentScroll);
}
}
// public void handleMouseInput() throws IOException
// {
// super.handleMouseInput();
// int i = Mouse.getEventDWheel();
//
// if (i != 0 && this.needsScrollBars())
// {
// int j = ((GuiCheat.ContainerCheating)this.inventorySlots).itemList.size() / 12 - 5;
//
// if (i > 0)
// {
// i = 1;
// }
//
// if (i < 0)
// {
// i = -1;
// }
//
// this.currentScroll = (float)((double)this.currentScroll - (double)i / (double)j);
// this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F);
// ((GuiCheat.ContainerCheating)this.inventorySlots).scrollTo(this.currentScroll);
// }
// }
public void drawScreen(int mouseX, int mouseY)
{
boolean flag = Button.MOUSE_LEFT.isDown(); //TODO: remove?
int x1 = 175 + 18 * 3;
int y1 = 18;
int x2 = x1 + 14;
int y2 = y1 + 112 + 18 * 4;
if (!this.wasClicking && flag && mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2)
{
this.isScrolling = this.needsScrollBars();
}
if (!flag)
{
this.isScrolling = false;
}
this.wasClicking = flag;
if (this.isScrolling)
{
this.currentScroll = ((float)(mouseY - y1) - 7.5F) / ((float)(y2 - y1) - 15.0F);
this.currentScroll = ExtMath.clampf(this.currentScroll, 0.0F, 1.0F);
((GuiCheat.ContainerCheating)this.inventorySlots).scrollTo(this.currentScroll);
}
super.drawScreen(mouseX, mouseY);
for (CheatTab tab : CheatTab.TABS)
{
if (this.renderInventoryHoveringText(tab, mouseX, mouseY))
{
break;
}
}
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
GlState.disableLighting();
}
protected void drawSlots(int mouseX, int mouseY) {
super.drawSlots(mouseX, mouseY);
for (CheatTab tabs : CheatTab.TABS)
{
this.drawTab(tabs);
}
}
// public void drawDefaultBackground() {
// }
// protected void renderToolTip(ItemStack stack, int x, int y)
// {
// if (selectedTabIndex == CheatTab.tabSearch.getIndex())
// {
// List<String> list = stack.getTooltip(this.gm.thePlayer);
// CheatTab tab = stack.getItem().getTab();
//
//// if (tab == null && stack.getItem() == Items.enchanted_book)
//// {
//// Map<Integer, Integer> map = EnchantmentHelper.getEnchantments(stack);
////
//// if (map.size() == 1)
//// {
//// Enchantment enchantment = Enchantment.getEnchantmentById(((Integer)map.keySet().iterator().next()).intValue());
////
//// for (CheatTab tabs : CheatTab.TABS)
//// {
//// if (tabs.hasRelevantEnchantmentType(enchantment.type))
//// {
//// tab = tabs;
//// break;
//// }
//// }
//// }
//// }
//
// for (int i = 1; i < list.size(); i++)
// {
// list.set(i, TextColor.LIGHT_GRAY + list.get(i));
// }
//
// if(tab != null)
// list.add(1, TextColor.BLUE + tab.getName());
//
// this.drawHoveringText(list, x, y);
// }
// else
// {
// super.renderToolTip(stack, x, y);
// }
// }
public void drawGuiContainerBackgroundLayer()
{
int i = 229;
int j = 18;
int k = j + 184;
this.rect(i, j, 12, 182, this.needsScrollBars() ? 0x303030 : 0x202020);
this.rect(i, j + (int)((float)(k - j - 17) * this.currentScroll), 12, 15, this.needsScrollBars() ? 0x808080 : 0x606060);
CheatTab tab = CheatTab.TABS[selectedTabIndex];
int x = 28 * tab.getTabColumn();
int y = 0;
if (tab.isRight())
{
x = this.xSize - 28;
}
else if (!tab.isLeft())
{
x += tab.getTabColumn();
}
if (tab.isTop())
{
y = y - 28;
}
else
{
y = y + (this.ySize - 4);
}
x = x + 6 - 1;
y = y + 8 + (tab.isTop() ? 1 : -1);
y = y + (tab.isTop() ? 17 : -3);
this.rect(x, y, 18, 2, 0xffffff);
}
protected boolean isInsideTab(CheatTab tab, int x, int y)
{
int col = tab.getTabColumn();
int tx = 28 * col;
int ty = 0;
if (tab.isRight())
{
tx = this.xSize - 28 + 2;
}
else if (!tab.isLeft())
{
tx += col;
}
if (tab.isTop())
{
ty = ty - 32;
}
else
{
ty = ty + this.ySize;
}
return x >= tx && x <= tx + 28 && y >= ty && y <= ty + 32;
}
protected boolean renderInventoryHoveringText(CheatTab tab, int x, int z)
{
int col = tab.getTabColumn();
int tx = 28 * col;
int ty = 0;
if (tab.isRight())
{
tx = this.xSize - 28 + 2;
}
else if (!tab.isLeft())
{
tx += col;
}
if (tab.isTop())
{
ty = ty - 32;
}
else
{
ty = ty + this.ySize;
}
if (this.isPointInRegion(tx + 3, ty + 3, 23, 27, x, z))
{
this.hover(tab.getName(), x, z);
return true;
}
else
{
return false;
}
}
public void addButtons() {
super.addButtons();
for(CheatTab tab : CheatTab.TABS) {
int x = 28 * tab.getTabColumn();
int y = 0;
if (tab.isRight())
{
x = this.xSize - 28;
}
else if (!tab.isLeft())
{
x += tab.getTabColumn();
}
if (tab.isTop())
{
y = y - 28;
}
else
{
y = y + (this.ySize - 4);
}
x = x + 6;
y = y + 8 + (tab.isTop() ? 1 : -1);
this.button(x - 1, y - 1, 18, 18);
}
}
protected void drawTab(CheatTab tab)
{
boolean flag = tab.getIndex() == selectedTabIndex;
boolean flag1 = tab.isTop();
int col = tab.getTabColumn();
// int tx = 0;
// int ty = 0;
int x = 28 * col;
int y = 0;
// int j1 = 32;
// if (flag)
// {
// ty += 32;
// }
if (tab.isRight())
{
x = this.xSize - 28;
// tx = 2 * 28;
}
else if (!tab.isLeft())
{
x += col;
// tx = 28;
}
if (flag1)
{
y = y - 28;
}
else
{
// ty += 64;
y = y + (this.ySize - 4);
}
// GlState.disableLighting();
// this.rect(x, y, tx, ty, 28, 32);
// this.zLevel = 100.0F;
this.itemRender.zLevel = 100.0F;
x = x + 6;
y = y + 8 + (flag1 ? 1 : -1);
// GlState.enableLighting();
// GlState.enableRescaleNormal();
ItemStack itemstack = tab.getIconItemStack();
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, x, y);
// this.itemRender.renderItemOverlays(itemstack, x, y);
// GlState.disableLighting();
this.itemRender.zLevel = 0.0F;
// this.zLevel = 0.0F;
}
// public int getSelectedTabIndex()
// {
// return selectedTabIndex;
// }
static class ContainerCheating extends Container
{
public List<ItemStack> itemList = Lists.<ItemStack>newArrayList();
public ContainerCheating()
{
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 12; ++j)
{
this.addSlotToContainer(new Slot(GuiCheat.tempInventory, i * 12 + j, 9 + j * 18, 18 + i * 18));
}
}
this.scrollTo(0.0F);
}
public boolean canInteractWith(EntityNPC playerIn)
{
return true;
}
public void scrollTo(float p_148329_1_)
{
int i = (this.itemList.size() + 12 - 1) / 12 - 9;
int j = (int)((double)(p_148329_1_ * (float)i) + 0.5D);
if (j < 0)
{
j = 0;
}
for (int k = 0; k < 9; ++k)
{
for (int l = 0; l < 12; ++l)
{
int i1 = l + (k + j) * 12;
if (i1 >= 0 && i1 < this.itemList.size())
{
GuiCheat.tempInventory.setInventorySlotContents(l + k * 12, (ItemStack)this.itemList.get(i1));
}
else
{
GuiCheat.tempInventory.setInventorySlotContents(l + k * 12, (ItemStack)null);
}
}
}
}
public boolean canScroll()
{
return this.itemList.size() > 12 * 9;
}
protected void retrySlotClick(int slotId, int clickedButton, boolean mode, EntityNPC playerIn)
{
}
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
{
return null;
}
public boolean canMergeSlot(ItemStack stack, Slot slotIn)
{
return false;
}
public boolean canDragIntoSlot(Slot p_94531_1_)
{
return false;
}
}
}