mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 01:29:05 +00:00
Fix Hoverable now being the last and top layer and wrap to shrink size
This commit is contained in:
1 parent
743ef08ad3
commit
61763e620e
5 files changed
+104
-33
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package kamkeel.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TextSplitter {
|
||||
public static List<String> splitText(String input, int maxSegmentLength) {
|
||||
List<String> 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<String> lines = splitText(longText, maxLineLength);
|
||||
|
||||
for (String line : lines) {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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){
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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<String> 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<String> 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<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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user