update to 0.1.4
This commit is contained in:
parent
17e135f3d3
commit
86c9b6e3f7
69 changed files with 4022 additions and 128 deletions
|
@ -17,6 +17,7 @@ import pm.j4.petroleum.modules.bindings.BindingManager;
|
|||
import pm.j4.petroleum.modules.list.ModList;
|
||||
import pm.j4.petroleum.modules.menu.ModMenu;
|
||||
import pm.j4.petroleum.modules.splash.SplashText;
|
||||
import pm.j4.petroleum.modules.xray.Xray;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
@ -54,7 +55,8 @@ public class PetroleumMod implements ModInitializer {
|
|||
new ModMenu(),
|
||||
new ModList(),
|
||||
new BindingManager(),
|
||||
new ExampleModule()
|
||||
new ExampleModule(),
|
||||
new Xray()
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -135,10 +137,10 @@ public class PetroleumMod implements ModInitializer {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
|
||||
ConfigManager.initConfig();
|
||||
|
||||
// always update mod data
|
||||
|
|
|
@ -7,7 +7,6 @@ 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;
|
||||
|
@ -22,12 +21,11 @@ public class PModMenuScreen extends Screen {
|
|||
* Instantiates a new P mod menu screen.
|
||||
*/
|
||||
public PModMenuScreen() {
|
||||
super(new TranslatableText("petroleum.modlist"));
|
||||
super(new TranslatableText("petroleum.modmenu"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.client.textRenderer.drawWithShadow(matrices, new LiteralText("Menu Open"), 10, 50, -1);
|
||||
this.renderBackground(matrices);
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
|
|
|
@ -1,34 +1,109 @@
|
|||
package pm.j4.petroleum.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ElementListWidget;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.option.BooleanOption;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
import pm.j4.petroleum.util.module.option.KeybindOption;
|
||||
import pm.j4.petroleum.util.module.option.ListOption;
|
||||
|
||||
/**
|
||||
* The type P module config entry.
|
||||
*/
|
||||
public class PModuleConfigEntry extends EntryListWidget.Entry<PModuleConfigEntry> {
|
||||
public class PModuleConfigEntry extends ElementListWidget.Entry<PModuleConfigEntry> {
|
||||
/**
|
||||
* The Option.
|
||||
*/
|
||||
protected final ConfigurationOption option;
|
||||
protected ConfigurationOption option;
|
||||
/**
|
||||
* The Display text.
|
||||
*/
|
||||
protected final Text displayText;
|
||||
|
||||
private PModuleConfigPane parent;
|
||||
|
||||
private List<Element> elements = new ArrayList<>();
|
||||
|
||||
private String trueValue;
|
||||
private String falseValue;
|
||||
|
||||
private Element selected;
|
||||
|
||||
/**
|
||||
* Instantiates a new P module config entry.
|
||||
*
|
||||
* @param option the option
|
||||
* @param text the text
|
||||
*/
|
||||
public PModuleConfigEntry(ConfigurationOption option, Text text) {
|
||||
public PModuleConfigEntry(ConfigurationOption option, Text text, PModuleConfigPane parent) {
|
||||
this.option = option;
|
||||
this.displayText = text;
|
||||
this.parent = parent;
|
||||
this.trueValue = "Yes";
|
||||
this.falseValue = "No";
|
||||
}
|
||||
|
||||
public PModuleConfigEntry(ConfigurationOption option, Text text, PModuleConfigPane parent, String trueValue, String falseValue) {
|
||||
this.option = option;
|
||||
this.displayText = text;
|
||||
this.parent = parent;
|
||||
this.trueValue = trueValue;
|
||||
this.falseValue = falseValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Element> children() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.isMouseOver(mouseX, mouseY)) {
|
||||
this.parent.setSelected(this);
|
||||
System.out.println(displayText.getString() + " clicked");
|
||||
String className = option.getClass().toString();
|
||||
elements.forEach((widget) -> {
|
||||
if (widget.mouseClicked(mouseX, mouseY, button)) {
|
||||
System.out.println("Button clicked");
|
||||
selected = widget;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
return this.isMouseOver(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if(this.selected != null) {
|
||||
return this.selected.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
|
||||
if(this.selected != null) {
|
||||
return this.selected.keyReleased(keyCode, scanCode, modifiers);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,12 +111,84 @@ public class PModuleConfigEntry extends EntryListWidget.Entry<PModuleConfigEntry
|
|||
if (this.displayText != null) {
|
||||
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, displayText, x, y, 0xAAAAAA);
|
||||
}
|
||||
System.out.println(option);
|
||||
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.getStringValue()), x, y + fontHeight + 4, 0xFFFFFF);
|
||||
//TODO use TranslatableText instead of LiteralText
|
||||
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, new LiteralText(option.getDescription() + " " + option.getStringValue()), x, y + fontHeight + 4, 0xFFFFFF);
|
||||
|
||||
System.out.println(elements.size());
|
||||
if(elements.size() == 0) {
|
||||
String className = option.getClass().toString();
|
||||
System.out.println(className);
|
||||
if (className.equals(BooleanOption.class.toString())) {
|
||||
System.out.println("boolean");
|
||||
elements.add(new ButtonWidget(x, y + (int)(fontHeight * 2.5),
|
||||
entryWidth,
|
||||
fontHeight * 2,
|
||||
new LiteralText(((BooleanOption)option).getValue() ? this.trueValue : this.falseValue), (button) -> {
|
||||
button.setMessage(new LiteralText((!((BooleanOption)option).getValue()) ? this.trueValue : this.falseValue));
|
||||
BooleanOption newValue = new BooleanOption(option.getConfigKey(), option.getDescription(), option.getParent());
|
||||
newValue.setValue((!((BooleanOption)option).getValue()));
|
||||
option.getParent().updateConfigOption(newValue.getConfigKey(), newValue);
|
||||
this.option = newValue;
|
||||
}));
|
||||
}
|
||||
else if (className.equals(ListOption.class.toString())) {
|
||||
// TODO: determine whether list options are viable,
|
||||
// considering that it would be easier to split lists into multiple PModuleConfigEntries
|
||||
System.out.println("list");
|
||||
}
|
||||
else if (className.equals(KeybindOption.class.toString())) {
|
||||
System.out.println("keybind");
|
||||
ButtonWidget bindButton = new ButtonWidget(x, y + (int)(fontHeight * 2.5),
|
||||
entryWidth,
|
||||
fontHeight * 2,
|
||||
new LiteralText(option.getStringValue().toUpperCase()), (button) -> {
|
||||
button.setMessage(new LiteralText("Press any key..."));
|
||||
}) {
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
if (this.active && this.visible) {
|
||||
//TODO
|
||||
if (keyCode != 257 && keyCode != 32 && keyCode != 335) {
|
||||
KeybindOption newValue = new KeybindOption(option.getConfigKey(), option.getDescription(), option.getParent());
|
||||
KeyBinding bind = new KeyBinding(((KeybindOption)option).getTranslationKey(), keyCode, "category.petroleum");
|
||||
newValue.fromKeybind(bind, option.getParent());
|
||||
Optional<ConfigHolder> config = ConfigManager.getConfig();
|
||||
assert config.isPresent();
|
||||
config.get().globalConfig.setBinding(bind, option.getParent());
|
||||
option = newValue;
|
||||
this.setMessage(new LiteralText(option.getStringValue().toUpperCase()));
|
||||
selected = null;
|
||||
return false;
|
||||
} else {
|
||||
this.playDownSound(MinecraftClient.getInstance().getSoundManager());
|
||||
this.onPress();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
elements.add(bindButton);
|
||||
}
|
||||
else {
|
||||
System.out.println("other/string");
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
else {
|
||||
elements.forEach((widget) -> {
|
||||
if (widget instanceof AbstractButtonWidget) {
|
||||
((AbstractButtonWidget)widget).render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ 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.ElementListWidget;
|
||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
|
@ -13,7 +14,7 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||
/**
|
||||
* The type P module config pane.
|
||||
*/
|
||||
public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
|
||||
public class PModuleConfigPane extends ElementListWidget<PModuleConfigEntry> {
|
||||
/**
|
||||
* The Parent.
|
||||
*/
|
||||
|
@ -23,6 +24,8 @@ public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
|
|||
*/
|
||||
private POptionEntry lastSelected;
|
||||
|
||||
private PModuleConfigEntry selectedConfigEntry;
|
||||
|
||||
/**
|
||||
* Instantiates a new P module config pane.
|
||||
*
|
||||
|
@ -37,15 +40,15 @@ public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
|
|||
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;
|
||||
}
|
||||
|
||||
public void setSelected(PModuleConfigEntry entry) {
|
||||
selectedConfigEntry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PModuleConfigEntry getSelected() {
|
||||
return null;
|
||||
return selectedConfigEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +70,7 @@ public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
|
|||
setScrollAmount(-Double.MAX_VALUE);
|
||||
String id = lastSelected.getModId();
|
||||
if (lastSelected != null && id != null && !id.isEmpty()) {
|
||||
children().addAll(lastSelected.module.getConfigEntries());
|
||||
children().addAll(lastSelected.module.getConfigEntries(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,15 +88,17 @@ public class PModuleConfigPane extends EntryListWidget<PModuleConfigEntry> {
|
|||
RenderSystem.shadeModel(7425);
|
||||
RenderSystem.disableTexture();
|
||||
|
||||
buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
|
||||
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();
|
||||
// darken config pane area
|
||||
|
||||
buffer.begin(7, VertexFormats.POSITION_COLOR_TEXTURE);
|
||||
buffer.vertex(this.left, (this.top + 4), 0.0D).color(0, 0, 0, 0).texture(0.0F, 1.0F).next();
|
||||
buffer.vertex(this.right, (this.top + 4), 0.0D).color(0, 0, 0, 0).texture(1.0F, 1.0F).next();
|
||||
buffer.vertex(this.right, this.top, 0.0D).color(0, 0, 0, 255).texture(1.0F, 0.0F).next();
|
||||
buffer.vertex(this.left, this.top, 0.0D).color(0, 0, 0, 255).texture(0.0F, 0.0F).next();
|
||||
buffer.vertex(this.left, this.bottom, 0.0D).color(0, 0, 0, 255).texture(0.0F, 1.0F).next();
|
||||
buffer.vertex(this.right, this.bottom, 0.0D).color(0, 0, 0, 255).texture(1.0F, 1.0F).next();
|
||||
buffer.vertex(this.right, (this.bottom - 4), 0.0D).color(0, 0, 0, 0).texture(1.0F, 0.0F).next();
|
||||
buffer.vertex(this.left, (this.bottom - 4), 0.0D).color(0, 0, 0, 0).texture(0.0F, 0.0F).next();
|
||||
t_1.draw();
|
||||
|
||||
buffer.begin(7, VertexFormats.POSITION_COLOR);
|
||||
|
|
|
@ -59,8 +59,25 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -70,11 +87,13 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
* @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(categoryName) + 8;
|
||||
int w = MinecraftClient.getInstance().textRenderer.getWidth(new TranslatableText(categoryName)) + 8;
|
||||
int h = MinecraftClient.getInstance().textRenderer.fontHeight + 8;
|
||||
this.width = w;
|
||||
this.collapsedWidth = w;
|
||||
|
@ -95,8 +114,29 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -123,6 +163,9 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
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));
|
||||
}
|
||||
|
@ -186,7 +229,8 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
if (this.expandedWidth == 0 || this.expandedHeight == 0) {
|
||||
this.expandedHeight = this.collapsedHeight + ((this.moduleHeight + 4) * modules.size());
|
||||
modules.forEach(module -> {
|
||||
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + 8;
|
||||
this.expandedWidth = this.width;
|
||||
int w = MinecraftClient.getInstance().textRenderer.getWidth(module.getReadableName()) + arrowSize + 8;
|
||||
if (w > this.expandedWidth) {
|
||||
this.expandedWidth = w;
|
||||
}
|
||||
|
@ -204,7 +248,6 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, this.alpha);
|
||||
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
float brightness = this.isFocused() ? 1.0F : 0.5F;
|
||||
RenderSystem.color4f(brightness, brightness, brightness, 1.0F);
|
||||
|
@ -224,6 +267,14 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
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) {
|
||||
|
@ -243,7 +294,6 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
int previousBottom = buttonBottom + (i * (this.moduleHeight + 4));
|
||||
int currentBottom = buttonBottom + ((i + 1) * (this.moduleHeight + 4));
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.color4f(0.5F, 0.5F, 0.5F, 0.5F);
|
||||
drawBox(t_1, buffer, matrix, buttonLeft, buttonRight, previousBottom + 1, currentBottom + 2);
|
||||
|
@ -277,6 +327,44 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
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 rotation2 = rotation + 120;
|
||||
double rotation3 = rotation + 240;
|
||||
int point1X = (int)(distance * Math.cos(Math.toRadians(rotation))) + centerX;
|
||||
int point1Y = (int)(distance * Math.sin(Math.toRadians(rotation))) + 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.
|
||||
*
|
||||
|
@ -289,6 +377,7 @@ public class PMovableButton extends AbstractButtonWidget {
|
|||
* @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();
|
||||
|
|
|
@ -14,10 +14,7 @@ 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 net.minecraft.text.*;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
@ -109,7 +106,6 @@ public class POptionsScreen extends Screen {
|
|||
}
|
||||
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) -> {
|
||||
//TODO see PModMenuScreen
|
||||
ConfigManager.saveAllModules();
|
||||
assert this.client != null;
|
||||
this.client.openScreen(this.previousScreen);
|
||||
|
@ -142,7 +138,8 @@ public class POptionsScreen extends Screen {
|
|||
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()));
|
||||
//TODO tooltop
|
||||
//selected.getModName()
|
||||
}
|
||||
textRenderer.draw(matrices, selected.getModName(), x + offset, paneY + 2 + lineSpacing, 0x808080);
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package pm.j4.petroleum.mixin;
|
||||
|
||||
/**
|
||||
* Mixin for in-game module management menu.
|
||||
* Includes module activation/deactivation, as well as some configuration options.
|
||||
* A separate menu for advanced configurations should also be added eventually.
|
||||
* This module should handle the rendering of the menu and all of its buttons,
|
||||
* while delegating button presses to @link pm.j4.petroleum.modules.menu.ModMenu
|
||||
*/
|
||||
public class ModMenuMixin {
|
||||
}
|
|
@ -10,9 +10,13 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
import pm.j4.petroleum.modules.splash.SplashText;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
import pm.j4.petroleum.util.module.option.BooleanOption;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -71,8 +75,13 @@ public class TitleScreenMixin extends Screen {
|
|||
locals = LocalCapture.CAPTURE_FAILSOFT)
|
||||
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci, float f, int i, int j, float g, int l) {
|
||||
Optional<ConfigHolder> config = ConfigManager.getConfig();
|
||||
if (config.isPresent() && config.get().isModuleEnabled("petroleum.splashtext")) {
|
||||
drawStringWithShadow(matrices, this.textRenderer, SplashText.get(), 2, this.height - 20, blink(13108374) | l);
|
||||
Optional<ModuleBase> splashText = PetroleumMod.getMod("petroleum.splashtext");
|
||||
if (config.isPresent() && config.get().isModuleEnabled("petroleum.splashtext")
|
||||
&& splashText.isPresent()) {
|
||||
Optional<ConfigurationOption> isActive = splashText.get().getConfigOption("petroleum.splashtext.active");
|
||||
if(isActive.isPresent() && ((BooleanOption)isActive.get()).getValue()) {
|
||||
drawStringWithShadow(matrices, this.textRenderer, SplashText.get(), 2, this.height - 20, blink(13108374) | l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package pm.j4.petroleum.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||
import pm.j4.petroleum.gui.PModuleConfigPane;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
import pm.j4.petroleum.util.module.option.BooleanOption;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
|
@ -23,10 +28,10 @@ public class ExampleModule extends ModuleBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, ConfigurationOption> getDefaultConfig() {
|
||||
Map<String, ConfigurationOption> options = new HashMap<>();
|
||||
options.put("petroleum.example_b_one", new BooleanOption("example"));
|
||||
options.put("petroleum.example_b_two", new BooleanOption("example"));
|
||||
public List<ConfigurationOption> getDefaultConfig() {
|
||||
List<ConfigurationOption> options = new ArrayList<>();
|
||||
options.add(new BooleanOption("petroleum.example.b_one","example", this));
|
||||
options.add(new BooleanOption("petroleum.example.b_two","example", this));
|
||||
return options;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,11 @@ import net.minecraft.text.TranslatableText;
|
|||
import org.lwjgl.glfw.GLFW;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||
import pm.j4.petroleum.gui.PModuleConfigPane;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.config.GlobalConfig;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
import pm.j4.petroleum.util.module.option.KeybindOption;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +39,11 @@ public class BindingManager extends ModuleBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<PModuleConfigEntry> getConfigEntries() {
|
||||
public List<PModuleConfigEntry> getConfigEntries(PModuleConfigPane sourcePane) {
|
||||
|
||||
//TODO multiple binds per module
|
||||
// thoughts: have modules include a list of module triggers/functions
|
||||
// which replace the ModuleBase in bindings?
|
||||
List<PModuleConfigEntry> entries = new ArrayList<>();
|
||||
|
||||
Map<KeybindOption, ModuleBase> mapped = new HashMap<>();
|
||||
|
@ -45,26 +51,13 @@ public class BindingManager extends ModuleBase {
|
|||
Map<KeyBinding, ModuleBase> binds = ConfigManager.getConfig().get().globalConfig.bindings;
|
||||
|
||||
binds.forEach((key, func) -> {
|
||||
KeybindOption o = new KeybindOption(func.getModuleName() + " " + func.getCategory());
|
||||
o.fromKeybind(key, func);
|
||||
mapped.put(o, func);
|
||||
KeybindOption option = new KeybindOption(func.getModuleName() + " " + func.getCategory(), func.getModuleName() + " " + func.getCategory(), func);
|
||||
option.fromKeybind(key, func);
|
||||
mapped.put(option, func);
|
||||
});
|
||||
}
|
||||
mapped.forEach((bind, module) -> {
|
||||
PModuleConfigEntry entry = new PModuleConfigEntry(bind, new TranslatableText(module.getModuleName())) {
|
||||
//TODO keybinding. most likely involves mixin to take direct key input
|
||||
// look into how keybinding in regular options screen works
|
||||
@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) {
|
||||
int fontHeight = MinecraftClient.getInstance().textRenderer.fontHeight;
|
||||
MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, "Key Value: " + this.option.getStringValue(), x, y + fontHeight + 4, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
};
|
||||
mapped.forEach((configEntry, module) -> {
|
||||
PModuleConfigEntry entry = new PModuleConfigEntry(configEntry, new TranslatableText(module.getModuleName()), sourcePane);
|
||||
entries.add(entry);
|
||||
});
|
||||
return entries;
|
||||
|
|
|
@ -2,7 +2,9 @@ package pm.j4.petroleum.modules.list;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
import java.util.Optional;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
|
@ -27,11 +29,12 @@ public class ModList extends ModuleBase {
|
|||
*/
|
||||
public static List<ModuleBase> getActive() {
|
||||
List<ModuleBase> result = new ArrayList<>();
|
||||
PetroleumMod.getActiveMods().forEach((mod) -> {
|
||||
Optional<ConfigHolder> config = ConfigManager.getConfig();
|
||||
config.ifPresent(configHolder -> configHolder.getEnabledModules().forEach((mod) -> {
|
||||
if (!mod.isHidden()) {
|
||||
result.add(mod);
|
||||
}
|
||||
});
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ import pm.j4.petroleum.util.module.ModuleBase;
|
|||
*/
|
||||
public class ModMenu extends ModuleBase {
|
||||
|
||||
/**
|
||||
* The constant coordinates.
|
||||
*/
|
||||
private static final Map<String, ButtonInformation> coordinates = new HashMap<>();
|
||||
|
||||
/**
|
||||
|
@ -47,6 +50,12 @@ public class ModMenu extends ModuleBase {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update coord.
|
||||
*
|
||||
* @param b the b
|
||||
* @param c the c
|
||||
*/
|
||||
public static void updateCoord(String b, ButtonInformation c) {
|
||||
if (c.x < 0.05) {
|
||||
c.x = 0.05;
|
||||
|
@ -78,6 +87,11 @@ public class ModMenu extends ModuleBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets buttons.
|
||||
*
|
||||
* @return the buttons
|
||||
*/
|
||||
public static Map<String, ButtonInformation> getButtons() {
|
||||
return coordinates;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
package pm.j4.petroleum.modules.splash;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||
import pm.j4.petroleum.gui.PModuleConfigPane;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
import pm.j4.petroleum.util.module.option.BooleanOption;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
|
||||
/**
|
||||
* The type Splash text.
|
||||
|
@ -13,9 +20,16 @@ public class SplashText extends ModuleBase {
|
|||
public SplashText() {
|
||||
super("petroleum.splashtext",
|
||||
"petroleum.misc",
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false);
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigurationOption> getDefaultConfig() {
|
||||
List<ConfigurationOption> options = new ArrayList<>();
|
||||
options.add(new BooleanOption("petroleum.splashtext.active", "Show the main menu version text.", this));
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,13 @@ package pm.j4.petroleum.modules.xray;
|
|||
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type Xray.
|
||||
*/
|
||||
public class Xray extends ModuleBase {
|
||||
/**
|
||||
* Instantiates a new Xray.
|
||||
*/
|
||||
public Xray() {
|
||||
super("petroleum.xray",
|
||||
"petroleum.render",
|
||||
|
|
|
@ -91,7 +91,4 @@ public class ConfigHolder {
|
|||
}
|
||||
}
|
||||
|
||||
public static void saveModule(ModuleBase module) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,13 @@ public class ConfigManager {
|
|||
|
||||
/**
|
||||
* Prepare config file.
|
||||
*
|
||||
* @param path the path
|
||||
* @param filename the filename
|
||||
* @return the file
|
||||
*/
|
||||
private static File prepareConfigFile(String path, String filename) {
|
||||
if(path != "") {
|
||||
if (path != "") {
|
||||
File directory = new File(FabricLoader.getInstance().getConfigDir().toString(), path);
|
||||
if (!directory.exists()) directory.mkdir();
|
||||
}
|
||||
|
@ -53,14 +57,17 @@ public class ConfigManager {
|
|||
config.globalConfig = new DefaultConfig();
|
||||
config.serverConfigs = new HashMap<>();
|
||||
|
||||
config = load("", "petroleum.json", ConfigHolder.class);
|
||||
config = load("petroleum/", "petroleum.json", ConfigHolder.class);
|
||||
initModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init modules.
|
||||
*/
|
||||
public static void initModules() {
|
||||
PetroleumMod.getActiveMods().forEach(module -> {
|
||||
ModuleConfig options = load("modules/", module.getModuleName() + ".json", ModuleConfig.class);
|
||||
if(options != null && options.options != null) {
|
||||
ModuleConfig options = load("petroleum/modules/", module.getModuleName() + ".json", ModuleConfig.class);
|
||||
if (options != null && options.options != null) {
|
||||
options.options.forEach((key, option) -> {
|
||||
if (module.hasOption(option.key)) {
|
||||
module.setConfigOption(option.key, option.value);
|
||||
|
@ -72,6 +79,12 @@ public class ConfigManager {
|
|||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param path the path
|
||||
* @param filename the filename
|
||||
* @param tClass the t class
|
||||
* @return the t
|
||||
*/
|
||||
private static <T> T load(String path, String filename, Class<T> tClass) {
|
||||
File file = prepareConfigFile(path, filename);
|
||||
|
@ -100,21 +113,31 @@ public class ConfigManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize element t.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param element the element
|
||||
* @param tClass the t class
|
||||
* @return the t
|
||||
*/
|
||||
public static <T> T deserializeElement(JsonElement element, Class<T> tClass) {
|
||||
return GSON.fromJson(element, tClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param path the path
|
||||
* @param filename the filename
|
||||
* @param data the data
|
||||
*/
|
||||
private static <T> void save(String path, String filename, T data) {
|
||||
File file = prepareConfigFile(path, filename);
|
||||
|
||||
String json = GSON.toJson(data);
|
||||
try (FileWriter fileWriter = new FileWriter(file)) {
|
||||
System.out.println("FILE WRITE ATTEMPT");
|
||||
System.out.println(path);
|
||||
System.out.println(json);
|
||||
fileWriter.write(json);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Couldn't save configuration file at " + path);
|
||||
|
@ -122,19 +145,30 @@ public class ConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save module.
|
||||
*
|
||||
* @param b the b
|
||||
*/
|
||||
public static void saveModule(ModuleBase b) {
|
||||
ModuleConfig c = new ModuleConfig();
|
||||
c.options = GlobalConfig.serializeModuleConfiguration(b);
|
||||
save("modules/", b.getModuleName() + ".json", c);
|
||||
save("petroleum/modules/", b.getModuleName() + ".json", c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all modules.
|
||||
*/
|
||||
public static void saveAllModules() {
|
||||
List<ModuleBase> mods = PetroleumMod.getActiveMods();
|
||||
mods.forEach(ConfigManager::saveModule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save global config.
|
||||
*/
|
||||
public static void saveGlobalConfig() {
|
||||
save("","petroleum.json", config);
|
||||
save("petroleum/", "petroleum.json", config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package pm.j4.petroleum.util.config;
|
|||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import pm.j4.petroleum.PetroleumMod;
|
||||
|
@ -43,15 +44,20 @@ public class GlobalConfig extends Config {
|
|||
* @param func the func
|
||||
*/
|
||||
public void setBinding(KeyBinding bind, ModuleBase func) {
|
||||
AtomicReference<KeyBinding> match = new AtomicReference<>();
|
||||
if (bindings.containsValue(func)) {
|
||||
bindings.forEach((key, binding) -> {
|
||||
if (binding.equals(func)) {
|
||||
PetroleumMod.removeBind(key);
|
||||
bindings.remove(key);
|
||||
match.set(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (match.get() != null) {
|
||||
bindings.remove(match.get());
|
||||
}
|
||||
|
||||
if (PetroleumMod.isActive(func.getModuleName())) {
|
||||
PetroleumMod.addBind(bind);
|
||||
bindings.put(bind, func);
|
||||
|
@ -69,6 +75,12 @@ public class GlobalConfig extends Config {
|
|||
moduleBase));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstruct binding key binding.
|
||||
*
|
||||
* @param info the info
|
||||
* @return the key binding
|
||||
*/
|
||||
public static KeyBinding reconstructBinding(BindingInfo info) {
|
||||
return new KeyBinding(
|
||||
info.translationKey,
|
||||
|
@ -79,7 +91,7 @@ public class GlobalConfig extends Config {
|
|||
}
|
||||
|
||||
/**
|
||||
* Extract binding binding info.
|
||||
* Extract binding info.
|
||||
*
|
||||
* @param b the b
|
||||
* @param f the f
|
||||
|
@ -147,8 +159,17 @@ public class GlobalConfig extends Config {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The Button locations.
|
||||
*/
|
||||
private final Map<String, ButtonInformation> buttonLocations = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Sets button.
|
||||
*
|
||||
* @param category the category
|
||||
* @param buttonInformation the button information
|
||||
*/
|
||||
public void setButton(String category, ButtonInformation buttonInformation) {
|
||||
if (buttonLocations.containsKey(category)) {
|
||||
buttonLocations.replace(category, buttonInformation);
|
||||
|
@ -157,6 +178,12 @@ public class GlobalConfig extends Config {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets button.
|
||||
*
|
||||
* @param category the category
|
||||
* @return the button
|
||||
*/
|
||||
public ButtonInformation getButton(String category) {
|
||||
if (buttonLocations.containsKey(category)) {
|
||||
return buttonLocations.get(category);
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
package pm.j4.petroleum.util.data;
|
||||
|
||||
/**
|
||||
* The type Button information.
|
||||
*/
|
||||
public class ButtonInformation {
|
||||
/**
|
||||
* The X.
|
||||
*/
|
||||
public double x;
|
||||
/**
|
||||
* The Y.
|
||||
*/
|
||||
public double y;
|
||||
public boolean open;
|
||||
/**
|
||||
* The Open.
|
||||
*/
|
||||
public final boolean open;
|
||||
|
||||
/**
|
||||
* Instantiates a new Button information.
|
||||
*
|
||||
* @param x the x
|
||||
* @param y the y
|
||||
* @param open the open
|
||||
*/
|
||||
public ButtonInformation(double x, double y, boolean open) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
|
@ -7,7 +7,15 @@ import java.util.Map;
|
|||
import pm.j4.petroleum.PetroleumMod;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type Category.
|
||||
*/
|
||||
public class Category {
|
||||
/**
|
||||
* Gets category map.
|
||||
*
|
||||
* @return the category map
|
||||
*/
|
||||
public static Map<String, List<ModuleBase>> getCategoryMap() {
|
||||
List<ModuleBase> modules = PetroleumMod.getActiveMods();
|
||||
Map<String, List<ModuleBase>> categoryMap = new HashMap<>();
|
||||
|
@ -27,6 +35,12 @@ public class Category {
|
|||
return categoryMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets by category.
|
||||
*
|
||||
* @param category the category
|
||||
* @return the by category
|
||||
*/
|
||||
public static List<ModuleBase> getByCategory(String category) {
|
||||
return getCategoryMap().containsKey(category) ? getCategoryMap().get(category) : new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,12 @@ package pm.j4.petroleum.util.data;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The type Module config.
|
||||
*/
|
||||
public class ModuleConfig {
|
||||
/**
|
||||
* The Options.
|
||||
*/
|
||||
public Map<String, OptionSerializiable> options;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,14 @@ public class OptionSerializiable {
|
|||
/**
|
||||
* Instantiates a new Option serializiable.
|
||||
*
|
||||
* @param value the value
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
public OptionSerializiable(String key, JsonElement value) {
|
||||
this.value = value;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.*;
|
|||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||
import pm.j4.petroleum.gui.PModuleConfigPane;
|
||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||
import pm.j4.petroleum.util.config.ConfigManager;
|
||||
import pm.j4.petroleum.util.module.option.ConfigurationOption;
|
||||
|
@ -19,6 +20,7 @@ public abstract class ModuleBase {
|
|||
* Parameters should be constant across restarts.
|
||||
*
|
||||
* @param name The name of the module
|
||||
* @param category the category
|
||||
* @param activatable Whether a module can be activated, or if it will remain in the state it was upon startup
|
||||
* @param hidden Whether the module will show up in @link pm.j4.petroleum.modules.menu.ModMenu or the active module list
|
||||
* @param hasConfigMenu whether a button in the configuration menu will show
|
||||
|
@ -30,7 +32,7 @@ public abstract class ModuleBase {
|
|||
this.activatable = activatable;
|
||||
this.hidden = hidden;
|
||||
this.hasConfigMenu = hasConfigMenu;
|
||||
this.moduleOptions = this.getDefaultConfig();
|
||||
this.moduleOptions = this.convertDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,8 +73,16 @@ public abstract class ModuleBase {
|
|||
return this.moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Category.
|
||||
*/
|
||||
private final String category;
|
||||
|
||||
/**
|
||||
* Gets category.
|
||||
*
|
||||
* @return the category
|
||||
*/
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
@ -165,6 +175,21 @@ public abstract class ModuleBase {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void updateConfigOption(String key, ConfigurationOption option) {
|
||||
System.out.println("update config option" + key + option.getStringValue());
|
||||
System.out.println(moduleOptions.keySet());
|
||||
if(moduleOptions.containsKey(key)) {
|
||||
System.out.println("matched");
|
||||
moduleOptions.replace(key, option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has option boolean.
|
||||
*
|
||||
* @param key the key
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean hasOption(String key) {
|
||||
return moduleOptions.containsKey(key);
|
||||
}
|
||||
|
@ -174,8 +199,17 @@ public abstract class ModuleBase {
|
|||
*
|
||||
* @return the default config
|
||||
*/
|
||||
protected Map<String, ConfigurationOption> getDefaultConfig() {
|
||||
return new HashMap<>();
|
||||
protected List<ConfigurationOption> getDefaultConfig() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private Map<String, ConfigurationOption> convertDefaultConfig() {
|
||||
List<ConfigurationOption> options = this.getDefaultConfig();
|
||||
Map<String, ConfigurationOption> mapped = new HashMap<>();
|
||||
options.forEach((option) -> {
|
||||
mapped.put(option.getConfigKey(), option);
|
||||
});
|
||||
return mapped;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,9 +230,9 @@ public abstract class ModuleBase {
|
|||
*
|
||||
* @return the config entries
|
||||
*/
|
||||
public List<PModuleConfigEntry> getConfigEntries() {
|
||||
public List<PModuleConfigEntry> getConfigEntries(PModuleConfigPane sourcePane) {
|
||||
List<PModuleConfigEntry> entries = new ArrayList<>();
|
||||
this.getModuleConfiguration().forEach((name, option) -> entries.add(new PModuleConfigEntry(option, new TranslatableText(name))));
|
||||
this.getModuleConfiguration().forEach((name, option) -> entries.add(new PModuleConfigEntry(option, new TranslatableText(name), sourcePane)));
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,32 @@ package pm.j4.petroleum.util.module.option;
|
|||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type Boolean value.
|
||||
*/
|
||||
public class BooleanOption extends ConfigurationOption {
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private boolean value;
|
||||
public BooleanOption(String description) {
|
||||
super(description);
|
||||
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param key
|
||||
* @param description the description
|
||||
*/
|
||||
public BooleanOption(String key, String description, ModuleBase parent) {
|
||||
super(key, description, parent);
|
||||
}
|
||||
|
||||
public boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(boolean value) { this.value = value; }
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return Boolean.toString(value);
|
||||
|
|
|
@ -1,27 +1,59 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type Configuration option.
|
||||
*
|
||||
*/
|
||||
public abstract class ConfigurationOption {
|
||||
/**
|
||||
* The Description.
|
||||
*/
|
||||
private final String description;
|
||||
private final String key;
|
||||
private final ModuleBase parent;
|
||||
|
||||
protected ConfigurationOption(String description) {
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param description the description
|
||||
*/
|
||||
public ConfigurationOption(String key, String description, ModuleBase parent) {
|
||||
this.description = description;
|
||||
this.key = key;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public final String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
public final String getConfigKey() { return key; }
|
||||
public final ModuleBase getParent() { return parent; }
|
||||
|
||||
/**
|
||||
* Gets string value.
|
||||
*
|
||||
* @return the string value
|
||||
*/
|
||||
public abstract String getStringValue();
|
||||
|
||||
/**
|
||||
* From json.
|
||||
*
|
||||
* @param e the e
|
||||
*/
|
||||
public abstract void fromJson(JsonElement e);
|
||||
|
||||
/**
|
||||
* To json json element.
|
||||
*
|
||||
* @return the json element
|
||||
*/
|
||||
public abstract JsonElement toJson();
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,29 @@ package pm.j4.petroleum.util.module.option;
|
|||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type Integer value.
|
||||
*/
|
||||
public class IntegerOption extends ConfigurationOption {
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private int value;
|
||||
protected IntegerOption(String description) {
|
||||
super(description);
|
||||
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param key
|
||||
* @param description the description
|
||||
* @param parent
|
||||
*/
|
||||
public IntegerOption(String key, String description, ModuleBase parent) {
|
||||
super(key, description, parent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getStringValue() {
|
||||
return Integer.toString(value);
|
||||
|
|
|
@ -12,10 +12,28 @@ import pm.j4.petroleum.util.module.ModuleBase;
|
|||
*/
|
||||
public class KeybindOption extends ConfigurationOption {
|
||||
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private KeyBinding value;
|
||||
/**
|
||||
* The Converted value.
|
||||
*/
|
||||
private BindingInfo convertedValue;
|
||||
public KeybindOption(String description) {
|
||||
super(description);
|
||||
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param key
|
||||
* @param description the description
|
||||
* @param parent
|
||||
*/
|
||||
public KeybindOption(String key, String description, ModuleBase parent) {
|
||||
super(key, description, parent);
|
||||
}
|
||||
|
||||
public String getTranslationKey() {
|
||||
return value.getTranslationKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,6 +53,12 @@ public class KeybindOption extends ConfigurationOption {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* From keybind.
|
||||
*
|
||||
* @param bind the bind
|
||||
* @param base the base
|
||||
*/
|
||||
public void fromKeybind(KeyBinding bind, ModuleBase base) {
|
||||
this.value = bind;
|
||||
this.convertedValue = GlobalConfig.extractBinding(bind, base);
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
package pm.j4.petroleum.util.module.option;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type List option.
|
||||
*/
|
||||
public class ListOption extends ConfigurationOption {
|
||||
protected ListOption(String description) {
|
||||
super(description);
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param key
|
||||
* @param description the description
|
||||
* @param parent
|
||||
*/
|
||||
public ListOption(String key, String description, ModuleBase parent) {
|
||||
super(key, description, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,18 +2,30 @@ package pm.j4.petroleum.util.module.option;
|
|||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import pm.j4.petroleum.util.module.ModuleBase;
|
||||
|
||||
/**
|
||||
* The type String value.
|
||||
*/
|
||||
public class StringOption extends ConfigurationOption {
|
||||
|
||||
/**
|
||||
* The Value.
|
||||
*/
|
||||
private String value;
|
||||
|
||||
protected StringOption(String description) {
|
||||
super(description);
|
||||
/**
|
||||
* Instantiates a new Configuration option.
|
||||
*
|
||||
* @param key
|
||||
* @param description the description
|
||||
* @param parent
|
||||
*/
|
||||
public StringOption(String key, String description, ModuleBase parent) {
|
||||
super(key, description, parent);
|
||||
}
|
||||
|
||||
|
||||
public String getStringValue() {
|
||||
return value;
|
||||
}
|
||||
|
|
13
src/main/resources/assets/petroleum/lang/en_us.json
Normal file
13
src/main/resources/assets/petroleum/lang/en_us.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"petroleum.bindings": "Binding Manager",
|
||||
"petroleum.example": "Test Module",
|
||||
"petroleum.splashtext": "Splash Text",
|
||||
"petroleum.modlist": "Module List",
|
||||
"petroleum.modmenu": "Mod Menu",
|
||||
|
||||
"petroleum.xray": "X-ray",
|
||||
|
||||
"petroleum.misc": "Miscellaneous",
|
||||
"petroleum.render": "Render",
|
||||
"petroleum.options": "Petroleum Options"
|
||||
}
|
|
@ -12,10 +12,8 @@
|
|||
"homepage": "https://j4.pm/",
|
||||
"sources": "https://gitdab.com/jane/petroleum"
|
||||
},
|
||||
|
||||
"license": "WTFPL",
|
||||
"icon": "assets/petroleum/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
|
@ -25,11 +23,11 @@
|
|||
"mixins": [
|
||||
"petroleum.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
"minecraft": "1.16.x",
|
||||
"kerosene": ">=0.1.5"
|
||||
},
|
||||
"suggests": {
|
||||
"flamingo": "*"
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"TitleScreenMixin",
|
||||
"OptionsMenuMixin",
|
||||
"EntryListWidgetAccessor",
|
||||
"DebugHudMixin",
|
||||
"ModListMixin"
|
||||
"EntryListWidgetAccessor",
|
||||
"ModListMixin",
|
||||
"OptionsMenuMixin",
|
||||
"TitleScreenMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue