Skip to content

Commit

Permalink
Rework stencil table GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Aug 20, 2014
1 parent 5dd0e0c commit bd997ab
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 41 deletions.
Binary file modified resources/assets/tinker/textures/gui/icons.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/main/java/tconstruct/library/client/GuiElement.java
@@ -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;
}
}
11 changes: 11 additions & 0 deletions src/main/java/tconstruct/library/client/StencilGuiElement.java
@@ -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;
}
}
Expand Up @@ -13,6 +13,8 @@

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>();
Expand Down Expand Up @@ -103,6 +105,27 @@ public static void registerManualSmeltery (String name, ItemStack output, ItemSt
}

//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);
Expand Down
Expand Up @@ -46,7 +46,7 @@ public static void registerStencil(ItemStack pattern)
*/
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;
Expand Down
45 changes: 38 additions & 7 deletions src/main/java/tconstruct/tools/TinkerTools.java
Expand Up @@ -355,13 +355,7 @@ public void preInit (FMLPreInitializationEvent event)

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
Expand Down Expand Up @@ -945,4 +939,41 @@ void registerMaterials ()

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
}
}
60 changes: 60 additions & 0 deletions src/main/java/tconstruct/tools/ToolProxyClient.java
Expand Up @@ -6,6 +6,7 @@
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;
Expand All @@ -23,6 +24,7 @@
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;
Expand Down Expand Up @@ -63,6 +65,7 @@ public void initialize ()
registerManualIcons();
registerManualRecipes();
addToolRenderMappings();
addStencilButtons();
addToolButtons();
}

Expand Down Expand Up @@ -325,6 +328,63 @@ public void onSound (SoundLoadEvent event)
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
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/tconstruct/tools/gui/GuiButtonStencil.java
@@ -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);
}
}
}

0 comments on commit bd997ab

Please sign in to comment.