use of com.lowdragmc.lowdraglib.gui.texture.TextTexture in project Multiblocked by Low-Drag-MC.
the class ItemsContentWidget method openConfigurator.
@Override
public void openConfigurator(WidgetGroup dialog) {
super.openConfigurator(dialog);
int x = 5;
int y = 25;
dialog.addWidget(new LabelWidget(5, y + 3, "multiblocked.gui.label.amount"));
dialog.addWidget(new TextFieldWidget(125 - 60, y, 60, 15, null, number -> {
content = content.isTag() ? new ItemsIngredient(content.getTag(), Integer.parseInt(number)) : new ItemsIngredient(content.ingredient, Integer.parseInt(number));
onContentUpdate();
}).setNumbersOnly(1, Integer.MAX_VALUE).setCurrentString(content.getAmount() + ""));
TextFieldWidget tag;
WidgetGroup groupOre = new WidgetGroup(x, y + 40, 120, 80);
WidgetGroup groupIngredient = new WidgetGroup(x, y + 20, 120, 80);
DraggableScrollableWidgetGroup container = new DraggableScrollableWidgetGroup(0, 20, 120, 50).setBackground(new ColorRectTexture(0xffaaaaaa));
groupIngredient.addWidget(container);
dialog.addWidget(groupIngredient);
dialog.addWidget(groupOre);
groupOre.addWidget(tag = new TextFieldWidget(30, 3, 90, 15, () -> content.isTag() ? content.getTag() : "", null).setResourceLocationOnly());
IItemHandlerModifiable handler;
PhantomSlotWidget phantomSlotWidget = new PhantomSlotWidget(handler = new ItemStackHandler(1), 0, 0, 1).setClearSlotOnRightClick(false);
groupOre.addWidget(phantomSlotWidget);
phantomSlotWidget.setChangeListener(() -> {
ItemStack newStack = handler.getStackInSlot(0);
if (newStack.isEmpty())
return;
ITagCollection<Item> tags = TagCollectionManager.getInstance().getItems();
Collection<ResourceLocation> ids = tags.getMatchingTags(newStack.getItem());
if (ids.size() > 0) {
String tagString = ids.stream().findAny().get().toString();
content = new ItemsIngredient(tagString, content.getAmount());
tag.setCurrentString(tagString);
phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ": " + ids.stream().map(ResourceLocation::toString).reduce("", (a, b) -> a + "\n" + b));
} else {
content = new ItemsIngredient("", content.getAmount());
tag.setCurrentString("");
handler.setStackInSlot(0, ItemStack.EMPTY);
}
onContentUpdate();
}).setBackgroundTexture(new ColorRectTexture(0xaf444444));
tag.setTextResponder(tagS -> {
content = new ItemsIngredient(tagS, content.getAmount());
ItemStack[] matches = content.ingredient.getItems();
handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ":\n" + content.getTag());
onContentUpdate();
});
tag.setHoverTooltips("multiblocked.gui.trait.item.ore_dic");
dialog.addWidget(new SwitchWidget(x, y + 22, 50, 15, (cd, r) -> {
groupOre.setVisible(r);
content = r ? new ItemsIngredient(tag.getCurrentString(), content.getAmount()) : new ItemsIngredient(content.ingredient, content.getAmount());
groupIngredient.setVisible(!r);
if (r) {
ItemStack[] matches = content.ingredient.getItems();
handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
phantomSlotWidget.setHoverTooltips("oreDict: \n" + content.getTag());
} else {
updateIngredientWidget(container);
}
onContentUpdate();
}).setPressed(content.isTag()).setHoverBorderTexture(1, -1).setBaseTexture(ResourceBorderTexture.BUTTON_COMMON, new TextTexture("tag (N)")).setPressedTexture(ResourceBorderTexture.BUTTON_COMMON, new TextTexture("tag (Y)")).setHoverTooltips("using tag dictionary"));
groupIngredient.setVisible(!content.isTag());
groupOre.setVisible(content.isTag());
if (content.isTag()) {
ItemStack[] matches = content.ingredient.getItems();
handler.setStackInSlot(0, matches.length > 0 ? matches[0] : ItemStack.EMPTY);
phantomSlotWidget.setHoverTooltips(LocalizationUtils.format("multiblocked.gui.trait.item.ore_dict") + ":\n" + content.getTag());
} else {
updateIngredientWidget(container);
}
groupIngredient.addWidget(new LabelWidget(x + 50, 5, "multiblocked.gui.tips.settings"));
groupIngredient.addWidget(new ButtonWidget(100, 0, 20, 20, cd -> {
ItemStack[] stacks = content.ingredient.getItems();
content = new ItemsIngredient(Ingredient.of(ArrayUtils.add(stacks, new ItemStack(Items.IRON_INGOT))), content.getAmount());
updateIngredientWidget(container);
onContentUpdate();
}).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/add.png")).setHoverBorderTexture(1, -1).setHoverTooltips("multiblocked.gui.trait.item.add"));
}
use of com.lowdragmc.lowdraglib.gui.texture.TextTexture in project Multiblocked by Low-Drag-MC.
the class MBDIModelRenderer method createConfigurator.
@Override
public Supplier<IMultiblockedRenderer> createConfigurator(WidgetGroup parent, DraggableScrollableWidgetGroup group, IMultiblockedRenderer current) {
TextFieldWidget tfw = new TextFieldWidget(1, 1, 150, 20, null, null);
group.addWidget(tfw);
File path = new File(Multiblocked.location, "assets/multiblocked/models");
group.addWidget(new ButtonWidget(155, 1, 20, 20, cd -> DialogWidget.showFileDialog(parent, "select a java model", path, true, DialogWidget.suffixFilter(".json"), r -> {
if (r != null && r.isFile()) {
tfw.setCurrentString("multiblocked:" + r.getPath().replace(path.getPath(), "").substring(1).replace(".json", "").replace('\\', '/'));
}
})).setButtonTexture(new ResourceTexture("multiblocked:textures/gui/darkened_slot.png"), new TextTexture("F", -1)).setHoverTooltips("multiblocked.gui.tips.file_selector"));
if (current instanceof IModelRenderer && ((IModelRenderer) current).modelLocation != null) {
tfw.setCurrentString(((IModelRenderer) current).modelLocation.toString());
}
return () -> {
if (tfw.getCurrentString().isEmpty()) {
return null;
} else {
return new MBDIModelRenderer(new ResourceLocation(tfw.getCurrentString()));
}
};
}
use of com.lowdragmc.lowdraglib.gui.texture.TextTexture in project Multiblocked by Low-Drag-MC.
the class ControllerBuilderWidget method updateScene.
@OnlyIn(Dist.CLIENT)
private void updateScene(JsonBlockPattern jsonPattern) {
if (thread != null) {
thread.interrupt();
thread = null;
}
TrackedDummyWorld world = new TrackedDummyWorld();
sceneWidget.createScene(world);
ImageWidget imageWidget;
sceneWidget.addWidget(imageWidget = new ImageWidget(0, 0, sceneWidget.getSize().width, sceneWidget.getSize().height));
imageWidget.setVisible(jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length() > 1000);
thread = new Thread(() -> {
int[] centerOffset = jsonPattern.getCenterOffset();
String[][] pattern = jsonPattern.pattern;
Set<BlockPos> posSet = new HashSet<>();
int offset = Math.max(pattern.length, Math.max(pattern[0].length, pattern[0][0].length()));
int sum = jsonPattern.pattern.length * jsonPattern.pattern[0].length * jsonPattern.pattern[0][0].length();
AtomicDouble progress = new AtomicDouble(0);
imageWidget.setImage(new TextTexture("multiblocked.gui.tips.building_scene").setSupplier(() -> I18n.get("multiblocked.gui.tips.building_scene") + String.format(" %.1f", progress.get()) + "%%").setWidth(sceneWidget.getSize().width));
int count = 0;
for (int i = 0; i < pattern.length; i++) {
for (int j = 0; j < pattern[0].length; j++) {
for (int k = 0; k < pattern[0][0].length(); k++) {
if (Thread.interrupted()) {
sceneWidget.waitToRemoved(imageWidget);
return;
}
count++;
progress.set(count * 100.0 / sum);
char symbol = pattern[i][j].charAt(k);
BlockPos pos = jsonPattern.getActualPosOffset(k - centerOffset[2], j - centerOffset[1], i - centerOffset[0], Direction.NORTH).offset(offset, offset, offset);
if (jsonPattern.symbolMap.containsKey(symbol)) {
List<BlockInfo> candidates = new ArrayList<>();
for (String s : jsonPattern.symbolMap.get(symbol)) {
SimplePredicate predicate = jsonPattern.predicates.get(s);
if (predicate instanceof PredicateComponent && ((PredicateComponent) predicate).definition != null) {
world.addBlock(pos, BlockInfo.fromBlock(MbdComponents.DummyComponentBlock));
DummyComponentTileEntity tileEntity = (DummyComponentTileEntity) world.getBlockEntity(pos);
assert tileEntity != null;
tileEntity.setDefinition(((PredicateComponent) predicate).definition);
tileEntity.isFormed = false;
tileEntity.setLevelAndPosition(world, pos);
posSet.add(pos);
break;
} else if (predicate != null && predicate.candidates != null) {
candidates.addAll(Arrays.asList(predicate.candidates.get()));
}
}
if (candidates.size() > 0) {
world.addBlock(pos, candidates.get(0));
posSet.add(pos);
}
}
}
}
}
Minecraft.getInstance().execute(() -> {
sceneWidget.setRenderedCore(posSet, null);
sceneWidget.waitToRemoved(imageWidget);
});
thread = null;
});
thread.start();
}
use of com.lowdragmc.lowdraglib.gui.texture.TextTexture 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.texture.TextTexture 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))));
}
}
}
Aggregations