initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,50 @@
package game.gui;
import game.inventory.ContainerBrewingStand;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
public class GuiBrewing extends GuiContainer
{
// private static final String brewingStandGuiTextures = "textures/gui/brewing_stand.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
private IInventory tileBrewingStand;
public GuiBrewing(InventoryPlayer playerInv, IInventory p_i45506_2_)
{
super(new ContainerBrewingStand(playerInv, p_i45506_2_));
this.playerInventory = playerInv;
this.tileBrewingStand = p_i45506_2_;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.tileBrewingStand.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
int k = this.tileBrewingStand.getField(0);
if (k > 0)
{
int l = (int)(28.0F * (1.0F - (float)k / 400.0F));
if (l > 0)
{
this.rect(97, 16, 9, l, 0xffff20);
}
}
}
}

625
java/src/game/gui/GuiCheat.java Executable file
View file

@ -0,0 +1,625 @@
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;
}
}
}

53
java/src/game/gui/GuiChest.java Executable file
View file

@ -0,0 +1,53 @@
package game.gui;
import game.Game;
import game.inventory.ContainerChest;
import game.inventory.IInventory;
public class GuiChest extends GuiContainer
{
// /** The ResourceLocation containing the chest GUI texture. */
// private static final String CHEST_GUI_TEXTURE = "textures/gui/generic_54.png";
private IInventory upperChestInventory;
private IInventory lowerChestInventory;
/**
* window height is calculated with these values; the more rows, the heigher
*/
private int inventoryRows;
public GuiChest(IInventory upperInv, IInventory lowerInv)
{
super(new ContainerChest(upperInv, lowerInv, Game.getGame().thePlayer));
this.upperChestInventory = upperInv;
this.lowerChestInventory = lowerInv;
// this.allowUserInput = false;
int i = 222;
int j = i - 108;
this.inventoryRows = lowerInv.getSizeInventory() / 9;
this.ySize = j + this.inventoryRows * 18;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.lowerChestInventory.getCommandName(), 8, 6);
this.drawString(this.upperChestInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.inventoryRows * 18 + 17);
//// this.rect(i, j + this.inventoryRows * 18 + 17, 0, 126, this.xSize, 96);
// }
}

View file

@ -0,0 +1,45 @@
package game.gui;
import game.ActButton;
import game.ActButton.Mode;
import game.Gui;
import game.Label;
import game.Textbox;
public class GuiConfirm extends Gui implements ActButton.Callback {
public static interface Callback {
void confirm(boolean confirmed);
}
protected Callback callback;
protected String messageLine1;
private String messageLine2;
protected String confirmButtonText;
protected String cancelButtonText;
private ActButton confirmBtn;
private ActButton cancelBtn;
public GuiConfirm(Callback callback, String msg1, String msg2, String msgConfirm, String msgCancel) {
this.callback = callback;
this.messageLine1 = msg1;
this.messageLine2 = msg2;
this.confirmButtonText = msgConfirm;
this.cancelButtonText = msgCancel;
}
public void init(int width, int height) {
this.add(new Label(0, 0, 500, 24, this.messageLine1, true));
this.add(new Textbox(0, 80, 500, 300, this.messageLine2));
this.confirmBtn = this.add(new ActButton(48, 500, 200, 24, (ActButton.Callback)this, this.confirmButtonText));
this.cancelBtn = this.add(new ActButton(252, 500, 200, 24, (ActButton.Callback)this, this.cancelButtonText));
this.shift();
}
public String getTitle() {
return "Aktion bestätigen";
}
public void use(ActButton btn, Mode mode) {
this.callback.confirm(btn == this.confirmBtn);
}
}

View file

