Skip to content

Commit

Permalink
Feature: Sacks page in pv (NotEnoughUpdates#891)
Browse files Browse the repository at this point in the history
* sacks in pv

* fix formatting

* a bit more formatting

* change location to make more sense

* suggested changes

* change colour

* add coloured tooltips

* remove some more magic numbers
  • Loading branch information
CalMWolfs authored Nov 4, 2023
1 parent df476f6 commit f197b51
Show file tree
Hide file tree
Showing 12 changed files with 586 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static int cleanAndParseInt(String str) {
return Integer.parseInt(str);
}

public static String shortNumberFormat(int n) {
return shortNumberFormat(n, 0);
}

public static String shortNumberFormat(double n) {
return shortNumberFormat(n, 0);
}
Expand Down Expand Up @@ -74,7 +78,9 @@ public static String shortNumberFormat(double n, int iteration) {

double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) % 10 == 0;
return d < 1000 ? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + sizeSuffix[iteration] : shortNumberFormat(d, iteration + 1);
return d < 1000
? (isRound || d > 9.99 ? (int) d * 10 / 10 : d + "") + "" + sizeSuffix[iteration]
: shortNumberFormat(d, iteration + 1);
}

public static String removeLastWord(String string, String splitString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class BasicPage extends GuiProfileViewerPage {
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODdkODg1YjMyYjBkZDJkNmI3ZjFiNTgyYTM0MTg2ZjhhNTM3M2M0NjU4OWEyNzM0MjMxMzJiNDQ4YjgwMzQ2MiJ9fX0="
);

private static final LinkedHashMap<String, ItemStack> dungeonsModeIcons = new LinkedHashMap<String, ItemStack>() {
private static final LinkedHashMap<String, ItemStack> pageModeIcon = new LinkedHashMap<String, ItemStack>() {
{
put(
"first_page",
Expand Down Expand Up @@ -1001,7 +1001,7 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
int guiLeft = GuiProfileViewer.getGuiLeft();
int guiTop = GuiProfileViewer.getGuiTop();

int i = onSlotToChangePage(mouseX, mouseY, guiLeft, guiTop);
int i = ProfileViewerUtils.onSlotToChangePage(mouseX, mouseY, guiLeft, guiTop);
switch (i) {
case 1:
onSecondPage = false;
Expand All @@ -1017,32 +1017,21 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
return false;
}

public int onSlotToChangePage(int mouseX, int mouseY, int guiLeft, int guiTop) {
if (mouseX >= guiLeft - 29 && mouseX <= guiLeft) {
if (mouseY >= guiTop && mouseY <= guiTop + 28) {
return 1;
} else if (mouseY + 28 >= guiTop && mouseY <= guiTop + 28 * 2) {
return 2;
}
}
return 0;
}

public void drawSideButtons() {
GlStateManager.enableDepth();
GlStateManager.translate(0, 0, 5);
if (onSecondPage) {
Utils.drawPvSideButton(1, dungeonsModeIcons.get("second_page"), true, guiProfileViewer);
Utils.drawPvSideButton(1, pageModeIcon.get("second_page"), true, guiProfileViewer);
} else {
Utils.drawPvSideButton(0, dungeonsModeIcons.get("first_page"), true, guiProfileViewer);
Utils.drawPvSideButton(0, pageModeIcon.get("first_page"), true, guiProfileViewer);
}
GlStateManager.translate(0, 0, -3);

GlStateManager.translate(0, 0, -2);
if (!onSecondPage) {
Utils.drawPvSideButton(1, dungeonsModeIcons.get("second_page"), false, guiProfileViewer);
Utils.drawPvSideButton(1, pageModeIcon.get("second_page"), false, guiProfileViewer);
} else {
Utils.drawPvSideButton(0, dungeonsModeIcons.get("first_page"), false, guiProfileViewer);
Utils.drawPvSideButton(0, pageModeIcon.get("first_page"), false, guiProfileViewer);
}
GlStateManager.disableDepth();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
* Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
Expand Down Expand Up @@ -76,6 +76,7 @@ public class CollectionsPage extends GuiProfileViewerPage {
private int page = 0;
private int maxPage = 0;


public CollectionsPage(GuiProfileViewer instance) {
super(instance);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
* Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
Expand Down Expand Up @@ -74,7 +74,7 @@ public class DungeonPage extends GuiProfileViewerPage {
"fa06cb0c471c1c9bc169af270cd466ea701946776056e472ecdaeb49f0f4a4dc",
"a435164c05cea299a3f016bbbed05706ebb720dac912ce4351c2296626aecd9a",
};
private static final LinkedHashMap<String, ItemStack> dungeonsModeIcons = new LinkedHashMap<String, ItemStack>() {
private static final LinkedHashMap<String, ItemStack> pageModeIcon = new LinkedHashMap<String, ItemStack>() {
{
put(
"catacombs",
Expand Down Expand Up @@ -650,17 +650,17 @@ private void drawSideButtons() {
GlStateManager.enableDepth();
GlStateManager.translate(0, 0, 5);
if (onMasterMode) {
Utils.drawPvSideButton(1, dungeonsModeIcons.get("master_catacombs"), true, getInstance());
Utils.drawPvSideButton(1, pageModeIcon.get("master_catacombs"), true, getInstance());
} else {
Utils.drawPvSideButton(0, dungeonsModeIcons.get("catacombs"), true, getInstance());
Utils.drawPvSideButton(0, pageModeIcon.get("catacombs"), true, getInstance());
}
GlStateManager.translate(0, 0, -3);

GlStateManager.translate(0, 0, -2);
if (!onMasterMode) {
Utils.drawPvSideButton(1, dungeonsModeIcons.get("master_catacombs"), false, getInstance());
Utils.drawPvSideButton(1, pageModeIcon.get("master_catacombs"), false, getInstance());
} else {
Utils.drawPvSideButton(0, dungeonsModeIcons.get("catacombs"), false, getInstance());
Utils.drawPvSideButton(0, pageModeIcon.get("catacombs"), false, getInstance());
}
GlStateManager.disableDepth();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
* Copyright (C) 2022-2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
Expand All @@ -24,6 +24,7 @@
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.miscfeatures.profileviewer.SacksPage;
import io.github.moulberry.notenoughupdates.profileviewer.info.QuiverInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -131,15 +132,49 @@ public class InventoriesPage extends GuiProfileViewerPage {
put("intelligence",2f);
}};

private boolean onSacksPage;
private final SacksPage sacksPage;

private static final LinkedHashMap<String, ItemStack> pageModeIcon = new LinkedHashMap<String, ItemStack>() {
{
put(
"inventories",
Utils.editItemStackInfo(
new ItemStack(Items.painting),
EnumChatFormatting.GRAY + "Inventories",
true
)
);
put(
"sacks",
Utils.editItemStackInfo(
NotEnoughUpdates.INSTANCE.manager.jsonToStack(
NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("LARGE_ENCHANTED_MINING_SACK")
),
EnumChatFormatting.GRAY + "Sacks",
true
)
);
}
};

public InventoriesPage(GuiProfileViewer instance) {
super(instance);
this.sacksPage = new SacksPage(getInstance());
}

@Override
public void drawPage(int mouseX, int mouseY, float partialTicks) {
int guiLeft = GuiProfileViewer.getGuiLeft();
int guiTop = GuiProfileViewer.getGuiTop();

drawSideButtons();

if (onSacksPage) {
sacksPage.drawPage(mouseX, mouseY, partialTicks);
return;
}

Minecraft.getMinecraft().getTextureManager().bindTexture(pv_invs);
Utils.drawTexturedRect(guiLeft, guiTop, getInstance().sizeX, getInstance().sizeY, GL11.GL_NEAREST);
getInstance().inventoryTextField.setSize(88, 20);
Expand Down Expand Up @@ -512,15 +547,31 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
int guiLeft = GuiProfileViewer.getGuiLeft();
int guiTop = GuiProfileViewer.getGuiTop();

getInstance().inventoryTextField.setSize(88, 20);
if (mouseX > guiLeft + 19 && mouseX < guiLeft + 19 + 88) {
if (mouseY > guiTop + getInstance().sizeY - 26 - 20 && mouseY < guiTop + getInstance().sizeY - 26) {
getInstance().inventoryTextField.mouseClicked(mouseX, mouseY, mouseButton);
getInstance().playerNameTextField.otherComponentClick();
return true;
if (!onSacksPage) {
getInstance().inventoryTextField.setSize(88, 20);
if (mouseX > guiLeft + 19 && mouseX < guiLeft + 19 + 88) {
if (mouseY > guiTop + getInstance().sizeY - 26 - 20 && mouseY < guiTop + getInstance().sizeY - 26) {
getInstance().inventoryTextField.mouseClicked(mouseX, mouseY, mouseButton);
getInstance().playerNameTextField.otherComponentClick();
return true;
}
}
}
return false;

int i = ProfileViewerUtils.onSlotToChangePage(mouseX, mouseY, guiLeft, guiTop);
switch (i) {
case 1:
onSacksPage = false;
break;
case 2:
onSacksPage = true;
break;

default:
break;
}

return sacksPage.mouseClick(mouseX, mouseY, mouseButton);
}

@Override
Expand Down Expand Up @@ -844,4 +895,23 @@ private int getRowsForInventory(String invName) {
return 6;
}
}

private void drawSideButtons() {
GlStateManager.enableDepth();
GlStateManager.translate(0, 0, 5);
if (onSacksPage) {
Utils.drawPvSideButton(1, pageModeIcon.get("sacks"), true, getInstance());
} else {
Utils.drawPvSideButton(0, pageModeIcon.get("inventories"), true, getInstance());
}
GlStateManager.translate(0, 0, -3);

GlStateManager.translate(0, 0, -2);
if (!onSacksPage) {
Utils.drawPvSideButton(1, pageModeIcon.get("sacks"), false, getInstance());
} else {
Utils.drawPvSideButton(0, pageModeIcon.get("inventories"), false, getInstance());
}
GlStateManager.disableDepth();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,15 @@ private static void getPlayerSkull(String username, Consumer<ItemStack> callback
}
});
}

public static int onSlotToChangePage(int mouseX, int mouseY, int guiLeft, int guiTop) {
if (mouseX >= guiLeft - 29 && mouseX <= guiLeft) {
if (mouseY >= guiTop && mouseY <= guiTop + 28) {
return 1;
} else if (mouseY + 28 >= guiTop && mouseY <= guiTop + 28 * 2) {
return 2;
}
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public JsonElement serialize(Pattern src, Type typeOfSrc, JsonSerializationConte
public static JsonObject SBLEVELS;
public static JsonObject MUSEUM;
public static JsonObject BESTIARY;
public static JsonObject SACKS;

private static final ReentrantLock lock = new ReentrantLock();

Expand Down Expand Up @@ -111,6 +112,7 @@ public void reload(RepositoryReloadEvent event) {
SBLEVELS = Utils.getConstant("sblevels", gson);
MUSEUM = Utils.getConstant("museum", gson);
BESTIARY = Utils.getConstant("bestiary", gson);
SACKS = Utils.getConstant("sacks", gson);

parseEssenceCosts();
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,10 @@ public static void drawStringCentered(String str, float x, float y, boolean shad
drawStringCentered(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour);
}

public static void drawStringCentered(String str, int x, int y, boolean shadow, int colour) {
drawStringCentered(str, Minecraft.getMinecraft().fontRendererObj, x, y, shadow, colour);
}

@Deprecated
public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) {
int strLen = fr.getStringWidth(str);
Expand Down
Loading

0 comments on commit f197b51

Please sign in to comment.