Skip to content

Commit

Permalink
Re-fixed #351
Browse files Browse the repository at this point in the history
Now with variables!
  • Loading branch information
Avalon2106 committed Dec 20, 2024
1 parent cc532d6 commit 40af521
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void initGui()
this.editor.setBounds(guiLeft+35, guiTop+46, 131, 80);

//Letter Change Buttons
buttonLetter = addButton(new GuiButtonDataLetterList(buttonList.size(), guiLeft+42-10, guiTop+14, false, variableToEdit, ArrowsAlignment.LEFT));
buttonLetter = addButton(new GuiButtonDataLetterList(buttonList.size(), guiLeft+42-10, guiTop+14, false, variableToEdit, ArrowsAlignment.LEFT, GuiButtonDataLetterList.DropdownPosition.BELOW));
buttonLetter.setAvoidGetter(this::getPacketFromPage);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void initGui()
}

//Letter Change Buttons
buttonLetter = addButton(new GuiButtonDataLetterList(buttonList.size(), guiLeft+42-10, guiTop+14, false, variableToEdit, ArrowsAlignment.LEFT));
buttonLetter = addButton(new GuiButtonDataLetterList(buttonList.size(), guiLeft+42-10, guiTop+14, false, variableToEdit, ArrowsAlignment.LEFT, GuiButtonDataLetterList.DropdownPosition.BELOW));
buttonLetter.setAvoidGetter(() -> list);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* @author Avalon
* @since 19.12.2024
*/
public class GuiButtonDataLetterList extends GuiButton
{
public class GuiButtonDataLetterList extends GuiButton {
private final ArrowsAlignment arrows;
@Nullable
private final GuiButtonIE buttonNext, buttonPrev;
private final DropdownPosition dropdownPosition;

public boolean dropped = false;
public final boolean hasEmpty;
Expand All @@ -36,143 +36,127 @@ public class GuiButtonDataLetterList extends GuiButton
@Nullable
private Supplier<DataPacket> avoidGetter;

public GuiButtonDataLetterList(int buttonId, int x, int y, boolean hasEmpty, char currentValue, ArrowsAlignment arrows)
{
super(buttonId, x, y, arrows==ArrowsAlignment.NONE?18: 28, 18, "");
public GuiButtonDataLetterList(int buttonId, int x, int y, boolean hasEmpty, char currentValue, ArrowsAlignment arrows, DropdownPosition dropdownPosition) {
super(buttonId, x, y, arrows == ArrowsAlignment.NONE ? 18 : 28, 18, "");
this.hasEmpty = hasEmpty;
selectedEntry = currentValue;
hoveredEntry = currentValue;
this.arrows = arrows;
this.dropdownPosition = dropdownPosition;

switch(arrows)
{
case LEFT:
{
this.buttonNext = new GuiButtonIE(0, x+1, y+2, 8, 6, "",
ImmersiveIntelligence.MODID+":textures/gui/emplacement_icons.png", 128, 77)
switch (arrows) {
case LEFT: {
this.buttonNext = new GuiButtonIE(0, x + 1, y + 2, 8, 6, "",
ImmersiveIntelligence.MODID + ":textures/gui/emplacement_icons.png", 128, 77)
.setHoverOffset(8, 0);
this.buttonPrev = new GuiButtonIE(1, x+1, y+10, 8, 6, "",
ImmersiveIntelligence.MODID+":textures/gui/emplacement_icons.png", 128, 77+6)
this.buttonPrev = new GuiButtonIE(1, x + 1, y + 10, 8, 6, "",
ImmersiveIntelligence.MODID + ":textures/gui/emplacement_icons.png", 128, 77 + 6)
.setHoverOffset(8, 0);
}
break;
case RIGHT:
{
this.buttonNext = new GuiButtonIE(0, x+width-9, y+2, 8, 6, "",
ImmersiveIntelligence.MODID+":textures/gui/emplacement_icons.png", 128, 77)
case RIGHT: {
this.buttonNext = new GuiButtonIE(0, x + width - 9, y + 2, 8, 6, "",
ImmersiveIntelligence.MODID + ":textures/gui/emplacement_icons.png", 128, 77)
.setHoverOffset(8, 0);
this.buttonPrev = new GuiButtonIE(1, x+width-9, y+10, 8, 6, "",
ImmersiveIntelligence.MODID+":textures/gui/emplacement_icons.png", 128, 77+6)
this.buttonPrev = new GuiButtonIE(1, x + width - 9, y + 10, 8, 6, "",
ImmersiveIntelligence.MODID + ":textures/gui/emplacement_icons.png", 128, 77 + 6)
.setHoverOffset(8, 0);
}
break;
default:
case NONE:
{
case NONE: {
buttonNext = null;
buttonPrev = null;
break;
}
}

}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
FontRenderer fr = ClientUtils.mc().fontRenderer;
if(!this.visible)
return;
if(!this.enabled)
GlStateManager.color(0.5f, 0.5f, 0.5f, 1);
else
GlStateManager.color(1, 1, 1, 1);
if (!this.visible) return;
if (!this.enabled) GlStateManager.color(0.5f, 0.5f, 0.5f, 1);
else GlStateManager.color(1, 1, 1, 1);
ClientUtils.bindTexture("immersiveintelligence:textures/gui/emplacement_icons.png");

if(buttonNext!=null)
buttonNext.drawButton(mc, mouseX, mouseY, partialTicks);
if(buttonPrev!=null)
buttonPrev.drawButton(mc, mouseX, mouseY, partialTicks);
if (buttonNext != null) buttonNext.drawButton(mc, mouseX, mouseY, partialTicks);
if (buttonPrev != null) buttonPrev.drawButton(mc, mouseX, mouseY, partialTicks);

int xx = arrows==ArrowsAlignment.LEFT?x+10: x;
int xx = arrows == ArrowsAlignment.LEFT ? x + 10 : x;

//frame
// Frame
this.drawTexturedModalRect(xx, y, 163, 142, 18, 18);

if(dropped)
{
if (dropped) {
GlStateManager.pushMatrix();
GlStateManager.enableDepth();
GlStateManager.translate(0,0,1);
GlStateManager.translate(0, 0, 1);

int dropdownX = xx;
int dropdownY = y + height;
if (dropdownPosition == DropdownPosition.RIGHT) {
dropdownX = xx + width;
dropdownY = y;
}

this.drawTexturedModalRect(xx, y+height, 56, 115, 96, 32);
this.drawTexturedModalRect(xx, y+height+32, 56, 195-4, 96, 20);
this.drawTexturedModalRect(dropdownX, dropdownY, 56, 115, 96, 32);
this.drawTexturedModalRect(dropdownX, dropdownY + 32, 56, 195 - 4, 96, 20);

if(IIMath.isPointInRectangle(xx+4, y+height+4, xx+4+10*fr.FONT_HEIGHT, y+height+52+4, mouseX, mouseY))
{
int hlX = ((int)Math.floor((mouseX-(xx+4))/(float)fr.FONT_HEIGHT));
int hlY = ((int)Math.floor((mouseY-(y+height+4))/(float)12));
if (IIMath.isPointInRectangle(dropdownX + 4, dropdownY + 4, dropdownX + 4 + 10 * fr.FONT_HEIGHT, dropdownY + 52 + 4, mouseX, mouseY)) {
int hlX = ((int) Math.floor((mouseX - (dropdownX + 4)) / (float) fr.FONT_HEIGHT));
int hlY = ((int) Math.floor((mouseY - (dropdownY + 4)) / (float) 12));

int i = hlX+(10*hlY);
if(i >= 0&&i < DataPacket.varCharacters.length)
int i = hlX + (10 * hlY);
if (i >= 0 && i < DataPacket.varCharacters.length)
hoveredEntry = DataPacket.varCharacters[i];
else
hoveredEntry = '/';
}
else
{
if(buttonNext!=null&&buttonNext.isMouseOver())
hoveredEntry = avoidGetter!=null?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, true, hasEmpty, avoidGetter.get()):
} else {
if (buttonNext != null && buttonNext.isMouseOver())
hoveredEntry = avoidGetter != null ?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, true, hasEmpty, avoidGetter.get()) :
IIUtils.cycleDataPacketChars(selectedEntry, true, hasEmpty);
else if(buttonPrev!=null&&buttonPrev.isMouseOver())
hoveredEntry = avoidGetter!=null?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, false, hasEmpty, avoidGetter.get()):
else if (buttonPrev != null && buttonPrev.isMouseOver())
hoveredEntry = avoidGetter != null ?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, false, hasEmpty, avoidGetter.get()) :
IIUtils.cycleDataPacketChars(selectedEntry, false, hasEmpty);
else
hoveredEntry = '/';
}

int cx = 0, cy = 0;
for(char c : hasEmpty?ArrayUtils.add(DataPacket.varCharacters, ' '): DataPacket.varCharacters)
{
this.drawTexturedModalRect(xx+1+cx*fr.FONT_HEIGHT, y+height+2+cy*12, 144, 89, 12, 12);
for (char c : hasEmpty ? ArrayUtils.add(DataPacket.varCharacters, ' ') : DataPacket.varCharacters) {
this.drawTexturedModalRect(dropdownX + 1 + cx * fr.FONT_HEIGHT, dropdownY + 2 + cy * 12, 144, 89, 12, 12);
cx++;
if(cx > 9)
{
if (cx > 9) {
cy++;
cx = 0;
}
}

cx = 0;
cy = 0;
DataPacket pack = avoidGetter!=null?avoidGetter.get():null;
for(char c : hasEmpty?ArrayUtils.add(DataPacket.varCharacters, ' '): DataPacket.varCharacters)
{
fr.drawString(String.valueOf(c==' '?'_': c), xx+4+cx*fr.FONT_HEIGHT, y+height+4+cy*12,
c==selectedEntry?Lib.COLOUR_I_ImmersiveOrange: ((pack!=null&&pack.hasVariable(c))?0x202020:(c==hoveredEntry?Lib.colour_nixieTubeText: 0xE0E0E0))
DataPacket pack = avoidGetter != null ? avoidGetter.get() : null;
for (char c : hasEmpty ? ArrayUtils.add(DataPacket.varCharacters, ' ') : DataPacket.varCharacters) {
fr.drawString(String.valueOf(c == ' ' ? '_' : c), dropdownX + 4 + cx * fr.FONT_HEIGHT, dropdownY + 4 + cy * 12,
c == selectedEntry ? Lib.COLOUR_I_ImmersiveOrange : ((pack != null && pack.hasVariable(c)) ? 0x202020 : (c == hoveredEntry ? Lib.colour_nixieTubeText : 0xE0E0E0))
);
cx++;
if(cx > 9)
{
if (cx > 9) {
cy++;
cx = 0;
}
}
GlStateManager.popMatrix();
}

fr.drawString(String.valueOf(selectedEntry==' '?'_': selectedEntry), xx+9-(int)Math.floor(fr.getCharWidth(selectedEntry==' '?'_': selectedEntry)/2f), y+5, Lib.COLOUR_I_ImmersiveOrange, true);

fr.drawString(String.valueOf(selectedEntry == ' ' ? '_' : selectedEntry), xx + 9 - (int) Math.floor(fr.getCharWidth(selectedEntry == ' ' ? '_' : selectedEntry) / 2f), y + 5, Lib.COLOUR_I_ImmersiveOrange, true);
}

public boolean keyTyped(char typedChar, int keyCode)
{
if(dropped)
{
if((hasEmpty&&typedChar==' ')||ArrayUtils.contains(DataPacket.varCharacters, typedChar))
{
public boolean keyTyped(char typedChar, int keyCode) {
if (dropped) {
if ((hasEmpty && typedChar == ' ') || ArrayUtils.contains(DataPacket.varCharacters, typedChar)) {
this.selectedEntry = typedChar;
return true;
}
Expand All @@ -181,77 +165,55 @@ public boolean keyTyped(char typedChar, int keyCode)
}

@Override
public boolean mousePressed(Minecraft mc, int mx, int my)
{
if(!(this.enabled&&this.visible))
public boolean mousePressed(Minecraft mc, int mx, int my) {
if (!(this.enabled && this.visible))
return false;

if(buttonNext!=null&&buttonNext.mousePressed(mc, mx, my))
{
selectedEntry = avoidGetter!=null?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, true, hasEmpty, avoidGetter.get()):
if (buttonNext != null && buttonNext.mousePressed(mc, mx, my)) {
selectedEntry = avoidGetter != null ?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, true, hasEmpty, avoidGetter.get()) :
IIUtils.cycleDataPacketChars(selectedEntry, true, hasEmpty);
return true;
}
else if(buttonPrev!=null&&buttonPrev.mousePressed(mc, mx, my))
{
selectedEntry = avoidGetter!=null?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, false, hasEmpty, avoidGetter.get()):
} else if (buttonPrev != null && buttonPrev.mousePressed(mc, mx, my)) {
selectedEntry = avoidGetter != null ?
IIUtils.cyclePacketCharsAvoiding(selectedEntry, false, hasEmpty, avoidGetter.get()) :
IIUtils.cycleDataPacketChars(selectedEntry, false, hasEmpty);
return true;
}
else if(dropped)
{
} else if (dropped) {
FontRenderer fr = ClientUtils.mc().fontRenderer;
int xx = arrows==ArrowsAlignment.LEFT?x+10: x;
if(IIMath.isPointInRectangle(xx+4, y+height+4, xx+4+10*fr.FONT_HEIGHT, y+height+52, mx, my))
{
if(hoveredEntry!='/')
{
int dropdownX = arrows == ArrowsAlignment.LEFT ? x + 10 : x;
int dropdownY = y + height;
if (dropdownPosition == DropdownPosition.RIGHT) {
dropdownX = x + width;
dropdownY = y;
}

if (IIMath.isPointInRectangle(dropdownX + 4, dropdownY + 4, dropdownX + 4 + 10 * fr.FONT_HEIGHT, dropdownY + 52, mx, my)) {
if (hoveredEntry != '/') {
selectedEntry = hoveredEntry;
dropped = false;
}
}
else
} else {
dropped = false;

int yDropDown = y+2+fr.FONT_HEIGHT;
/*
int hh = Math.min(perPage, entries.length)*fr.FONT_HEIGHT;
boolean b = Utils.isPointInRectangle(x, yDropDown, x+width, yDropDown+hh, mx, my);
if(b)
{
int mmY = my-yDropDown;
for(int i = 0; i < Math.min(perPage, entries.length); i++)
if(mmY >= i*fr.FONT_HEIGHT&&mmY < (i+1)*fr.FONT_HEIGHT)
{
selectedEntry = offset+i;
dropped = false;
}
}
else
dropped = false;
*/
return true;
}
else
{
return this.dropped = IIMath.isPointInRectangle(x, y, x+width, y+height, mx, my);
} else {
return this.dropped = IIMath.isPointInRectangle(x, y, x + width, y + height, mx, my);
}
}

public void setAvoidGetter(Supplier<DataPacket> avoidGetter)
{
public void setAvoidGetter(Supplier<DataPacket> avoidGetter) {
this.avoidGetter = avoidGetter;
}

/**
* Determines on which side the arrows will be placed (if NONE, no arrows will be displayed)
*/
public enum ArrowsAlignment
{
public enum ArrowsAlignment {
LEFT,
RIGHT,
NONE
}
}

public enum DropdownPosition {
BELOW,
RIGHT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pl.pabilo8.immersiveintelligence.client.gui.elements.buttons.GuiButtonDataLetterList.ArrowsAlignment;
import pl.pabilo8.immersiveintelligence.client.gui.elements.buttons.GuiButtonDataLetterList;
import pl.pabilo8.immersiveintelligence.client.gui.elements.buttons.GuiButtonDataLetterList.DropdownPosition;
import pl.pabilo8.immersiveintelligence.common.util.IIReference;

/**
Expand All @@ -30,7 +31,7 @@ public void init()
{
super.init();

this.buttonVariable = addButton(new GuiButtonDataLetterList(buttonList.size(), x+width-130, y+25, false, c, ArrowsAlignment.LEFT));
this.buttonVariable = addButton(new GuiButtonDataLetterList(buttonList.size(), x+width-130, y+25, false, c, ArrowsAlignment.LEFT, DropdownPosition.RIGHT));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
/**
* @author Pabilo8
* @since 07.09.2021
* @author Avalon
* @since 19.12.2024
*/
public class GuiDataEditorExpression extends GuiDataEditor<DataTypeExpression>
{
Expand Down Expand Up @@ -88,10 +90,9 @@ public void init()
if(page==0)
{
//add the lower-placed buttons first, so rendering (lack of) order is happy
dropdownLetterPicker = addButton(new GuiButtonDataLetterList(buttonList.size(), x+2, y+2+24+14, true, dataType.getRequiredVariable(), ArrowsAlignment.RIGHT));
dropdownLetterPicker = addButton(new GuiButtonDataLetterList(buttonList.size(), x+2, y+2+24+14, true, dataType.getRequiredVariable(), ArrowsAlignment.LEFT, GuiButtonDataLetterList.DropdownPosition.RIGHT));

dropdownOperationPicker = addButton(new GuiButtonDropdownList(buttonList.size(), x+2, y+14, width-4, 20, 4, operations.toArray(new String[0])))
.setTranslationFunc(s -> I18n.format(IIReference.DATA_KEY+"function."+s));
dropdownOperationPicker = addButton(new GuiButtonDropdownList(buttonList.size(), x+2, y+14, width-4, 20, 4, operations.toArray(new String[0])));
dropdownOperationPicker.selectedEntry = operations.indexOf(dataType.getMeta().name());
dropdownOperationPicker.enabled = !operations.isEmpty();
}
Expand Down

0 comments on commit 40af521

Please sign in to comment.