Button (mostly) persists between closing and re-opening. does not

persist between restarts. also refactored ModuleBase & related out of
module
This commit is contained in:
janeptrv 2020-10-08 00:58:13 -04:00
parent fab5de9751
commit c35f42e486
28 changed files with 167 additions and 54 deletions

View file

@ -13,7 +13,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.server.integrated.IntegratedServer;
import pm.j4.petroleum.modules.ExampleModule;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.modules.bindings.BindingManager;
import pm.j4.petroleum.modules.list.ModList;
import pm.j4.petroleum.modules.menu.ModMenu;
@ -136,13 +136,13 @@ public class PetroleumMod implements ModInitializer {
@Override
public void onInitialize() {
ConfigManager.initConfig();
//initialize any keybinds, data, etc.
activeMods.forEach(ModuleBase::init);
// always update mod data
Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer("petroleum");
modContainer.ifPresent(container -> modData = container.getMetadata());
//initialize any keybinds, data, etc.
activeMods.forEach(ModuleBase::init);
Optional<ConfigHolder> conf = ConfigManager.getConfig();
//initialize keybind handler
conf.ifPresent(configHolder -> ClientTickEvents.END_CLIENT_TICK.register(client -> {
@ -154,7 +154,6 @@ public class PetroleumMod implements ModInitializer {
configHolder.globalConfig.bindings.get(b).activate(client);
}
}
//System.out.println(getServerAddress());
}));
}
}

View file

