aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-05-15 18:59:20 +0900
committersyeyoung <cyong06@naver.com>2021-05-15 18:59:20 +0900
commit63388918589d76702abde59d8af48a0319283027 (patch)
tree367379ae3c6d7115cb671013bd664fb98cd321b2 /src/main
parente330634ad3a79cb6c010762509dbecfc2c587bce (diff)
downloadSkyblock-Dungeons-Guide-63388918589d76702abde59d8af48a0319283027.tar.gz
Skyblock-Dungeons-Guide-63388918589d76702abde59d8af48a0319283027.tar.bz2
Skyblock-Dungeons-Guide-63388918589d76702abde59d8af48a0319283027.zip
Text alignment
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java10
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java2
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java26
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java12
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRedRoom.java2
5 files changed, 39 insertions, 13 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java
index 663d7893..d6a45487 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/secret/FeatureMechanicBrowse.java
@@ -209,6 +209,9 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPreRenderLis
fr.drawString("Cancel Current", 3, i * fr.FONT_HEIGHT, 0xFF00FFFF);
} else {
Gui.drawRect(-1, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF444444);
+ GlStateManager.enableBlend();
+ GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
fr.drawString((String)obj, 3, i * fr.FONT_HEIGHT, 0xFFEEEEEE);
}
}
@@ -226,14 +229,19 @@ public class FeatureMechanicBrowse extends GuiFeature implements GuiPreRenderLis
if (new Rectangle(feature.x + feature.width, popupStart.y + i * fr.FONT_HEIGHT, feature.width, fr.FONT_HEIGHT).contains(mouseX, mouseY)) {
Gui.drawRect(-2, i * fr.FONT_HEIGHT, feature.width - 3, i * fr.FONT_HEIGHT + fr.FONT_HEIGHT - 1, 0xFF555555);
}
+ GlStateManager.enableBlend();
+ GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
fr.drawString(possibleStates.get(i), 0, i * fr.FONT_HEIGHT, 0xFFFFFFFF);
}
}
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GlStateManager.popMatrix();
- GlStateManager.enableBlend();
GlStateManager.enableTexture2D();
+ GlStateManager.enableBlend();
+ GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
private void clip(ScaledResolution resolution, int x, int y, int width, int height) {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java
index 0201e262..23132b3a 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java
@@ -135,7 +135,7 @@ public class PanelTextParameterConfig extends MPanel {
List<StyledText> texts = feature.getDummyText();
Map<String, TextStyle> styles = feature.getStylesMap();
- List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.drawTextWithStylesAssociated(texts, 0,0, styles);
+ List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.drawTextWithStylesAssociated(texts, 0,0, getBounds().width, styles, StyledTextRenderer.Alignment.LEFT);
boolean bool =clip.contains(absMousex, absMousey);
for (StyledTextRenderer.StyleTextAssociated calc3: calc) {
if (selected.contains(calc3.getStyledText().getGroup())) {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java
index 01ce7d3b..fc37cf70 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java
@@ -32,12 +32,24 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
public class StyledTextRenderer {
- public static List<StyleTextAssociated> drawTextWithStylesAssociated(List<StyledText> texts, int x, int y, Map<String, TextStyle> styleMap) {
- int currX = x;
- int currY = y;
+
+ public static enum Alignment {
+ LEFT, CENTER, RIGHT
+ }
+
+
+
+ public static List<StyleTextAssociated> drawTextWithStylesAssociated(List<StyledText> texts, int x, int y,int width, Map<String, TextStyle> styleMap, Alignment alignment) {
+ String[] totalLines = texts.stream().map( a-> a.getText()).collect(Collectors.joining()).split("\n");
+
+
+ int currentLine = 0;
FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+ int currX = alignment == Alignment.LEFT ? x : alignment == Alignment.CENTER ? (x+width-fr.getStringWidth(totalLines[currentLine]))/2 : (x+width-fr.getStringWidth(totalLines[currentLine]));
+ int currY = y;
int maxHeightForLine = 0;
List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>();
for (StyledText st : texts) {
@@ -53,13 +65,15 @@ public class StyledTextRenderer {
if (i+1 != lines.length) {
currY += maxHeightForLine ;
- currX = x;
+ currentLine++;
+ currX = alignment == Alignment.LEFT ? x : alignment == Alignment.CENTER ? (x+width-fr.getStringWidth(totalLines[currentLine]))/2 : (x+width-fr.getStringWidth(totalLines[currentLine]));
maxHeightForLine = 0;
}
}
if (st.getText().endsWith("\n")) {
- currY += maxHeightForLine ;
- currX = x;
+ currY += maxHeightForLine;
+ currentLine++;
+ currX = alignment == Alignment.LEFT ? x : alignment == Alignment.CENTER ? (x+width-fr.getStringWidth(totalLines[currentLine]))/2 : (x+width-fr.getStringWidth(totalLines[currentLine]));
maxHeightForLine = 0;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java
index d2e4f79f..470c4d77 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java
@@ -43,6 +43,8 @@ public abstract class TextHUDFeature extends GuiFeature implements StyledTextPro
protected TextHUDFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) {
super(category, name, description, key, keepRatio, width, height);
this.parameters.put("textStylesNEW", new FeatureParameter<List<TextStyle>>("textStylesNEW", "", "", new ArrayList<TextStyle>(), "list_textStyle"));
+ this.parameters.put("alignRight", new FeatureParameter<Boolean>("alignRight", "Align Right", "Align text to right", false, "boolean"));
+ this.parameters.put("alignCenter", new FeatureParameter<Boolean>("alignCenter", "Align Center", "Align text to center (overrides alignright)", false, "boolean"));
}
@Override
@@ -50,12 +52,13 @@ public abstract class TextHUDFeature extends GuiFeature implements StyledTextPro
if (isHUDViewable()) {
List<StyledText> asd = getText();
+ double scale = 1;
if (doesScaleWithHeight()) {
FontRenderer fr = getFontRenderer();
- double scale = getFeatureRect().getRectangle().getHeight() / (fr.FONT_HEIGHT* countLines(asd));
+ scale = getFeatureRect().getRectangle().getHeight() / (fr.FONT_HEIGHT* countLines(asd));
GlStateManager.scale(scale, scale, 0);
}
- StyledTextRenderer.drawTextWithStylesAssociated(getText(), 0, 0, getStylesMap());
+ StyledTextRenderer.drawTextWithStylesAssociated(getText(), 0, 0, (int) (Math.abs(getFeatureRect().getWidth())/scale), getStylesMap(),this.<Boolean>getParameter("alignCenter").getValue() ? StyledTextRenderer.Alignment.CENTER : this.<Boolean>getParameter("alignRight").getValue() ? StyledTextRenderer.Alignment.RIGHT : StyledTextRenderer.Alignment.LEFT);
}
}
@@ -66,12 +69,13 @@ public abstract class TextHUDFeature extends GuiFeature implements StyledTextPro
@Override
public void drawDemo(float partialTicks) {
List<StyledText> asd = getDummyText();
+ double scale = 1;
if (doesScaleWithHeight()) {
FontRenderer fr = getFontRenderer();
- double scale = getFeatureRect().getRectangle().getHeight() / (fr.FONT_HEIGHT * countLines(asd));
+ scale = getFeatureRect().getRectangle().getHeight() / (fr.FONT_HEIGHT * countLines(asd));
GlStateManager.scale(scale, scale, 0);
}
- StyledTextRenderer.drawTextWithStylesAssociated(getDummyText(), 0, 0, getStylesMap());
+ StyledTextRenderer.drawTextWithStylesAssociated(getDummyText(), 0, 0, (int) (Math.abs(getFeatureRect().getWidth())/scale), getStylesMap(),this.<Boolean>getParameter("alignCenter").getValue() ? StyledTextRenderer.Alignment.CENTER : this.<Boolean>getParameter("alignRight").getValue() ? StyledTextRenderer.Alignment.RIGHT : StyledTextRenderer.Alignment.LEFT);
}
public int countLines(List<StyledText> texts) {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRedRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRedRoom.java
index bb897cd6..0ae66bf7 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRedRoom.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorRedRoom.java
@@ -106,7 +106,7 @@ public class RoomProcessorRedRoom extends GeneralRoomProcessor {
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- StyledTextRenderer.drawTextWithStylesAssociated(featureWarningOnPortal.getText(), 0, 0, featureWarningOnPortal.getStylesMap());
+ StyledTextRenderer.drawTextWithStylesAssociated(featureWarningOnPortal.getText(), 0, 0,0, featureWarningOnPortal.getStylesMap(), StyledTextRenderer.Alignment.LEFT);
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
GlStateManager.depthMask(true);