use of com.teamwizardry.librarianlib.features.math.Vec2d in project Wizardry by TeamWizardry.
the class ComponentWhitelistedModifiers method refresh.
public void refresh() {
if (worktable.selectedComponent == null) {
setVisible(false);
addTag("disabled");
return;
} else {
setVisible(true);
removeTag("disabled");
}
HashSet<GuiComponent> temp = new HashSet<>(list.getChildren());
for (GuiComponent component : temp) {
list.relationships.remove(component);
}
Module module = worktable.getModule(worktable.selectedComponent);
if (module == null)
return;
if (module.applicableModifiers() == null)
return;
if (Objects.requireNonNull(module.applicableModifiers()).length <= 0)
return;
ModuleModifier[] modifiers = module.applicableModifiers();
if (modifiers == null)
return;
for (ModuleModifier modifier : modifiers) {
ComponentRect bar = new ComponentRect(0, 0, getSize().getXi(), 16);
bar.getColor().setValue(new Color(0x80000000, true));
ComponentSprite plate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
bar.add(plate);
Sprite icon = new Sprite(new ResourceLocation(Wizardry.MODID, "textures/gui/worktable/icons/" + modifier.getID() + ".png"));
ComponentSprite iconComp = new ComponentSprite(icon, 2, 2, 12, 12);
plate.add(iconComp);
ComponentText text = new ComponentText(20, 4, ComponentText.TextAlignH.LEFT, ComponentText.TextAlignV.TOP);
text.getText().setValue(TextFormatting.GREEN + modifier.getShortHandName());
bar.add(text);
bar.render.getTooltip().func((Function<GuiComponent, java.util.List<String>>) t -> {
List<String> txt = new ArrayList<>();
for (GuiComponent comp : worktable.paperComponents.keySet()) if (comp.hasTag("dragging"))
return txt;
txt.add(TextFormatting.GOLD + module.getReadableName());
if (GuiScreen.isShiftKeyDown())
txt.add(TextFormatting.GRAY + module.getDescription());
else
txt.add(TextFormatting.GRAY + LibrarianLib.PROXY.translate("wizardry.misc.sneak"));
return txt;
});
bar.BUS.hook(GuiComponentEvents.MouseInEvent.class, event -> {
bar.getColor().setValue(new Color(0x66000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseOutEvent.class, event -> {
bar.getColor().setValue(new Color(0x80000000, true));
});
bar.BUS.hook(GuiComponentEvents.MouseDownEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x4D000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseUpEvent.class, event -> {
if (event.component.getMouseOver()) {
bar.getColor().setValue(new Color(0x80000000, true));
}
});
bar.BUS.hook(GuiComponentEvents.MouseClickEvent.class, (event) -> {
if (!event.component.getMouseOver())
return;
int i = worktable.selectedComponent.hasData(Integer.class, modifier.getID()) ? worktable.selectedComponent.getData(Integer.class, modifier.getID()) : 0;
int status = -1;
if (event.getButton() == EnumMouseButton.LEFT) {
worktable.selectedComponent.setData(Integer.class, modifier.getID(), ++i);
status = 0;
} else if (event.getButton() == EnumMouseButton.RIGHT) {
if (worktable.selectedComponent.hasData(Integer.class, modifier.getID())) {
if (worktable.selectedComponent.getData(Integer.class, modifier.getID()) > 0) {
worktable.selectedComponent.setData(Integer.class, modifier.getID(), --i);
status = 1;
} else {
worktable.selectedComponent.removeData(Integer.class, modifier.getID());
}
}
}
ComponentSprite fakePlate = new ComponentSprite(TableModule.plate, 0, 0, 16, 16);
bar.add(fakePlate);
ComponentSprite fakeIconComp = new ComponentSprite(icon, 2, 2, 12, 12);
fakePlate.add(fakeIconComp);
ScheduledEventAnimation scheduled = new ScheduledEventAnimation(20, fakePlate::invalidate);
Vec2d r = worktable.selectedComponent.thisPosToOtherContext(bar);
KeyframeAnimation<ComponentSprite> animX = new KeyframeAnimation<>(fakePlate, "pos.x");
animX.setDuration(20);
if (status == 0) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getX(), Easing.easeInBack) });
} else if (status == 1) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getX(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
}
KeyframeAnimation<ComponentSprite> animY = new KeyframeAnimation<>(fakePlate, "pos.y");
animY.setDuration(20);
if (status == 0) {
animY.setKeyframes(new Keyframe[] { new Keyframe(0, 0, Easing.linear), new Keyframe(1f, r.getY(), Easing.easeInBack) });
} else if (status == 1) {
animX.setKeyframes(new Keyframe[] { new Keyframe(0, r.getY(), Easing.linear), new Keyframe(1f, 0, Easing.easeInBack) });
}
worktable.getMainComponents().add(scheduled, animX, animY);
});
list.add(bar);
}
}
use of com.teamwizardry.librarianlib.features.math.Vec2d in project Wizardry by TeamWizardry.
the class TableModule method drawWire.
@SuppressWarnings("unused")
public static void drawWire(Vec2d start, Vec2d end, Color primary, Color secondary) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.translate(0, 0, -1);
streak.getTex().bind();
InterpBezier2D bezier = new InterpBezier2D(start, end);
List<Vec2d> list = bezier.list(50);
Vec2d pointerPos = null, behindPointer = null;
float p = 0;
for (int i = 0; i < list.size() - 1; i++) {
float x = (float) (start.length() + ClientTickHandler.getTicks() + ClientTickHandler.getPartialTicks()) / 30f;
if (i == (int) ((x - Math.floor(x)) * 50f)) {
p = i / (list.size() - 1.0f);
}
}
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
Vec2d lastPoint = null;
for (int i = 0; i < list.size() - 1; i++) {
Vec2d point = list.get(i);
if (lastPoint == null) {
lastPoint = point;
continue;
}
float dist = (i / (list.size() - 1.0f));
float wire;
if (dist < p) {
float z = Math.abs(dist - p);
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
} else {
float z = Math.abs(dist - (p + 1f));
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
}
float r = lerp(primary.getRed(), secondary.getRed(), wire) / 255f;
float g = lerp(primary.getGreen(), secondary.getGreen(), wire) / 255f;
float b = lerp(primary.getBlue(), secondary.getBlue(), wire) / 255f;
Vec2d normal = point.sub(lastPoint).normalize();
Vec2d perp = new Vec2d(-normal.getYf(), normal.getXf()).mul((1.0f - 2.0f * Math.abs(dist - 0.5f) + 0.3f));
Vec2d point1 = lastPoint.sub(normal.mul(0.5)).add(perp);
Vec2d point2 = point.add(normal.mul(0.5)).add(perp);
Vec2d point3 = point.add(normal.mul(0.5)).sub(perp);
Vec2d point4 = lastPoint.sub(normal.mul(0.5)).sub(perp);
vb.pos(point1.getXf(), point1.getYf(), 0).tex(0, 0).color(r, g, b, 1f).endVertex();
vb.pos(point2.getXf(), point2.getYf(), 0).tex(0, 1).color(r, g, b, 1f).endVertex();
vb.pos(point3.getXf(), point3.getYf(), 0).tex(1, 0).color(r, g, b, 1f).endVertex();
vb.pos(point4.getXf(), point4.getYf(), 0).tex(1, 1).color(r, g, b, 1f).endVertex();
lastPoint = point;
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
use of com.teamwizardry.librarianlib.features.math.Vec2d in project Wizardry by TeamWizardry.
the class TableModule method drawComponent.
@Override
public void drawComponent(@NotNull Vec2d mousePos, float partialTicks) {
super.drawComponent(mousePos, partialTicks);
Sprite plate;
plate = selectedModule == this ? PLATE_HIGHLIGHTED : PLATE;
Vec2d pos = Vec2d.ZERO;
Vec2d size = new Vec2d(plate.getWidth(), plate.getHeight());
if (selectedModule == this || (getMouseOver() && !hasTag("connecting"))) {
size = size.add(6, 6);
pos = pos.sub(3, 3);
}
if (hasTag("connecting")) {
drawWire(pos.add(size.getX() / 2.0, size.getY() / 2.0), mousePos, getColorForModule(module.getModuleType()), Color.WHITE);
} else if (linksTo != null) {
Vec2d posTo = new Vec2d(linksTo.getPos().getX() - (linksTo.getSize().getXi() / 2.0), linksTo.getPos().getY() - (linksTo.getSize().getYi() / 2.0));
drawWire(pos.add(size.getX() / 2.0, size.getY() / 2.0), posTo.add(size.getX() / 2.0, size.getY() / 2.0), getColorForModule(module.getModuleType()), getColorForModule(linksTo.getModule().getModuleType()));
}
plate.bind();
plate.draw(0, pos.getXi(), pos.getYi(), size.getXi(), size.getYi());
double shrink = 2;
icon.bind();
icon.draw(0, (float) ((plate.getWidth() / 2.0) - ((size.getX() - shrink) / 2.0)), (float) ((plate.getHeight() / 2.0) - ((size.getY() - shrink) / 2.0)), (float) (size.getX() - shrink), (float) (size.getYi() - shrink));
}
use of com.teamwizardry.librarianlib.features.math.Vec2d in project Wizardry by TeamWizardry.
the class WorktableGui method addScrollbar.
private void addScrollbar(ComponentSprite parent, ComponentGrid gridView, int x, int y, ModuleType type, int trackSize) {
ComponentSprite scrollBar = new ComponentSprite(SCROLL_BAR_GRIP, x, y, 5, 80);
ComponentSprite bar = new ComponentSprite(SCROLL_BAR, 1, 0, 3, 11);
int moduleCount = ModuleRegistry.INSTANCE.getModules(type).size();
scrollBar.BUS.hook(GuiComponentEvents.MouseDragEvent.class, (event) -> {
if (!event.component.getMouseOver() && !parent.getMouseOver())
return;
for (GuiComponent comp : paperComponents.keySet()) if (comp.hasTag("dragging"))
return;
float contentSize = (float) ((moduleCount / 3.0) * 16.0);
float windowSize = trackSize;
float windowContentRatio = windowSize / contentSize;
float gripSize = MathHelper.clamp(trackSize * windowContentRatio, SCROLL_BAR_GRIP.getHeight(), gridView.getSize().getYi());
float windowScrollAreaSize = contentSize - windowSize;
float windowPosition = 100;
float windowPositionRatio = windowPosition / windowScrollAreaSize;
float trackScrollAreaSize = trackSize - gripSize;
float gripPositionOnTrack = trackScrollAreaSize * windowPositionRatio;
float mousePositionDelta = event.getMousePos().getYi();
float newGripPosition = MathHelper.clamp(gripPositionOnTrack + mousePositionDelta, 0, trackScrollAreaSize);
float newGripPositionRatio = newGripPosition / trackScrollAreaSize;
windowPosition = newGripPositionRatio * windowScrollAreaSize;
float percent = windowPosition / contentSize;
ArrayList<GuiComponent> compTmp = new ArrayList<>(gridView.getChildren());
compTmp.forEach(gridView.relationships::remove);
ArrayList<GuiComponent> tmp = new ArrayList<>();
for (Module module : ModuleRegistry.INSTANCE.getModules(type)) {
TableModule item = new TableModule(this, parent, module, false, false);
tmp.add(item.component);
}
ArrayList<GuiComponent> scrollable = (ArrayList<GuiComponent>) Utils.getVisibleComponents(tmp, percent);
for (GuiComponent component : scrollable) {
gridView.add(component);
}
});
scrollBar.BUS.hook(GuiComponentEvents.MouseWheelEvent.class, (event) -> {
if (!event.component.getMouseOver() && !parent.getMouseOver())
return;
for (GuiComponent comp : paperComponents.keySet()) if (comp.hasTag("dragging"))
return;
int dir = event.getDirection().ydirection * -16;
double barPos = bar.getPos().getY();
double clamp = MathHelper.clamp(barPos + dir, 0, (gridView.getSize().getY() - 1) - 11);
bar.setPos(new Vec2d(bar.getPos().getX(), clamp));
double percent = MathHelper.clamp(clamp / ((gridView.getSize().getY() - 1) - 11), 0, 1);
ArrayList<GuiComponent> compTmp = new ArrayList<>(gridView.getChildren());
compTmp.forEach(gridView.relationships::remove);
ArrayList<GuiComponent> tmp = new ArrayList<>();
for (Module module : ModuleRegistry.INSTANCE.getModules(type)) {
TableModule item = new TableModule(this, parent, module, false, false);
tmp.add(item.component);
}
ArrayList<GuiComponent> scrollable = (ArrayList<GuiComponent>) Utils.getVisibleComponents(tmp, percent);
for (GuiComponent component : scrollable) {
gridView.add(component);
}
});
scrollBar.add(bar);
getMainComponents().add(scrollBar);
}
use of com.teamwizardry.librarianlib.features.math.Vec2d in project Wizardry by TeamWizardry.
the class TableModule method drawWire.
public static void drawWire(Vec2d start, Vec2d end, Color primary, Color secondary) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.translate(0, 0, -1);
STREAK.bind();
InterpBezier2D bezier = new InterpBezier2D(start, end);
List<Vec2d> list = bezier.list(50);
Vec2d pointerPos = null, behindPointer = null;
float p = 0;
for (int i = 0; i < list.size() - 1; i++) {
float x = (float) (start.length() + ClientTickHandler.getTicks() + ClientTickHandler.getPartialTicks()) / 30f;
if (i == (int) ((x - Math.floor(x)) * 50f)) {
p = i / (list.size() - 1.0f);
}
}
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vb = tessellator.getBuffer();
vb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
Vec2d lastPoint = null;
for (int i = 0; i < list.size() - 1; i++) {
Vec2d point = list.get(i);
if (lastPoint == null) {
lastPoint = point;
continue;
}
float dist = (i / (list.size() - 1.0f));
float wire;
if (dist < p) {
float z = Math.abs(dist - p);
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
} else {
float z = Math.abs(dist - (p + 1f));
wire = 256.0f / 27.0f * (z * z * z - z * z * z * z);
}
float r = lerp(primary.getRed(), secondary.getRed(), wire) / 255f;
float g = lerp(primary.getGreen(), secondary.getGreen(), wire) / 255f;
float b = lerp(primary.getBlue(), secondary.getBlue(), wire) / 255f;
Vec2d normal = point.sub(lastPoint).normalize();
Vec2d perp = new Vec2d(-normal.getYf(), normal.getXf()).mul((1.0f - 2.0f * Math.abs(dist - 0.5f) + 0.3f));
Vec2d point1 = lastPoint.sub(normal.mul(0.5)).add(perp);
Vec2d point2 = point.add(normal.mul(0.5)).add(perp);
Vec2d point3 = point.add(normal.mul(0.5)).sub(perp);
Vec2d point4 = lastPoint.sub(normal.mul(0.5)).sub(perp);
vb.pos(point1.getXf(), point1.getYf(), 0).tex(0, 0).color(r, g, b, 1f).endVertex();
vb.pos(point2.getXf(), point2.getYf(), 0).tex(0, 1).color(r, g, b, 1f).endVertex();
vb.pos(point3.getXf(), point3.getYf(), 0).tex(1, 0).color(r, g, b, 1f).endVertex();
vb.pos(point4.getXf(), point4.getYf(), 0).tex(1, 1).color(r, g, b, 1f).endVertex();
lastPoint = point;
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
Aggregations