@ -0,0 +1,981 @@
package game.gui;
import java.util.List;
import java.util.Set;
import game.Button;
import game.Drawing;
import game.Drawing.Vec2i;
import game.ExtMath;
import game.Gui;
import game.InventoryButton;
import game.WCF;
import game.collect.Lists;
import game.collect.Sets;
import game.color.TextColor;
import game.inventory.Container;
import game.inventory.InventoryPlayer;
import game.inventory.Slot;
import game.item.ItemStack;
import game.renderer.GlState;
import game.renderer.ItemRenderer;
import game.renderer.entity.RenderItem;
public abstract class GuiContainer extends Gui
{
private class Overlay {
private final ItemStack stack;
private final int x;
private final int y;
private final String alt;
private Overlay(ItemStack stack, int x, int y, String alt) {
this.stack = stack;
this.x = x;
this.y = y;
this.alt = alt;
}
}
// /** The location of the inventory background texture */
// protected static final String inventoryBackground = "textures/gui/inventory.png";
protected RenderItem itemRender;
// public int width;
// public int height;
/** The X size of the inventory window in pixels. */
protected int xSize = 176;
/** The Y size of the inventory window in pixels. */
protected int ySize = 166;
/** A list of the players inventory slots */
public Container inventorySlots;
// /**
// * Starting X position for the Gui. Inconsistent use for Gui backgrounds.
// */
// protected int guiLeft;
//
// /**
// * Starting Y position for the Gui. Inconsistent use for Gui backgrounds.
// */
// protected int guiTop;
/** holds the slot currently hovered */
private Slot theSlot;
/** Used when touchscreen is enabled. */
private Slot clickedSlot;
/** Used when touchscreen is enabled. */
private boolean isRightMouseClick;
/** Used when touchscreen is enabled */
private ItemStack draggedStack;
private int touchUpX;
private int touchUpY;
private Slot returningStackDestSlot;
private long returningStackTime;
/** Used when touchscreen is enabled */
private ItemStack returningStack;
private Slot currentDragTargetSlot;
private long dragItemDropDelay;
protected final Set<Slot> dragSplittingSlots = Sets.<Slot>newHashSet();
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
protected boolean dragSplitting;
private int dragSplittingLimit;
private int dragSplittingButton;
private boolean ignoreMouseUp;
private int dragSplittingRemnant;
private long lastClickTime;
private Slot lastClickSlot;
private int lastClickButton;
private boolean doubleClick;
private ItemStack shiftClickedSlot;
private int container_x;
private int container_y;
private int container_w;
private int container_h;
private int hover_x;
private int hover_y;
private String tooltip;
public void drawString(String text, int x, int y) {
x = x * 2 + this.container_x;
y = y * 2 + this.container_y;
Drawing.txt_draw(x, y, x, y, x + 440, y + 260, 0xffffffff, text);
}
public int getStringWidth(String text) {
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, text);
return size.xpos / 2;
}
public void rect(int x, int y, int width, int height, int color) {
Drawing.drawRectColor(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | color);
}
public InventoryButton button(int x, int y, int w, int h) {
return this.add(new InventoryButton(this.container_x + x * 2, this.container_y + y * 2, w * 2, h * 2));
}
// public void uidims(int w, int h) {
// }
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
super.mouse(btn, x, y, ctrl, shift);
// public void click(Button btn, int x, int y) {
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
this.mouseClicked((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum
// }
}
public void mouserel(Button btn, int x, int y) {
super.mouserel(btn, x, y);
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
this.mouseReleased((x - this.container_x) / 2, (y - this.container_y) / 2, btn.ordinal()); //TODO: enum
// }
}
public void drag(int x, int y) {
super.drag(x, y);
// if(this.openGui != null) {
// int x = SKC.getMouseX() * this.openGui.width / this.gm.fb_x;
// int y = this.openGui.height - SKC.getMouseY() * this.openGui.height / this.gm.fb_y - 1;
if(Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown() || Button.MOUSE_MIDDLE.isDown())
this.mouseDragged((x - this.container_x) / 2, (y - this.container_y) / 2);
// }
}
public GuiContainer(Container inventorySlotsIn)
{
this.inventorySlots = inventorySlotsIn;
this.ignoreMouseUp = true;
}
public void init(int width, int height) {
this.itemRender = this.gm.getRenderItem();
this.tooltip = null;
// this.width = width;
// this.height = height;
// this.initialize(this.gm.getGame());
// this.container_x = this.container_y = this.container_w = this.container_h = 0;
this.container_x = (width - (this.container_w = (this.xSize * 2))) / 2;
this.container_y = (height - (this.container_h = (this.ySize * 2))) / 2;
this.initGui();
this.addButtons();
}
public void hover(String text, int x, int y) {
this.tooltip = text;
this.hover_x = x * 2 + this.container_x + 16;
this.hover_y = y * 2 + this.container_y + 16;
}
public String getTitle() {
return "Inventar";
}
// public int getXSize() {
// return this.xSize;
// }
//
// public int getYSize() {
// return this.ySize;
// }
// public final void initialize(Game gm) {
// }
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.gm.thePlayer.openContainer = this.inventorySlots;
// this.guiLeft = (this.width - this.xSize) / 2;
// this.guiTop = (this.height - this.ySize) / 2;
// this.addButtons();
}
public void addButtons() {
// this.uidims(this.xSize, this.ySize);
if(this.inventorySlots != null) {
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
this.button(slot.xDisplayPosition - 1, slot.yDisplayPosition - 1, 18, 18);
}
}
}
protected void drawSlots(int mouseX, int mouseY) {
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
{
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
this.drawSlot(slot);
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered())
{
this.theSlot = slot;
}
}
}
public void drawOverlays() {
for(Overlay overlay : this.drawnOverlays) {
this.renderItemOverlayIntoGUI(overlay.stack, overlay.x, overlay.y, overlay.alt);
}
this.drawnOverlays.clear();
if(this.tooltip != null)
Drawing.drawTextbox(this.tooltip, this.hover_x, this.hover_y, 0xaf000000);
this.tooltip = null;
}
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY)
{
if(this.gm == null)
return;
// this.drawGradientRect(0, 0, this.width, this.height, -1072689136, -804253680);
// int i = this.guiLeft;
// int j = this.guiTop;
// this.drawGuiContainerBackgroundLayer(mouseX, mouseY);
GlState.disableRescaleNormal();
ItemRenderer.disableStandardItemLighting();
GlState.disableLighting();
GlState.disableDepth();
// super.drawScreen(mouseX, mouseY, partialTicks);
ItemRenderer.enableGUIStandardItemLighting();
// SKC.glPushMatrix();
// SKC.glTranslatef((float)i, (float)j, 0.0F);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
GlState.enableRescaleNormal();
this.theSlot = null;
int k = 240;
int l = 240;
WCF.glMultiTexCoord2f(WCF.GL_TEXTURE1, (float)k / 1.0F, (float)l / 1.0F);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawSlots(mouseX, mouseY);
ItemRenderer.disableStandardItemLighting();
// this.drawGuiContainerForegroundLayer(mouseX, mouseY);
ItemRenderer.enableGUIStandardItemLighting();
InventoryPlayer inventoryplayer = this.gm.thePlayer.inventory;
ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack;
if (itemstack != null)
{
int j2 = 8;
int k2 = this.draggedStack == null ? 8 : 16;
String s = null;
if (this.draggedStack != null && this.isRightMouseClick)
{
itemstack = itemstack.copy();
itemstack.stackSize = ExtMath.ceilf((float)itemstack.stackSize / 2.0F);
}
else if (this.dragSplitting && this.dragSplittingSlots.size() > 1)
{
itemstack = itemstack.copy();
itemstack.stackSize = this.dragSplittingRemnant;
if (itemstack.stackSize == 0)
{
s = "" + TextColor.YELLOW + "0";
}
}
this.drawItemStack(itemstack, mouseX - j2, mouseY - k2, s);
}
if (this.returningStack != null)
{
float f = (float)(System.currentTimeMillis() - this.returningStackTime) / 100.0F;
if (f >= 1.0F)
{
f = 1.0F;
this.returningStack = null;
}
int l2 = this.returningStackDestSlot.xDisplayPosition - this.touchUpX;
int i3 = this.returningStackDestSlot.yDisplayPosition - this.touchUpY;
int l1 = this.touchUpX + (int)((float)l2 * f);
int i2 = this.touchUpY + (int)((float)i3 * f);
this.drawItemStack(this.returningStack, l1, i2, (String)null);
}
// SKC.glPopMatrix();
if (inventoryplayer.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack())
{
ItemStack itemstack1 = this.theSlot.getStack();
this.renderToolTip(itemstack1, mouseX, mouseY);
}
GlState.enableLighting();
GlState.enableDepth();
ItemRenderer.enableStandardItemLighting();
}
/**
* Render an ItemStack. Args : stack, x, y, format
*/
private void drawItemStack(ItemStack stack, int x, int y, String altText)
{
WCF.glTranslatef(0.0F, 0.0F, 32.0F);
// this.zLevel = 200.0F;
this.itemRender.zLevel = 200.0F;
this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
this.drawnOverlays.add(new Overlay(stack, x, y - (this.draggedStack == null ? 0 : 8), altText));
// this.zLevel = 0.0F;
this.itemRender.zLevel = 0.0F;
}
protected void renderToolTip(ItemStack stack, int x, int y) {
List<String> list = stack.getTooltip(this.gm.thePlayer);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < list.size(); ++i) {
if(i != 0)
sb.append("\n" + TextColor.LGRAY + (String)list.get(i));
else
sb.append((String)list.get(i));
}
this.hover(sb.toString(), x, y);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
}
public void drawGuiContainerBackgroundLayer() {
}
public void drawPost() {
WCF.glPushMatrix();
WCF.glTranslatef((this.gm.fb_x - this.xSize * 2) / 2, (this.gm.fb_y - this.ySize * 2) / 2, 0.0f);
// int k1 = SKC.getMouseX();
// int l1 = this.gm.fb_y - SKC.getMouseY() - 1;
WCF.glScalef(2.0f, 2.0f, 2.0f);
this.drawScreen((this.gm.mouse_x - this.container_x) / 2, (this.gm.mouse_y - this.container_y) / 2);
WCF.glPopMatrix();
ItemRenderer.disableStandardItemLighting();
// GlState.color(1.0f, 1.0f, 1.0f, 1.0f);
}
private void drawSlot(Slot slotIn)
{
int i = slotIn.xDisplayPosition;
int j = slotIn.yDisplayPosition;
ItemStack itemstack = slotIn.getStack();
boolean flag = false;
boolean flag1 = slotIn == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick;
ItemStack itemstack1 = this.gm.thePlayer.inventory.getItemStack();
String s = null;
if (slotIn == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null)
{
itemstack = itemstack.copy();
itemstack.stackSize /= 2;
}
else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && itemstack1 != null)
{
if (this.dragSplittingSlots.size() == 1)
{
return;
}
if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn))
{
itemstack = itemstack1.copy();
flag = true;
Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize);
if (itemstack.stackSize > itemstack.getMaxStackSize())
{
s = TextColor.YELLOW + ItemStack.formatAmount(itemstack.getMaxStackSize());
itemstack.stackSize = itemstack.getMaxStackSize();
}
if (itemstack.stackSize > slotIn.getItemStackLimit(itemstack))
{
s = TextColor.YELLOW + ItemStack.formatAmount(slotIn.getItemStackLimit(itemstack));
itemstack.stackSize = slotIn.getItemStackLimit(itemstack);
}
}
else
{
this.dragSplittingSlots.remove(slotIn);
this.updateDragSplitting();
}
}
// this.zLevel = 100.0F;
this.itemRender.zLevel = 100.0F;
// if (itemstack == null)
// {
// String s1 = slotIn.getSlotTexture();
//
// if (s1 != null)
// {
// TextureAtlasSprite sprite = this.gm.getTextureMapBlocks().getAtlasSprite(s1);
// GlState.disableLighting();
// this.gm.getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
// this.rectuv(i, j, 16, 16, sprite.getMinU(), sprite.getMinV(), sprite.getMaxU(), sprite.getMaxV());
// GlState.enableLighting();
// flag1 = true;
// }
// }
if (!flag1)
{
// if (flag)
// {
// drawRect(i, j, i + 16, j + 16, -2130706433);
// SKC.highlight(i, j, 16, 16);
// }
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j);
this.drawnOverlays.add(new Overlay(itemstack, i, j, s));
}
this.itemRender.zLevel = 0.0F;
// this.zLevel = 0.0F;
}
private void updateDragSplitting()
{
ItemStack itemstack = this.gm.thePlayer.inventory.getItemStack();
if (itemstack != null && this.dragSplitting)
{
this.dragSplittingRemnant = itemstack.stackSize;
for (Slot slot : this.dragSplittingSlots)
{
ItemStack itemstack1 = itemstack.copy();
int i = slot.getStack() == null ? 0 : slot.getStack().stackSize;
Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i);
if (itemstack1.stackSize > itemstack1.getMaxStackSize())
{
itemstack1.stackSize = itemstack1.getMaxStackSize();
}
if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1))
{
itemstack1.stackSize = slot.getItemStackLimit(itemstack1);
}
this.dragSplittingRemnant -= itemstack1.stackSize - i;
}
}
}
/**
* Returns the slot at the given coordinates or null if there is none.
*/
private Slot getSlotAtPosition(int x, int y)
{
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
{
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i);
if (this.isMouseOverSlot(slot, x, y))
{
return slot;
}
}
return null;
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
if(this.gm == null)
return;
// super.mouseClicked(mouseX, mouseY, mouseButton);
// boolean flag = mouseButton == this.gm.bindTertiary.getKeyCode() + 100;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
long i = System.currentTimeMillis();
this.doubleClick = this.lastClickSlot == slot && i - this.lastClickTime < 250L && this.lastClickButton == mouseButton;
this.ignoreMouseUp = false;
if (mouseButton == 0 || mouseButton == 1) // || flag)
{
// int j = this.guiLeft;
// int k = this.guiTop;
boolean flag1 = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
int l = -1;
if (slot != null)
{
l = slot.slotNumber;
}
if (flag1)
{
l = -999;
}
// if (this.gm.touchscreen && flag1 && this.gm.thePlayer.inventory.getItemStack() == null)
// {
// this.gm.displayGuiScreen((GuiScreen)null);
// return;
// }
if (l != -1)
{
// if (this.gm.touchscreen)
// {
// if (slot != null && slot.getHasStack())
// {
// this.clickedSlot = slot;
// this.draggedStack = null;
// this.isRightMouseClick = mouseButton == 1;
// }
// else
// {
// this.clickedSlot = null;
// }
// }
// else
if (!this.dragSplitting)
{
if (this.gm.thePlayer.inventory.getItemStack() == null)
{
// if (mouseButton == this.gm.bindTertiary.getKeyCode() + 100)
// {
// this.handleMouseClick(slot, l, mouseButton, 3);
// }
// else
// {
boolean flag2 = l != -999 && this.gm.shift();
int i1 = 0;
if (flag2)
{
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
i1 = 1;
}
else if (l == -999)
{
i1 = 4;
}
this.handleMouseClick(slot, l, mouseButton, i1);
// }
this.ignoreMouseUp = true;
}
else
{
this.dragSplitting = true;
this.dragSplittingButton = mouseButton;
this.dragSplittingSlots.clear();
if (mouseButton == 0)
{
this.dragSplittingLimit = 0;
}
else if (mouseButton == 1)
{
this.dragSplittingLimit = 1;
}
// else if (mouseButton == this.gm.bindTertiary.getKeyCode() + 100)
// {
// this.dragSplittingLimit = 2;
// }
}
}
}
}
this.lastClickSlot = slot;
this.lastClickTime = i;
this.lastClickButton = mouseButton;
}
/**
* Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
* lastButtonClicked & timeSinceMouseClick.
*/
public void mouseDragged(int mouseX, int mouseY)
{
if(this.gm == null)
return;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
ItemStack itemstack = this.gm.thePlayer.inventory.getItemStack();
// if (this.clickedSlot != null && this.gm.touchscreen)
// {
// if (clickedMouseButton == 0 || clickedMouseButton == 1)
// {
// if (this.draggedStack == null)
// {
// if (slot != this.clickedSlot && this.clickedSlot.getStack() != null)
// {
// this.draggedStack = this.clickedSlot.getStack().copy();
// }
// }
// else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false))
// {
// long i = this.gm.getSystemTime();
//
// if (this.currentDragTargetSlot == slot)
// {
// if (i - this.dragItemDropDelay > 500L)
// {
// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
// this.handleMouseClick(slot, slot.slotNumber, 1, 0);
// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0);
// this.dragItemDropDelay = i + 750L;
// --this.draggedStack.stackSize;
// }
// }
// else
// {
// this.currentDragTargetSlot = slot;
// this.dragItemDropDelay = i;
// }
// }
// }
// }
// else
if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot))
{
this.dragSplittingSlots.add(slot);
this.updateDragSplitting();
}
}
/**
* Called when a mouse button is released. Args : mouseX, mouseY, releaseButton
*/
public void mouseReleased(int mouseX, int mouseY, int state)
{
if(this.gm == null)
return;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
// int i = this.guiLeft;
// int j = this.guiTop;
boolean flag = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
int k = -1;
if (slot != null)
{
k = slot.slotNumber;
}
if (flag)
{
k = -999;
}
if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot((ItemStack)null, slot))
{
if (this.gm.shift())
{
if (slot != null && slot.inventory != null && this.shiftClickedSlot != null)
{
for (Slot slot2 : this.inventorySlots.inventorySlots)
{
if (slot2 != null && slot2.canTakeStack(this.gm.thePlayer) && slot2.getHasStack() && slot2.inventory == slot.inventory && Container.canAddItemToSlot(slot2, this.shiftClickedSlot, true))
{
this.handleMouseClick(slot2, slot2.slotNumber, state, 1);
}
}
}
}
else
{
this.handleMouseClick(slot, k, state, 6);
}
this.doubleClick = false;
this.lastClickTime = 0L;
}
else
{
if (this.dragSplitting && this.dragSplittingButton != state)
{
this.dragSplitting = false;
this.dragSplittingSlots.clear();
this.ignoreMouseUp = true;
return;
}
if (this.ignoreMouseUp)
{
this.ignoreMouseUp = false;
return;
}
// if (this.clickedSlot != null && this.gm.touchscreen)
// {
// if (state == 0 || state == 1)
// {
// if (this.draggedStack == null && slot != this.clickedSlot)
// {
// this.draggedStack = this.clickedSlot.getStack();
// }
//
// boolean flag2 = Container.canAddItemToSlot(slot, this.draggedStack, false);
//
// if (k != -1 && this.draggedStack != null && flag2)
// {
// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0);
// this.handleMouseClick(slot, k, 0, 0);
//
// if (this.gm.thePlayer.inventory.getItemStack() != null)
// {
// this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, 0);
// this.touchUpX = mouseX - i;
// this.touchUpY = mouseY - j;
// this.returningStackDestSlot = this.clickedSlot;
// this.returningStack = this.draggedStack;
// this.returningStackTime = this.gm.getSystemTime();
// }
// else
// {
// this.returningStack = null;
// }
// }
// else if (this.draggedStack != null)
// {
// this.touchUpX = mouseX - i;
// this.touchUpY = mouseY - j;
// this.returningStackDestSlot = this.clickedSlot;
// this.returningStack = this.draggedStack;
// this.returningStackTime = this.gm.getSystemTime();
// }
//
// this.draggedStack = null;
// this.clickedSlot = null;
// }
// }
// else
if (this.dragSplitting && !this.dragSplittingSlots.isEmpty())
{
this.handleMouseClick((Slot)null, -999, Container.func_94534_d(0, this.dragSplittingLimit), 5);
for (Slot slot1 : this.dragSplittingSlots)
{
this.handleMouseClick(slot1, slot1.slotNumber, Container.func_94534_d(1, this.dragSplittingLimit), 5);
}
this.handleMouseClick((Slot)null, -999, Container.func_94534_d(2, this.dragSplittingLimit), 5);
}
else if (this.gm.thePlayer.inventory.getItemStack() != null)
{
// if (state == this.gm.bindTertiary.getKeyCode() + 100)
// {
// this.handleMouseClick(slot, k, state, 3);
// }
// else
// {
boolean flag1 = k != -999 && this.gm.shift();
if (flag1)
{
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
}
this.handleMouseClick(slot, k, state, flag1 ? 1 : 0);
// }
}
}
if (this.gm.thePlayer.inventory.getItemStack() == null)
{
this.lastClickTime = 0L;
}
this.dragSplitting = false;
}
/**
* Returns if the passed mouse position is over the specified slot. Args : slot, mouseX, mouseY
*/
private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY)
{
return this.isPointInRegion(slotIn.xDisplayPosition, slotIn.yDisplayPosition, 16, 16, mouseX, mouseY);
}
/**
* Test if the 2D point is in a rectangle (relative to the GUI). Args : rectX, rectY, rectWidth, rectHeight, pointX,
* pointY
*/
protected boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY)
{
// int i = this.guiLeft;
// int j = this.guiTop;
// pointX = pointX - i;
// pointY = pointY - j;
return pointX >= left - 1 && pointX < left + right + 1 && pointY >= top - 1 && pointY < top + bottom + 1;
}
/**
* Called when the mouse is clicked over a slot or outside the gui.
*/
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType)
{
if (slotIn != null)
{
slotId = slotIn.slotNumber;
}
this.gm.controller.windowClick(this.inventorySlots.windowId, slotId, clickedButton, clickType, this.gm.thePlayer);
}
public void dropItem() {
if (this.gm != null && this.gm.thePlayer != null && this.theSlot != null && this.theSlot.getHasStack())
{
// if (keyCode == this.gm.bindTertiary.getKeyCode())
// {
// this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, 0, 3);
// }
// else
// if (keyCode == this.gm.keyBindDrop.getKeyCode())
// {
this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, this.gm.ctrl() ? 1 : 0, 4);
// }
}
}
// /**
// * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
// * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
// */
// protected void keyTyped(char typedChar, int keyCode)
// {
//// if (keyCode == 1 || keyCode == this.gm.keyBindInventory.getKeyCode())
//// {
//// this.gm.thePlayer.closeScreen();
//// }
//
// this.checkHotbarKeys(keyCode);
//
//
// }
/**
* This function is what controls the hotbar shortcut check when you press a number key when hovering a stack. Args
* : keyCode, Returns true if a Hotbar key is pressed, else false
*/
public void useHotbar(int slot)
{
if (this.gm != null && this.gm.thePlayer != null && this.gm.thePlayer.inventory.getItemStack() == null && this.theSlot != null)
{
// for (int i = 0; i < 9; ++i)
// {
// if (keyCode == this.gm.keyBindsHotbar[i].getKeyCode())
// {
this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, slot, 2);
// return true;
// }
// }
}
// return false;
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
if (this.gm != null && this.gm.thePlayer != null)
{
this.inventorySlots.onContainerClosed(this.gm.thePlayer);
}
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
// public boolean doesGuiPauseGame()
// {
// return false;
// }
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
// super.updateScreen();
if (this.gm != null && this.gm.thePlayer != null && (!this.gm.thePlayer.isEntityAlive() || this.gm.thePlayer.dead))
{
this.gm.thePlayer.closeScreen();
}
}
public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text)
{
renderItemOverlay(stack, this.container_x + xPosition * 2, this.container_y + yPosition * 2, text);
}
public static void renderItemOverlay(ItemStack stack, int xPosition, int yPosition, String text)
{
if (stack != null)
{
if (stack.stackSize != 1 || text != null)
{
String s = text == null ? ItemStack.formatAmount(stack.stackSize) : text;
if (text == null && stack.stackSize < 1)
{
s = TextColor.RED + ItemStack.formatAmount(stack.stackSize);
}
// this.drawString(s, , );
Vec2i size = Drawing.txt_size(0, 0, 0, 0, 65536, 65536, s);
int x = xPosition + 34 - size.xpos; // this.getStringWidth(s);
int y = yPosition + 17;
// x = x * 2 + this.container_x;
// y = y * 2 + this.container_y;
Drawing.txt_draw(x, y, x, y, x + 440, y + 260, 0xffffffff, s);
}
if (stack.isItemDamaged())
{
int j = (int)Math.round(28.0D - (double)stack.getItemDamage() * 28.0D / (double)stack.getMaxDamage());
int i = (int)Math.round(255.0D - (double)stack.getItemDamage() * 255.0D / (double)stack.getMaxDamage());
draw(xPosition + 2, yPosition + 26, 28, 4, 0, 0, 0);
draw(xPosition + 2, yPosition + 26, 26, 2, (255 - i) / 4, 64, 0);
draw(xPosition + 2, yPosition + 26, j, 2, 255 - i, i, 0);
}
}
}
private static void draw(int x, int y, int width, int height, int red, int green, int blue)
{
// Drawing.gfx_draw_rect_color(this.container_x + x * 2, this.container_y + y * 2, width * 2, height * 2, 0xff000000 | (red << 16) | (green << 8) | blue);
Drawing.drawRectColor(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue);
}
public void drawBackground() {
Drawing.drawRect2GradBorder(this.container_x, this.container_y, this.container_w, this.container_h, 0xff3f3f3f, 0xff000000, 0xff7f7f7f, 0xff4f4f4f, 0xff4f4f4f, 0xff1f1f1f);
}
}

View file

