just a copy of petroleum right now

This commit is contained in:
jane 2020-12-19 18:30:50 -05:00
commit 183c81258a
88 changed files with 7405 additions and 0 deletions

View file

@ -0,0 +1,70 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.Map;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import pm.j4.petroleum.modules.menu.ModMenu;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.data.ButtonInformation;
import pm.j4.petroleum.util.data.Category;
/**
* The type P mod menu screen.
*/
public class PModMenuScreen extends Screen {
/**
* Instantiates a new P mod menu screen.
*/
public PModMenuScreen() {
super(new TranslatableText("petroleum.modmenu"));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
super.render(matrices, mouseX, mouseY, delta);
}
@Override
protected void init() {
Map<String, ButtonInformation> coordinateMap = ModMenu.getButtons();
coordinateMap.forEach((category, coord) -> {
this.addButton(new PMovableButton((int) (coord.x * this.width),
(int) (coord.y * this.height),
category,
Category.getByCategory(category),
coord.open,
this));
});
}
@Override
public void onClose() {
if (ConfigManager.getConfig().isPresent()) {
ConfigManager.getConfig().get().disableModule("petroleum.modmenu");
this.buttons.forEach(button -> ((PMovableButton) button).updateCoordinate());
ConfigManager.saveGlobalConfig();
}
super.onClose();
}
@Override
public void renderBackground(MatrixStack matrices) {
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
RenderSystem.enableBlend();
buffer.begin(7, VertexFormats.POSITION_COLOR);
buffer.vertex(0, this.height, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(this.width, this.height, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(this.width, 0, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
buffer.vertex(0, 0, 0.0D).color(0.1F, 0.1F, 0.1F, 0.3F).next();
t_1.draw();
RenderSystem.disableBlend();
}
}

View file

@ -0,0 +1,69 @@
package pm.j4.petroleum.gui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.EntryListWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import pm.j4.petroleum.util.module.option.BooleanOption;
import pm.j4.petroleum.util.module.option.ConfigurationOption;
import pm.j4.petroleum.util.module.option.ListOption;
/**
* The type P module config entry.
*/
public class PModuleConfigEntry extends EntryListWidget.Entry<PModuleConfigEntry> {
/**
* The Option.
*/
protected final ConfigurationOption option;
/**
* The Display text.
*/
protected final Text displayText;
/**
* Instantiates a new P module config entry.
*
* @param option the option
* @param text the text
*/
public PModuleConfigEntry(ConfigurationOption option, Text text) {
this.option = option;
this.displayText = text;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.isMouseOver(mouseX, mouseY)) {
return true;
}
return false;
}
@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
if (this.displayText != null) {
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, displayText, x, y, 0xAAAAAA);
}
if (this.option != null) {
//TODO option text box (?)
// option should be centered or otherwise offset
// but not extend past the side of the pane
int fontHeight = MinecraftClient.getInstance().textRenderer.fontHeight;
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, new LiteralText(option.getDescription() + " " + option.getStringValue()), x, y + fontHeight + 4, 0xFFFFFF);
String className = option.getClass().toString();
if (className == BooleanOption.class.toString()) {
// boolean button
}
else if (className == ListOption.class.toString()) {
// handle list
// TODO: determine whether list options are viable,
// considering that it would be easier to split lists into multiple PModuleConfigEntries
}
else {
// string button
}
}
}
}

View file

