Full Imports and Code Format Optimization

This commit is contained in:
Kam committed 2025-03-12 20:12:01 -04:00
1 parent 250edf099c
commit 6815f579a7
1192 files changed
+60344 -62167

No files matched your search

@@ -11,11 +11,10 @@ import java.util.*;
import static noppes.npcs.client.gui.util.GuiNPCInterface.resizingActive;
public class GuiCustomScroll extends GuiScreen
{
public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png");
public class GuiCustomScroll extends GuiScreen {
public static final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/misc.png");
public List<String> list;
public final HashMap<String,Integer> colors = new HashMap<>();
public final HashMap<String, Integer> colors = new HashMap<>();
public int id;
public int guiLeft = 0;
@@ -35,15 +34,14 @@ public class GuiCustomScroll extends GuiScreen
public boolean multipleSelection = false;
private ICustomScrollListener listener;
private boolean isSorted = true;
public boolean visible = true;
private boolean selectable = true;
public boolean visible = true;
private boolean selectable = true;
private boolean hasSubGUI = false;
private int lastClickedItem;
private long lastClickedTime = 0;
public GuiCustomScroll(GuiScreen parent, int id)
{
public GuiCustomScroll(GuiScreen parent, int id) {
width = 176;
height = 166;
xSize = 176;
@@ -55,45 +53,44 @@ public class GuiCustomScroll extends GuiScreen
scrollY = 0;
scrollHeight = 0;
isScrolling = false;
if(parent instanceof ICustomScrollListener)
listener = (ICustomScrollListener) parent;
if (parent instanceof ICustomScrollListener)
listener = (ICustomScrollListener) parent;
this.list = new ArrayList<String>();
this.id = id;
}
public GuiCustomScroll(GuiScreen parent, int id, boolean multipleSelection)
{
this(parent,id);
this.multipleSelection = multipleSelection;
public GuiCustomScroll(GuiScreen parent, int id, boolean multipleSelection) {
this(parent, id);
this.multipleSelection = multipleSelection;
}
public GuiCustomScroll(GuiScreen parent, int id, int allowHover)
{
this(parent,id);
public GuiCustomScroll(GuiScreen parent, int id, int allowHover) {
this(parent, id);
this.hoverableText = true;
}
public void setSize(int x, int y){
ySize = y;
xSize = x;
public void setSize(int x, int y) {
ySize = y;
xSize = x;
listHeight = 14 * list.size();
if(listHeight > 0)
scrollHeight = (int) (((double)(ySize - 8) / (double)listHeight) * (ySize-8));
if (listHeight > 0)
scrollHeight = (int) (((double) (ySize - 8) / (double) listHeight) * (ySize - 8));
else
scrollHeight = Integer.MAX_VALUE;
scrollHeight = Integer.MAX_VALUE;
maxScrollY = listHeight - (ySize - 8) - 1;
}
public void drawScreen(int i, int j, float f, int mouseScrolled){
if(!visible)
return;
public void drawScreen(int i, int j, float f, int mouseScrolled) {
if (!visible)
return;
drawGradientRect(guiLeft, guiTop, xSize+guiLeft ,ySize+guiTop, 0xc0101010, 0xd0101010);
drawGradientRect(guiLeft, guiTop, xSize + guiLeft, ySize + guiTop, 0xc0101010, 0xd0101010);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(resource);
if(scrollHeight < ySize - 8){
if (scrollHeight < ySize - 8) {
drawScrollBar();
}
GL11.glPushMatrix();
@@ -103,155 +100,143 @@ 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);
drawItems();
if(oldHover != hover){
if (oldHover != hover) {
oldHover = hover;
hoverCount = 0;
}
else {
if(hoverCount < 110)
} else {
if (hoverCount < 110)
hoverCount++;
}
if(!hasSubGUI && hover != -1 && hoverableText && hoverCount > 100){
if (!hasSubGUI && 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);
super.drawHoveringText(lines, i - guiLeft, j - guiTop, this.fontRendererObj);
GL11.glDisable(GL11.GL_LIGHTING);
}
GL11.glPopMatrix();
if(scrollHeight < ySize - 8){
i -= guiLeft;
j -= guiTop;
if(Mouse.isButtonDown(0) && !resizingActive){
if(i >= xSize-9 && i < xSize-4 && j >= 4 && j < ySize){
if (scrollHeight < ySize - 8) {
i -= guiLeft;
j -= guiTop;
if (Mouse.isButtonDown(0) && !resizingActive) {
if (i >= xSize - 9 && i < xSize - 4 && j >= 4 && j < ySize) {
isScrolling = true;
}
}
else
} else
isScrolling = false;
if(isScrolling){
scrollY = (((j - 8) * listHeight) / (ySize-8)) - (scrollHeight);
if(scrollY < 0){
if (isScrolling) {
scrollY = (((j - 8) * listHeight) / (ySize - 8)) - (scrollHeight);
if (scrollY < 0) {
scrollY = 0;
}
if(scrollY > maxScrollY){
if (scrollY > maxScrollY) {
scrollY = maxScrollY;
}
}
if(mouseScrolled != 0){
scrollY += mouseScrolled > 0?-14:14;
if(scrollY > maxScrollY)
if (mouseScrolled != 0) {
scrollY += mouseScrolled > 0 ? -14 : 14;
if (scrollY > maxScrollY)
scrollY = maxScrollY;
if(scrollY < 0)
if (scrollY < 0)
scrollY = 0;
}
}
}
public void drawHover(int i, int j){
if(!visible)
public void drawHover(int i, int j) {
if (!visible)
return;
if(!hoverableText)
if (!hoverableText)
return;
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft, guiTop, 0.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if(oldHover != hover){
if (oldHover != hover) {
oldHover = hover;
hoverCount = 0;
}
else {
if(hoverCount < 110)
} else {
if (hoverCount < 110)
hoverCount++;
}
if(!hasSubGUI && hover != -1 && hoverableText && hoverCount > 100){
if (!hasSubGUI && 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);
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)
{
public boolean mouseInOption(int i, int j, int k) {
int l = 4;
int i1 = ((14 * k + 4) - scrollY);
return i >= l - 1 && i < l + xSize - 11 && j >= i1 - 1 && j < i1 + 8;
}
protected void drawItems()
{
for(int i = 0; i < list.size(); i++)
{
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));
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);
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);
}
}
}
public String getSelected(){
if(selected == -1 || selected >= list.size() )
return null;
return list.get(selected);
public String getSelected() {
if (selected == -1 || selected >= list.size())
return null;
return list.get(selected);
}
private int getMouseOver(int i, int j){
i -= guiLeft;
j -= guiTop;
//fontRenderer.drawString(".", i , j, 0xffffff);
if(i >= 4 && i < xSize - 4 && j >= 4 && j < ySize)
{
for(int j1 = 0; j1 < list.size(); j1++)
{
if(!mouseInOption(i, j, j1))
{
private int getMouseOver(int i, int j) {
i -= guiLeft;
j -= guiTop;
//fontRenderer.drawString(".", i , j, 0xffffff);
if (i >= 4 && i < xSize - 4 && j >= 4 && j < ySize) {
for (int j1 = 0; j1 < list.size(); j1++) {
if (!mouseInOption(i, j, j1)) {
continue;
}
@@ -260,32 +245,31 @@ public class GuiCustomScroll extends GuiScreen
}
return -1;
return -1;
}
public void mouseClicked(int i, int j, int k)
{
if(resizingActive)
public void mouseClicked(int i, int j, int k) {
if (resizingActive)
return;
if(k != 0 || hover < 0)
return;
if(multipleSelection) {
if(selectedList.contains(list.get(hover))) {
selectedList.remove(list.get(hover));
} else {
selectedList.add(list.get(hover));
}
} else {
if(hover >= 0)
selected = hover;
hover = -1;
}
if (k != 0 || hover < 0)
return;
if (multipleSelection) {
if (selectedList.contains(list.get(hover))) {
selectedList.remove(list.get(hover));
} else {
selectedList.add(list.get(hover));
}
} else {
if (hover >= 0)
selected = hover;
hover = -1;
}
if(listener != null) {
if (listener != null) {
long time = System.currentTimeMillis();
listener.customScrollClicked(i, j, k, this);
if(selected >= 0 && selected == lastClickedItem && time - lastClickedTime < 500) {
if (selected >= 0 && selected == lastClickedItem && time - lastClickedTime < 500) {
listener.customScrollDoubleClicked(list.get(selected), this);
}
lastClickedTime = time;
@@ -293,94 +277,99 @@ public class GuiCustomScroll extends GuiScreen
}
}
private void drawScrollBar()
{
private void drawScrollBar() {
int i = guiLeft + xSize - 9;
int j = guiTop + (int)(((double)scrollY / (double)listHeight) * (double)(ySize-8)) + 4;
int j = guiTop + (int) (((double) scrollY / (double) listHeight) * (double) (ySize - 8)) + 4;
int k = j;
drawTexturedModalRect(i, k, xSize, 9, 5, 1);
for(k++; k < (j + scrollHeight) - 1; k++)
{
for (k++; k < (j + scrollHeight) - 1; k++) {
drawTexturedModalRect(i, k, xSize, 10, 5, 1);
}
drawTexturedModalRect(i, k, xSize, 11, 5, 1);
}
public boolean hasSelected() {
return selected >= 0;
}
public boolean hasSelected() {
public void setList(List<String> list){
isSorted = true;
return selected >= 0;
}
public void setList(List<String> list) {
isSorted = true;
list.removeAll(Collections.singleton(null));
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
this.list = list;
setSize(xSize,ySize);
}
this.list = list;
setSize(xSize, ySize);
}
public void setList(List<String> list, boolean ascending, boolean caseOrder){
public void setList(List<String> list, boolean ascending, boolean caseOrder) {
isSorted = true;
if(caseOrder){
if (caseOrder) {
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
}
if(!ascending){
if (!ascending) {
Collections.reverse(list);
}
this.list = list;
setSize(xSize,ySize);
setSize(xSize, ySize);
}
public void setUnsortedList(List<String> list){
isSorted = false;
this.list = list;
setSize(xSize,ySize);
}
public void replace(String old, String name) {
String select = getSelected();
list.remove(old);
list.add(name);
if(isSorted)
Collections.sort(list,String.CASE_INSENSITIVE_ORDER);
if(old.equals(select))
select = name;
public void setUnsortedList(List<String> list) {
isSorted = false;
this.list = list;
setSize(xSize, ySize);
}
selected = list.indexOf(select);
setSize(xSize,ySize);
}
public void setSelected(String name) {
selected = list.indexOf(name);
}
public void clear() {
public void replace(String old, String name) {
String select = getSelected();
list.remove(old);
list.add(name);
if (isSorted)
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
if (old.equals(select))
select = name;
selected = list.indexOf(select);
setSize(xSize, ySize);
}
public void setSelected(String name) {
selected = list.indexOf(name);
}
public void clear() {
list = new ArrayList<String>();
selected = -1;
scrollY = 0;
setSize(xSize,ySize);
}
public List<String> getList() {
return list;
}
public HashSet<String> getSelectedList() {
return selectedList;
}
public void setSelectedList(HashSet<String> selectedList) {
this.selectedList = selectedList;
}
public GuiCustomScroll setUnselectable() {
selectable = false;
return this;
}
selected = -1;
scrollY = 0;
setSize(xSize, ySize);
}
public List<String> getList() {
return list;
}
public HashSet<String> getSelectedList() {
return selectedList;
}
public void setSelectedList(HashSet<String> selectedList) {
this.selectedList = selectedList;
}
public GuiCustomScroll setUnselectable() {
selectable = false;
return this;
}
public boolean isMouseOver(int x, int y) {
return x >= this.guiLeft && x <= this.guiLeft + this.xSize && y >= this.guiTop && y <= this.guiTop + this.ySize;
}
public void resetScroll(){
public void resetScroll() {
scrollY = 0;
}
public void updateSubGUI(boolean hasSubGUI)
{
public void updateSubGUI(boolean hasSubGUI) {
this.hasSubGUI = hasSubGUI;
}
}