Skip to content

Commit a3a3171

Browse files
authored
Add Progress Bars that direct Players to JEI Page (#203)
* Create RecipeProgressWidget * Give steam machines clickable progress bars * Add a check on the existence of RecipeMapCategory * Simplify said check * Why did I change that?????
1 parent 2727068 commit a3a3171

File tree

10 files changed

+76
-8
lines changed

10 files changed

+76
-8
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package gregtech.api.gui.widgets;
2+
3+
import gregtech.api.GTValues;
4+
import gregtech.api.gui.resources.TextureArea;
5+
import gregtech.api.recipes.RecipeMap;
6+
import gregtech.integration.jei.GTJeiPlugin;
7+
import gregtech.integration.jei.recipe.RecipeMapCategory;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraftforge.fml.client.config.GuiUtils;
10+
11+
import java.util.Collections;
12+
import java.util.function.DoubleSupplier;
13+
14+
public class RecipeProgressWidget extends ProgressWidget {
15+
private final RecipeMap<?> recipeMap;
16+
private final static int HOVER_TEXT_WIDTH = 200;
17+
18+
public RecipeProgressWidget(DoubleSupplier progressSupplier, int x, int y, int width, int height, RecipeMap<?> recipeMap) {
19+
super(progressSupplier, x, y, width, height);
20+
this.recipeMap = recipeMap;
21+
}
22+
23+
public RecipeProgressWidget(DoubleSupplier progressSupplier, int x, int y, int width, int height, TextureArea fullImage, MoveType moveType, RecipeMap<?> recipeMap) {
24+
super(progressSupplier, x, y, width, height, fullImage, moveType);
25+
this.recipeMap = recipeMap;
26+
}
27+
28+
@Override
29+
public boolean mouseClicked(int mouseX, int mouseY, int button) {
30+
if (!GTValues.isModLoaded(GTValues.MODID_JEI))
31+
return false;
32+
if (isMouseOverElement(mouseX, mouseY) && RecipeMapCategory.getCategoryMap().containsKey(recipeMap)) {
33+
// Since categories were even registered at all, we know JEI is active.
34+
GTJeiPlugin.jeiRuntime.getRecipesGui().showCategories(Collections.singletonList(RecipeMapCategory.getCategoryMap().get(recipeMap).getUid()));
35+
return true;
36+
}
37+
return false;
38+
}
39+
40+
41+
@Override
42+
public void drawInForeground(int mouseX, int mouseY) {
43+
super.drawInForeground(mouseX, mouseY);
44+
if (isMouseOverElement(mouseX, mouseY) && GTValues.isModLoaded(GTValues.MODID_JEI)) {
45+
Minecraft mc = Minecraft.getMinecraft();
46+
GuiUtils.drawHoveringText(Collections.singletonList("Show Recipes"), mouseX, mouseY,
47+
sizes.getScreenWidth(),
48+
sizes.getScreenHeight(), HOVER_TEXT_WIDTH, mc.fontRenderer);
49+
}
50+
}
51+
52+
}

src/main/java/gregtech/api/recipes/RecipeMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import gregtech.api.gui.resources.TextureArea;
1616
import gregtech.api.gui.widgets.ProgressWidget;
1717
import gregtech.api.gui.widgets.ProgressWidget.MoveType;
18+
import gregtech.api.gui.widgets.RecipeProgressWidget;
1819
import gregtech.api.gui.widgets.SlotWidget;
1920
import gregtech.api.gui.widgets.TankWidget;
2021
import gregtech.api.recipes.builders.IntCircuitRecipeBuilder;
@@ -367,7 +368,7 @@ private double jeiProgressBar() {
367368
//this DOES NOT include machine control widgets or binds player inventory
368369
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids, int yOffset) {
369370
ModularUI.Builder builder = ModularUI.defaultBuilder(yOffset);
370-
builder.widget(new ProgressWidget(progressSupplier, 78, 23 + yOffset, 20, 20, progressBarTexture, moveType));
371+
builder.widget(new RecipeProgressWidget(progressSupplier, 78, 23 + yOffset, 20, 20, progressBarTexture, moveType, this));
371372
addInventorySlotGroup(builder, importItems, importFluids, false, yOffset);
372373
addInventorySlotGroup(builder, exportItems, exportFluids, true, yOffset);
373374
if (this.specialTexture != null && this.specialTexturePosition != null)

src/main/java/gregtech/common/metatileentities/steam/SteamAlloySmelter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gregtech.api.gui.resources.TextureArea;
66
import gregtech.api.gui.widgets.ProgressWidget;
77
import gregtech.api.gui.widgets.ProgressWidget.MoveType;
8+
import gregtech.api.gui.widgets.RecipeProgressWidget;
89
import gregtech.api.gui.widgets.SlotWidget;
910
import gregtech.api.metatileentity.MetaTileEntity;
1011
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -49,7 +50,7 @@ public ModularUI createUI(EntityPlayer player) {
4950
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, slotBackground))
5051
.widget(new SlotWidget(this.importItems, 1, 35, 25)
5152
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, slotBackground))
52-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 26, 20, 16)
53+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 26, 20, 16, workableHandler.recipeMap)
5354
.setProgressBar(getFullGuiTexture("progress_bar_%s_furnace"),
5455
getFullGuiTexture("progress_bar_%s_furnace_filled"),
5556
MoveType.HORIZONTAL))