@ -0,0 +1,115 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.EntryListWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
/**
* The type P module config pane.
*/
public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
/**
* The Parent.
*/
private final POptionsScreen parent;
/**
* The Last selected.
*/
private POptionEntry lastSelected;
/**
* Instantiates a new P module config pane.
*
* @param client the client
* @param width the width
* @param height the height
* @param top the top
* @param bottom the bottom
* @param entryHeight the entry height
* @param screen the screen
*/
public PModuleConfigPane(MinecraftClient client, int width, int height, int top, int bottom, int entryHeight, POptionsScreen screen) {
super(client, width, height, top, bottom, entryHeight);
this.parent = screen;
/**
* The Text renderer.
*/
TextRenderer textRenderer = client.textRenderer;
}
@Override
public PModuleConfigEntry getSelected() {
return null;
}
@Override
public int getRowWidth() {
return this.width - 10;
}
@Override
protected int getScrollbarPositionX() {
return this.width - 6 + left;
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
POptionEntry selectedEntry = parent.getSelected();
if (selectedEntry != lastSelected) {
lastSelected = selectedEntry;
clearEntries();
setScrollAmount(-Double.MAX_VALUE);
String id = lastSelected.getModId();
if (lastSelected != null && id != null && !id.isEmpty()) {
children().addAll(lastSelected.module.getConfigEntries());
}
}
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
RenderSystem.depthFunc(515);
RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA,
GlStateManager.DstFactor.ONE_MINUS_DST_ALPHA,
GlStateManager.SrcFactor.ZERO,
GlStateManager.DstFactor.ONE);
RenderSystem.disableAlphaTest();
RenderSystem.shadeModel(7425);
RenderSystem.disableTexture();
buffer.begin(7, VertexFormats.POSITION_COLOR_TEXTURE);
buffer.vertex(this.left, (this.top + 4), 0.0D).texture(0.0F, 1.0F).color(0, 0, 0, 0).next();
buffer.vertex(this.right, (this.top + 4), 0.0D).texture(1.0F, 1.0F).color(0, 0, 0, 0).next();
buffer.vertex(this.right, this.top, 0.0D).texture(1.0F, 0.0F).color(0, 0, 0, 255).next();
buffer.vertex(this.left, this.top, 0.0D).texture(0.0F, 0.0F).color(0, 0, 0, 255).next();
buffer.vertex(this.left, this.bottom, 0.0D).texture(0.0F, 1.0F).color(0, 0, 0, 255).next();
buffer.vertex(this.right, this.bottom, 0.0D).texture(1.0F, 1.0F).color(0, 0, 0, 255).next();
buffer.vertex(this.right, (this.bottom - 4), 0.0D).texture(1.0F, 0.0F).color(0, 0, 0, 0).next();
buffer.vertex(this.left, (this.bottom - 4), 0.0D).texture(0.0F, 0.0F).color(0, 0, 0, 0).next();
t_1.draw();
buffer.begin(7, VertexFormats.POSITION_COLOR);
buffer.vertex(this.left, this.bottom, 0.0D).color(0, 0, 0, 128).next();
buffer.vertex(this.right, this.bottom, 0.0D).color(0, 0, 0, 128).next();
buffer.vertex(this.right, this.top, 0.0D).color(0, 0, 0, 128).next();
buffer.vertex(this.left, this.top, 0.0D).color(0, 0, 0, 128).next();
t_1.draw();
int rl = this.getRowLeft();
int sc = this.top + 4 - (int) this.getScrollAmount();
this.renderList(matrices, rl, sc, mouseX, mouseY, delta);
RenderSystem.enableTexture();
RenderSystem.shadeModel(7424);
RenderSystem.enableAlphaTest();
RenderSystem.disableBlend();
}
}

View file

