Skip to content

Commit

Permalink
Grid UI in multiblock part switcher (#1032)
Browse files Browse the repository at this point in the history
* feat: use a grid UI in the multiblock part switcher

* chore: version & changelog
  • Loading branch information
mikerooni authored and screret committed Mar 30, 2024
1 parent 7f8ec23 commit fd6911b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Version: 1.1.4.a
### CHANGES:
- ported multi-amp energy hatches not giving overclocks. You now always need 2 energy hatches for an overclock.
- made dynamic data- and resourcepacks appear in the pack list(s)
- Use a grid-based UI for the multiblock part switcher
3 changes: 3 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -3032,6 +3032,9 @@
"gtceu.multiblock.multiple_recipemaps.tooltip": "˙ǝsn oʇ ǝpoɯ ǝuıɥɔɐɯ ɥɔıɥʍ ǝbuɐɥɔ oʇ ɹǝןןoɹʇuoɔ ǝɥʇ ɹǝʌıɹpʍǝɹɔS",
"gtceu.multiblock.multiple_recipemaps_recipes.tooltip": "ɹ§%sǝ§ :sǝpoW ǝuıɥɔɐW",
"gtceu.multiblock.not_enough_energy": "˙ʎbɹǝuǝ ǝɹoɯ spǝǝu ǝuıɥɔɐW :⅁NINᴚⱯM",
"gtceu.multiblock.page_switcher.io.both": "sʇndʇnO + sʇnduI pǝuıqɯoƆϛ§",
"gtceu.multiblock.page_switcher.io.export": "sʇndʇnOㄣ§",
"gtceu.multiblock.page_switcher.io.import": "sʇnduIᄅ§",
"gtceu.multiblock.parallel": "ןǝןןɐɹɐԀ uı sǝdıɔǝᴚ %d oʇ dn buıɯɹoɟɹǝԀ",
"gtceu.multiblock.parallelizable.tooltip": "˙sǝɥɔʇɐH ןoɹʇuoƆ ןǝןןɐɹɐԀ ɥʇıʍ ǝzıןǝןןɐɹɐd uɐƆ",
"gtceu.multiblock.pattern.clear_amount_1": "ɹ§ʇuoɹɟ uı ǝɔɐds ƖxƖxƖ ɹɐǝןɔ ɐ ǝʌɐɥ ʇsnW9§",
Expand Down
3 changes: 3 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3032,6 +3032,9 @@
"gtceu.multiblock.multiple_recipemaps.tooltip": "Screwdriver the controller to change which machine mode to use.",
"gtceu.multiblock.multiple_recipemaps_recipes.tooltip": "Machine Modes: §e%s§r",
"gtceu.multiblock.not_enough_energy": "WARNING: Machine needs more energy.",
"gtceu.multiblock.page_switcher.io.both": "§5Combined Inputs + Outputs",
"gtceu.multiblock.page_switcher.io.export": "§4Outputs",
"gtceu.multiblock.page_switcher.io.import": "§2Inputs",
"gtceu.multiblock.parallel": "Performing up to %d Recipes in Parallel",
"gtceu.multiblock.parallelizable.tooltip": "Can parallelize with Parallel Control Hatches.",
"gtceu.multiblock.pattern.clear_amount_1": "§6Must have a clear 1x1x1 space in front§r",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,12 @@ default List<Component> getTabTooltips() {
default TooltipComponent getTabTooltipComponent() {
return null;
}

@Nullable
default PageGroupingData getPageGroupingData() {
return null;
}

record PageGroupingData(@Nullable String groupKey, int groupPositionWeight) {
}
}
51 changes: 35 additions & 16 deletions src/main/java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.mutable.MutableInt;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -39,22 +43,37 @@ public Widget createMainPage(FancyMachineUIWidget widget) {
scrollableGroup.setYBarStyle(GuiTextures.SLIDER_BACKGROUND_VERTICAL, GuiTextures.BUTTON);
container.addWidget(scrollableGroup);

int currentY = 0;
for (IFancyUIProvider page : pages) {
var pageWidget = new WidgetGroup(0, currentY, 146, 24);

pageWidget.addWidget(new ButtonWidget(0, 0, 146, 24, GuiTextures.BACKGROUND, clickData -> onPageSwitched.accept(page)));
pageWidget.addWidget(new ImageWidget(2, 2, 20, 20, page.getTabIcon()));
pageWidget.addWidget(new ImageWidget(24, 2, 118, 20,
new TextTexture(ChatFormatting.BLACK.toString() + page.getTitle().getString())
.setDropShadow(false)
.setWidth(118)
.setType(TextTexture.TextType.LEFT_ROLL)
));

scrollableGroup.addWidget(pageWidget);
currentY += 28;
}
var groupedPages = pages.stream().collect(Collectors.groupingBy(page ->
Objects.requireNonNullElse(page.getPageGroupingData(), new PageGroupingData(null, -1))
));

final MutableInt currentY = new MutableInt(0);
groupedPages.keySet().stream()
.sorted(Comparator.comparingInt(PageGroupingData::groupPositionWeight))
.forEachOrdered(group -> {
if (group.groupKey() != null) {
scrollableGroup.addWidget(new LabelWidget(0, currentY.getAndAdd(12), group.groupKey()).setDropShadow(false));
}

final var currentPage = new MutableInt(0);
currentY.subtract(30); // To account for adding it back on the first page inside this group

groupedPages.get(group).forEach(page -> {
var index = currentPage.getAndIncrement();
var y = currentY.addAndGet(index % 5 == 0 ? 30 : 0); // Jump to the next row every 5 parts

var pageWidget = new WidgetGroup((index % 5) * 30, y, 25, 25);
pageWidget.addWidget(new ButtonWidget(0, 0, 25, 25, GuiTextures.BACKGROUND, clickData -> onPageSwitched.accept(page)));
pageWidget.addWidget(new ImageWidget(4, 4, 17, 17, page.getTabIcon()));
// For some reason, this doesn't work in any other way:
pageWidget.widgets.get(0).setHoverTooltips(page.getTitle().getString());
scrollableGroup.addWidget(pageWidget);
});

if (!groupedPages.get(group).isEmpty()) {
currentY.add(30);
}
});

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.Getter;
import lombok.Setter;
import net.minecraft.MethodsReturnNonnullByDefault;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

Expand Down Expand Up @@ -47,4 +48,14 @@ public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

@Nullable
@Override
public PageGroupingData getPageGroupingData() {
return switch (this.io) {
case IN -> new PageGroupingData("gtceu.multiblock.page_switcher.io.import", 1);
case OUT -> new PageGroupingData("gtceu.multiblock.page_switcher.io.export", 2);
case BOTH -> new PageGroupingData("gtceu.multiblock.page_switcher.io.both", 3);
case NONE -> null;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public static void init(RegistrateLangProvider provider) {
provider.add("gtceu.io.both", "Both");
provider.add("gtceu.io.none", "None");

provider.add("gtceu.multiblock.page_switcher.io.import", "§2Inputs");
provider.add("gtceu.multiblock.page_switcher.io.export", "§4Outputs");
provider.add("gtceu.multiblock.page_switcher.io.both", "§5Combined Inputs + Outputs");

provider.add("enchantment.disjunction", "Disjunction");
provider.add("gtceu.multiblock.steam_grinder.description", "A Multiblock Macerator at the Steam Age. Requires at least 14 Bronze Casings to form. Cannot use normal Input/Output busses, nor Fluid Hatches other than the Steam Hatch.");
provider.add("gtceu.multiblock.steam.low_steam", "Not enough Steam to run!");
Expand Down

0 comments on commit fd6911b

Please sign in to comment.