Skip to content

Commit

Permalink
Added description for snitches, fixed textbox bug, and scaled snitch …
Browse files Browse the repository at this point in the history
…text
  • Loading branch information
MrLittleKitty committed Jan 8, 2017
1 parent 3a2ab49 commit 68e75c6
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
public class SnitchListQualifier
{
public static final int MAX_QUALIFIER_TEXT_LENGTH = Integer.MAX_VALUE;

private static final String CULL_TIME_TOKEN = "cull_time";
private static final String WORLD_TOKEN = "world";
private static final String GROUP_TOKEN = "group";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public EditColorGui(GuiScreen cancelToScreen, Color baseColor, String titleText,
this.titleWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(titleText);
}

private static final int MAX_COLOR_TEXT_LENGTH = 3;

public void initGui()
{
greenWidth = mc.fontRendererObj.getStringWidth("Green");
Expand All @@ -51,24 +53,21 @@ public void initGui()
int rgbBoxWidth = (width-GuiConstants.STANDARD_SEPARATION_DISTANCE)/3;
int buttonWidth = (width-GuiConstants.STANDARD_SEPARATION_DISTANCE)/3;

this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
redBox.setClamp(0,255);
redBox.setMaxStringLength(3);
redBox.setText(Integer.toString(baseColor.getRedInt()));
redBox.setFocused(true);

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);

this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
greenBox.setClamp(0,255);
greenBox.setMaxStringLength(3);
greenBox.setText(Integer.toString(baseColor.getGreenInt()));

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);

this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
blueBox.setClamp(0,255);
blueBox.setMaxStringLength(3);
blueBox.setText(Integer.toString(baseColor.getBlueInt()));

this.buttonList.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gmail.nuclearcat1337.snitch_master.gui;

import net.minecraft.client.gui.GuiScreen;

/**
* Created by Mr_Little_Kitty on 1/7/2017.
*/
public class EditDescriptionGui extends GuiScreen
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void initGui()
int xPos = (this.width/2) - (GuiConstants.LARGE_TEXBOX_LENGTH/2);
int yPos = (this.height/2) - (GuiConstants.STANDARD_TEXTBOX_HEIGHT) - (GuiConstants.STANDARD_SEPARATION_DISTANCE/2);

stringBox = new TextBox(editString,fontRendererObj,xPos,yPos,GuiConstants.LARGE_TEXBOX_LENGTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false);
stringBox.setMaxStringLength(maxStringLength);
stringBox = new TextBox(editString,fontRendererObj,xPos,yPos,GuiConstants.LARGE_TEXBOX_LENGTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,maxStringLength);
stringBox.setFocused(true);

this.buttonList.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public NewSnitchListGui(GuiScreen cancelToScreen, SnitchMaster snitchMaster)
this.snitchMaster = snitchMaster;
}

private static final int MAX_NAME_TEXT_LENGTH = 20;
private static final int MAX_COLOR_TEXT_LENGTH = 3;

public void initGui()
{
qualifierBoxWidth = mc.fontRendererObj.getStringWidth(SnitchList.MAX_NAME_CHARACTERS+"WWW"); //TODO---Idk this is kind of just an arbitrary width
Expand All @@ -56,33 +59,28 @@ public void initGui()
int yPos = (this.height / 2) - (GuiConstants.STANDARD_BUTTON_HEIGHT*3) - (GuiConstants.STANDARD_SEPARATION_DISTANCE) ;
int xPos = (this.width/2) - (nameBoxWidth/2);

nameBox = new TextBox("",fontRendererObj,xPos,yPos,nameBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false);
nameBox.setMaxStringLength(20);
nameBox = new TextBox("",fontRendererObj,xPos,yPos,nameBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,MAX_NAME_TEXT_LENGTH);
nameBox.setFocused(true);

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);
xPos = nameBox.xPosition;

this.qualifierBox = new TextBox("",fontRendererObj,xPos,yPos,qualifierBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false);
qualifierBox.setMaxStringLength(100);
this.qualifierBox = new TextBox("",fontRendererObj,xPos,yPos,qualifierBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,false,false,SnitchListQualifier.MAX_QUALIFIER_TEXT_LENGTH);

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);

this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.redBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
redBox.setClamp(0,255);
redBox.setMaxStringLength(3);

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);