@ -0,0 +1,42 @@
package game.gui;
import game.inventory.ContainerWorkbench;
import game.inventory.InventoryPlayer;
import game.world.BlockPos;
import game.world.World;
public class GuiCrafting extends GuiContainer
{
// private static final String craftingTableGuiTextures = "textures/gui/crafting_table.png";
public GuiCrafting(InventoryPlayer playerInv, World worldIn)
{
this(playerInv, worldIn, BlockPos.ORIGIN);
}
public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition)
{
super(new ContainerWorkbench(playerInv, worldIn, blockPosition));
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString("Handwerk", 28, 6);
this.drawString("Inventar", 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(craftingTableGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,46 @@
package game.gui;
import game.inventory.ContainerDispenser;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
public class GuiDispenser extends GuiContainer
{
// private static final String dispenserGuiTextures = "textures/gui/dispenser.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
/** The inventory contained within the corresponding Dispenser. */
public IInventory dispenserInventory;
public GuiDispenser(InventoryPlayer playerInv, IInventory dispenserInv)
{
super(new ContainerDispenser(playerInv, dispenserInv));
this.playerInventory = playerInv;
this.dispenserInventory = dispenserInv;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.dispenserInventory.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(dispenserGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

290
java/src/game/gui/GuiEnchant.java Executable file
View file

@ -0,0 +1,290 @@
package game.gui;
import game.ExtMath;
import game.color.TextColor;
import game.enchantment.Enchantment;
import game.inventory.ContainerEnchantment;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.rng.Random;
import game.tileentity.IWorldNameable;
import game.world.World;
public class GuiEnchant extends GuiContainer
{
/** The ResourceLocation containing the Enchantment GUI texture location */
// private static final String ENCHANTMENT_TABLE_GUI_TEXTURE = "textures/gui/enchanting_table.png";
private static final String[] NAMES = "the elder scrolls klaatu berata niktu xyzzy bless curse light darkness fire air earth water hot dry cold wet ignite snuff embiggen twist shorten stretch fiddle destroy imbue galvanize enchant free limited range of towards inside sphere cube self other ball mental physical grow shrink demon elemental spirit animal creature beast humanoid undead fresh stale ".split(" ");
/** The player inventory currently bound to this GuiEnchantment instance. */
private final InventoryPlayer playerInventory;
private final Random nameRand = new Random();
private final Random random = new Random();
private final ContainerEnchantment container;
private final IWorldNameable table;
public int field_147073_u;
public float field_147071_v;
public float field_147069_w;
public float field_147082_x;
public float field_147081_y;
public float field_147080_z;
public float field_147076_A;
ItemStack field_147077_B;
public GuiEnchant(InventoryPlayer inventory, World worldIn, IWorldNameable table)
{
super(new ContainerEnchantment(inventory, worldIn));
this.playerInventory = inventory;
this.container = (ContainerEnchantment)this.inventorySlots;
this.table = table;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.table.getCommandName(), 12, 5);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
this.func_147068_g();
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
super.mouseClicked(mouseX, mouseY, mouseButton);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
for (int k = 0; k < 3; ++k)
{
int l = mouseX - 60;
int i1 = mouseY - (14 + 19 * k);
if (l >= 0 && i1 >= 0 && l < 108 && i1 < 19 && this.container.enchantItem(this.gm.thePlayer, k))
{
this.gm.controller.sendEnchantPacket(this.container.windowId, k);
}
}
}
public void addButtons() {
super.addButtons();
this.button(60, 14 + 19 * 0, 108, 19);
this.button(60, 14 + 19 * 1, 108, 19);
this.button(60, 14 + 19 * 2, 108, 19);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
this.nameRand.setSeed((long)this.container.xpSeed);
for (int l = 0; l < 3; ++l)
{
int i1 = 60;
int j1 = i1 + 20;
String s = this.getRandomName();
int l1 = this.container.enchantLevels[l];
if (l1 == 0)
{
this.rect(i1, 14 + 19 * l, 108, 19, 0x404040);
}
else
{
String s1 = "" + l1;
int i2 = 6839882;
if (/* (k < l + 1 || */ this.gm.thePlayer.experienceLevel < l1) // && !this.gm.thePlayer.creative)
{
this.rect(i1, 14 + 19 * l, 108, 19, 0x400000);
this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x200000);
this.drawString(s, j1, 16 + 19 * l); // , /*k1,*/ (i2 & 16711422) >> 1);
i2 = 4226832;
}
else
{
// int j2 = SKC.getMouseX() - this.guiLeft - 60;
// int k2 = SKC.getMouseY() - this.guiTop - (14 + 19 * l);
// if (j2 >= 0 && k2 >= 0 && j2 < 108 && k2 < 19)
// {
// this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20);
// i2 = 16777088;
// }
// else
// {
this.rect(i1, 14 + 19 * l, 108, 19, 0x20ff20);
// }
this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x008000);
this.drawString(s, j1, 16 + 19 * l);
i2 = 8453920;
}
this.drawString(s1, j1 + 86 - this.getStringWidth(s1), 16 + 19 * l + 7);
}
}
}
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY)
{
super.drawScreen(mouseX, mouseY);
// boolean flag = this.gm.thePlayer.creative;
// int i = this.container.getLapisAmount();
for (int j = 0; j < 3; ++j)
{
int k = this.container.enchantLevels[j];
int l = this.container.enchantmentIds[j];
int i1 = j + 1;
if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0)
{
StringBuilder sb = new StringBuilder();
if (l >= 0 && Enchantment.getEnchantmentById(l & 255) != null)
{
String s = Enchantment.getEnchantmentById(l & 255).getFormattedName((l & 65280) >> 8);
sb.append(TextColor.WHITE + s + " . . . ?");
}
// if (!flag)
// {
// if (l >= 0 && sb.length() != 0)
// {
// sb.append("\n");
// }
if (this.gm.thePlayer.experienceLevel < k)
{
sb.append((sb.length() != 0 ? "\n" : "") + TextColor.RED + String.format("Erfahrungsstufe %d erforderlich", this.container.enchantLevels[j]));
}
else
{
String s1 = "";
// if (i1 == 1)
// {
// s1 = I18n.format("container.enchant.lapis.one");
// }
// else
// {
// s1 = I18n.format("container.enchant.lapis.many", i1);
// }
//
// if (i >= i1)
// {
// list.add(ChatFormat.GRAY.toString() + "" + s1);
// }
// else
// {
// list.add(ChatFormat.RED.toString() + "" + s1);
// }
if (i1 == 1)
{
s1 = "1 Erfahrungsstufe";
}
else
{
s1 = String.format("%d Erfahrungsstufen", i1);
}
sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1);
}
// }
this.hover(sb.toString(), mouseX, mouseY);
break;
}
}
}
private String getRandomName()
{
int i = this.nameRand.zrange(2) + 3;
String s = "";
for (int j = 0; j < i; ++j)
{
if (j > 0)
{
s = s + " ";
}
String name = NAMES[this.nameRand.zrange(NAMES.length)];
for(int z = 0; z < name.length(); z++) {
s += (char)(name.charAt(z) - 0x61 + 0x80);
}
}
return s;
}
private void func_147068_g()
{
ItemStack itemstack = this.inventorySlots.getSlot(0).getStack();
if (!ItemStack.areItemStacksEqual(itemstack, this.field_147077_B))
{
this.field_147077_B = itemstack;
while (true)
{
this.field_147082_x += (float)(this.random.zrange(4) - this.random.zrange(4));
if (this.field_147071_v > this.field_147082_x + 1.0F || this.field_147071_v < this.field_147082_x - 1.0F)
{
break;
}
}
}
++this.field_147073_u;
this.field_147069_w = this.field_147071_v;
this.field_147076_A = this.field_147080_z;
boolean flag = false;
for (int i = 0; i < 3; ++i)
{
if (this.container.enchantLevels[i] != 0)
{
flag = true;
}
}
if (flag)
{
this.field_147080_z += 0.2F;
}
else
{
this.field_147080_z -= 0.2F;
}
this.field_147080_z = ExtMath.clampf(this.field_147080_z, 0.0F, 1.0F);
float f1 = (this.field_147082_x - this.field_147071_v) * 0.4F;
float f = 0.2F;
f1 = ExtMath.clampf(f1, -f, f);
this.field_147081_y += (f1 - this.field_147081_y) * 0.9F;
this.field_147071_v += this.field_147081_y;
}
}

View file

