use of com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup in project Multiblocked by Low-Drag-MC.
the class PartBuilderWidget method walkFile.
private void walkFile(String type, IGuiTexture icon, File path, BiConsumer<JsonElement, File> consumer) {
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles((s, name) -> name.endsWith(".json"))).orElse(new File[0])) {
SelectableWidgetGroup widgetGroup = (SelectableWidgetGroup) new SelectableWidgetGroup(0, files.size() * 22, containers.getSize().width, 20).setOnSelected(group -> {
JsonElement jsonElement = FileUtility.loadJson(file);
if (jsonElement != null && jsonElement.isJsonObject()) {
try {
setNewRenderer(Multiblocked.GSON.fromJson(jsonElement, PartDefinition.class).baseRenderer, type);
} catch (Exception ignored) {
}
}
}).setSelectedTexture(-2, 0xff00aa00).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(134, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> {
JsonElement jsonElement = FileUtility.loadJson(file);
if (jsonElement != null && jsonElement.isJsonObject()) {
try {
consumer.accept(jsonElement, file);
} catch (Exception ignored) {
}
}
}).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, icon));
files.add(widgetGroup);
containers.addWidget(widgetGroup);
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup in project Multiblocked by Low-Drag-MC.
the class ControllerBuilderWidget method updateList.
protected void updateList() {
int size = files.size();
files.forEach(containers::waitToRemoved);
files.clear();
File path = new File(Multiblocked.location, "definition/controller");
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles((s, name) -> name.endsWith(".json"))).orElse(new File[0])) {
SelectableWidgetGroup widgetGroup = (SelectableWidgetGroup) new SelectableWidgetGroup(0, (containers.widgets.size() - size) * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
templateButton.setVisible(false);
selected = null;
onJsonSelected(file);
}).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(134, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> {
JsonElement jsonElement = FileUtility.loadJson(file);
if (jsonElement != null) {
try {
String recipeMap = jsonElement.getAsJsonObject().get("recipeMap").getAsString();
JsonBlockPattern pattern = Multiblocked.GSON.fromJson(jsonElement.getAsJsonObject().get("basePattern"), JsonBlockPattern.class);
ControllerDefinition definition = Multiblocked.GSON.fromJson(jsonElement, ControllerDefinition.class);
new ControllerWidget(this, definition, pattern, recipeMap, jsonObject -> {
if (jsonObject != null) {
FileUtility.saveJson(file, jsonObject);
}
});
} catch (Exception ignored) {
}
}
}).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(Items.PAPER)));
files.add(widgetGroup);
containers.addWidget(widgetGroup);
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup in project Multiblocked by Low-Drag-MC.
the class RecipeMapBuilderWidget method updateRecipeMapList.
private void updateRecipeMapList() {
recipeMapList.clearAllWidgets();
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(RecipeMap.EMPTY);
}
selected = null;
File path = new File(Multiblocked.location, "recipe_map");
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles()).orElse(new File[0])) {
if (file.isFile() && file.getName().endsWith(".json")) {
recipeMapList.addWidget(new SelectableWidgetGroup(5, 1 + recipeMapList.widgets.size() * 22, getSize().width - 30, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(W -> {
selected = file;
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class));
}
}).addWidget(new ImageWidget(0, 0, 120, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ButtonWidget(104, 4, 12, 12, new ResourceTexture("multiblocked:textures/gui/option.png"), cd -> new RecipeMapWidget(parent, Multiblocked.GSON.fromJson(FileUtility.loadJson(file), RecipeMap.class), recipeMap -> {
if (recipeMap != null) {
if (selected == file) {
if (onRecipeMapSelected != null) {
onRecipeMapSelected.accept(recipeMap);
}
}
JsonElement element = Multiblocked.GSON.toJsonTree(recipeMap);
FileUtility.saveJson(file, element);
}
})).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.tips.settings")).addWidget(new ImageWidget(2, 0, 96, 20, new TextTexture(file.getName().replace(".json", "")).setWidth(96).setType(TextTexture.TextType.ROLL))));
}
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup in project Multiblocked by Low-Drag-MC.
the class TemplateBuilderWidget method readInitialData.
@Override
public void readInitialData(PacketBuffer buffer) {
super.readInitialData(buffer);
this.addWidget(containers = new DraggableScrollableWidgetGroup(200, 120, 150, 98));
containers.setClientSideWidget();
for (int i = buffer.readVarInt(); i > 0; i--) {
ItemStack itemStack = buffer.readItem();
int slotIndex = buffer.readVarInt();
containers.addWidget(new SelectableWidgetGroup(0, containers.widgets.size() * 22, containers.getSize().width, 20).setSelectedTexture(-2, 0xff00aa00).setOnSelected(w -> onSelected(itemStack, slotIndex)).addWidget(new ImageWidget(0, 0, 150, 20, new ColorRectTexture(0x4faaaaaa))).addWidget(new ImageWidget(32, 0, 100, 20, new TextTexture(itemStack.getDisplayName().getString()).setWidth(100).setType(TextTexture.TextType.ROLL))).addWidget(new ImageWidget(4, 2, 18, 18, new ItemStackTexture(itemStack))));
}
}
use of com.lowdragmc.lowdraglib.gui.widget.SelectableWidgetGroup in project Multiblocked by Low-Drag-MC.
the class ControllerScriptWidget method updateList.
private void updateList() {
jsonList.clearAllWidgets();
selected = null;
File path = new File(Multiblocked.location, "definition/controller");
if (!path.isDirectory()) {
if (!path.mkdirs()) {
return;
}
}
for (File file : Optional.ofNullable(path.listFiles()).orElse(new File[0])) {
if (file.isFile() && file.getName().endsWith(".json")) {
jsonList.addWidget(new SelectableWidgetGroup(0, 1 + jsonList.widgets.size() * 11, jsonList.getSize().width, 10).setSelectedTexture(-1, -1).setOnSelected(W -> selected = file).addWidget(new ImageWidget(0, 0, jsonList.getSize().width, 10, new ColorRectTexture(0xff000000))).addWidget(new ImageWidget(0, 0, jsonList.getSize().width, 10, new TextTexture(file.getName().replace(".json", "")).setWidth(jsonList.getSize().width).setType(TextTexture.TextType.ROLL))));
}
}
}
Aggregations