aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/recipe/BasicUIProperties.java
diff options
context:
space:
mode:
authormiozune <miozune@gmail.com>2023-12-04 05:34:27 +0900
committerGitHub <noreply@github.com>2023-12-03 21:34:27 +0100
commitf74c7cc297d1d19d38a19683cd277ad9ce605d3a (patch)
treeb2a5d66ec5a959099240fb1db239ffc0f9531839 /src/main/java/gregtech/api/recipe/BasicUIProperties.java
parentb08cde7de4ec93cba05fb070991ad1dffb800ce1 (diff)
downloadGT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.gz
GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.tar.bz2
GT5-Unofficial-f74c7cc297d1d19d38a19683cd277ad9ce605d3a.zip
Refactor RecipeMap (#2345)
* Remove deprecated and unused things * Move recipemap subclasses * Move GT_Recipe_Map to outside and rename to RecipeMap * Move recipemap instances to separated class & remove prepending s * Remove useless GT_Recipe constructors * Always use ModularUI * Rename IGT_RecipeMap -> IRecipeMap * Add RecipeMapBuilder * Remove more deprecated and unused things * Fix RecipeMap type parameters * Use multimap for recipe index * Fix bending recipe error in dev env * Remove mUniqueIdentifier * Update AE2FC * Less edgy texture for NEI recipe background * Add replicator fluid output slot for NEI and machine GUI * Fix fluid fuels not having fuel value in large boilers * Remove GT_RectHandler and NEI_TransferRectHost * Remove RecipeMapHandler * Move NEI energy description from RecipeMapFrontend to Power * Refactor the way to filter fusion recipes * Check restriction for some properties * Remove showVoltageAmperage * Make Power accept GT_Recipe * Fix NPE * Move NEI duration description to Power from Frontend * Directly implement IRecipeProcessingAwareHatch for GT_MetaTileEntity_Hatch_InputBus_ME * Make Power integrated with GT_OverclockCalculator * Rename Power -> OverclockDescriber * Don't modify recipe find logic until postload finishes * Reformat reserved MTE ids * Fix check for too few inputs on recipe addition * Move replicator logic to backend * Stop un-hiding assline recipes * Allow setting custom recipe comparator & implement for fusion * Update AE2FC * Rename getRecipeList and getRecipes -> getRecipeMap * Automatically register recipe catalysts * Cleanup the way to detect recipe collision * Make use of BasicUIProperties for basic machines * Make use of BasicUIProperties for UIHelper * Rename specialHandler -> recipeTransformer * Add way to automatically register handler info * Add recipe category * Add some APIs for addons * Rename blastRecipes -> blastFurnaceRecipes * Remove GT_MetaTileEntity_BasicMachine_GT_Recipe#mSharedTank and #mRequiresFluidForFiltering * Don't require setting duration and EU/t for fuel recipes * Don't require setting EU/t for primitive blast furnace recipes * Revert change to addMultiblockChemicalRecipe * Fix large boiler general desc recipe not being added * Hide duration and EU/t from large boiler * Cleanup recipe stacktrace draw * Extend metadata usage of recipe builder to recipe itself * Implement metadata handling & NEI comparator for PCB factory * Some rename around NEIRecipeInfo * Some toString implementations * Add more APIs for addons & some rename * Infer handler icon from recipe catalyst if one is not set * Also shrink recipe title when OC is not used * Remove rare earth centrifuge recipe * Use metadata for replicator backend * Adjust geothermal generator output slot * Allow having multiple transferrects * Store recipemap reference in backend * Rename vacuumRecipes -> vacuumFreezerRecipes * Add config to tweak visibility of recipe categories * Remove mHideRecyclingRecipes in favor of recipe category config * Fix typo fluidSolidfierRecipes -> fluidSolidifierRecipes * Refactor findRecipe and ProcessingLogic to use Stream * Fix BBF handler icon & remove bronze blast furnace * Add fluent API for findRecipe * Add way to stop adding progressbar * Change arg order for special texture * Avoid overwriting interesting failure with NO_RECIPE * Some changes for FuelBackend * Set space project icon * Remove localization from TT * Remove CNC recipe adder * Move recipe extractor from AE2FC * Minor internal change for ProcessingLogic#applyRecipe * More javadoc on #getAvailableRecipeMaps * Better implementation of #ofSupplier * Move replicator exponent config to GT_Proxy * Remove RC & IC2 macerator handling * Rename StreamUtil -> GT_StreamUtil * Refactor code around RecipeMetadataStorage * Revise #compileRecipe javadoc * Switch extreme diesel recipe loader to downstream recipe map * Optimize #reMap * Rename reload -> reloadNEICache * Minor tweak for drawEnergyInfo * a bit more doc * Adjust recipe catalysts * Add toString implementation for GT_Fluid for debug * Minor revision for OilCrackerBackend * Index replicator recipes by material --------- Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech/api/recipe/BasicUIProperties.java')
-rw-r--r--src/main/java/gregtech/api/recipe/BasicUIProperties.java251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/recipe/BasicUIProperties.java b/src/main/java/gregtech/api/recipe/BasicUIProperties.java
new file mode 100644
index 0000000000..fde86785b2
--- /dev/null
+++ b/src/main/java/gregtech/api/recipe/BasicUIProperties.java
@@ -0,0 +1,251 @@
+package gregtech.api.recipe;
+
+import java.awt.Rectangle;
+import java.util.List;
+import java.util.function.IntFunction;
+import java.util.function.Supplier;
+
+import javax.annotation.Nullable;
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture;
+import com.gtnewhorizons.modularui.api.drawable.IDrawable;
+import com.gtnewhorizons.modularui.api.math.Pos2d;
+import com.gtnewhorizons.modularui.api.math.Size;
+import com.gtnewhorizons.modularui.common.widget.ProgressBar;
+
+import gregtech.api.gui.modularui.FallbackableSteamTexture;
+import gregtech.api.gui.modularui.SteamTexture;
+import gregtech.api.util.FieldsAreNonnullByDefault;
+import gregtech.api.util.MethodsReturnNonnullByDefault;
+
+/**
+ * Data object to store properties, used to draw both basic machine GUI and NEI recipe GUI, mainly GUI widgets.
+ * Not all the info used to draw NEI are listed here, see also {@link NEIRecipeProperties}.
+ * <p>
+ * Use {@link #builder()} for creation.
+ */
+@ParametersAreNonnullByDefault
+@MethodsReturnNonnullByDefault
+@FieldsAreNonnullByDefault
+public final class BasicUIProperties {
+
+ /**
+ * Starts constructing BasicUIProperties.
+ */
+ public static BasicUIPropertiesBuilder builder() {
+ return new BasicUIPropertiesBuilder();
+ }
+
+ /**
+ * Creates new builder from this instance.
+ */
+ public BasicUIPropertiesBuilder toBuilder() {
+ return new BasicUIPropertiesBuilder().maxItemInputs(maxItemInputs)
+ .maxItemOutputs(maxItemOutputs)
+ .maxFluidInputs(maxFluidInputs)
+ .maxFluidOutputs(maxFluidOutputs)
+ .slotOverlays(slotOverlays)
+ .slotOverlaysSteam(slotOverlaysSteam)
+ .progressBarTexture(progressBarTexture)
+ .progressBarTextureSteam(progressBarTextureSteam)
+ .progressBarDirection(progressBarDirection)
+ .progressBarSize(progressBarSize)
+ .progressBarPos(progressBarPos)
+ .useProgressBar(useProgressBar)
+ .useSpecialSlot(useSpecialSlot)
+ .neiTransferRect(neiTransferRect)
+ .neiTransferRectId(neiTransferRectId)
+ .specialTextures(specialTextures)
+ .specialTexturesSteam(specialTexturesSteam)
+ .logo(logo)
+ .logoSize(logoSize)
+ .logoPos(logoPos)
+ .itemInputPositionsGetter(itemInputPositionsGetter)
+ .itemOutputPositionsGetter(itemOutputPositionsGetter)
+ .specialItemPositionGetter(specialItemPositionGetter)
+ .fluidInputPositionsGetter(fluidInputPositionsGetter)
+ .fluidOutputPositionsGetter(fluidOutputPositionsGetter)
+ .amperage(amperage);
+ }
+
+ /**
+ * How many item inputs does this recipemap usually has at most.
+ * It does not actually restrict number of items used in the recipe.
+ */
+ public final int maxItemInputs;
+ /**
+ * How many item outputs does this recipemap usually has at most.
+ * It does not actually restrict number of items used in the recipe.
+ */
+ public final int maxItemOutputs;
+ /**
+ * How many fluid inputs does this recipemap usually has at most.
+ * It does not actually restrict number of items used in the recipe.
+ */
+ public final int maxFluidInputs;
+ /**
+ * How many fluid outputs does this recipemap usually has at most.
+ * It does not actually restrict number of items used in the recipe.
+ */
+ public final int maxFluidOutputs;
+
+ private final SlotOverlayGetter<IDrawable> slotOverlays;
+ private final SlotOverlayGetter<SteamTexture> slotOverlaysSteam;
+
+ /**
+ * Progressbar used for BasicMachine GUI and NEI.
+ */
+ @Nullable
+ public final FallbackableUITexture progressBarTexture;
+ /**
+ * Progressbar used for steam machine GUI.
+ */
+ @Nullable
+ public final FallbackableSteamTexture progressBarTextureSteam;
+ /**
+ * Direction of progressbar animation.
+ */
+ public final ProgressBar.Direction progressBarDirection;
+ /**
+ * Size of the progressbar. (20, 36) by default.
+ */
+ public final Size progressBarSize;
+ /**
+ * Position of the progressbar. (78, 24) by default.
+ */
+ public final Pos2d progressBarPos;
+ /**
+ * Image size in the direction of progressbar. Used for non-smooth rendering.
+ */
+ public final int progressBarImageSize;
+
+ /**
+ * If progressbar should be added.
+ */
+ public final boolean useProgressBar;
+
+ /**
+ * If special slot has its usage for this GUI.
+ */
+ public final boolean useSpecialSlot;
+
+ /**
+ * GUI area where clicking shows up all the recipes available.
+ */
+ public final List<Rectangle> neiTransferRect;
+ /**
+ * ID used to open NEI recipe GUI when progressbar is clicked.
+ */
+ @Nullable
+ public final String neiTransferRectId;
+
+ /**
+ * Additional textures shown on GUI.
+ */
+ public final List<Pair<IDrawable, Pair<Size, Pos2d>>> specialTextures;
+ /**
+ * Additional textures shown on steam machine GUI.
+ */
+ public final List<Pair<SteamTexture, Pair<Size, Pos2d>>> specialTexturesSteam;
+
+ /**
+ * Logo shown on GUI. GregTech logo by default.
+ */
+ public final IDrawable logo;
+ /**
+ * Size of logo. (17, 17) by default.
+ */
+ public final Size logoSize;
+ /**
+ * Position of logo. (152, 63) by default.
+ */
+ public final Pos2d logoPos;
+
+ public final IntFunction<List<Pos2d>> itemInputPositionsGetter;
+ public final IntFunction<List<Pos2d>> itemOutputPositionsGetter;
+ public final Supplier<Pos2d> specialItemPositionGetter;
+ public final IntFunction<List<Pos2d>> fluidInputPositionsGetter;
+ public final IntFunction<List<Pos2d>> fluidOutputPositionsGetter;
+
+ /**
+ * Amperage for the recipemap. Even though this is placed at frontend because backend logic doesn't need it,
+ * some machine logic also use this variable.
+ */
+ public final int amperage;
+
+ BasicUIProperties(int maxItemInputs, int maxItemOutputs, int maxFluidInputs, int maxFluidOutputs,
+ SlotOverlayGetter<IDrawable> slotOverlays, SlotOverlayGetter<SteamTexture> slotOverlaysSteam,
+ @Nullable FallbackableUITexture progressBarTexture, @Nullable FallbackableSteamTexture progressBarTextureSteam,
+ ProgressBar.Direction progressBarDirection, Size progressBarSize, Pos2d progressBarPos, boolean useProgressBar,
+ boolean useSpecialSlot, List<Rectangle> neiTransferRect, @Nullable String neiTransferRectId,
+ List<Pair<IDrawable, Pair<Size, Pos2d>>> specialTextures,
+ List<Pair<SteamTexture, Pair<Size, Pos2d>>> specialTexturesSteam, IDrawable logo, Size logoSize, Pos2d logoPos,
+ IntFunction<List<Pos2d>> itemInputPositionsGetter, IntFunction<List<Pos2d>> itemOutputPositionsGetter,
+ Supplier<Pos2d> specialItemPositionGetter, IntFunction<List<Pos2d>> fluidInputPositionsGetter,
+ IntFunction<List<Pos2d>> fluidOutputPositionsGetter, int amperage) {
+ if (maxItemInputs < 0 || maxItemOutputs < 0 || maxFluidInputs < 0 || maxFluidOutputs < 0) {
+ throw new IllegalArgumentException(
+ "maxItemInputs, maxItemOutputs, maxFluidInputs and maxFluidOutputs cannot be negative");
+ }
+ if (amperage < 1) {
+ throw new IllegalArgumentException("Amperage cannot be lower than 1");
+ }
+ this.maxItemInputs = maxItemInputs;
+ this.maxItemOutputs = maxItemOutputs;
+ this.maxFluidInputs = maxFluidInputs;
+ this.maxFluidOutputs = maxFluidOutputs;
+ this.slotOverlays = slotOverlays;
+ this.slotOverlaysSteam = slotOverlaysSteam;
+ this.progressBarTexture = progressBarTexture;
+ this.progressBarTextureSteam = progressBarTextureSteam;
+ this.progressBarDirection = progressBarDirection;
+ this.progressBarSize = progressBarSize;
+ this.progressBarPos = progressBarPos;
+ this.useProgressBar = useProgressBar;
+ this.useSpecialSlot = useSpecialSlot;
+ this.neiTransferRect = neiTransferRect;
+ this.neiTransferRectId = neiTransferRectId;
+ this.specialTextures = specialTextures;
+ this.specialTexturesSteam = specialTexturesSteam;
+ this.logo = logo;
+ this.logoSize = logoSize;
+ this.logoPos = logoPos;
+ this.itemInputPositionsGetter = itemInputPositionsGetter;
+ this.itemOutputPositionsGetter = itemOutputPositionsGetter;
+ this.specialItemPositionGetter = specialItemPositionGetter;
+ this.fluidInputPositionsGetter = fluidInputPositionsGetter;
+ this.fluidOutputPositionsGetter = fluidOutputPositionsGetter;
+ this.amperage = amperage;
+
+ this.progressBarImageSize = switch (progressBarDirection) {
+ case UP, DOWN -> progressBarSize.height;
+ case CIRCULAR_CW -> Math.max(progressBarSize.width, progressBarSize.height);
+ default -> progressBarSize.width;
+ };
+ }
+
+ /**
+ * Retrieves overlay for slot, with given matching conditions.
+ */
+ @Nullable
+ public IDrawable getOverlayForSlot(int index, boolean isFluid, boolean isOutput, boolean isSpecial) {
+ return slotOverlays.apply(index, isFluid, isOutput, isSpecial);
+ }
+
+ /**
+ * Retrieves overlay for slot of steam machines, with given matching conditions.
+ */
+ @Nullable
+ public SteamTexture getOverlayForSlotSteam(int index, boolean isFluid, boolean isOutput, boolean isSpecial) {
+ return slotOverlaysSteam.apply(index, isFluid, isOutput, isSpecial);
+ }
+
+ public interface SlotOverlayGetter<T> {
+
+ @Nullable
+ T apply(int index, boolean isFluid, boolean isOutput, boolean isSpecial);
+ }
+}