Skip to content

Commit

Permalink
Improve ME Interface Terminal UI (#368)
Browse files Browse the repository at this point in the history
Co-authored-by: NotMyWing <[email protected]>
  • Loading branch information
serenibyss and NotMyWing authored May 24, 2024
1 parent 59edb38 commit 78c7235
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 276 deletions.
7 changes: 5 additions & 2 deletions src/api/java/appeng/api/config/ActionItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ public enum ActionItems
DIVIDE_BY_THREE,
DECREASE_BY_ONE,
MAX_COUNT,
FREE_MOLECULAR_SLOT_SHORTCUT,
MOLECULAR_ASSEMBLERS_ON,
MOLECULAR_ASSEMBLERS_OFF,
TOGGLE_SHOW_FULL_INTERFACES_ON,
TOGGLE_SHOW_FULL_INTERFACES_OFF,
TOGGLE_SHOW_ONLY_INVALID_PATTERNS_ON,
TOGGLE_SHOW_ONLY_INVALID_PATTERNS_OFF,
HIGHLIGHT_INTERFACE
}
}
2 changes: 1 addition & 1 deletion src/main/java/appeng/client/gui/AEBaseGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected void drawGuiSlot(GuiCustomSlot slot, int mouseX, int mouseY, float par
}
}

