Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/slprime/chromatictooltips/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.lwjgl.input.Keyboard;

import com.slprime.chromatictooltips.converter.DividerConverter;
import com.slprime.chromatictooltips.converter.DividerTextConverter;
import com.slprime.chromatictooltips.converter.ModifierConverter;
import com.slprime.chromatictooltips.enricher.ContextInfoEnricher;
import com.slprime.chromatictooltips.enricher.EnchantmentEnricher;
Expand Down Expand Up @@ -73,6 +74,7 @@ public void preInit(FMLPreInitializationEvent event) {
TooltipHandler.setRendererClass(TooltipRenderer.class);

TooltipRegistry.addLineConverter(ModifierConverter.PATTERN, new ModifierConverter());
TooltipRegistry.addLineConverter(DividerTextConverter.PATTERN, new DividerTextConverter());
TooltipRegistry.addLineConverter(DividerConverter.PATTERN, new DividerConverter());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.slprime.chromatictooltips.component;

import com.slprime.chromatictooltips.api.ITooltipComponent;
import com.slprime.chromatictooltips.api.TooltipContext;
import com.slprime.chromatictooltips.util.TooltipFontContext;

public class DividerTextComponent extends SpaceComponent {

protected int colorCodeIndex = -1;
protected int marginLeft = 0;
protected String text;
protected SpaceComponent right;

public DividerTextComponent(SpaceComponent left, SpaceComponent right, int height, int marginLeft,
int colorCodeIndex, String text) {
super(left);
this.height = height;
this.right = right;
this.colorCodeIndex = colorCodeIndex;
this.marginLeft = marginLeft;
this.text = text;
}

@Override
public ITooltipComponent[] paginate(TooltipContext context, int maxWidth, int maxHeight) {
this.mixColor = (0xFF << 24) | TooltipFontContext.getColor(this.colorCodeIndex);
this.right.mixColor = this.mixColor;
return new ITooltipComponent[] { this };
}

@Override
public int getWidth() {
return this.marginLeft + TooltipFontContext.getStringWidth(this.text);
}

@Override
public int getHeight() {
return Math.max(this.height, TooltipFontContext.getFontHeight());
}

protected void drawSegment(SpaceComponent space, int x, int y, int width, int height, TooltipContext context) {

if (space.decorators == null || width <= 0) {
return;
}

if (space.transform != null && space.transform.isAnimated()) {
space.transform.pushTransformMatrix(x, y, width, height, context.getAnimationStartTime());
x = y = 0;
}

space.decorators.draw(x, y, width, height, context, space.mixColor);

if (space.transform != null && space.transform.isAnimated()) {
space.transform.popTransformMatrix();
}
}

@Override
public void draw(int x, int y, int availableWidth, TooltipContext context) {
x += this.marginLeft;
availableWidth -= this.marginLeft;

final int blockHeight = getHeight();
final int textWidth = TooltipFontContext.getStringWidth(this.text);
final int lineWidth = Math.max(0, (availableWidth - textWidth) / 2);

drawSegment(this, x, y, lineWidth, blockHeight, context);
drawSegment(this.right, x + availableWidth - lineWidth, y, lineWidth, blockHeight, context);

final int textY = y + (blockHeight - TooltipFontContext.getFontHeight()) / 2;
TooltipFontContext.drawString(this.text, x + lineWidth, textY, this.mixColor);
}

@Override
public String toString() {
return "DividerTextTooltipComponent{height=" + this.height
+ ", colorCodeIndex="
+ this.colorCodeIndex
+ ", text="
+ this.text
+ "}";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.slprime.chromatictooltips.converter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.gson.JsonObject;
import com.slprime.chromatictooltips.api.ITooltipComponent;
import com.slprime.chromatictooltips.api.ITooltipLineConverter;
import com.slprime.chromatictooltips.api.TooltipContext;
import com.slprime.chromatictooltips.api.TooltipStyle;
import com.slprime.chromatictooltips.component.DividerTextComponent;
import com.slprime.chromatictooltips.component.SpaceComponent;
import com.slprime.chromatictooltips.util.TooltipFontContext;

public class DividerTextConverter implements ITooltipLineConverter {

public static final Pattern PATTERN = Pattern.compile(
"^(\\s*)(?:§[0-9a-fk-or])*§([0-9a-f])(?:§[0-9a-fk-or])*-{2,}(?:§r)?\\s+(.+?)\\s+(?:§[0-9a-fk-or])*-{2,}(?:§r)?$",
Pattern.CASE_INSENSITIVE);

@Override
public ITooltipComponent convert(Matcher matcher, TooltipContext context) {

if (matcher.matches()) {
final String colorCode = matcher.group(2);
final int colorCodeIndex = "0123456789abcdef".indexOf(colorCode.toLowerCase());
final int marginLeft = TooltipFontContext.getStringWidth(matcher.group(1));
final String text = matcher.group(3);

final TooltipStyle rendererStyle = context.getRenderer()
.getStyle();
final TooltipStyle style = rendererStyle.containsKey("dividerText")
? rendererStyle.getAsStyle("dividerText")
: new TooltipStyle(createDefaultStyle());

return new DividerTextComponent(
new SpaceComponent(style.getAsStyle("left")),
new SpaceComponent(style.getAsStyle("right")),
style.getAsInt("height", 10),
marginLeft,
colorCodeIndex,
text);
}

return null;
}

protected JsonObject createDefaultStyle() {
final JsonObject style = new JsonObject();

style.add("left", createSideStyle("marginRight"));
style.add("right", createSideStyle("marginLeft"));
style.addProperty("height", 10);

return style;
}

protected JsonObject createSideStyle(String marginProperty) {
final JsonObject decorator = new JsonObject();

decorator.addProperty("type", "background");
decorator.addProperty("color", "0xFFFFFFFF");
decorator.addProperty("alignBlock", "center");
decorator.addProperty(marginProperty, 4);
decorator.addProperty("height", 1);

final JsonObject side = new JsonObject();
side.add("decorator", decorator);

return side;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void drawItemStack(ItemStack stack, long stackAmount, boolean show
final TextureManager renderEngine = TooltipUtils.mc()
.getTextureManager();

drawIromIcon(() -> {
drawIcon(() -> {
itemRender.zLevel += 100.0F;
itemRender.renderItemAndEffectIntoGUI(font, renderEngine, stack, 0, 0);

Expand All @@ -126,7 +126,7 @@ public static void drawFluidStack(FluidStack stack, long stackAmount) {
return;
}

drawIromIcon(() -> {
drawIcon(() -> {
GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
TooltipUtils.bindTexture(TextureMap.locationBlocksTexture);
Expand All @@ -146,7 +146,7 @@ public static void drawFluidStack(FluidStack stack, long stackAmount) {

}

protected static void drawIromIcon(Runnable drawIcon, long stackAmount, boolean fluid) {
protected static void drawIcon(Runnable drawIcon, long stackAmount, boolean fluid) {
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
RenderHelper.enableGUIStandardItemLighting();

Expand Down
22 changes: 22 additions & 0 deletions src/main/resources/assets/chromatictooltips/tooltip.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@
"height": 10
},

"dividerText": {
"left": {
"decorator": {
"type": "background",
"color": "0xFFFFFFFF",
"alignBlock": "center",
"marginRight": 4,
"height": 1
}
},
"right": {
"decorator": {
"type": "background",
"color": "0xFFFFFFFF",
"alignBlock": "center",
"marginLeft": 4,
"height": 1
}
},
"height": 10
},

"sectionSpacing": 4,

"navigation": {
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/assets/chromatictooltips/tooltip.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@
"height": 10
},

"dividerText": {
"left": {
"decorator": {
"type": "background",
"color": "0xFFFFFFFF",
"alignBlock": "center",
"height": 1
}
},
"right": {
"decorator": {
"type": "background",
"color": "0xFFFFFFFF",
"alignBlock": "center",
"height": 1
}
},
"height": 10
},

"sectionSpacing": 4,

"navigation": {
Expand Down