use of net.malisis.core.client.gui.component.decoration.BasicLine in project Almura by AlmuraDev.
the class ExchangeScreen method construct.
@Override
public void construct() {
guiscreenBackground = false;
// Detect if screen area is large enough to display.
if (minScreenWidth > this.resolution.getScaledWidth() || minScreenHeight > this.resolution.getScaledHeight()) {
notificationManager.handlePopup(new PopupNotification("Exchange Error", "Screen area of: " + minScreenHeight + " x " + minScreenWidth + " required.", 5));
this.close();
return;
}
// Main Panel
final BasicForm form = new BasicForm(this, minScreenWidth, minScreenHeight, this.getExchange().getName());
// Search section
final BasicContainer<?> searchContainer = new BasicContainer<>(this, 295, 322);
searchContainer.setPosition(0, 0, Anchor.LEFT | Anchor.TOP);
searchContainer.setColor(0);
searchContainer.setBorder(FontColors.WHITE, 1, 185);
searchContainer.setBackgroundAlpha(215);
searchContainer.setPadding(3, 3);
final UILabel itemSearchLabel = new UILabel(this, I18n.format("almura.feature.exchange.text.item_name") + ":");
itemSearchLabel.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).scale(1.1F).build());
itemSearchLabel.setPosition(0, 4, Anchor.LEFT | Anchor.TOP);
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(145, 0);
this.itemDisplayNameSearchBox.setPosition(itemSearchLabel.getWidth() + innerPadding, 2, Anchor.LEFT | Anchor.TOP);
this.itemDisplayNameSearchBox.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
final UILabel sellerSearchLabel = new UILabel(this, I18n.format("almura.feature.exchange.text.seller") + ":");
sellerSearchLabel.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).scale(1.1F).build());
sellerSearchLabel.setPosition(itemDisplayNameSearchBox.getX() - sellerSearchLabel.getWidth() - 1, getPaddedY(itemSearchLabel, 7), Anchor.LEFT | Anchor.TOP);
this.sellerSearchTextBox = new BasicTextBox(this, "");
this.sellerSearchTextBox.setAcceptsReturn(false);
this.sellerSearchTextBox.setAcceptsTab(false);
this.sellerSearchTextBox.setTabIndex(1);
this.sellerSearchTextBox.setOnEnter(tb -> this.search());
this.sellerSearchTextBox.setSize(145, 0);
this.sellerSearchTextBox.setPosition(this.itemDisplayNameSearchBox.getX(), getPaddedY(this.itemDisplayNameSearchBox, 4), Anchor.LEFT | Anchor.TOP);
this.sellerSearchTextBox.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
// Sort combobox
// Sort combobox
this.comboBoxSortType = new UISelect<>(this, 78);
this.comboBoxSortType.setOptions(Arrays.asList(FeatureSortTypes.CREATED_ASC, FeatureSortTypes.CREATED_DESC, FeatureSortTypes.PRICE_ASC, FeatureSortTypes.PRICE_DESC, FeatureSortTypes.ITEM_DISPLAY_NAME_ASC, FeatureSortTypes.ITEM_DISPLAY_NAME_DESC, ExchangeSortTypes.SELLER_NAME_ASC, ExchangeSortTypes.SELLER_NAME_DESC));
// Because that's reasonable.
this.comboBoxSortType.setLabelFunction(type -> type == null ? "" : type.getName());
this.comboBoxSortType.select(FeatureSortTypes.CREATED_ASC);
this.comboBoxSortType.setPosition(-(innerPadding + 1), 2, Anchor.RIGHT | Anchor.TOP);
// Search button
final UIButton buttonSearch = new UIButtonBuilder(this).width(80).anchor(Anchor.RIGHT | Anchor.TOP).position(-innerPadding, this.sellerSearchTextBox.getY() - 1).text(I18n.format("almura.feature.common.button.search")).onClick(this::search).build("button.search");
// Separator
final BasicContainer<?> forSaleTopLine = new BasicContainer<>(this, searchContainer.getRawWidth() - 2, 1);
forSaleTopLine.setColor(FontColors.WHITE);
forSaleTopLine.setBackgroundAlpha(185);
forSaleTopLine.setPosition(0, BasicScreen.getPaddedY(this.sellerSearchTextBox, 4), Anchor.CENTER | Anchor.TOP);
this.forSaleList = new BasicList<>(this, UIComponent.INHERITED, 254);
this.forSaleList.setPosition(0, BasicScreen.getPaddedY(forSaleTopLine, 2));
this.forSaleList.setItemComponentFactory(ForSaleItemComponent::new);
this.forSaleList.setItemComponentSpacing(1);
this.forSaleList.setSelectConsumer((i) -> this.updateControls());
// No results label
this.noResultsLabel = new UILabel(this, "No results found.");
this.noResultsLabel.setPosition(0, this.forSaleList.getY() + 8, Anchor.TOP | Anchor.CENTER);
this.noResultsLabel.setFontOptions(FontColors.GRAY_FO);
this.noResultsLabel.setVisible(false);
// Bottom Page Control - first button
this.buttonFirstPage = new UIButtonBuilder(this).size(20).anchor(Anchor.LEFT | Anchor.BOTTOM).position(0, 0).text("|<").enabled(false).onClick(() -> setPage(1)).build("button.first");
// Bottom Page Control - previous button
this.buttonPreviousPage = new UIButtonBuilder(this).size(20).anchor(Anchor.LEFT | Anchor.BOTTOM).position(getPaddedX(this.buttonFirstPage, innerPadding), 0).text("<").enabled(false).onClick(() -> setPage(--this.currentPage)).build("button.previous");
// Search pages label
this.labelSearchPage = new UILabel(this, "");
this.labelSearchPage.setPosition(0, -4, Anchor.CENTER | Anchor.BOTTOM);
// Bottom Page Control - last button
this.buttonLastPage = new UIButtonBuilder(this).size(20).anchor(Anchor.RIGHT | Anchor.BOTTOM).position(0, 0).text(">|").enabled(false).onClick(() -> setPage(this.pages)).build("button.last");
// Bottom Page Control - next button
this.buttonNextPage = new UIButtonBuilder(this).size(20).anchor(Anchor.RIGHT | Anchor.BOTTOM).position(getPaddedX(this.buttonLastPage, innerPadding, Anchor.RIGHT), 0).text(">").enabled(false).onClick(() -> setPage(++this.currentPage)).build("button.next");
// Separator
final BasicLine forSaleBottomLine = new BasicLine(this, searchContainer.getRawWidth() - 2);
forSaleBottomLine.setPosition(0, BasicScreen.getPaddedY(this.buttonFirstPage, 2, Anchor.BOTTOM), Anchor.CENTER | Anchor.BOTTOM);
// Add Elements of Search Area
searchContainer.add(itemSearchLabel, this.itemDisplayNameSearchBox, sellerSearchLabel, this.sellerSearchTextBox, buttonSearch, this.comboBoxSortType, this.buttonFirstPage, this.buttonPreviousPage, this.buttonNextPage, this.buttonLastPage, this.forSaleList, this.noResultsLabel, this.labelSearchPage, forSaleTopLine, forSaleBottomLine);
// Buy container
final BasicContainer<?> buyContainer = new BasicContainer(this, 295, 21);
buyContainer.setPosition(0, getPaddedY(searchContainer, innerPadding), Anchor.LEFT | Anchor.TOP);
buyContainer.setColor(0);
buyContainer.setBorder(FontColors.WHITE, 1, 185);
buyContainer.setBackgroundAlpha(215);
buyContainer.setPadding(3, 0);
this.buttonBuyOne = new UIButtonBuilder(this).width(60).anchor(Anchor.LEFT | Anchor.MIDDLE).position(0, 0).text(I18n.format("almura.feature.common.button.buy.one")).enabled(false).onClick(() -> this.buy(1)).build("button.buy.single");
this.buttonBuyStack = new UIButtonBuilder(this).width(60).anchor(Anchor.LEFT | Anchor.MIDDLE).position(BasicScreen.getPaddedX(this.buttonBuyOne, 10), 0).text(I18n.format("almura.feature.common.button.buy.stack", 0)).enabled(false).onClick(() -> {
final ForSaleItem forSaleItem = this.forSaleList.getSelectedItem();
if (forSaleItem != null) {
this.buy(forSaleItem.asRealStack().getMaxStackSize());
}
}).build("button.buy.stack");
this.buttonBuyAll = new UIButtonBuilder(this).width(50).anchor(Anchor.RIGHT | Anchor.MIDDLE).position(0, 0).text(I18n.format("almura.feature.common.button.buy.all")).enabled(false).onClick(() -> {
final ForSaleItem forSaleItem = this.forSaleList.getSelectedItem();
if (forSaleItem != null) {
this.buy(forSaleItem.getQuantity());
}
}).build("button.buy.all");
this.buttonBuyQuantity = new UIButtonBuilder(this).width(60).anchor(Anchor.RIGHT | Anchor.MIDDLE).position(BasicScreen.getPaddedX(this.buttonBuyAll, 10, Anchor.RIGHT), 0).text(I18n.format("almura.feature.common.button.buy.quantity")).enabled(false).onClick(() -> {
final ForSaleItem forSaleItem = this.forSaleList.getSelectedItem();
if (forSaleItem != null) {
new ExchangeBuyQuantityScreen(this, this.axs, forSaleItem).display();
}
}).build("button.buy.quantity");
buyContainer.add(this.buttonBuyOne, this.buttonBuyStack, this.buttonBuyQuantity, this.buttonBuyAll);
// Listable Items section
final BasicContainer<?> listableItemsContainer = new BasicContainer(this, 295, 345);
listableItemsContainer.setPosition(0, 0, Anchor.RIGHT | Anchor.TOP);
listableItemsContainer.setBorder(FontColors.WHITE, 1, 185);
listableItemsContainer.setColor(0);
listableItemsContainer.setBackgroundAlpha(215);
listableItemsContainer.setPadding(3, 3);
final UILabel listableItemsLabel = new UILabel(this, I18n.format("almura.feature.exchange.title.listable_items"));
listableItemsLabel.setPosition(0, 2, Anchor.CENTER | Anchor.TOP);
listableItemsLabel.setFontOptions(FontColors.WHITE_FO);
final BasicLine listTopLine = new BasicLine(this, listableItemsContainer.getRawWidth() - 2);
listTopLine.setPosition(0, BasicScreen.getPaddedY(listableItemsLabel, 3), Anchor.TOP | Anchor.CENTER);
this.listItemList = new BasicList<>(this, UIComponent.INHERITED, 302);
this.listItemList.setPosition(0, BasicScreen.getPaddedY(listTopLine, 2));
this.listItemList.setItemComponentFactory(ListItemComponent::new);
this.listItemList.setItemComponentSpacing(1);
this.listItemList.setSelectConsumer((i) -> this.updateControls());
this.buttonList = new UIButtonBuilder(this).width(40).anchor(Anchor.LEFT | Anchor.BOTTOM).position(0, 0).text(I18n.format("almura.feature.common.button.list")).enabled(false).onClick(this::list).build("button.list");
this.labelLimit = new UILabel(this, "");
this.labelLimit.setPosition(0, -2, Anchor.CENTER | Anchor.BOTTOM);
final UIButton buttonOffer = new UIButtonBuilder(this).width(30).anchor(Anchor.RIGHT | Anchor.BOTTOM).position(0, 0).text(TextFormatting.DARK_GREEN + "+" + TextFormatting.GRAY + "/" + TextFormatting.RED + "-").enabled(true).onClick(() -> exchangeManager.requestExchangeSpecificOfferGui(this.axs.getId())).build("button.offer");
// Separator
final BasicLine listBottomLine = new BasicLine(this, searchContainer.getRawWidth() - 2);
listBottomLine.setPosition(0, BasicScreen.getPaddedY(this.buttonList, 2, Anchor.BOTTOM), Anchor.CENTER | Anchor.BOTTOM);
listableItemsContainer.add(listableItemsLabel, listTopLine, this.listItemList, this.buttonList, this.labelLimit, buttonOffer, listBottomLine);
form.add(searchContainer, buyContainer, listableItemsContainer);
addToScreen(form);
this.itemDisplayNameSearchBox.focus();
}
use of net.malisis.core.client.gui.component.decoration.BasicLine in project Almura by AlmuraDev.
the class StoreListScreen method construct.
@Override
public void construct() {
this.guiscreenBackground = false;
this.form = new BasicForm(this, 250, 130, I18n.format("almura.feature.common.text.list"));
// Fixes issue overlapping draws from parent
this.form.setZIndex(10);
this.form.setBackgroundAlpha(255);
final int containerWidth = getPaddedWidth(this.form) / 2 - 1;
// Buy container
this.buyContainer = new BasicContainer<>(this, containerWidth, -18);
this.buyContainer.setColor(FontColors.BLACK);
this.buyContainer.setBorder(FontColors.WHITE, 1, 185);
this.buyContainer.setPadding(2);
this.buyTitleLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.button.buy"));
this.buyTitleLabel.setPosition(0, 2, Anchor.TOP | Anchor.CENTER);
final BasicLine buyLine = new BasicLine(this, getPaddedWidth(this.buyContainer) + 2);
buyLine.setPosition(-1, getPaddedY(this.buyTitleLabel, 2));
this.buyPricePerTextBox = new BasicTextBox(this, this.toModifyBuy != null ? this.toModifyBuy.getPrice().toString() : "");
this.buyPricePerTextBox.setPosition(-2, getPaddedY(buyLine, 2), Anchor.TOP | Anchor.RIGHT);
this.buyPricePerTextBox.setSize(50, 0);
this.buyPricePerTextBox.setAcceptsTab(false);
this.buyPricePerTextBox.setTabIndex(1);
this.buyPricePerTextBox.setFilter(s -> this.filterAndLimit(s, 2, true));
this.buyPricePerTextBox.register(this);
this.buyPerLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.price_per") + ":");
this.buyPerLabel.setPosition(getPaddedX(this.buyPricePerTextBox, 2, Anchor.RIGHT), this.buyPricePerTextBox.getY() + 2, Anchor.TOP | Anchor.RIGHT);
this.buyQtyTextBox = new BasicTextBox(this, "");
this.buyQtyTextBox.setPosition(-2, getPaddedY(this.buyPricePerTextBox, 2), Anchor.TOP | Anchor.RIGHT);
this.buyQtyTextBox.setSize(50, 0);
this.buyQtyTextBox.setAcceptsTab(false);
this.buyQtyTextBox.setTabIndex(2);
this.buyQtyTextBox.setFilter(s -> this.filterAndLimit(s, 0, false));
this.buyQtyTextBox.register(this);
this.buyQtyLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.quantity") + ":");
this.buyQtyLabel.setPosition(getPaddedX(this.buyQtyTextBox, 2, Anchor.RIGHT), this.buyQtyTextBox.getY() + 2, Anchor.TOP | Anchor.RIGHT);
this.buyInfiniteCheckBox = new UICheckBox(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.infinite"));
this.buyInfiniteCheckBox.setPosition(this.buyContainer.componentX(this.buyQtyTextBox) - this.buyContainer.getRightPadding() - this.buyContainer.getRightBorderSize(), getPaddedY(this.buyQtyTextBox, 2));
this.buyInfiniteCheckBox.register(this);
final int column2X = this.buyContainer.componentX(this.buyQtyTextBox) - this.buyContainer.getRightPadding() - this.buyContainer.getRightBorderSize();
this.buyTotalPriceLabel = new UILabel(this);
this.buyTotalPriceLabel.setFontOptions(FontOptions.builder().shadow(false).color(0x999999).build());
this.buyTotalPriceLabel.setPosition(column2X + 2, 0, Anchor.BOTTOM | Anchor.LEFT);
buyTotalLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.total") + ":");
buyTotalLabel.setPosition(this.buyTotalPriceLabel.getX() - buyTotalLabel.getWidth() - 3, 0, Anchor.BOTTOM | Anchor.LEFT);
this.buyContainer.add(this.buyTitleLabel, buyLine, this.buyPerLabel, this.buyPricePerTextBox, this.buyQtyLabel, this.buyQtyTextBox, this.buyInfiniteCheckBox, buyTotalLabel, this.buyTotalPriceLabel);
// Sell container
this.sellContainer = new BasicContainer<>(this, containerWidth, -18);
this.sellContainer.setColor(FontColors.BLACK);
this.sellContainer.setBorder(FontColors.WHITE, 1, 185);
this.sellContainer.setPadding(2);
this.sellContainer.setPosition(0, 0, Anchor.TOP | Anchor.RIGHT);
this.sellTitleLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.button.sell"));
this.sellTitleLabel.setPosition(0, 2, Anchor.TOP | Anchor.CENTER);
final BasicLine sellLine = new BasicLine(this, getPaddedWidth(this.sellContainer) + 2);
sellLine.setPosition(-1, getPaddedY(this.sellTitleLabel, 2));
this.sellPricePerTextBox = new BasicTextBox(this, this.toModifySell != null ? this.toModifySell.getPrice().toString() : "");
this.sellPricePerTextBox.setPosition(-2, getPaddedY(sellLine, 2), Anchor.TOP | Anchor.RIGHT);
this.sellPricePerTextBox.setSize(50, 0);
this.sellPricePerTextBox.setAcceptsTab(false);
this.sellPricePerTextBox.setTabIndex(3);
this.sellPricePerTextBox.setFilter(s -> this.filterAndLimit(s, 2, false));
this.sellPricePerTextBox.register(this);
this.sellPerLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.price_per") + ":");
this.sellPerLabel.setPosition(getPaddedX(this.sellPricePerTextBox, 2, Anchor.RIGHT), this.sellPricePerTextBox.getY() + 2, Anchor.TOP | Anchor.RIGHT);
this.sellQtyTextBox = new BasicTextBox(this, "");
this.sellQtyTextBox.setPosition(-2, getPaddedY(this.sellPricePerTextBox, 2), Anchor.TOP | Anchor.RIGHT);
this.sellQtyTextBox.setSize(50, 0);
this.sellQtyTextBox.setAcceptsTab(false);
this.sellQtyTextBox.setTabIndex(4);
this.sellQtyTextBox.setFilter(s -> this.filterAndLimit(s, 0, false));
this.sellQtyTextBox.register(this);
this.sellQtyLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.quantity") + ":");
this.sellQtyLabel.setPosition(getPaddedX(this.sellQtyTextBox, 2, Anchor.RIGHT), this.sellQtyTextBox.getY() + 2, Anchor.TOP | Anchor.RIGHT);
this.sellInfiniteCheckBox = new UICheckBox(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.infinite"));
this.sellInfiniteCheckBox.setPosition(column2X, getPaddedY(this.sellQtyTextBox, 2));
this.sellInfiniteCheckBox.register(this);
this.sellTotalPriceLabel = new UILabel(this, "");
this.sellTotalPriceLabel.setFontOptions(FontOptions.builder().shadow(false).color(0x999999).build());
this.sellTotalPriceLabel.setPosition(column2X + 2, 0, Anchor.BOTTOM | Anchor.LEFT);
sellTotalLabel = new UILabel(this, TextFormatting.WHITE + I18n.format("almura.feature.common.text.price_per") + ":");
sellTotalLabel.setPosition(this.sellTotalPriceLabel.getX() - sellTotalLabel.getWidth() - 3, 0, Anchor.BOTTOM | Anchor.LEFT);
this.sellContainer.add(this.sellTitleLabel, sellLine, this.sellPerLabel, this.sellPricePerTextBox, this.sellQtyLabel, this.sellQtyTextBox, this.sellInfiniteCheckBox, sellTotalLabel, this.sellTotalPriceLabel);
this.buttonList = new UIButtonBuilder(this).text(I18n.format(this.toModifyBuy != null || this.toModifySell != null ? "almura.feature.common.button.modify" : "almura.feature.common.text.list")).anchor(Anchor.BOTTOM | Anchor.RIGHT).onClick(this::listOrModify).width(50).enabled(false).build("button.list");
this.buttonCancel = new UIButtonBuilder(this).text(I18n.format("almura.button.cancel")).anchor(Anchor.BOTTOM | Anchor.RIGHT).x(getPaddedX(this.buttonList, 2, Anchor.RIGHT)).onClick(this::close).width(50).build("button.cancel");
this.form.add(this.buyContainer, this.sellContainer, this.buttonCancel, this.buttonList);
this.addToScreen(this.form);
// Update quantity
if (this.toModifyBuy != null) {
if (this.toModifyBuy.getQuantity() == -1) {
this.buyInfiniteCheckBox.setChecked(true);
this.buyInfiniteCheckBox.fireEvent(new ComponentEvent.ValueChange<>(this.buyInfiniteCheckBox, false, true));
} else {
this.buyQtyTextBox.setText(String.valueOf(this.toModifyBuy.getQuantity()));
}
}
if (this.toModifySell != null) {
if (this.toModifySell.getQuantity() == -1) {
this.sellInfiniteCheckBox.setChecked(true);
this.sellInfiniteCheckBox.fireEvent(new ComponentEvent.ValueChange<>(this.sellInfiniteCheckBox, false, true));
} else {
this.sellQtyTextBox.setText(String.valueOf(this.toModifySell.getQuantity()));
}
}
this.buyPricePerTextBox.focus();
}
use of net.malisis.core.client.gui.component.decoration.BasicLine 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