this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.greenBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
greenBox.setClamp(0,255);
greenBox.setMaxStringLength(3);

yPos += (GuiConstants.STANDARD_BUTTON_HEIGHT + GuiConstants.SMALL_SEPARATION_DISTANCE);

this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
this.blueBox = new TextBox("",fontRendererObj,xPos,yPos,rgbBoxWidth,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,MAX_COLOR_TEXT_LENGTH);
blueBox.setClamp(0,255);
blueBox.setMaxStringLength(3);

this.buttonList.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ public void initGui()
int yPos = (this.height / 2) - (GuiConstants.STANDARD_TEXTBOX_HEIGHT/2);
int xPos = (this.width/2) - GuiConstants.STANDARD_SEPARATION_DISTANCE/2 - BOX_AND_BUTTON_WIDTH;

startIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
startIndexBox.setMaxStringLength(3);
startIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,3);
startIndexBox.setClamp(0,999);
startIndexBox.setFocused(true);

xPos += (startIndexBox.width + GuiConstants.STANDARD_SEPARATION_DISTANCE);

stopIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false);
stopIndexBox.setMaxStringLength(3);
stopIndexBox = new TextBox("",fontRendererObj,xPos,yPos, BOX_AND_BUTTON_WIDTH,GuiConstants.STANDARD_TEXTBOX_HEIGHT,true,false,3);
stopIndexBox.setClamp(0,999);

yPos += GuiConstants.STANDARD_TEXTBOX_HEIGHT + GuiConstants.STANDARD_SEPARATION_DISTANCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gmail.nuclearcat1337.snitch_master.gui.controls;

import net.minecraft.client.gui.GuiControls;
import net.minecraft.client.gui.GuiTextField;

/**
* Created by Mr_Little_Kitty on 1/7/2017.
*/
public class ControlGui
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class TextBox extends GuiTextField
private Integer clampedMinimum;
private Integer clampedMaximum;

public TextBox(String text, FontRenderer renderer, int x, int y, int width, int height, boolean numeric, boolean allowNegative)
public TextBox(String text, FontRenderer renderer, int x, int y, int width, int height, boolean numeric, boolean allowNegative, int maxStringLength)
{
super(0,renderer,x,y,width,height);
super.setMaxStringLength(maxStringLength);
super.setText(text);
this.number = numeric;
this.allowNegative = allowNegative;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.gmail.nuclearcat1337.snitch_master.gui.snitchtable;

import com.gmail.nuclearcat1337.snitch_master.gui.tables.TableColumn;
import com.gmail.nuclearcat1337.snitch_master.snitches.Snitch;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

import java.util.List;

/**
* Created by Mr_Little_Kitty on 1/7/2017.
*/
public class SnitchDescriptionColumn implements TableColumn<Snitch>
{
private static Minecraft mc;

public SnitchDescriptionColumn()
{
mc = Minecraft.getMinecraft();
}

@Override
public GuiButton[] prepareEntry(Snitch item)
{
return null;
}

@Override
public String getColumnName()
{
return "Description";
}

@Override
public boolean doBoundsCheck()
{
return true;
}

@Override
public void clicked(Snitch item, boolean leftClick, int xPos, int yPos, GuiButton[] buttons, GuiScreen parentScreen, int slotIndex)
{

}

@Override
public void released(Snitch item, int xPos, int yPos, GuiButton[] buttons, GuiScreen parentScreen,int slotIndex)
{

}

@Override
public void draw(Snitch snitch, int xPos, int yPos, int columnWidth, int slotHeight, GuiButton[] buttons,int slotIndex, int mouseX, int mouseY)
{
String text = snitch.getDescription() == null ? "No Description" : "Hover to view";
int yFinal = yPos + ((slotHeight - mc.fontRendererObj.FONT_HEIGHT) /2);
int nameWidth = mc.fontRendererObj.getStringWidth(text);
int namePos = xPos + (columnWidth /2) - (nameWidth/2);
mc.fontRendererObj.drawString(text, namePos ,yFinal, 16777215);
}

@Override
public int getDrawWidth(Snitch snitch)
{
String text = snitch.getDescription() == null ? "No Description" : "Hover to view";
return mc.fontRendererObj.getStringWidth(text);
}


@Override
public List<String> hover(Snitch snitch, int xPos, int yPos)
{
return snitch.getDescription();
}

@Override
public boolean canSort()
{
return false;
}

@Override
public int compare(Snitch snitch, Snitch other)
{
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ protected Collection<Pair<TableColumn<Snitch>,Boolean>> initializeColumns()

columns.add(packageValues(new SnitchNameColumn(), true));
columns.add(packageValues(new SnitchGroupColumn(), true));
columns.add(packageValues(new SnitchDescriptionColumn(), true));
columns.add(packageValues(new SnitchCullTimeColumn(), false));

columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.X), true));
columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Y), true));
columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Z), true));
columns.add(packageValues(new SnitchWorldColumn(), true));
columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.X), false));
columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Y), false));
columns.add(packageValues(new SnitchCoordinateColumn(SnitchCoordinateColumn.CoordinateType.Z), false));
columns.add(packageValues(new SnitchWorldColumn(), false));

