diff --git a/src/main/java/kamkeel/util/TextSplitter.java b/src/main/java/kamkeel/util/TextSplitter.java new file mode 100644 index 000000000..30092cf92 --- /dev/null +++ b/src/main/java/kamkeel/util/TextSplitter.java @@ -0,0 +1,40 @@ +package kamkeel.util; + +import java.util.ArrayList; +import java.util.List; + +public class TextSplitter { + public static List splitText(String input, int maxSegmentLength) { + List result = new ArrayList<>(); + + while (input.length() > maxSegmentLength) { + int spaceIndex = input.lastIndexOf(" ", maxSegmentLength); + if (spaceIndex == -1) { + // No space found within the maxSegmentLength, so split at the exact length. + result.add(input.substring(0, maxSegmentLength)); + input = input.substring(maxSegmentLength); + } else { + // Split at the last space within maxSegmentLength. + result.add(input.substring(0, spaceIndex)); + input = input.substring(spaceIndex + 1); // Skip the space. + } + } + + if (!input.isEmpty()) { + result.add(input); + } + + return result; + } + + public static void main(String[] args) { + String longText = "This is a very long string that needs to be split into multiple lines based on a maximum line length of 30 characters."; + int maxLineLength = 30; + + List lines = splitText(longText, maxLineLength); + + for (String line : lines) { + System.out.println(line); + } + } +} \ No newline at end of file diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 4b1b28d18..70751237b 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -444,13 +444,13 @@ public class NoppesUtilServer { Quest quest = QuestController.Instance.quests.get(questId); if(quest == null) continue; - map.put(quest.category.title + ": " + quest.title + "(Active quest)",questId); + map.put(quest.category.title + ": " + quest.title + " (Active)",questId); } for(int questId : data.finishedQuests.keySet()){ Quest quest = QuestController.Instance.quests.get(questId); if(quest == null) continue; - map.put(quest.category.title + ": " + quest.title + "(Finished quest)",questId); + map.put(quest.category.title + ": " + quest.title + " (Finished)",questId); } } else if(type == EnumPlayerData.Transport){ diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 846e6cd00..d56eaf2b0 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -43,6 +43,14 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou { super.initGui(); + if(catScroll == null){ + catScroll = new GuiCustomScroll(this,0, 0); + catScroll.setSize(143, 185); + } + catScroll.guiLeft = guiLeft + 64; + catScroll.guiTop = guiTop + 4; + this.addScroll(catScroll); + if(dialogScroll == null){ dialogScroll = new GuiCustomScroll(this,1, 0); dialogScroll.setSize(143, 185); @@ -51,13 +59,6 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou dialogScroll.guiTop = guiTop + 4; this.addScroll(dialogScroll); - if(catScroll == null){ - catScroll = new GuiCustomScroll(this,0, 0); - catScroll.setSize(143, 185); - } - catScroll.guiLeft = guiLeft + 64; - catScroll.guiTop = guiTop + 4; - this.addScroll(catScroll); addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 64, guiTop + 4 + 3 + 185, 143, 20, catSearch)); this.addButton(new GuiNpcButton(44,guiLeft + 3, guiTop + 8, 58, 20, "gui.categories")); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 0774e4e11..28e336450 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.util; +import kamkeel.util.TextSplitter; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.RenderHelper; @@ -100,20 +101,28 @@ public class GuiCustomScroll extends GuiScreen GL11.glTranslatef(guiLeft, guiTop, 0.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - if(selectable){ + if(selectable) hover = getMouseOver(i,j); - if(oldHover != hover){ - oldHover = hover; - hoverCount = 0; - } - else { - if(hoverCount < 110) - hoverCount++; - } - } drawItems(); - + + if(oldHover != hover){ + oldHover = hover; + hoverCount = 0; + } + else { + if(hoverCount < 110) + hoverCount++; + } + + if(hover != -1 && hoverableText && hoverCount > 100){ + String displayString = StatCollector.translateToLocal(list.get(hover)); + GL11.glColor4f(1, 1, 1, 1); + List lines = TextSplitter.splitText(displayString, 30); + super.drawHoveringText(lines, i-guiLeft, j-guiTop, this.fontRendererObj); + GL11.glDisable(GL11.GL_LIGHTING); + } + GL11.glPopMatrix(); if(scrollHeight < ySize - 8){ i -= guiLeft; @@ -146,6 +155,37 @@ public class GuiCustomScroll extends GuiScreen } } + public void drawHover(int i, int j, float f, int mouseScrolled){ + if(!visible) + return; + + if(!hoverableText) + return; + + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft, guiTop, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + if(oldHover != hover){ + oldHover = hover; + hoverCount = 0; + } + else { + if(hoverCount < 110) + hoverCount++; + } + + if(hover != -1 && hoverableText && hoverCount > 100){ + String displayString = StatCollector.translateToLocal(list.get(hover)); + GL11.glColor4f(1, 1, 1, 1); + List lines = TextSplitter.splitText(displayString, 30); + super.drawHoveringText(lines, i-guiLeft, j-guiTop, this.fontRendererObj); + GL11.glDisable(GL11.GL_LIGHTING); + } + + GL11.glPopMatrix(); + } + public boolean mouseInOption(int i, int j, int k) { int l = 4; @@ -187,15 +227,6 @@ public class GuiCustomScroll extends GuiScreen } else if(i == hover){ fontRendererObj.drawString(text, j , k, 0x00ff00); - if(hoverableText && hoverCount > 100){ - GL11.glColor4f(1, 1, 1, 1); - List lines = new ArrayList(); - 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); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 445e22974..3bc929dec 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -252,15 +252,14 @@ public abstract class GuiNPCInterface extends GuiScreen tf.drawTextBox(i, j); } for(GuiCustomScroll scroll : scrolls.values()) - if(!scroll.hoverableText){ - scroll.drawScreen(i, j, f, hasSubGui()?0:this.mouseWheel); - } + 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); + scroll.drawHover(i, j, f, hasSubGui()?0:this.mouseWheel); } if(subgui != null) subgui.drawScreen(i,j,f);