@ -0,0 +1,281 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;
import pm.j4.petroleum.mixin.EntryListWidgetAccessor;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P module configuration widget.
*/
public class PModuleConfigurationWidget extends AlwaysSelectedEntryListWidget<POptionEntry> {
/**
* The Parent.
*/
private final POptionsScreen parent;
/**
* The Module id.
*/
private String moduleId = null;
/**
* The Mods.
*/
private List<ModuleBase> mods;
/**
* The Extra mods.
*/
private final Set<ModuleBase> extraMods = new HashSet<>();
/**
* The Scrolling.
*/
private boolean scrolling = false;
/**
* Instantiates a new P module configuration widget.
*
* @param client the client
* @param width the width
* @param height the height
* @param y1 the y 1
* @param y2 the y 2
* @param entryHeight the entry height
* @param list the list
* @param parent the parent
*/
public PModuleConfigurationWidget(MinecraftClient client, int width, int height, int y1, int y2, int entryHeight, PModuleConfigurationWidget list, POptionsScreen parent) {
super(client, width, height, y1, y2, entryHeight);
this.parent = parent;
if (list != null) {
mods = list.mods;
}
setScrollAmount(parent.getScrollPercent() * Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4)));
}
@Override
public void setScrollAmount(double amount) {
super.setScrollAmount(amount);
int denominator = Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4));
if (denominator <= 0) {
parent.updateScrollPercent(0);
} else {
parent.updateScrollPercent(getScrollAmount() / Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4)));
}
}
@Override
protected boolean isFocused() {
return parent.getFocused() == this;
}
/**
* Select.
*
* @param entry the entry
*/
public void select(POptionEntry entry) {
this.setSelected(entry);
}
@Override
public void setSelected(POptionEntry entry) {
super.setSelected(entry);
moduleId = entry.getModId();
parent.updateSelected(entry);
}
@Override
protected boolean isSelectedItem(int index) {
return super.isSelectedItem(index);
}
@Override
public int addEntry(POptionEntry entry) {
if (extraMods.contains(entry.module)) {
return 0;
}
extraMods.add(entry.module);
int i = super.addEntry(entry);
if (entry.getModId().equals(moduleId)) {
setSelected(entry);
}
return i;
}
@Override
protected boolean removeEntry(POptionEntry entry) {
extraMods.remove(entry.module);
return super.removeEntry(entry);
}
@Override
protected POptionEntry remove(int index) {
extraMods.remove(getEntry(index).module);
return super.remove(index);
}
@Override
protected void renderList(MatrixStack matrices, int x, int y, int mouseX, int mouseY, float delta) {
int itemCount = this.getItemCount();
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
for (int index = 0; index < itemCount; ++index) {
int entryTop = this.getRowTop(index);
int entryBottom = this.getRowTop(index) + this.itemHeight;
if (entryBottom >= this.top && entryTop <= this.bottom) {
int entryHeight = this.itemHeight - 4;
POptionEntry entry = this.getEntry(index);
int rowWidth = this.getRowWidth();
int entryLeft;
if (((EntryListWidgetAccessor) this).isRenderSelection() && this.isSelectedItem(index)) {
entryLeft = getRowLeft() - 2 + entry.getXOffset();
int selectionRight = x + rowWidth + 2;
RenderSystem.disableTexture();
float brightness = this.isFocused() ? 1.0F : 0.5F;
RenderSystem.color4f(brightness, brightness, brightness, 1.0F);
Matrix4f matrix = matrices.peek().getModel();
buffer.begin(7, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft, entryTop + entryHeight + 2, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop + entryHeight + 2, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop - 2, 0.0F).next();
buffer.vertex(matrix, entryLeft, entryTop - 2, 0.0F).next();
t_1.draw();
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 1.0F);
buffer.begin(7, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft + 1, entryTop + entryHeight + 1, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop + entryHeight + 1, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop - 1, 0.0F).next();
buffer.vertex(matrix, entryLeft + 1, entryTop - 1, 0.0F).next();
t_1.draw();
RenderSystem.enableTexture();
}
entryLeft = this.getRowLeft();
entry.render(matrices,
index,
entryTop,
entryLeft,
rowWidth,
entryHeight,
mouseX,
mouseY,
this.isMouseOver(mouseX, mouseY) && Objects.equals(this.getEntryAtPos(mouseX, mouseY), entry),
delta);
}
}
}
@Override
protected void updateScrollingState(double mouseX, double mouseY, int button) {
super.updateScrollingState(mouseX, mouseY, button);
this.scrolling = button == 0 &&
mouseX >= (double) this.getScrollbarPositionX() &&
mouseX < (double) (this.getScrollbarPositionX() + 6);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
this.updateScrollingState(mouseX, mouseY, button);
if (!this.isMouseOver(mouseX, mouseY)) {
return false;
} else {
POptionEntry entry = this.getEntryAtPos(mouseX, mouseY);
if (entry != null) {
if (entry.mouseClicked(mouseX, mouseY, button)) {
this.setFocused(entry);
this.setDragging(true);
return true;
} else if (button == 0) {
this.clickedHeader((int) (mouseX - (double) (this.left + this.width / 2 - this.getRowWidth() / 2)),
(int) (mouseY - (double) this.top) + (int) this.getScrollAmount() - 4);
}
}
}
return this.scrolling;
}
/**
* Gets entry at pos.
*
* @param x the x
* @param y the y
* @return the entry at pos
*/
public final POptionEntry getEntryAtPos(double x, double y) {
int i = MathHelper.floor(y - (double) this.top) - this.headerHeight + (int) this.getScrollAmount() - 4;
int index = i / this.itemHeight;
return x < (double) this.getScrollbarPositionX() &&
x >= (double) getRowLeft() &&
x <= (double) (getRowLeft() + getRowWidth()) &&
index >= 0 && i >= 0 &&
index < this.getItemCount() ? this.children().get(index) : null;
}
@Override
protected int getScrollbarPositionX() {
return this.width - 6;
}
@Override
public int getRowWidth() {
return this.width - (Math.max(0, this.getMaxPosition() - (this.bottom - this.top - 4)) > 0 ? 18 : 12);
}
@Override
public int getRowLeft() {
return left + 6;
}
/**
* Gets width.
*
* @return the width
*/
public int getWidth() {
return width;
}
/**
* Gets top.
*
* @return the top
*/
public int getTop() {
return this.top;
}
/**
* Gets parent.
*
* @return the parent
*/
public POptionsScreen getParent() {
return parent;
}
@Override
protected int getMaxPosition() {
return super.getMaxPosition() + 4;
}
/**
* Gets displayed count.
*
* @return the displayed count
*/
public int getDisplayedCount() {
return children().size();
}
}

