Upload files to "src/openonyx/ui/internal"
This commit is contained in:
1 parent
c4daafb043
commit
8be910a919
5 files changed
+884
No files matched your search
@@ -0,0 +1,156 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import openonyx.history.internal.EnumSetting;
|
||||
import openonyx.history.internal.MultiSelectSetting;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.render.group_d.Animation;
|
||||
import openonyx.render.group_d.Easings;
|
||||
import openonyx.render.group_e.FontStyle;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.theme.ThemeManager;
|
||||
import openonyx.ui.MaterialIcons;
|
||||
import openonyx.ui.RenderContext;
|
||||
|
||||
public class MultiSelectControl<E extends Enum<E>> extends SettingControl {
|
||||
private final List<float[]> list;
|
||||
private float c;
|
||||
private static final float a = 9.0F;
|
||||
private final List<Animation> animations;
|
||||
private final MultiSelectSetting<E> multiSelectSetting;
|
||||
private static final float M = 5.0F;
|
||||
private boolean L;
|
||||
private static final float j = 12.0F;
|
||||
private static final float m = 23.0F;
|
||||
|
||||
public MultiSelectControl(MultiSelectSetting<E> multiSelectSetting) {
|
||||
int jx = 3 & 4;
|
||||
super(multiSelectSettingx);
|
||||
this.animations = new ArrayList<>();
|
||||
this.list = new ArrayList<>();
|
||||
this.c = 50.0F;
|
||||
this.multiSelectSetting = multiSelectSettingx;
|
||||
|
||||
for (int i = jx; jx < multiSelectSettingx.getValues().size(); jx = i) {
|
||||
this.animations.add(new Animation(0.0F));
|
||||
float[] f = new float[3];
|
||||
boolean bl = true;
|
||||
f[0] = 0.0F;
|
||||
f[1] = 0.0F;
|
||||
i++;
|
||||
f[2] = 0.0F;
|
||||
this.list.add(f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(float f, float g, int i) {
|
||||
MultiSelectControl multiSelectControl1 = this;
|
||||
if (multiSelectControl1.i() && i == 0) {
|
||||
for (int jx = i = 0; jx < multiSelectControl1.list.size(); jx = ++i) {
|
||||
float[] h = multiSelectControl1.list.get(i);
|
||||
if (f >= h[0] && f < h[0] + h[2] && g >= h[1] && g < h[1] + 23.0F) {
|
||||
multiSelectControl1.multiSelectSetting.toggle(multiSelectControl1.multiSelectSetting.getValues().get(i));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float L(RenderContext renderContext) {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RenderContext renderContext) {
|
||||
MultiSelectControl multiSelectControl1 = this;
|
||||
multiSelectControl1.update(renderContext);
|
||||
float h = multiSelectControl1.f;
|
||||
float g = multiSelectControl1.l();
|
||||
float f = 23.0F;
|
||||
|
||||
for (int k = i = 0; k < multiSelectControl1.multiSelectSetting.getValues().size(); k = i) {
|
||||
boolean bl = multiSelectControl1.multiSelectSetting.contains(multiSelectControl1.multiSelectSetting.getValues().get(i));
|
||||
Animation animation = multiSelectControl1.animations.get(i);
|
||||
Animation animation1;
|
||||
if (!multiSelectControl1.L) {
|
||||
animation.set(bl ? 1.0F : 0.0F);
|
||||
animation1 = animation;
|
||||
} else {
|
||||
if (animation.getTarget() != (bl ? 1.0F : 0.0F)) {
|
||||
animation.animateTo(bl ? 1.0F : 0.0F, 250.0F, Easings.EASING2);
|
||||
}
|
||||
|
||||
animation1 = animation;
|
||||
}
|
||||
|
||||
animation1.update(renderContext.i);
|
||||
float jx = multiSelectControl1.L(renderContext, i, animation.getValue());
|
||||
if (h > multiSelectControl1.f && h + jx > multiSelectControl1.f + multiSelectControl1.e) {
|
||||
h = multiSelectControl1.f;
|
||||
g += f + 5.0F;
|
||||
}
|
||||
|
||||
multiSelectControl1.list.get(i)[0] = h;
|
||||
multiSelectControl1.list.get(i)[1] = g;
|
||||
multiSelectControl1.list.get(i)[2] = jx;
|
||||
i++;
|
||||
h += jx + 5.0F;
|
||||
}
|
||||
|
||||
multiSelectControl1.L = true;
|
||||
multiSelectControl1.c = g + f + 6.0F - multiSelectControl1.d;
|
||||
}
|
||||
|
||||
private float L(RenderContext renderContext, int i, float f) {
|
||||
String string = EnumSetting.displayName((Enum<?>)this.multiSelectSetting.getValues().get(i));
|
||||
float g = renderContext.render2D.getTextWidth(Fonts.FONT_STYLE16, string);
|
||||
return 18.0F + g + 16.0F * f;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void d(RenderContext renderContext, float o) {
|
||||
MultiSelectControl multiSelectControl1 = this;
|
||||
Render2D render2D = renderContext.render2D;
|
||||
int mx = 0;
|
||||
multiSelectControl1.L(renderContext, multiSelectControl1.e);
|
||||
|
||||
for (int i = 0; mx < multiSelectControl1.multiSelectSetting.getValues().size(); mx = i) {
|
||||
float[] k = multiSelectControl1.list.get(i);
|
||||
float f = multiSelectControl1.animations.get(i).getValue();
|
||||
float l = k[0];
|
||||
float g = k[1];
|
||||
float h = k[2];
|
||||
int jx = renderContext.H >= l && renderContext.H < l + h && renderContext.f >= g && renderContext.f < g + 23.0F;
|
||||
if (f > 0.01F) {
|
||||
render2D.roundedRect(l, g, h, 23.0F, 8.0F, multiSelectControl1.L(ThemeManager.withAlpha(renderContext.palette().secondaryContainer(), f)));
|
||||
}
|
||||
|
||||
if (f < 0.99F) {
|
||||
render2D.roundedOutline(l, g, h, 23.0F, 8.0F, 1.0F, multiSelectControl1.L(ThemeManager.withAlpha(renderContext.palette().outline(), 1.0F - f)));
|
||||
}
|
||||
|
||||
if (jx) {
|
||||
render2D.roundedRect(l, g, h, 23.0F, 8.0F, multiSelectControl1.L(ThemeManager.withAlpha(renderContext.palette().onSurface(), 0.08F)));
|
||||
}
|
||||
|
||||
h = l + 9.0F + 16.0F * f;
|
||||
jx = f > 0.5F ? renderContext.palette().onSecondaryContainer() : renderContext.palette().onSurfaceVariant();
|
||||
if (f > 0.05F) {
|
||||
MaterialIcons.d(render2D, l + 9.0F + 6.0F, g + 11.5F, 12.0F * (0.7F + 0.3F * f), multiSelectControl1.L(ThemeManager.withAlpha(jx, f)));
|
||||
}
|
||||
|
||||
FontStyle fontStyle = Fonts.FONT_STYLE16;
|
||||
String string = EnumSetting.displayName((Enum<?>)multiSelectControl1.multiSelectSetting.getValues().get(i));
|
||||
float n = g + 11.5F;
|
||||
i++;
|
||||
render2D.drawTextVCentered(fontStyle, string, h, n, multiSelectControl1.L(jx));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import openonyx.connection.ProxySettings;
|
||||
import openonyx.connection.ProxySettingsMode;
|
||||
import openonyx.connection.internal.AuthException;
|
||||
import openonyx.connection.internal.AuthHttpClient;
|
||||
import openonyx.connection.internal.AuthHttpClientData;
|
||||
import openonyx.core.OnyxClient;
|
||||
import openonyx.input.KeyInput;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.ui.KeyShortcuts;
|
||||
import openonyx.ui.RenderContext;
|
||||
import openonyx.ui.UiComponent;
|
||||
import openonyx.utilities.AsyncExecutor;
|
||||
|
||||
public class ProxyEditor extends UiComponent {
|
||||
private final UiButton uiButton;
|
||||
private static final float G = 14.0F;
|
||||
private Consumer<String> stringConsumer;
|
||||
private static final float K = 10.0F;
|
||||
private boolean B;
|
||||
private static final float C = 144.0F;
|
||||
private boolean J;
|
||||
private final SegmentedControl segmentedControl;
|
||||
private static final float c = 28.0F;
|
||||
private final UiButton uiButton2;
|
||||
private static final float k = 88.0F;
|
||||
private final SearchField searchField;
|
||||
private final SearchField searchField2;
|
||||
private final SearchField searchField3;
|
||||
private static final int j = 8000;
|
||||
private final ToggleSwitch toggleSwitch;
|
||||
private Consumer<String> stringConsumer2;
|
||||
private static final String l = "https://api.minecraftservices.com/publickeys";
|
||||
private static final float I = 10.0F;
|
||||
private final ToggleSwitch toggleSwitch2 = new ToggleSwitch(() -> this.J, boolean1 -> this.J = boolean1);
|
||||
private static final float H = 8.0F;
|
||||
|
||||
public static float I() {
|
||||
return 308.0F;
|
||||
}
|
||||
|
||||
private void h() {
|
||||
OnyxClient.accountManager.getProxySettings().L(this.L(), this.J, this.B, this.searchField3.L(), this.searchField2.L(), this.searchField.L());
|
||||
OnyxClient.accountManager.L();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(KeyInput keyInput) {
|
||||
if (super.keyTyped(keyInput)) {
|
||||
return true;
|
||||
} else if (KeyShortcuts.i(keyInput)) {
|
||||
this.i();
|
||||
return true;
|
||||
} else {
|
||||
return keyInput.key() == 15 ? this.L(keyInput.d()) : false;
|
||||
}
|
||||
}
|
||||
|
||||
public void d(Consumer<String> consumer) {
|
||||
this.stringConsumer2 = consumer;
|
||||
}
|
||||
|
||||
public ProxyEditor() {
|
||||
this.toggleSwitch = new ToggleSwitch(() -> this.B, boolean1 -> this.B = boolean1);
|
||||
String[] strings = new String[2];
|
||||
boolean bl = true;
|
||||
strings[0] = "SOCKS5";
|
||||
strings[1] = "HTTP/HTTPS";
|
||||
this.segmentedControl = new SegmentedControl(strings, i -> {
|
||||
if (i < 0 || i >= ProxySettingsMode.values().length) {
|
||||
;
|
||||
}
|
||||
});
|
||||
this.searchField3 = new SearchField("Address");
|
||||
this.searchField2 = new SearchField("Username");
|
||||
this.searchField = new SearchField("Password");
|
||||
this.uiButton = new UiButton(UiButtonMode.OUTLINED, "Test connection", () -> {
|
||||
ProxyEditor proxyEditor2 = this;
|
||||
if (!proxyEditor2.J) {
|
||||
if (proxyEditor2.stringConsumer != null) {
|
||||
proxyEditor2.stringConsumer.accept("Enable a proxy before testing");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
proxyEditor2.h();
|
||||
} catch (IllegalArgumentException illegalArgumentException) {
|
||||
if (proxyEditor2.stringConsumer != null) {
|
||||
proxyEditor2.stringConsumer.accept(illegalArgumentException.getMessage());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
proxyEditor2.uiButton.d(true);
|
||||
AsyncExecutor.L(() -> {
|
||||
ProxyEditor proxyEditor4 = this;
|
||||
String string = null;
|
||||
|
||||
try {
|
||||
AuthHttpClientData authHttpClientData;
|
||||
if (!(authHttpClientData = AuthHttpClient.L("https://api.minecraftservices.com/publickeys", 8000)).L()) {
|
||||
string = new StringBuilder().insert(0, "Proxy test returned HTTP ").append(authHttpClientData.status()).toString();
|
||||
}
|
||||
} catch (AuthException | RuntimeException authException) {
|
||||
string = authException.getMessage() == null ? authException.toString() : authException.getMessage();
|
||||
}
|
||||
|
||||
String string1 = string;
|
||||
mc.addScheduledTask(() -> {
|
||||
this.uiButton.d(false);
|
||||
if (string1 == null) {
|
||||
if (this.stringConsumer2 != null) {
|
||||
this.stringConsumer2.accept("Proxy connection verified");
|
||||
return;
|
||||
}
|
||||
} else if (this.stringConsumer != null) {
|
||||
this.stringConsumer.accept(string1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
this.uiButton2 = new UiButton(UiButtonMode.FILLED, "Save", this::i);
|
||||
this.searchField.d(true);
|
||||
this.searchField3.L(this::i);
|
||||
this.searchField2.L(this::i);
|
||||
this.searchField.L(this::i);
|
||||
this.uiComponents.add(this.toggleSwitch2);
|
||||
this.uiComponents.add(this.toggleSwitch);
|
||||
this.uiComponents.add(this.segmentedControl);
|
||||
this.uiComponents.add(this.searchField3);
|
||||
this.uiComponents.add(this.searchField2);
|
||||
this.uiComponents.add(this.searchField);
|
||||
this.uiComponents.add(this.uiButton);
|
||||
this.uiComponents.add(this.uiButton2);
|
||||
}
|
||||
|
||||
public void L(Consumer<String> consumer) {
|
||||
this.stringConsumer = consumer;
|
||||
}
|
||||
|
||||
private ProxySettingsMode L() {
|
||||
return ProxySettingsMode.values()[this.segmentedControl.L()];
|
||||
}
|
||||
|
||||
public void I() {
|
||||
ProxyEditor proxyEditor1 = this;
|
||||
ProxySettings proxySettings = OnyxClient.accountManager.getProxySettings();
|
||||
proxyEditor1.J = proxySettings.d();
|
||||
proxyEditor1.B = proxySettings.L();
|
||||
proxyEditor1.segmentedControl.L(proxySettings.L().ordinal());
|
||||
proxyEditor1.searchField3.L(proxySettings.L());
|
||||
proxyEditor1.searchField2.L(proxySettings.D());
|
||||
proxyEditor1.searchField.L(proxySettings.i());
|
||||
proxyEditor1.searchField3.D(false);
|
||||
proxyEditor1.searchField2.D(false);
|
||||
proxyEditor1.searchField.D(false);
|
||||
}
|
||||
|
||||
public void i() {
|
||||
ProxyEditor proxyEditor1 = this;
|
||||
|
||||
try {
|
||||
proxyEditor1.h();
|
||||
OnyxClient.accountManager.L().whenComplete((void_, throwable) -> mc.addScheduledTask(() -> {
|
||||
if (throwable != null) {
|
||||
if (this.stringConsumer != null) {
|
||||
this.stringConsumer.accept(throwable.getCause() == null ? throwable.getMessage() : throwable.getCause().getMessage());
|
||||
}
|
||||
} else {
|
||||
if (this.stringConsumer2 != null) {
|
||||
this.stringConsumer2.accept(this.J ? "Proxy settings applied" : "Proxy disabled");
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException illegalArgumentException) {
|
||||
if (proxyEditor1.stringConsumer != null) {
|
||||
proxyEditor1.stringConsumer.accept(illegalArgumentException.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void L() {
|
||||
ProxyEditor proxyEditor1 = this;
|
||||
float f = proxyEditor1.d;
|
||||
proxyEditor1.toggleSwitch2.setBounds(proxyEditor1.f, f + 3.0F, 38.0F, 22.0F);
|
||||
float g = f + 38.0F;
|
||||
proxyEditor1.toggleSwitch.setBounds(proxyEditor1.f, g + 3.0F, 38.0F, 22.0F);
|
||||
float h = g + 42.0F;
|
||||
proxyEditor1.segmentedControl.setBounds(proxyEditor1.f, h, proxyEditor1.e, 30.0F);
|
||||
float i = h + 44.0F;
|
||||
proxyEditor1.searchField3.setBounds(proxyEditor1.f, i, proxyEditor1.e, 40.0F);
|
||||
float jx = i + 50.0F;
|
||||
proxyEditor1.searchField2.setBounds(proxyEditor1.f, jx, proxyEditor1.e, 40.0F);
|
||||
float kx = jx + 50.0F;
|
||||
proxyEditor1.searchField.setBounds(proxyEditor1.f, kx, proxyEditor1.e, 40.0F);
|
||||
float lx = kx + 54.0F;
|
||||
proxyEditor1.uiButton2.setBounds(proxyEditor1.f + proxyEditor1.e - 88.0F, lx, 88.0F, 30.0F);
|
||||
proxyEditor1.uiButton.setBounds(proxyEditor1.uiButton2.d() - 8.0F - 144.0F, lx, 144.0F, 30.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderContext renderContext) {
|
||||
Render2D render2D = renderContext.render2D;
|
||||
render2D.drawTextVCentered(
|
||||
Fonts.getFontstylE14(), "Use proxy", this.toggleSwitch2.d() + 38.0F + 10.0F, this.toggleSwitch2.D() + 11.0F, renderContext.palette().onSurface()
|
||||
);
|
||||
render2D.drawTextVCentered(
|
||||
Fonts.getFontstylE14(),
|
||||
"Use for account login",
|
||||
this.toggleSwitch.d() + 38.0F + 10.0F,
|
||||
this.toggleSwitch.D() + 11.0F,
|
||||
renderContext.palette().onSurfaceVariant()
|
||||
);
|
||||
super.render(renderContext);
|
||||
}
|
||||
|
||||
private boolean L(boolean bl) {
|
||||
ProxyEditor proxyEditor1 = this;
|
||||
SearchField[] searchFields2 = new SearchField[3];
|
||||
boolean bl1 = true;
|
||||
searchFields2[0] = proxyEditor1.searchField3;
|
||||
searchFields2[1] = proxyEditor1.searchField2;
|
||||
searchFields2[2] = proxyEditor1.searchField;
|
||||
SearchField[] searchFields = searchFields2;
|
||||
int i = -1;
|
||||
|
||||
for (int m = kx = 0; m < searchFields.length; m = ++kx) {
|
||||
if (searchFields[kx].i()) {
|
||||
i = kx;
|
||||
}
|
||||
}
|
||||
|
||||
int lx = Math.floorMod(i + (bl ? -1 : 1), searchFields.length);
|
||||
SearchField[] searchFields1 = searchFields;
|
||||
i = searchFields.length;
|
||||
|
||||
int jx;
|
||||
for (int n = jx = 0; n < i; n = jx) {
|
||||
searchFields1[jx++].D(false);
|
||||
}
|
||||
|
||||
searchFields[lx].D(true);
|
||||
searchFields[lx].d();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import openonyx.history.Range;
|
||||
import openonyx.history.internal.RangeSetting;
|
||||
import openonyx.input.KeyInput;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.render.group_d.Animation;
|
||||
import openonyx.render.group_d.Easings;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.theme.ThemeManager;
|
||||
import openonyx.ui.RenderContext;
|
||||
|
||||
public class RangeControl extends SettingControl {
|
||||
private final Animation animation;
|
||||
private static final float c = 5.0F;
|
||||
private int a;
|
||||
private int k;
|
||||
private float g;
|
||||
private static final float M = 16.0F;
|
||||
private static final float L = 3.0F;
|
||||
private static final float j = 3.0F;
|
||||
private static final float m = 3.0F;
|
||||
private final Animation animation2 = new Animation(3.0F);
|
||||
private final RangeSetting rangeSetting;
|
||||
|
||||
private void L(float f) {
|
||||
double d = this.rangeSetting.fromNormalized((f - this.m()) / this.B());
|
||||
double e = this.k == 0 ? this.rangeSetting.getHigh() : this.rangeSetting.getLow();
|
||||
this.rangeSetting.setValue(new Range(e, d));
|
||||
if (d < e) {
|
||||
this.k = 0;
|
||||
} else {
|
||||
if (d > e) {
|
||||
this.k = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float L(RenderContext renderContext) {
|
||||
return this.l() - this.d + 3.0F + 6.0F;
|
||||
}
|
||||
|
||||
public RangeControl(RangeSetting rangeSetting) {
|
||||
super(rangeSettingx);
|
||||
this.animation = new Animation(3.0F);
|
||||
this.k = -1;
|
||||
this.a = -1;
|
||||
this.rangeSetting = rangeSettingx;
|
||||
}
|
||||
|
||||
private float G() {
|
||||
return this.l() + 1.5F;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void d(RenderContext renderContext, float f) {
|
||||
RangeControl rangeControl1 = this;
|
||||
Render2D render2D;
|
||||
Render2D render2D1 = render2D = renderContext.render2D;
|
||||
float l = renderContext.render2D.getTextWidth(Fonts.FONT_STYLE2, rangeControl1.rangeSetting.format());
|
||||
rangeControl1.L(renderContext, rangeControl1.e - l - 12.0F);
|
||||
render2D1.drawTextRightVCentered(
|
||||
Fonts.FONT_STYLE2,
|
||||
rangeControl1.rangeSetting.format(),
|
||||
rangeControl1.f + rangeControl1.e,
|
||||
rangeControl1.I(),
|
||||
rangeControl1.L(renderContext.palette().onSurfaceVariant())
|
||||
);
|
||||
float mx = rangeControl1.G();
|
||||
float h = rangeControl1.L(rangeControl1.rangeSetting.getLow());
|
||||
float i = rangeControl1.L(rangeControl1.rangeSetting.getHigh());
|
||||
float gx = rangeControl1.animation2.getValue() / 2.0F;
|
||||
float jx = rangeControl1.animation.getValue() / 2.0F;
|
||||
float kx;
|
||||
if ((kx = h - gx - 5.0F) > rangeControl1.f) {
|
||||
render2D.roundedRect(
|
||||
rangeControl1.f, mx - 1.5F, kx - rangeControl1.f, 3.0F, Float.MAX_VALUE, rangeControl1.L(renderContext.palette().surfaceContainerHighest())
|
||||
);
|
||||
}
|
||||
|
||||
gx = h + gx + 5.0F;
|
||||
if ((kx = i - jx - 5.0F) > gx) {
|
||||
render2D.roundedRect(gx, mx - 1.5F, kx - gx, 3.0F, Float.MAX_VALUE, rangeControl1.L(renderContext.palette().primary()));
|
||||
}
|
||||
|
||||
if ((gx = i + jx + 5.0F) < rangeControl1.f + rangeControl1.e) {
|
||||
render2D.roundedRect(
|
||||
gx, mx - 1.5F, rangeControl1.f + rangeControl1.e - gx, 3.0F, Float.MAX_VALUE, rangeControl1.L(renderContext.palette().surfaceContainerHighest())
|
||||
);
|
||||
}
|
||||
|
||||
rangeControl1.L(renderContext, f, h, mx, rangeControl1.animation2.getValue(), 0);
|
||||
rangeControl1.L(renderContext, f, i, mx, rangeControl1.animation.getValue(), 1);
|
||||
}
|
||||
|
||||
private float m() {
|
||||
return this.f + 3.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(float f, float g, int i) {
|
||||
boolean bl = this.k >= 0;
|
||||
this.k = -1;
|
||||
return bl;
|
||||
}
|
||||
|
||||
private void L(Animation animation, int i) {
|
||||
RangeControl rangeControl1 = this;
|
||||
float f = rangeControl1.k == i ? 1.5F : (rangeControl1.a == i ? 4.5F : 3.0F);
|
||||
if (animationx.getTarget() != f) {
|
||||
animationx.animateTo(f, 150.0F, Easings.EASING6);
|
||||
}
|
||||
}
|
||||
|
||||
private float L(double d) {
|
||||
return this.m() + this.B() * (float)this.rangeSetting.normalize(d);
|
||||
}
|
||||
|
||||
private double L() {
|
||||
return this.rangeSetting.getStep() > 0.0 ? this.rangeSetting.getStep() : (this.rangeSetting.getMax() - this.rangeSetting.getMin()) / 100.0;
|
||||
}
|
||||
|
||||
private int L(float f) {
|
||||
float gx = Math.abs(f - this.L(this.rangeSetting.getLow()));
|
||||
f = Math.abs(f - this.L(this.rangeSetting.getHigh()));
|
||||
return gx <= f ? 0 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RenderContext renderContext) {
|
||||
super.update(renderContext);
|
||||
this.a = -1;
|
||||
this.g = renderContext.H;
|
||||
if (Math.abs(renderContext.f - this.G()) <= 16.0F) {
|
||||
float f = Math.abs(renderContext.H - this.L(this.rangeSetting.getLow()));
|
||||
float gx = Math.abs(renderContext.H - this.L(this.rangeSetting.getHigh()));
|
||||
if (Math.min(f, gx) <= 8.0F) {
|
||||
this.a = f <= gx ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.L(this.animation2, 0);
|
||||
this.L(this.animation, 1);
|
||||
this.animation2.update(renderContext.i);
|
||||
this.animation.update(renderContext.i);
|
||||
if (this.k >= 0) {
|
||||
this.L(renderContext.H);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(float f, float g, int i) {
|
||||
if (!this.i() || i != 0 || !this.contains(f, gx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gx < this.j()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.k = this.L(f);
|
||||
this.L(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void L(RenderContext renderContext, float f, float g, float h, float i, int j) {
|
||||
RangeControl rangeControl1 = this;
|
||||
Render2D render2D = renderContext.render2D;
|
||||
if (rangeControl1.a == jx || rangeControl1.k == jx) {
|
||||
render2D.circle(gx, h, 11.0F, ThemeManager.withAlpha(renderContext.palette().primary(), f * (rangeControl1.k == jx ? 0.1F : 0.08F)));
|
||||
}
|
||||
|
||||
render2D.roundedRect(gx - i / 2.0F, h - 8.0F, i, 16.0F, Float.MAX_VALUE, rangeControl1.L(renderContext.palette().primary()));
|
||||
}
|
||||
|
||||
private float B() {
|
||||
return this.e - 6.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(float f, float g, int i, float h, float j) {
|
||||
if (this.k < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.L(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(KeyInput keyInput) {
|
||||
if (this.i() && this.h) {
|
||||
double d = switch (keyInput.key()) {
|
||||
case 203 -> {
|
||||
while (false) {
|
||||
}
|
||||
|
||||
yield -this.L();
|
||||
}
|
||||
case 205 -> this.L();
|
||||
default -> 0.0;
|
||||
};
|
||||
if (d == 0.0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.L(this.g) == 0) {
|
||||
this.rangeSetting.setLow(this.rangeSetting.getLow() + d);
|
||||
} else {
|
||||
this.rangeSetting.setHigh(this.rangeSetting.getHigh() + d);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.render.group_d.ColorAnimation;
|
||||
import openonyx.render.group_e.FontStyle;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.theme.ThemeManager;
|
||||
import openonyx.ui.RenderContext;
|
||||
import openonyx.ui.UiSupport_545;
|
||||
|
||||
public class SearchField extends TextInput {
|
||||
private final UiSupport_545 uiSupport_545 = new UiSupport_545();
|
||||
private Runnable runnable;
|
||||
private static final float L = 11.0F;
|
||||
private static final float j = 2.0F;
|
||||
public static final float m = 40.0F;
|
||||
private static final float h = 1.0F;
|
||||
private static final float l = 12.0F;
|
||||
private static final float I = 9.0F;
|
||||
private Consumer<String> stringConsumer;
|
||||
private static final float H = 12.0F;
|
||||
private final String e;
|
||||
|
||||
@Override
|
||||
protected float l() {
|
||||
return this.f + 12.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RenderContext renderContext) {
|
||||
super.update(renderContext);
|
||||
this.uiSupport_545.L(renderContext.i, this.h, false);
|
||||
}
|
||||
|
||||
public void L(Consumer<String> consumer) {
|
||||
this.stringConsumer = consumer;
|
||||
}
|
||||
|
||||
public SearchField(String string) {
|
||||
this.e = string;
|
||||
this.i = 40.0F;
|
||||
this.textEditor.L(string -> {
|
||||
if (this.stringConsumer != null) {
|
||||
this.stringConsumer.accept(stringx);
|
||||
}
|
||||
});
|
||||
this.textEditor.d(() -> {
|
||||
if (this.runnable != null) {
|
||||
this.runnable.run();
|
||||
}
|
||||
});
|
||||
this.textEditor.L(() -> this.D(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FontStyle L() {
|
||||
return Fonts.getFontstylE15();
|
||||
}
|
||||
|
||||
public void L(Runnable runnable) {
|
||||
this.runnable = runnablex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float h() {
|
||||
return this.f + this.e - 12.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderContext renderContext) {
|
||||
Render2D render2D = renderContext.render2D;
|
||||
float f = this.animation.getValue();
|
||||
boolean bl = this.i() || !this.textEditor.L();
|
||||
render2D.roundedRect(this.f, this.d, this.e, this.i, 4.0F, renderContext.palette().surfaceContainerHighest());
|
||||
this.uiSupport_545.L(render2D, this.f, this.d, this.e, this.i, 4.0F, renderContext.palette().onSurface());
|
||||
render2D.roundedOutline(
|
||||
this.f, this.d, this.e, this.i, 4.0F, 1.0F + 1.0F * f, ColorAnimation.L(renderContext.palette().outline(), renderContext.palette().primary(), f)
|
||||
);
|
||||
SearchField searchField1;
|
||||
if (bl) {
|
||||
render2D.drawTextVCentered(
|
||||
Fonts.getFontstylE2(), this.e, this.l(), this.d + 9.0F, f > 0.5F ? renderContext.palette().primary() : renderContext.palette().onSurfaceVariant()
|
||||
);
|
||||
searchField1 = this;
|
||||
} else {
|
||||
render2D.drawTextVCentered(
|
||||
this.L(), this.e, this.l(), this.d + this.i / 2.0F, ThemeManager.withAlpha(renderContext.palette().onSurfaceVariant(), 0.7F)
|
||||
);
|
||||
searchField1 = this;
|
||||
}
|
||||
|
||||
searchField1.L(renderContext, bl ? this.d + this.i - 11.0F : this.d + this.i / 2.0F, 12.0F, renderContext.palette().onSurface());
|
||||
if (this.h) {
|
||||
render2D.useTextCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.render.group_d.Animation;
|
||||
import openonyx.render.group_d.Easings;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.ui.MaterialIcons;
|
||||
import openonyx.ui.RenderContext;
|
||||
import openonyx.ui.UiComponent;
|
||||
import openonyx.ui.UiSupport_545;
|
||||
|
||||
public class SegmentedControl extends UiComponent {
|
||||
private final Animation animation;
|
||||
private final Animation animation2;
|
||||
private final UiSupport_545[] uiSupport_545s;
|
||||
private static final float M = 14.0F;
|
||||
private static final float L = 5.0F;
|
||||
private boolean j;
|
||||
public static final float m = 30.0F;
|
||||
private final Animation animation3 = new Animation(0.0F);
|
||||
private final String[] l;
|
||||
private static final float I = 2.0F;
|
||||
private int f;
|
||||
private final IntConsumer intConsumer;
|
||||
private int e;
|
||||
|
||||
private int L(float f, float g) {
|
||||
return !this.contains(fx, g) ? -1 : Math.clamp((int)((fx - this.f - 2.0F) / this.I()), 0, this.l.length - 1);
|
||||
}
|
||||
|
||||
public void L(int i) {
|
||||
if (i != this.f) {
|
||||
this.f = i;
|
||||
this.animation3.animateTo(this.L(i), 300.0F, Easings.EASING2);
|
||||
this.animation.animateTo(this.I(), 300.0F, Easings.EASING2);
|
||||
this.animation2.set(0.0F).animateTo(19.0F, 300.0F, Easings.EASING2);
|
||||
this.intConsumer.accept(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(RenderContext renderContext) {
|
||||
SegmentedControl segmentedControl1 = this;
|
||||
Render2D render2D = renderContext.render2D;
|
||||
int k = 0;
|
||||
render2D.roundedOutline(
|
||||
segmentedControl1.f, segmentedControl1.d, segmentedControl1.e, segmentedControl1.i, Float.MAX_VALUE, 1.0F, renderContext.palette().outline()
|
||||
);
|
||||
render2D.roundedRect(
|
||||
segmentedControl1.animation3.getValue(),
|
||||
segmentedControl1.d + 2.0F,
|
||||
segmentedControl1.animation.getValue(),
|
||||
segmentedControl1.i - 4.0F,
|
||||
Float.MAX_VALUE,
|
||||
renderContext.palette().secondaryContainer()
|
||||
);
|
||||
|
||||
for (int jx = 0; k < segmentedControl1.l.length; k = ++jx) {
|
||||
boolean bl = jx == segmentedControl1.f;
|
||||
segmentedControl1.uiSupport_545s[jx]
|
||||
.L(
|
||||
render2D,
|
||||
segmentedControl1.L(jx),
|
||||
segmentedControl1.d + 2.0F,
|
||||
segmentedControl1.I(),
|
||||
segmentedControl1.i - 4.0F,
|
||||
Float.MAX_VALUE,
|
||||
renderContext.palette().onSurface()
|
||||
);
|
||||
int i = bl ? renderContext.palette().onSecondaryContainer() : renderContext.palette().onSurfaceVariant();
|
||||
float h = bl ? segmentedControl1.animation2.getValue() : 0.0F;
|
||||
float fx = render2D.getTextWidth(Fonts.FONT_STYLE14, segmentedControl1.l[jx]);
|
||||
fx = segmentedControl1.L(jx) + (segmentedControl1.I() - fx - h) / 2.0F;
|
||||
float g = segmentedControl1.d + segmentedControl1.i / 2.0F;
|
||||
if (h > 0.5F) {
|
||||
render2D.pushScissor(fx, segmentedControl1.d, h, segmentedControl1.i);
|
||||
MaterialIcons.d(render2D, fx + 7.0F, g, 14.0F, i);
|
||||
render2D.popScissor();
|
||||
}
|
||||
|
||||
render2D.drawTextVCentered(Fonts.FONT_STYLE14, segmentedControl1.l[jx], fx + h, g, i);
|
||||
if (jx > 0 && jx != segmentedControl1.f && jx - 1 != segmentedControl1.f) {
|
||||
render2D.rect(segmentedControl1.L(jx), segmentedControl1.d + 2.0F, 1.0F, segmentedControl1.i - 4.0F, renderContext.palette().outline());
|
||||
}
|
||||
}
|
||||
|
||||
if (segmentedControl1.e >= 0) {
|
||||
render2D.usePointerCursor();
|
||||
}
|
||||
}
|
||||
|
||||
public SegmentedControl(String[] strings, IntConsumer intConsumer) {
|
||||
this.animation = new Animation(0.0F);
|
||||
this.animation2 = new Animation(0.0F);
|
||||
this.e = -1;
|
||||
this.l = strings;
|
||||
this.intConsumer = intConsumerx;
|
||||
this.i = 30.0F;
|
||||
UiSupport_545[] uiSupport_545s1 = new UiSupport_545[strings.length];
|
||||
boolean bl = true;
|
||||
this.uiSupport_545s = uiSupport_545s1;
|
||||
|
||||
for (int k = i = 0; k < strings.length; k = i) {
|
||||
UiSupport_545[] uiSupport_545sx = this.uiSupport_545s;
|
||||
int jx = i;
|
||||
UiSupport_545 uiSupport_545 = new UiSupport_545();
|
||||
i++;
|
||||
uiSupport_545sx[jx] = uiSupport_545;
|
||||
}
|
||||
}
|
||||
|
||||
private float I() {
|
||||
return (this.e - 4.0F) / this.l.length;
|
||||
}
|
||||
|
||||
public int L() {
|
||||
return this.f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(float f, float g, int i) {
|
||||
int jx = this.L(fx, g);
|
||||
if (i == 0 && jx >= 0) {
|
||||
this.L(jx);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private float L(int i) {
|
||||
return this.f + 2.0F + this.I() * i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RenderContext renderContext) {
|
||||
super.update(renderContext);
|
||||
if (!this.j) {
|
||||
this.j = true;
|
||||
this.animation3.set(this.L(this.f));
|
||||
this.animation.set(this.I());
|
||||
this.animation2.set(19.0F);
|
||||
}
|
||||
|
||||
this.e = this.L(renderContext.H, renderContext.f);
|
||||
|
||||
int i;
|
||||
for (int jx = i = 0; jx < this.uiSupport_545s.length; jx = i) {
|
||||
UiSupport_545 uiSupport_545 = this.uiSupport_545s[i];
|
||||
boolean bl = i == this.e;
|
||||
i++;
|
||||
uiSupport_545.L(renderContext.i, bl, false);
|
||||
}
|
||||
|
||||
this.animation3.update(renderContext.i);
|
||||
this.animation.update(renderContext.i);
|
||||
this.animation2.update(renderContext.i);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user