From 90fb4c2cdcd813d085e4c72d161b0efe06bcd164 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 6 Feb 2021 02:43:13 +0900 Subject: text hud go brrr --- .../features/text/TextHUDFeature.java | 45 +++++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java') 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 d8e72d68..d019f6bd 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java @@ -24,7 +24,7 @@ import java.util.Map; public abstract class TextHUDFeature extends GuiFeature { 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>("textStyles", "", "", new ArrayList(), "list_textstyle")); + this.parameters.put("textStyles", new FeatureParameter>("textStyles", "", "", new ArrayList(), "list_textStyle")); } @Override @@ -32,6 +32,13 @@ public abstract class TextHUDFeature extends GuiFeature { drawTextWithStylesAssociated(getText(), 0, 0, getStylesMap()); } + @Override + public void drawDemo(float partialTicks) { + drawTextWithStylesAssociated(getDummyText(), 0, 0, getStylesMap()); + } + + public abstract boolean isEnabled(); + public abstract List getUsedTextStyle(); public List getDummyText() { return getText(); @@ -41,13 +48,21 @@ public abstract class TextHUDFeature extends GuiFeature { public List getStyles() { return this.>getParameter("textStyles").getValue(); } + private Map stylesMap; public Map getStylesMap() { - List styles = getStyles(); - Map res = new HashMap(); - for (TextStyle ts:styles) { - res.put(ts.getGroupName(), ts); + if (stylesMap == null) { + List styles = getStyles(); + Map res = new HashMap(); + for (TextStyle ts : styles) { + res.put(ts.getGroupName(), ts); + } + for (String str : getUsedTextStyle()) { + if (!res.containsKey(str)) + res.put(str, new TextStyle(str, new AColor(0xffffffff, true))); + } + stylesMap = res; } - return res; + return stylesMap; } public List drawTextWithStylesAssociated(List texts, int x, int y, Map styleMap) { @@ -57,7 +72,7 @@ public abstract class TextHUDFeature extends GuiFeature { int maxHeightForLine = 0; List associateds = new ArrayList(); for (StyledText st : texts) { - TextStyle ts = styleMap.get(st); + TextStyle ts = styleMap.get(st.getGroup()); String[] lines = st.getText().split("\n"); for (int i = 0; i < lines.length; i++) { String str = lines[i]; @@ -68,11 +83,16 @@ public abstract class TextHUDFeature extends GuiFeature { maxHeightForLine = d.height; if (i+1 != lines.length) { - currY += maxHeightForLine; + currY += maxHeightForLine ; currX = x; maxHeightForLine = 0; } } + if (st.getText().endsWith("\n")) { + currY += maxHeightForLine ; + currX = x; + maxHeightForLine = 0; + } } return associateds; } @@ -84,7 +104,7 @@ public abstract class TextHUDFeature extends GuiFeature { int maxHeightForLine = 0; List associateds = new ArrayList(); for (StyledText st : texts) { - TextStyle ts = styleMap.get(st); + TextStyle ts = styleMap.get(st.getGroup()); String[] lines = st.getText().split("\n"); for (int i = 0; i < lines.length; i++) { String str = lines[i]; @@ -100,6 +120,11 @@ public abstract class TextHUDFeature extends GuiFeature { maxHeightForLine = 0; } } + if (st.getText().endsWith("\n")) { + currY += maxHeightForLine; + currX = x; + maxHeightForLine = 0; + } } return associateds; } @@ -134,7 +159,7 @@ public abstract class TextHUDFeature extends GuiFeature { ConfigPanelCreator.map.put("base." + getKey() , new Supplier() { @Override public MPanel get() { - return new PanelDefaultParameterConfig(config, TextHUDFeature.this); + return new PanelTextParameterConfig(config, TextHUDFeature.this); } }); return "base." + getKey() ; -- cgit