diff options
author | syeyoung <cyong06@naver.com> | 2021-02-24 17:51:37 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-02-24 17:51:37 +0900 |
commit | 3b947abc9a467ac13fcf8ad542edae527d984360 (patch) | |
tree | d51352fe4162ac28cd6c8a47154ea9b8fdaaa2a9 /src/main/java/kr/syeyoung/dungeonsguide/features/text | |
parent | d9ebe7b909ab386f21ec15f2ab5e2c58a71391f9 (diff) | |
download | Skyblock-Dungeons-Guide-3b947abc9a467ac13fcf8ad542edae527d984360.tar.gz Skyblock-Dungeons-Guide-3b947abc9a467ac13fcf8ad542edae527d984360.tar.bz2 Skyblock-Dungeons-Guide-3b947abc9a467ac13fcf8ad542edae527d984360.zip |
portal warning
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/text')
4 files changed, 128 insertions, 100 deletions
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 3a87075c..adc4ca6d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java @@ -32,7 +32,7 @@ import java.util.List; public class PanelTextParameterConfig extends MPanel { - private TextHUDFeature feature; + private StyledTextProvider feature; private MEditableAColor currentColor; private MEditableAColor backgroundColor; @@ -48,7 +48,7 @@ public class PanelTextParameterConfig extends MPanel { } private GuiConfig config; - public PanelTextParameterConfig(final GuiConfig config, final TextHUDFeature feature) { + public PanelTextParameterConfig(final GuiConfig config, final StyledTextProvider feature) { this.config = config; this.feature = feature; setBackgroundColor(new Color(38, 38, 38, 255)); @@ -115,13 +115,13 @@ public class PanelTextParameterConfig extends MPanel { List<StyledText> texts = feature.getDummyText(); Map<String, TextStyle> styles = feature.getStylesMap(); - List<TextHUDFeature.StyleTextAssociated> calc = feature.drawTextWithStylesAssociated(texts, 0,0, styles); + List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.drawTextWithStylesAssociated(texts, 0,0, styles); boolean bool =clip.contains(absMousex, absMousey); - for (TextHUDFeature.StyleTextAssociated calc3: calc) { + for (StyledTextRenderer.StyleTextAssociated calc3: calc) { if (selected.contains(calc3.getStyledText().getGroup())) { Gui.drawRect(calc3.getRectangle().x, calc3.getRectangle().y, calc3.getRectangle().x + calc3.getRectangle().width, calc3.getRectangle().y + calc3.getRectangle().height, 0x4244A800); } else if (bool && calc3.getRectangle().contains((relMousex0-5 -offsetX) * scale , (relMousey0 - 5 - offsetY) * scale)) { - for (TextHUDFeature.StyleTextAssociated calc2 : calc) { + for (StyledTextRenderer.StyleTextAssociated calc2 : calc) { if (calc2.getStyledText().getGroup().equals(calc3.getStyledText().getGroup())) Gui.drawRect(calc2.getRectangle().x, calc2.getRectangle().y, calc2.getRectangle().x + calc2.getRectangle().width, calc2.getRectangle().y + calc2.getRectangle().height, 0x55777777); } @@ -163,8 +163,8 @@ public class PanelTextParameterConfig extends MPanel { Map<String, TextStyle> styles = feature.getStylesMap(); boolean existed = selected.isEmpty(); boolean found = false; - List<TextHUDFeature.StyleTextAssociated> calc = feature.calculate(texts, 0,0, styles); - for (TextHUDFeature.StyleTextAssociated calc3: calc) { + List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.calculate(texts, 0,0, styles); + for (StyledTextRenderer.StyleTextAssociated calc3: calc) { if (calc3.getRectangle().contains((relMouseX-5 -offsetX) * scale , (relMouseY - 5 - offsetY) * scale)) { if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { if (!selected.contains(calc3.getStyledText().getGroup())) diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextProvider.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextProvider.java new file mode 100644 index 00000000..e354b744 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextProvider.java @@ -0,0 +1,12 @@ +package kr.syeyoung.dungeonsguide.features.text; + +import java.util.List; +import java.util.Map; + +public interface StyledTextProvider { + List<StyledText> getDummyText(); + List<StyledText> getText(); + + List<TextStyle> getStyles(); + Map<String, TextStyle> getStylesMap(); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java new file mode 100644 index 00000000..b20b2f33 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledTextRenderer.java @@ -0,0 +1,106 @@ +package kr.syeyoung.dungeonsguide.features.text; + +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +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; + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int maxHeightForLine = 0; + List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); + for (StyledText st : texts) { + TextStyle ts = styleMap.get(st.getGroup()); + String[] lines = st.getText().split("\n"); + for (int i = 0; i < lines.length; i++) { + String str = lines[i]; + Dimension d = drawFragmentText(fr, str, ts, currX, currY, false); + associateds.add(new StyleTextAssociated(st, new Rectangle(currX, currY, d.width, d.height))); + currX += d.width; + if (maxHeightForLine < d.height) + maxHeightForLine = d.height; + + if (i+1 != lines.length) { + currY += maxHeightForLine ; + currX = x; + maxHeightForLine = 0; + } + } + if (st.getText().endsWith("\n")) { + currY += maxHeightForLine ; + currX = x; + maxHeightForLine = 0; + } + } + return associateds; + } + + public static List<StyleTextAssociated> calculate(List<StyledText> texts, int x, int y, Map<String, TextStyle> styleMap) { + int currX = x; + int currY = y; + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + int maxHeightForLine = 0; + List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); + for (StyledText st : texts) { + TextStyle ts = styleMap.get(st.getGroup()); + String[] lines = st.getText().split("\n"); + for (int i = 0; i < lines.length; i++) { + String str = lines[i]; + Dimension d = drawFragmentText(fr, str, ts, currX, currY, true); + associateds.add(new StyleTextAssociated(st, new Rectangle(currX, currY, d.width, d.height))); + currX += d.width; + if (maxHeightForLine < d.height) + maxHeightForLine = d.height; + + if (i+1 != lines.length) { + currY += maxHeightForLine; + currX = x; + maxHeightForLine = 0; + } + } + if (st.getText().endsWith("\n")) { + currY += maxHeightForLine; + currX = x; + maxHeightForLine = 0; + } + } + return associateds; + } + + @Data + @AllArgsConstructor + public static class StyleTextAssociated { + private StyledText styledText; + private Rectangle rectangle; + } + + public static Dimension drawFragmentText(FontRenderer fr, String content, TextStyle style, int x, int y, boolean stopDraw) { + if (stopDraw) + return new Dimension(fr.getStringWidth(content), fr.FONT_HEIGHT); + + Gui.drawRect(x,y, x+fr.getStringWidth(content), y + fr.FONT_HEIGHT, RenderUtils.getColorAt(x,y, style.getBackground())); + + if (!style.getColor().isChroma()) { + fr.drawString(content, x, y, style.getColor().getRGB(), style.isShadow()); + return new Dimension(fr.getStringWidth(content), fr.FONT_HEIGHT); + }else { + char[] charArr = content.toCharArray(); + int width = 0; + for (int i = 0; i < charArr.length; i++) { + fr.drawString(String.valueOf(charArr[i]), x + width, y, RenderUtils.getColorAt(x + width, y, style.getColor()), style.isShadow()); + width += fr.getCharWidth(charArr[i]); + } + return new Dimension(width, fr.FONT_HEIGHT); + } + } +} 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 c0e521f0..c80eb0db 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java @@ -21,7 +21,7 @@ import java.awt.*; import java.util.*; import java.util.List; -public abstract class TextHUDFeature extends GuiFeature { +public abstract class TextHUDFeature extends GuiFeature implements StyledTextProvider { 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("textStyles", new FeatureParameter<List<TextStyle>>("textStyles", "", "", new ArrayList<TextStyle>(), "list_textStyle")); @@ -37,7 +37,7 @@ public abstract class TextHUDFeature extends GuiFeature { double scale = getFeatureRect().getHeight() / (fr.FONT_HEIGHT* countLines(asd)); GlStateManager.scale(scale, scale, 0); } - drawTextWithStylesAssociated(getText(), 0, 0, getStylesMap()); + StyledTextRenderer.drawTextWithStylesAssociated(getText(), 0, 0, getStylesMap()); } } @@ -53,7 +53,7 @@ public abstract class TextHUDFeature extends GuiFeature { double scale = getFeatureRect().getHeight() / (fr.FONT_HEIGHT * countLines(asd)); GlStateManager.scale(scale, scale, 0); } - drawTextWithStylesAssociated(getDummyText(), 0, 0, getStylesMap()); + StyledTextRenderer.drawTextWithStylesAssociated(getDummyText(), 0, 0, getStylesMap()); } public int countLines(List<StyledText> texts) { @@ -97,96 +97,6 @@ public abstract class TextHUDFeature extends GuiFeature { return stylesMap; } - public List<StyleTextAssociated> drawTextWithStylesAssociated(List<StyledText> texts, int x, int y, Map<String, TextStyle> styleMap) { - int currX = x; - int currY = y; - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int maxHeightForLine = 0; - List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); - for (StyledText st : texts) { - TextStyle ts = styleMap.get(st.getGroup()); - String[] lines = st.getText().split("\n"); - for (int i = 0; i < lines.length; i++) { - String str = lines[i]; - Dimension d = drawFragmentText(fr, str, ts, currX, currY, false); - associateds.add(new StyleTextAssociated(st, new Rectangle(currX, currY, d.width, d.height))); - currX += d.width; - if (maxHeightForLine < d.height) - maxHeightForLine = d.height; - - if (i+1 != lines.length) { - currY += maxHeightForLine ; - currX = x; - maxHeightForLine = 0; - } - } - if (st.getText().endsWith("\n")) { - currY += maxHeightForLine ; - currX = x; - maxHeightForLine = 0; - } - } - return associateds; - } - - public List<StyleTextAssociated> calculate(List<StyledText> texts, int x, int y, Map<String, TextStyle> styleMap) { - int currX = x; - int currY = y; - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int maxHeightForLine = 0; - List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); - for (StyledText st : texts) { - TextStyle ts = styleMap.get(st.getGroup()); - String[] lines = st.getText().split("\n"); - for (int i = 0; i < lines.length; i++) { - String str = lines[i]; - Dimension d = drawFragmentText(fr, str, ts, currX, currY, true); - associateds.add(new StyleTextAssociated(st, new Rectangle(currX, currY, d.width, d.height))); - currX += d.width; - if (maxHeightForLine < d.height) - maxHeightForLine = d.height; - - if (i+1 != lines.length) { - currY += maxHeightForLine; - currX = x; - maxHeightForLine = 0; - } - } - if (st.getText().endsWith("\n")) { - currY += maxHeightForLine; - currX = x; - maxHeightForLine = 0; - } - } - return associateds; - } - - @Data - @AllArgsConstructor - public static class StyleTextAssociated { - private StyledText styledText; - private Rectangle rectangle; - } - - public Dimension drawFragmentText(FontRenderer fr, String content, TextStyle style, int x, int y, boolean stopDraw) { - if (stopDraw) - return new Dimension(fr.getStringWidth(content), fr.FONT_HEIGHT); - - Gui.drawRect(x,y, x+fr.getStringWidth(content), y + fr.FONT_HEIGHT, RenderUtils.getColorAt(x,y, style.getBackground())); - - if (!style.getColor().isChroma()) { - fr.drawString(content, x, y, style.getColor().getRGB(), style.isShadow()); - return new Dimension(fr.getStringWidth(content), fr.FONT_HEIGHT); - }else { - char[] charArr = content.toCharArray(); - int width = 0; - for (int i = 0; i < charArr.length; i++) { - fr.drawString(String.valueOf(charArr[i]), x + width, y, RenderUtils.getColorAt(x + width, y, style.getColor()), style.isShadow()); - width += fr.getCharWidth(charArr[i]); - } - return new Dimension(width, fr.FONT_HEIGHT); - } - } @Override public String getEditRoute(final GuiConfig config) { |