@ -1,6 +1,7 @@
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;
@ -8,8 +9,10 @@ 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.PetroleumMod;
import pm.j4.petroleum.modules.menu.ModMenu;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.data.Category;
import pm.j4.petroleum.util.data.Coordinate;
/**
* The type P mod menu screen.
@ -31,7 +34,10 @@ public class PModMenuScreen extends Screen {
@Override
protected void init() {
this.addButton(new PMovableButton(10, 10, "Test", PetroleumMod.getActiveMods()));
Map<String, Coordinate> 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), this));
});
}
@Override

View file

@ -5,7 +5,7 @@ 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.modules.base.ConfigurationOption;
import pm.j4.petroleum.util.module.ConfigurationOption;
/**
* The type P module config entry.

View file

@ -14,7 +14,7 @@ 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.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P module configuration widget.

View file

@ -10,9 +10,12 @@ 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.base.ModuleBase;
import pm.j4.petroleum.modules.menu.ModMenu;
import pm.j4.petroleum.util.data.Coordinate;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P movable button.
@ -60,6 +63,10 @@ public class PMovableButton extends AbstractButtonWidget {
*/
private final int padding = 5;
private String category;
private PModMenuScreen parent;
/**
* Instantiates a new P movable button.
*
@ -68,8 +75,9 @@ public class PMovableButton extends AbstractButtonWidget {
* @param categoryName the category name
* @param modules the modules
*/
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules) {
super(x, y, 0, 0, new LiteralText(categoryName));
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules, PModMenuScreen parent) {
super(x, y, 0, 0, new TranslatableText(categoryName));
this.category = categoryName;
int w = MinecraftClient.getInstance().textRenderer.getWidth(categoryName) + 8;
int h = MinecraftClient.getInstance().textRenderer.fontHeight + 8;
this.width = w;
@ -80,6 +88,7 @@ public class PMovableButton extends AbstractButtonWidget {
this.expandedHeight = 0;
this.moduleHeight = h;
this.modules = modules;
this.parent = parent;
}
@Override
@ -89,6 +98,11 @@ public class PMovableButton extends AbstractButtonWidget {
super.onClick(mouseX, mouseY);
}
private void onExtraClick(double mouseX, double mouseY) {
System.out.println("extra click");
//TODO module things
}
@Override
public void onRelease(double mouseX, double mouseY) {
int mx = (int) mouseX;
@ -103,6 +117,8 @@ public class PMovableButton extends AbstractButtonWidget {
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
ModMenu.updateCoord(this.category, new Coordinate((this.x / (double)parent.width), (this.y / (double)parent.height)));
}
// fuck click sounds
@ -111,7 +127,11 @@ public class PMovableButton extends AbstractButtonWidget {
if (this.active && this.visible) {
if (this.isValidClickButton(button)) {
boolean bl = this.clicked(mouseX, mouseY);
if (bl) {
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;
}

View file

@ -9,7 +9,7 @@ import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Language;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type P option entry.

View file

@ -19,7 +19,7 @@ import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.util.config.ConfigManager;
/**

View file

@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.modules.list.ModList;
import pm.j4.petroleum.util.config.ConfigHolder;
import pm.j4.petroleum.util.config.ConfigManager;

View file

@ -3,9 +3,9 @@ package pm.j4.petroleum.modules;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.MinecraftClient;
import pm.j4.petroleum.modules.base.ConfigurationOption;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.modules.base.option.BooleanValue;
import pm.j4.petroleum.util.module.ConfigurationOption;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.util.module.option.BooleanValue;
/**
* The type Example module.
@ -15,7 +15,11 @@ public class ExampleModule extends ModuleBase {
* example mod
*/
public ExampleModule() {
super("petroleum.example", true, false, true);
super("petroleum.example",
"petroleum.misc",
true,
false,
true);
}
@Override

View file

@ -1,9 +0,0 @@
package pm.j4.petroleum.modules.base.option;
import pm.j4.petroleum.modules.base.StringWritable;
/**
* The type Dummy value.
*/
public class DummyValue extends StringWritable<Boolean> {
}

View file

@ -9,9 +9,9 @@ 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.modules.base.ConfigurationOption;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.modules.base.option.KeybindValue;
import pm.j4.petroleum.util.module.ConfigurationOption;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.util.module.option.KeybindValue;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.config.GlobalConfig;
@ -25,6 +25,7 @@ public class BindingManager extends ModuleBase {
*/
public BindingManager() {
super("petroleum.bindings",
"petroleum.misc",
false,
true,
true);

View file

@ -3,7 +3,7 @@ package pm.j4.petroleum.modules.list;
import java.util.ArrayList;
import java.util.List;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type Mod list.
@ -14,6 +14,7 @@ public class ModList extends ModuleBase {
*/
public ModList() {
super("petroleum.modlist",
"petroleum.misc",
true,
true,
true);

View file

@ -1,25 +1,55 @@
package pm.j4.petroleum.modules.menu;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.MinecraftClient;
import pm.j4.petroleum.gui.PModMenuScreen;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.data.Category;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.util.config.ConfigManager;
import pm.j4.petroleum.util.data.Coordinate;
/**
* The type Mod menu.
*/
public class ModMenu extends ModuleBase {
private static Map<String, Coordinate> coordinates = new HashMap<>();
/**
* Instantiates a new Mod menu.
*/
public ModMenu() {
super("petroleum.modmenu",
"petroleum.misc",
true,
true,
true);
}
@Override
public void init() {
Map<String, List<ModuleBase>> categories = Category.getCategoryMap();
final double[] h = {.1};
categories.forEach((category, moduleList) -> {
System.out.println("category: " + category);
Coordinate coord = new Coordinate(.1, h[0]);
h[0] += .01;
coordinates.put(category, coord);
});
}
public static void updateCoord(String b, Coordinate c) {
if (coordinates.containsKey(b)) {
coordinates.replace(b, c);
}
else {
System.out.println("issue! no matching coordinate found");
System.out.println(b);
}
}
@Override
public void activate(MinecraftClient client) {
this.toggle();
@ -29,4 +59,8 @@ public class ModMenu extends ModuleBase {
client.openScreen(null);
}
}
public static Map<String, Coordinate> getButtons() {
return coordinates;
}
}

View file

@ -1,7 +1,7 @@
package pm.j4.petroleum.modules.splash;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type Splash text.
@ -12,6 +12,7 @@ public class SplashText extends ModuleBase {
*/
public SplashText() {
super("petroleum.splashtext",
"petroleum.misc",
true,
true,
false);

View file

@ -3,7 +3,7 @@ package pm.j4.petroleum.util.config;
import java.util.ArrayList;
import java.util.List;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type Config.

View file

@ -4,7 +4,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.util.module.ModuleBase;
/**
* The type Config holder.

View file

@ -5,9 +5,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.modules.base.ConfigurationOption;
import pm.j4.petroleum.modules.base.ModuleBase;
import pm.j4.petroleum.modules.base.option.OptionTypeMatcher;
import pm.j4.petroleum.util.module.ConfigurationOption;
import pm.j4.petroleum.util.module.ModuleBase;
import pm.j4.petroleum.util.module.option.OptionTypeMatcher;
import pm.j4.petroleum.modules.bindings.BindingInfo;
/**

View file

@ -0,0 +1,31 @@
package pm.j4.petroleum.util.data;
import java.util.*;
import pm.j4.petroleum.PetroleumMod;
import pm.j4.petroleum.util.module.ModuleBase;
public class Category {
public static Map<String, List<ModuleBase>> getCategoryMap() {
List<ModuleBase> modules = PetroleumMod.getActiveMods();
Map<String, List<ModuleBase>> categoryMap = new HashMap<>();
modules.forEach(module -> {
if(!categoryMap.containsKey(module.getCategory())) {
List<ModuleBase> m = new ArrayList<>();
m.add(module);
categoryMap.put(module.getCategory(), m);
}
else {
List<ModuleBase> m = categoryMap.get(module.getCategory());
List<ModuleBase> nm = new ArrayList<>();
nm.addAll(m);
m.add(module);
categoryMap.replace(module.getCategory(), nm);
}
});
return categoryMap;
}
public static List<ModuleBase> getByCategory(String category) {
return getCategoryMap().containsKey(category) ? getCategoryMap().get(category) : new ArrayList<>();
}
}

View file

@ -0,0 +1,11 @@
package pm.j4.petroleum.util.data;
public class Coordinate {
public double x;
public double y;
public Coordinate(double x, double y) {
this.x = x;
this.y = y;
}
}

View file

@ -1,4 +1,4 @@
package pm.j4.petroleum.modules.base;
package pm.j4.petroleum.util.module;
/**
* The type Configuration option.

View file

@ -1,4 +1,4 @@
package pm.j4.petroleum.modules.base;
package pm.j4.petroleum.util.module;
import java.util.*;
import net.minecraft.client.MinecraftClient;
@ -21,8 +21,9 @@ public abstract class ModuleBase {
* @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
*/
public ModuleBase(String name, boolean activatable, boolean hidden, boolean hasConfigMenu) {
public ModuleBase(String name, String category, boolean activatable, boolean hidden, boolean hasConfigMenu) {
this.moduleName = name;
this.category = category;
this.readableName = new TranslatableText(name);
this.activatable = activatable;
this.hidden = hidden;
@ -67,6 +68,10 @@ public abstract class ModuleBase {
return this.moduleName;
}
private final String category;
public String getCategory() { return this.category; }
/**
* The Readable name.
*/

View file

@ -1,4 +1,4 @@
package pm.j4.petroleum.modules.base;
package pm.j4.petroleum.util.module;
/**
* The type String writable.

View file

@ -1,6 +1,6 @@
package pm.j4.petroleum.modules.base.option;
package pm.j4.petroleum.util.module.option;
import pm.j4.petroleum.modules.base.StringWritable;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type Boolean value.

View file

@ -0,0 +1,9 @@
package pm.j4.petroleum.util.module.option;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type Dummy value.
*/
public class DummyValue extends StringWritable<Boolean> {
}

View file

@ -1,6 +1,6 @@
package pm.j4.petroleum.modules.base.option;
package pm.j4.petroleum.util.module.option;
import pm.j4.petroleum.modules.base.StringWritable;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type Integer value.

View file

@ -1,7 +1,7 @@
package pm.j4.petroleum.modules.base.option;
package pm.j4.petroleum.util.module.option;
import net.minecraft.client.options.KeyBinding;
import pm.j4.petroleum.modules.base.StringWritable;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type Keybind value.

View file

@ -1,6 +1,6 @@
package pm.j4.petroleum.modules.base.option;
package pm.j4.petroleum.util.module.option;
import pm.j4.petroleum.modules.base.StringWritable;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type Option type matcher.

View file

@ -1,6 +1,6 @@
package pm.j4.petroleum.modules.base.option;
package pm.j4.petroleum.util.module.option;
import pm.j4.petroleum.modules.base.StringWritable;
import pm.j4.petroleum.util.module.StringWritable;
/**
* The type String value.