use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.
the class GuiList method initGui.
@Override
public void initGui() {
super.initGui();
for (int line = 0; line < container.slots.length; line++) {
WidgetListSlot[] arr = container.slots[line];
for (int slot = 0; slot < arr.length; slot++) {
final WidgetListSlot listSlot = arr[slot];
GuiRectangle rectangle = new GuiRectangle(8 + slot * 18, 32 + line * 34, 16, 16);
IGuiArea phantomSlotArea = rectangle.offset(mainGui.rootElement);
mainGui.shownElements.add(listSlot.new GuiElementPhantomSlot(mainGui, phantomSlotArea) {
@Override
protected boolean shouldDrawHighlight() {
if (listSlot.slotIndex == 0) {
return true;
}
return !GuiList.this.container.lines[listSlot.lineIndex].isOneStackMode();
}
@Override
public void drawBackground(float partialTicks) {
if (!shouldDrawHighlight()) {
ICON_HIGHLIGHT.drawAt(this);
}
}
@Nonnull
@Override
public ItemStack getStack() {
if (shouldDrawHighlight()) {
return super.getStack();
} else {
NonNullList<ItemStack> data = GuiList.this.getExamplesList(listSlot.lineIndex, container.lines[listSlot.lineIndex].getSortingType());
if (data.size() >= listSlot.slotIndex) {
return data.get(listSlot.slotIndex - 1);
} else {
return StackUtil.EMPTY;
}
}
}
@Override
public void onMouseClicked(int button) {
super.onMouseClicked(button);
if (contains(gui.mouse)) {
clearExamplesCache(listSlot.lineIndex);
}
}
});
}
}
buttonList.clear();
for (int sy = 0; sy < ListHandler.HEIGHT; sy++) {
int bOff = sy * BUTTON_COUNT;
int bOffX = this.guiLeft + 8 + ListHandler.WIDTH * 18 - BUTTON_COUNT * 11;
int bOffY = this.guiTop + 32 + sy * 34 + 18;
GuiImageButton buttonPrecise = new GuiImageButton(mainGui, bOff + 0, bOffX, bOffY, 11, TEXTURE_BASE, 176, 16, 176, 28);
buttonPrecise.setToolTip(ToolTip.createLocalized("gui.list.nbt"));
buttonPrecise.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonPrecise);
GuiImageButton buttonType = new GuiImageButton(mainGui, bOff + 1, bOffX + 11, bOffY, 11, TEXTURE_BASE, 176, 16, 185, 28);
buttonType.setToolTip(ToolTip.createLocalized("gui.list.metadata"));
buttonType.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonType);
GuiImageButton buttonMaterial = new GuiImageButton(mainGui, bOff + 2, bOffX + 22, bOffY, 11, TEXTURE_BASE, 176, 16, 194, 28);
buttonMaterial.setToolTip(ToolTip.createLocalized("gui.list.oredict"));
buttonMaterial.setBehaviour(IButtonBehaviour.TOGGLE);
mainGui.shownElements.add(buttonMaterial);
}
for (IGuiElement elem : mainGui.shownElements) {
if (elem instanceof GuiImageButton) {
GuiImageButton b = (GuiImageButton) elem;
int id = Integer.parseInt(b.id);
int lineId = id / BUTTON_COUNT;
int buttonId = id % BUTTON_COUNT;
if (container.lines[lineId].getOption(buttonId)) {
b.activate();
}
b.registerListener(this);
}
}
textField = new GuiTextField(6, this.fontRenderer, guiLeft + 10, guiTop + 10, 156, 12);
textField.setMaxStringLength(32);
textField.setText(BCCoreItems.list.getName(container.getListItemStack()));
textField.setFocused(false);
}
use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.
the class BuildCraftJsonGui method load.
public final void load() {
ResourceLoaderContext loadHistory = new ResourceLoaderContext();
try (InputStreamReader reader = loadHistory.startLoading(jsonGuiDefinition)) {
JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
JsonGuiInfo info = new JsonGuiInfo(obj, context, loadHistory);
sizeX = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeX, context).evaluate();
sizeY = (int) GenericExpressionCompiler.compileExpressionLong(info.sizeY, context).evaluate();
varData.setNodes(info.createTickableNodes());
for (JsonGuiElement elem : info.elements) {
String typeName = elem.properties.get("type");
ElementType type = JsonGuiTypeRegistry.TYPES.get(typeName);
if (type == null) {
BCLog.logger.warn("Unknown type " + typeName);
} else {
IGuiElement e = type.deserialize(this, rootElement, info, elem);
String parent = elem.properties.get("parent");
IContainingElement p = properties.get("custom." + parent, IContainingElement.class);
properties.put("custom." + elem.name, e);
if (p == null) {
shownElements.add(e);
} else {
p.getChildElements().add(e);
p.calculateSizes();
}
}
}
} catch (InvalidExpressionException iee) {
throw new JsonSyntaxException("Failed to resolve the size of " + jsonGuiDefinition, iee);
} catch (IOException e) {
throw new Error(e);
}
loadHistory.finishLoading();
}
use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.
the class GuiElementStatementDrag method onMouseClicked.
// IInteractableElement
@Override
public void onMouseClicked(int button) {
if (button != 1) {
return;
}
for (IGuiElement element : gui.getElementsAt(gui.mouse.getX(), gui.mouse.getY())) {
if (element instanceof IReference<?>) {
IReference<?> ref = (IReference<?>) element;
Object obj = ref.get();
if (obj == null || obj instanceof IGuiSlot) {
startDragging((IGuiSlot) obj);
break;
}
}
}
}
use of buildcraft.lib.gui.IGuiElement in project BuildCraft by BuildCraft.
the class GuiElementStatementDrag method onMouseReleased.
@Override
public void onMouseReleased(int button) {
if (!isDragging) {
return;
}
for (IGuiElement element : gui.getElementsAt(gui.mouse.getX(), gui.mouse.getY())) {
if (element instanceof IReference<?>) {
IReference<?> ref = (IReference<?>) element;
ref.setIfCan(dragging);
}
}
isDragging = false;
dragging = null;
if (gui.currentMenu == this) {
gui.currentMenu = null;
}
}
Aggregations