Files
NotEnoughItems/src/main/java/codechicken/nei/LayoutStyleMinecraft.java
T

200 lines
7.0 KiB
Java
Raw Normal View History

2014-04-29 10:54:20 +10:00
package codechicken.nei;
2019-12-24 13:37:41 -08:00
import codechicken.nei.api.LayoutStyle;
import codechicken.nei.drawable.DrawableBuilder;
2019-12-24 13:37:41 -08:00
import net.minecraft.client.gui.inventory.GuiContainer;
2014-04-29 10:54:20 +10:00
import org.lwjgl.opengl.GL11;
import static codechicken.lib.gui.GuiDraw.drawStringC;
2019-12-24 13:37:41 -08:00
import static codechicken.nei.LayoutManager.bookmarkPanel;
2021-03-20 22:38:46 -07:00
import static codechicken.nei.LayoutManager.bookmarksButton;
2019-12-24 13:37:41 -08:00
import static codechicken.nei.LayoutManager.delete;
import static codechicken.nei.LayoutManager.dropDown;
2022-05-06 22:41:45 +03:00
import static codechicken.nei.LayoutManager.presetsPanel;
2019-12-24 13:37:41 -08:00
import static codechicken.nei.LayoutManager.gamemode;
import static codechicken.nei.LayoutManager.heal;
import static codechicken.nei.LayoutManager.itemPanel;
import static codechicken.nei.LayoutManager.itemPresenceOverlays;
2019-12-24 13:37:41 -08:00
import static codechicken.nei.LayoutManager.magnet;
import static codechicken.nei.LayoutManager.options;
import static codechicken.nei.LayoutManager.rain;
import static codechicken.nei.LayoutManager.searchField;
import static codechicken.nei.LayoutManager.timeButtons;
import static codechicken.nei.NEIClientConfig.canPerformAction;
import static codechicken.nei.NEIClientConfig.disabledActions;
import static codechicken.nei.NEIClientConfig.getMagnetMode;
import static codechicken.nei.NEIClientConfig.isEnabled;
2014-04-29 10:54:20 +10:00
2019-12-24 13:37:41 -08:00
public class LayoutStyleMinecraft extends LayoutStyle
2014-04-29 10:54:20 +10:00
{
2019-12-24 13:37:41 -08:00
public int buttonCount;
public int leftSize;
public int numButtons;
2014-04-29 10:54:20 +10:00
@Override
public String getName() {
return "minecraft";
}
@Override
public void init() {
delete.icon = new Image(144, 12, 12, 12);
2019-12-24 13:37:41 -08:00
rain.icon = new Image(120, 12, 12, 12);
2014-04-29 10:54:20 +10:00
gamemode.icons[0] = new Image(132, 12, 12, 12);
gamemode.icons[1] = new Image(156, 12, 12, 12);
gamemode.icons[2] = new Image(168, 12, 12, 12);
magnet.icon = new Image(180, 24, 12, 12);
timeButtons[0].icon = new Image(132, 24, 12, 12);
timeButtons[1].icon = new Image(120, 24, 12, 12);
timeButtons[2].icon = new Image(144, 24, 12, 12);
timeButtons[3].icon = new Image(156, 24, 12, 12);
heal.icon = new Image(168, 24, 12, 12);
itemPresenceOverlays[0] = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 40, 8, 8).build();
itemPresenceOverlays[1] = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8).build();
2014-04-29 10:54:20 +10:00
}
@Override
public void reset() {
2019-12-24 13:37:41 -08:00
buttonCount = 0;
2014-04-29 10:54:20 +10:00
}
@Override
2019-12-24 13:37:41 -08:00
public void layout(GuiContainer gui, VisiblityData visiblity) {
reset();
leftSize = ItemPanels.bookmarkPanel.getWidth(gui);
2020-01-21 20:20:23 -08:00
numButtons = Math.max(leftSize / 18, 1);
2019-12-24 13:37:41 -08:00
delete.state = 0x4;
if (NEIController.getDeleteMode())
delete.state |= 1;
else if (!visiblity.enableDeleteMode)
delete.state |= 2;
rain.state = 0x4;
if (disabledActions.contains("rain"))
rain.state |= 2;
else if (NEIClientUtils.isRaining())
rain.state |= 1;
gamemode.state = 0x4;
if (NEIClientUtils.getGamemode() != 0) {
gamemode.state |= 0x1;
gamemode.index = NEIClientUtils.getGamemode() - 1;
2014-04-29 10:54:20 +10:00
} else {
2019-12-24 13:37:41 -08:00
if (NEIClientUtils.isValidGamemode("creative"))
gamemode.index = 0;
else if (NEIClientUtils.isValidGamemode("creative+"))
gamemode.index = 1;
else if (NEIClientUtils.isValidGamemode("adventure"))
gamemode.index = 2;
}
2021-03-20 22:38:46 -07:00
bookmarksButton.index = NEIClientConfig.isBookmarkPanelHidden() ? 0 : 1;
2021-03-15 22:31:36 -07:00
options.index = NEIClientConfig.getCheatMode();
2019-12-24 13:37:41 -08:00
magnet.state = 0x4 | (getMagnetMode() ? 1 : 0);
if (canPerformAction("delete"))
layoutButton(delete);
if (canPerformAction("rain"))
layoutButton(rain);
if (NEIClientUtils.isValidGamemode("creative") ||
NEIClientUtils.isValidGamemode("creative+") ||
NEIClientUtils.isValidGamemode("adventure"))
layoutButton(gamemode);
if (canPerformAction("magnet"))
layoutButton(magnet);
if (canPerformAction("time")) {
for (int i = 0; i < 4; i++) {
timeButtons[i].state = disabledActions.contains(NEIActions.timeZones[i]) ? 2 : 0;
layoutButton(timeButtons[i]);
}
2014-04-29 10:54:20 +10:00
}
2019-12-24 13:37:41 -08:00
if (canPerformAction("heal"))
layoutButton(heal);
itemPanel.resize(gui);
bookmarkPanel.resize(gui);
options.x = isEnabled() ? 0 : 6;
options.y = isEnabled() ? gui.height - 22 : gui.height - 28;
2021-03-15 22:31:36 -07:00
options.w = 22;
2019-12-24 13:37:41 -08:00
options.h = 22;
2021-03-20 22:38:46 -07:00
bookmarksButton.x = 24 + (isEnabled() ? 0 : 6);
bookmarksButton.y = isEnabled() ? gui.height - 22 : gui.height - 28;
bookmarksButton.w = 22;
bookmarksButton.h = 22;
2019-12-24 13:37:41 -08:00
2022-05-06 22:41:45 +03:00
dropDown.h = 18;
dropDown.w = 150;
dropDown.y = 0;
dropDown.x = (gui.width - gui.xSize) / 2 + gui.xSize - dropDown.w;
2019-12-24 13:37:41 -08:00
2022-05-06 22:41:45 +03:00
presetsPanel.h = 16;
presetsPanel.w = 150;
presetsPanel.y = 2;
presetsPanel.x = (gui.width - gui.xSize) / 2 + gui.xSize - presetsPanel.w;
2019-12-24 13:37:41 -08:00
searchField.h = 20;
searchField.w = 150;
searchField.x = (gui.width - searchField.w) / 2;
2022-05-06 22:41:45 +03:00
searchField.y = gui.height - searchField.h - 2;
2019-12-24 13:37:41 -08:00
if (!visiblity.showItemSection) {
searchField.setFocus(false);
}
}
public void layoutButton(Button button) {
2022-05-06 22:41:45 +03:00
button.x = 2 + (buttonCount % numButtons) * 19;
button.y = 2 + (buttonCount / numButtons) * 18;
2014-04-29 10:54:20 +10:00
button.h = 17;
button.w = button.contentWidth() + 6;
2019-12-24 13:37:41 -08:00
buttonCount++;
2014-04-29 10:54:20 +10:00
}
@Override
public void drawButton(Button b, int mousex, int mousey) {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1, 1, 1, 1);
int tex;
if ((b.state & 0x3) == 2)
tex = 0;
else if ((b.state & 0x4) == 0 && b.contains(mousex, mousey) ||//not a state button and mouseover
2019-12-24 13:37:41 -08:00
(b.state & 0x3) == 1)//state active
2014-04-29 10:54:20 +10:00
tex = 2;
else
tex = 1;
LayoutManager.drawButtonBackground(b.x, b.y, b.w, b.h, true, tex);
2014-04-29 10:54:20 +10:00
Image icon = b.getRenderIcon();
if (icon == null) {
2021-03-15 22:31:36 -07:00
int colour = tex == 2 ? 0xffffa0 : tex == 0 ? 0x601010 : 0xe0e0e0;
2014-04-29 10:54:20 +10:00
drawStringC(b.getRenderLabel(), b.x + b.w / 2, b.y + (b.h - 8) / 2, colour);
2014-04-29 10:54:20 +10:00
} else {
GL11.glColor4f(1, 1, 1, 1);
2021-03-15 22:31:36 -07:00
final int iconX = b.x + (b.w - icon.width) / 2;
final int iconY = b.y + (b.h - icon.height) / 2;
2021-03-23 23:34:05 -07:00
2021-03-15 22:31:36 -07:00
LayoutManager.drawIcon(iconX, iconY, icon);
2014-04-29 10:54:20 +10:00
}
}
@Override
public void drawSubsetTag(String text, int x, int y, int w, int h, int state, boolean mouseover) {
if(state == 1)
GL11.glColor4f(0.65F, 0.65F, 0.65F, 1.0F);
else
GL11.glColor4f(1, 1, 1, 1);
LayoutManager.drawButtonBackground(x, y, w, h, false, state == 0 ? 0 : 1);
if(text != null)
drawStringC(text, x, y, w, h, state == 2 ? 0xFFE0E0E0 : 0xFFA0A0A0);
2014-04-29 10:54:20 +10:00
}
}