Add Hotkeys Widget Settings (#613)

Co-authored-by: slprime <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-03-24 15:48:11 +01:00
1 parent 98c8981f05
commit eb40e3b112
11 files changed
+105 -57

No files matched your search

@@ -4,6 +4,7 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
@@ -102,6 +103,39 @@ public class FormattedTextField extends GuiTextField {
this.editable = p_146184_1_;
}
@Override
public void writeText(String p_146191_1_) {
String newText = "";
String substr = ChatAllowedCharacters.filerAllowedCharacters(p_146191_1_);
int cursorPosition = getCursorPosition();
int maxStringLength = getMaxStringLength();
String text = getText();
if (text.isEmpty()) {
newText = substr.substring(0, Math.min(maxStringLength, substr.length()));
cursorPosition = newText.length();
} else {
int selectionEnd = getSelectionEnd();
String textStart = text.substring(0, Math.min(cursorPosition, selectionEnd));
String textEnd = text.substring(Math.max(cursorPosition, selectionEnd));
newText = textStart + substr + textEnd;
if (newText.length() > maxStringLength) {
newText = newText.substring(0, maxStringLength);
}
cursorPosition = Math.min(textStart.length() + substr.length(), newText.length());
}
setText(newText);
setCursorPosition(cursorPosition);
}
@Override
public int getNthWordFromPos(int p_146183_1_, int p_146183_2_) {
return this.func_146197_a(p_146183_1_, p_146183_2_, true);
}
@Override
public void drawTextBox() {
if (this.getVisible()) {
@@ -234,8 +234,7 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
return true;
}
if (NEIClientConfig.isKeyHashDown("gui.next_tooltip")) {
GuiContainerManager.incrementTooltipPage();
if (NEIClientConfig.isKeyHashDown("gui.next_tooltip") && GuiContainerManager.incrementTooltipPage()) {
return true;
}
@@ -184,7 +184,7 @@ public class LayoutStyleMinecraft extends LayoutStyle {
final Rectangle4i area = new Rectangle4i(0, 0, 0, BUTTON_SIZE);
if (NEIClientConfig.isSearchWidgetCentered()) {
area.w = gui.xSize - MARGIN * 2;
area.w = Math.min(gui.xSize, 176) - MARGIN * 2;
area.x = (gui.width - area.w) / 2;
area.y = gui.height - BUTTON_SIZE - MARGIN;
} else if (NEIClientConfig.showItemQuantityWidget()) {
@@ -46,7 +46,6 @@ import codechicken.nei.config.GuiHighlightTips;
import codechicken.nei.config.GuiNEIOptionList;
import codechicken.nei.config.GuiOptionList;
import codechicken.nei.config.GuiPanelSettings;
import codechicken.nei.config.OptionButton;
import codechicken.nei.config.OptionCycled;
import codechicken.nei.config.OptionGamemodes;
import codechicken.nei.config.OptionIntegerField;
@@ -289,19 +288,6 @@ public class NEIClientConfig {
0,
OptionIntegerField.UNSIGNED_INT_MAX));
API.addOption(
new OptionButton(
"inventory.collapsibleItems.reloadLabel",
"inventory.collapsibleItems.reloadButton",
"inventory.collapsibleItems.reloadTip") {
@Override
public boolean onClick(int button) {
LayoutManager.markItemsDirty();
return super.onClick(button);
}
});
tag.getTag("inventory.itemzoom.enabled").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.itemzoom.enabled", true));
@@ -369,6 +355,9 @@ public class NEIClientConfig {
tag.getTag("inventory.gridRenderingCacheMode").getIntValue(0);
API.addOption(new OptionCycled("inventory.gridRenderingCacheMode", 3, true));
tag.getTag("inventory.hotkeysHelpText").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.hotkeysHelpText", true));
tag.getTag("loadPluginsInParallel").getBooleanValue(true);
tag.getTag("itemLoadingTimeout").getIntValue(500);
@@ -554,7 +554,8 @@ public class GuiContainerManager {
}
ItemStack stack = getStackMouseOver(window);
if (tooltip.isEmpty() && shouldShowTooltip(window)) { // mouseover tip, not holding an item
boolean showTooltip = shouldShowTooltip(window);
if (tooltip.isEmpty() && showTooltip) { // mouseover tip, not holding an item
font = getFontRenderer(stack);
if (stack != null) {
tooltip = itemDisplayNameMultiline(stack, window, true);
@@ -569,7 +570,7 @@ public class GuiContainerManager {
if (!tooltip.isEmpty()) tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); // add space after 'title'
if (shouldShowTooltip(window)) {
if (showTooltip) {
List<String> hotkeystips = collectHotkeyTips(mousex, mousey);
if (!hotkeystips.isEmpty()) {
@@ -615,23 +616,19 @@ public class GuiContainerManager {
}
private List<String> collectHotkeyTips(int mousex, int mousey) {
Map<String, String> hotkeys = new HashMap<>();
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
hotkeys = handler.handleHotkeys(window, mousex, mousey, hotkeys);
if (NEIClientUtils.altKey()) {
Map<String, String> hotkeys = new HashMap<>();
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
hotkeys = handler.handleHotkeys(window, mousex, mousey, hotkeys);
}
}
}
if (!hotkeys.isEmpty()) {
List<String> hotkeystips = new ArrayList<>();
if (!hotkeys.isEmpty()) {
List<String> hotkeystips = new ArrayList<>();
if (!NEIClientUtils.altKey()) {
hotkeystips.add(
EnumChatFormatting.GRAY + translate(
"showHotkeys",
EnumChatFormatting.GOLD + translate("key.alt") + EnumChatFormatting.GRAY));
} else {
Map<String, List<String>> messages = new HashMap<>();
hotkeys.remove(null);
hotkeys.remove("");
@@ -664,9 +661,28 @@ public class GuiContainerManager {
hotkeystips.set(
hotkeystips.size() - 1,
hotkeystips.get(hotkeystips.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
return hotkeystips;
}
return hotkeystips;
} else if (NEIClientConfig.getBooleanSetting("inventory.hotkeysHelpText")) {
boolean existsHotkeys = false;
synchronized (instanceTooltipHandlers) {
for (IContainerTooltipHandler handler : instanceTooltipHandlers) {
if (!handler.handleHotkeys(window, mousex, mousey, new HashMap<>()).isEmpty()) {
existsHotkeys = true;
break;
}
}
}
if (existsHotkeys) {
return Collections.singletonList(
EnumChatFormatting.GRAY + translate(
"showHotkeys",
EnumChatFormatting.GOLD + translate("key.alt") + EnumChatFormatting.GRAY));
}
}
return Collections.emptyList();
@@ -675,39 +691,50 @@ public class GuiContainerManager {
private String getHotkeyTip(List<String> keys, String message) {
return EnumChatFormatting.GOLD
+ String.join(EnumChatFormatting.DARK_GRAY + " / " + EnumChatFormatting.GOLD, keys)
+ EnumChatFormatting.GRAY
+ EnumChatFormatting.DARK_GRAY
+ " - "
+ EnumChatFormatting.GRAY
+ message
+ EnumChatFormatting.RESET;
}
private static int tooltipPage;
private static int maxTooltipPage;
public static void drawPagedTooltip(FontRenderer font, int x, int y, List<String> list) {
if (list.isEmpty()) return;
List<List<String>> tooltips = splitTooltipByPage(list);
tooltipPage = tooltipPage < tooltips.size() ? tooltipPage : 0;
if (tooltips.size() > 1) {
tooltips.get(tooltipPage).add(
EnumChatFormatting.ITALIC + NEIClientUtils.translate(
"inventory.tooltip.page",
tooltipPage + 1,
tooltips.size(),
NEIClientConfig.getKeyName("gui.next_tooltip")));
maxTooltipPage = tooltips.size();
tooltipPage = tooltipPage < maxTooltipPage ? tooltipPage : 0;
final List<String> currentTooltip = tooltips.get(tooltipPage);
if (maxTooltipPage > 1) {
final String pageTooltip = EnumChatFormatting.ITALIC + NEIClientUtils.translate(
"inventory.tooltip.page",
tooltipPage + 1,
maxTooltipPage,
NEIClientConfig.getKeyName("gui.next_tooltip"));
currentTooltip.set(
currentTooltip.size() - 1,
currentTooltip.get(currentTooltip.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
currentTooltip.add(pageTooltip);
}
if (NEIModContainer.isGTNHLibLoaded()) {
drawMultilineTip(
font,
x,
y,
tooltips.get(tooltipPage),
currentTooltip,
RenderTooltipEventHelper.getBackgroundStart(),
RenderTooltipEventHelper.getBackgroundEnd(),
RenderTooltipEventHelper.getBorderStart(),
RenderTooltipEventHelper.getBorderEnd());
return;
} else {
drawMultilineTip(font, x, y, currentTooltip);
}
drawMultilineTip(font, x, y, tooltips.get(tooltipPage));
}
public static List<List<String>> splitTooltipByPage(List<String> list) {
@@ -752,8 +779,8 @@ public class GuiContainerManager {
}
}
public static void incrementTooltipPage() {
tooltipPage++;
public static boolean incrementTooltipPage() {
return tooltipPage != Math.min(tooltipPage++, maxTooltipPage);
}
public void renderSlotUnderlay(Slot slot) {
@@ -86,7 +86,7 @@ public class StackInfo {
}
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
if (stackA == null || stackB == null || !stackA.isItemEqual(stackB)) {
if (stackA == null || stackB == null || stackA.getItem() != stackB.getItem()) {
return false;
}
@@ -24,7 +24,7 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
nbTag.setInteger("Count", saveStackSize ? stack.stackSize : 1);
nbTag.setShort("Damage", (short) stack.getItemDamage());
if (stack.hasTagCompound()) {
if (stack.hasTagCompound() && !stack.getTagCompound().hasNoTags()) {
nbTag.setTag("tag", stack.getTagCompound());
}
@@ -38,13 +38,13 @@ public class NEIMouseUtils {
if (mouseBind >= 0) {
int button = unhash(mouseBind);
switch (button) {
case 0:
case MOUSE_BTN_LMB:
mouseText.add(NEIClientUtils.translate("mouse.left"));
break;
case 1:
case MOUSE_BTN_RMB:
mouseText.add(NEIClientUtils.translate("mouse.right"));
break;
case 2:
case MOUSE_BTN_MMB:
mouseText.add(NEIClientUtils.translate("mouse.middle"));
break;
default:
@@ -24,7 +24,7 @@ public enum ReadableNumberConverter {
/**
* String representation of the sorted postfixes
*/
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
private static final char[] ENCODED_POSTFIXES = "kMGTPE".toCharArray();
private final Format format;