Rework stencil table GUI

This commit is contained in:
Bernhard Bonigl committed 2014-08-20 22:23:12 +02:00
1 parent 5dd0e0c8fa
commit bd997ab05e
9 files changed
+252 -39

No files matched your search

@@ -0,0 +1,15 @@
package tconstruct.library.client;
public class GuiElement {
public final int buttonIconX;
public final int buttonIconY;
public final String domain;
public final String texture;
public GuiElement(int buttonIconX, int buttonIconY, String domain, String texture) {
this.buttonIconX = buttonIconX;
this.buttonIconY = buttonIconY;
this.domain = domain;
this.texture = texture;
}
}
@@ -0,0 +1,11 @@
package tconstruct.library.client;
public class StencilGuiElement extends GuiElement {
public final int stencilIndex;
public StencilGuiElement(int buttonIconX, int buttonIconY, int stencilIndex, String domain, String texture) {
super(buttonIconX, buttonIconY, domain, texture);
this.stencilIndex = stencilIndex;
}
}
@@ -13,6 +13,8 @@ import tconstruct.library.tools.ToolCore;
public class TConstructClientRegistry
{
public static ArrayList<StencilGuiElement> stencilButtons = new ArrayList<StencilGuiElement>();
public static ArrayList<StencilGuiElement> stencilButtons2 = new ArrayList<StencilGuiElement>();
public static ArrayList<ToolGuiElement> toolButtons = new ArrayList<ToolGuiElement>(20);
public static ArrayList<ToolGuiElement> tierTwoButtons = new ArrayList<ToolGuiElement>();
public static Map<String, ItemStack> manualIcons = new HashMap<String, ItemStack>();
@@ -103,6 +105,27 @@ public class TConstructClientRegistry
}
//Gui
public static void addStencilButton (StencilGuiElement element)
{
stencilButtons.add(element);
}
public static void addStencilButton (int xButton, int yButton, int index, String domain, String texture)
{
stencilButtons.add(new StencilGuiElement(xButton, yButton, index, domain, texture));
}
public static void addStencilButton2 (StencilGuiElement element)
{
stencilButtons.add(element);
}
// adds a button to the right side of the stencil table
public static void addStencilButton2 (int xButton, int yButton, int index, String domain, String texture)
{
stencilButtons2.add(new StencilGuiElement(xButton, yButton, index, domain, texture));
}
public static void addToolButton (ToolGuiElement element)
{
toolButtons.add(element);
@@ -46,7 +46,7 @@ public class StencilBuilder {
*/
public static int getIndex(ItemStack stencil) {
for(int i = 0; i < instance.stencils.size(); i++)
if(ItemStack.areItemStackTagsEqual(stencil, getStencil(i)))
if(OreDictionary.itemMatches(stencil, getStencil(i), false))
return i;
return -1;
@@ -355,13 +355,7 @@ public class TinkerTools
registerMaterials();
// register stencils/wooden patterns in the stencil table
StencilBuilder.registerBlankStencil(new ItemStack(TinkerTools.blankPattern));
for(int i = 1; i < 26; i++) {
if(i == 22) continue; // hide full guard
StencilBuilder.registerStencil(TinkerTools.woodPattern, i);
}
registerStencils();
//TODO: Redesign stencil table to be a sensible block
@@ -945,4 +939,41 @@ public class TinkerTools
pb.addToolPattern((IPattern) TinkerTools.woodPattern);
}
private void registerStencils()
{
StencilBuilder.registerBlankStencil(new ItemStack(TinkerTools.blankPattern));
// we register this manually because we want that specific order
StencilBuilder.registerStencil(TinkerTools.woodPattern, 1); // tool rod
StencilBuilder.registerStencil(TinkerTools.woodPattern, 9); // binding
StencilBuilder.registerStencil(TinkerTools.woodPattern, 14); // large tool rod
StencilBuilder.registerStencil(TinkerTools.woodPattern, 15); // large binding
StencilBuilder.registerStencil(TinkerTools.woodPattern, 2); // pickaxe head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 3); // shovel head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 4); // hatchet head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 18); // scythe
StencilBuilder.registerStencil(TinkerTools.woodPattern, 21); // hammer head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 19); // excavator head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 17); // lumberaxe head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 16); // large plate
StencilBuilder.registerStencil(TinkerTools.woodPattern, 10); // frying pan
StencilBuilder.registerStencil(TinkerTools.woodPattern, 11); // battlesign
StencilBuilder.registerStencil(TinkerTools.woodPattern, 13); // chisel
StencilBuilder.registerStencil(TinkerTools.woodPattern, 12); // knifeblade
StencilBuilder.registerStencil(TinkerTools.woodPattern, 5); // swordblade
StencilBuilder.registerStencil(TinkerTools.woodPattern, 20); // cleaver blade
StencilBuilder.registerStencil(TinkerTools.woodPattern, 8); // crossbar
StencilBuilder.registerStencil(TinkerTools.woodPattern, 7); // small guard
StencilBuilder.registerStencil(TinkerTools.woodPattern, 6); // wide guard
StencilBuilder.registerStencil(TinkerTools.woodPattern, 25); // arrow head
StencilBuilder.registerStencil(TinkerTools.woodPattern, 24); // fletchling
StencilBuilder.registerStencil(TinkerTools.woodPattern, 23); // bowstring
}
}
@@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
@@ -23,6 +24,7 @@ import tconstruct.common.TProxyCommon;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
import tconstruct.library.crafting.StencilBuilder;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.ToolCore;
import tconstruct.smeltery.TinkerSmeltery;
@@ -63,6 +65,7 @@ public class ToolProxyClient extends ToolProxyCommon
registerManualIcons();
registerManualRecipes();
addToolRenderMappings();
addStencilButtons();
addToolButtons();
}
@@ -325,6 +328,63 @@ public class ToolProxyClient extends ToolProxyCommon
MinecraftForge.EVENT_BUS.unregister(this);
}
void addStencilButtons ()
{
int[][] icons = {
{0,3}, // tool rod
{1,3}, // binding
{8,3}, // large tool rod
{9,3}, // large binding
{0,2}, // pickaxe head
{3,2}, // shovel head
{2,2}, // hatchet head
{8,2}, // scythe
{11,2}, // hammer head
{10,2}, // excavator head
{6,2}, // lumberaxe head
{9,2}, // large plate
{},
{4,2}, // frying pan
{5,2}, // battlesign
{7,3}, // chisel
{},
{7,2}, // knifeblade
{1,2}, // swordblade
{6,3}, // cleaver blade
{},
{4,3}, // crossbar
{3,3}, // small guard
{2,3}, // wide guard
{},
{11,3}, // arrow head
{12,3}, // fletchling
{10,3}, // bowstring
};
int i = 0;
for(ItemStack stack : StencilBuilder.getStencils()) {
// spacer
while(icons[i].length == 0)
{
addStencilButton(0,0, -1);
i++;
}
addStencilButton(icons[i][0], icons[i][1], StencilBuilder.getIndex(stack));
i++;
}
}
void addStencilButton (int xButton, int yButton, int index)
{
TConstructClientRegistry.addStencilButton(xButton, yButton, index, "tinker", "textures/gui/icons.png");
}
static int[][] itemIcons = { new int[] { 0, 3, 0 }, // Repair
new int[] { 1, 4, 0 }, // Pickaxe
new int[] { 2, 5, 0 }, // Shovel
@@ -0,0 +1,50 @@
package tconstruct.tools.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import tconstruct.library.client.StencilGuiElement;
import tconstruct.library.client.ToolGuiElement;
public class GuiButtonStencil extends GuiButton{
/**
* True for pointing right (next page), false for pointing left (previous
* page).
*/
int textureX;
int textureY;
public String texture;
public StencilGuiElement element;
private static ResourceLocation background;
public GuiButtonStencil(int id, int posX, int posY, int texX, int texY, String domain, String tex, StencilGuiElement e)
{
super(id, posX, posY, 18, 18, "");
textureX = texX;
textureY = texY;
texture = tex;
element = e;
background = new ResourceLocation(domain, tex);
}
/**
* Draws this button to the screen.
*/
@Override
public void drawButton (Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
boolean var4 = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(background);
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
int var5 = this.getHoverState(this.field_146123_n);
int index = 18 * getHoverState(field_146123_n);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 144 + index * 2, 234, 18, 18);
this.drawTexturedModalRect(this.xPosition, this.yPosition, textureX * 18, textureY * 18, 18, 18);
}
}
}
@@ -11,6 +11,9 @@ import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.TConstruct;
import tconstruct.library.client.StencilGuiElement;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
import tconstruct.library.crafting.StencilBuilder;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.inventory.PatternShaperContainer;
@@ -20,13 +23,13 @@ import tconstruct.util.network.PatternTablePacket;
public class StencilTableGui extends GuiContainer
{
StencilTableLogic logic;
int patternIndex;
int activeButton;
public StencilTableGui(InventoryPlayer inventoryplayer, StencilTableLogic shaper, World world, int x, int y, int z)
{
super(new PatternShaperContainer(inventoryplayer, shaper));
logic = shaper;
patternIndex = 0;
activeButton = 0;
}
@Override
@@ -62,24 +65,42 @@ public class StencilTableGui extends GuiContainer
public void initGui ()
{
super.initGui();
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
int bpr = 4; // buttons per row!
int cornerX = this.guiLeft - 22*bpr;
int cornerY = this.guiTop + 2;
this.buttonList.clear();
/*ToolGuiElement repair = TConstruct.toolButtons.get(0);
GuiButtonTool repairButton = new GuiButtonTool(0, cornerX - 110, cornerY, repair.buttonIconX, repair.buttonIconY, repair.texture); // Repair
repairButton.enabled = false;
this.buttonList.add(repairButton);*/
this.buttonList.add(new GuiButton(0, cornerX - 120, cornerY, 120, 20, (StatCollector.translateToLocal("gui.stenciltable1"))));
this.buttonList.add(new GuiButton(1, cornerX - 120, cornerY + 20, 120, 20, (StatCollector.translateToLocal("gui.stenciltable2"))));
//for (int iter = 0; iter < TConstructContent.patternOutputs.length; iter++)
//{
int id = 0;
for (int iter = 0; iter < TConstructClientRegistry.stencilButtons.size(); iter++)
{
StencilGuiElement element = TConstructClientRegistry.stencilButtons.get(iter);
if(element.stencilIndex == -1)
continue;
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture,
element);
this.buttonList.add(button);
}
/*ToolGuiElement element = TConstruct.toolButtons.get(iter);
GuiButtonTool button = new GuiButtonTool(iter, cornerX - 110 + 22 * (iter % 5), cornerY + 22 * (iter / 5), element.buttonIconX, element.buttonIconY, element.texture); // Repair
this.buttonList.add(button);*/
//}
// secondary buttons, yay!
// these are to use for other mods :I
cornerX = this.guiLeft + this.xSize + 4;
for (int iter = 0; iter < TConstructClientRegistry.stencilButtons2.size(); iter++)
{
StencilGuiElement element = TConstructClientRegistry.stencilButtons2.get(iter);
if(element.stencilIndex == -1)
continue;
GuiButtonStencil button = new GuiButtonStencil(id++, cornerX + 22 * (iter % bpr), cornerY + 22 * (iter / bpr), element.buttonIconX, element.buttonIconY, element.domain, element.texture,
element);
this.buttonList.add(button);
}
// get the correct setting :I
if(logic.getStackInSlot(1) != null)
activeButton = StencilBuilder.getIndex(logic.getStackInSlot(1));
setActiveButton(activeButton);
}
@Override
@@ -88,28 +109,30 @@ public class StencilTableGui extends GuiContainer
ItemStack pattern = logic.getStackInSlot(0);
if (pattern != null && StencilBuilder.isBlank(pattern))
{
if (button.id == 0)
int id = ((GuiButtonStencil)button).element.stencilIndex;
ItemStack stack = StencilBuilder.getStencil(id);
if(stack != null)
{
patternIndex++;
if (patternIndex >= StencilBuilder.getStencilCount() - 1)
patternIndex = 0;
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
else if (button.id == 1)
{
patternIndex--;
if (patternIndex < 0)
patternIndex = StencilBuilder.getStencilCount() - 2;
}
ItemStack stack = StencilBuilder.getStencil(patternIndex);
logic.setInventorySlotContents(1, stack);
updateServer(stack);
}
setActiveButton(button.id);
}
private void setActiveButton(int id)
{
// deactivate old button
((GuiButton)this.buttonList.get(activeButton)).enabled = true;
// update active button
activeButton = id;
// activate the button
((GuiButton)this.buttonList.get(activeButton)).enabled = false;
}
void updateServer (ItemStack stack)
{
TConstruct.packetPipeline.sendToServer(new PatternTablePacket(logic.xCoord, logic.yCoord, logic.zCoord, stack));
}
}