@ -0,0 +1,71 @@
package game.gui;
import game.inventory.ContainerFurnace;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
import game.tileentity.TileEntityFurnace;
public class GuiFurnace extends GuiContainer
{
// private static final String furnaceGuiTextures = "textures/gui/furnace.png";
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
private IInventory tileFurnace;
public GuiFurnace(InventoryPlayer playerInv, IInventory furnaceInv)
{
super(new ContainerFurnace(playerInv, furnaceInv));
this.playerInventory = playerInv;
this.tileFurnace = furnaceInv;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.tileFurnace.getCommandName();
this.drawString(s, 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
/**
* Args : renderPartialTicks, mouseX, mouseY
*/
public void drawGuiContainerBackgroundLayer()
{
this.rect(58, 36, 12, 14, 0x202020);
if (TileEntityFurnace.isBurning(this.tileFurnace))
{
int k = this.getBurnLeftScaled(13);
k = Math.min(k, 13);
this.rect(58, 36 + 13 - k, 12, k + 1, 0xff7f00);
}
int l = this.getCookProgressScaled(24);
this.rect(79, 39, 24, 8, 0x606060);
if(l > 0)
this.rect(79, 39, l + 1, 8, 0xffaf00);
}
private int getCookProgressScaled(int pixels)
{
int i = this.tileFurnace.getField(2);
int j = this.tileFurnace.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getBurnLeftScaled(int pixels)
{
int i = this.tileFurnace.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileFurnace.getField(0) * pixels / i;
}
}

View file

@ -0,0 +1,40 @@
package game.gui;
import game.ActButton;
import game.Gui;
import game.Label;
import game.color.TextColor;
import game.ActButton.Mode;
public class GuiGameOver extends Gui {
public static final GuiGameOver INSTANCE = new GuiGameOver();
private ActButton button;
private int timer;
private GuiGameOver() {
}
public void init(int width, int height) {
this.timer = 0;
this.add(new Label(0, 0, 200, 20, "Du bist gestorben!"));
this.add(new Label(0, 32, 200, 20, "Punktestand: " + TextColor.YELLOW + this.gm.thePlayer.experienceLevel));
this.button = this.add(new ActButton(0, 100, 200, 20, new ActButton.Callback() {
public void use(ActButton elem, Mode action) {
GuiGameOver.this.gm.thePlayer.respawnPlayer();
GuiGameOver.this.gm.displayGuiScreen(null);
}
}, "Wiederbeleben"));
this.shift();
this.button.enabled = false;
}
public String getTitle() {
return "Game over";
}
public void updateScreen() {
if(++this.timer >= 20)
this.button.enabled = true;
}
}

View file

@ -0,0 +1,49 @@
package game.gui;
import game.Game;
import game.inventory.ContainerHopper;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
public class GuiHopper extends GuiContainer
{
// /** The ResourceLocation containing the gui texture for the hopper */
// private static final String HOPPER_GUI_TEXTURE = "textures/gui/hopper.png";
/** The player inventory currently bound to this GUI instance */
private IInventory playerInventory;
/** The hopper inventory bound to this GUI instance */
private IInventory hopperInventory;
public GuiHopper(InventoryPlayer playerInv, IInventory hopperInv)
{
super(new ContainerHopper(playerInv, hopperInv, Game.getGame().thePlayer));
this.playerInventory = playerInv;
this.hopperInventory = hopperInv;
// this.allowUserInput = false;
this.ySize = 133;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.hopperInventory.getCommandName(), 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(HOPPER_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

79
java/src/game/gui/GuiHorse.java Executable file
View file

@ -0,0 +1,79 @@
package game.gui;
import game.Game;
import game.entity.animal.EntityHorse;
import game.inventory.ContainerHorseInventory;
import game.inventory.IInventory;
public class GuiHorse extends GuiContainer
{
// private static final String horseGuiTextures = "textures/gui/horse.png";
/** The player inventory bound to this GUI. */
private IInventory playerInventory;
/** The horse inventory bound to this GUI. */
private IInventory horseInventory;
// /** The EntityHorse whose inventory is currently being accessed. */
// private EntityHorse horseEntity;
// /** The mouse x-position recorded during the last rendered frame. */
// private float mousePosx;
//
// /** The mouse y-position recorded during the last renderered frame. */
// private float mousePosY;
public GuiHorse(IInventory playerInv, IInventory horseInv, EntityHorse horse)
{
super(new ContainerHorseInventory(playerInv, horseInv, horse, Game.getGame().thePlayer));
this.playerInventory = playerInv;
this.horseInventory = horseInv;
// this.horseEntity = horse;
// this.allowUserInput = false;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.horseInventory.getCommandName(), 8, 6);
this.drawString(this.playerInventory.getCommandName(), 8, this.ySize - 96 + 2);
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(horseGuiTextures);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//
//// if (this.horseEntity.isChested())
//// {
//// this.rect(i + 79, j + 17, 0, this.ySize, 90, 54);
//// }
//
//// if (this.horseEntity.canWearArmor())
//// {
//// this.rect(i + 7, j + 35, 0, this.ySize + 54, 18, 18);
//// }
//
//// GuiInventory.drawEntityOnScreen(i + 51, j + 60, 17, (float)(i + 51) - this.mousePosx, (float)(j + 75 - 50) - this.mousePosY, this.horseEntity);
// }
// /**
// * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
// */
// public void drawScreen(int mouseX, int mouseY)
// {
// this.mousePosx = (float)mouseX;
// this.mousePosY = (float)mouseY;
// super.drawScreen(mouseX, mouseY);
// }
}

View file

@ -0,0 +1,58 @@
package game.gui;
import game.entity.npc.EntityNPC;
public class GuiInventory extends GuiContainer
{
// private final GuiCheat cheat;
// private float oldMouseX;
// private float oldMouseY;
public GuiInventory(EntityNPC player)
{
super(player.inventoryContainer);
// this.allowUserInput = true;
// this.cheat = cheat;
}
// public void updateScreen()
// {
// this.updateActivePotionEffects();
// }
// public void initGui()
// {
//// this.buttonList.clear();
// super.initGui();
// if(this.cheat != null)
// this.buttonList.add(new Button(1, this.guiLeft + this.xSize - 16, this.guiTop + 4, 12, 12, "X"));
// }
public void drawGuiContainerForegroundLayer()
{
this.drawString("Handwerk", 86, 16);
}
// public void drawScreen(int mouseX, int mouseY, float partialTicks)
// {
// super.drawScreen(mouseX, mouseY, partialTicks);
// this.oldMouseX = (float)mouseX;
// this.oldMouseY = (float)mouseY;
// }
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(inventoryBackground);
// int i = this.guiLeft;
// int j = this.guiTop;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// drawEntityOnScreen(i + 51, j + 75, 30, (float)(i + 51) - this.oldMouseX, (float)(j + 75 - 50) - this.oldMouseY, this.gm.thePlayer);
// }
// public void actionPerformed(int button)
// {
// if(button == 1 && this.cheat != null && this.gm.thePlayer.inventory.getItemStack() == null)
// this.gm.displayGuiScreen(this.cheat);
// }
}

407
java/src/game/gui/GuiList.java Executable file
View file

@ -0,0 +1,407 @@
package game.gui;
import java.util.List;
import game.Button;
import game.Drawing;
import game.ExtMath;
import game.Gui;
import game.collect.Lists;
import game.renderer.DefaultVertexFormats;
import game.renderer.GlState;
import game.renderer.Tessellator;
import game.renderer.RenderBuffer;
public abstract class GuiList<T extends ListEntry> extends Gui
{
protected final List<T> elements = Lists.newArrayList();
protected int width;
protected int height;
protected int top;
protected int bottom;
protected int right;
protected int left;
protected int mouseX;
protected int mouseY;
protected int initialClickY = -2;
protected float scrollMultiplier;
protected float amountScrolled;
protected int selectedElement = -1;
protected long lastClicked;
public abstract int getListWidth(); // 220
public abstract int getSlotHeight();
protected int getScrollBarX()
{
return 0;
}
public void setDimensions(int widthIn, int heightIn, int topIn, int bottomIn)
{
this.width = widthIn;
this.height = heightIn;
this.top = topIn;
this.bottom = bottomIn;
this.left = 0;
this.right = widthIn;
}
public void init(int width, int height) {
this.selectedElement = -1;
}
public void setSlotXBoundsFromLeft(int leftIn)
{
this.left = leftIn;
this.right = leftIn + this.width;
}
public final T getListEntry(int index) {
return this.elements.get(index);
}
public final T getSelected() {
return this.selectedElement < 0 ? null : this.elements.get(this.selectedElement);
}
public final int getSize() {
return this.elements.size();
}
protected int getContentHeight()
{
return this.getSize() * this.getSlotHeight();
}
public int getSlotIndexFromScreenCoords(int x, int y)
{
int i = this.left + this.width / 2 - this.getListWidth() / 2;
int j = this.left + this.width / 2 + this.getListWidth() / 2;
int k = y - this.top + (int)this.amountScrolled - 4;
int l = k / this.getSlotHeight();
return this.isInList(x, y) && x >= i && x <= j && l >= 0 && k >= 0 && l < this.getSize() ? l : -1;
}
protected boolean isInList(int x, int y)
{
return x >= this.getScrollBarX() + 6; // x < this.getScrollBarX();
}
protected final boolean isSelected(int slotIndex)
{
return slotIndex == this.selectedElement;
}
protected void bindAmountScrolled()
{
this.amountScrolled = ExtMath.clampf(this.amountScrolled, 0.0F, (float)this.getMaxScroll());
}
public int getMaxScroll()
{
return Math.max(0, this.getContentHeight() - (this.bottom - this.top - 4));
}
public int getAmountScrolled()
{
return (int)this.amountScrolled;
}
public boolean isMouseYWithinSlotBounds(int p_148141_1_)
{
return p_148141_1_ >= this.top && p_148141_1_ <= this.bottom && this.mouseX >= this.left && this.mouseX <= this.right;
}
public void scrollBy(int amount)
{
this.amountScrolled += (float)amount;
this.bindAmountScrolled();
this.initialClickY = -2;
}
// public void actionPerformed(Button button)
// {
// if (button.enabled)
// {
// if (button.id == this.scrollUpButtonID)
// {
// this.amountScrolled -= (float)(this.slotHeight * 2 / 3);
// this.initialClickY = -2;
// this.bindAmountScrolled();
// }
// else if (button.id == this.scrollDownButtonID)
// {
// this.amountScrolled += (float)(this.slotHeight * 2 / 3);
// this.initialClickY = -2;
// this.bindAmountScrolled();
// }
// }
// }
public void draw()
{
int mouseXIn = this.gm.mouse_x;
int mouseYIn = this.gm.mouse_y;
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlState.disableLighting();
GlState.disableFog();
GlState.enableTexture2D();
RenderBuffer worldrenderer = Tessellator.getBuffer();
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)this.left, (double)this.bottom, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)this.right, (double)this.bottom, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)this.right, (double)this.top, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
worldrenderer.pos((double)this.left, (double)this.top, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
Tessellator.draw();
int x = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int y = this.top + 4 - (int)this.amountScrolled;
this.drawSelectionBox(x, y, mouseXIn, mouseYIn);
GlState.disableDepth();
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
GlState.enableBlend();
GlState.tryBlendFuncSeparate(770, 771, 0, 1);
GlState.disableAlpha();
GlState.shadeModel(7425);
GlState.disableTexture2D();
int i1 = 4;
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)this.left, (double)(this.top + i1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)this.right, (double)(this.top + i1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)this.right, (double)(this.bottom - i1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
worldrenderer.pos((double)this.left, (double)(this.bottom - i1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
Tessellator.draw();
int j1 = this.getMaxScroll();
if (j1 > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = ExtMath.clampi(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
if (l1 < this.top)
{
l1 = this.top;
}
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
worldrenderer.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
Tessellator.draw();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
worldrenderer.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
worldrenderer.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
Tessellator.draw();
}
GlState.enableTexture2D();
GlState.shadeModel(7424);
GlState.enableAlpha();
GlState.disableBlend();
super.draw();
}
public void handleMouseInput()
{
if (this.isMouseYWithinSlotBounds(this.mouseY))
{
// if (Button.MOUSE_LEFT.isDown() && this.getEnabled())
// {
if (this.initialClickY == -1)
{
boolean flag1 = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom)
{
int j2 = (this.width - this.getListWidth()) / 2;
int k2 = (this.width + this.getListWidth()) / 2;
int l2 = this.mouseY - this.top + (int)this.amountScrolled - 4;
int i1 = l2 / this.getSlotHeight();
if (i1 < this.getSize() && this.mouseX >= j2 && this.mouseX <= k2 && i1 >= 0 && l2 >= 0)
{
}
else if (this.mouseX >= j2 && this.mouseX <= k2 && l2 < 0)
{
flag1 = false;
}
int i3 = this.getScrollBarX();
int j1 = i3 + 6;
if (this.mouseX >= i3 && this.mouseX <= j1)
{
this.scrollMultiplier = -1.0F;
int k1 = this.getMaxScroll();
if (k1 < 1)
{
k1 = 1;
}
int l1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
l1 = ExtMath.clampi(l1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float)(this.bottom - this.top - l1) / (float)k1;
}
else
{
this.scrollMultiplier = 1.0F;
}
if (flag1)
{
this.initialClickY = this.mouseY;
}
else
{
this.initialClickY = -2;
}
}
else
{
this.initialClickY = -2;
}
}
else if (this.initialClickY >= 0)
{
this.amountScrolled -= (float)(this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = this.mouseY;
}
// }
// else
// {
// this.initialClickY = -1;
// }
}
}
protected void drawSelectionBox(int x, int y, int mouseXIn, int mouseYIn)
{
int size = this.getSize();
RenderBuffer rb = Tessellator.getBuffer();
for (int z = 0; z < size; z++)
{
int y1 = y + z * this.getSlotHeight();
int h = this.getSlotHeight() - 4;
if (this.isSelected(z))
{
int x1 = this.left + (this.width / 2 - this.getListWidth() / 2);
int x2 = this.left + this.width / 2 + this.getListWidth() / 2;
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
GlState.disableTexture2D();
rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
rb.pos((double)x1, (double)(y1 + h + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x2, (double)(y1 + h + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x2, (double)(y1 - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)x1, (double)(y1 - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
rb.pos((double)(x1 + 1), (double)(y1 + h + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x2 - 1), (double)(y1 + h + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x2 - 1), (double)(y1 - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
rb.pos((double)(x1 + 1), (double)(y1 - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
Tessellator.draw();
GlState.enableTexture2D();
}
boolean hover = this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == z;
this.getListEntry(z).draw(x, y1, mouseXIn - x, mouseYIn - y1, hover);
if(hover)
Drawing.drawRectColor(x - 2, y1 - 2, this.getListWidth(), this.getSlotHeight(), this.gm.style.hover);
}
}
protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha)
{
RenderBuffer rb = Tessellator.getBuffer();
this.gm.getTextureManager().bindTexture(Gui.DIRT_BACKGROUND);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
rb.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
rb.pos((double)this.left, (double)endY, 0.0D).tex(0.0D, (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
rb.pos((double)(this.left + this.width), (double)endY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
rb.pos((double)(this.left + this.width), (double)startY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
rb.pos((double)this.left, (double)startY, 0.0D).tex(0.0D, (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
Tessellator.draw();
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift)
{
super.mouse(btn, x, y, ctrl, shift);
if (this.isMouseYWithinSlotBounds(y))
{
int i = this.getSlotIndexFromScreenCoords(x, y);
if (i >= 0)
{
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int k = this.top + 4 - this.getAmountScrolled() + i * this.getSlotHeight();
int l = x - j;
int i1 = y - k;
boolean flag = i == this.selectedElement && System.currentTimeMillis() - this.lastClicked < (long)this.gm.dclickDelay;
this.selectedElement = i;
this.lastClicked = System.currentTimeMillis();
this.getListEntry(i).select(flag, l, i1);
}
}
if(btn == Button.MOUSE_LEFT && this.clicked(x, y) == null)
this.handleMouseInput();
}
public void mouserel(Button btn, int x, int y) {
super.mouserel(btn, x, y);
if(btn == Button.MOUSE_LEFT)
this.initialClickY = -1;
}
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);
if(scr_y != 0 && this.clicked(x, y) == null)
this.amountScrolled -= (float)(ExtMath.clampi(scr_y, -1, 1) * this.getSlotHeight() / 2);
}
public void drag(int x, int y) {
super.drag(x, y);
if(this.selected == null && Button.MOUSE_LEFT.isDown())
this.handleMouseInput();
}
}

View file

@ -0,0 +1,44 @@
package game.gui;
import game.Game;
import game.inventory.ContainerMachine;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
import game.tileentity.TileEntityMachine;
public class GuiMachine extends GuiContainer
{
// private final String texture;
private final IInventory playerInv;
private final IInventory machineInv;
private final TileEntityMachine machine;
public GuiMachine(InventoryPlayer player, IInventory inv, TileEntityMachine machine)
{
super(new ContainerMachine(player, machine, inv, Game.getGame().thePlayer));
this.playerInv = player;
this.machineInv = machine;
// this.allowUserInput = false;
this.ySize = 153;
// this.texture = "textures/gui/" + texture + ".png";
this.machine = machine;
}
public void drawGuiContainerForegroundLayer()
{
this.drawString(this.machine.getStatus().color + this.machineInv.getCommandName() + " - " + this.machine.getStatus().name, 8, 6);
this.drawString(this.playerInv.getCommandName(), 8, this.ySize - 96 + 2);
this.drawString(String.format("Temperatur: %d °", this.machine.getTemperature()), 8, 18);
this.drawString(this.machine.formatDisplay(), 8, 28);
}
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(this.texture);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
// }
}

View file

@ -0,0 +1,286 @@
package game.gui;
import game.WCF;
import game.inventory.ContainerMerchant;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.packet.CPacketAction;
import game.renderer.GlState;
import game.renderer.ItemRenderer;
import game.village.MerchantRecipe;
import game.village.MerchantRecipeList;
import game.world.World;
public class GuiMerchant extends GuiContainer
{
// private static final String MERCHANT_GUI_TEXTURE = "textures/gui/trading.png";
private int selectedMerchantRecipe;
private String chatComponent;
public GuiMerchant(InventoryPlayer inv, String name, World worldIn)
{
super(new ContainerMerchant(inv, null, worldIn));
this.chatComponent = name != null ? name : "NSC";
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
// public void initGui()
// {
// super.initGui();
// }
public void addButtons() {
super.addButtons();
this.button(120 + 27, 24, 12, 16);
this.button(36 - 19, 24, 12, 16);
this.button(36 - 1, 24 - 1, 18, 18);
this.button(62 - 1, 24 - 1, 18, 18);
this.button(120 - 1, 24 - 1, 18, 18);
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
if (mouseButton == 0)
{
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
if(mouseX >= 147 && mouseX < 147 + 12 && mouseY >= 24 && mouseY < 24 + 16) {
this.switchTrade(true);
return;
}
else if(mouseX >= 17 && mouseX < 17 + 12 && mouseY >= 24 && mouseY < 24 + 16) {
this.switchTrade(false);
return;
}
// this.buttonList.add(new Button(1, i + 120 + 27, j + 24 - 1, 12, 19, ">"));
// this.buttonList.add(new Button(2, i + 36 - 19, j + 24 - 1, 12, 19, "<"));
}
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
String s = this.chatComponent;
this.drawString(s, 8, 6);
this.drawString("Inventar", 8, this.ySize - 96 + 2);
}
public void drawOverlays() {
super.drawOverlays();
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && !merchantrecipelist.isEmpty()) {
int k = this.selectedMerchantRecipe;
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
ItemStack itemstack = merchantrecipe.getItemToBuy();
ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy();
ItemStack itemstack2 = merchantrecipe.getItemToSell();
this.renderItemOverlayIntoGUI(itemstack, 36, 24, null);
if(itemstack1 != null)
this.renderItemOverlayIntoGUI(itemstack1, 62, 24, null);
this.renderItemOverlayIntoGUI(itemstack2, 120, 24, null);
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
public void switchTrade(boolean forward)
{
boolean flag = false;
if (forward)
{
++this.selectedMerchantRecipe;
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && this.selectedMerchantRecipe >= merchantrecipelist.size())
{
this.selectedMerchantRecipe = merchantrecipelist.size() - 1;
}
flag = true;
}
else
{
--this.selectedMerchantRecipe;
if (this.selectedMerchantRecipe < 0)
{
this.selectedMerchantRecipe = 0;
}
flag = true;
}
if (flag)
{
((ContainerMerchant)this.inventorySlots).setCurrentRecipeIndex(this.selectedMerchantRecipe);
// PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
// packetbuffer.writeInt(this.selectedMerchantRecipe);
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_TRADE,
this.selectedMerchantRecipe));
}
}
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.gm.thePlayer);
//
//// if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
//// {
//// int k = this.selectedMerchantRecipe;
////
//// if (k < 0 || k >= merchantrecipelist.size())
//// {
//// return;
//// }
//
//// MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
//
//// if (merchantrecipe.isRecipeDisabled())
//// {
//// this.gm.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
//// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
//// GlState.disableLighting();
//// this.rect(this.guiLeft + 83, this.guiTop + 21, 212, 0, 28, 21);
//// this.rect(this.guiLeft + 83, this.guiTop + 51, 212, 0, 28, 21);
//// }
//// }
// }
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
public void drawScreen(int mouseX, int mouseY)
{
super.drawScreen(mouseX, mouseY);
MerchantRecipeList merchantrecipelist = this.getRecipes();
if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
{
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
int k = this.selectedMerchantRecipe;
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
ItemStack itemstack = merchantrecipe.getItemToBuy();
ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy();
ItemStack itemstack2 = merchantrecipe.getItemToSell();
WCF.glPushMatrix();
ItemRenderer.enableGUIStandardItemLighting();
GlState.disableLighting();
GlState.enableRescaleNormal();
GlState.enableColorMaterial();
GlState.enableLighting();
this.itemRender.zLevel = 100.0F;
this.itemRender.renderItemAndEffectIntoGUI(itemstack, 36, 24);
// this.itemRender.renderItemOverlays(itemstack, 36, 24);
if (itemstack1 != null)
{
this.itemRender.renderItemAndEffectIntoGUI(itemstack1, 62, 24);
// this.itemRender.renderItemOverlays(itemstack1, 62, 24);
}
this.itemRender.renderItemAndEffectIntoGUI(itemstack2, 120, 24);
// this.itemRender.renderItemOverlays(itemstack2, 120, 24);
this.itemRender.zLevel = 0.0F;
GlState.disableLighting();
if (this.isPointInRegion(36, 24, 16, 16, mouseX, mouseY) && itemstack != null)
{
this.renderToolTip(itemstack, mouseX, mouseY);
}
else if (itemstack1 != null && this.isPointInRegion(62, 24, 16, 16, mouseX, mouseY) && itemstack1 != null)
{
this.renderToolTip(itemstack1, mouseX, mouseY);
}
else if (itemstack2 != null && this.isPointInRegion(120, 24, 16, 16, mouseX, mouseY) && itemstack2 != null)
{
this.renderToolTip(itemstack2, mouseX, mouseY);
}
// else if (merchantrecipe.isRecipeDisabled() && (this.isPointInRegion(83, 21, 28, 21, mouseX, mouseY) || this.isPointInRegion(83, 51, 28, 21, mouseX, mouseY)))
// {
// this.drawCreativeTabHoveringText(I18n.format("merchant.deprecated"), mouseX, mouseY);
// }
WCF.glPopMatrix();
GlState.enableLighting();
GlState.enableDepth();
ItemRenderer.enableStandardItemLighting();
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
// if(mouseX >= i + 147 && mouseX < i + 147 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) {
// SKC.highlight(i + 147, j + 23, 12, 19);
// }
// else if(mouseX >= i + 17 && mouseX < i + 17 + 12 && mouseY >= j + 23 && mouseX < j + 23 + 19) {
// SKC.highlight(i + 17, j + 23, 12, 19);
// }
}
}
public void setRecipes(MerchantRecipeList recipes)
{
((ContainerMerchant)this.inventorySlots).getMerchantInventory().setRecipes(recipes);
}
private MerchantRecipeList getRecipes()
{
return ((ContainerMerchant)this.inventorySlots).getMerchantInventory().getRecipes();
}
// static class MerchantButton extends Button
// {
// private final boolean next;
//
// public MerchantButton(int buttonID, int x, int y, boolean isNext)
// {
// super(buttonID, x, y, 12, 19, "");
// this.next = isNext;
// }
//
// public void drawButton(Game gm, int mouseX, int mouseY)
// {
// if (this.visible)
// {
// gm.getTextureManager().bindTexture(GuiMerchant.MERCHANT_GUI_TEXTURE);
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
// int i = 0;
// int j = 176;
//
// if (!this.enabled)
// {
// j += this.width * 2;
// }
// else if (flag)
// {
// j += this.width;
// }
//
// if (!this.next)
// {
// i += this.height;
// }
//
// this.rect(this.xPosition, this.yPosition, j, i, this.width, this.height);
// }
// }
// }
}

218
java/src/game/gui/GuiRepair.java Executable file
View file

@ -0,0 +1,218 @@
package game.gui;
import java.util.List;
import game.Game;
import game.inventory.Container;
import game.inventory.ContainerRepair;
import game.inventory.ICrafting;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.world.World;
public class GuiRepair extends GuiContainer implements ICrafting
{
// private static final String anvilResource = "textures/gui/anvil.png";
private ContainerRepair anvil;
// private TextField nameField;
private InventoryPlayer playerInventory;
public GuiRepair(InventoryPlayer inventoryIn, World worldIn)
{
super(new ContainerRepair(inventoryIn, worldIn, Game.getGame().thePlayer));
this.playerInventory = inventoryIn;
this.anvil = (ContainerRepair)this.inventorySlots;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
// Keyboard.enableRepeatEvents(true);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
// this.nameField = new TextField(i + 62, j + 24, 103, 12);
// this.nameField.setTextColor(-1);
// this.nameField.setDisabledTextColour(-1);
// this.nameField.setEnableBackgroundDrawing(false);
// this.nameField.setMaxStringLength(30);
this.inventorySlots.removeCraftingFromCrafters(this);
this.inventorySlots.onCraftGuiOpened(this);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
super.onGuiClosed();
// Keyboard.enableRepeatEvents(false);
this.inventorySlots.removeCraftingFromCrafters(this);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
*/
public void drawGuiContainerForegroundLayer()
{
// GlState.disableLighting();
// GlState.disableBlend();
this.drawString("Amboss", 60, 6);
if (this.anvil.maximumCost > 0)
{
int i = 8453920;
boolean flag = true;
String s = String.format("Erfahrungskosten: %d", this.anvil.maximumCost);
if (this.anvil.maximumCost >= 40) // && !this.gm.thePlayer.creative)
{
s = "Zu teuer!";
i = 16736352;
}
else if (!this.anvil.getSlot(2).getHasStack())
{
flag = false;
}
else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player))
{
i = 16736352;
}
if (flag)
{
int j = -16777216 | (i & 16579836) >> 2 | i & -16777216;
int k = this.xSize - 8 - this.getStringWidth(s);
int l = 67;
// if (FontRenderer.getUnicodeFlag())
// {
// drawRect(k - 3, l - 2, this.xSize - 7, l + 10, -16777216);
// drawRect(k - 2, l - 1, this.xSize - 8, l + 9, -12895429);
// }
// else
// {
this.drawString(s, k, l + 1);
this.drawString(s, k + 1, l);
this.drawString(s, k + 1, l + 1);
// }
this.drawString(s, k, l);
}
}
// GlState.enableLighting();
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
// protected void keyTyped(char typedChar, int keyCode)
// {
// if (this.nameField.textboxKeyTyped(typedChar, keyCode))
//// {
// this.renameItem();
//// }
//// else
//// {
//// super.keyTyped(typedChar, keyCode);
//// }
// }
//
// private void renameItem()
// {
// String s = this.nameField.getText();
// Slot slot = this.anvil.getSlot(0);
//
// if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
// {
// s = "";
// }
//
// this.anvil.updateItemName(s);
// this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.ITEM, s));
// }
//
// /**
// * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
// */
// protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
// {
// super.mouseClicked(mouseX, mouseY, mouseButton);
// this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
// }
/**
* Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
*/
// public void drawScreen(int mouseX, int mouseY, float partialTicks)
// {
// super.drawScreen(mouseX, mouseY, partialTicks);
// GlState.disableLighting();
// GlState.disableBlend();
// this.nameField.drawTextBox();
// }
// /**
// * Args : renderPartialTicks, mouseX, mouseY
// */
// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY)
// {
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// this.gm.getTextureManager().bindTexture(anvilResource);
// int i = (this.width - this.xSize) / 2;
// int j = (this.height - this.ySize) / 2;
//// this.rect(i, j, 0, 0, this.xSize, this.ySize);
//// this.rect(i + 59, j + 20, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
//
//// if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack())
//// {
//// this.rect(i + 99, j + 45, this.xSize, 0, 28, 21);
//// }
// }
/**
* update the crafting window inventory with the items in the list
*/
public void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList)
{
this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack());
}
/**
* Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
* contents of that slot. Args: Container, slot number, slot contents
*/
public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
{
// if (slotInd == 0)
// {
// this.nameField.setText(stack == null ? "" : stack.getDisplayName());
// this.nameField.setEnabled(stack != null);
//
// if (stack != null)
// {
// this.renameItem();
// }
// }
}
/**
* Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
* and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
* value. Both are truncated to shorts in non-local SMP.
*/
public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue)
{
}
public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_)
{
}
}

728
java/src/game/gui/GuiSkin.java Executable file
View file

@ -0,0 +1,728 @@
package game.gui;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import javax.imageio.ImageIO;
import game.Game;
import game.audio.SoundManager;
import game.collect.Lists;
import game.collect.Sets;
import game.entity.npc.Alignment;
import game.entity.npc.CharacterInfo;
import game.entity.npc.EntityNPC;
import game.entity.npc.ModelPart;
import game.entity.npc.SpeciesInfo;
import game.gui.element.Button;
import game.gui.element.Slider;
import game.gui.element.TextField;
import game.gui.element.Slider.SliderReceiver;
import game.gui.inventory.GuiInventory;
import game.init.EntityRegistry;
import game.init.SpeciesRegistry;
import game.init.SpeciesRegistry.ModelType;
import game.io.FileUtils;
import game.io.Log;
import game.lib.input.Keyboard;
import game.network.NetHandlerPlayServer;
import game.packet.CPacketAction;
import game.packet.CPacketMessage;
import game.renderer.FontRenderer;
import game.renderer.GlState;
import game.renderer.texture.DynamicTexture;
import game.renderer.texture.EntityTexManager;
import game.renderer.texture.TextureUtil;
import game.util.Predicate;
public class GuiSkin extends GuiScreen
{
private static class SkinEntry implements GuiListExtended.IGuiListEntry
{
private static final String SKINS_BUTTONS = "textures/gui/server_selection.png";
private final GuiSkin owner;
private final Game gm;
private final File skinFile;
private final String id;
private final ModelType model;
private final CharacterInfo charinfo;
private final BufferedImage skinImage;
private final String icon;
private DynamicTexture dyntex;
private long clickTime;
protected SkinEntry(GuiSkin parent, String id, File file, CharacterInfo charinfo, BufferedImage image, ModelType model)
{
this.owner = parent;
this.skinFile = file;
this.charinfo = charinfo;
this.id = id;
this.model = model;
this.gm = Game.getGame();
if(this.skinFile != null) // {
this.skinImage = image;
// this.skin = skin.getName().substring(0, skin.getName().length() - 4);
// }
else // {
this.skinImage = null;
// this.skin = null;
// }
if(this.skinImage != null) {
this.icon = "skins/" + this.id + "/icon";
this.dyntex = new DynamicTexture(this.skinImage);
this.gm.getTextureManager().loadTexture(this.icon, this.dyntex);
}
else {
this.icon = null;
this.dyntex = null;
}
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected)
{
// FontRenderer.drawString(this.skin == null ? "---" : this.skin, x + 32 + 3, y + 1, 16777215);
List<String> list = FontRenderer.listFormattedStringToWidth((this.skinFile != null ? this.skinFile.getName()
: (this.charinfo == null ? "Standard" : (
(this.charinfo.species.prefix && this.charinfo.spclass != null && this.charinfo.spclass.type != null ?
this.charinfo.spclass.type.toString() :
EntityRegistry.getEntityName(this.charinfo.species.id))
+ (this.charinfo.name.isEmpty() ? "" : (" " + this.charinfo.name)) + " (" + this.charinfo.skin + ")")))
// + TextColor.LIGHT_GRAY + " (" + TextColor.GREEN +
// this.model.display + TextColor.LIGHT_GRAY +")"
, listWidth - 16 - 2);
for (int i = 0; i < Math.min(list.size(), 2); ++i)
{
FontRenderer.drawString((String)list.get(i), x + 16 + 3, y + FontRenderer.FONT_HEIGHT * i, this.charinfo == null ?
(this.skinFile != null ? 0xffffff : 0xc0c0c0) : this.charinfo.color1 | this.charinfo.color2);
}
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
// if(this.model != ModelType.HUMANOID) {
// this.drawTextureAt(x, y, EntitySkinManager.HEAD_DEF);
// }
if (this.dyntex != null)
{
this.drawTextureAt(x, y, this.icon);
}
else if(this.charinfo == null)
{
this.drawTextureAt(x, y, EntityTexManager.getDefault(this.model));
}
else
{
this.drawTextureAt(x, y, EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ?
this.charinfo.skin.substring(1) : this.charinfo.skin));
}
if (/* this.gm.touchscreen || */ isSelected)
{
this.gm.getTextureManager().bindTexture(SKINS_BUTTONS);
Gui.drawRect(x, y, x + 16, y + 16, -1601138544);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
int k1 = mouseX - x;
int l1 = mouseY - y;
if (k1 < 16 && k1 > 0)
{
Gui.drawScaledCustomSizeModalRect(x, y, 0.0F, 32.0F, 32, 32, 16, 16, 256.0F, 256.0F);
}
}
}
protected void drawTextureAt(int x, int y, String tex)
{
this.gm.getTextureManager().bindTexture(tex);
GlState.enableBlend();
this.gm.getRenderManager().getRenderObject(this.model).renderHead(x, y, this.model.texWidth, this.model.texHeight, 2);
GlState.disableBlend();
}
public void deleteTexture() {
if(this.dyntex != null) {
this.gm.getTextureManager().deleteTexture(this.icon);
this.dyntex = null;
}
}
/**
* Returns true if the mouse has been pressed on this control.
*/
public boolean mousePressed(int slotIndex, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_)
{
if (Game.getSystemTime() - this.clickTime < 250L)
{
this.owner.close();
return true;
}
else {
BufferedImage img = this.skinImage;
boolean slim = false;
if(this.charinfo != null) {
try {
img = TextureUtil.readImage(FileUtils.getStream(
EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) :
this.charinfo.skin)));
}
catch(IOException e) {
if(e instanceof FileNotFoundException)
Log.warn("Textur für Skin ist nicht vorhanden: " +
EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) :
this.charinfo.skin));
else
Log.error("Konnte Textur nicht laden", e);
return false;
}
slim = this.charinfo.skin.startsWith("~");
}
else if(this.skinFile != null) {
slim = this.skinFile.getName().startsWith("slim_");
}
this.owner.selectEntry(slotIndex, slim);
this.owner.selectSkin(this.id, img, slim, this.model);
if(p_148278_5_ < 16 && p_148278_5_ > 0)
this.owner.close();
this.clickTime = Game.getSystemTime();
return false;
}
}
public File getFile()
{
return this.skinFile;
}
public boolean canConvert()
{
return this.skinFile != null && this.model == ModelType.HUMANOID;
}
public String getLocation()
{
return this.charinfo == null ? null : (this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) : this.charinfo.skin);
}
public boolean canCopy()
{
return this.charinfo != null;
}
}
private static class SkinSelector extends GuiListExtended
{
private final GuiSkin owner;
private final List<SkinEntry> skinList = Lists.<SkinEntry>newArrayList();
private int selectedSlotIndex = -1;
public SkinSelector(GuiSkin ownerIn, ModelType model, String currentSkin, Game gmIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(gmIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.owner = ownerIn;
// this.setBackgroundDrawing(false);
this.load(currentSkin, model);
}
public static BufferedImage loadSkin(File file)
{
BufferedImage img = null;
try {
img = ImageIO.read(file);
}
catch(IOException e) {
return null;
}
if(img == null) {
return null;
}
// if(img.getWidth() != 64 || img.getHeight() != 64) { // || img.getType() != BufferedImage.TYPE_INT_ARGB) {
// return null;
// }
return img;
}
public void load(String currentSkin, ModelType model)
{
this.unload();
File[] files = new File("skins").listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().endsWith(".png");
}
});
int pos = 0;
// for(ModelType model : ModelType.values()) {
this.skinList.add(new SkinEntry(this.owner, "default", null, null, null, model));
if("default".equals(currentSkin))
this.setSelectedSlotIndex(pos);
pos++;
// }
if(files != null) {
Arrays.sort(files);
for(File file : files)
{
BufferedImage img = loadSkin(file);
if(img != null) {
// for(ModelType model : ModelType.values()) {
if(img.getWidth() == model.texWidth && img.getHeight() == model.texHeight) {
this.skinList.add(new SkinEntry(this.owner, file.getName(), file, null, img, model));
if(file.getName().equals(currentSkin))
this.setSelectedSlotIndex(pos);
pos++;
}
// }
}
}
}
for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) {
for(CharacterInfo charinfo : species.chars) {
if(charinfo.species.renderer == model) {
// for(Entry<String, ModelType> entry : SpeciesRegistry.SKINS.entrySet()) {
this.skinList.add(new SkinEntry(this.owner, charinfo.skin, null, charinfo, null, charinfo.species.renderer));
if(charinfo.skin.equals(currentSkin))
this.setSelectedSlotIndex(pos);
pos++;
}
}
}
}
public void unload()
{
for (SkinEntry entry : this.skinList)
{
entry.deleteTexture();
}
this.skinList.clear();
}
protected int getScrollBarX()
{
return 0;
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return 274 - 20;
}
protected boolean isInList(int x, int y)
{
return x >= 6;
}
}
private class DragAdjust extends Button {
private int mouseX;
private int mouseY;
private float yawOffset;
private float pitchOffset;
public boolean dragging;
public DragAdjust(int id, int x, int y, int w, int h) {
super(id, x, y, w, h, "");
}
public void drawButton(Game gm, int mouseX, int mouseY) {
if(this.visible && this.dragging) {
GuiSkin.this.yaw = this.yawOffset + (this.mouseX - mouseX) * 2.0f;
GuiSkin.this.pitch = this.pitchOffset + (this.mouseY - mouseY) * 2.0f;
}
if(this.visible)
drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, 0x20ffffff);
}
public boolean mousePressed(Game gm, int mouseX, int mouseY) {
if(super.mousePressed(gm, mouseX, mouseY)) {
this.mouseX = mouseX;
this.mouseY = mouseY;
this.yawOffset = GuiSkin.this.yaw;
this.pitchOffset = GuiSkin.this.pitch;
this.dragging = true;
return true;
}
else {
return false;
}
}
public void mouseReleased(int mouseX, int mouseY) {
this.dragging = false;
}
public void playPressSound(SoundManager soundHandlerIn) {
}
}
private class ButtonPart extends Button
{
private final ModelPart part;
private ButtonPart(int id, int x, int y, int width, int height, ModelPart part)
{
super(id, x, y, width, height, GuiSkin.this.formatPart(part));
this.part = part;
}
}
private class ButtonAlign extends Button
{
private final Alignment align;
private ButtonAlign(int id, int x, int y, int width, int height, Alignment align)
{
super(id, x, y, width, height, align.color + align.display);
this.align = align;
}
}
private class HeightReceiver implements SliderReceiver {
private int height;
private HeightReceiver(int value) {
this.height = value;
}
public float getValue(Game gm) {
return this.height;
}
public void setValue(Game gm, float value) {
this.height = (int)value;
if(gm.thePlayer != null)
gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, this.height));
}
public String formatValue(Game gm) {
return "Spieler-Größe: " + (int)this.height + " cm";
}
}
private final Set<ModelPart> parts = Sets.newHashSet(ModelPart.values());
private final GuiScreen parentScreen;
private SkinSelector listSelector;
private Button convertButton;
private Button templateButton;
private Button modelButton;
private DragAdjust adjust;
private TextField nameField;
private boolean initialized;
// private int update;
private float yaw;
private float pitch;
public GuiSkin(GuiScreen parentScreen)
{
this.parentScreen = parentScreen;
}
public void updateScreen()
{
// if(this.update > 0)
// this.update -= 1;
this.nameField.updateCursorCounter();
// if(this.gm.nickChanged) {
// this.nameField.setText(this.gm.nickname);
// this.gm.nickChanged = false;
// }
}
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
if (!this.initialized)
{
this.initialized = true;
this.listSelector = new SkinSelector(this, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel(), this.gm.skinId.isEmpty() ? null : this.gm.skinId,
this.gm, 274, this.height, 32, this.height - 32, 20);
}
else
{
this.listSelector.setDimensions(274, this.height, 32, this.height - 32);
}
this.buttonList.add(new Button(8, 164, this.height - 28, 274 - 164, 20, "Neu laden"));
int flags = this.gm.thePlayer == null ? ~ModelPart.ARMS_SLIM.getMask() : this.gm.thePlayer.getModelParts();
this.parts.clear();
for(ModelPart part : ModelPart.values()) {
if((flags & part.getMask()) == part.getMask())
this.parts.add(part);
}
this.buttonList.add(this.convertButton = new Button(9, 10, this.height - 28, 150, 20,
"Konvertieren: " +
(this.parts.contains(ModelPart.ARMS_SLIM) ? "Schlank" : "Standard")));
this.buttonList.add(this.templateButton = new Button(10, this.width - 274, this.height - 28, 150, 20,
"Vorlage kopieren"));
this.buttonList.add(this.adjust = new DragAdjust(20, 274 + 10, 64, this.width - 274 - 274 - 20, this.height - 128));
for (int z = 0; z < ModelPart.values().length; z++)
{
ModelPart part = ModelPart.values()[z];
Button button = new ButtonPart(z + 500, this.width - 274 + (z & 1) * 134, 32 + 24 * (z >> 1), 130, 20, part);
if(part == ModelPart.ARMS_SLIM)
this.modelButton = button;
this.buttonList.add(button);
}
for (int z = 0; z < Alignment.values().length; z++)
{
Button button;
this.buttonList.add(button = new ButtonAlign(z + 600, this.width - 274 + (z % 3) * 89, this.height - 158 + 23 * (z / 3), 86, 20,
Alignment.values()[z]));
button.enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != Alignment.values()[z];
}
// this.gm.setFloatValue(Options.PLAYER_HEIGHT, );
this.buttonList.add(new Slider(30, this.width - 274, this.height - 28 - 54, 264, 20,
new HeightReceiver(this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().size * this.gm.thePlayer.getHeight() * 100.0f + 0.5f)),
120.0f, 320.0f, 1.0f)
// protected void mouseDragged(Game gm, int mouseX, int mouseY) {
// if(this.visible && this.dragging)
// GuiSkin.this.update = 2;
// super.mouseDragged(gm, mouseX, mouseY);
// }
//
// public boolean mouseScrolled(Game gm, int mouseX, int mouseY, int offset) {
// if(super.mouseScrolled(gm, mouseX, mouseY, offset)) {
// GuiSkin.this.update = 2;
// return true;
// }
// return false;
// }
);
this.buttonList.add(new Button(0, this.width - 274 + 154, this.height - 28, 264 - 154, 20, "Fertig"));
this.convertButton.enabled = false;
this.templateButton.enabled = false;
this.nameField = new TextField(this.width - 274 + 2, this.height + 2 - 28 - 24, 260, 16);
this.nameField.setMaxStringLength(32);
this.nameField.setText(this.gm.thePlayer == null ? "" : this.gm.thePlayer.getCustomNameTag());
this.nameField.setValidator(new Predicate<String>()
{
public boolean apply(String name)
{
return NetHandlerPlayServer.isValidNick(name);
}
});
// this.gm.nickChanged = false;
}
private void sendNameToServer()
{
String name = this.nameField.getText();
if(name.isEmpty())
this.nameField.setText(this.gm.thePlayer == null ? "..." : this.gm.thePlayer.getCustomNameTag());
else if(this.gm.thePlayer != null)
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.DISPLAY, name));
}
public void selectSkin(String id, BufferedImage img, boolean slim, ModelType model)
{
this.gm.setSkin(img, id, model, slim);
}
public void close() {
this.gm.displayGuiScreen(this.parentScreen);
}
public void selectEntry(int index, boolean slim)
{
this.listSelector.setSelectedSlotIndex(index);
if(this.listSelector.getSelectedIndex() >= 0) {
SkinEntry entry = this.listSelector.getListEntry(this.listSelector.getSelectedIndex());
if(slim != this.parts.contains(ModelPart.ARMS_SLIM))
try {
this.actionPerformed(this.modelButton);
}
catch(IOException e) {
}
// this.update = 2;
this.convertButton.enabled = entry.canConvert();
this.templateButton.enabled = entry.canCopy();
}
else {
this.convertButton.enabled = false;
this.templateButton.enabled = false;
}
}
public boolean doesGuiPauseGame()
{
return false;
}
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
if(!this.adjust.dragging)
this.listSelector.handleMouseInput();
}
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
this.listSelector.unload();
}
protected void actionPerformed(Button button) throws IOException
{
if (button.enabled)
{
if (button.id == 0)
{
this.gm.displayGuiScreen(this.parentScreen);
}
else if (button.id == 8)
{
this.refreshList();
}
else if (button.id == 9)
{
if(this.listSelector.getSelectedIndex() >= 0) {
SkinEntry entry = this.listSelector.getListEntry(this.listSelector.getSelectedIndex());
if(entry.getFile() != null && SkinConverter.convertSkin(entry.getFile(), new File("skins"),
this.parts.contains(ModelPart.ARMS_SLIM))) {
this.refreshList();
}
}
}
else if (button.id == 10)
{
if(this.listSelector.getSelectedIndex() >= 0) {
SkinEntry entry = this.listSelector.getListEntry(this.listSelector.getSelectedIndex());
if(entry.getLocation() != null) {
String loc = (this.parts.contains(ModelPart.ARMS_SLIM) ? "slim_" : "") + entry.getLocation();
File file = new File(new File("skins"), loc + ".png");
int z = 1;
while(file.exists()) {
file = new File(new File("skins"), loc + "_" + (++z) + ".png");
}
InputStream in = null;
try {
in = FileUtils.getStream(EntityNPC.getSkinTexture(entry.getLocation()));
Files.copy(in, file.toPath());
}
catch(Exception e) {
if(e instanceof FileNotFoundException)
Log.warn("Textur ist nicht zum Kopieren vorhanden: " + FileUtils.getStream(EntityNPC.getSkinTexture(entry.getLocation())));
else
Log.error("Konnte Textur nicht kopieren", e);
}
finally {
FileUtils.closeQuietly(in);
}
this.refreshList();
}
}
}
else if (button.id == 30)
{
// this.update = 2;
}
else if (button instanceof ButtonPart)
{
ModelPart part = ((ButtonPart)button).part;
// this.switchModelPartEnabled(part);
if(!this.parts.contains(part))
this.parts.add(part);
else
this.parts.remove(part);
if(this.gm.thePlayer != null) {
int n = 0;
for(ModelPart p : this.parts) {
n |= p.getMask();
}
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_MODELPARTS, n));
}
button.display = this.formatPart(part);
// this.update = 2;
if(part == ModelPart.ARMS_SLIM)
this.convertButton.display = "Konvertieren: " +
(this.parts.contains(ModelPart.ARMS_SLIM) ? "Schlank" : "Standard");
}
else if (button instanceof ButtonAlign)
{
if(this.gm.thePlayer != null) {
this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN,
((ButtonAlign)button).align.ordinal()));
for(Button btn : this.buttonList) {
if(btn instanceof ButtonAlign)
btn.enabled = ((ButtonAlign)button).align != ((ButtonAlign)btn).align;
}
}
}
}
}
public void refreshList()
{
this.gm.displayGuiScreen(new GuiSkin(this.parentScreen));
}
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if(this.nameField.isFocused() && keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER) {
this.sendNameToServer();
this.nameField.setFocused(false);
}
else {
this.nameField.textboxKeyTyped(typedChar, keyCode);
}
if(keyCode == Keyboard.KEY_F5)
this.refreshList();
else
super.keyTyped(typedChar, keyCode);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawBackground();
// this.drawGradientRect(0, 0, this.width, this.height - 32, 0xC0101010, 0xD0101010);
this.listSelector.drawScreen(mouseX, mouseY, partialTicks);
// this.drawBackground(0, this.height - 32, this.width, 32);
// drawRect(284, 64, this.width - 284, this.height - 64, 0x20000000);
FontRenderer.drawCenteredString("Charakter anpassen", this.width / 2, 20, 0xffffff);
FontRenderer.drawStringWithShadow("Anzeigename", this.nameField.xPosition, this.nameField.yPosition - 10, 10526880);
this.nameField.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
GuiInventory.drawEntity(274 + (this.width - 274 - 274) / 2, this.height / 2 + 80, 80.0f /* *
1.8f */ / this.gm.thePlayer.getHeight(), this.yaw, this.pitch, this.gm.thePlayer);
}
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.listSelector.mouseClicked(mouseX, mouseY, mouseButton);
boolean flag = this.nameField.isFocused();
this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
if(flag && !this.nameField.isFocused())
this.sendNameToServer();
// else if(!flag && this.nameField.isFocused())
// this.nameField.setText(TextColor.getCodes(this.nameField.getText()));
}
protected void mouseReleased(int mouseX, int mouseY, int state)
{
super.mouseReleased(mouseX, mouseY, state);
this.listSelector.mouseReleased(mouseX, mouseY, state);
}
private String formatPart(ModelPart part)
{
return part.getName() + ": " + (
this.parts.contains(part) ? (part == ModelPart.ARMS_SLIM ? "Schlank" : "An") :
(part == ModelPart.ARMS_SLIM ? "Standard" : "Aus"));
}
}

