Search in sources :

Example 6 with TableCell

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);
}
Also used : TitledCell(ivorius.reccomplex.gui.table.cell.TitledCell) IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) TableDataSourceMazePathList(ivorius.reccomplex.gui.worldscripts.mazegenerator.TableDataSourceMazePathList) TableCellTitle(ivorius.reccomplex.gui.table.cell.TableCellTitle) TableCell(ivorius.reccomplex.gui.table.cell.TableCell) ivorius.reccomplex.world.gen.feature.structure.generic.maze(ivorius.reccomplex.world.gen.feature.structure.generic.maze) GuiTable(ivorius.reccomplex.gui.table.GuiTable) TableCellBoolean(ivorius.reccomplex.gui.table.cell.TableCellBoolean) TableDataSourceSegmented(ivorius.reccomplex.gui.table.datasource.TableDataSourceSegmented) TextFormatting(net.minecraft.util.text.TextFormatting) Set(java.util.Set) TableDataSourcePreloaded(ivorius.reccomplex.gui.table.datasource.TableDataSourcePreloaded) Selection(ivorius.reccomplex.world.gen.feature.structure.generic.Selection) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) TitledCell(ivorius.reccomplex.gui.table.cell.TitledCell) List(java.util.List) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) MazeRuleConnectAll(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.saved.MazeRuleConnectAll) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) TableCellBoolean(ivorius.reccomplex.gui.table.cell.TableCellBoolean) Set(java.util.Set) TableCellTitle(ivorius.reccomplex.gui.table.cell.TableCellTitle) TableDataSourceMazePathList(ivorius.reccomplex.gui.worldscripts.mazegenerator.TableDataSourceMazePathList) List(java.util.List)

Example 7 with TableCell

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);
    }
}
Also used : TableCell(ivorius.reccomplex.gui.table.cell.TableCell) GuiButton(net.minecraft.client.gui.GuiButton)

Aggregations

TableCell (ivorius.reccomplex.gui.table.cell.TableCell)7 IvTranslations (ivorius.ivtoolkit.tools.IvTranslations)5 TitledCell (ivorius.reccomplex.gui.table.cell.TitledCell)5 TableDataSourceSegmented (ivorius.reccomplex.gui.table.datasource.TableDataSourceSegmented)5 Nonnull (javax.annotation.Nonnull)4 TableDataSourceExpression (ivorius.reccomplex.gui.TableDataSourceExpression)3 ivorius.reccomplex.gui.table (ivorius.reccomplex.gui.table)3 GuiTable (ivorius.reccomplex.gui.table.GuiTable)2 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)2 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)2 TableCellBoolean (ivorius.reccomplex.gui.table.cell.TableCellBoolean)2 TableCellString (ivorius.reccomplex.gui.table.cell.TableCellString)2 Directions (ivorius.ivtoolkit.blocks.Directions)1 FloatRange (ivorius.ivtoolkit.gui.FloatRange)1 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)1 GuiValidityStateIndicator (ivorius.reccomplex.gui.GuiValidityStateIndicator)1 RCGuiHandler (ivorius.reccomplex.gui.RCGuiHandler)1 RCGuiTables (ivorius.reccomplex.gui.RCGuiTables)1 TableDataSourceBlockPos (ivorius.reccomplex.gui.TableDataSourceBlockPos)1 TableDirections (ivorius.reccomplex.gui.TableDirections)1