config ui design start
This commit is contained in:
@@ -22,7 +22,7 @@ public class ConfigScreen extends Screen
|
|||||||
protected void init()
|
protected void init()
|
||||||
{
|
{
|
||||||
this.layout.addHeader(this.title, this.textRenderer);
|
this.layout.addHeader(this.title, this.textRenderer);
|
||||||
this.body = new OptionList(this.client, this.layout.getWidth(), this.layout.getContentHeight(), this.layout.getHeaderHeight(), 25);
|
this.body = new OptionList(this.client, this.layout.getWidth(), this.layout.getContentHeight(), this.layout.getHeaderHeight(), 50);
|
||||||
this.addItems();
|
this.addItems();
|
||||||
this.layout.addBody(body);
|
this.layout.addBody(body);
|
||||||
this.layout.addFooter(ButtonWidget.builder(ScreenTexts.DONE, button -> this.close()).width(200).build());
|
this.layout.addFooter(ButtonWidget.builder(ScreenTexts.DONE, button -> this.close()).width(200).build());
|
||||||
@@ -34,8 +34,7 @@ public class ConfigScreen extends Screen
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
ButtonWidget widget = ButtonWidget.builder(Text.of("TEST"), button -> System.out.println("button pressed")).build();
|
this.body.add();
|
||||||
this.body.add(widget);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Option extends ElementListWidget.Entry<Option>
|
public class Option extends ElementListWidget.Entry<Option>
|
||||||
{
|
{
|
||||||
private final ClickableWidget widget;
|
private final List<ClickableWidget> widgets;
|
||||||
|
|
||||||
public Option(ClickableWidget widget)
|
public Option(ClickableWidget... widgets)
|
||||||
{
|
{
|
||||||
this.widget = widget;
|
this.widgets = List.of(widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,15 +26,22 @@ public class Option extends ElementListWidget.Entry<Option>
|
|||||||
@Override
|
@Override
|
||||||
public List<? extends Element> children()
|
public List<? extends Element> children()
|
||||||
{
|
{
|
||||||
return List.of(this.widget);
|
return widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY()
|
||||||
|
{
|
||||||
|
return super.getY() - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks)
|
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks)
|
||||||
{
|
{
|
||||||
this.widget.setX(this.getX());
|
for (ClickableWidget widget : widgets)
|
||||||
this.widget.setY(this.getY());
|
{
|
||||||
this.widget.setWidth(this.getWidth());
|
widget.setY(this.getY() + (this.getHeight() - widget.getHeight()) / 2);
|
||||||
this.widget.render(context, mouseX, mouseY, deltaTicks);
|
widget.render(context, mouseX, mouseY, deltaTicks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.kasetoatz.fastghast.configscreen;
|
package com.kasetoatz.fastghast.configscreen;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.widget.*;
|
import net.minecraft.client.gui.widget.*;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class OptionList extends ElementListWidget<Option>
|
public class OptionList extends ElementListWidget<Option>
|
||||||
{
|
{
|
||||||
@@ -16,8 +20,37 @@ public class OptionList extends ElementListWidget<Option>
|
|||||||
return this.width - 30;
|
return this.width - 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ClickableWidget widget)
|
@Override
|
||||||
|
protected int getContentsHeightWithPadding()
|
||||||
{
|
{
|
||||||
this.addEntry(new Option(widget));
|
return super.getContentsHeightWithPadding() - 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta)
|
||||||
|
{
|
||||||
|
List<Option> options = this.children();
|
||||||
|
for (int i = 0; i < options.size(); i++)
|
||||||
|
{
|
||||||
|
Option option = options.get(i);
|
||||||
|
if (option.getY() + option.getHeight() < this.getY())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (option.getY() > this.getY() + this.height)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
context.fill(0, Math.max(option.getY(), this.getY()), option.getWidth() + 30, Math.min(option.getY() + option.getHeight(), this.getY() + this.height), (i % 2 == 0) ? 0x50555555 : 0x50333333);
|
||||||
|
}
|
||||||
|
super.renderWidget(context, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add()
|
||||||
|
{
|
||||||
|
this.addEntry(new Option(
|
||||||
|
new TextWidget(20, 0, 200, 40, Text.of("TEST TEXT"), client.textRenderer),
|
||||||
|
ButtonWidget.builder(Text.of("TEST BUTTON"), button -> System.out.println("test button pressed")).dimensions(this.getWidth() - 100, 0, 80, 40).build())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user