Search in sources :

Example 6 with WTable

use of mathax.client.gui.widgets.containers.WTable in project Client by MatHax.

the class LeftRightListSettingScreen method initWidgets.

private void initWidgets(Registry<T> registry) {
    // Left (all)
    WTable left = abc(pairs -> registry.forEach(t -> {
        if (skipValue(t) || collection.contains(t))
            return;
        int words = Utils.search(getValueName(t), filterText);
        if (words > 0)
            pairs.add(new Pair<>(t, words));
    }), true, t -> {
        addValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            addValue(registry, v);
    });
    if (left.cells.size() > 0)
        table.add(theme.verticalSeparator()).expandWidgetY();
    // Right (selected)
    abc(pairs -> {
        for (T value : collection) {
            if (skipValue(value))
                continue;
            int words = Utils.search(getValueName(value), filterText);
            if (words > 0)
                pairs.add(new Pair<>(value, words));
        }
    }, false, t -> {
        removeValue(registry, t);
        T v = getAdditionalValue(t);
        if (v != null)
            removeValue(registry, v);
    });
}
Also used : Utils(mathax.client.utils.Utils) Pair(net.minecraft.util.Pair) GuiTheme(mathax.client.gui.GuiTheme) Collection(java.util.Collection) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Cell(mathax.client.gui.utils.Cell) WTable(mathax.client.gui.widgets.containers.WTable) List(java.util.List) Setting(mathax.client.settings.Setting) WTextBox(mathax.client.gui.widgets.input.WTextBox) WPressable(mathax.client.gui.widgets.pressable.WPressable) Comparator(java.util.Comparator) WindowScreen(mathax.client.gui.WindowScreen) WWidget(mathax.client.gui.widgets.WWidget) WTable(mathax.client.gui.widgets.containers.WTable) Pair(net.minecraft.util.Pair)

Example 7 with WTable

use of mathax.client.gui.widgets.containers.WTable in project Client by MatHax.

the class PotionSettingScreen method initWidgets.

@Override
public void initWidgets() {
    WTable table = add(theme.table()).expandX().widget();
    for (MyPotion potion : MyPotion.values()) {
        table.add(theme.itemWithLabel(potion.potion, potion.potion.getName().getString()));
        WButton select = table.add(theme.button("Select")).widget();
        select.action = () -> {
            setting.set(potion);
            close();
        };
        table.row();
    }
}
Also used : WTable(mathax.client.gui.widgets.containers.WTable) WButton(mathax.client.gui.widgets.pressable.WButton) MyPotion(mathax.client.utils.misc.MyPotion)

Example 8 with WTable

use of mathax.client.gui.widgets.containers.WTable in project Client by MatHax.

the class ServerFinderScreen method initWidgets.

@Override
public void initWidgets() {
    add(theme.label("This will search for servers with similar IPs"));
    add(theme.label("to the IP you type into the field below."));
    add(theme.label("The servers it finds will be added to your server list."));
    WTable table = add(new WTable()).expandX().widget();
    table.add(theme.label("Server address:"));
    table.add(ipBox).expandX();
    table.row();
    table.add(theme.label("Max. Threads:"));
    table.add(maxThreadsBox);
    table.row();
    table.add(theme.label("Scan ports"));
    table.add(scanPortsBox);
    table.row();
    table.add(theme.label("Versions:"));
    table.add(versionBox).expandX();
    add(stateLabel);
    add(checkedLabel);
    add(workingLabel);
    WHorizontalList list = add(theme.horizontalList()).expandX().widget();
    list.add(searchButton).expandX();
    list.add(theme.button("Save")).expandX().widget().action = this::saveToFile;
    searchButton.action = this::searchOrCancel;
}
Also used : WTable(mathax.client.gui.widgets.containers.WTable) WHorizontalList(mathax.client.gui.widgets.containers.WHorizontalList)

Example 9 with WTable

use of mathax.client.gui.widgets.containers.WTable in project Client by MatHax.

the class EditBookTitleAndAuthorScreen method initWidgets.

