use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.
the class GeneralConfigGui method initGui.
@Override
public void initGui() {
super.initGui();
reg((edit = new GuiButtonIcon(1, new ResourceLocation("textures/chromahud/iconsheet.png"), 5, 0, 1, .4f)), button -> {
// Open Gui for editing element
if (currentElement != null) {
Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(currentElement, mod));
}
});
((GuiButtonIcon) edit).setOutline(true);
reg(new GuiButton(2, 2, ResolutionUtil.current().getScaledHeight() - 22, 100, 20, "New"), (guiButton) -> {
DisplayElement blank = DisplayElement.blank();
ChromaHUDApi.getInstance().getElements().add(blank);
Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(blank, mod));
});
edit.visible = false;
}
use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.
the class GeneralConfigGui method handleMouseInput.
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
ScaledResolution current = ResolutionUtil.current();
int i = Mouse.getEventDWheel();
List<DisplayElement> elements = ChromaHUDApi.getInstance().getElements();
if (elements.size() > 0) {
if (i < 0) {
if (currentElement == null) {
currentElement = elements.get(0);
} else {
int i1 = elements.indexOf(currentElement);
i1++;
if (i1 > elements.size() - 1)
i1 = 0;
currentElement = elements.get(i1);
}
} else if (i > 0) {
if (currentElement == null) {
currentElement = elements.get(0);
} else {
int i1 = elements.indexOf(currentElement);
i1--;
if (i1 < 0)
i1 = elements.size() - 1;
currentElement = elements.get(i1);
}
}
}
boolean isOver = false;
for (GuiButton button : buttonList) {
if (button.isMouseOver())
isOver = true;
}
if (!mouseDown && Mouse.isButtonDown(0) && !isOver) {
// Mouse pushed down. Calculate current element
int clickX = Mouse.getX() / current.getScaleFactor();
int clickY = Mouse.getY() / current.getScaleFactor();
boolean found = false;
for (DisplayElement element : mod.getDisplayElements()) {
Dimension dimension = element.getDimensions();
double displayXLoc = current.getScaledWidth_double() * element.getXloc();
if (element.isRightSided())
displayXLoc -= element.getDimensions().getWidth();
double displayYLoc = current.getScaledHeight_double() - current.getScaledHeight_double() * element.getYloc();
if (clickX > displayXLoc && clickX < displayXLoc + dimension.getWidth() && clickY < displayYLoc && clickY > displayYLoc - dimension.getHeight()) {
// Open gui
if (currentElement != null && currentElement == element && pastClick) {
// Safely nuke the fields and deactivate the chroma effect
element.setSelected(false);
currentElement = null;
mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
Hyperium.INSTANCE.getHandlers().getGuiDisplayHandler().setDisplayNextTick(new DisplayElementConfig(element, mod));
return;
}
currentElement = element;
element.setSelected(true);
found = true;
break;
}
}
if (!found) {
if (currentElement != null)
currentElement.setSelected(false);
currentElement = null;
}
}
mouseDown = Mouse.isButtonDown(0);
if (mouseDown) {
pastClick = true;
dTick = 5;
}
}
use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.
the class GeneralConfigGui method drawScreen.
@SuppressWarnings("Duplicates")
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
ScaledResolution current = ResolutionUtil.current();
drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
List<DisplayElement> elementList = mod.getDisplayElements();
elementList.stream().filter(element -> currentElement == null || currentElement != element).forEach(element -> {
ElementRenderer.startDrawing(element);
try {
element.drawForConfig();
} catch (Exception e) {
e.printStackTrace();
}
ElementRenderer.endDrawing(element);
});
if (currentElement != null) {
ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
double offset = currentElement.isRightSided() ? currentElement.getDimensions().getWidth() : 0;
// Left top right bottom
double x1 = currentElement.getXloc() * resolution.getScaledWidth_double() - offset;
double x2 = currentElement.getXloc() * resolution.getScaledWidth_double() + currentElement.getDimensions().getWidth() - offset;
double y1 = currentElement.getYloc() * resolution.getScaledHeight_double();
double y2 = currentElement.getYloc() * resolution.getScaledHeight_double() + currentElement.getDimensions().getHeight();
// Chroma selection background
if (currentElement.isSelected()) {
HyperiumGui.drawChromaBox((int) x1 - 2, (int) y1 - 2, (int) x2 + 2, (int) y2 - 2, 0.2F);
}
ElementRenderer.startDrawing(currentElement);
// Draw the element after the background
currentElement.drawForConfig();
ElementRenderer.endDrawing(currentElement);
// Turns the edit image on
edit.visible = true;
int propX = (int) x1 - 5;
int propY = (int) y1 - 20;
if (propX < 10 || propX > resolution.getScaledWidth() - 200) {
propX = resolution.getScaledWidth() / 2;
}
if (propY > resolution.getScaledHeight() - 5 || propY < 0)
propY = resolution.getScaledHeight() / 2;
edit.xPosition = propX;
edit.yPosition = propY;
// moving the thing
if (Mouse.isButtonDown(0)) {
if (mouseX > x1 - 2 && mouseX < x2 + 2 && mouseY > y1 - 2 && mouseY < y2 + 2 || lastD) {
// inside
double x3 = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
double y3 = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
currentElement.setXloc(currentElement.getXloc() - (lastX - x3) / ((double) ResolutionUtil.current().getScaleFactor()));
currentElement.setYloc(currentElement.getYloc() + (lastY - y3) / ((double) ResolutionUtil.current().getScaleFactor()));
// Math to keep it inside screen
if (currentElement.getXloc() * resolution.getScaledWidth_double() - offset < 0) {
if (currentElement.isRightSided())
currentElement.setXloc(offset / resolution.getScaledWidth_double());
else
currentElement.setXloc(0);
}
if (currentElement.getYloc() < 0)
currentElement.setYloc(0);
if (currentElement.getXloc() * resolution.getScaledWidth() + currentElement.getDimensions().getWidth() - offset > resolution.getScaledWidth()) {
currentElement.setXloc(currentElement.isRightSided() ? 1.0 : (resolution.getScaledWidth_double() - currentElement.getDimensions().getWidth()) / resolution.getScaledWidth_double());
}
if (currentElement.getYloc() * resolution.getScaledHeight() + currentElement.getDimensions().getHeight() > resolution.getScaledHeight()) {
currentElement.setYloc((resolution.getScaledHeight_double() - currentElement.getDimensions().getHeight()) / resolution.getScaledHeight_double());
}
lastD = true;
}
} else {
lastD = false;
}
} else {
edit.visible = false;
}
lastX = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
lastY = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
if (dTick <= 0 && pastClick)
pastClick = false;
if (pastClick)
dTick--;
}
use of cc.hyperium.mods.chromahud.DisplayElement in project Hyperium by HyperiumClient.
the class AddItemsGui method drawScreen.
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
mouseLock = mouseLock && Mouse.isButtonDown(0);
ScaledResolution current = ResolutionUtil.current();
drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
ElementRenderer.startDrawing(target);
if (adding) {
Color defaultColor = new Color(255, 255, 255, 100);
int cursorY = 50 + offset;
drawCenteredString(mc.fontRendererObj, "Click Explore to see examples!", current.getScaledWidth() / 2, cursorY - 30, Color.RED.getRGB());
List<ChromaHUDParser> parsers = ChromaHUDApi.getInstance().getParsers();
for (ChromaHUDParser parser : parsers) {
Map<String, String> names = parser.getNames();
for (Map.Entry<String, String> entry : names.entrySet()) {
String s = entry.getKey();
String text1 = entry.getValue() + "";
drawRect(current.getScaledWidth() / 2 - 80, cursorY, current.getScaledWidth() / 2 + 80, cursorY + 20, defaultColor.getRGB());
int j = Color.RED.getRGB();
int width = 160;
int height = 20;
mc.fontRendererObj.drawString(text1, ((current.getScaledWidth() >> 1) - 80 + (width >> 1) - (mc.fontRendererObj.getStringWidth(text1) >> 1)), cursorY + ((height - 8) >> 1), j, false);
int i = ResolutionUtil.current().getScaledHeight() - (Mouse.getY() / current.getScaleFactor());
if (Mouse.isButtonDown(0) && !mouseLock)
if (i >= cursorY && i <= cursorY + 23) {
int i1 = Mouse.getX() / current.getScaleFactor();
if (i1 >= current.getScaledWidth() / 2 - 80 && i1 <= current.getScaledWidth() / 2 + 80) {
DisplayItem item = ChromaHUDApi.getInstance().parse(s, 0, new JsonHolder().put("type", s));
element.getDisplayItems().add(item);
element.adjustOrdinal();
mc.displayGuiScreen(new EditItemsGui(element, mod));
}
}
cursorY += 23;
}
}
} else {
int cursorY = 50 + offset;
List<ChromaHUDParser> parsers = ChromaHUDApi.getInstance().getParsers();
for (ChromaHUDParser parser : parsers) {
ChromaHUDDescription description = parser.description();
String text = "Items in " + description.getName() + ".";
mc.fontRendererObj.drawString(text, (current.getScaledWidth() - mc.fontRendererObj.getStringWidth(text)) >> 1, cursorY, Color.RED.getRGB(), true);
cursorY += 30;
Map<String, String> names = parser.getNames();
for (Map.Entry<String, String> entry : names.entrySet()) {
String s = entry.getKey();
String text1 = entry.getValue() + ": ";
DisplayElement displayElement = find(s);
if (displayElement == null) {
String text2 = "ERROR LOCATING DISPLAY ELEMENT " + s;
mc.fontRendererObj.drawString(text2, (current.getScaledWidth() - mc.fontRendererObj.getStringWidth(text2)) >> 1, cursorY, Color.RED.getRGB(), true);
cursorY += 15;
continue;
}
Dimension dimensions = displayElement.getDimensions();
int stringWidth = mc.fontRendererObj.getStringWidth(text1);
double totalWidth = dimensions.getWidth() + stringWidth;
double left = (current.getScaledWidth_double() - totalWidth) / 2;
double startDraw = left + stringWidth;
displayElement.setXloc(startDraw / current.getScaledWidth_double());
displayElement.setYloc(((double) cursorY) / current.getScaledHeight_double());
displayElement.drawForConfig();
mc.fontRendererObj.drawString(text1, (float) ((current.getScaledWidth() - totalWidth) / 2), cursorY, Color.RED.getRGB(), true);
cursorY += dimensions.getHeight() + 5;
}
}
}
ElementRenderer.endDrawing(target);
}
Aggregations