src/main/java/gregtech/common/metatileentities/steam/SteamCompressor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.gui.ModularUI;
55
import gregtech.api.gui.widgets.ProgressWidget;
66
import gregtech.api.gui.widgets.ProgressWidget.MoveType;
7+
import gregtech.api.gui.widgets.RecipeProgressWidget;
78
import gregtech.api.gui.widgets.SlotWidget;
89
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -40,7 +41,7 @@ public ModularUI createUI(EntityPlayer player) {
4041
return createUITemplate(player)
4142
.widget(new SlotWidget(this.importItems, 0, 53, 25)
4243
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("slot_%s_compressor_background")))
43-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 78, 25, 20, 18)
44+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 78, 25, 20, 18, workableHandler.recipeMap)
4445
.setProgressBar(getFullGuiTexture("progress_bar_%s_compressor"),
4546
getFullGuiTexture("progress_bar_%s_compressor_filled"),
4647
MoveType.HORIZONTAL))

src/main/java/gregtech/common/metatileentities/steam/SteamExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gregtech.api.capability.impl.NotifiableItemStackHandler;
44
import gregtech.api.gui.ModularUI;
55
import gregtech.api.gui.widgets.ProgressWidget;
6+
import gregtech.api.gui.widgets.RecipeProgressWidget;
67
import gregtech.api.gui.widgets.SlotWidget;
78
import gregtech.api.metatileentity.MetaTileEntity;
89
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -39,7 +40,7 @@ public ModularUI createUI(EntityPlayer player) {
3940
return createUITemplate(player)
4041
.widget(new SlotWidget(this.importItems, 0, 53, 25)
4142
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("slot_%s_extractor_background")))
42-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 25, 20, 18)
43+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 25, 20, 18, workableHandler.recipeMap)
4344
.setProgressBar(getFullGuiTexture("progress_bar_%s_extractor"),
4445
getFullGuiTexture("progress_bar_%s_extractor_filled"),
4546
ProgressWidget.MoveType.HORIZONTAL))

src/main/java/gregtech/common/metatileentities/steam/SteamFurnace.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.gui.ModularUI;
55
import gregtech.api.gui.widgets.ProgressWidget;
66
import gregtech.api.gui.widgets.ProgressWidget.MoveType;
7+
import gregtech.api.gui.widgets.RecipeProgressWidget;
78
import gregtech.api.gui.widgets.SlotWidget;
89
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -45,7 +46,7 @@ public ModularUI createUI(EntityPlayer player) {
4546
return createUITemplate(player)
4647
.widget(new SlotWidget(this.importItems, 0, 53, 25)
4748
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("slot_%s_furnace_background")))
48-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 26, 20, 16)
49+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 26, 20, 16, workableHandler.recipeMap)
4950
.setProgressBar(getFullGuiTexture("progress_bar_%s_furnace"),
5051
getFullGuiTexture("progress_bar_%s_furnace_filled"),
5152
MoveType.HORIZONTAL))