private void drawTooltip(ITooltip tooltip, int mouseX, int mouseY) {
protected void drawTooltip(ITooltip tooltip, int mouseX, int mouseY) {
final int x = tooltip.xPos(); // ((GuiImgButton) c).x;
int y = tooltip.yPos(); // ((GuiImgButton) c).y;

Expand Down
544 changes: 286 additions & 258 deletions src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/main/java/appeng/client/gui/widgets/GuiImgButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ public GuiImgButton(final int x, final int y, final Enum idx, final Enum val) {
this.registerApp(11 + 4 * 16, Settings.ACTIONS, ActionItems.DECREASE_BY_ONE, ButtonToolTips.DecreaseByOne, ButtonToolTips.DecreaseByOneDesc);
this.registerApp(12 + 4 * 16, Settings.ACTIONS, ActionItems.MAX_COUNT, ButtonToolTips.MaxCount, ButtonToolTips.MaxCountDesc);

this.registerApp(6 + 5 * 16, Settings.ACTIONS, ActionItems.FREE_MOLECULAR_SLOT_SHORTCUT, ButtonToolTips.FreeMolecularSlotShortcut, ButtonToolTips.FreeMolecularSlotShortcutDesc);
this.registerApp(6 + 5 * 16, Settings.ACTIONS, ActionItems.MOLECULAR_ASSEMBLERS_ON, ButtonToolTips.ToggleMolecularAssemblers, ButtonToolTips.ToggleMolecularAssemblersOnDesc);
this.registerApp(7 + 5 * 16, Settings.ACTIONS, ActionItems.TOGGLE_SHOW_FULL_INTERFACES_ON, ButtonToolTips.ToggleShowFullInterfaces, ButtonToolTips.ToggleShowFullInterfacesOnDesc);
this.registerApp(8 + 5 * 16, Settings.ACTIONS, ActionItems.TOGGLE_SHOW_FULL_INTERFACES_OFF, ButtonToolTips.ToggleShowFullInterfaces, ButtonToolTips.ToggleShowFullInterfacesOffDesc);
this.registerApp(9 + 5 * 16, Settings.ACTIONS, ActionItems.MOLECULAR_ASSEMBLERS_OFF, ButtonToolTips.ToggleMolecularAssemblers, ButtonToolTips.ToggleMolecularAssemblersOffDesc);
this.registerApp(6 + 6 * 16, Settings.ACTIONS, ActionItems.HIGHLIGHT_INTERFACE, ButtonToolTips.HighlightInterface, "");
this.registerApp(4 + 5 * 16, Settings.ACTIONS, ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERNS_OFF, ButtonToolTips.ToggleShowOnlyInvalidInterface, ButtonToolTips.ToggleShowOnlyInvalidInterfaceOffDesc);
this.registerApp(5 + 5 * 16, Settings.ACTIONS, ActionItems.TOGGLE_SHOW_ONLY_INVALID_PATTERNS_ON, ButtonToolTips.ToggleShowOnlyInvalidInterface, ButtonToolTips.ToggleShowOnlyInvalidInterfaceOnDesc);

this.registerApp(8, Settings.ACTIONS, ActionItems.ENCODE, ButtonToolTips.Encode, ButtonToolTips.EncodeDescription);
this.registerApp(4 + 3 * 16, Settings.ACTIONS, ItemSubstitution.ENABLED, ButtonToolTips.Substitutions, ButtonToolTips.SubstitutionsDescEnabled);
Expand Down
236 changes: 236 additions & 0 deletions src/main/java/appeng/client/gui/widgets/MEGuiTooltipTextField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
package appeng.client.gui.widgets;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;

/**
* Different implementation of a text field that wraps instead of extends
* MC's {@link GuiTextField}. This is necessary because of deobfuscated name
* collision between {@link ITooltip} and GuiTextField, which would cause
* crashes in an obfuscated environment. Additionally, since we are not extending that
* class, we can construct this object differently and allow its position to be
* mutable like most other widgets.
*/
public class MEGuiTooltipTextField implements ITooltip {

protected GuiTextField field;

private static final int PADDING = 2;
private static boolean previousKeyboardRepeatEnabled;
private static MEGuiTooltipTextField previousKeyboardRepeatEnabledField;
private String tooltip;
private int fontPad;

public int x;
public int y;
public int w;
public int h;

/**
* Uses the values to instantiate a padded version of a text field. Pays attention to the '_' caret.
*
* @param width absolute width
* @param height absolute height
* @param tooltip tooltip message
*/
public MEGuiTooltipTextField(final int width, final int height, final String tooltip) {
final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
field = new GuiTextField(0, fontRenderer, 0, 0, 0, 0);

w = width;
h = height;

setMessage(tooltip);

this.fontPad = fontRenderer.getCharWidth('_');

setDimensionsAndColor();
}

public MEGuiTooltipTextField(final int width, final int height) {
this(width, height, "");
}

public MEGuiTooltipTextField() {
this(0, 0);
}

protected void setDimensionsAndColor() {
field.x = this.x + PADDING;
field.y = this.y + PADDING;
field.width = this.w - PADDING * 2 - this.fontPad;
field.height = this.h - PADDING * 2;
}

public void onTextChange(final String oldText) {}

public void mouseClicked(final int xPos, final int yPos, final int button) {

if (!this.isMouseIn(xPos, yPos)) {
setFocused(false);
return;
}

field.setCanLoseFocus(false);
setFocused(true);

if (button == 1) {
setText("");
} else {
field.mouseClicked(xPos, yPos, button);
}

field.setCanLoseFocus(true);
}

/**
* Checks if the mouse is within the element
*
* @param xCoord current x coord of the mouse
* @param yCoord current y coord of the mouse
* @return true if mouse position is within the getText field area
*/
public boolean isMouseIn(final int xCoord, final int yCoord) {
final boolean withinXRange = this.x <= xCoord && xCoord < this.x + this.w;
final boolean withinYRange = this.y <= yCoord && yCoord < this.y + this.h;

return withinXRange && withinYRange;
}

public boolean textboxKeyTyped(final char keyChar, final int keyID) {
if (!isFocused()) {
return false;
}

final String oldText = getText();
boolean handled = field.textboxKeyTyped(keyChar, keyID);

if (!handled && (keyID == Keyboard.KEY_RETURN || keyID == Keyboard.KEY_NUMPADENTER
|| keyID == Keyboard.KEY_ESCAPE)) {
setFocused(false);
}

if (handled) {
onTextChange(oldText);
}

return handled;
}

public void drawTextBox() {
if (field.getVisible()) {
setDimensionsAndColor();
GuiTextField.drawRect(
this.x + 1,
this.y + 1,
this.x + this.w - 1,
this.y + this.h - 1,
isFocused() ? 0xFF606060 : 0xFFA8A8A8);
field.drawTextBox();
}
}

public void setText(String text, boolean ignoreTrigger) {
final String oldText = getText();

int currentCursorPos = field.getCursorPosition();
field.setText(text);
field.setCursorPosition(currentCursorPos);

if (!ignoreTrigger) {
onTextChange(oldText);
}
}

public void setText(String text) {
setText(text, false);
}

public void setCursorPositionEnd() {
field.setCursorPositionEnd();
}

public void setFocused(boolean focus) {
if (field.isFocused() == focus) {
return;
}

field.setFocused(focus);

if (focus) {

if (previousKeyboardRepeatEnabledField == null) {
previousKeyboardRepeatEnabled = Keyboard.areRepeatEventsEnabled();
}

previousKeyboardRepeatEnabledField = this;
Keyboard.enableRepeatEvents(true);
} else {

if (previousKeyboardRepeatEnabledField == this) {
previousKeyboardRepeatEnabledField = null;
Keyboard.enableRepeatEvents(previousKeyboardRepeatEnabled);
}
}
}

public void setMaxStringLength(final int size) {
field.setMaxStringLength(size);
}

public void setEnableBackgroundDrawing(final boolean b) {
field.setEnableBackgroundDrawing(b);
}

public void setTextColor(final int color) {
field.setTextColor(color);
}

public void setCursorPositionZero() {
field.setCursorPositionZero();
}

public boolean isFocused() {
return field.isFocused();
}

public String getText() {
return field.getText();
}

public void setMessage(String t) {
tooltip = t;
}

@Override
public String getMessage() {
return tooltip;
}

@Override
public boolean isVisible() {
return field.getVisible();
}

@Override
public int xPos() {
return x;
}

@Override
public int yPos() {
return y;
}

@Override
public int getWidth() {
return w;
}

@Override
public int getHeight() {
return h;
}
}
11 changes: 9 additions & 2 deletions src/main/java/appeng/core/localization/ButtonToolTips.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,20 @@ public enum ButtonToolTips {
DecreaseByOneDesc,
MaxCount,
MaxCountDesc,
FreeMolecularSlotShortcut,
FreeMolecularSlotShortcutDesc,
ToggleMolecularAssemblers,
ToggleMolecularAssemblersOnDesc,
ToggleMolecularAssemblersOffDesc,
ToggleShowFullInterfaces,
ToggleShowFullInterfacesOnDesc,
ToggleShowFullInterfacesOffDesc,
ToggleShowOnlyInvalidInterface,
ToggleShowOnlyInvalidInterfaceOnDesc,
ToggleShowOnlyInvalidInterfaceOffDesc,
HighlightInterface,
HighlightInterfaceDesc,
SearchFieldInputs,
SearchFieldOutputs,
SearchFieldNames,

// Used in the tooltips of the items in the terminal, when moused over
ItemsStored,
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/appeng/core/localization/PlayerMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public enum PlayerMessages {
DeviceNotLinked,
StationCanNotBeLocated,
SettingCleared,
MissingPatternsToEncode;
MissingPatternsToEncode,
InterfaceInOtherDimParam,
InterfaceInOtherDim,
InterfaceHighlighted,
;

public ITextComponent get(Object... params) {
return new TextComponentTranslation(this.getName(), params);
}

public ITextComponent get() {
return new TextComponentTranslation(this.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class PartInterfaceTerminal extends AbstractPartDisplay {
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
public String in = "";
public String out = "";
public boolean onlyInterfacesWithFreeSlots = false;

public PartInterfaceTerminal(final ItemStack is) {
super(is);
Expand All @@ -64,9 +61,4 @@ public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, fi
public IPartModel getStaticModels() {
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
}

public void saveSearchStrings(String in, String out) {
this.in = in;
this.out = out;
}
}
16 changes: 13 additions & 3 deletions src/main/resources/assets/appliedenergistics2/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ chat.appliedenergistics2.ResetSettings=New device configuration created and copi
chat.appliedenergistics2.AmmoDepleted=Ammo Depleted.
chat.appliedenergistics2.isNowLocked=Monitor is now Locked.
chat.appliedenergistics2.isNowUnlocked=Monitor is now Unlocked.
chat.appliedenergistics2.InterfaceInOtherDimParam=Interface located at dimension: %d [ %s ] and cannot be highlighted
chat.appliedenergistics2.InterfaceInOtherDim=Interface is located in another dimension and cannot be highlighted
chat.appliedenergistics2.InterfaceHighlighted=The interface is now highlighted at X: %s Y: %s Z: %s

// Creative Tabs
itemGroup.appliedenergistics2=Applied Energistics 2
Expand Down Expand Up @@ -374,12 +377,19 @@ gui.tooltips.appliedenergistics2.DecreaseByOne=Decrease one
gui.tooltips.appliedenergistics2.DecreaseByOneDesc=Will try to add decrease the items set in the crafting slots by one DOES NOT MAINTAIN INGREDIENT RATIO
gui.tooltips.appliedenergistics2.MaxCount=Maximize slot count
gui.tooltips.appliedenergistics2.MaxCountDesc=Will maximize the output maintaing the input ratio of the items set in the crafting slots
gui.tooltips.appliedenergistics2.FreeMolecularSlotShortcut=Show Crafting interfaces with free slots
gui.tooltips.appliedenergistics2.FreeMolecularSlotShortcutDesc=Shortcut that toggles interfaces with free slots and searches for molecular assemblers
gui.tooltips.appliedenergistics2.ToggleMolecularAssemblers=Toggles showing crafting interfaces only
gui.tooltips.appliedenergistics2.ToggleMolecularAssemblersOffDesc=Showing all interfaces
gui.tooltips.appliedenergistics2.ToggleMolecularAssemblersOnDesc=Showing only interfaces on molecular assemblers
gui.tooltips.appliedenergistics2.ToggleShowFullInterfaces=Toggles showing interfaces with full slots
gui.tooltips.appliedenergistics2.ToggleShowFullInterfacesOnDesc=Showing all interfaces
gui.tooltips.appliedenergistics2.ToggleShowFullInterfacesOffDesc=Showing only interfaces with free slots
gui.tooltips.appliedenergistics2.HighlightInterface=Highlight interface
gui.tooltips.appliedenergistics2.ToggleShowOnlyInvalidInterface=Toggles showing interfaces with invalid patterns
gui.tooltips.appliedenergistics2.ToggleShowOnlyInvalidInterfaceOffDesc=Showing all interfaces
gui.tooltips.appliedenergistics2.ToggleShowOnlyInvalidInterfaceOnDesc=Showing only interfaces with invalid patterns
gui.tooltips.appliedenergistics2.HighlightInterface=Highlight Interface
gui.tooltips.appliedenergistics2.SearchFieldInputs=Recipe Inputs
gui.tooltips.appliedenergistics2.SearchFieldOutputs=Recipe Outputs
gui.tooltips.appliedenergistics2.SearchFieldNames=Interface Names
gui.tooltips.appliedenergistics2.PartialTransfer=Move stored items into the crafting grid
gui.tooltips.appliedenergistics2.MissingItem=§cMissing item
gui.tooltips.appliedenergistics2.CraftableItem=§9Craftable item
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 78c7235

Please sign in to comment.