use of binnie.core.api.gui.IWidget in project Binnie by ForestryMC.
the class WindowAbstractDatabase method initialiseClient.
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
this.setSize(new Point(176 + this.selectionBoxWidth + 22 + 8, 208));
this.addEventHandler(EventValueChanged.class, event -> {
Object value = event.getValue();
IWidget eventOriginParent = event.getOrigin().getParent();
if (eventOriginParent instanceof ControlPage && !(value instanceof DatabaseTab)) {
ControlPage parent = (ControlPage) eventOriginParent;
if (parent.getValue() instanceof IDatabaseMode) {
for (IWidget child : parent.getChildren()) {
if (child instanceof ControlPages) {
if (value == null) {
child.hide();
} else {
child.show();
for (IWidget widget : child.getChildren()) {
if (widget instanceof PageAbstract) {
PageAbstract pageAbstract = (PageAbstract) widget;
pageAbstract.onValueChanged(value);
}
}
}
}
}
}
}
});
this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.DIRECT_CHILD, this, event -> {
for (final ModeWidgets widgets : WindowAbstractDatabase.this.modes.values()) {
widgets.getListBox().setValidator(object -> {
if (Objects.equals(event.getValue(), "")) {
return true;
}
ControlTextOption controlTextOption = (ControlTextOption) object;
return controlTextOption.getText().toLowerCase().contains(event.getValue().toLowerCase());
});
}
});
new ControlHelp(this, 4, 4);
(this.panelInformation = new Panel(this, 24, 24, 144, 176, MinecraftGUI.PanelType.BLACK)).setColor(860416);
(this.panelSearch = new Panel(this, 176, 24, this.selectionBoxWidth, 160, MinecraftGUI.PanelType.BLACK)).setColor(860416);
this.modePages = new ControlPages<>(this, 0, 0, this.getSize().xPos(), this.getSize().yPos());
new ControlTextEdit(this, 176, 184, this.selectionBoxWidth, 16);
this.createMode(Mode.SPECIES, new ModeWidgets(Mode.SPECIES, this, (area, modePage) -> {
final GameProfile playerName = this.getUsername();
final Collection<IAlleleSpecies> speciesList = this.master ? this.system.getAllSpecies() : this.system.getDiscoveredSpecies(this.getWorld(), playerName);
ControlSpeciesBox controlSpeciesBox = new ControlSpeciesBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlSpeciesBox.setOptions(speciesList);
return controlSpeciesBox;
}));
this.createMode(Mode.BRANCHES, new ModeWidgets(Mode.BRANCHES, this, (area, modePage) -> {
final EntityPlayer player = this.getPlayer();
final GameProfile playerName = player.getGameProfile();
final Collection<IClassification> speciesList = this.master ? this.system.getAllBranches() : this.system.getDiscoveredBranches(this.getWorld(), playerName);
ControlBranchBox controlBranchBox = new ControlBranchBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlBranchBox.setOptions(speciesList);
return controlBranchBox;
}));
this.createMode(Mode.BREEDER, new ModeWidgets(Mode.BREEDER, this, (area, modePage) -> {
return new ControlListBox(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}));
this.addTabs();
final ControlTabBar<IDatabaseMode> tab = new ControlTabBar<>(this, 176 + this.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, this.modePages.getValues(), DatabaseControlTab::new);
CraftGUIUtil.linkWidgets(tab, this.modePages);
this.changeMode(Mode.SPECIES);
for (final IDatabaseMode mode : this.modes.keySet()) {
ModeWidgets modeWidgets = this.modes.get(mode);
modeWidgets.setInfoTabs(new ControlTabBar<>(modeWidgets.getModePage(), 8, 24, 16, 176, Alignment.LEFT, modeWidgets.getInfoPages().getValues()));
CraftGUIUtil.linkWidgets(modeWidgets.getInfoTabs(), modeWidgets.getInfoPages());
}
}
use of binnie.core.api.gui.IWidget in project Binnie by ForestryMC.
the class PageBranchOverview method onValueChanged.
@Override
public void onValueChanged(final IClassification branch) {
this.branchName.setValue(TextFormatting.UNDERLINE + I18N.localise(DatabaseConstants.BRANCH_KEY + ".name", branch.getName()));
this.branchScientific.setValue(TextFormatting.ITALIC + I18N.localise(DatabaseConstants.BRANCH_KEY + ".apidae", branch.getScientific()));
this.branchAuthority.setValue(I18N.localise(DatabaseConstants.BRANCH_KEY + ".discoveredBy", TextFormatting.BOLD + branch.getMemberSpecies()[0].getAuthority()));
for (final IWidget widget : this.branchDescription) {
this.deleteChild(widget);
}
this.branchDescription.clear();
String desc = branch.getDescription();
if (desc == null || Objects.equals(desc, "") || desc.contains("for.")) {
desc = I18N.localise(DatabaseConstants.BRANCH_KEY + ".noDesc");
}
StringBuilder line = new StringBuilder();
final List<String> descLines = new ArrayList<>();
for (final String str : desc.split(" ")) {
if (RenderUtil.getTextWidth(line + " " + str) > 134) {
descLines.add(TextFormatting.ITALIC + line.toString() + TextFormatting.RESET);
line = new StringBuilder();
}
line.append(' ').append(str);
}
descLines.add(line.toString());
int i = 0;
for (final String dLine : descLines) {
this.branchDescription.add(new ControlTextCentered(this, 84 + 12 * i++, dLine));
}
}
use of binnie.core.api.gui.IWidget in project Binnie by ForestryMC.
the class ControlList method setValue.
@Override
public void setValue(@Nullable final T value) {
if (value == this.value) {
return;
}
this.value = value;
if (this.optionWidgets.containsKey(value)) {
final IWidget child = this.optionWidgets.get(value);
this.parent.ensureVisible(child.getYPos(), child.getYPos() + child.getHeight(), this.getHeight());
}
this.parent.callEvent(new EventValueChanged<Object>(this.parent, value));
}
use of binnie.core.api.gui.IWidget in project Binnie by ForestryMC.
the class ControlList method filterOptions.
public void filterOptions() {
int height = 0;
this.optionWidgets.clear();
for (final Map.Entry<T, IWidget> entry : this.allOptions.entrySet()) {
if (this.isValidOption(entry.getValue())) {
entry.getValue().show();
this.optionWidgets.put(entry.getKey(), entry.getValue());
entry.getValue().setPosition(new Point(0, height));
height += entry.getValue().getSize().yPos();
} else {
entry.getValue().hide();
}
}
this.setValue(this.getValue());
this.setSize(new Point(this.getSize().xPos(), height));
}
use of binnie.core.api.gui.IWidget in project Binnie by ForestryMC.
the class GuiCraftGUI method keyTyped.
@Override
protected void keyTyped(final char c, final int key) {
if (key == 1 || (key == this.mc.gameSettings.keyBindInventory.getKeyCode() && this.window.getFocusedWidget() == null)) {
this.mc.player.closeScreen();
}
final IWidget origin = (this.window.getFocusedWidget() == null) ? this.window : this.window.getFocusedWidget();
this.window.callEvent(new EventKey.Down(origin, c, key));
}
Aggregations