use of net.malisis.core.client.gui.component.container.BasicList in project Almura by AlmuraDev.
the class StoreScreen method construct.
@Override
public void construct() {
guiscreenBackground = false;
final BasicForm form = new BasicForm(this, 257, 300, this.store.getName());
form.setBackgroundAlpha(255);
final BasicContainer<?> storeContainer = new BasicContainer<>(this, 251, UIComponent.INHERITED);
storeContainer.setBorder(FontColors.WHITE, 1, 185);
storeContainer.setPadding(3);
storeContainer.setColor(0);
// Buy tab
final int leftOffset = storeContainer.getLeftPadding() - storeContainer.getLeftBorderSize();
this.buyTabContainer = new BasicContainer<>(this, this.tabWidth, this.tabHeight);
this.buyTabContainer.setBorders(FontColors.WHITE, 185, 1, 1, 1, 0);
this.buyTabContainer.setPosition(2, 2);
this.buyTabContainer.setColor(defaultTabColor);
this.buyTabContainer.attachData(SideType.BUY);
// Buy tab label
this.buyTabLabel = new UILabel(this, I18n.format("almura.feature.common.button.buy"));
this.buyTabLabel.setPosition(0, 1, Anchor.MIDDLE | Anchor.CENTER);
// Always use the same data as their parent
this.buyTabLabel.attachData(this.buyTabContainer.getData());
this.buyTabContainer.add(this.buyTabLabel);
// Sell tab
this.sellTabContainer = new BasicContainer<>(this, this.tabWidth, this.tabHeight);
this.sellTabContainer.setBorders(FontColors.WHITE, 185, 1, 1, 1, 0);
this.sellTabContainer.setColor(defaultTabColor);
this.sellTabContainer.setPosition(-2, 2, Anchor.TOP | Anchor.RIGHT);
this.sellTabContainer.attachData(SideType.SELL);
// Sell tab label
this.sellTabLabel = new UILabel(this, I18n.format("almura.feature.common.button.sell"));
this.sellTabLabel.setPosition(0, 1, Anchor.MIDDLE | Anchor.CENTER);
// Always use the same data as their parent
this.sellTabLabel.attachData(this.sellTabContainer.getData());
this.sellTabContainer.add(this.sellTabLabel);
// Doesn't exist.
this.thisDoesNotExistLine = new BasicLine(this, this.tabWidth - 2);
this.thisDoesNotExistLine.setBackgroundAlpha(255);
this.thisDoesNotExistLine.setColor(selectedTabColor);
// Bottom tab line
final BasicLine tabContainerLineBottom = new BasicLine(this, storeContainer.getWidth() - (storeContainer.getLeftBorderSize() + storeContainer.getRightBorderSize()), 1);
tabContainerLineBottom.setPosition(-leftOffset, BasicScreen.getPaddedY(this.buyTabContainer, 0));
// Search Y
final int searchY = BasicScreen.getPaddedY(tabContainerLineBottom, 2);
// Item Display Name Search Label
final UILabel itemSearchLabel = new UILabel(this, I18n.format("almura.feature.exchange.text.item_name") + ":");
itemSearchLabel.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).build());
itemSearchLabel.setPosition(1, searchY + 3, Anchor.LEFT | Anchor.TOP);
// Item Display Name Search Text Box
this.itemDisplayNameSearchBox = new BasicTextBox(this, "");
this.itemDisplayNameSearchBox.setAcceptsReturn(false);
this.itemDisplayNameSearchBox.setAcceptsTab(false);
this.itemDisplayNameSearchBox.setTabIndex(0);
this.itemDisplayNameSearchBox.setOnEnter((tb) -> this.search());
this.itemDisplayNameSearchBox.setSize(60, 0);
this.itemDisplayNameSearchBox.setPosition(BasicScreen.getPaddedX(itemSearchLabel, innerPadding), searchY + 1, Anchor.LEFT | Anchor.TOP);
this.itemDisplayNameSearchBox.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
// Sort combobox
this.comboBoxSortType = new UISelect<>(this, 78);
this.comboBoxSortType.setPosition(BasicScreen.getPaddedX(this.itemDisplayNameSearchBox, innerPadding), searchY + 1);
this.comboBoxSortType.setOptions(Arrays.asList(FeatureSortTypes.ITEM_DISPLAY_NAME_ASC, FeatureSortTypes.ITEM_DISPLAY_NAME_DESC, FeatureSortTypes.PRICE_ASC, FeatureSortTypes.PRICE_DESC));
this.comboBoxSortType.setOptionsWidth(UISelect.LONGEST_OPTION);
// Because that's reasonable.
this.comboBoxSortType.setLabelFunction(type -> type == null ? "" : type.getName());
this.comboBoxSortType.select(FeatureSortTypes.ITEM_DISPLAY_NAME_ASC);
// Search button
final UIButton buttonSearch = new UIButtonBuilder(this).width(50).anchor(Anchor.RIGHT | Anchor.TOP).position(0, searchY).text(I18n.format("almura.feature.common.button.search")).onClick(this::search).build("button.search");
// List
this.itemList = new BasicList<>(this, UIComponent.INHERITED, BasicScreen.getPaddedHeight(form) - this.buyTabContainer.getHeight() - tabContainerLineBottom.getHeight() - buttonSearch.getHeight() - 30);
this.itemList.setPosition(0, BasicScreen.getPaddedY(buttonSearch, 2));
this.itemList.setSelectConsumer(i -> this.updateStoreControls());
this.itemList.setItemComponentSpacing(1);
this.itemList.setBorder(FontColors.WHITE, 1, 185);
this.itemList.setPadding(2);
this.itemList.setItemComponentFactory(StoreItemComponent::new);
this.buttonTransactOne = new UIButtonBuilder(this).width(60).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(() -> this.transact(1)).build("button.transact.single");
this.buttonTransactStack = new UIButtonBuilder(this).width(60).x(BasicScreen.getPaddedX(this.buttonTransactOne, 2)).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(() -> {
if (this.itemList.getSelectedItem() == null) {
return;
}
final int value = this.itemList.getSelectedItem().asRealStack().getMaxStackSize();
this.transact(value);
}).build("button.transact.stack");
this.buttonTransactAll = new UIButtonBuilder(this).width(60).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(() -> {
final StoreItem selectedItem = this.itemList.getSelectedItem();
if (selectedItem == null) {
return;
}
// Determine the value to transact
final int value;
if (this.currentSide == SideType.BUY) {
// If we are buying then base the value on the quantity remaining for the item to purchase
value = this.itemList.getSelectedItem().getQuantity();
} else {
// If we're selling then base it on how many we have in our main inventory
value = Minecraft.getMinecraft().player.inventory.mainInventory.stream().filter(i -> ItemStack.areItemsEqual(i, selectedItem.asRealStack())).mapToInt(ItemStack::getCount).sum();
}
this.transact(value);
}).build("button.transact.all");
this.buttonTransactQuantity = new UIButtonBuilder(this).width(60).x(BasicScreen.getPaddedX(this.buttonTransactAll, 2, Anchor.RIGHT)).anchor(Anchor.BOTTOM | Anchor.RIGHT).enabled(false).onClick(() -> {
final StoreItem selectedItem = this.itemList.getSelectedItem();
if (selectedItem == null) {
return;
}
new StoreTransactQuantityScreen(this, this.store, selectedItem, this.currentSide).display();
}).build("button.transact.quantity");
storeContainer.add(this.buyTabContainer, this.sellTabContainer, tabContainerLineBottom, this.thisDoesNotExistLine, itemSearchLabel, this.itemDisplayNameSearchBox, this.comboBoxSortType, buttonSearch, this.itemList, this.buttonTransactOne, this.buttonTransactStack, this.buttonTransactQuantity, this.buttonTransactAll);
form.add(storeContainer);
// Logic for admin pane
if (this.isAdmin) {
// Adjust form width
form.setWidth(form.getWidth() + 224);
// Create admin pane
final BasicContainer<?> adminContainer = new BasicContainer(this, 220, UIComponent.INHERITED);
adminContainer.setPosition(BasicScreen.getPaddedX(storeContainer, 4), 0);
adminContainer.setBorder(FontColors.WHITE, 1, 185);
adminContainer.setPadding(3);
adminContainer.setColor(0);
// Buy tab label
this.typeLabel = new UILabel(this, TextFormatting.WHITE + "Type: ");
this.typeLabel.setPosition(0, 2, Anchor.TOP | Anchor.LEFT);
// Item location selection
this.locationSelect = new UISelect<>(this, UIComponent.INHERITED);
this.locationSelect.setOptions(itemFinderRelationshipMap.keySet());
this.locationSelect.setLabelFunction(o -> I18n.format(o.translationKey));
this.locationSelect.setPosition(30, 0);
this.locationSelect.setSize(184, 12);
this.locationSelect.maxDisplayedOptions(24);
this.locationSelect.register(this);
// Search text box
this.adminSearchTextBox = new BasicTextBox(this, "");
this.adminSearchTextBox.setSize(UIComponent.INHERITED, this.locationSelect.getHeight());
this.adminSearchTextBox.setPosition(0, BasicScreen.getPaddedY(this.locationSelect, 2));
this.adminSearchTextBox.register(this);
// Item list
this.adminItemList = new BasicList<>(this, UIComponent.INHERITED, BasicScreen.getPaddedHeight(form) - this.locationSelect.getHeight() - this.adminSearchTextBox.getHeight() - 28);
this.adminItemList.setItemComponentFactory(AdminItemComponent::new);
this.adminItemList.setItemComponentSpacing(1);
this.adminItemList.setPosition(0, BasicScreen.getPaddedY(this.adminSearchTextBox, 2));
this.adminItemList.setPadding(2);
this.adminItemList.setBorder(FontColors.WHITE, 1, 185);
this.adminItemList.setSelectConsumer(i -> this.updateAdminControls());
this.buttonAdminList = new UIButtonBuilder(this).width(50).anchor(Anchor.BOTTOM | Anchor.LEFT).enabled(false).onClick(this::listOrModify).text(I18n.format("almura.feature.common.button.list")).build("button.list");
this.buttonAdminUnlist = new UIButtonBuilder(this).width(50).anchor(Anchor.BOTTOM | Anchor.LEFT).position(BasicScreen.getPaddedX(this.buttonAdminList, 2), 0).enabled(false).onClick(this::unlist).text(I18n.format("almura.feature.common.button.unlist")).build("button.unlist");
this.adminListTotalLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.total") + ": ");
this.adminListTotalLabel.setPosition(0, -2, Anchor.BOTTOM | Anchor.RIGHT);
adminContainer.add(this.typeLabel, this.locationSelect, this.adminSearchTextBox, this.adminItemList, this.buttonAdminList, this.buttonAdminUnlist, this.adminListTotalLabel);
form.add(adminContainer);
// Select the first item
this.locationSelect.selectFirst();
}
addToScreen(form);
}
Aggregations