View file

@ -0,0 +1,7 @@
package game.gui;
public interface ListEntry
{
void draw(int x, int y, int mouseX, int mouseY, boolean hovered);
void select(boolean dclick, int mx, int my);
}

View file

@ -0,0 +1,405 @@
package game.gui.world;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import game.collect.Sets;
import game.color.TextColor;
import game.dimension.DimType;
import game.dimension.Dimension;
import game.dimension.Space;
import game.gui.GuiScreen;
import game.gui.element.Button;
import game.gui.element.TextField;
import game.init.UniverseRegistry;
import game.lib.input.Keyboard;
import game.network.NetHandlerPlayServer;
import game.renderer.FontRenderer;
import game.rng.Random;
import game.util.Predicate;
import game.world.Region;
public class GuiCreate extends GuiScreen
{
private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
private GuiScreen parentScreen;
private TextField worldNameField;
private TextField worldSeedField;
private TextField worldUserField;
// private Button modeButton;
private Button dimButton;
// private String descLine1;
// private String descLine2;
private String[] descLines;
private boolean alreadyGenerated;
private boolean fileExists;
private boolean fileInvalid;
private String seed;
private String decoded;
private int dimension;
private static long getSeed(String str) {
if(str == null || str.isEmpty())
return (new Random()).longv();
try {
return Long.parseLong(str);
}
catch(NumberFormatException e) {
}
long seed = 0L;
if(str.length() <= 9) {
for(int z = 0; z < str.length(); z++) {
seed <<= 7;
char c = str.charAt(z);
if(c >= 0x80) {
seed = -1L;
break;
}
seed |= (long)c;
}
}
else if(str.length() == 10) {
String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS;
for(int z = 0; z < str.length(); z++) {
seed <<= 6;
int idx = ch.indexOf(str.charAt(z));
if(idx == -1) {
seed = -1L;
break;
}
seed |= (long)idx;
}
if(seed != -1L)
seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L;
}
else if(str.length() <= 12) {
for(int z = 0; z < str.length(); z++) {
seed <<= 5;
int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z)));
if(idx == -1) {
seed = -1L;
break;
}
seed |= (long)idx;
}
if(seed != -1L)
seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L;
}
else {
seed = -1L;
}
if(seed == -1L) {
seed = 0L;
for(int z = 0; z < str.length(); z++) {
seed <<= 7;
seed |= (long)((char)(str.charAt(z) & 0x7f));
}
seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L;
}
return seed;
}
private static String decodeSeed(long seed, String def) {
if(seed == 0L)
return (def == null ? ("" + seed) : def);
if((seed & 0x8000000000000000L) == 0L) {
String str = "";
long value = seed;
while(value != 0L) {
char c = (char)(value & 0x7fL);
if(c < 32 || c > 126)
return (def == null ? ("" + seed) : def);
str = c + str;
value >>= 7;
}
try {
Long.parseLong(str);
}
catch(NumberFormatException e) {
return str;
}
return (def == null ? ("" + seed) : def);
}
String chset;
int len;
int shift;
long mask;
long type = (seed >> 60) & 0xf;
switch((int)type) {
case 0x8:
chset = MBASE32_CHARS;
len = 11;
shift = 5;
mask = 0x1fL;
break;
case 0x9:
chset = MBASE32_CHARS;
len = 12;
shift = 5;
mask = 0x1fL;
break;
case 0xa:
chset = MBASE64A_CHARS;
len = 10;
shift = 6;
mask = 0x3fL;
break;
case 0xb:
chset = MBASE64B_CHARS;
len = 10;
shift = 6;
mask = 0x3fL;
break;
default:
return (def == null ? ("" + seed) : def);
}
String str = "";
for(int z = 0; z < len; z++) {
str = chset.charAt((int)(seed & mask)) + str;
seed >>= shift;
}
try {
Long.parseLong(str);
}
catch(NumberFormatException e) {
return str;
}
return (def == null ? ("" + seed) : def);
}
public GuiCreate(GuiScreen parent)
{
UniverseRegistry.clear();
this.parentScreen = parent;
// this.worldSeed = "";
// this.worldName = "Neue Welt";
}
public void updateScreen()
{
this.worldNameField.updateCursorCounter();
this.worldSeedField.updateCursorCounter();
this.worldUserField.updateCursorCounter();
String text = this.worldSeedField.getText();
if(text.isEmpty()) {
this.seed = "Zufällig";
this.decoded = "-";
}
else {
this.seed = "" + getSeed(text);
try {
this.decoded = decodeSeed(Long.parseLong(text), "-");
}
catch(NumberFormatException e) {
this.decoded = decodeSeed(getSeed(text), "-");
}
}
this.fileExists = false;
this.fileInvalid = false;
text = this.worldNameField.getText().trim();
// for(String n : GuiCreate.DISALLOWED_FILES) {
// if(text.equalsIgnoreCase(n)) {
// ((Button)this.buttonList.get(0)).enabled = false;
// this.fileInvalid = true;
// return;
// }
// }
if(this.fileInvalid = GuiCreate.DISALLOWED_FILES.contains(text.toUpperCase())) {
((Button)this.buttonList.get(0)).enabled = false;
return;
}
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
((Button)this.buttonList.get(0)).enabled = false;
}
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new Button(0, this.width / 2 - 155, this.height - 28, 150, 20, "Neue Welt erstellen"));
this.buttonList.add(new Button(1, this.width / 2 + 5, this.height - 28, 150, 20, "Abbrechen"));
// this.buttonList.add(this.modeButton = new Button(2, this.width / 2 - 155, 175, 310, 20, ""));
this.buttonList.add(this.dimButton = new Button(2, this.width / 2 - 155, 220, 310, 20, ""));
this.worldNameField = new TextField(this.width / 2 - 100, 60, 200, 20);
this.worldNameField.setFocused(true);
this.worldNameField.setValidator(new Predicate<String>() {
public boolean apply(String name) {
for(int z = 0; z < name.length(); z++) {
if(DISALLOWED_CHARS.contains(name.charAt(z)))
return false;
}
return true;
}
});
// this.worldNameField.setText("Welt");
this.worldSeedField = new TextField(this.width / 2 - 100, 136, 200, 20);
// this.worldSeedField.setText(this.worldSeed);
this.worldUserField = new TextField(this.width / 2 - 100, 98, 200, 20);
this.worldUserField.setMaxStringLength(16);
this.worldUserField.setValidator(new Predicate<String>() {
public boolean apply(String name) {
return NetHandlerPlayServer.isValidUser(name);
}
});
// this.calcSaveDirName();
// this.setModeButton();
this.setDimButton();
((Button)this.buttonList.get(0)).enabled = false;
}
// private void setModeButton() {
// this.modeButton.display = "Kreativmodus: " + (this.noCreative ? "Aus" : "An");
// this.descLine1 = this.noCreative ? "Suche nach Ressourcen, baue Werkzeuge, Waffen und mehr"
// : "Unbegrenzte Rohstoffe, Flugmodus, Unverwundbarkeit, keine";
// this.descLine2 = this.noCreative ? "Gegenstände, sammle Erfahrung und erkunde die Welten"
// : "Energie oder Mana und sofortiges Zerstören von Blöcken";
// }
private void setDimButton() {
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : UniverseRegistry.getBaseDimensions().get(this.dimension);
this.dimButton.display = (dim == Space.INSTANCE ? "" :
((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ?
"Vorlage" : (dim.getType() == DimType.PLANET ? "Heimplanet" : "Dimension")) + ": ")) +
(dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() :
dim.getFormattedName(false));
this.descLines = dim.getFormattedName(true).split(" / ");
}
// private void calcSaveDirName()
// {
// this.saveDirName = this.worldNameField.getText().trim();
//
//// for (char c : DISALLOWED_CHARS)
//// {
//// this.saveDirName = this.saveDirName.replace(c, '_');
//// }
//
// if (!this.saveDirName.isEmpty())
//// {
//// this.saveDirName = "World";
//// }
//
// this.saveDirName = getUncollidingSaveDirName(Region.SAVE_DIR, this.saveDirName);
// }
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
protected void actionPerformed(Button button) throws IOException
{
if (button.enabled)
{
if (button.id == 1)
{
this.gm.displayGuiScreen(this.parentScreen);
}
else if (button.id == 0)
{
this.gm.displayGuiScreen(null);
if(this.alreadyGenerated)
return;
this.alreadyGenerated = true;
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
UniverseRegistry.getBaseDimensions().get(this.dimension);
dim.setSeed(getSeed(this.worldSeedField.getText()));
this.gm.launchIntegratedServer(this.worldNameField.getText().trim(), dim, this.worldUserField.getText());
}
// else if (button.id == 2)
// {
// this.noCreative ^= true;
// this.setModeButton();
// }
else if (button.id == 2)
{
// int index = Integer.MAX_VALUE;
// for(int z = 0; z < UniverseRegistry.getBasePlanets().size(); z++) {
// if(UniverseRegistry.getBasePlanets().get(z).getDimensionId() == this.dimension) {
// index = z;
// break;
// }
// }
if(this.dimension == Integer.MAX_VALUE) {
this.dimension = GuiScreen.isShiftKeyDown() ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
}
else {
if(GuiScreen.isShiftKeyDown()) {
if(--this.dimension < 0)
this.dimension = Integer.MAX_VALUE;
}
else {
if(++this.dimension >= UniverseRegistry.getBaseDimensions().size())
this.dimension = Integer.MAX_VALUE;
}
}
// this.dimension = index == Integer.MAX_VALUE ? Space.INSTANCE.getDimensionId() :
// UniverseRegistry.getBasePlanets().get(index).getDimensionId();
this.setDimButton();
}
}
}
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
// if (this.worldNameField.isFocused())
// {
this.worldNameField.textboxKeyTyped(typedChar, keyCode);
// this.worldName = this.worldNameField.getText();
// }
// else if (this.worldSeedField.isFocused())
// {
this.worldSeedField.textboxKeyTyped(typedChar, keyCode);
// this.worldSeed = this.worldSeedField.getText();
// }
// else if (this.worldUserField.isFocused())
// {
this.worldUserField.textboxKeyTyped(typedChar, keyCode);
// }
if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed((Button)this.buttonList.get(0));
}
((Button)this.buttonList.get(0)).enabled = this.worldNameField.getText().length() > 0 && this.worldUserField.getText().length() > 0;
// this.calcSaveDirName();
}
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.worldSeedField.mouseClicked(mouseX, mouseY, mouseButton);
this.worldNameField.mouseClicked(mouseX, mouseY, mouseButton);
this.worldUserField.mouseClicked(mouseX, mouseY, mouseButton);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawBackground();
FontRenderer.drawCenteredString("Neue Welt erstellen", this.width / 2, 20, -1);
FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336);
FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336);
FontRenderer.drawStringWithShadow((this.worldNameField.getText().trim().isEmpty() || this.fileExists || this.fileInvalid ? TextColor.DARK_RED : "")
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : ""), this.width / 2 - 100, 49, -6250336);
FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336);
this.worldSeedField.drawTextBox();
this.worldNameField.drawTextBox();
this.worldUserField.drawTextBox();
// FontRenderer.drawStringWithShadow(this.descLine1, this.width / 2 - 153, 197, -6250336);
// FontRenderer.drawStringWithShadow(this.descLine2, this.width / 2 - 153, 197 + FontRenderer.FONT_HEIGHT + 1, -6250336);
for(int z = 1; z < this.descLines.length; z++) {
FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336);
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View file

