diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/consts/TextRenderType.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/consts/TextRenderType.java new file mode 100644 index 0000000..7fa9b2c --- /dev/null +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/consts/TextRenderType.java @@ -0,0 +1,7 @@ +package com.github.graycat27.forge.flightHUDmod.consts; + +public enum TextRenderType { + NORMAL, + SHADOW, + OUTLINE +} diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/Compass.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/Compass.java index 9c6e97e..d89e12b 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/Compass.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/Compass.java @@ -3,12 +3,15 @@ import com.github.graycat27.forge.flightHUDmod.consts.CompassScaleValue; import com.github.graycat27.forge.flightHUDmod.consts.DirectionValue; import com.github.graycat27.forge.flightHUDmod.consts.TextHorizontalPosition; +import com.github.graycat27.forge.flightHUDmod.consts.TextRenderType; import com.github.graycat27.forge.flightHUDmod.guiDisplay.IGuiValueDisplay; import com.github.graycat27.forge.flightHUDmod.guiDisplay.TextDisplay; import com.github.graycat27.forge.flightHUDmod.unit.Direction; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; +import javax.xml.soap.Text; + import static com.github.graycat27.forge.flightHUDmod.FlightHUDMod.modSettings; import java.util.ArrayList; @@ -44,7 +47,8 @@ private void initDisplayComponent(){ boolean isVisible = this.isDisplayed(); String text = ""; TextHorizontalPosition hPos = TextHorizontalPosition.CENTER; - degreesDisplay = new TextDisplay(centerPosX, posY + 2*height, width, height, isVisible, text, hPos); + TextRenderType rTy = TextRenderType.OUTLINE; + degreesDisplay = new TextDisplay(centerPosX, posY + 2*height, width, height, isVisible, text, hPos, rTy); //scale scaleDisplayList = new ArrayList<>(); @@ -61,12 +65,14 @@ private void initDisplayComponent(){ } text = scaleBuilder.toString(); width = mc.fontRenderer.getStringWidth(text); - scaleDisplayList.add(new TextDisplay(centerPosX, posY+height, width, height, isVisible, text, hPos)); + rTy = TextRenderType.NORMAL; + scaleDisplayList.add(new TextDisplay(centerPosX, posY+height, width, height, isVisible, text, hPos, rTy)); //中心マーク text = "‡"; width = mc.fontRenderer.getStringWidth(text); - scaleDisplayList.add(new TextDisplay(centerPosX, posY+height, width, height, isVisible, text, hPos)); + rTy = TextRenderType.SHADOW; + scaleDisplayList.add(new TextDisplay(centerPosX, posY+height, width, height, isVisible, text, hPos, rTy)); if(direction != null) { final double leftDirection = direction.value() - widthDgr / 2.0; @@ -80,36 +86,42 @@ private void initDisplayComponent(){ int deltaX = (int)((v.value() - direction.value()) * pxParDgr); text = v.toString(); width = mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.OUTLINE; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); text = "+"; width =mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.SHADOW; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY + height, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); continue; } if(leftDirection - Direction.ROUND <= v.value() && v.value() < rightDirection - Direction.ROUND){ int deltaX = (int)((v.value() - direction.value() + Direction.ROUND) * pxParDgr); text = v.toString(); width = mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.OUTLINE; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); text = "+"; width =mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.SHADOW; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY + height, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); continue; } if(leftDirection + Direction.ROUND <= v.value() && v.value() < rightDirection + Direction.ROUND){ int deltaX = (int)((v.value() - direction.value() - Direction.ROUND) * pxParDgr); text = v.toString(); width = mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.OUTLINE; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); text = "+"; width =mc.fontRenderer.getStringWidth(text); + rTy = TextRenderType.SHADOW; scaleDisplayList.add(new TextDisplay(centerPosX + deltaX, posY + height, - width, height, isVisible, text, hPos)); + width, height, isVisible, text, hPos, rTy)); continue; } } diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/HeightMeter.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/HeightMeter.java index b7bd620..e66574e 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/HeightMeter.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/HeightMeter.java @@ -1,6 +1,7 @@ package com.github.graycat27.forge.flightHUDmod.guiComponent; import com.github.graycat27.forge.flightHUDmod.consts.TextHorizontalPosition; +import com.github.graycat27.forge.flightHUDmod.consts.TextRenderType; import com.github.graycat27.forge.flightHUDmod.guiDisplay.IGuiValueDisplay; import com.github.graycat27.forge.flightHUDmod.guiDisplay.TextDisplay; import com.github.graycat27.forge.flightHUDmod.unit.Height; @@ -35,7 +36,8 @@ private void initDisplayComponent(){ boolean isVisible = this.isDisplayed(); String text = ""; TextHorizontalPosition hPos = TextHorizontalPosition.LEFT; - textDisplay = new TextDisplay(posX, posY, width, height, isVisible, text, hPos); + TextRenderType renderType = TextRenderType.OUTLINE; + textDisplay = new TextDisplay(posX, posY, width, height, isVisible, text, hPos, renderType); } @Override diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/PitchMeter.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/PitchMeter.java index 6f39fa3..4b0e81b 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/PitchMeter.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/PitchMeter.java @@ -2,6 +2,7 @@ import com.github.graycat27.forge.flightHUDmod.FlightHUDMod; import com.github.graycat27.forge.flightHUDmod.consts.TextHorizontalPosition; +import com.github.graycat27.forge.flightHUDmod.consts.TextRenderType; import com.github.graycat27.forge.flightHUDmod.guiDisplay.IGuiValueDisplay; import com.github.graycat27.forge.flightHUDmod.guiDisplay.TextDisplay; import com.github.graycat27.forge.flightHUDmod.unit.Pitch; @@ -60,13 +61,15 @@ private void initDisplayComponent(){ boolean isVisible = this.isDisplayed(); String text = ""; TextHorizontalPosition hPos = TextHorizontalPosition.LEFT; - pitchTextDisplay = new TextDisplay(posX+markWidth, centerY, pitchWidth, height, isVisible, text, hPos); + TextRenderType rTy = TextRenderType.OUTLINE; + pitchTextDisplay = new TextDisplay(posX+markWidth, centerY, pitchWidth, height, isVisible, text, hPos, rTy); hPos = TextHorizontalPosition.CENTER; - centerMarkTextDisplay = new TextDisplay(posX, centerY, markWidth, height, isVisible, text, hPos); + centerMarkTextDisplay = new TextDisplay(posX, centerY, markWidth, height, isVisible, text, hPos, rTy); //each 15° display degreesMarkTextDisplays = new ArrayList<>(); final double fov = mc.gameSettings.fov; + rTy = TextRenderType.SHADOW; if(pitch != null){ //fov = windowHeight view angle int interval = modSettings.getInterval(); @@ -103,7 +106,7 @@ private void initDisplayComponent(){ } int width = mc.fontRenderer.getStringWidth(angleText); IGuiValueDisplay angleDisplay = new TextDisplay(posX, dispPosY, - width, height, isVisible, angleText, hPos); + width, height, isVisible, angleText, hPos, rTy); degreesMarkTextDisplays.add(angleDisplay); } @@ -143,8 +146,9 @@ private void initDisplayComponent(){ getDgrString((int)flightDegrees) : getDgrStringDecimal1(flightDegrees); String flightPitchText = String.format("> %s <", flightPitch); int width = mc.fontRenderer.getStringWidth(flightPitchText); + rTy = TextRenderType.OUTLINE; speedPitchTextDisplay = new TextDisplay(posX, (int)(centerY - levelY), - width, height, isVisible, flightPitchText, hPos); + width, height, isVisible, flightPitchText, hPos, rTy); } } @@ -188,7 +192,7 @@ public void update() { pitch = new Pitch(player); initDisplayComponent(); - String val = String.format(" %s -", pitch.valToString()); + String val = String.format(" %s", pitch.valToString()); pitchTextDisplay.setDispValue(val); centerMarkTextDisplay.setDispValue(Line.mark); } diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/SpeedMeter.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/SpeedMeter.java index c566ac2..1a0ce2f 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/SpeedMeter.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiComponent/SpeedMeter.java @@ -1,6 +1,7 @@ package com.github.graycat27.forge.flightHUDmod.guiComponent; import com.github.graycat27.forge.flightHUDmod.consts.TextHorizontalPosition; +import com.github.graycat27.forge.flightHUDmod.consts.TextRenderType; import com.github.graycat27.forge.flightHUDmod.guiDisplay.IGuiValueDisplay; import com.github.graycat27.forge.flightHUDmod.guiDisplay.TextDisplay; import com.github.graycat27.forge.flightHUDmod.unit.Speed; @@ -43,23 +44,25 @@ private void initDisplayComponent(){ String unitText = "[m/s]"; int unitWidth = mc.fontRenderer.getStringWidth(unitText); TextHorizontalPosition unitPos = TextHorizontalPosition.LEFT; + TextRenderType rTy = TextRenderType.SHADOW; //init and display - horizonSpeedTextDisplay = new TextDisplay(posX + unitWidth, basePosY, width, height, isVisible, text, hPos); - speedUnitDisplay = new TextDisplay(posX - width, basePosY, unitWidth, height, isVisible, unitText, unitPos); + speedUnitDisplay = new TextDisplay(posX - width, basePosY, unitWidth, height, isVisible, unitText, unitPos, rTy); + rTy = TextRenderType.OUTLINE; + horizonSpeedTextDisplay = new TextDisplay(posX + 1 + unitWidth, basePosY, width, height, isVisible, text, hPos, rTy); if(speed != null && speed.getVerticalSpeed() >= 0){ //going UP verticalSpeedTextDisplay = new TextDisplay(posX, basePosY-height, - width, height, isVisible, text, hPos); + width, height, isVisible, text, hPos, rTy); actualSpeedTextDisplay = new TextDisplay(posX + width*2/3, basePosY - (int)(2.5*height), - width, height, isVisible, text, hPos); + width, height, isVisible, text, hPos, rTy); }else{ //going DOWN verticalSpeedTextDisplay = new TextDisplay(posX, basePosY+height, - width, height, isVisible, text, hPos); + width, height, isVisible, text, hPos, rTy); actualSpeedTextDisplay = new TextDisplay(posX + width*2/3, basePosY + (int)(2.5*height), - width, height, isVisible, text, hPos); + width, height, isVisible, text, hPos, rTy); } } diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiDisplay/TextDisplay.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiDisplay/TextDisplay.java index 0c8f6b5..d3facc8 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiDisplay/TextDisplay.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/guiDisplay/TextDisplay.java @@ -2,8 +2,10 @@ import com.github.graycat27.forge.flightHUDmod.FlightHUDMod; import com.github.graycat27.forge.flightHUDmod.consts.TextHorizontalPosition; +import com.github.graycat27.forge.flightHUDmod.consts.TextRenderType; import com.github.graycat27.forge.flightHUDmod.setting.GuiColor; +import com.github.graycat27.forge.flightHUDmod.util.TextRenderUtil; import com.mojang.blaze3d.matrix.MatrixStack; import net.minecraft.client.Minecraft; import org.apache.commons.lang3.math.NumberUtils; @@ -16,18 +18,23 @@ public class TextDisplay extends GuiDisplay implements IGuiValueDisplay { /** 禁止パターン 改行を含む場合 */ private static final Pattern denyPattern = Pattern.compile(".*\\R.*"); private final TextHorizontalPosition hPos; + private final TextRenderType renderType; public TextDisplay(int posX, int posY, int width, int height, boolean isVisible, - String text, TextHorizontalPosition hPos){ + String text, TextHorizontalPosition hPos, TextRenderType renderType){ super(posX, posY, width, height, isVisible); if(hPos == null){ throw new IllegalArgumentException("TextDisplay constructor param was null : hPos"); } + if(renderType == null){ + throw new IllegalArgumentException("TextDisplay constructor param was null : renderType"); + } this.hPos = hPos; + this.renderType = renderType; setDispValue(text); } public TextDisplay(int posX, int posY, int width, int height, boolean isVisible, - String text, TextHorizontalPosition hPos, GuiColor color){ + String text, TextHorizontalPosition hPos, TextRenderType renderType, GuiColor color){ super(posX, posY, width, height, isVisible, color); if(hPos == null){ throw new IllegalArgumentException("TextDisplay constructor param was null : hPos"); @@ -35,7 +42,11 @@ public TextDisplay(int posX, int posY, int width, int height, boolean isVisible, if(color == null){ throw new IllegalArgumentException("TextDisplay constructor param was null : color"); } + if(renderType == null){ + throw new IllegalArgumentException("TextDisplay constructor param was null : renderType"); + } this.hPos = hPos; + this.renderType = renderType; setDispValue(text); } @@ -90,8 +101,16 @@ private void drawText(){ break; } - Minecraft.getInstance().fontRenderer.drawStringWithShadow(new MatrixStack(), - getDispValue(), fixPosX, fixPosY, getColor().getInt()); + switch (renderType){ + case SHADOW: + TextRenderUtil.drawStringWithShadow(getDispValue(), fixPosX, fixPosY, getColor()); + break; + case OUTLINE: + TextRenderUtil.drawStringWithOutLine(getDispValue(), fixPosX, fixPosY, getColor(), GuiColor.BLACK); + break; + default: + TextRenderUtil.drawString(getDispValue(), fixPosX, fixPosY, getColor()); + } } private boolean isAllowedPattern(String text){ @@ -106,7 +125,7 @@ public TextDisplay clone(){ TextDisplay obj = null; try{ obj = new TextDisplay(getDispPosX(), getDispPosY(), getDispWidth(), getDispHeight(), - isVisible(), getDispValue(), this.hPos, getColor()); + isVisible(), getDispValue(), this.hPos, this.renderType, getColor()); }catch(IllegalArgumentException e){ FlightHUDMod.getLogger().warn("couldn't make clone object", e); } diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/setting/GuiColor.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/setting/GuiColor.java index e0f8313..ca117ee 100644 --- a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/setting/GuiColor.java +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/setting/GuiColor.java @@ -8,6 +8,7 @@ public enum GuiColor { WHITE("FFFFFF"), RED("FF3030"), BLUE("00C0FF"), + BLACK("000000"), DEFAULT("00FF44"); diff --git a/project/src/main/java/com/github/graycat27/forge/flightHUDmod/util/TextRenderUtil.java b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/util/TextRenderUtil.java new file mode 100644 index 0000000..8961230 --- /dev/null +++ b/project/src/main/java/com/github/graycat27/forge/flightHUDmod/util/TextRenderUtil.java @@ -0,0 +1,28 @@ +package com.github.graycat27.forge.flightHUDmod.util; + +import com.github.graycat27.forge.flightHUDmod.setting.GuiColor; +import com.mojang.blaze3d.matrix.MatrixStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; + +public class TextRenderUtil { + + private static Minecraft mc = Minecraft.getInstance(); + private static FontRenderer fRnd = mc.fontRenderer; + + public static void drawString(String text, int posX, int posY, GuiColor color){ + fRnd.drawString(new MatrixStack(), text, (float)posX, (float)posY, color.getInt()); + } + + public static void drawStringWithShadow(String text, int posX, int posY, GuiColor color){ + fRnd.drawStringWithShadow(new MatrixStack(), text, (float)posX, (float)posY, color.getInt()); + } + + public static void drawStringWithOutLine(String text, int posX, int posY, GuiColor foreColor, GuiColor backColor){ + drawString(text, posX-1, posY, backColor); + drawString(text, posX+1, posY, backColor); + drawString(text, posX, posY-1, backColor); + drawString(text, posX, posY+1, backColor); + drawString(text, posX, posY, foreColor); + } +}