use of ivorius.reccomplex.gui.table.cell.TableCell in project RecurrentComplex by Ivorforce.
the class TableDataSourceMazeRuleConnectAll method cellForIndexInSegment.
@Override
public TableCell cellForIndexInSegment(GuiTable table, int index, int segment) {
if (segment == 0) {
TableCellBoolean preventCell = new TableCellBoolean("prevent", rule.preventConnection, TextFormatting.GOLD + IvTranslations.get("reccomplex.mazerule.connect.prevent"), TextFormatting.GREEN + IvTranslations.get("reccomplex.mazerule.connect.prevent"));
preventCell.addPropertyConsumer(val -> rule.preventConnection = val);
return new TitledCell(preventCell);
} else if (segment == 2) {
TableCellBoolean cell = new TableCellBoolean("additive", rule.additive, TextFormatting.GREEN + IvTranslations.get("reccomplex.mazerule.connectall.additive"), TextFormatting.GOLD + IvTranslations.get("reccomplex.mazerule.connectall.subtractive"));
cell.addPropertyConsumer(val -> {
rule.additive = val;
tableDelegate.reloadData();
});
return new TitledCell(cell);
} else if (segment == 4) {
return new TitledCell(new TableCellTitle("", IvTranslations.get("reccomplex.mazerule.connectall.preview")));
} else if (segment == 5) {
ConnectorFactory factory = new ConnectorFactory();
Set<Connector> blockedConnections = Collections.singleton(factory.get(ConnectorStrategy.DEFAULT_WALL));
List<SavedMazePath> exitPaths = MazeRuleConnectAll.getPaths(rule.exits, expected, blockedConnections, factory).collect(Collectors.toList());
return new TitledCell(new TableCellTitle("", exitPaths.get(index).toString()));
}
return super.cellForIndexInSegment(table, index, segment);
}
use of ivorius.reccomplex.gui.table.cell.TableCell in project RecurrentComplex by Ivorforce.
the class GuiTable method initGui.
public void initGui() {
buttonMap.clear();
for (TableCell cell : currentCells) cell.setHidden(true);
currentCells.clear();
////////
int numberOfCells = dataSource.numberOfCells();
int supportedSlotNumber = tableBounds.getHeight() / HEIGHT_PER_SLOT;
if (firstTime) {
if (supportedSlotNumber > numberOfCells && allowsNegativeScroll && startCentered)
// Scroll to the middle
currentScroll = (getMinScroll() + getMaxScroll()) / 2;
firstTime = false;
} else
// If we're too far down we scroll up now
updateScrollUpwards(0);
int roundedScrollIndex = MathHelper.floor(currentScroll + 0.5f);
scrollUpButton = new GuiButton(-1, tableBounds.getMaxX() + SCROLL_BAR_MARGIN, tableBounds.getMinY(), SCROLL_BAR_WIDTH - SCROLL_BAR_MARGIN, 20, TextFormatting.BOLD + "↑");
delegate.addButtonToTable(scrollUpButton);
scrollDownButton = new GuiButton(-1, tableBounds.getMaxX() + SCROLL_BAR_MARGIN, tableBounds.getMaxY() - 20, SCROLL_BAR_WIDTH - SCROLL_BAR_MARGIN, 20, TextFormatting.BOLD + "↓");
delegate.addButtonToTable(scrollDownButton);
boolean needsUpScroll = canScrollUp(numberOfCells);
boolean needsDownScroll = canScrollDown(numberOfCells);
scrollUpButton.enabled = needsUpScroll;
scrollDownButton.enabled = needsDownScroll;
showsScrollBar = needsUpScroll || needsDownScroll || !hideScrollbarIfUnnecessary;
scrollUpButton.visible = showsScrollBar;
scrollDownButton.visible = showsScrollBar;
int baseY = tableBounds.getMinY() + (tableBounds.getHeight() - (!allowsNegativeScroll && startCentered ? Math.min(numberOfCells, supportedSlotNumber) : supportedSlotNumber) * HEIGHT_PER_SLOT) / 2;
for (int index = 0; index < supportedSlotNumber && roundedScrollIndex + index < numberOfCells; index++) {
int cellIndex = roundedScrollIndex + index;
if (cellIndex < 0)
continue;
TableCell cell = cachedCells.get(cellIndex);
boolean initCell = cell == null;
if (initCell)
cell = dataSource.cellForIndex(this, cellIndex);
if (cell == null)
throw new NullPointerException("Cell not initialized: at " + cellIndex);
int cellY = index * HEIGHT_PER_SLOT + 1;
cell.setBounds(Bounds.fromAxes(tableBounds.getMinX(), tableBounds.getWidth(), baseY + cellY, HEIGHT_PER_SLOT - 2));
cell.setHidden(false);
cell.initGui(this);
if (initCell)
cachedCells.put(cellIndex, cell);
currentCells.add(cell);
}
}
Aggregations