Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Keybindings changes
Browse files Browse the repository at this point in the history
Merged PAGE_RENAME keybind with ADDRESS_EDIT
Removed ADDRESS_REMOVE
Fixed crash with empty Notebook Page
  • Loading branch information
MrJake222 committed Feb 3, 2021
1 parent cd2ef6f commit 05b773d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 164 deletions.
69 changes: 19 additions & 50 deletions src/main/java/mrjake/aunis/event/InputHandlerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
import mrjake.aunis.item.dialer.UniverseDialerActionPacketToServer;
import mrjake.aunis.item.notebook.NotebookActionEnum;
import mrjake.aunis.item.notebook.NotebookActionPacketToServer;
import mrjake.aunis.item.notebook.NotebookItem;
import mrjake.aunis.item.notebook.PageNotebookItem;
import mrjake.aunis.packet.AunisPacketHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
Expand All @@ -46,18 +43,15 @@ public class InputHandlerClient {
private static final KeyBinding MODE_DOWN = new KeyBinding("config.aunis.mode_down", 0, "Aunis");
private static final KeyBinding ADDRESS_UP = new KeyBinding("config.aunis.address_up", 0, "Aunis");
private static final KeyBinding ADDRESS_DOWN = new KeyBinding("config.aunis.address_down", 0, "Aunis");
private static final KeyBinding ADDRESS_REMOVE = new KeyBinding("config.aunis.address_remove", Keyboard.KEY_DELETE, "Aunis");

// Used to open common gui on Notebook/Universe dialer
private static final KeyBinding ADDRESS_EDIT = new KeyBinding("config.aunis.address_edit", Keyboard.KEY_INSERT, "Aunis");

// Universe dialer bindings
// TODO Unify DIALER_ABORT and DIALER_OC_PROGRAM into ADDRESS_EDIT
private static final KeyBinding DIALER_ABORT = new KeyBinding("config.aunis.universe_dialer.abort", Keyboard.KEY_K, "Aunis");
private static final KeyBinding DIALER_OC_PROGRAM = new KeyBinding("config.aunis.universe_dialer.oc_program", Keyboard.KEY_O, "Aunis");

// Notebook page bindings
private static final KeyBinding PAGE_RENAME = new KeyBinding("config.aunis.page_notebook.rename", Keyboard.KEY_R, "Aunis");

// Unpress
private static final Method METHOD_UNPRESS = ObfuscationReflectionHelper.findMethod(KeyBinding.class, "func_74505_d", void.class);

Expand All @@ -70,16 +64,12 @@ public class InputHandlerClient {
MODE_DOWN,
ADDRESS_UP,
ADDRESS_DOWN,
ADDRESS_REMOVE,

ADDRESS_EDIT,

// Universe dialer bindings
DIALER_ABORT,
DIALER_OC_PROGRAM,

// Notebook page bindings
PAGE_RENAME
DIALER_OC_PROGRAM
};

// Init function, call from preInit
Expand Down Expand Up @@ -204,13 +194,10 @@ else if (ADDRESS_DOWN.isPressed()) {
next = true;
}

else if (ADDRESS_REMOVE.isPressed())
action = UniverseDialerActionEnum.ADDRESS_REMOVE;

else if (DIALER_ABORT.isPressed())
else if (DIALER_ABORT.isPressed()) // TODO Merge DIALER_ABORT into AddressChangeGui
action = UniverseDialerActionEnum.ABORT;

else if (DIALER_OC_PROGRAM.isPressed())
else if (DIALER_OC_PROGRAM.isPressed()) // TODO Merge DIALER_OC_PROGRAM into AddressChangeGui
Minecraft.getMinecraft().displayGuiScreen(new OCMessageGui());


Expand All @@ -222,7 +209,6 @@ else if (DIALER_OC_PROGRAM.isPressed())

else if (checkForItem(AunisItems.NOTEBOOK_ITEM)) {
EnumHand hand = getHand(AunisItems.NOTEBOOK_ITEM);
ItemStack stack = Minecraft.getMinecraft().player.getHeldItem(hand);
NotebookActionEnum action = null;
boolean next = false;

Expand All @@ -236,41 +222,12 @@ else if (ADDRESS_DOWN.isPressed()) {
next = true;
}

else if (ADDRESS_REMOVE.isPressed())
action = NotebookActionEnum.ADDRESS_REMOVE;

else if (PAGE_RENAME.isPressed()) {
String name = "";

if (stack.hasTagCompound()) {
NBTTagCompound pageTag = NotebookItem.getSelectedPageFromCompound(stack.getTagCompound());
name = PageNotebookItem.getNameFromCompound(pageTag);
}

Minecraft.getMinecraft().displayGuiScreen(new PageRenameGui(name, hand, true));
}

// ---------------------------------------------
if (action != null) {
AunisPacketHandler.INSTANCE.sendToServer(new NotebookActionPacketToServer(action, hand, next));
}
}

else if (checkForItem(AunisItems.PAGE_NOTEBOOK_ITEM)) {
EnumHand hand = getHand(AunisItems.PAGE_NOTEBOOK_ITEM);
ItemStack stack = Minecraft.getMinecraft().player.getHeldItem(hand);

if (PAGE_RENAME.isPressed() && stack.getMetadata() == 1) {
String name = "";

if (stack.hasTagCompound()) {
name = PageNotebookItem.getNameFromCompound(stack.getTagCompound());
}

Minecraft.getMinecraft().displayGuiScreen(new PageRenameGui(name, hand, false));
}
}

if (ADDRESS_EDIT.isPressed()) {
tryOpenAddressGui(player);
}
Expand All @@ -285,15 +242,27 @@ else if (checkForItem(AunisItems.PAGE_NOTEBOOK_ITEM)) {
}

private static void tryOpenAddressGui(EntityPlayer player) {
EnumHand hand = getHand(AunisItems.NOTEBOOK_ITEM);
EnumHand hand = getHand(AunisItems.PAGE_NOTEBOOK_ITEM);
if (hand != null) {
ItemStack stack = player.getHeldItem(hand);

if (stack.getMetadata() == 1) {
// Full page (not empty)
Minecraft.getMinecraft().displayGuiScreen(new PageRenameGui(hand, player.getHeldItem(hand)));
}

return;
}

hand = getHand(AunisItems.NOTEBOOK_ITEM);
if (hand != null) {
Minecraft.getMinecraft().displayGuiScreen(new NotebookAddressChangeGui(hand, getItemStack(player, AunisItems.NOTEBOOK_ITEM)));
Minecraft.getMinecraft().displayGuiScreen(new NotebookAddressChangeGui(hand, player.getHeldItem(hand)));
return;
}

hand = getHand(AunisItems.UNIVERSE_DIALER);
if (hand != null) {
Minecraft.getMinecraft().displayGuiScreen(new UniverseAddressChangeGui(hand, getItemStack(player, AunisItems.UNIVERSE_DIALER)));
Minecraft.getMinecraft().displayGuiScreen(new UniverseAddressChangeGui(hand, player.getHeldItem(hand)));
return;
}
}
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/mrjake/aunis/gui/GuiScreenTextFields.java

This file was deleted.

14 changes: 7 additions & 7 deletions src/main/java/mrjake/aunis/gui/PageRenameGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.ArrayList;
import java.util.List;

import mrjake.aunis.item.notebook.PageNotebookItem;
import mrjake.aunis.item.notebook.PageNotebookSetNameToServer;
import mrjake.aunis.packet.AunisPacketHandler;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import org.lwjgl.input.Keyboard;

Expand All @@ -20,16 +22,14 @@ public class PageRenameGui extends GuiScreen {
private List<LabeledTextBox> textBoxes = new ArrayList<>();
private GuiButton saveButton;

private String originalName;
private EnumHand hand;
private boolean notebook;
private String originalName;

public PageRenameGui(String name, EnumHand hand, boolean notebook) {
this.originalName = name;
public PageRenameGui(EnumHand hand, ItemStack stack) {
this.hand = hand;
this.notebook = notebook;
originalName = PageNotebookItem.getNameFromCompound(stack.getTagCompound());
}

@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
Expand Down Expand Up @@ -95,7 +95,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
protected void actionPerformed(GuiButton button) throws IOException {
String name = textBoxes.get(0).textField.getText();

AunisPacketHandler.INSTANCE.sendToServer(new PageNotebookSetNameToServer(hand, name, notebook));
AunisPacketHandler.INSTANCE.sendToServer(new PageNotebookSetNameToServer(hand, name));
keyTyped(' ', 1); // close GUI
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.lwjgl.opengl.GL11;

import mrjake.aunis.Aunis;
import mrjake.aunis.gui.BetterButton;
import mrjake.aunis.packet.AunisPacketHandler;
import mrjake.aunis.packet.gui.address.AddressDataTypeEnum;
Expand Down Expand Up @@ -141,7 +142,7 @@ protected void action(AddressActionEnum action) {

/**
* Called on mouse clicked on every instance of {@link AbstractAddressEntry}
* @return {@code true} when an action was performed, {@code false} if no element was activated.
* @return {@code true} when a button was clicked, {@code false} if other or no element was activated.
*/
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseButton != 0)
Expand All @@ -158,9 +159,7 @@ public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
}

for (GuiTextField tf : textFields) {
if (tf.mouseClicked(mouseX, mouseY, mouseButton)) {
return true;
}
tf.mouseClicked(mouseX, mouseY, mouseButton);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* saved addresses.
*
* @author MrJake222
*
* TODO Add OpenComputers menu support to UniverseAddressChangeGui
*/
public class UniverseAddressChangeGui extends AbstractAddressChangeGui {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
public enum UniverseDialerActionEnum {
MODE_CHANGE,
ADDRESS_CHANGE,
ADDRESS_REMOVE,
ABORT
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
Expand Down Expand Up @@ -86,22 +85,6 @@ public IMessage onMessage(UniverseDialerActionPacketToServer message, MessageCon
break;


case ADDRESS_REMOVE:
switch (mode) {
case MEMORY:
case OC:
NBTTagList addressList = compound.getTagList(mode.tagListName, NBT.TAG_COMPOUND);

if (selected < addressList.tagCount())
addressList.removeTag(selected);

default:
break;
}

break;


case ABORT:
if (compound.hasKey("linkedGate")) {
BlockPos pos = BlockPos.fromLong(compound.getLong("linkedGate"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mrjake.aunis.item.notebook;

public enum NotebookActionEnum {
ADDRESS_CHANGE,
ADDRESS_REMOVE;
ADDRESS_CHANGE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
Expand Down Expand Up @@ -73,28 +71,6 @@ public IMessage onMessage(NotebookActionPacketToServer message, MessageContext c
}

break;


case ADDRESS_REMOVE:
// Create page
NBTTagCompound pageTag = NotebookItem.getSelectedPageFromCompound(compound);
ItemStack page = new ItemStack(AunisItems.PAGE_NOTEBOOK_ITEM, 1, 1);
page.setTagCompound(pageTag);

// Remove page
NBTTagList addressList = compound.getTagList("addressList", NBT.TAG_COMPOUND);

if (addressList.tagCount() == 1)
player.setHeldItem(message.hand, ItemStack.EMPTY);
else if (selected < addressList.tagCount()) {
addressList.removeTag(selected);
compound.setInteger("selected", MathHelper.clamp(selected, 0, addressList.tagCount()-1));
}

// Add page
player.addItemStackToInventory(page);

break;
}
}
});
Expand Down
Loading

0 comments on commit 05b773d

Please sign in to comment.