Reformated code, minor tweaks.

This commit is contained in:
0xSeb
2015-11-05 15:17:05 +01:00
parent 6744bf304a
commit 9b88779bc7
5 changed files with 92 additions and 65 deletions
@@ -1,6 +1,7 @@
package de.skate702.craftingkeys.config; package de.skate702.craftingkeys.config;
import de.skate702.craftingkeys.util.LanguageLocalizer; import de.skate702.craftingkeys.util.LanguageLocalizer;
import de.skate702.craftingkeys.util.Logger;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -35,16 +36,6 @@ public class GuiConfig extends GuiScreen {
private int buttonInventoryID = 306; private int buttonInventoryID = 306;
private int buttonVillagerID = 307; private int buttonVillagerID = 307;
public enum GuiType{
ANVIL,
FURNACE,
BREWINGSTAND,
ENCHANTMENT,
INVENTORY,
VILAGER,
DISPENSER;
}
@Override @Override
public void initGui() { public void initGui() {
@@ -61,42 +52,52 @@ public class GuiConfig extends GuiScreen {
addStandardButtons(); addStandardButtons();
} }
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) { public void drawScreen(int mouseX, int mouseY, float partialTicks) {
//Setting up //Setting up
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
drawDefaultBackground(); //drawWorldBackground(0); drawDefaultBackground(); //drawWorldBackground(0);
//Title //Title
drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.title"), width / 2, height / 2 - 115, pureWhite.getRGB()); drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.title"), width / 2, height / 2 - 115, pureWhite.getRGB());
// Info-text and fake line // Info-text and fake line
drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.description"), width / 2, height / 2 - 10, pureWhite.getRGB()); drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.description"), width / 2, height / 2 - 10, pureWhite.getRGB());
drawCenteredString(fontRendererObj, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", width / 2, height / 2 + 8, lightGray.getRGB()); drawCenteredString(fontRendererObj, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", width / 2, height / 2 + 8, lightGray.getRGB());
drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.usage"), width / 2, height / 2 + 23, pureWhite.getRGB()); drawCenteredString(fontRendererObj, LanguageLocalizer.localize("craftingkeys.config.usage"), width / 2, height / 2 + 23, pureWhite.getRGB());
// Key Info // Key Info
drawCenteredString(fontRendererObj, "Stack Key", guiBasePosition + 130, height / 2 - 96, pureWhite.getRGB()); drawCenteredString(fontRendererObj, "Stack Key", guiBasePosition + 130, height / 2 - 96, pureWhite.getRGB());
drawCenteredString(fontRendererObj, "Drop Key", guiBasePosition + 130, height / 2 - 58, pureWhite.getRGB()); drawCenteredString(fontRendererObj, "Drop Key", guiBasePosition + 130, height / 2 - 58, pureWhite.getRGB());
//Draw line to let it look better //Draw line to let it look better
drawHorizontalLine(guiBasePosition - 86, guiBasePosition + 85, height / 2 - 20, pureWhite.getRGB()); drawHorizontalLine(guiBasePosition - 86, guiBasePosition + 85, height / 2 - 20, pureWhite.getRGB());
drawCraftingTable(); drawCraftingTable();
// Insert Gui by selected Type // Insert Gui by selected Type
if(guiShowType == GuiType.FURNACE){
genFurnaceInfo(); switch (guiShowType) {
}else if(guiShowType == GuiType.BREWINGSTAND){
genBrewingStandInfo(); case FURNACE:
}else if(guiShowType == GuiType.DISPENSER){ genFurnaceInfo();
genDispenserInfo(); break;
}else if(guiShowType == GuiType.ENCHANTMENT){ case BREWINGSTAND:
genEnchantmentInfo(); genBrewingStandInfo();
}else if(guiShowType == GuiType.INVENTORY){ break;
genInventoryInfo(); case DISPENSER:
}else if(guiShowType == GuiType.VILAGER){ genDispenserInfo();
genVillagerInfo(); break;
}else if(guiShowType == GuiType.ANVIL){ case ENCHANTMENT:
genAnvilInfo(); genEnchantmentInfo();
break;
case INVENTORY:
genInventoryInfo();
break;
case VILAGER:
genVillagerInfo();
break;
case ANVIL:
genAnvilInfo();
break;
} }
//Draw line to let it look better //Draw line to let it look better
drawHorizontalLine(guiShowBasePosition - 86, guiShowBasePosition + 85, guiShowBaseHeight + 80, lightGray.getRGB()); drawHorizontalLine(guiShowBasePosition - 86, guiShowBasePosition + 85, guiShowBaseHeight + 80, lightGray.getRGB());
@@ -107,38 +108,38 @@ public class GuiConfig extends GuiScreen {
@Override @Override
public void actionPerformed(GuiButton button) { public void actionPerformed(GuiButton button) {
if (button.id == buttonAbortID) { if (button.id == buttonAbortID) {
Logger.warn("actionPerformed(b)", "Not implemented yet");
}else if (button.id == buttonSaveID) { } else if (button.id == buttonSaveID) {
Logger.warn("actionPerformed(b)", "Not implemented yet");
}else if(button.id == buttonInventoryID) { } else if (button.id == buttonInventoryID) {
guiShowType = GuiType.INVENTORY; guiShowType = GuiType.INVENTORY;
}else if(button.id == buttonEnchantmentID){ } else if (button.id == buttonEnchantmentID) {
guiShowType = GuiType.ENCHANTMENT; guiShowType = GuiType.ENCHANTMENT;
}else if(button.id == buttonBrewingstandID){ } else if (button.id == buttonBrewingstandID) {
guiShowType = GuiType.BREWINGSTAND; guiShowType = GuiType.BREWINGSTAND;
}else if(button.id == buttonDispenserID){ } else if (button.id == buttonDispenserID) {
guiShowType = GuiType.DISPENSER; guiShowType = GuiType.DISPENSER;
}else if(button.id == buttonFurnaceID){ } else if (button.id == buttonFurnaceID) {
guiShowType = GuiType.FURNACE; guiShowType = GuiType.FURNACE;
}else if(button.id == buttonVillagerID){ } else if (button.id == buttonVillagerID) {
guiShowType = GuiType.VILAGER; guiShowType = GuiType.VILAGER;
}else if(button.id == buttonAnvilID){ } else if (button.id == buttonAnvilID) {
guiShowType = GuiType.ANVIL; guiShowType = GuiType.ANVIL;
} }
} }
private void drawCraftingTable() {
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/crafting_table.png"));
drawTexturedModalRect(guiBasePosition - 86, height / 2 - 100, 1, 0, 174, 80);
drawString(fontRendererObj, "Crafting Table", guiBasePosition - 33, height / 2 - 100 + 3, lightGray.getRGB());
}
//GUI GENERATORS: //GUI GENERATORS:
/* /*
TODO: Create strings for showing the Keybindings TODO: Create strings for showing the Keybindings
*/ */
private void drawCraftingTable(){
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/crafting_table.png"));
drawTexturedModalRect(guiBasePosition - 86, height / 2 - 100, 1, 0, 174, 80);
drawString(fontRendererObj, "Crafting Table", guiBasePosition - 33, height / 2 - 100 + 3, lightGray.getRGB());
}
private void genFurnaceInfo() { private void genFurnaceInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/furnace.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/furnace.png"));
@@ -164,43 +165,42 @@ public class GuiConfig extends GuiScreen {
drawCenteredString(fontRendererObj, "D", guiBasePosition - 86 + 109, guiShowBaseHeight + 50, highlight.getRGB()); drawCenteredString(fontRendererObj, "D", guiBasePosition - 86 + 109, guiShowBaseHeight + 50, highlight.getRGB());
} }
private void genEnchantmentInfo(){ private void genEnchantmentInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/enchanting_table.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/enchanting_table.png"));
drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80); drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80);
drawString(fontRendererObj, "Enchanting", guiShowBasePosition - 20, guiShowBaseHeight + 3, lightGray.getRGB()); drawString(fontRendererObj, "Enchanting", guiShowBasePosition - 20, guiShowBaseHeight + 3, lightGray.getRGB());
} }
private void genAnvilInfo(){ private void genAnvilInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/anvil.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/anvil.png"));
drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80); drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80);
drawString(fontRendererObj, "Anvil", guiShowBasePosition - 17, guiShowBaseHeight + 3, lightGray.getRGB()); drawString(fontRendererObj, "Anvil", guiShowBasePosition - 17, guiShowBaseHeight + 3, lightGray.getRGB());
} }
private void genVillagerInfo(){ private void genVillagerInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/villager.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/villager.png"));
drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80); drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80);
drawString(fontRendererObj, "Villager", guiShowBasePosition - 17, guiShowBaseHeight + 3, lightGray.getRGB()); drawString(fontRendererObj, "Villager", guiShowBasePosition - 17, guiShowBaseHeight + 3, lightGray.getRGB());
} }
private void genInventoryInfo(){ private void genInventoryInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/inventory.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));
drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80); drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80);
drawString(fontRendererObj, "Inventory", guiShowBasePosition - 20, guiShowBaseHeight + 3, lightGray.getRGB()); drawString(fontRendererObj, "Inventory", guiShowBasePosition - 20, guiShowBaseHeight + 3, lightGray.getRGB());
} }
private void genDispenserInfo(){ private void genDispenserInfo() {
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F); GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/dispenser.png")); mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/dispenser.png"));
drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80); drawTexturedModalRect(guiShowBasePosition - 86, guiShowBaseHeight, 1, 0, 174, 80);
drawString(fontRendererObj, "Dispenser", guiShowBasePosition - 23, guiShowBaseHeight + 3, lightGray.getRGB()); drawString(fontRendererObj, "Dispenser", guiShowBasePosition - 23, guiShowBaseHeight + 3, lightGray.getRGB());
} }
private void addStandardButtons() {
private void addStandardButtons(){
// Add control buttons // Add control buttons
buttonList.add((new GuiButton(buttonAbortID, width - 53, 3, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.abort")))); buttonList.add((new GuiButton(buttonAbortID, width - 53, 3, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.abort"))));
buttonList.add((new GuiButton(buttonSaveID, width - 53, 26, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.save")))); buttonList.add((new GuiButton(buttonSaveID, width - 53, 26, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.save"))));
@@ -211,16 +211,16 @@ public class GuiConfig extends GuiScreen {
buttonList.add((new GuiButton(buttonInventoryID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight, 70, 20, "Inventory"))); buttonList.add((new GuiButton(buttonInventoryID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight, 70, 20, "Inventory")));
buttonList.add((new GuiButton(buttonFurnaceID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 20 + 1, 70, 20, "Furnace"))); buttonList.add((new GuiButton(buttonFurnaceID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 20 + 1, 70, 20, "Furnace")));
buttonList.add((new GuiButton(buttonBrewingstandID, guiShowBasePosition + 86 + 5, guiShowBaseHeight, 90, 20, "Brewing Stand"))); buttonList.add((new GuiButton(buttonBrewingstandID, guiShowBasePosition + 86 + 5, guiShowBaseHeight, 90, 20, "Brewing Stand")));
buttonList.add((new GuiButton(buttonDispenserID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 2*20 + 2*1, 70, 20, "Dispenser"))); buttonList.add((new GuiButton(buttonDispenserID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 2 * 20 + 2, 70, 20, "Dispenser")));
buttonList.add((new GuiButton(buttonVillagerID, guiShowBasePosition + 86 + 5, guiShowBaseHeight + 20 + 1, 70, 20, "Villager"))); buttonList.add((new GuiButton(buttonVillagerID, guiShowBasePosition + 86 + 5, guiShowBaseHeight + 20 + 1, 70, 20, "Villager")));
buttonList.add((new GuiButton(buttonEnchantmentID, guiShowBasePosition + 86 + 5, guiShowBaseHeight + 2*20 + 2*1, 70, 20, "Enchanting"))); buttonList.add((new GuiButton(buttonEnchantmentID, guiShowBasePosition + 86 + 5, guiShowBaseHeight + 2 * 20 + 2, 70, 20, "Enchanting")));
buttonList.add((new GuiButton(buttonAnvilID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 3*20 + 3*1, 70, 20, "Anvil"))); buttonList.add((new GuiButton(buttonAnvilID, guiShowBasePosition - 86 - 70 - 5, guiShowBaseHeight + 3 * 20 + 3, 70, 20, "Anvil")));
//Adding Crafting Buttons //Adding Crafting Buttons
addCraftingButtons(); addCraftingButtons();
} }
private void addCraftingButtons(){ private void addCraftingButtons() {
buttonList.add((new GuiButton(0, guiBasePosition - 60, height / 2 - 87, 20, 20, "Q"))); buttonList.add((new GuiButton(0, guiBasePosition - 60, height / 2 - 87, 20, 20, "Q")));
buttonList.add((new GuiButton(1, guiBasePosition - 41, height / 2 - 87, 20, 20, "W"))); buttonList.add((new GuiButton(1, guiBasePosition - 41, height / 2 - 87, 20, 20, "W")));
buttonList.add((new GuiButton(2, guiBasePosition - 22, height / 2 - 87, 20, 20, "E"))); buttonList.add((new GuiButton(2, guiBasePosition - 22, height / 2 - 87, 20, 20, "E")));
@@ -233,6 +233,16 @@ public class GuiConfig extends GuiScreen {
buttonList.add((new GuiButton(9, guiBasePosition + 34, height / 2 - 67, 22, 20, "Ctrl"))); buttonList.add((new GuiButton(9, guiBasePosition + 34, height / 2 - 67, 22, 20, "Ctrl")));
} }
public enum GuiType {
ANVIL,
FURNACE,
BREWINGSTAND,
ENCHANTMENT,
INVENTORY,
VILAGER,
DISPENSER
}
//TODO:Get strings from language file(Localizer)... //TODO:Get strings from language file(Localizer)...
//TODO:Add things that make this GUI an Config ... :P //TODO:Add things that make this GUI an Config ... :P
} }
@@ -3,13 +3,27 @@ package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Logger;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
/**
* Manages a Anvil GUI Inventory.
*/
public class AnvilManager extends ContainerManager { public class AnvilManager extends ContainerManager {
private static AnvilManager instance = null; private static AnvilManager instance = null;
/**
* Creates a new Anvil Manager with the given container.
*
* @param container The container from a crafting GUI
*/
private AnvilManager(Container container) { private AnvilManager(Container container) {
super(container); super(container);
} }
/**
* Returns a Anvil Manager Instance operating on the given container
*
* @param container A container from a GUI
* @return manager-singleton
*/
public static AnvilManager getInstance(Container container) { public static AnvilManager getInstance(Container container) {
if (instance == null) { if (instance == null) {
instance = new AnvilManager(container); instance = new AnvilManager(container);
@@ -21,7 +35,7 @@ public class AnvilManager extends ContainerManager {
@Override @Override
protected int specificKeyToSlotIndex() { protected int specificKeyToSlotIndex() {
return mapKeyToSlot(-1, -1, -1, 0, 1, -1 , -1, -1, -1); return mapKeyToSlot(-1, -1, -1, 0, 1, -1, -1, -1, -1);
} }
@Override @Override
@@ -46,7 +60,10 @@ public class AnvilManager extends ContainerManager {
@Override @Override
protected void interact() { protected void interact() {
Logger.info("interact()", "Clicked on Anvil Output.");
leftClick(2); leftClick(2);
} }
@@ -4,13 +4,12 @@ import net.minecraft.util.StatCollector;
public class LanguageLocalizer { public class LanguageLocalizer {
/** /**
*If another language than de_DE or en_US is selected the English one is used... * If another language than de_DE or en_US is selected the English one is used...
* *
* @param unloc The unlocalized string which is in the definded in the language file * @param unloc The unlocalized string which is in the definded in the language file
* @return localized The localized String * @return localized The localized String
*/ */
public static String localize(String unloc){ public static String localize(String unloc) {
String localized = StatCollector.translateToLocal(unloc); return StatCollector.translateToLocal(unloc);
return localized;
} }
} }
@@ -29,8 +29,8 @@ de.skate702.craftingkeys.warn.line2=Es gibt noch viele Fehler, und es fehlen noc
de.skate702.craftingkeys.warn.line3=Mehr Info's findest du auf: https://github.com/0xSeb/CraftingKeys! de.skate702.craftingkeys.warn.line3=Mehr Info's findest du auf: https://github.com/0xSeb/CraftingKeys!
craftingkeys.config.title=Crafting Keys Konfiguration craftingkeys.config.title=Crafting Keys Konfiguration
craftingkeys.config.description=Konfiguriere hier deine Tastenbelegung und klicke dann auf "Sichern". craftingkeys.config.description=Konfiguriere hier deine Tastenbelegung und klicke dann auf "Speichern".
craftingkeys.config.button.save=Sichern craftingkeys.config.button.save=Speichern
craftingkeys.config.button.abort=Abbruch craftingkeys.config.button.abort=Abbruch
craftingkeys.config.usage=Waehle das GUI, fuer das du die Tastenbelegung sehen moechtest. craftingkeys.config.usage=Waehle die Oberflaeche fuer die du die Tastenbelegung sehen moechtest.
@@ -34,3 +34,4 @@ craftingkeys.config.button.save=Save
craftingkeys.config.button.abort=Abort craftingkeys.config.button.abort=Abort
craftingkeys.config.usage=Use the buttons to select the GUI which you want to see the Keybindings for! craftingkeys.config.usage=Use the buttons to select the GUI which you want to see the Keybindings for!
# TODO: Same style for the keys