@Override
public void initWidgets() {
    WTable t = add(theme.table()).expandX().widget();
    t.add(theme.label("Title"));
    WTextBox title = t.add(theme.textBox(itemStack.getOrCreateNbt().getString("title"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.label("Author"));
    WTextBox author = t.add(theme.textBox(itemStack.getNbt().getString("author"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.button("Done")).expandX().widget().action = () -> {
        itemStack.getNbt().putString("author", author.get());
        itemStack.getNbt().putString("title", title.get());
        BookScreen.Contents contents = new BookScreen.WrittenBookContents(itemStack);
        List<String> pages = new ArrayList<>(contents.getPageCount());
        for (int i = 0; i < contents.getPageCount(); i++) pages.add(contents.getPage(i).getString());
        mc.getNetworkHandler().sendPacket(new BookUpdateC2SPacket(hand == Hand.MAIN_HAND ? mc.player.getInventory().selectedSlot : 40, pages, Optional.of(title.get())));
        close();
    };
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) WTable(mathax.client.gui.widgets.containers.WTable) BookScreen(net.minecraft.client.gui.screen.ingame.BookScreen) ArrayList(java.util.ArrayList) WTextBox(mathax.client.gui.widgets.input.WTextBox)

Example 10 with WTable

use of mathax.client.gui.widgets.containers.WTable in project Client by MatHax.

the class LeftRightListSettingScreen method abc.

private WTable abc(Consumer<List<Pair<T, Integer>>> addValues, boolean isLeft, Consumer<T> buttonAction) {
    // Create
    Cell<WTable> cell = this.table.add(theme.table()).top();
    WTable table = cell.widget();
    Consumer<T> forEach = t -> {
        if (!includeValue(t))
            return;
        table.add(getValueWidget(t));
        WPressable button = table.add(isLeft ? theme.plus() : theme.minus()).expandCellX().right().widget();
        button.action = () -> buttonAction.accept(t);
        table.row();
    };
    // Sort
    List<Pair<T, Integer>> values = new ArrayList<>();
    addValues.accept(values);
    if (!filterText.isEmpty())
        values.sort(Comparator.comparingInt(value -> -value.getRight()));
    for (Pair<T, Integer> pair : values) forEach.accept(pair.getLeft());
    if (table.cells.size() > 0)
        cell.expandX();
    return table;
}
Also used : Utils(mathax.client.utils.Utils) Pair(net.minecraft.util.Pair) GuiTheme(mathax.client.gui.GuiTheme) Collection(java.util.Collection) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Cell(mathax.client.gui.utils.Cell) WTable(mathax.client.gui.widgets.containers.WTable) List(java.util.List) Setting(mathax.client.settings.Setting) WTextBox(mathax.client.gui.widgets.input.WTextBox) WPressable(mathax.client.gui.widgets.pressable.WPressable) Comparator(java.util.Comparator) WindowScreen(mathax.client.gui.WindowScreen) WWidget(mathax.client.gui.widgets.WWidget) WPressable(mathax.client.gui.widgets.pressable.WPressable) WTable(mathax.client.gui.widgets.containers.WTable) ArrayList(java.util.ArrayList) Pair(net.minecraft.util.Pair)

Aggregations

WTable (mathax.client.gui.widgets.containers.WTable)14 WTextBox (mathax.client.gui.widgets.input.WTextBox)6 ArrayList (java.util.ArrayList)4 WButton (mathax.client.gui.widgets.pressable.WButton)4 GuiTheme (mathax.client.gui.GuiTheme)3 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 WindowScreen (mathax.client.gui.WindowScreen)2 Cell (mathax.client.gui.utils.Cell)2 WWidget (mathax.client.gui.widgets.WWidget)2 WHorizontalList (mathax.client.gui.widgets.containers.WHorizontalList)2 WPressable (mathax.client.gui.widgets.pressable.WPressable)2 Setting (mathax.client.settings.Setting)2 Utils (mathax.client.utils.Utils)2 Pair (net.minecraft.util.Pair)2 Registry (net.minecraft.util.registry.Registry)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 File (java.io.File)1