columns.add(packageValues(new SnitchDistanceColumn(), true));
columns.add(packageValues(new TableButtonColumn<>("Lists", "View", VIEW_LISTS_BUTTON_WIDTH, viewListsClick), true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public void renderSnitches(RenderWorldLastEvent event)
}
}

private static final float MIN_TEXT_RENDER_SCALE = 0.0075f;
private static final float MAX_TEXT_RENDER_SCALE = 0.04f;

private static final float SCALE_STEP = (MAX_TEXT_RENDER_SCALE-MIN_TEXT_RENDER_SCALE)/TEXT_RENDER_DISTANCE;


private static void RenderFloatingText(String[] text, float x, float y, float z, int color, boolean renderBlackBackground, float partialTickTime)
{
//Thanks to Electric-Expansion mod for the majority of this code
Expand All @@ -114,8 +120,8 @@ private static void RenderFloatingText(String[] text, float x, float y, float z,
float dx = x-playerX;
float dy = y-playerY;
float dz = z-playerZ;
//float distance = (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
float scale = 0.03f;
float distance = (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
float scale = MIN_TEXT_RENDER_SCALE + (distance*SCALE_STEP);//.01f; //Min font scale for max text render distance

GL11.glColor4f(1f, 1f, 1f, 0.5f);
GL11.glPushMatrix();
Expand Down Expand Up @@ -147,20 +153,8 @@ private static void RenderFloatingText(String[] text, float x, float y, float z,
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer worldrenderer = tessellator.getBuffer();

//GL11.glDisable(GL11.GL_TEXTURE_2D);
GlStateManager.disableTexture2D();

/* OLD 1.8 rendering code
//worldrenderer.startDrawingQuads();
worldrenderer.func_181668_a(7, DefaultVertexFormats.field_181709_i); //field_181707_g maybe?
GlStateManager.color(0.0F, 0.0F, 0.0F, 0.5F);
worldrenderer.putPosition(-stringMiddle - 1, -1 + 0, 0.0D);
worldrenderer.putPosition(-stringMiddle - 1, 8 + lineHeight*text.length-lineHeight, 0.0D);
worldrenderer.putPosition(stringMiddle + 1, 8 + lineHeight*text.length-lineHeight, 0.0D);
worldrenderer.putPosition(stringMiddle + 1, -1 + 0, 0.0D);
*/

//This code taken from 1.8.8 net.minecraft.client.renderer.entity.Render.renderLivingLabel()
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldrenderer.pos((double) (-stringMiddle - 1), (double) (-1), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
Expand All @@ -169,7 +163,7 @@ private static void RenderFloatingText(String[] text, float x, float y, float z,
worldrenderer.pos((double) (stringMiddle + 1), (double) (-1), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();

tessellator.draw();
//GL11.glEnable(GL11.GL_TEXTURE_2D);

GlStateManager.enableTexture2D();
}

Expand Down Expand Up @@ -200,7 +194,6 @@ private void renderBox(int x, int y, int z, int radius, Color color, double alph

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glLineWidth(5.0F);
//GL11.glDisable(GL11.GL_LIGHTING);

GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
Expand Down Expand Up @@ -237,7 +230,6 @@ private void renderBox(int x, int y, int z, int radius, Color color, double alph
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL13.GL_MULTISAMPLE);
//GL11.glEnable(GL11.GL_LIGHTING);

GL11.glPopMatrix();

Expand Down
Loading

0 comments on commit 68e75c6

Please sign in to comment.