public class Panel {
private Category category;
private int posX, posY, width, height;
private boolean selected;
private int startX, startY;
private ArrayList<Module> modules = new ArrayList<>(); // Modules which is ui
public Panel(Category category, int posX, int posY) {
// Sets poses, sizes and category
this.category = category;
this.posX = posX;
this.posY = posY;
this.width = 100; // you can change its value
this.height = 30; // and this you can change
int offset = posY + height;
for(Module module : getModulesByCategory(category)) { // module which abstract
Module uiModule = new Module(this, module, posX, offset); // (Panel parent, Module module, int posX, int posY), argument module is abstract
modues.add(uiModule);
offset += uiModule.getHeight() + 3; // 3 is indentation Y
}
}
// draw the panel and modules
public void drawScreen(int mouseX, int mouseY) {
// Title background
Gui.drawRect(posX, posY, width, height, new Color(51, 79, 214).getRGB());
// Title text
mc.fontRendererObj.drawCenteredString(category.name(), posX + (width / 2), posY + (height / 2), -1); // Color -1 return white
// Draw modules if category selected
if(selected) {
for(Module module : modules) {
module.drawScreen(mouseX, mouseY);
}
}
}
public void mouseClicked(int mouseX, int mouseY, int mouseClicked) {
if(isHovered(mouseX, mouseY, posX, posY, width, height) && mouseClicked == 1) { // mouseClicked 0 = LMB, 1 = RMB
selected = !selected;
} else if(isHovered(mouseX, mouseY, posX, posY, width, height) && mouseClicked == 0) {
startX = mouseX;
startY = mouseY;
}
for(Module module : modules) {
modules.mouseClicked(mouseX, mouseY, mouseClicked);
}
}
// allow drag category
public void mouseClickMove(int mouseX, int mouseY, int mouseClicked) {
if(isHovered(mouseX, mouseY, posX, posY, width, height) && mouseClicked == 0) {
this.posX += mouseX - startX;
this.posY += mouseY - startY;
for(Module module : modules) {
module.setPos(module.getPosX() + mouseX - startX, module.getPosY() + mouseY - startY); // (int posX, int posY)
}
startX = mouseX;
startY = mouseY;
}
}
// Method which return modules by category, if you haven't
public ArrayList<Module> getModulesByCategory(Category category) {
ArrayList<Module> modules = new ArrayList<>();
for(Module module : Client.INSTANCE.getModuleManager().getModules()) { // Module which abstract and all modules extends from him
if(module.getCategory() == category)
modules.add(module);
}
return modules;
}
public boolean isHovered(int mouseX, int mouseY, int posX, int posY, int width, int height) {
return (mouseX > posX && mouseX < posX + width) && (mouseY > posY && mouseY < posY + height);
}
public void calculateHeight() {
for(int i = 1; i < getModulesByCategory(category).size(); i++) {
modules.get(i).setPosY(modules.get(i - 1).getPosY() + modules.get(i - 1).getHeight() + 3);
}
}
}