View file

@ -0,0 +1,389 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.List;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;
import pm.j4.petroleum.modules.menu.ModMenu;
import pm.j4.petroleum.util.data.ButtonInformation;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P movable button.
*/
public class PMovableButton extends AbstractButtonWidget {
/**
* The Expanded.
*/
private boolean expanded;
/**
* The Collapsed width.
*/
private final int collapsedWidth;
/**
* The Expanded width.
*/
private int expandedWidth;
/**
* The Collapsed height.
*/
private final int collapsedHeight;
/**
* The Expanded height.
*/
private int expandedHeight;
/**
* The Module height.
*/
private final int moduleHeight;
/**
* The Modules.
*/
private final List<ModuleBase> modules;
/**
* The Stored x.
*/
private int storedX;
/**
* The Stored y.
*/
private int storedY;
/**
* The Spin.
*/
private double spin;
/**
* The Arrow size.
*/
private final int arrowSize = 10;
/**
* The Category.
*/
private final String category;
/**
* The Parent.
*/
private final PModMenuScreen parent;
/**
* Instantiates a new P movable button.
*
* @param x the x
* @param y the y
* @param categoryName the category name
* @param modules the modules
* @param open the open
* @param parent the parent
*/
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules, boolean open, PModMenuScreen parent) {
super(x, y, 0, 0, new TranslatableText(categoryName));
this.category = categoryName;
int w = MinecraftClient.getInstance().textRenderer.getWidth(new TranslatableText(categoryName)) + 8;
int h = MinecraftClient.getInstance().textRenderer.fontHeight + 8;
this.width = w;
this.collapsedWidth = w;
this.expandedWidth = 0;
this.height = h;
this.collapsedHeight = h;
this.expandedHeight = 0;
this.moduleHeight = h;
this.expanded = open;
this.modules = modules;
this.parent = parent;
}
@Override
public void onClick(double mouseX, double mouseY) {
this.storedX = (int) mouseX;
this.storedY = (int) mouseY;
super.onClick(mouseX, mouseY);
}
/**
* On extra click.
*
* @param mouseX the mouse x
* @param mouseY the mouse y
*/
private void onExtraClick(double mouseX, double mouseY) {
System.out.println("extra click");
int increment = this.moduleHeight + 4;
int location = (int)mouseY - (this.y + this.collapsedHeight);
int index = location / increment;
System.out.println("index: " + index);
if(modules.size() >= index) {
ModuleBase affectedModule = modules.get(index);
System.out.println("module: " + affectedModule);
if(affectedModule.isActivatable()) {
System.out.println("toggling");
affectedModule.toggle();
}
}
else {
System.out.println("index too great");
}
//TODO module things
}
@Override
public void onRelease(double mouseX, double mouseY) {
int mx = (int) mouseX;
int my = (int) mouseY;
/**
* The Padding.
*/
int padding = 5;
if (storedX + padding > mx && storedX - padding < mx &&
storedY + padding > my && storedY - padding < my) {
this.expanded = !this.expanded;
}
}
@Override
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
this.x += (int) deltaX;
this.y += (int) deltaY;
// i really hate to do it but nowhere else will it properly save
this.updateCoordinate();
}
/**
* Update coordinate.
*/
public void updateCoordinate() {
ModMenu.updateCoord(this.category, new ButtonInformation((this.x / (double) parent.width), (this.y / (double) parent.height), this.expanded));
}
// fuck click sounds
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.active && this.visible) {
if (this.isValidClickButton(button)) {
boolean bl = this.clicked(mouseX, mouseY);
if (bl && mouseY > this.y + this.collapsedHeight && mouseY < this.y + this.expandedHeight) {
this.onExtraClick(mouseX, mouseY);
return true;
} else if (bl) {
this.onClick(mouseX, mouseY);
return true;
}
}
}
return false;
}
/**
* Transition max width.
*
* @param width the width
*/
private void transitionMaxWidth(int width) {
double increment = ((width - this.width) / 20.0);
int sign = (width > this.width) ? 1 : -1;
if (increment == 0) {
this.width = width;
} else if (increment < 1 && increment > -1) {
this.width += sign;
} else {
this.width += (int) increment;
}
}
/**
* Transition max height.
*
* @param height the height
*/
private void transitionMaxHeight(int height) {
double increment = ((height - this.height) / 20.0);
int sign = (height > this.height) ? 1 : -1;
if (increment == 0) {
this.height = height;
} else if (increment < 1 && increment > -1) {
this.height += sign;
} else {
this.height += (int) increment;
}
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
if (this.expandedWidth == 0 || this.expandedHeight == 0) {
this.expandedHeight = this.collapsedHeight + ((this.moduleHeight + 4) * modules.size());
modules.forEach(module -> {
this.expandedWidth = this.width;
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + arrowSize + 8;
if (w > this.expandedWidth) {
this.expandedWidth = w;
}
});
// this should only run when opening the screen for the first time
if (this.expanded) {
this.height = expandedHeight;
this.width = expandedWidth;
}
}
MinecraftClient minecraftClient = MinecraftClient.getInstance();
TextRenderer textRenderer = minecraftClient.textRenderer;
minecraftClient.getTextureManager().bindTexture(WIDGETS_LOCATION);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
RenderSystem.disableTexture();
RenderSystem.defaultBlendFunc();
float brightness = this.isFocused() ? 1.0F : 0.5F;
RenderSystem.color4f(brightness, brightness, brightness, 1.0F);
Matrix4f matrix = matrices.peek().getModel();
int buttonLeft = this.x;
int buttonRight = this.x + width + 2;
int buttonTop = this.y;
int buttonBottom = this.y + this.collapsedHeight;
int buttonExpandedBottom = this.y + this.height;
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonTop - 2, buttonBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonTop - 1, buttonBottom + 1);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 0.9F);
drawEquilateralTriangle(t_1, buffer, matrix, 40, 40, 180, arrowSize);
drawEquilateralTriangle(t_1, buffer, matrix, 60, 60, 0, arrowSize);
drawEquilateralTriangle(t_1, buffer, matrix, 40, 60, 90, arrowSize);
drawEquilateralTriangle(t_1, buffer, matrix, 60, 40, 360, arrowSize);
drawEquilateralTriangle(t_1, buffer, matrix, 80, 40, 270, arrowSize);
drawEquilateralTriangle(t_1, buffer, matrix, 80, 60, 120, arrowSize);
int j = this.active ? 16777215 : 10526880;
if (this.expanded) {
if (this.width != this.expandedWidth || this.height != this.expandedHeight) {
transitionMaxWidth(this.expandedWidth);
transitionMaxHeight(this.expandedHeight);
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonBottom + 1, buttonExpandedBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonBottom + 2, buttonExpandedBottom + 1);
if ((this.height - 8) / 2 > (this.collapsedHeight)) {
drawCenteredText(matrices, textRenderer, new LiteralText("..."), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
} else {
for (int i = 0; i < modules.size(); i++) {
int adjustedIndex = i + 1;
int previousBottom = buttonBottom + (i * (this.moduleHeight + 4));
int currentBottom = buttonBottom + ((i + 1) * (this.moduleHeight + 4));
RenderSystem.defaultBlendFunc();
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, previousBottom + 1, currentBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, previousBottom + 2, currentBottom + 1);
drawCenteredText(matrices,
textRenderer,
modules.get(i).getReadableName(),
this.x + this.width / 2,
this.y + ((this.collapsedHeight - 8) / 2 + ((moduleHeight + 4) * adjustedIndex)),
j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
}
} else {
if (this.width != this.collapsedWidth || this.height != this.collapsedHeight) {
transitionMaxWidth(this.collapsedWidth);
transitionMaxHeight(this.collapsedHeight);
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, buttonBottom + 1, buttonExpandedBottom + 2);
RenderSystem.color4f(0.0F, 0.0F, 0.0F, 0.3F);
drawBox(t_1, buffer, matrix, buttonLeft + 1, buttonRight - 1, buttonBottom + 2, buttonExpandedBottom + 1);
if ((this.height - 8) / 2 > (this.collapsedHeight)) {
drawCenteredText(matrices, textRenderer, new LiteralText("..."), this.x + this.width / 2, this.y + (this.height - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
}
}
RenderSystem.enableTexture();
drawCenteredText(matrices, textRenderer, this.getMessage(), this.x + this.width / 2, this.y + (this.collapsedHeight - 8) / 2, j | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
/**
* Draw equilateral triangle.
*
* @param t_1 the t 1
* @param buffer the buffer
* @param matrix the matrix
* @param centerX the center x
* @param centerY the center y
* @param rotation the rotation
* @param distance the distance
*/
private void drawEquilateralTriangle(Tessellator t_1, BufferBuilder buffer, Matrix4f matrix, int centerX, int centerY, double rotation, int distance) {
double rotation1 = rotation;
double rotation2 = rotation + 120;
double rotation3 = rotation + 240;
int point1X = (int)(distance * Math.cos(Math.toRadians(rotation1))) + centerX;
int point1Y = (int)(distance * Math.sin(Math.toRadians(rotation1))) + centerY;
int point2X = (int)(distance * Math.cos(Math.toRadians(rotation2))) + centerX;
int point2Y = (int)(distance * Math.sin(Math.toRadians(rotation2))) + centerY;
int point3X = (int)(distance * Math.cos(Math.toRadians(rotation3))) + centerX;
int point3Y = (int)(distance * Math.sin(Math.toRadians(rotation3))) + centerY;
//RenderSystem.enableBlend();
RenderSystem.disableBlend();
buffer.begin(7, VertexFormats.POSITION_COLOR);
buffer.vertex(matrix, centerX, centerY, 0.0F).color(0.0F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, centerX, point1Y, 0.0F).color(0.0F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, point1X, point1Y, 0.0F).color(0.0F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, centerX, centerY, 0.0F).color(0.5F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, centerX, point2Y, 0.0F).color(0.5F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, point2X, point2Y, 0.0F).color(0.5F, 1.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, centerX, centerY, 0.0F).color(1.0F, 0.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, centerX, point3Y, 0.0F).color(1.0F, 0.0F, 1.0F, 1.0F).next();
buffer.vertex(matrix, point3X, point3Y, 0.0F).color(1.0F, 0.0F, 1.0F, 1.0F).next();
t_1.draw();
}
/**
* Draw box.
*
* @param t_1 the t 1
* @param buffer the buffer
* @param matrix the matrix
* @param buttonLeft the button left
* @param buttonRight the button right
* @param buttonTop the button top
* @param buttonBottom the button bottom
*/
private void drawBox(Tessellator t_1, BufferBuilder buffer, Matrix4f matrix, int buttonLeft, int buttonRight, int buttonTop, int buttonBottom) {
RenderSystem.enableBlend();
buffer.begin(7, VertexFormats.POSITION);
buffer.vertex(matrix, buttonLeft, buttonBottom, 0.0F).next();
buffer.vertex(matrix, buttonRight, buttonBottom, 0.0F).next();
buffer.vertex(matrix, buttonRight, buttonTop, 0.0F).next();
buffer.vertex(matrix, buttonLeft, buttonTop, 0.0F).next();
t_1.draw();
}
}

View file

@ -0,0 +1,94 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Language;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P option entry.
*/
public class POptionEntry extends AlwaysSelectedEntryListWidget.Entry<POptionEntry> {
/**
* The Module.
*/
protected final ModuleBase module;
/**
* The Client.
*/
protected final MinecraftClient client;
/**
* The List.
*/
private final PModuleConfigurationWidget list;
/**
* Instantiates a new P option entry.
*
* @param mod the mod
* @param list the list
*/
public POptionEntry(ModuleBase mod, PModuleConfigurationWidget list) {
this.module = mod;
this.client = MinecraftClient.getInstance();
this.list = list;
}
//TODO TEST move text to be centered
@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
x += getXOffset();
entryWidth -= getXOffset();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
Text name = this.getModName();
StringVisitable nameString = name;
int maxNameWidth = entryWidth - 32 - 3;
TextRenderer font = this.client.textRenderer;
if (font.getWidth(name) > maxNameWidth) {
StringVisitable ellipse = StringVisitable.plain("...");
nameString = StringVisitable.concat(font.trimToWidth(nameString, maxNameWidth - font.getWidth(ellipse)), ellipse);
}
font.draw(matrices, Language.getInstance().reorder(nameString), x + 32 + 3, y + (entryHeight / 2), 0xFFFFFF);
}
@Override
public boolean mouseClicked(double x, double y, int b) {
this.list.select(this);
return true;
}
/**
* Gets mod id.
*
* @return the mod id
*/
public String getModId() {
return module.getModuleName();
}
/**
* Gets mod name.
*
* @return the mod name
*/
public TranslatableText getModName() {
return module.getReadableName();
}
/**
* Gets x offset.
*
* @return the x offset
*/
public int getXOffset() {
return 0;
}
}

View file

@ -0,0 +1,224 @@
package pm.j4.petroleum.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P options screen.
*/
@SuppressWarnings("deprecation")
public class POptionsScreen extends Screen {
/**
* The Previous screen.
*/
private final Screen previousScreen;
/**
* The Scroll percent.
*/
private double scrollPercent = 0;
/**
* The Modules.
*/
private PModuleConfigurationWidget modules;
/**
* The Config pane.
*/
private PModuleConfigPane configPane;
/**
* The Selected.
*/
private POptionEntry selected;
/**
* The Tooltip.
*/
private Text tooltip;
/**
* The Pane y.
*/
private int paneY;
/**
* The Right pane x.
*/
private int rightPaneX;
/**
* Instantiates a new P options screen.
*
* @param previousScreen the previous screen
*/
public POptionsScreen(Screen previousScreen) {
super(new TranslatableText("petroleum.options"));
this.previousScreen = previousScreen;
}
@Override
public void onClose() {
super.onClose();
assert this.client != null;
this.client.openScreen(previousScreen);
}
protected void init() {
paneY = 48;
int paneWidth = this.width / 2 - 8;
rightPaneX = width - paneWidth;
this.modules = new PModuleConfigurationWidget(this.client,
this.width - paneWidth,
this.height,
paneY + 19,
this.height - 36,
36,
this.modules,
this);
this.modules.setLeftPos(0);
this.children.add(this.modules);
this.configPane = new PModuleConfigPane(this.client,
paneWidth,
this.height,
paneY + 19,
this.height - 36,
48,
this);
this.configPane.setLeftPos(paneWidth);
this.children.add(this.configPane);
List<ModuleBase> configurableModules = new ArrayList<>();
if (ConfigManager.getConfig().isPresent()) {
configurableModules.addAll(PetroleumMod.getActiveMods()
.stream().filter(ModuleBase::configurable)
.collect(Collectors.toList()));
}
configurableModules.forEach(module -> this.modules.addEntry(new POptionEntry(module, this.modules)));
this.addButton(new ButtonWidget(this.width / 2 - 75, this.height - 30, 150, 20, ScreenTexts.DONE, (buttonWidget) -> {
ConfigManager.saveAllModules();
assert this.client != null;
this.client.openScreen(this.previousScreen);
}));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
this.modules.render(matrices, mouseX, mouseY, delta);
if (selected != null) {
this.configPane.render(matrices, mouseX, mouseY, delta);
}
RenderSystem.disableBlend();
drawTextWithShadow(matrices, this.textRenderer, this.title, this.modules.getWidth() / 2, 8, 16777215);
super.render(matrices, mouseX, mouseY, delta);
if (selected != null) {
int offset = 36;
int x = rightPaneX;
int maxNameWidth = this.width - (x + offset);
int lineSpacing = textRenderer.fontHeight + 1;
Text name = selected.getModName();
StringVisitable trimmedName = name;
if (textRenderer.getWidth(name) > maxNameWidth) {
StringVisitable ellipsis = StringVisitable.plain("...");
trimmedName = StringVisitable.concat(textRenderer.trimToWidth(name, maxNameWidth - textRenderer.getWidth(ellipsis)), ellipsis);
}
if (mouseX > x + offset && mouseY > paneY + 1 && mouseY < paneY + 1 + textRenderer.fontHeight && mouseX < x + offset + textRenderer.getWidth(trimmedName)) {
setTooltip(new LiteralText("Configure " + selected.getModName()));
}
textRenderer.draw(matrices, selected.getModName(), x + offset, paneY + 2 + lineSpacing, 0x808080);
if (this.tooltip != null) {
this.renderOrderedTooltip(matrices, textRenderer.wrapLines(this.tooltip, Integer.MAX_VALUE), mouseX, mouseY);
}
}
}
/**
* Sets tooltip.
*
* @param tooltip the tooltip
*/
private void setTooltip(Text tooltip) {
this.tooltip = tooltip;
}
@Override
public void renderBackground(MatrixStack matrices) {
POptionsScreen.overlayBackground(this.width, this.height);
}
/**
* Overlay background.
*
* @param x2 the x 2
* @param y2 the y 2
*/
static void overlayBackground(int x2, int y2) {
Tessellator t_1 = Tessellator.getInstance();
BufferBuilder buffer = t_1.getBuffer();
Objects.requireNonNull(MinecraftClient.getInstance()).getTextureManager().bindTexture(DrawableHelper.OPTIONS_BACKGROUND_TEXTURE);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
buffer.vertex(0, y2, 0.0D).texture(0 / 32.0F, y2 / 32.0F).color(64, 64, 64, 255).next();
buffer.vertex(x2, y2, 0.0D).texture(x2 / 32.0F, y2 / 32.0F).color(64, 64, 64, 255).next();
buffer.vertex(x2, 0, 0.0D).texture(x2 / 32.0F, 0 / 32.0F).color(64, 64, 64, 255).next();
buffer.vertex(0, 0, 0.0D).texture(0 / 32.0F, 0 / 32.0F).color(64, 64, 64, 255).next();
t_1.draw();
}
/**
* Gets scroll percent.
*
* @return the scroll percent
*/
double getScrollPercent() {
return scrollPercent;
}
/**
* Update scroll percent.
*
* @param scrollPercent the scroll percent
*/
void updateScrollPercent(double scrollPercent) {
this.scrollPercent = scrollPercent;
}
/**
* Gets selected.
*
* @return the selected
*/
POptionEntry getSelected() {
return selected;
}
/**
* Update selected.
*
* @param entry the entry
*/
void updateSelected(POptionEntry entry) {
if (entry != null) {
this.selected = entry;
}
}
}