Upload files to "src/openonyx/ui/internal"
This commit is contained in:
1 parent
7f20024adb
commit
8186c1dd79
5 files changed
+1116
No files matched your search
@@ -0,0 +1,227 @@
|
||||
package openonyx.ui.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.block.Block;
|
||||
import openonyx.history.internal.BlockSetSetting;
|
||||
import openonyx.render.Render2D;
|
||||
import openonyx.theme.Fonts;
|
||||
import openonyx.theme.ThemeManager;
|
||||
import openonyx.ui.MaterialIcons;
|
||||
import openonyx.ui.RenderContext;
|
||||
|
||||
public class BlockListControl extends SettingControl {
|
||||
private final List<Block> blocks;
|
||||
private static final int F = 6;
|
||||
private final SearchField searchField = new SearchField("Search blocks");
|
||||
private float A;
|
||||
private int K;
|
||||
private final List<float[]> list;
|
||||
private static final float C = 22.0F;
|
||||
private static final float J = 9.0F;
|
||||
private int D;
|
||||
private static final float c = 10.0F;
|
||||
private float a;
|
||||
private static final float k = 6.0F;
|
||||
private final List<Block> blocks2;
|
||||
private String M;
|
||||
private static final float L = 5.0F;
|
||||
private final BlockSetSetting blockSetSetting;
|
||||
private static final float m = 22.0F;
|
||||
|
||||
@Override
|
||||
public void update(RenderContext renderContext) {
|
||||
BlockListControl blockListControl1 = this;
|
||||
int l = 0;
|
||||
blockListControl1.searchField.setBounds(blockListControl1.f, blockListControl1.l(), blockListControl1.e, 40.0F);
|
||||
blockListControl1.A = blockListControl1.l() + 40.0F + 6.0F;
|
||||
blockListControl1.K = -1;
|
||||
|
||||
for (int j = 0; l < blockListControl1.blocks.size(); l = ++j) {
|
||||
float f = blockListControl1.A + j * 22.0F;
|
||||
if (renderContext.H >= blockListControl1.f
|
||||
&& renderContext.H < blockListControl1.f + blockListControl1.e
|
||||
&& renderContext.f >= f
|
||||
&& renderContext.f < f + 22.0F) {
|
||||
blockListControl1.K = j;
|
||||
}
|
||||
}
|
||||
|
||||
blockListControl1.blocks2.clear();
|
||||
blockListControl1.blocks2.addAll(blockListControl1.blockSetSetting.getValue());
|
||||
blockListControl1.list.clear();
|
||||
float h = blockListControl1.f;
|
||||
float kx = blockListControl1.A + blockListControl1.blocks.size() * 22.0F + (blockListControl1.blocks.isEmpty() ? 0.0F : 6.0F);
|
||||
l = 0;
|
||||
blockListControl1.D = -1;
|
||||
|
||||
for (int i = 0; l < blockListControl1.blocks2.size(); l = i) {
|
||||
float g = Math.min(blockListControl1.L(renderContext, blockListControl1.blocks2.get(i)), blockListControl1.e);
|
||||
if (h > blockListControl1.f && h + g > blockListControl1.f + blockListControl1.e) {
|
||||
h = blockListControl1.f;
|
||||
kx += 27.0F;
|
||||
}
|
||||
|
||||
float[] mx = new float[3];
|
||||
boolean bl = true;
|
||||
mx[0] = h;
|
||||
mx[1] = kx;
|
||||
mx[2] = g;
|
||||
blockListControl1.list.add(mx);
|
||||
if (renderContext.H >= h && renderContext.H < h + g && renderContext.f >= kx && renderContext.f < kx + 22.0F) {
|
||||
blockListControl1.D = i;
|
||||
}
|
||||
|
||||
i++;
|
||||
h += g + 5.0F;
|
||||
}
|
||||
|
||||
blockListControl1.a = (blockListControl1.blocks2.isEmpty() ? kx : kx + 22.0F) + 6.0F - blockListControl1.d;
|
||||
blockListControl1.update(renderContext);
|
||||
}
|
||||
|
||||
public BlockListControl(BlockSetSetting blockSetSetting) {
|
||||
super(blockSetSettingx);
|
||||
this.blocks = new ArrayList<>();
|
||||
this.blocks2 = new ArrayList<>();
|
||||
this.list = new ArrayList<>();
|
||||
this.M = "";
|
||||
this.a = 60.0F;
|
||||
this.K = -1;
|
||||
this.D = -1;
|
||||
this.blockSetSetting = blockSetSettingx;
|
||||
this.searchField
|
||||
.L(
|
||||
string -> {
|
||||
this.M = string == null ? "" : string.trim().toLowerCase(Locale.ROOT);
|
||||
this.blocks.clear();
|
||||
if (!this.M.isEmpty()) {
|
||||
Iterator iterator = Block.blockRegistry.iterator();
|
||||
|
||||
label34:
|
||||
while (true) {
|
||||
for (Iterator iterator1 = iterator; iterator1.hasNext(); iterator1 = iterator) {
|
||||
Block block;
|
||||
if (BlockSetSetting.L(block = (Block)iterator.next()).contains(this.M)
|
||||
|| block.getLocalizedName().toLowerCase(Locale.ROOT).contains(this.M)) {
|
||||
this.blocks.add(block);
|
||||
if (this.blocks.size() >= 6) {
|
||||
break label34;
|
||||
}
|
||||
continue label34;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
this.uiComponents.add(this.searchField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(float f, float g, int i) {
|
||||
if (!this.i() || i != 0) {
|
||||
return false;
|
||||
} else if (this.searchField.mouseClicked(f, g, i)) {
|
||||
return true;
|
||||
} else if (this.K >= 0) {
|
||||
this.blockSetSetting.D(this.blocks.get(this.K));
|
||||
return true;
|
||||
} else if (this.D >= 0) {
|
||||
this.blockSetSetting.d(this.blocks2.get(this.D));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float L(RenderContext renderContext) {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void d(RenderContext renderContext, float w) {
|
||||
BlockListControl blockListControl1 = this;
|
||||
Render2D render2D = renderContext.render2D;
|
||||
String string = blockListControl1.blocks2.size() + " selected";
|
||||
float f = render2D.getTextWidth(Fonts.FONT_STYLE2, string);
|
||||
blockListControl1.L(renderContext, blockListControl1.e - f - 12.0F);
|
||||
render2D.drawTextRightVCentered(
|
||||
Fonts.FONT_STYLE2,
|
||||
string,
|
||||
blockListControl1.f + blockListControl1.e,
|
||||
blockListControl1.I(),
|
||||
blockListControl1.L(renderContext.palette().onSurfaceVariant())
|
||||
);
|
||||
blockListControl1.searchField.render(renderContext);
|
||||
|
||||
for (int r = l = 0; r < blockListControl1.blocks.size(); r = ++l) {
|
||||
Block block = blockListControl1.blocks.get(l);
|
||||
float g = blockListControl1.A + l * 22.0F;
|
||||
boolean bl = blockListControl1.blockSetSetting.L(block);
|
||||
if (blockListControl1.K == l) {
|
||||
render2D.roundedRect(
|
||||
blockListControl1.f,
|
||||
g,
|
||||
blockListControl1.e,
|
||||
22.0F,
|
||||
4.0F,
|
||||
blockListControl1.L(ThemeManager.withAlpha(renderContext.palette().onSurface(), 0.08F))
|
||||
);
|
||||
}
|
||||
|
||||
render2D.drawTextVCentered(
|
||||
Fonts.FONT_STYLE15,
|
||||
render2D.trimToWidth(Fonts.FONT_STYLE15, L(block), blockListControl1.e - 30.0F),
|
||||
blockListControl1.f + 8.0F,
|
||||
g + 11.0F,
|
||||
blockListControl1.L(bl ? renderContext.palette().primary() : renderContext.palette().onSurface())
|
||||
);
|
||||
if (bl) {
|
||||
MaterialIcons.d(
|
||||
render2D, blockListControl1.f + blockListControl1.e - 14.0F, g + 11.0F, 12.0F, blockListControl1.L(renderContext.palette().primary())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (int q = mx = 0; q < blockListControl1.list.size(); q = mx) {
|
||||
float[] n = blockListControl1.list.get(mx);
|
||||
float o = n[0];
|
||||
float p = n[1];
|
||||
float h = n[2];
|
||||
render2D.roundedRect(o, p, h, 22.0F, 8.0F, blockListControl1.L(renderContext.palette().secondaryContainer()));
|
||||
if (blockListControl1.D == mx) {
|
||||
render2D.roundedRect(o, p, h, 22.0F, 8.0F, blockListControl1.L(ThemeManager.withAlpha(renderContext.palette().onSurface(), 0.08F)));
|
||||
}
|
||||
|
||||
int i = renderContext.palette().onSecondaryContainer();
|
||||
float j = h - 18.0F - 10.0F - 5.0F;
|
||||
render2D.drawTextVCentered(
|
||||
Fonts.FONT_STYLE16, render2D.trimToWidth(Fonts.FONT_STYLE16, L(blockListControl1.blocks2.get(mx)), j), o + 9.0F, p + 11.0F, blockListControl1.L(i)
|
||||
);
|
||||
h = o + h - 9.0F - 5.0F;
|
||||
j = p + 11.0F;
|
||||
float kx = 4.0F;
|
||||
render2D.I(h - kx, j - kx, h + kx, j + kx, 1.4F, blockListControl1.L(i));
|
||||
float s = h - kx;
|
||||
float t = j + kx;
|
||||
float u = h + kx;
|
||||
float v = j - kx;
|
||||
mx++;
|
||||
render2D.I(s, t, u, v, 1.4F, blockListControl1.L(i));
|
||||
}
|
||||
}
|
||||
|
||||
private float L(RenderContext renderContext, Block block) {
|
||||
return 18.0F + renderContext.render2D.getTextWidth(Fonts.FONT_STYLE16, L(block)) + 10.0F + 5.0F;
|
||||
}
|
||||
|
||||
private static String L(Block block) {
|
||||
return block.getLocalizedName();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user