Skip to content

Commit

Permalink
Merge pull request #43 from graycat27/textOutline#42
Browse files Browse the repository at this point in the history
  • Loading branch information
graycat27 authored Mar 25, 2021
2 parents 4721530 + 80029b2 commit 80e3b4a
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.graycat27.forge.flightHUDmod.consts;

public enum TextRenderType {
NORMAL,
SHADOW,
OUTLINE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<>();
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,26 +18,35 @@ 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");
}
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);
}

Expand Down Expand Up @@ -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){
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum GuiColor {
WHITE("FFFFFF"),
RED("FF3030"),
BLUE("00C0FF"),
BLACK("000000"),


DEFAULT("00FF44");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 80e3b4a

Please sign in to comment.