src/main/java/gregtech/common/metatileentities/steam/SteamHammer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.gui.ModularUI;
55
import gregtech.api.gui.widgets.ImageWidget;
66
import gregtech.api.gui.widgets.ProgressWidget;
7+
import gregtech.api.gui.widgets.RecipeProgressWidget;
78
import gregtech.api.gui.widgets.SlotWidget;
89
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -40,7 +41,7 @@ public ModularUI createUI(EntityPlayer player) {
4041
return createUITemplate(player)
4142
.widget(new SlotWidget(this.importItems, 0, 53, 25)
4243
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("slot_%s_hammer_background")))
43-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 25, 20, 18)
44+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 25, 20, 18, workableHandler.recipeMap)
4445
.setProgressBar(getFullGuiTexture("progress_bar_%s_hammer"),
4546
getFullGuiTexture("progress_bar_%s_hammer_filled"),
4647
ProgressWidget.MoveType.VERTICAL))

src/main/java/gregtech/common/metatileentities/steam/SteamMacerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.capability.impl.RecipeLogicSteam;
55
import gregtech.api.gui.ModularUI;
66
import gregtech.api.gui.widgets.ProgressWidget;
7+
import gregtech.api.gui.widgets.RecipeProgressWidget;
78
import gregtech.api.gui.widgets.SlotWidget;
89
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -42,7 +43,7 @@ public ModularUI createUI(EntityPlayer player) {
4243
return createUITemplate(player)
4344
.widget(new SlotWidget(this.importItems, 0, 53, 25)
4445
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("slot_%s_macerator_background")))
45-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 26, 21, 18)
46+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 26, 21, 18, workableHandler.recipeMap)
4647
.setProgressBar(getFullGuiTexture("progress_bar_%s_macerator"),
4748
getFullGuiTexture("progress_bar_%s_macerator_filled"),
4849
ProgressWidget.MoveType.HORIZONTAL))

src/main/java/gregtech/common/metatileentities/steam/SteamRockBreaker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gregtech.api.capability.impl.RecipeLogicSteam;
55
import gregtech.api.gui.ModularUI;
66
import gregtech.api.gui.widgets.ProgressWidget;
7+
import gregtech.api.gui.widgets.RecipeProgressWidget;
78
import gregtech.api.gui.widgets.SlotWidget;
89
import gregtech.api.metatileentity.MetaTileEntity;
910
import gregtech.api.metatileentity.MetaTileEntityHolder;
@@ -59,7 +60,7 @@ public ModularUI createUI(EntityPlayer player) {
5960
return createUITemplate(player)
6061
.widget(new SlotWidget(this.importItems, 0, 53, 34)
6162
.setBackgroundTexture(BRONZE_SLOT_BACKGROUND_TEXTURE, getFullGuiTexture("overlay_%s_dust")))
62-
.widget(new ProgressWidget(workableHandler::getProgressPercent, 79, 35, 21, 18)
63+
.widget(new RecipeProgressWidget(workableHandler::getProgressPercent, 79, 35, 21, 18, workableHandler.recipeMap)
6364
.setProgressBar(getFullGuiTexture("progress_bar_%s_macerator"),
6465
getFullGuiTexture("progress_bar_%s_macerator_filled"),
6566
ProgressWidget.MoveType.HORIZONTAL))

src/main/java/gregtech/integration/jei/recipe/RecipeMapCategory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.minecraftforge.items.SlotItemHandler;
3131

3232
import javax.annotation.Nonnull;
33+
import java.util.HashMap;
3334
import java.util.List;
3435

3536
public class RecipeMapCategory implements IRecipeCategory<GTRecipeWrapper> {
@@ -41,6 +42,8 @@ public class RecipeMapCategory implements IRecipeCategory<GTRecipeWrapper> {
4142
private final IDrawable backgroundDrawable;
4243

4344
private final int FONT_HEIGHT = 9;
45+
private static final HashMap<RecipeMap<?>, RecipeMapCategory> categoryMap = new HashMap<>();
46+
private double timer = 0;
4447

4548
public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
4649
this.recipeMap = recipeMap;
@@ -60,6 +63,7 @@ public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
6063
).build(new BlankUIHolder(), Minecraft.getMinecraft().player);
6164
this.modularUI.initWidgets();
6265
this.backgroundDrawable = guiHelper.createBlankDrawable(modularUI.getWidth(), modularUI.getHeight() * 2 / 3);
66+
categoryMap.put(recipeMap, this);
6367
}
6468

6569
@Override
@@ -171,4 +175,8 @@ public void drawExtras(@Nonnull Minecraft minecraft) {
171175
widget.drawInForeground(0, 0);
172176
}
173177
}
178+
179+
public static HashMap<RecipeMap<?>, RecipeMapCategory> getCategoryMap() {
180+
return categoryMap;
181+
}
174182
}

0 commit comments

Comments
 (0)