use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.
the class SodiumOptionsGUI method renderOptionTooltip.
@SuppressWarnings("SuspiciousNameCombination")
private void renderOptionTooltip(ControlElement<?> element, int mouseX, int mouseY, float delta) {
Rect2i dim = element.getDimensions();
int textPadding = 3;
int boxPadding = 3;
int boxX = dim.getX() + dim.getWidth() + boxPadding;
int boxY = dim.getY() + boxPadding;
int boxWidth = Math.min(this.width - (dim.getX() + dim.getWidth() + (boxPadding * 2)), 280);
Option<?> option = element.getOption();
List<String> tooltip = new ArrayList<>(this.font.wrapStringToWidthAsList(option.getTooltip(), boxWidth - (textPadding * 2)));
OptionImpact impact = option.getImpact();
if (impact != null) {
tooltip.add("");
tooltip.add(TextFormat.GRAY + "Performance Impact: " + impact.toDisplayString());
}
int boxHeight = (tooltip.size() * 12) + boxPadding;
this.fillGradient(boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000, 0xE0000000);
for (int i = 0; i < tooltip.size(); i++) {
String str = tooltip.get(i);
if (str.isEmpty()) {
continue;
}
this.font.draw(str, boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF);
}
}
use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.
the class SodiumOptionsGUI method rebuildGUIOptions.
private void rebuildGUIOptions() {
int x = 10;
int y = 28;
for (OptionGroup group : this.currentPage.getGroups()) {
for (Option<?> option : group.getOptions()) {
Control<?> control = option.getControl();
ControlElement<?> element = control.createElement(new Rect2i(x, y, 200, 18));
Validate.notNull(element);
this.controls.add(element);
this.children.add(element);
y += 18;
}
y += 4;
}
}
use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.
the class SodiumOptionsGUI method rebuildGUI.
private void rebuildGUI() {
this.controls.clear();
this.children.clear();
this.drawable.clear();
if (this.currentPage == null) {
if (this.pages.isEmpty()) {
throw new IllegalStateException("No pages are available?!");
}
// Just use the first page for now
this.currentPage = this.pages.get(0);
}
this.rebuildGUIPages();
this.rebuildGUIOptions();
this.applyButton = new FlatButtonWidget(new Rect2i(10, this.height - 30, 80, 20), "Apply", this::applyChanges);
this.closeButton = new FlatButtonWidget(new Rect2i(96, this.height - 30, 80, 20), "Close", this::popScreen);
this.children.add(this.applyButton);
this.children.add(this.closeButton);
this.resetButton = new FlatButtonWidget(new Rect2i(this.width - 96, this.height - 30, 80, 20), "Reset", this::resetChanges);
this.children.add(this.resetButton);
for (Element element : this.children) {
if (element instanceof Drawable) {
this.drawable.add((Drawable) element);
}
}
}
use of net.minecraft.client.util.Rect2i in project sodium-fabric by CaffeineMC.
the class SodiumOptionsGUI method rebuildGUIPages.
private void rebuildGUIPages() {
int x = 10;
int y = 6;
for (OptionPage page : this.pages) {
int width = 10 + this.font.getStringWidth(page.getName());
FlatButtonWidget button = new FlatButtonWidget(new Rect2i(x, y, width, 16), page.getName(), () -> {
this.setPage(page);
});
button.setSelected(this.currentPage == page);
x += width + 6;
this.children.add(button);
}
}
Aggregations