Button positions now persist across restart, with some issues.
This commit is contained in:
parent
c35f42e486
commit
35ff8912de
13 changed files with 127 additions and 48 deletions
|
@ -13,13 +13,13 @@ import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.options.KeyBinding;
|
import net.minecraft.client.options.KeyBinding;
|
||||||
import net.minecraft.server.integrated.IntegratedServer;
|
import net.minecraft.server.integrated.IntegratedServer;
|
||||||
import pm.j4.petroleum.modules.ExampleModule;
|
import pm.j4.petroleum.modules.ExampleModule;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
|
||||||
import pm.j4.petroleum.modules.bindings.BindingManager;
|
import pm.j4.petroleum.modules.bindings.BindingManager;
|
||||||
import pm.j4.petroleum.modules.list.ModList;
|
import pm.j4.petroleum.modules.list.ModList;
|
||||||
import pm.j4.petroleum.modules.menu.ModMenu;
|
import pm.j4.petroleum.modules.menu.ModMenu;
|
||||||
import pm.j4.petroleum.modules.splash.SplashText;
|
import pm.j4.petroleum.modules.splash.SplashText;
|
||||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||||
import pm.j4.petroleum.util.config.ConfigManager;
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
|
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
|
@ -136,14 +136,17 @@ public class PetroleumMod implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
ConfigManager.initConfig();
|
ConfigManager.initConfig();
|
||||||
//initialize any keybinds, data, etc.
|
|
||||||
activeMods.forEach(ModuleBase::init);
|
|
||||||
|
|
||||||
// always update mod data
|
// always update mod data
|
||||||
Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer("petroleum");
|
Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer("petroleum");
|
||||||
modContainer.ifPresent(container -> modData = container.getMetadata());
|
modContainer.ifPresent(container -> modData = container.getMetadata());
|
||||||
|
|
||||||
Optional<ConfigHolder> conf = ConfigManager.getConfig();
|
Optional<ConfigHolder> conf = ConfigManager.getConfig();
|
||||||
|
|
||||||
|
|
||||||
|
//initialize any keybinds, data, etc.
|
||||||
|
activeMods.forEach(ModuleBase::init);
|
||||||
|
|
||||||
//initialize keybind handler
|
//initialize keybind handler
|
||||||
conf.ifPresent(configHolder -> ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
conf.ifPresent(configHolder -> ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
if (PetroleumMod.client != client) {
|
if (PetroleumMod.client != client) {
|
||||||
|
|
|
@ -11,8 +11,8 @@ import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import pm.j4.petroleum.modules.menu.ModMenu;
|
import pm.j4.petroleum.modules.menu.ModMenu;
|
||||||
import pm.j4.petroleum.util.config.ConfigManager;
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.data.ButtonInformation;
|
||||||
import pm.j4.petroleum.util.data.Category;
|
import pm.j4.petroleum.util.data.Category;
|
||||||
import pm.j4.petroleum.util.data.Coordinate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type P mod menu screen.
|
* The type P mod menu screen.
|
||||||
|
@ -34,15 +34,24 @@ public class PModMenuScreen extends Screen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
Map<String, Coordinate> coordinateMap = ModMenu.getButtons();
|
Map<String, ButtonInformation> coordinateMap = ModMenu.getButtons();
|
||||||
coordinateMap.forEach((category, coord) -> {
|
coordinateMap.forEach((category, coord) -> {
|
||||||
this.addButton(new PMovableButton((int)(coord.x * this.width), (int)(coord.y * this.height), category, Category.getByCategory(category), this));
|
this.addButton(new PMovableButton((int) (coord.x * this.width),
|
||||||
|
(int) (coord.y * this.height),
|
||||||
|
category,
|
||||||
|
Category.getByCategory(category),
|
||||||
|
coord.open,
|
||||||
|
this));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
ConfigManager.getConfig().get().disableModule("petroleum.modmenu");
|
if (ConfigManager.getConfig().isPresent()) {
|
||||||
|
ConfigManager.getConfig().get().disableModule("petroleum.modmenu");
|
||||||
|
this.buttons.forEach(button -> ((PMovableButton) button).updateCoordinate());
|
||||||
|
ConfigManager.save();
|
||||||
|
}
|
||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Matrix4f;
|
import net.minecraft.util.math.Matrix4f;
|
||||||
import pm.j4.petroleum.modules.menu.ModMenu;
|
import pm.j4.petroleum.modules.menu.ModMenu;
|
||||||
import pm.j4.petroleum.util.data.Coordinate;
|
import pm.j4.petroleum.util.data.ButtonInformation;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,9 +63,9 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
*/
|
*/
|
||||||
private final int padding = 5;
|
private final int padding = 5;
|
||||||
|
|
||||||
private String category;
|
private final String category;
|
||||||
|
|
||||||
private PModMenuScreen parent;
|
private final PModMenuScreen parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new P movable button.
|
* Instantiates a new P movable button.
|
||||||
|
@ -75,7 +75,7 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
* @param categoryName the category name
|
* @param categoryName the category name
|
||||||
* @param modules the modules
|
* @param modules the modules
|
||||||
*/
|
*/
|
||||||
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules, PModMenuScreen parent) {
|
public PMovableButton(int x, int y, String categoryName, List<ModuleBase> modules, boolean open, PModMenuScreen parent) {
|
||||||
super(x, y, 0, 0, new TranslatableText(categoryName));
|
super(x, y, 0, 0, new TranslatableText(categoryName));
|
||||||
this.category = categoryName;
|
this.category = categoryName;
|
||||||
int w = MinecraftClient.getInstance().textRenderer.getWidth(categoryName) + 8;
|
int w = MinecraftClient.getInstance().textRenderer.getWidth(categoryName) + 8;
|
||||||
|
@ -87,6 +87,7 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
this.collapsedHeight = h;
|
this.collapsedHeight = h;
|
||||||
this.expandedHeight = 0;
|
this.expandedHeight = 0;
|
||||||
this.moduleHeight = h;
|
this.moduleHeight = h;
|
||||||
|
this.expanded = open;
|
||||||
this.modules = modules;
|
this.modules = modules;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +118,13 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
|
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||||
this.x += (int) deltaX;
|
this.x += (int) deltaX;
|
||||||
this.y += (int) deltaY;
|
this.y += (int) deltaY;
|
||||||
|
|
||||||
// i really hate to do it but nowhere else will it properly save
|
// 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)));
|
this.updateCoordinate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateCoordinate() {
|
||||||
|
ModMenu.updateCoord(this.category, new ButtonInformation((this.x / (double) parent.width), (this.y / (double) parent.height), this.expanded));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fuck click sounds
|
// fuck click sounds
|
||||||
|
@ -130,8 +136,7 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
if (bl && mouseY > this.y + this.collapsedHeight && mouseY < this.y + this.expandedHeight) {
|
if (bl && mouseY > this.y + this.collapsedHeight && mouseY < this.y + this.expandedHeight) {
|
||||||
this.onExtraClick(mouseX, mouseY);
|
this.onExtraClick(mouseX, mouseY);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (bl) {
|
||||||
else if (bl) {
|
|
||||||
this.onClick(mouseX, mouseY);
|
this.onClick(mouseX, mouseY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +193,11 @@ public class PMovableButton extends AbstractButtonWidget {
|
||||||
this.expandedWidth = w;
|
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();
|
MinecraftClient minecraftClient = MinecraftClient.getInstance();
|
||||||
|
|
|
@ -19,8 +19,8 @@ import net.minecraft.text.StringVisitable;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import pm.j4.petroleum.PetroleumMod;
|
import pm.j4.petroleum.PetroleumMod;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
|
||||||
import pm.j4.petroleum.util.config.ConfigManager;
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type P options screen.
|
* The type P options screen.
|
||||||
|
|
|
@ -15,10 +15,10 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
|
||||||
import pm.j4.petroleum.modules.list.ModList;
|
import pm.j4.petroleum.modules.list.ModList;
|
||||||
import pm.j4.petroleum.util.config.ConfigHolder;
|
import pm.j4.petroleum.util.config.ConfigHolder;
|
||||||
import pm.j4.petroleum.util.config.ConfigManager;
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Mod list mixin.
|
* The type Mod list mixin.
|
||||||
|
|
|
@ -9,11 +9,11 @@ import net.minecraft.text.TranslatableText;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import pm.j4.petroleum.PetroleumMod;
|
import pm.j4.petroleum.PetroleumMod;
|
||||||
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
import pm.j4.petroleum.gui.PModuleConfigEntry;
|
||||||
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.config.GlobalConfig;
|
||||||
import pm.j4.petroleum.util.module.ConfigurationOption;
|
import pm.j4.petroleum.util.module.ConfigurationOption;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
import pm.j4.petroleum.util.module.option.KeybindValue;
|
import pm.j4.petroleum.util.module.option.KeybindValue;
|
||||||
import pm.j4.petroleum.util.config.ConfigManager;
|
|
||||||
import pm.j4.petroleum.util.config.GlobalConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Binding manager.
|
* The type Binding manager.
|
||||||
|
@ -44,7 +44,6 @@ public class BindingManager extends ModuleBase {
|
||||||
Map<ConfigurationOption<KeybindValue>, ModuleBase> mapped = new HashMap<>();
|
Map<ConfigurationOption<KeybindValue>, ModuleBase> mapped = new HashMap<>();
|
||||||
if (ConfigManager.getConfig().isPresent()) {
|
if (ConfigManager.getConfig().isPresent()) {
|
||||||
Map<KeyBinding, ModuleBase> binds = ConfigManager.getConfig().get().globalConfig.bindings;
|
Map<KeyBinding, ModuleBase> binds = ConfigManager.getConfig().get().globalConfig.bindings;
|
||||||
System.out.println("Number of bindings: " + binds.size());
|
|
||||||
binds.forEach((key, func) -> mapped.put(new ConfigurationOption<>(new KeybindValue(key)), func));
|
binds.forEach((key, func) -> mapped.put(new ConfigurationOption<>(new KeybindValue(key)), func));
|
||||||
}
|
}
|
||||||
mapped.forEach((bind, module) -> {
|
mapped.forEach((bind, module) -> {
|
||||||
|
|
|
@ -5,17 +5,17 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import pm.j4.petroleum.gui.PModMenuScreen;
|
import pm.j4.petroleum.gui.PModMenuScreen;
|
||||||
|
import pm.j4.petroleum.util.config.ConfigManager;
|
||||||
|
import pm.j4.petroleum.util.data.ButtonInformation;
|
||||||
import pm.j4.petroleum.util.data.Category;
|
import pm.j4.petroleum.util.data.Category;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
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.
|
* The type Mod menu.
|
||||||
*/
|
*/
|
||||||
public class ModMenu extends ModuleBase {
|
public class ModMenu extends ModuleBase {
|
||||||
|
|
||||||
private static Map<String, Coordinate> coordinates = new HashMap<>();
|
private static final Map<String, ButtonInformation> coordinates = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Mod menu.
|
* Instantiates a new Mod menu.
|
||||||
|
@ -28,25 +28,43 @@ public class ModMenu extends ModuleBase {
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO figure out resizing
|
||||||
|
// the number itself changes, so it should just be probably like some onResize bullshit in PModMenuScreen
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
Map<String, List<ModuleBase>> categories = Category.getCategoryMap();
|
Map<String, List<ModuleBase>> categories = Category.getCategoryMap();
|
||||||
final double[] h = {.1};
|
final double[] h = {.1};
|
||||||
categories.forEach((category, moduleList) -> {
|
categories.forEach((category, moduleList) -> {
|
||||||
System.out.println("category: " + category);
|
ButtonInformation conf = ConfigManager.getConfig().isPresent() ?
|
||||||
Coordinate coord = new Coordinate(.1, h[0]);
|
ConfigManager.getConfig().get().globalConfig.getButton(category) :
|
||||||
|
null;
|
||||||
|
ButtonInformation coord = conf != null ? conf : new ButtonInformation(.1, h[0], false);
|
||||||
h[0] += .01;
|
h[0] += .01;
|
||||||
coordinates.put(category, coord);
|
coordinates.put(category, coord);
|
||||||
|
if (ConfigManager.getConfig().isPresent()) {
|
||||||
|
ConfigManager.getConfig().get().globalConfig.setButton(category, coord);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCoord(String b, Coordinate c) {
|
public static void updateCoord(String b, ButtonInformation c) {
|
||||||
|
if (c.x < 0.05) {
|
||||||
|
c.x = 0.05;
|
||||||
|
}
|
||||||
|
if (c.x > .95) {
|
||||||
|
c.x = .95;
|
||||||
|
}
|
||||||
|
if (c.y < 0.05) {
|
||||||
|
c.y = 0.05;
|
||||||
|
}
|
||||||
|
if (c.y > .95) {
|
||||||
|
c.y = .95;
|
||||||
|
}
|
||||||
if (coordinates.containsKey(b)) {
|
if (coordinates.containsKey(b)) {
|
||||||
coordinates.replace(b, c);
|
coordinates.replace(b, c);
|
||||||
}
|
if (ConfigManager.getConfig().isPresent()) {
|
||||||
else {
|
ConfigManager.getConfig().get().globalConfig.setButton(b, c);
|
||||||
System.out.println("issue! no matching coordinate found");
|
}
|
||||||
System.out.println(b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +78,7 @@ public class ModMenu extends ModuleBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Coordinate> getButtons() {
|
public static Map<String, ButtonInformation> getButtons() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,8 @@ import java.util.*;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import pm.j4.petroleum.PetroleumMod;
|
import pm.j4.petroleum.PetroleumMod;
|
||||||
import pm.j4.petroleum.modules.bindings.BindingInfo;
|
import pm.j4.petroleum.modules.bindings.BindingInfo;
|
||||||
|
import pm.j4.petroleum.modules.menu.ModMenu;
|
||||||
|
import pm.j4.petroleum.util.data.ButtonInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Config manager.
|
* The type Config manager.
|
||||||
|
@ -135,6 +137,12 @@ class SerializationHelper {
|
||||||
});
|
});
|
||||||
jsonConfig.add("module_configuration", moduleConfigs);
|
jsonConfig.add("module_configuration", moduleConfigs);
|
||||||
|
|
||||||
|
JsonObject tabCoordinates = new JsonObject();
|
||||||
|
ModMenu.getButtons().forEach((category, coordinates) -> {
|
||||||
|
tabCoordinates.add(category, ctx.serialize(coordinates));
|
||||||
|
});
|
||||||
|
jsonConfig.add("button_coordinates", tabCoordinates);
|
||||||
|
|
||||||
return jsonConfig;
|
return jsonConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,6 +169,13 @@ class SerializationHelper {
|
||||||
} else {
|
} else {
|
||||||
options = new HashMap<>();
|
options = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
if (obj.has("button_coordinates")) {
|
||||||
|
obj.get("button_coordinates").getAsJsonObject().entrySet().forEach(
|
||||||
|
value -> {
|
||||||
|
cfg.setButton(value.getKey(), ctx.deserialize(value.getValue(), ButtonInformation.class));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
PetroleumMod.getActiveMods().forEach(module -> {
|
PetroleumMod.getActiveMods().forEach(module -> {
|
||||||
if (options.containsKey(module.getModuleName())) {
|
if (options.containsKey(module.getModuleName())) {
|
||||||
cfg.deserializeModuleConfiguration(options.get(module.getModuleName()), module);
|
cfg.deserializeModuleConfiguration(options.get(module.getModuleName()), module);
|
||||||
|
|
|
@ -5,10 +5,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import net.minecraft.client.options.KeyBinding;
|
import net.minecraft.client.options.KeyBinding;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.client.util.InputUtil;
|
||||||
import pm.j4.petroleum.PetroleumMod;
|
import pm.j4.petroleum.PetroleumMod;
|
||||||
|
import pm.j4.petroleum.modules.bindings.BindingInfo;
|
||||||
|
import pm.j4.petroleum.util.data.ButtonInformation;
|
||||||
import pm.j4.petroleum.util.module.ConfigurationOption;
|
import pm.j4.petroleum.util.module.ConfigurationOption;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
import pm.j4.petroleum.util.module.option.OptionTypeMatcher;
|
import pm.j4.petroleum.util.module.option.OptionTypeMatcher;
|
||||||
import pm.j4.petroleum.modules.bindings.BindingInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Global config.
|
* The type Global config.
|
||||||
|
@ -139,5 +140,23 @@ public class GlobalConfig extends Config {
|
||||||
module.setConfigOption(option.key, new ConfigurationOption<>(OptionTypeMatcher.match(option.type, option.value)));
|
module.setConfigOption(option.key, new ConfigurationOption<>(OptionTypeMatcher.match(option.type, option.value)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Map<String, ButtonInformation> buttonLocations = new HashMap<>();
|
||||||
|
|
||||||
|
public void setButton(String category, ButtonInformation buttonInformation) {
|
||||||
|
if (buttonLocations.containsKey(category)) {
|
||||||
|
buttonLocations.replace(category, buttonInformation);
|
||||||
|
} else {
|
||||||
|
buttonLocations.put(category, buttonInformation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonInformation getButton(String category) {
|
||||||
|
if (buttonLocations.containsKey(category)) {
|
||||||
|
return buttonLocations.get(category);
|
||||||
|
}
|
||||||
|
System.out.println("Could not find button of category " + category);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package pm.j4.petroleum.util.data;
|
||||||
|
|
||||||
|
public class ButtonInformation {
|
||||||
|
public double x;
|
||||||
|
public double y;
|
||||||
|
public boolean open;
|
||||||
|
|
||||||
|
public ButtonInformation(double x, double y, boolean open) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.open = open;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
package pm.j4.petroleum.util.data;
|
package pm.j4.petroleum.util.data;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import pm.j4.petroleum.PetroleumMod;
|
import pm.j4.petroleum.PetroleumMod;
|
||||||
import pm.j4.petroleum.util.module.ModuleBase;
|
import pm.j4.petroleum.util.module.ModuleBase;
|
||||||
|
|
||||||
|
@ -9,16 +12,15 @@ public class Category {
|
||||||
List<ModuleBase> modules = PetroleumMod.getActiveMods();
|
List<ModuleBase> modules = PetroleumMod.getActiveMods();
|
||||||
Map<String, List<ModuleBase>> categoryMap = new HashMap<>();
|
Map<String, List<ModuleBase>> categoryMap = new HashMap<>();
|
||||||
modules.forEach(module -> {
|
modules.forEach(module -> {
|
||||||
if(!categoryMap.containsKey(module.getCategory())) {
|
if (!categoryMap.containsKey(module.getCategory())) {
|
||||||
List<ModuleBase> m = new ArrayList<>();
|
List<ModuleBase> m = new ArrayList<>();
|
||||||
m.add(module);
|
m.add(module);
|
||||||
categoryMap.put(module.getCategory(), m);
|
categoryMap.put(module.getCategory(), m);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
List<ModuleBase> m = categoryMap.get(module.getCategory());
|
List<ModuleBase> m = categoryMap.get(module.getCategory());
|
||||||
List<ModuleBase> nm = new ArrayList<>();
|
List<ModuleBase> nm = new ArrayList<>();
|
||||||
nm.addAll(m);
|
nm.addAll(m);
|
||||||
m.add(module);
|
nm.add(module);
|
||||||
categoryMap.replace(module.getCategory(), nm);
|
categoryMap.replace(module.getCategory(), nm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -70,7 +70,9 @@ public abstract class ModuleBase {
|
||||||
|
|
||||||
private final String category;
|
private final String category;
|
||||||
|
|
||||||
public String getCategory() { return this.category; }
|
public String getCategory() {
|
||||||
|
return this.category;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Readable name.
|
* The Readable name.
|
||||||
|
|
Loading…
Reference in a new issue