aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-02-05 23:43:38 +0900
committersyeyoung <cyong06@naver.com>2021-02-05 23:43:38 +0900
commitfe4dfe76628650cdd186726f7e419e8a2c4a624e (patch)
tree529c624fa00a38081db4572ab35a003175711457 /src/main
parenteae4f215143ef9ce659f73c7d4e3dac08e894cec (diff)
downloadSkyblock-Dungeons-Guide-fe4dfe76628650cdd186726f7e419e8a2c4a624e.tar.gz
Skyblock-Dungeons-Guide-fe4dfe76628650cdd186726f7e419e8a2c4a624e.tar.bz2
Skyblock-Dungeons-Guide-fe4dfe76628650cdd186726f7e419e8a2c4a624e.zip
mnn text
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameter.java2
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java2
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyle.java11
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyleList.java24
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java103
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java9
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java124
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java5
8 files changed, 269 insertions, 11 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameter.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameter.java
index a712c08b..72cbf4b9 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameter.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/MParameter.java
@@ -31,7 +31,7 @@ public class MParameter extends MPanel {
private PanelDefaultParameterConfig config;
private MLabel label2;
- public MParameter(AbstractFeature abstractFeature, final FeatureParameter parameter, final PanelDefaultParameterConfig config, final GuiConfig config2) {
+ public MParameter(AbstractFeature abstractFeature, final FeatureParameter parameter, final GuiConfig config2) {
this.config = config;
this.parameter = parameter;
this.feature = abstractFeature;
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
index 708d510b..ee31fe36 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDefaultParameterConfig.java
@@ -36,7 +36,7 @@ public class PanelDefaultParameterConfig extends MPanel {
public PanelDefaultParameterConfig(final GuiConfig config, AbstractFeature feature) {
this.config = config;
for (FeatureParameter parameter: feature.getParameters()) {
- add(new MParameter(feature, parameter, this, config));
+ add(new MParameter(feature, parameter, config));
}
setBackgroundColor(new Color(38, 38, 38, 255));
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyle.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyle.java
index 3e43d65b..4965b3bd 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyle.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyle.java
@@ -1,6 +1,7 @@
package kr.syeyoung.dungeonsguide.config.types;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import kr.syeyoung.dungeonsguide.features.text.TextStyle;
@@ -14,11 +15,17 @@ public class TCTextStyle implements TypeConverter<TextStyle> {
@Override
public TextStyle deserialize(JsonElement element) {
- return new Color(element.getAsInt());
+ TextStyle textStyle = new TextStyle();
+ textStyle.setColor(TypeConverterRegistry.getTypeConverter("acolor", AColor.class).deserialize(element.getAsJsonObject().get("color")));
+ textStyle.setGroupName(element.getAsJsonObject().get("group").getAsString());
+ return textStyle;
}
@Override
public JsonElement serialize(TextStyle element) {
- return new JsonPrimitive(element.getRGB());
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("color", TypeConverterRegistry.getTypeConverter("acolor", AColor.class).serialize(element.getColor()));
+ jsonObject.addProperty("group", element.getGroupName());
+ return jsonObject;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyleList.java b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyleList.java
index 88a0aa66..4fd75da2 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyleList.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/config/types/TCTextStyleList.java
@@ -1,23 +1,37 @@
package kr.syeyoung.dungeonsguide.config.types;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
+import kr.syeyoung.dungeonsguide.features.text.TextStyle;
+import java.util.ArrayList;
import java.util.List;
-public class TCTextStyleList implements TypeConverter<List> {
+public class TCTextStyleList implements TypeConverter<List<TextStyle>> {
@Override
public String getTypeString() {
return "list_textStyle";
}
@Override
- public List deserialize(JsonElement element) {
- return new Color(element.getAsInt());
+ public List<TextStyle> deserialize(JsonElement element) {
+ JsonArray arr = element.getAsJsonArray();
+ TypeConverter<TextStyle> conv = TypeConverterRegistry.getTypeConverter("textstyle", TextStyle.class);
+ List<TextStyle> texts = new ArrayList<TextStyle>();
+ for (JsonElement element2:arr) {
+ texts.add(conv.deserialize(element2));
+ }
+ return texts;
}
@Override
- public JsonElement serialize(List element) {
- return new JsonPrimitive(element.getRGB());
+ public JsonElement serialize(List<TextStyle> element) {
+ JsonArray array = new JsonArray();
+ TypeConverter<TextStyle> conv = TypeConverterRegistry.getTypeConverter("textstyle", TextStyle.class);
+ for (TextStyle st:element) {
+ array.add(conv.serialize(st));
+ }
+ return array;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java
new file mode 100644
index 00000000..16f7cb74
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java
@@ -0,0 +1,103 @@
+package kr.syeyoung.dungeonsguide.features.text;
+
+import kr.syeyoung.dungeonsguide.config.guiconfig.FeatureEditPane;
+import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig;
+import kr.syeyoung.dungeonsguide.config.guiconfig.MParameter;
+import kr.syeyoung.dungeonsguide.features.AbstractFeature;
+import kr.syeyoung.dungeonsguide.features.FeatureParameter;
+import kr.syeyoung.dungeonsguide.features.text.StyledText;
+import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature;
+import kr.syeyoung.dungeonsguide.features.text.TextStyle;
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import kr.syeyoung.dungeonsguide.gui.elements.MButton;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.renderer.GlStateManager;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.List;
+
+public class PanelTextParameterConfig extends MPanel {
+
+ private TextHUDFeature feature;
+
+ @Override
+ public void onBoundsUpdate() {
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setBounds(new Rectangle(0,0,parentWidth, parentHeight));
+ }
+
+ private GuiConfig config;
+ public PanelTextParameterConfig(final GuiConfig config, TextHUDFeature feature) {
+ this.config = config;
+ for (FeatureParameter parameter: feature.getParameters()) {
+ if (!parameter.getKey().equalsIgnoreCase("textStyles"))
+ add(new MParameter(feature, parameter, config));
+ }
+ setBackgroundColor(new Color(38, 38, 38, 255));
+ }
+
+
+ MPanel within;
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ int heights = 100;
+ within = null;
+ for (MPanel panel:getChildComponents()) {
+ panel.setPosition(new Point(5, -offsetY + heights + 5));
+ heights += panel.getBounds().height;
+
+ if (panel.getBounds().contains(relMousex0,relMousey0)) within = panel;
+ }
+ renderStyleEdit(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor);
+ if (within instanceof MParameter) {
+ FeatureParameter feature = ((MParameter) within).getParameter();
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ FeatureEditPane.drawHoveringText(new ArrayList<String>(Arrays.asList(feature.getDescription().split("\n"))), relMousex0,relMousey0, Minecraft.getMinecraft().fontRendererObj);
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ }
+ }
+
+ public void renderStyleEdit(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ GlStateManager.pushMatrix();
+ GlStateManager.translate(0, -offsetY, 0);
+ List<StyledText> texts = feature.getDummyText();
+ Map<String, TextStyle> styles = feature.getStylesMap();
+ List<TextHUDFeature.StyleTextAssociated> calc = feature.calculate(texts, 5,5, styles);
+ for (TextHUDFeature.StyleTextAssociated calc3: calc) {
+ if (calc3.getRectangle().contains(relMousex0, relMousey0)) {
+ for (TextHUDFeature.StyleTextAssociated calc2 : calc) {
+ if (calc2.getStyledText() == calc3.getStyledText())
+ Gui.drawRect(calc2.getRectangle().x, calc2.getRectangle().y, calc2.getRectangle().x + calc2.getRectangle().width, calc2.getRectangle().y + calc2.getRectangle().height, 0xFF5E5E5E);
+ }
+ break;
+ }
+ }
+ feature.drawTextWithStylesAssociated(texts, 5,5, styles);
+
+ // draw actual logic
+ GlStateManager.popMatrix();
+ }
+
+
+ public int offsetY = 0;
+
+ @Override
+ public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
+ if (scrollAmount > 0) offsetY -= 20;
+ else if (scrollAmount < 0) offsetY += 20;
+ if (offsetY < 0) offsetY = 0;
+ }
+
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java
new file mode 100644
index 00000000..aee344cd
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java
@@ -0,0 +1,9 @@
+package kr.syeyoung.dungeonsguide.features.text;
+
+import lombok.Data;
+
+@Data
+public class StyledText {
+ private String text;
+ private String group;
+}
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 d2cf793d..d8e72d68 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextHUDFeature.java
@@ -1,9 +1,23 @@
package kr.syeyoung.dungeonsguide.features.text;
+import com.google.common.base.Supplier;
+import kr.syeyoung.dungeonsguide.config.guiconfig.ConfigPanelCreator;
+import kr.syeyoung.dungeonsguide.config.guiconfig.GuiConfig;
+import kr.syeyoung.dungeonsguide.config.guiconfig.PanelDefaultParameterConfig;
+import kr.syeyoung.dungeonsguide.config.types.AColor;
+import kr.syeyoung.dungeonsguide.features.AbstractFeature;
import kr.syeyoung.dungeonsguide.features.FeatureParameter;
import kr.syeyoung.dungeonsguide.features.GuiFeature;
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import kr.syeyoung.dungeonsguide.utils.RenderUtils;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import java.awt.*;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -13,10 +27,116 @@ public abstract class TextHUDFeature extends GuiFeature {
this.parameters.put("textStyles", new FeatureParameter<List<TextStyle>>("textStyles", "", "", new ArrayList<TextStyle>(), "list_textstyle"));
}
- public abstract List<String> getUsedTextStyle();
-
@Override
public void drawHUD(float partialTicks) {
+ drawTextWithStylesAssociated(getText(), 0, 0, getStylesMap());
+ }
+
+ public abstract List<String> getUsedTextStyle();
+ public List<StyledText> getDummyText() {
+ return getText();
+ }
+ public abstract List<StyledText> getText();
+ public List<TextStyle> getStyles() {
+ return this.<List<TextStyle>>getParameter("textStyles").getValue();
+ }
+ public Map<String, TextStyle> getStylesMap() {
+ List<TextStyle> styles = getStyles();
+ Map<String, TextStyle> res = new HashMap<String, TextStyle>();
+ for (TextStyle ts:styles) {
+ res.put(ts.getGroupName(), ts);
+ }
+ return res;
+ }
+
+ 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);
+ 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;
+ }
+ }
+ }
+ 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);
+ 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;
+ }
+ }
+ }
+ 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);
+
+ if (!style.getColor().isChroma()) {
+ fr.drawString(content, x, y, style.getColor().getRGB());
+ 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.getChromaColorAt(x + width, y, style.getColor().getChromaSpeed()));
+ width += fr.getCharWidth(charArr[i]);
+ }
+ return new Dimension(width, fr.FONT_HEIGHT);
+ }
+ }
+
+ @Override
+ public String getEditRoute(final GuiConfig config) {
+ ConfigPanelCreator.map.put("base." + getKey() , new Supplier<MPanel>() {
+ @Override
+ public MPanel get() {
+ return new PanelDefaultParameterConfig(config, TextHUDFeature.this);
+ }
+ });
+ return "base." + getKey() ;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java
index 68243d84..7375122c 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java
@@ -70,6 +70,11 @@ public class RenderUtils {
GlStateManager.disableBlend();
}
+ public static int getChromaColorAt(int x, int y, float speed) {
+ float blah = (speed * System.currentTimeMillis()) % 360;
+ return Color.HSBtoRGB((((blah + x * x + y * y) % 360) / 360.0f), 1,1);
+ }
+
public static WorldRenderer color(WorldRenderer worldRenderer, int color ){
return worldRenderer.color(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color &0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f);
}