From d4a5a02f91c355580689277349b1afc61d65250b Mon Sep 17 00:00:00 2001 From: Mr_Little_Kitty Date: Sat, 3 Dec 2016 02:08:28 -0800 Subject: [PATCH] Added Gui list view titles and fixed some small gui bugs --- .../snitch_master/gui/EditSnitchListsGui.java | 13 ++++++++- .../snitch_master/gui/EditSnitchesGui.java | 15 +++++++++-- .../snitch_master/gui/MainGui.java | 4 +-- .../snitch_master/gui/NewSnitchListGui.java | 2 +- .../snitch_master/gui/SnitchGui.java | 6 ++--- .../snitch_master/gui/SnitchListsGui.java | 27 ++++++++++--------- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchListsGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchListsGui.java index cfdfa95..f31a195 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchListsGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchListsGui.java @@ -16,6 +16,9 @@ public class EditSnitchListsGui extends GuiScreen { private GuiScreen parentScreen; + private final String title; + private final int titleWidth; + private SnitchListsGui snitchListGUI; private SnitchMaster snitchMaster; private Collection snitchLists; @@ -26,12 +29,14 @@ public class EditSnitchListsGui extends GuiScreen private static final int RENDER_ON_BUTTON_WIDTH = GuiConstants.SMALL_BUTTON_WIDTH; private static final int RENDER_OFF_BUTTON_WIDTH = GuiConstants.SMALL_BUTTON_WIDTH; - public EditSnitchListsGui(GuiScreen guiscreen, SnitchMaster snitchMaster, Collection listsToDisplay, boolean fullList) + public EditSnitchListsGui(GuiScreen guiscreen, SnitchMaster snitchMaster, Collection listsToDisplay, boolean fullList, String title) { this.parentScreen = guiscreen; this.snitchMaster = snitchMaster; this.fullList = fullList; snitchLists = listsToDisplay; + this.title = title; + this.titleWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(title); } @Override @@ -39,6 +44,12 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); this.snitchListGUI.drawScreen(mouseX, mouseY, partialTicks); + + int yPos = 16 - (mc.fontRendererObj.FONT_HEIGHT/2); + int xPos = (this.width/2) - (titleWidth/2); + + mc.fontRendererObj.drawString(title, xPos ,yPos, 16777215); + super.drawScreen(mouseX, mouseY, partialTicks); } diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchesGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchesGui.java index ea636cb..0d1abf3 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchesGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/EditSnitchesGui.java @@ -2,6 +2,7 @@ import com.gmail.nuclearcat1337.snitch_master.snitches.Snitch; import com.gmail.nuclearcat1337.snitch_master.snitches.SnitchList; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -15,6 +16,9 @@ */ public class EditSnitchesGui extends GuiScreen { + private final String title; + private final int titleWidth; + private GuiScreen parentScreen; private Collection snitches; @@ -23,10 +27,12 @@ public class EditSnitchesGui extends GuiScreen private static final int DONE_BUTTON_WIDTH = GuiConstants.SMALL_BUTTON_WIDTH*3; //private static final int NEW_BUTTON_WIDTH = GuiConstants.SMALL_BUTTON_WIDTH; - public EditSnitchesGui(GuiScreen guiscreen, Collection snitches) + public EditSnitchesGui(GuiScreen guiscreen, Collection snitches, String title) { this.parentScreen = guiscreen; this.snitches = snitches; + this.title = title; + this.titleWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(title); } @Override @@ -36,8 +42,13 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) this.snitchesGui.drawScreen(mouseX, mouseY, partialTicks); super.drawScreen(mouseX, mouseY, partialTicks); + int yPos = 16 - (mc.fontRendererObj.FONT_HEIGHT/2); + int xPos = (this.width/2) - (titleWidth/2); + + mc.fontRendererObj.drawString(title, xPos ,yPos, 16777215); + int index = snitchesGui.getSlotIndexFromScreenCoords(mouseX,mouseY); - if(index > 0) + if(index >= 0) { Snitch snitch = snitchesGui.getSnitchForIndex(index); if(mouseX >= snitchesGui.getCoordsLeftBound() && mouseX <= snitchesGui.getCoordsRightBound()) diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/MainGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/MainGui.java index 6a7f611..d30ace7 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/MainGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/MainGui.java @@ -88,10 +88,10 @@ public void actionPerformed(GuiButton button) // break; case 2: //"View Snitch Lists" this.mc.gameSettings.saveOptions(); - this.mc.displayGuiScreen(new EditSnitchListsGui(this,snitchMaster,snitchMaster.getSnitchLists().asCollection(),true)); + this.mc.displayGuiScreen(new EditSnitchListsGui(this,snitchMaster,snitchMaster.getSnitchLists().asCollection(),true, "All Snitch Lists")); break; case 3: //"View Snitches" - this.mc.displayGuiScreen(new EditSnitchesGui(this,snitchMaster.getSnitches())); + this.mc.displayGuiScreen(new EditSnitchesGui(this,snitchMaster.getSnitches(),"All Snitches")); break; case 4: //"Done" this.mc.displayGuiScreen((GuiScreen) null); diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java index 6acd0f0..e0961f1 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/NewSnitchListGui.java @@ -227,7 +227,7 @@ public void actionPerformed(GuiButton button) //Handles any things that need to happen when lists change. (saving, etc) lists.snitchListChanged(); - Minecraft.getMinecraft().displayGuiScreen(new EditSnitchListsGui(null,snitchMaster,snitchMaster.getSnitchLists().asCollection(),true)); + Minecraft.getMinecraft().displayGuiScreen(new EditSnitchListsGui(null,snitchMaster,snitchMaster.getSnitchLists().asCollection(),true, "All Snitch Lists")); break; } } diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchGui.java index 58f07e8..ee753d4 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchGui.java @@ -102,7 +102,7 @@ public SnitchGui(EditSnitchesGui parentScreen, Collection snitchesToDisp protected void drawListHeader(int xPosition, int yPosition, Tessellator tessalator) { - yPosition = yPosition + this.getSlotHeight(); + yPosition = yPosition;// + this.getSlotHeight(); String root = ChatFormatting.UNDERLINE + "" + ChatFormatting.BOLD; int nameWidth = mc.fontRendererObj.getStringWidth(root+ NAME_HEADER); int groupWidth = mc.fontRendererObj.getStringWidth(root+ GROUP_HEADER); @@ -214,7 +214,7 @@ private SnitchEntry(Snitch snitch) public void drawEntry(int slotIndex, int xPosition, int yPosition, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { - int yFinal = yPosition + (slotHeight + mc.fontRendererObj.FONT_HEIGHT); /// 2; + int yFinal = yPosition + ((slotHeight - mc.fontRendererObj.FONT_HEIGHT) /2); //+ (slotHeight + mc.fontRendererObj.FONT_HEIGHT); /// 2; int workingWidth = (width-xPosition); int xPos = xPosition + (workingWidth/2) - (entryWidth/2); @@ -285,7 +285,7 @@ public boolean mousePressed(int index, int xPos, int yPos, int mouseEvent, int r if(snitch.getAttachedSnitchLists().size() > 0) { //Sorry im cheating by using the static instance but im lazy and its only 1 line right? right? :( - mc.displayGuiScreen(new EditSnitchListsGui(cancelToScreen, SnitchMaster.instance, snitch.getAttachedSnitchLists(), false)); + mc.displayGuiScreen(new EditSnitchListsGui(cancelToScreen, SnitchMaster.instance, snitch.getAttachedSnitchLists(), false, "Snitch Lists for Snitch: "+(snitch.getSnitchName().isEmpty() ? "[Not Named]" : snitch.getSnitchName()))); return true; } } diff --git a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchListsGui.java b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchListsGui.java index 421fd27..c42e717 100644 --- a/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchListsGui.java +++ b/src/main/java/com/gmail/nuclearcat1337/snitch_master/gui/SnitchListsGui.java @@ -212,52 +212,53 @@ private SnitchListEntry(SnitchList snitchList, int index) public void drawEntry(int slotIndex, int xPosition, int yPosition, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { - int yFinal = yPosition + (slotHeight + SnitchListsGui.this.mc.fontRendererObj.FONT_HEIGHT) / 2; + int stringYPosition = yPosition + ((slotHeight - SnitchListsGui.this.mc.fontRendererObj.FONT_HEIGHT) / 2); + yPosition = yPosition + ((slotHeight - GuiConstants.STANDARD_BUTTON_HEIGHT) /2); int workingWidth = (width-xPosition); int xPos = xPosition + (workingWidth/2) - (entryWidth/2); - upButton.yPosition = yPosition + (upButton.height/3); + upButton.yPosition = yPosition;// + (upButton.height/3); upButton.xPosition = xPos; xPos += upButton.width + GuiConstants.SMALL_SEPARATION_DISTANCE; toggleRenderButton.displayString = snitchList.shouldRenderSnitches() ? "On" : "Off"; - toggleRenderButton.yPosition = yPosition + (toggleRenderButton.height/3); + toggleRenderButton.yPosition = yPosition;// + (toggleRenderButton.height/3); toggleRenderButton.xPosition = xPos; xPos += toggleRenderButton.width + GuiConstants.SMALL_SEPARATION_DISTANCE; - downButton.yPosition = yPosition + (downButton.height/3); + downButton.yPosition = yPosition;// + (downButton.height/3); downButton.xPosition = xPos; xPos += downButton.width + (GuiConstants.STANDARD_SEPARATION_DISTANCE*2); - this.upButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); - this.downButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); - this.toggleRenderButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); - int stringWidth = mc.fontRendererObj.getStringWidth(snitchList.getListName()); int namePos = xPos + (NAME_COLUMN_WIDTH /2) - (stringWidth/2); - mc.fontRendererObj.drawString(snitchList.getListName(), namePos ,yFinal,16777215); + mc.fontRendererObj.drawString(snitchList.getListName(), namePos , stringYPosition,16777215); xPos += NAME_COLUMN_WIDTH + (GuiConstants.STANDARD_SEPARATION_DISTANCE*2); - editColorButton.yPosition = yPosition + (editColorButton.height/3); + editColorButton.yPosition = yPosition;// + (editColorButton.height/3); editColorButton.xPosition = xPos; xPos += EDIT_COLOR_BUTTON_WIDTH + (GuiConstants.STANDARD_SEPARATION_DISTANCE*2); - editQualifierButton.yPosition = yPosition + (editQualifierButton.height/3); + editQualifierButton.yPosition = yPosition;// + (editQualifierButton.height/3); editQualifierButton.xPosition = xPos; xPos += EDIT_QUALIFIER_BUTTON_WIDTH + (GuiConstants.STANDARD_SEPARATION_DISTANCE*2); - viewSnitchesButton.yPosition = yPosition +(viewSnitchesButton.height/3); + viewSnitchesButton.yPosition = yPosition;// +(viewSnitchesButton.height/3); viewSnitchesButton.xPosition = xPos; + + this.upButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); + this.downButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); + this.toggleRenderButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); this.editColorButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); this.editQualifierButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); this.viewSnitchesButton.drawButton(SnitchListsGui.this.mc, mouseX, mouseY); @@ -308,7 +309,7 @@ public boolean mousePressed(int index, int xPos, int yPos, int mouseEvent, int r if(snitches.isEmpty()) viewSnitchesButton.displayString = "None"; else - mc.displayGuiScreen(new EditSnitchesGui(cancelToScreen,snitches)); + mc.displayGuiScreen(new EditSnitchesGui(cancelToScreen,snitches,"Snitches for Snitch List: "+snitchList.getListName())); return true; }