@ -0,0 +1,140 @@
package game.gui.world;
import java.io.File;
import game.ActButton;
import game.Gui;
import game.Label;
import game.Textbox;
import game.Textbox.Action;
import game.ActButton.Mode;
import game.color.TextColor;
import game.network.NetHandlerPlayServer;
import game.world.Region;
public class GuiEdit extends Gui implements ActButton.Callback, Textbox.Callback {
public static interface Callback {
void confirm(String name);
}
private final String original;
private final boolean player;
private final String title;
private final String action;
private final String desc;
private final Callback callback;
private Textbox nameField;
private ActButton actionButton;
private ActButton cancelButton;
private Label actionLabel;
private boolean fileExists;
private boolean noChange;
public GuiEdit(String original, boolean player, String title, String action, String desc, Callback callback) {
this.original = original;
this.player = player;
this.title = title;
this.action = action;
this.desc = desc;
this.callback = callback;
}
public void updateScreen() {
this.actionButton.enabled = true;
this.fileExists = false;
this.noChange = false;
String text = this.nameField.getText().trim();
if(text.isEmpty() || (this.noChange = (text.equals(this.original) || (!this.player && !text.replaceAll("[\\./\"]", "_")
.equals(text))))) {
this.actionButton.enabled = false;
this.actionLabel.setText(this.getLabelDesc());
return;
}
if(this.player) {
this.actionLabel.setText(this.getLabelDesc());
return;
}
// {
// if(!StringValidator.isValidUser(text))
// this.actionButton.enabled = false;
// }
// else {
// for(String n : GuiCreate.DISALLOWED_FILES) {
// if(text.equalsIgnoreCase(n)) {
// this.actionButton.enabled = false;
// return;
// }
// }
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
this.actionButton.enabled = false;
this.actionLabel.setText(this.getLabelDesc());
// }
}
public void init(int width, int height) {
this.actionButton = this.add(new ActButton(width / 2 - 100, height / 4 + 96 + 12, 200, 20, (ActButton.Callback)this, this.action));
this.cancelButton = this.add(new ActButton(width / 2 - 100, height / 4 + 120 + 12, 200, 20, (ActButton.Callback)this, "Abbrechen"));
this.nameField = this.add(new Textbox(width / 2 - 100, 60, 200, 20, this.player ? NetHandlerPlayServer.MAX_USER_LENGTH : 256, true, this, this.player ? NetHandlerPlayServer.VALID_USER : GuiWorlds.VALID_FILE, this.original == null ? "" : this.original));
this.nameField.setSelected();
// if(this.player) {
// this.nameField.setMaxStringLength(16);
// this.nameField.setValidator(new Predicate<String>() {
// public boolean apply(String name) {
// return NetHandlerPlayServer.isValidUser(name);
// }
// });
// }
// else {
// this.nameField.setValidator(new Predicate<String>() {
// public boolean apply(String name) {
// for(int z = 0; z < name.length(); z++) {
// if(GuiCreate.DISALLOWED_CHARS.contains(name.charAt(z)))
// return false;
// }
// return true;
// }
// });
// }
this.actionLabel = this.add(new Label(width / 2 - 100, 20, 200, 24, this.getLabelDesc()));
// this.shift();
// this.nameField.setText();
this.actionButton.enabled = false;
}
public String getTitle() {
return "Welt bearbeiten";
}
public void use(ActButton btn, Mode mode) {
this.callback.confirm(btn == this.actionButton ? this.nameField.getText().trim() : null);
}
public void use(Textbox elem, Action action) {
if(action == Action.SEND)
this.use(this.actionButton, Mode.PRIMARY);
}
// protected void actionPerformed(Button button) throws IOException {
// if(button.enabled) {
// if(button.id == 1) {
// }
// else if(button.id == 0) {
// this.callback.confirm(this.nameField.getText().trim());
//// this.gm.displayGuiScreen(this.parent);
// }
// }
// }
// protected void keyTyped(char typedChar, int keyCode) throws IOException {
// ((Button)this.buttonList.get(0)).enabled = this.nameField.getText().trim().length() > 0;
////
//// if(keyCode == 28 || keyCode == 156) {
//// this.actionPerformed((Button)this.buttonList.get(0));
//// }
// }
private String getLabelDesc() {
return (this.actionButton.enabled ? "" : TextColor.DRED) + this.desc +
(this.fileExists ? " - Existiert bereits" : (this.noChange ? " - Nicht geändert" : ""));
}
}

