Add Hoverable Text to specific scroll List

This commit is contained in:
Kam committed 2023-11-06 19:19:17 -05:00
1 parent 0284ab9a00
commit 2b54c0afd6
15 files changed
+75 -95

No files matched your search

@@ -29,7 +29,7 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData,
{
super.initGui();
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll = new GuiCustomScroll(this,0, 0);
scroll.setSize(165, 208);
}
scroll.guiLeft = guiLeft + 4;
@@ -36,7 +36,7 @@ public class GuiNPCFactionSetup extends GuiNPCInterface2 implements IScrollData,
addButton(new GuiNpcButton(12, guiLeft + 90, guiTop + 64, 80, 20, "faction.points"));
if(scrollFactions == null){
scrollFactions = new GuiCustomScroll(this,0);
scrollFactions = new GuiCustomScroll(this,0,0);
scrollFactions.setSize(180, 200);
}
scrollFactions.guiLeft = guiLeft + 200;
@@ -35,7 +35,7 @@ public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollD
this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
if(scrollAnimations == null){
scrollAnimations = new GuiCustomScroll(this,0);
scrollAnimations = new GuiCustomScroll(this,0, 0);
scrollAnimations.setSize(143, 185);
}
scrollAnimations.guiLeft = guiLeft + 220;
@@ -41,7 +41,7 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr
this.addButton(new GuiNpcButton(6,guiLeft + 340, guiTop + 10, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(7,guiLeft + 340, guiTop + 32, 45, 20, "gui.remove"));
if(scroll == null)
scroll = new GuiCustomScroll(this,0);
scroll = new GuiCustomScroll(this,0,0);
scroll.setSize(160, 180);
scroll.guiLeft = guiLeft + 174;
scroll.guiTop = guiTop + 8;
@@ -43,8 +43,16 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou
{
super.initGui();
if(dialogScroll == null){
dialogScroll = new GuiCustomScroll(this,1, 0);
dialogScroll.setSize(143, 185);
}
dialogScroll.guiLeft = guiLeft + 212;
dialogScroll.guiTop = guiTop + 4;
this.addScroll(dialogScroll);
if(catScroll == null){
catScroll = new GuiCustomScroll(this,0);
catScroll = new GuiCustomScroll(this,0, 0);
catScroll.setSize(143, 185);
}
catScroll.guiLeft = guiLeft + 64;
@@ -58,14 +66,6 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou
this.addButton(new GuiNpcButton(5,guiLeft + 3, guiTop + 61, 58, 20, "gui.remove"));
this.addButton(new GuiNpcButton(6,guiLeft + 3, guiTop + 94, 58, 20, "gui.edit"));
if(dialogScroll == null){
dialogScroll = new GuiCustomScroll(this,1);
dialogScroll.setSize(143, 185);
}
dialogScroll.guiLeft = guiLeft + 212;
dialogScroll.guiTop = guiTop + 4;
this.addScroll(dialogScroll);
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 212, guiTop + 4 + 3 + 185, 143, 20, diagSearch));
this.addButton(new GuiNpcButton(33,guiLeft + 358, guiTop + 8, 58, 20, "dialog.dialogs"));
@@ -34,7 +34,7 @@ public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollDat
this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
if(scrollFactions == null){
scrollFactions = new GuiCustomScroll(this,0);
scrollFactions = new GuiCustomScroll(this,0, 0);
scrollFactions.setSize(143, 185);
}
scrollFactions.guiLeft = guiLeft + 220;
@@ -34,7 +34,7 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
this.addButton(new GuiNpcButton(2,guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll = new GuiCustomScroll(this,0,0);
scroll.setSize(143, 185);
}
scroll.guiLeft = guiLeft + 214;
@@ -48,8 +48,16 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup,
{
super.initGui();
if(questScroll == null){
questScroll = new GuiCustomScroll(this,1, 0);
questScroll.setSize(143, 185);
}
questScroll.guiLeft = guiLeft + 212;
questScroll.guiTop = guiTop + 4;
this.addScroll(questScroll);
if(catScroll == null){
catScroll = new GuiCustomScroll(this,0);
catScroll = new GuiCustomScroll(this,0, 0);
catScroll.setSize(143, 185);
}
catScroll.guiLeft = guiLeft + 64;
@@ -63,14 +71,6 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup,
this.addButton(new GuiNpcButton(5,guiLeft + 3, guiTop + 61, 58, 20, "gui.remove"));
this.addButton(new GuiNpcButton(6,guiLeft + 3, guiTop + 94, 58, 20, "gui.edit"));
if(questScroll == null){
questScroll = new GuiCustomScroll(this,1);
questScroll.setSize(143, 185);
}
questScroll.guiLeft = guiLeft + 212;
questScroll.guiTop = guiTop + 4;
this.addScroll(questScroll);
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 212, guiTop + 4 + 3 + 185, 143, 20, questSearch));
this.addButton(new GuiNpcButton(33,guiLeft + 358, guiTop + 8, 58, 20, "quest.quests"));
@@ -36,7 +36,7 @@ public class GuiNPCManageTags extends GuiNPCInterface2 implements IScrollData,IC
this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
if(scrollTags == null){
scrollTags = new GuiCustomScroll(this,0);
scrollTags = new GuiCustomScroll(this,0, 0);
scrollTags.setSize(143, 185);
}
scrollTags.guiLeft = guiLeft + 220;
@@ -35,7 +35,7 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements IScrollD
public void initGui()
{
super.initGui();
scroll = new GuiCustomScroll(this,0);
scroll = new GuiCustomScroll(this,0, 0);
scroll.setSize(303, 175);
scroll.guiLeft = guiLeft + 4;
scroll.guiTop = guiTop + 16;
@@ -41,7 +41,7 @@ public class GuiNpcManageRecipes extends GuiContainerNPCInterface2 implements IS
super.initGui();
if(scroll == null)
scroll = new GuiCustomScroll(this,0);
scroll = new GuiCustomScroll(this,0,0);
scroll.setSize(130, 180);
scroll.guiLeft = guiLeft + 172;
scroll.guiTop = guiTop + 8;
@@ -33,7 +33,7 @@ public class GuiNpcNaturalSpawns extends GuiNPCInterface2 implements IGuiData, I
public void initGui(){
super.initGui();
if(this.scrollNaturalSpawns == null){
this.scrollNaturalSpawns = new GuiCustomScroll(this,0);
this.scrollNaturalSpawns = new GuiCustomScroll(this,0,0);
this.scrollNaturalSpawns.setSize(143, 185);
}
this.scrollNaturalSpawns.guiLeft = guiLeft + 214;
@@ -1,61 +0,0 @@
package noppes.npcs.client.gui.util;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.GuiNpcMobSpawner;
import noppes.npcs.controllers.data.Tag;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.util.*;
public class GuiButtonScroll extends GuiCustomScroll
{
private HashMap<Integer,GuiNpcButton> scrollButtons = new HashMap<Integer,GuiNpcButton>();
public GuiButtonScroll(GuiScreen parent, int id)
{
super(parent, id);
}
@Override
protected void drawItems()
{
for(int i = 0; i < list.size(); i++)
{
int j = 4;
int k = (14 * i + 4) - scrollY;
if(k >= 4 && k + 12 < ySize)
{
int xOffset = scrollHeight < ySize - 8?0:10;
String displayString = StatCollector.translateToLocal(list.get(i));
String text = "";
float maxWidth = (xSize + xOffset - 8) * 0.8f;
if(fontRendererObj.getStringWidth(displayString) > maxWidth){
for(int h = 0; h < displayString.length(); h++){
char c = displayString.charAt(h);
text += c;
if(fontRendererObj.getStringWidth(text) > maxWidth)
break;
}
if(displayString.length() > text.length())
text += "...";
}
else
text = displayString;
if((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
drawVerticalLine(j-2, k-4, k + 10, 0xffffffff);
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3 , 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k + 10 , 0xffffffff);
fontRendererObj.drawString(text, j , k, 0xffffff);
}
else if(i == hover)
fontRendererObj.drawString(text, j , k, 0x00ff00);
else
fontRendererObj.drawString(text, j , k, 0xffffff);
}
}
}
}
@@ -1,13 +1,18 @@
package noppes.npcs.client.gui.util;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.util.*;
import static noppes.npcs.client.gui.util.GuiHoverText.buttonTextures;
public class GuiCustomScroll extends GuiScreen
{
public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png");
@@ -21,6 +26,9 @@ public class GuiCustomScroll extends GuiScreen
public int selected;
protected HashSet<String> selectedList;
protected int hover;
protected int oldHover;
private int hoverCount = 0;
protected boolean hoverableText = false;
private int listHeight;
protected int scrollY;
protected int maxScrollY;
@@ -55,6 +63,14 @@ public class GuiCustomScroll extends GuiScreen
this(parent,id);
this.multipleSelection = multipleSelection;
}
public GuiCustomScroll(GuiScreen parent, int id, int allowHover)
{
this(parent,id);
this.multipleSelection = multipleSelection;
this.hoverableText = true;
}
public void setSize(int x, int y){
ySize = y;
xSize = x;
@@ -85,9 +101,17 @@ public class GuiCustomScroll extends GuiScreen
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if(selectable)
hover = getMouseOver(i,j);
if(selectable){
hover = getMouseOver(i,j);
if(oldHover != hover){
oldHover = hover;
hoverCount = 0;
}
else {
hoverCount++;
}
}
drawItems();
GL11.glPopMatrix();
@@ -161,14 +185,25 @@ public class GuiCustomScroll extends GuiScreen
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k + 10 , 0xffffffff);
fontRendererObj.drawString(text, j , k, 0xffffff);
}
else if(i == hover)
fontRendererObj.drawString(text, j , k, 0x00ff00);
else if(i == hover){
fontRendererObj.drawString(text, j , k, 0x00ff00);
if(hoverableText && hoverCount > 100){
GL11.glColor4f(1, 1, 1, 1);
List<String> lines = new ArrayList<String>();
lines.add(displayString);
GL11.glTranslatef(j + 2, k + 2, 30);
super.drawHoveringText(Arrays.asList(displayString), 0, 0, this.fontRendererObj);
GL11.glTranslatef(-j - 2, -(k + 2), 30);
GL11.glDisable(GL11.GL_LIGHTING);
}
}
else
fontRendererObj.drawString(text, j , k, 0xffffff);
}
}
}
public String getSelected(){
if(selected == -1 || selected >= list.size() )
return null;
@@ -252,10 +252,16 @@ public abstract class GuiNPCInterface extends GuiScreen
tf.drawTextBox(i, j);
}
for(GuiCustomScroll scroll : scrolls.values())
scroll.drawScreen(i, j, f, hasSubGui()?0:this.mouseWheel);
if(!scroll.hoverableText){
scroll.drawScreen(i, j, f, hasSubGui()?0:this.mouseWheel);
}
for(GuiScreen gui : extra.values())
gui.drawScreen(i, j, f);
super.drawScreen(i, j, f);
for(GuiCustomScroll scroll : scrolls.values())
if(scroll.hoverableText){
scroll.drawScreen(i, j, f, hasSubGui()?0:this.mouseWheel);
}
if(subgui != null)
subgui.drawScreen(i,j,f);
}