Fixed not being able to move inventory items in Grid GUI's to hotbar via the number keys, fixes #235

This commit is contained in:
Raoul Van den Berge
2016-08-06 22:27:26 +02:00
parent aa8e49d2f9
commit 122fd98db8
7 changed files with 48 additions and 43 deletions

View File

@@ -6,6 +6,7 @@
- Slight performance improvement in GUI's
- Fixed not being able to change some configs in blocks
- Fixed serverside configs not syncing up with clientside
- Fixed not being able to move inventory items in Grid GUI's to hotbar via the number keys
**Features**
- Added German translation by ChillUpX

View File

@@ -16,7 +16,7 @@ public class GuiStorage extends GuiBase {
private IStorageGui gui;
private String texture;
public static GuiTextField PRIORITY;
private GuiTextField priorityField;
private int barX = 8;
private int barY = 54;
@@ -49,13 +49,14 @@ public class GuiStorage extends GuiBase {
addSideButton(new SideButtonCompare(gui.getCompareParameter(), CompareUtils.COMPARE_NBT));
}
PRIORITY = new GuiTextField(0, fontRendererObj, x + 98 + 1, y + 54 + 1, 25, fontRendererObj.FONT_HEIGHT);
PRIORITY.setText(String.valueOf(gui.getPriorityParameter().getValue()));
PRIORITY.setEnableBackgroundDrawing(false);
PRIORITY.setVisible(true);
PRIORITY.setTextColor(16777215);
PRIORITY.setCanLoseFocus(true);
PRIORITY.setFocused(false);
priorityField = new GuiTextField(0, fontRendererObj, x + 98 + 1, y + 54 + 1, 25, fontRendererObj.FONT_HEIGHT);
priorityField.setEnableBackgroundDrawing(false);
priorityField.setVisible(true);
priorityField.setTextColor(16777215);
priorityField.setCanLoseFocus(true);
priorityField.setFocused(false);
updatePriority(gui.getPriorityParameter().getValue());
}
@Override
@@ -72,7 +73,7 @@ public class GuiStorage extends GuiBase {
drawTexture(x + barX, y + barY + barHeight - barHeightNew, 179, barHeight - barHeightNew, barWidth, barHeightNew);
PRIORITY.drawTextBox();
priorityField.drawTextBox();
}
@Override
@@ -97,13 +98,15 @@ public class GuiStorage extends GuiBase {
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
PRIORITY.mouseClicked(mouseX, mouseY, mouseButton);
priorityField.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
protected void keyTyped(char character, int keyCode) throws IOException {
if (!checkHotbarKeys(keyCode) && PRIORITY.textboxKeyTyped(character, keyCode)) {
Integer result = Ints.tryParse(PRIORITY.getText());
if (checkHotbarKeys(keyCode)) {
// NO OP
} else if (priorityField.textboxKeyTyped(character, keyCode)) {
Integer result = Ints.tryParse(priorityField.getText());
if (result != null) {
TileDataManager.setParameter(gui.getPriorityParameter(), result);
@@ -112,4 +115,8 @@ public class GuiStorage extends GuiBase {
super.keyTyped(character, keyCode);
}
}
public void updatePriority(int priority) {
priorityField.setText(String.valueOf(priority));
}
}

View File

@@ -37,7 +37,7 @@ public class GuiGrid extends GuiBase {
private GridSortingQuantity quantitySorting = new GridSortingQuantity();
private GridSortingName nameSorting = new GridSortingName();
public static GuiTextField SEARCH_FIELD;
private GuiTextField searchField;
private ContainerGrid container;
private List<ClientStack> items = new ArrayList<>();
@@ -64,15 +64,16 @@ public class GuiGrid extends GuiBase {
int sx = x + 80 + 1;
int sy = y + 6 + 1;
if (SEARCH_FIELD == null) {
SEARCH_FIELD = new GuiTextField(0, fontRendererObj, sx, sy, 88 - 6, fontRendererObj.FONT_HEIGHT);
SEARCH_FIELD.setEnableBackgroundDrawing(false);
SEARCH_FIELD.setVisible(true);
SEARCH_FIELD.setTextColor(16777215);
if (searchField == null) {
searchField = new GuiTextField(0, fontRendererObj, sx, sy, 88 - 6, fontRendererObj.FONT_HEIGHT);
searchField.setEnableBackgroundDrawing(false);
searchField.setVisible(true);
searchField.setTextColor(16777215);
updateSearchFieldFocus(grid.getSearchBoxMode());
} else {
SEARCH_FIELD.xPosition = sx;
SEARCH_FIELD.yPosition = sy;
searchField.xPosition = sx;
searchField.yPosition = sy;
}
addSideButton(new SideButtonGridViewType(grid));
@@ -92,7 +93,7 @@ public class GuiGrid extends GuiBase {
if (grid.isConnected()) {
items.addAll(RefinedStorage.INSTANCE.items);
String query = SEARCH_FIELD.getText().trim().toLowerCase();
String query = searchField.getText().trim().toLowerCase();
Iterator<ClientStack> t = items.iterator();
@@ -243,7 +244,7 @@ public class GuiGrid extends GuiBase {
drawTexture(x + 152, y + 114, 240, ty * 16, 16, 16);
}
SEARCH_FIELD.drawTextBox();
searchField.drawTextBox();
}
@Override
@@ -328,11 +329,11 @@ public class GuiGrid extends GuiBase {
public void mouseClicked(int mouseX, int mouseY, int clickedButton) throws IOException {
super.mouseClicked(mouseX, mouseY, clickedButton);
SEARCH_FIELD.mouseClicked(mouseX, mouseY, clickedButton);
searchField.mouseClicked(mouseX, mouseY, clickedButton);
if (clickedButton == 1 && inBounds(79, 5, 90, 12, mouseX - guiLeft, mouseY - guiTop)) {
SEARCH_FIELD.setText("");
SEARCH_FIELD.setFocused(true);
searchField.setText("");
searchField.setFocused(true);
updateJEI();
}
@@ -385,7 +386,9 @@ public class GuiGrid extends GuiBase {
@Override
protected void keyTyped(char character, int keyCode) throws IOException {
if (!checkHotbarKeys(keyCode) && SEARCH_FIELD.textboxKeyTyped(character, keyCode)) {
if (checkHotbarKeys(keyCode)) {
// NO OP
} else if (searchField.textboxKeyTyped(character, keyCode)) {
updateJEI();
} else {
super.keyTyped(character, keyCode);
@@ -394,13 +397,12 @@ public class GuiGrid extends GuiBase {
private void updateJEI() {
if (IntegrationJEI.isLoaded() && (grid.getSearchBoxMode() == TileGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED || grid.getSearchBoxMode() == TileGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED)) {
IntegrationJEI.INSTANCE.getRuntime().getItemListOverlay().setFilterText(SEARCH_FIELD.getText());
IntegrationJEI.INSTANCE.getRuntime().getItemListOverlay().setFilterText(searchField.getText());
}
}
// @TODO: This is buggy...
public static void updateSearchFieldFocus(int mode) {
SEARCH_FIELD.setCanLoseFocus(!TileGrid.isSearchBoxModeWithAutoselection(mode));
SEARCH_FIELD.setFocused(TileGrid.isSearchBoxModeWithAutoselection(mode));
public void updateSearchFieldFocus(int mode) {
searchField.setCanLoseFocus(!TileGrid.isSearchBoxModeWithAutoselection(mode));
searchField.setFocused(TileGrid.isSearchBoxModeWithAutoselection(mode));
}
}

View File

@@ -43,5 +43,7 @@ public class SideButtonGridSearchBoxMode extends SideButton {
}
gui.getGrid().onSearchBoxModeChanged(mode);
gui.updateSearchFieldFocus(mode);
}
}

View File

@@ -1,7 +1,6 @@
package refinedstorage.tile.config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.FMLCommonHandler;
@@ -25,12 +24,8 @@ public interface IPrioritizable {
((IPrioritizable) tile).setPriority(value);
}
}, parameter -> {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if (gui instanceof GuiStorage) {
((GuiStorage) gui).PRIORITY.setText(String.valueOf(parameter.getValue()));
}
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && Minecraft.getMinecraft().currentScreen instanceof GuiStorage) {
((GuiStorage) Minecraft.getMinecraft().currentScreen).updatePriority(parameter.getValue());
}
});
}

View File

@@ -1,5 +1,6 @@
package refinedstorage.tile.grid;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.*;
@@ -101,8 +102,8 @@ public class TileGrid extends TileNode implements IGrid {
}
}
}, parameter -> {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
GuiGrid.updateSearchFieldFocus(parameter.getValue());
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && Minecraft.getMinecraft().currentScreen instanceof GuiGrid) {
((GuiGrid) Minecraft.getMinecraft().currentScreen).updateSearchFieldFocus(parameter.getValue());
}
});

View File

@@ -10,7 +10,6 @@ import refinedstorage.RefinedStorage;
import refinedstorage.api.network.IGridHandler;
import refinedstorage.block.EnumGridType;
import refinedstorage.gui.grid.GridFilteredItem;
import refinedstorage.gui.grid.GuiGrid;
import refinedstorage.inventory.ItemHandlerBasic;
import refinedstorage.inventory.ItemHandlerGridFilterInGrid;
import refinedstorage.item.ItemWirelessGrid;
@@ -136,8 +135,6 @@ public class WirelessGrid implements IGrid {
RefinedStorage.INSTANCE.network.sendToServer(new MessageWirelessGridSettingsUpdate(getViewType(), getSortingDirection(), getSortingType(), searchBoxMode));
this.searchBoxMode = searchBoxMode;
GuiGrid.updateSearchFieldFocus(searchBoxMode);
}
@Override