View file

@ -0,0 +1,633 @@
package game.gui.world;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
import game.ActButton;
import game.CharValidator;
import game.ActButton.Mode;
import game.Drawing;
import game.FileCallback;
import game.FileUtils;
import game.GuiMenu;
import game.Log;
import game.WCF;
import game.collect.Sets;
import game.color.TextColor;
import game.dimension.Dimension;
import game.gui.GuiConfirm;
import game.gui.GuiList;
import game.gui.ListEntry;
import game.gui.world.GuiEdit.Callback;
import game.init.Config;
import game.init.UniverseRegistry;
import game.nbt.NBTLoader;
import game.nbt.NBTTagCompound;
import game.world.Converter;
import game.world.Converter.SaveVersion;
import game.world.Region;
import game.world.World;
import game.world.Region.FolderInfo;
public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.Callback
{
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
private final String file;
private final String name;
private final long seed;
private final FolderInfo info;
public SaveInfo(String file, String name, long seed, FolderInfo info) {
this.file = file;
this.name = name;
this.seed = seed;
this.info = info;
}
public String getFile() {
return this.file;
}
public String getName() {
return this.name == null ? "<?>" : this.name;
}
public String getUser() {
return this.info.user == null ? "<?>" : this.info.user;
}
public String getUsername() {
return this.info.user;
}
public boolean mustConvert() {
return this.info.legacy != null;
}
public String getVersion() {
return this.info.legacy == null ? (this.info.version == null ? "<Unbekannt>" : this.info.version) : this.info.legacy.toString();
}
public boolean isIncompatible() {
return this.info.legacy == SaveVersion.RELEASE_1_13;
}
public long getLastPlayed() {
return this.info.lastPlayed;
}
public long getSeed() {
return this.seed;
}
public int compareTo(SaveInfo comp) {
return this.info.lastPlayed < comp.info.lastPlayed ? 1 : (this.info.lastPlayed > comp.info.lastPlayed ? -1 : this.file.compareTo(comp.file));
}
public void select(boolean isDoubleClick, int mouseX, int mouseY)
{
boolean use = !this.isIncompatible();
boolean cur = use && !this.mustConvert();
GuiWorlds.this.selectButton.setText(!use || !cur ? "Konvertieren" : "Welt spielen");
GuiWorlds.this.selectButton.enabled = use;
GuiWorlds.this.deleteButton.enabled = true;
GuiWorlds.this.pruneButton.enabled = cur;
GuiWorlds.this.copyButton.enabled = use;
GuiWorlds.this.moveButton.enabled = use;
GuiWorlds.this.seedButton.enabled = cur;
GuiWorlds.this.userButton.enabled = cur;
GuiWorlds.this.dupeButton.enabled = cur;
if (isDoubleClick && use)
{
GuiWorlds.this.playWorld(null);
}
}
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
{
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
(TextColor.GRAY + " - " + TextColor.RESET + this.getUser())), x + 2, y, 0xffffffff);
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getName())
, x + 2, y + 18, 0xff808080);
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
"Zuletzt gespielt: " + DATE_FORMAT.format(new Date(this.getLastPlayed()))) + " " + TextColor.LGRAY + this.getVersion(), x + 2, y + 18 + 16, 0xff808080);
}
}
public static final GuiWorlds INSTANCE = new GuiWorlds();
public static final Set<Character> DISALLOWED_CHARS = Sets.newHashSet('/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\',
'<', '>', '|', '\"', ':');
public static final CharValidator VALID_FILE = new CharValidator() {
public boolean valid(char ch) {
return !DISALLOWED_CHARS.contains(ch);
}
};
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
private boolean starting;
private int warningTimer;
private String warningMessage;
private ActButton deleteButton;
private ActButton pruneButton;
private ActButton selectButton;
private ActButton copyButton;
private ActButton moveButton;
private ActButton seedButton;
private ActButton userButton;
private ActButton dupeButton;
private ActButton createButton;
private GuiWorlds()
{
}
public void init(int width, int height)
{
this.starting = false;
this.setDimensions(width, height, 48, height - 64);
boolean create = true;
this.elements.clear();
try
{
Region.SAVE_DIR.mkdirs();
if(!Region.SAVE_DIR.exists() || !Region.SAVE_DIR.isDirectory())
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
// java.util.List<SaveInfo> list = Lists.<SaveInfo>newArrayList();
File[] files = Region.SAVE_DIR.listFiles();
if(files == null)
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
for(File file : files) {
if(!file.isDirectory())
continue;
FolderInfo info = Region.loadWorldInfo(file);
if(info == null)
info = Converter.convertMapFormat(file, null);
if(info == null) {
this.elements.add(new SaveInfo(file.getName(), null,
0L, new FolderInfo(World.START_TIME, null, file.lastModified(), null, null)));
continue;
}
Dimension dim = info.legacy != null ? null : UniverseRegistry.getDimension(Config.spawnDim);
if(dim != null) {
File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"),
dim.getDimensionName()), "data.nbt");
try {
dim.fromNbt(NBTLoader.readGZip(dat).getCompoundTag("Generator"));
}
catch(Exception e) {
}
}
this.elements.add(new SaveInfo(file.getName(), dim == null ? null : TextColor.stripCodes(dim.getFormattedName(true)),
dim == null ? 0L : dim.getSeed(), info));
}
// this.saveList = list;
Collections.sort(this.elements);
}
catch (Exception e)
{
Log.IO.error("Konnte Weltliste nicht laden", e);
this.elements.clear();
create = false;
this.warningTimer = 120;
this.warningMessage = "Welten-Ordner nicht lesbar!";
}
this.add(this.selectButton = new ActButton(width / 2 - 153 - 39, height - 52, 72, 20, (ActButton.Callback)this, "Welt spielen"));
this.add(this.createButton = new ActButton(width / 2 + 81 + 72 + 6 - 39, height - 52, 72, 20, (ActButton.Callback)this,
(create ? "" : "" + TextColor.DRED) + (create ? "Neue Welt ..." : "Fehler!")));
this.add(this.deleteButton = new ActButton(width / 2 - 75 - 39, height - 28, 72, 20, (ActButton.Callback)this, "Löschen"));
this.add(this.pruneButton = new ActButton(width / 2 + 3 - 39, height - 28, 72, 20, (ActButton.Callback)this, "Leeren"));
this.add(this.copyButton = new ActButton(width / 2 - 153 - 39, height - 28, 72, 20, (ActButton.Callback)this, "Kopieren"));
this.add(this.moveButton = new ActButton(width / 2 + 81 - 39, height - 28, 72, 20, (ActButton.Callback)this, "Verschieben"));
this.add(this.seedButton = new ActButton(width / 2 + 3 - 39, height - 52, 72, 20, (ActButton.Callback)this, "Startwert"));
this.add(this.userButton = new ActButton(width / 2 - 75 - 39, height - 52, 72, 20, (ActButton.Callback)this, "Spieler"));
this.add(this.dupeButton = new ActButton(width / 2 + 81 - 39, height - 52, 72, 20, (ActButton.Callback)this, "Duplizieren"));
this.add(new ActButton(width / 2 + 81 + 72 + 6 - 39, height - 28, 72, 20, GuiMenu.INSTANCE, "Abbrechen"));
this.add(new ActButton(20, 20, 200, 24, new ActButton.Callback() {
public void use(ActButton elem, ActButton.Mode action) {
if(GuiWorlds.this.gm.theWorld != null)
return;
GuiWorlds.this.gm.showDirDialog("Welt öffnen", "saves", new FileCallback() {
public void selected(File file) {
if(GuiWorlds.this.gm.theWorld == null && GuiWorlds.this.gm.open instanceof GuiWorlds)
GuiWorlds.this.gm.startServer(file, "sen");
}
});
}
}, "Welt laden"));
this.selectButton.enabled = false;
this.deleteButton.enabled = false;
this.pruneButton.enabled = false;
this.copyButton.enabled = false;
this.moveButton.enabled = false;
this.seedButton.enabled = false;
this.userButton.enabled = false;
this.dupeButton.enabled = false;
this.createButton.enabled = create;
}
public String getTitle() {
return "Welt auswählen";
}
public int getListWidth()
{
return 660;
}
public int getSlotHeight()
{
return 56;
}
public void updateScreen() {
super.updateScreen();
// this.userField.updateCursorCounter();
if(this.warningTimer > 0) {
if(--this.warningTimer == 0) {
this.warningMessage = null;
}
}
}
// /**
// * Handles mouse input.
// */
// public void handleMouseInput() throws IOException
// {
// super.handleMouseInput();
// this.availableWorlds.handleMouseInput();
// }
// private void loadLevelList() {
//
// }
private String getSaveAt()
{
return this.getSelected().getFile();
}
// protected String getNameAt(int index)
// {
// String s = ((SaveInfo)this.saveList.get(index)).getName();
//
// if (s == null || s.isEmpty())
// {
// s = I18n.format("selectWorld.world") + " " + (index + 1);
// }
//
// return s;
// }
// public void addWorldSelectionButtons(boolean create)
// {
//// this.userField = new TextField(this.width / 2 + 4 + 2, 26, 146, 16);
//// this.userField.setMaxStringLength(16);
//// this.userField.setText(this.gm.localUser);
//// this.userField.setValidator(new Predicate<String>()
//// {
//// public boolean apply(String name)
//// {
//// return StringValidator.isValidUser(name);
//// }
//// });
// }
public void use(ActButton button, Mode mode)
{
// if (button.enabled)
// {
if (button == this.deleteButton)
{
String s = this.getSaveAt();
if (s != null)
{
GuiConfirm guiyesno = makeYesNo(this, s, false);
this.gm.displayGuiScreen(guiyesno);
}
}
else if (button == this.pruneButton)
{
String s = this.getSaveAt();
if (s != null)
{
GuiConfirm guiyesno = makeYesNo(this, s, true);
this.gm.displayGuiScreen(guiyesno);
}
}
else if (button == this.selectButton)
{
// if(isShiftKeyDown())
//
// else
this.playWorld(null);
}
else if (button == this.createButton)
{
if(GuiWorlds.this.gm.theWorld == null) {
if(this.gm.shift()) {
// this.gm.displayGuiScreen(null);
this.gm.startServer(null, "debug");
}
else {
// this.gm.displayGuiScreen(new GuiCreate(this)); //TODO: create
}
}
}
else if (button == this.userButton)
{
this.gm.displayGuiScreen(new GuiEdit(this.getSelected().getUsername(), true,
"Spieler für '" + this.getSaveAt() + "' ändern", "Ändern", "Spielername", new Callback() {
public void confirm(String name) {
if(name != null)
GuiWorlds.this.changeUser(name);
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
}
}));
}
// else if (button.id == 0)
// {
// this.gm.displayGuiScreen(this.parentScreen);
// }
else if (button == this.dupeButton)
{
}
else if (button == this.copyButton)
{
this.gm.displayGuiScreen(new GuiEdit("", false,
"Welt '" + this.getSaveAt() + "' kopieren", "Kopieren", "Ordner der Welt", new Callback() {
public void confirm(String name) {
if(name != null)
GuiWorlds.this.copyWorld(name);
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
}
}));
}
else if (button == this.moveButton)
{
this.gm.displayGuiScreen(new GuiEdit(this.getSaveAt(), false,
"Welt '" + this.getSaveAt() + "' verschieben", "Verschieben", "Ordner der Welt", new Callback() {
public void confirm(String name) {
if(name != null)
GuiWorlds.this.moveWorld(name);
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
}
}));
}
else if (button == this.seedButton)
{
WCF.setClipboard("" + this.getSelected().getSeed());
this.warningTimer = 40;
this.warningMessage = TextColor.DGREEN + "Startwert wurde in die Zwischenablage kopiert";
}
// else
// {
// this.availableWorlds.actionPerformed(button);
// }
// }
}
private void copyWorld(String name) {
File oldDir = new File(Region.SAVE_DIR, this.getSaveAt());
// String name = this.getSaveAt(this.selectedIndex);
// while(new File(Region.SAVE_DIR, name).exists()) {
// name = name + "-";
// }
File newDir = new File(Region.SAVE_DIR, name);
Log.IO.info("Kopiere Welt " + oldDir + " nach " + newDir);
if(!copyFiles(oldDir, newDir, oldDir.listFiles())) {
this.warningTimer = 120;
this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!";
}
// try
// {
// this.loadLevelList();
// }
// catch (Exception anvilconverterexception)
// {
// Log.error((String)"Konnte Weltliste nicht laden", (Throwable)anvilconverterexception);
// }
this.gm.displayGuiScreen(this);
}
private void moveWorld(String dest) {
File oldDir = new File(Region.SAVE_DIR, this.getSaveAt());
File newDir = new File(Region.SAVE_DIR, dest);
Log.IO.info("Kopiere Welt " + oldDir + " nach " + newDir);
if(!copyFiles(oldDir, newDir, oldDir.listFiles())) {
this.warningTimer = 120;
this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!";
return;
}
if(!this.deleteWorld(false)) {
this.warningTimer = 120;
this.warningMessage = "Fehler beim Löschen der Welt!";
}
this.gm.displayGuiScreen(this);
}
private void changeUser(String user) {
File file = new File(new File(Region.SAVE_DIR, this.getSaveAt()), "level.nbt");
if(file.exists()) {
try {
NBTTagCompound tag = NBTLoader.readGZip(file);
tag.setString("Owner", user);
NBTLoader.writeGZip(tag, file);
}
catch(Exception e) {
Log.IO.error("Fehler beim Verarbeiten von " + file, e);
}
}
// this.gm.displayGuiScreen(this);
}
private void playWorld(String user)
{
if(GuiWorlds.this.gm.theWorld != null)
return;
// this.gm.displayGuiScreen(null);
if (!this.starting)
{
this.starting = true;
// int index = this.selectedIndex;
if(user == null)
user = this.getSelected().getUsername();
String dir = this.getSaveAt();
File folder = new File(Region.SAVE_DIR, dir);
if(folder.isDirectory()) {
if(user == null) {
this.gm.displayGuiScreen(new GuiEdit("", true,
"Spieler für '" + dir + "' festlegen", "Festlegen", "Spielername", new Callback() {
public void confirm(String name) {
if(name != null)
GuiWorlds.this.playWorld(name);
else
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
}
}));
this.starting = false;
}
else {
if(this.getSelected().mustConvert()) {
this.gm.convert(folder, user);
this.gm.displayGuiScreen(this);
this.starting = false;
}
else {
this.gm.startServer(folder, user);
}
}
}
}
}
// public void confirmClicked(boolean result)
// {
// if (this.confirmingDelete >= 0 || this.confirmingPrune >= 0)
// {
// boolean prune = this.confirmingPrune >= 0;
// int id = prune ? this.confirmingPrune : this.confirmingDelete;
// this.confirmingDelete = -1;
// this.confirmingPrune = -1;
//
// if (result)
// {
//// Region.clearCache(true);
// if(!this.deleteWorld(prune)) {
// this.warningTimer = 120;
// this.warningMessage = "Fehler beim " + (prune ? "Leeren" : "Löschen") + " der Welt!";
// }
//
//// try
//// {
//// this.loadLevelList();
//// }
//// catch (Exception anvilconverterexception)
//// {
//// Log.error((String)"Konnte Weltliste nicht laden", (Throwable)anvilconverterexception);
//// }
// }
//
// this.gm.displayGuiScreen(this);
// }
// }
private boolean deleteWorld(final boolean pruneOnly)
{
File worldDir = new File(Region.SAVE_DIR, this.getSaveAt());
if (!worldDir.exists())
{
return true;
}
Log.IO.info((pruneOnly ? "Leere" : "Lösche") + " Welt " + worldDir);
boolean flag = false;
for (int i = 1; i <= 5; ++i)
{
Log.IO.info("Versuch " + i + "...");
if (FileUtils.deleteFiles(worldDir.listFiles(new FileFilter() {
public boolean accept(File file) {
return !pruneOnly || (file.isDirectory() ? file.getName().equals("chunk") : file.getName().equals("signs.nbt"));
}
})))
{
flag = true;
break;
}
Log.IO.warn("Konnte Inhalt nicht löschen.");
if (i < 5)
{
try
{
Thread.sleep(500L);
}
catch (InterruptedException e)
{
;
}
}
}
return pruneOnly ? flag : worldDir.delete();
}
private static boolean copyFiles(File source, File dest, File[] files)
{
dest.mkdirs();
if(files == null || !dest.isDirectory()) {
Log.IO.warn("Konnte Ordner " + source + " nicht nach " + dest + " kopieren");
return false;
}
boolean flag = true;
for (int i = 0; i < files.length; ++i)
{
File file = files[i];
File nfile = new File(dest, file.getName());
Log.IO.info("Kopiere " + file + " nach " + nfile);
if (file.isDirectory())
{
flag &= copyFiles(file, nfile, file.listFiles());
continue;
}
try {
Files.copy(file.toPath(), nfile.toPath(), StandardCopyOption.REPLACE_EXISTING);
// Files.copy(file, nfile);
}
catch(IOException e) {
Log.IO.error("Konnte Datei " + file + " nicht nach " + nfile + " kopieren", e);
flag = false;
}
}
return flag;
}
public void drawOverlays()
{
super.drawOverlays();
if(this.warningMessage != null) {
drawRect(this.gm.fb_x / 2 - 191, this.gm.fb_y - 82, this.gm.fb_x / 2 + 191, this.gm.fb_y - 66, 0xff808080);
drawRect(this.gm.fb_x / 2 - 190, this.gm.fb_y - 81, this.gm.fb_x / 2 + 190, this.gm.fb_y - 67, 0xff000000);
Drawing.drawText(this.warningMessage, this.gm.fb_x / 2, this.gm.fb_y - 78, 0xffff0000);
}
}
public static GuiConfirm makeYesNo(GuiWorlds selectWorld, String name, boolean prune)
{
String s = prune ? "Willst du diese Welt wirklich leeren?" : "Bist du sicher, dass du diese Welt löschen möchtest?";
String s1 = "\'" + name + "\' " + (prune ? "wird alle Daten außer dem Spieler und Einstellungen verlieren!"
: "wird für immer verloren sein! (Eine lange Zeit!)");
String s2 = prune ? "Leeren" : "Löschen";
String s3 = "Abbrechen";
GuiConfirm guiyesno = new GuiConfirm(new GuiConfirm.Callback() {
@Override
public void confirm(boolean confirmed) {
if(confirmed && !selectWorld.deleteWorld(prune)) {
selectWorld.warningTimer = 120;
selectWorld.warningMessage = "Fehler beim " + (prune ? "Leeren" : "Löschen") + " der Welt!";
}
selectWorld.gm.displayGuiScreen(selectWorld);
}
}, s, s1, s2, s3);
return guiyesno;
}
}