diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide')
11 files changed, 612 insertions, 103 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiConfig.java index 628e80ef..0da479db 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiConfig.java @@ -63,19 +63,24 @@ public class GuiConfig extends GuiScreen { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - GlStateManager.pushMatrix(); - GlStateManager.pushAttrib(); - GlStateManager.disableLighting(); - GlStateManager.disableFog();GL11.glDisable(GL11.GL_FOG); - GlStateManager.color(1,1,1,1); - GlStateManager.disableDepth(); - GlStateManager.depthMask(false); - mainPanel.render0(scaledResolution, new Point(0,0), new Rectangle(0,0,scaledResolution.getScaledWidth(),scaledResolution.getScaledHeight()), mouseX, mouseY, mouseX, mouseY, partialTicks); - GlStateManager.enableDepth(); - GlStateManager.depthMask(true); - GlStateManager.popAttrib(); - GlStateManager.popMatrix(); + try { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + GlStateManager.disableLighting(); + GlStateManager.disableFog(); + GL11.glDisable(GL11.GL_FOG); + GlStateManager.color(1, 1, 1, 1); + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + mainPanel.render0(scaledResolution, new Point(0, 0), new Rectangle(0, 0, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight()), mouseX, mouseY, mouseX, mouseY, partialTicks); + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + } catch (Throwable e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonDeaths.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonDeaths.java index 89fcc47c..ecf1d6fb 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonDeaths.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonDeaths.java @@ -7,40 +7,91 @@ import kr.syeyoung.dungeonsguide.features.FeatureParameter; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.features.listener.ChatListener; import kr.syeyoung.dungeonsguide.features.listener.TickListener; +import kr.syeyoung.dungeonsguide.features.text.StyledText; +import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature; import kr.syeyoung.dungeonsguide.utils.TextUtils; import net.minecraft.client.gui.FontRenderer; import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.ClientChatReceivedEvent; import org.lwjgl.opengl.GL11; +import scala.actors.threadpool.Arrays; import java.awt.*; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class FeatureDungeonDeaths extends GuiFeature implements ChatListener { +public class FeatureDungeonDeaths extends TextHUDFeature implements ChatListener { public FeatureDungeonDeaths() { super("Dungeon", "Display Deaths", "Display names of player and death count in dungeon run", "dungeon.stats.deaths", false, getFontRenderer().getStringWidth("longestplayernamepos: 100"), getFontRenderer().FONT_HEIGHT * 6); this.setEnabled(false); - parameters.put("color", new FeatureParameter<Color>("color", "Color", "Color of text", Color.orange, "color")); +// parameters.put("color", new FeatureParameter<Color>("color", "Color", "Color of text", Color.orange, "color")); } SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); @Override - public void drawHUD(float partialTicks) { - if (!skyblockStatus.isOnDungeon()) return; + public boolean isEnabled() { + if (!skyblockStatus.isOnDungeon()) return false; + DungeonContext context = skyblockStatus.getContext(); + if (context == null) return false; + return true; + } + + @Override + public List<String> getUsedTextStyle() { + return Arrays.asList(new String[] { + "username", "separator", "deaths", "total", "totalDeaths" + }); + } + + @Override + public List<StyledText> getText() { + + List<StyledText> text= new ArrayList<StyledText>(); + DungeonContext context = skyblockStatus.getContext(); - if (context == null) return; Map<String, Integer> deaths = context.getDeaths(); int i = 0; int deathsCnt = 0; - FontRenderer fr = getFontRenderer(); for (Map.Entry<String, Integer> death:deaths.entrySet()) { - fr.drawString(death.getKey()+": "+death.getValue(), 0,i, this.<Color>getParameter("color").getValue().getRGB()); - i += 8; - deathsCnt += death.getValue(); + text.add(new StyledText(death.getKey(),"username")); + text.add(new StyledText(": ","separator")); + text.add(new StyledText(death.getValue()+"\n","deaths")); } - fr.drawString("Total Deaths: "+deathsCnt, 0,i, this.<Color>getParameter("color").getValue().getRGB()); + text.add(new StyledText("Total Deaths","total")); + text.add(new StyledText(": ","separator")); + text.add(new StyledText(deathsCnt+"","totalDeaths")); + + return text; + } + + private static final List<StyledText> dummyText= new ArrayList<StyledText>(); + static { + dummyText.add(new StyledText("syeyoung","username")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("-130\n","deaths")); + dummyText.add(new StyledText("notsyeyoung","username")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("-13\n","deaths")); + dummyText.add(new StyledText("dungeonsguide","username")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("-42\n","deaths")); + dummyText.add(new StyledText("penguinman","username")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("0\n","deaths")); + dummyText.add(new StyledText("probablysalt","username")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("0\n","deaths")); + dummyText.add(new StyledText("Total Deaths","total")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("0","totalDeaths")); + } + + @Override + public List<StyledText> getDummyText() { + return dummyText; } public int getTotalDeaths() { @@ -54,17 +105,6 @@ public class FeatureDungeonDeaths extends GuiFeature implements ChatListener { return d; } - @Override - public void drawDemo(float partialTicks) { - FontRenderer fr = getFontRenderer(); - fr.drawString("syeyoung: -130", 0,0, this.<Color>getParameter("color").getValue().getRGB()); - fr.drawString("notsyeyoung: -13", 0,8, this.<Color>getParameter("color").getValue().getRGB()); - fr.drawString("dungeonsguide: -42", 0,16, this.<Color>getParameter("color").getValue().getRGB()); - fr.drawString("--not more--", 0,24, this.<Color>getParameter("color").getValue().getRGB()); - fr.drawString("--maybe more--", 0,32, this.<Color>getParameter("color").getValue().getRGB()); - fr.drawString("Total Deaths: 0", 0,40, this.<Color>getParameter("color").getValue().getRGB()); - } - Pattern deathPattern = Pattern.compile("§r§c ☠ (.+?)§r§7 .+and became a ghost.+"); Pattern meDeathPattern = Pattern.compile("§r§c ☠ §r§7You .+and became a ghost.+"); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMilestone.java b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMilestone.java index bb65cb2c..6f2a6912 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMilestone.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/impl/dungeon/FeatureDungeonMilestone.java @@ -8,6 +8,8 @@ import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.features.listener.ChatListener; import kr.syeyoung.dungeonsguide.features.listener.TickListener; +import kr.syeyoung.dungeonsguide.features.text.StyledText; +import kr.syeyoung.dungeonsguide.features.text.TextHUDFeature; import kr.syeyoung.dungeonsguide.utils.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -17,11 +19,14 @@ import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.ClientChatReceivedEvent; import org.lwjgl.opengl.GL11; +import scala.actors.threadpool.Arrays; import java.awt.*; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; -public class FeatureDungeonMilestone extends GuiFeature implements ChatListener { +public class FeatureDungeonMilestone extends TextHUDFeature implements ChatListener { public FeatureDungeonMilestone() { super("Dungeon", "Display Current Class Milestone", "Display current class milestone of yourself", "dungeon.stats.milestone", true, getFontRenderer().getStringWidth("Milestone: 12"), getFontRenderer().FONT_HEIGHT); this.setEnabled(false); @@ -29,30 +34,47 @@ public class FeatureDungeonMilestone extends GuiFeature implements ChatListener } SkyblockStatus skyblockStatus = e.getDungeonsGuide().getSkyblockStatus(); + + private static final List<StyledText> dummyText= new ArrayList<StyledText>(); + static { + dummyText.add(new StyledText("Milestone","title")); + dummyText.add(new StyledText(": ","separator")); + dummyText.add(new StyledText("9","number")); + } + @Override - public void drawHUD(float partialTicks) { - if (!skyblockStatus.isOnDungeon()) return; - FontRenderer fr = getFontRenderer(); - double scale = getFeatureRect().getHeight() / fr.FONT_HEIGHT; - GlStateManager.scale(scale, scale, 0); + public boolean isEnabled() { + return skyblockStatus.isOnDungeon(); + } + + @Override + public List<String> getUsedTextStyle() { + return Arrays.asList(new String[] { + "title", "separator", "number" + }); + } + + @Override + public List<StyledText> getDummyText() { + return dummyText; + } + + @Override + public List<StyledText> getText() { + List<StyledText> actualBit = new ArrayList<StyledText>(); + actualBit.add(new StyledText("Milestone","title")); + actualBit.add(new StyledText(": ","separator")); for (NetworkPlayerInfo networkPlayerInfoIn : Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()) { String name = networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName()); if (name.startsWith("§r Milestone: §r")) { String milestone = TextUtils.stripColor(name).substring(13); - fr.drawString("Milestone: "+milestone, 0,0, this.<Color>getParameter("color").getValue().getRGB()); - return; + actualBit.add(new StyledText(milestone+"","number")); + break; } } - fr.drawString("Milestone: ?", 0,0, this.<Color>getParameter("color").getValue().getRGB()); + return actualBit; } - @Override - public void drawDemo(float partialTicks) { - FontRenderer fr = getFontRenderer(); - double scale = getFeatureRect().getHeight() / fr.FONT_HEIGHT; - GlStateManager.scale(scale, scale, 0); - fr.drawString("Milestone: 9", 0,0, this.<Color>getParameter("color").getValue().getRGB()); - } public static final Pattern milestone_pattern = Pattern.compile("§r§e§l(.+) Milestone §r§e(.)§r§7: .+ §r§a(.+)§r"); 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 16f7cb74..4be95491 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java @@ -3,6 +3,7 @@ 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.config.types.AColor; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureParameter; import kr.syeyoung.dungeonsguide.features.text.StyledText; @@ -10,94 +11,142 @@ 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 kr.syeyoung.dungeonsguide.gui.elements.MColor; +import kr.syeyoung.dungeonsguide.gui.elements.MEditableAColor; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; 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.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import org.w3c.dom.css.Rect; import java.awt.*; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; +import java.util.*; import java.util.List; public class PanelTextParameterConfig extends MPanel { private TextHUDFeature feature; + private MEditableAColor currentColor; + @Override public void onBoundsUpdate() { } @Override public void resize(int parentWidth, int parentHeight) { - this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + this.setBounds(new Rectangle(5,5,parentWidth-10, parentHeight-10)); } private GuiConfig config; - public PanelTextParameterConfig(final GuiConfig config, TextHUDFeature feature) { + public PanelTextParameterConfig(final GuiConfig config, final TextHUDFeature feature) { this.config = config; - for (FeatureParameter parameter: feature.getParameters()) { - if (!parameter.getKey().equalsIgnoreCase("textStyles")) - add(new MParameter(feature, parameter, config)); - } + this.feature = feature; setBackgroundColor(new Color(38, 38, 38, 255)); + + currentColor = new MEditableAColor(); + currentColor.setColor(new AColor(0xff555555, true)); + currentColor.setEnableEdit(false); + currentColor.setSize(new Dimension(15, 10)); + currentColor.setBounds(new Rectangle(275 , 14, 15, 10)); + currentColor.setOnUpdate(new Runnable() { + @Override + public void run() { + for (String se:selected) + feature.getStylesMap().get(se).setColor(currentColor.getColor()); + } + }); + add(currentColor); } + private Set<String> selected = new HashSet<String>(); - 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; + GlStateManager.pushMatrix(); - 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); - } - } + int width = 200, height = 100; + Gui.drawRect(0,0,getBounds().width, getBounds().height, 0xFF444444); + Gui.drawRect(4,4,width+6, height+6, 0xFF222222); + Gui.drawRect(5,5,width+5, height+5, 0xFF555555); + Rectangle clip = new Rectangle(scissor.x + 5, scissor.y + 5, width, height); + clip(new ScaledResolution(Minecraft.getMinecraft()), clip.x, clip.y, clip.width, clip.height); - 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); + boolean bool =clip.contains(absMousex, absMousey); for (TextHUDFeature.StyleTextAssociated calc3: calc) { - if (calc3.getRectangle().contains(relMousex0, relMousey0)) { + 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, 0xFF44A800); + } else if (bool && 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); + 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, 0xFF777777); } - break; } } feature.drawTextWithStylesAssociated(texts, 5,5, styles); + clip(new ScaledResolution(Minecraft.getMinecraft()), scissor.x, scissor.y, scissor.width, scissor.height); - // draw actual logic + + GlStateManager.translate(5, height + 7, 0); + GlStateManager.scale(0.5,0.5,0); + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + fr.drawString("Press Shift to multi-select", 0, 0, 0xFFBFBFBF); GlStateManager.popMatrix(); - } + GlStateManager.pushMatrix(); + GlStateManager.translate(width + 15, 5, 0); + GlStateManager.pushMatrix(); + GlStateManager.scale(0.5,0.5,0); + fr.drawString("Selected Groups: "+selected, 0, 0, 0xFFBFBFBF); + GlStateManager.popMatrix(); + fr.drawString("Text Color: ", 0, 10, 0xFFFFFFFF); - public int offsetY = 0; + GlStateManager.popMatrix(); + } @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; - } + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + List<StyledText> texts = feature.getDummyText(); + Map<String, TextStyle> styles = feature.getStylesMap(); + boolean existed = selected.isEmpty(); + boolean found = false; + List<TextHUDFeature.StyleTextAssociated> calc = feature.calculate(texts, 5,5, styles); + for (TextHUDFeature.StyleTextAssociated calc3: calc) { + if (calc3.getRectangle().contains(relMouseX, relMouseY)) { + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + if (!selected.contains(calc3.getStyledText().getGroup())) + selected.add(calc3.getStyledText().getGroup()); + else + selected.remove(calc3.getStyledText().getGroup()); + } else { + selected.clear(); + selected.add(calc3.getStyledText().getGroup()); + } + found = true; + } + } + if (!found && !(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) && relMouseX >= 5 && relMouseX <= 205 && relMouseY >= 5 && relMouseY <= 105) { + selected.clear(); + } + currentColor.setEnableEdit(selected.size() != 0); + if (existed != selected.isEmpty()) { + if (selected.size() != 0) + currentColor.setColor(styles.get(selected.iterator().next()).getColor()); + else + currentColor.setColor(new AColor(0xff555555, true)); + } + + if (selected.size() == 1) + currentColor.setColor(styles.get(selected.iterator().next()).getColor()); + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java index aee344cd..904fd034 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/StyledText.java @@ -1,8 +1,10 @@ package kr.syeyoung.dungeonsguide.features.text; +import lombok.AllArgsConstructor; import lombok.Data; @Data +@AllArgsConstructor 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 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<List<TextStyle>>("textStyles", "", "", new ArrayList<TextStyle>(), "list_textstyle")); + this.parameters.put("textStyles", new FeatureParameter<List<TextStyle>>("textStyles", "", "", new ArrayList<TextStyle>(), "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<String> getUsedTextStyle(); public List<StyledText> getDummyText() { return getText(); @@ -41,13 +48,21 @@ public abstract class TextHUDFeature extends GuiFeature { public List<TextStyle> getStyles() { return this.<List<TextStyle>>getParameter("textStyles").getValue(); } + private Map<String, TextStyle> stylesMap; 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); + if (stylesMap == null) { + List<TextStyle> styles = getStyles(); + Map<String, TextStyle> res = new HashMap<String, TextStyle>(); + 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<StyleTextAssociated> drawTextWithStylesAssociated(List<StyledText> texts, int x, int y, Map<String, TextStyle> styleMap) { @@ -57,7 +72,7 @@ public abstract class TextHUDFeature extends GuiFeature { int maxHeightForLine = 0; List<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); 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<StyleTextAssociated> associateds = new ArrayList<StyleTextAssociated>(); 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<MPanel>() { @Override public MPanel get() { - return new PanelDefaultParameterConfig(config, TextHUDFeature.this); + return new PanelTextParameterConfig(config, TextHUDFeature.this); } }); return "base." + getKey() ; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextStyle.java b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextStyle.java index 74e3c66a..2353cd11 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextStyle.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/TextStyle.java @@ -1,11 +1,15 @@ package kr.syeyoung.dungeonsguide.features.text; import kr.syeyoung.dungeonsguide.config.types.AColor; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.awt.*; @Data +@AllArgsConstructor +@NoArgsConstructor public class TextStyle { private String groupName; private AColor color; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java index 50d5b85f..ce3dd669 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java @@ -119,7 +119,7 @@ public class MPanel { GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale); } - private Rectangle determineClip(Rectangle rect1, Rectangle rect2) { + protected Rectangle determineClip(Rectangle rect1, Rectangle rect2) { int minX = Math.max(rect1.x, rect2.x); int minY = Math.max(rect1.y, rect2.y); int maxX = Math.min(rect1.x + rect1.width, rect2.x + rect2.width); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java new file mode 100644 index 00000000..61b506c3 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java @@ -0,0 +1,80 @@ +package kr.syeyoung.dungeonsguide.gui.elements; + +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import net.minecraft.client.gui.Gui; + +import java.awt.*; + +@AllArgsConstructor +@NoArgsConstructor +public class MEditableAColor extends MPanel { + @Getter + @Setter + private AColor color = new AColor(0xffffffff, true); + @Getter + @Setter + private Dimension size = new Dimension(20,15); + + @Getter + @Setter + private boolean enableEdit = false; + + @Getter + @Setter + private Runnable onUpdate; + + public void setEnableEdit(boolean enableEdit) { + this.enableEdit = enableEdit; + if (portable != null && !enableEdit) { + remove(portable); + portable = null; + } + } + + private MPortableColorEdit portable = null; + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + Rectangle rectangle = getBounds(); + + int x = (rectangle.width - getSize().width) / 2; + int y = (rectangle.height - getSize().height) / 2; + if (color.isChroma()) + Gui.drawRect(x,y,x+getSize().width,y+getSize().height, RenderUtils.getChromaColorAt(absMousex - relMousex0, absMousey - relMousey0, color.getChromaSpeed())); + else + Gui.drawRect(x,y,x+getSize().width,y+getSize().height, getColor().getRGB()); + + Gui.drawRect(x,y,x+getSize().width,y+1, 0xff333333); + Gui.drawRect(x,y,x+1,y+getSize().height, 0xff333333); + Gui.drawRect(x+getSize().width-1,y,x+getSize().width,y+getSize().height, 0xff333333); + Gui.drawRect(x,y+getSize().height-1,x+getSize().width,y+getSize().height, 0xff333333); + } + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (!enableEdit) return; + if (lastAbsClip.contains(absMouseX, absMouseY) && portable == null) { + portable = new MPortableColorEdit() { + @Override + public void update2() { + MEditableAColor.this.color = portable.getColor(); + if (onUpdate != null) + onUpdate.run(); + } + }; + portable.setColor(color); + System.out.println(relMouseX+ " " +relMouseY); + portable.setBounds(new Rectangle(relMouseX, relMouseY, 100, 60)); + add(portable); + } else if (portable != null && !portable.getBounds().contains(relMouseX, relMouseY)) { + remove(portable); + portable = null; + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java new file mode 100644 index 00000000..fd4d49dc --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java @@ -0,0 +1,282 @@ +package kr.syeyoung.dungeonsguide.gui.elements; + +import kr.syeyoung.dungeonsguide.config.types.AColor; +import kr.syeyoung.dungeonsguide.gui.MPanel; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import lombok.Getter; +import lombok.Setter; +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 net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.MathHelper; +import org.lwjgl.opengl.GL11; + +import java.awt.*; + +public class MPortableColorEdit extends MPanel { + + private float[] hsv = new float[3]; + private float alpha = 0; + private float chromaSpeed = 0; + + @Getter + private AColor color; + + public void setColor(AColor color) { + this.color = color; + + alpha = color.getAlpha() / 255.0f; + chromaSpeed = color.isChroma() ? color.getChromaSpeed() : 0; + Color.RGBtoHSB(color.getRed(), color.getBlue(), color.getGreen(), hsv); + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + + Gui.drawRect(0,0,getSize().width,getSize().height, 0xff333333); + Gui.drawRect(1,1,getSize().width-1,getSize().height-1, 0xffa1a1a1); + + int width = getBounds().height- 10; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + int shademodel = GL11.glGetInteger(GL11.GL_SHADE_MODEL); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + GlStateManager.enableBlend(); + GlStateManager.disableDepth(); + GlStateManager.disableTexture2D(); + GlStateManager.disableCull();; + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + // worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR); + + int rgb = Color.HSBtoRGB(hsv[0], hsv[1], 1); + float r = (rgb >> 16 & 255) / 255.0f; + float g = (rgb >> 8 & 255) / 255.0f; + float b = (rgb & 255) / 255.0f; + GL11.glBegin(GL11.GL_TRIANGLES); + GlStateManager.color(0,0,0,alpha);GL11.glVertex3i(15+width ,5, 0); + GlStateManager.color(0,0,0,alpha);GL11.glVertex3i(10+width , 5, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(15+width , 5+width, 0); + + GlStateManager.color(0,0,0,alpha); GL11.glVertex3i(10+width , 5, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(10+width , 5 + width, 0); + GlStateManager.color(r,g,b,alpha);GL11.glVertex3i(15+width , 5+width, 0); + GL11.glEnd(); + rgb = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]); + r = (rgb >> 16 & 255) / 255.0f; + g = (rgb >> 8 & 255) / 255.0f; + b = (rgb & 255) / 255.0f; + GL11.glBegin(GL11.GL_TRIANGLES); + GlStateManager.color(r,g,b,0);GL11.glVertex3i(25+width ,5, 0); + GlStateManager.color(r,g,b,0);GL11.glVertex3i(20+width , 5, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(25+width , 5+width, 0); + + GlStateManager.color(r,g,b,0); GL11.glVertex3i(20+width , 5, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(20+width , 5+ width, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(25+width , 5+width, 0); + GL11.glEnd(); + + + GL11.glBegin(GL11.GL_TRIANGLES); + rgb = RenderUtils.getChromaColorAt(0,0, chromaSpeed); + r = (rgb >> 16 & 255) / 255.0f; + g = (rgb >> 8 & 255) / 255.0f; + b = (rgb & 255) / 255.0f; + GlStateManager.color(r,g,b,1);GL11.glVertex3i(35+width ,5, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(30+width , 5, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(35+width , 5+width, 0); + + GlStateManager.color(r,g,b,1); GL11.glVertex3i(30+width , 5, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(30+width , 5+ width, 0); + GlStateManager.color(r,g,b,1);GL11.glVertex3i(35+width , 5+width, 0); + GL11.glEnd(); + + + + float radius = width/2f; + float cx = 5 + radius; + float cy = 5 + radius; + + GL11.glBegin(GL11.GL_TRIANGLE_FAN); + GlStateManager.color(1,1,1,alpha); + GL11.glVertex3f(cx,cy,0); + for (int i = 0; i <= 360; i++) { + float rad = 3.141592653f * i / 180; + int rgb2 = Color.HSBtoRGB(i / 360f, 1, hsv[2]); + float r2 = (rgb2 >> 16 & 255) / 255.0f; + float g2 = (rgb2 >> 8 & 255) / 255.0f; + float b2 = (rgb2 & 255) / 255.0f; + GlStateManager.color(r2,g2,b2, alpha); + GL11.glVertex3f(MathHelper.cos(rad) * radius + cx, MathHelper.sin(rad) * radius + cy, 0); + } + GL11.glEnd(); + GlStateManager.shadeModel(shademodel); + + GlStateManager.color(1,1,1,1); + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION); + float rad2 = 2 * 3.141592653f * hsv[0] ; + float x = 5 + radius + (MathHelper.cos(rad2)) * hsv[1] * radius; + float y = 5 + radius + (MathHelper.sin(rad2))* hsv[1] * radius; + for (int i = 0; i < 100; i++) { + float rad = 2 * 3.141592653f * (i / 100f); + worldrenderer.pos(MathHelper.sin(rad) * 2 + x, MathHelper.cos(rad) * 2 + y, 0).endVertex(); + } + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(8+width, 5 + (hsv[2]) * width, 0.5).endVertex(); + worldrenderer.pos(17+width, 5 + (hsv[2]) * width, 0.5).endVertex(); + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(18+width, 5 + (alpha) * width, 0.5).endVertex(); + worldrenderer.pos(27+width, 5 + (alpha) * width, 0.5).endVertex(); + tessellator.draw(); + + worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + worldrenderer.pos(28+width, 5 + (chromaSpeed) * width, 0.5).endVertex(); + worldrenderer.pos(37+width, 5 + (chromaSpeed) * width, 0.5).endVertex(); + tessellator.draw(); + + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.color(1,1,1,1); + GlStateManager.color(1,1,1,1); + } + + @Override + public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + int relMousex = relMousex0 - getBounds().x; + int relMousey = relMousey0 - getBounds().y; + + GlStateManager.translate(getBounds().x, getBounds().y, 0); + GlStateManager.color(1,1,1,0); + + + Rectangle absBound = getBounds().getBounds(); + absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y); + Rectangle clip = determineClip(parentClip, absBound); + lastAbsClip = clip; + + clip(resolution, clip.x, clip.y, clip.width, clip.height); + GlStateManager.pushAttrib(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + + GlStateManager.pushAttrib(); + GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB()); + GlStateManager.popAttrib(); + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + + GL11.glEnable(GL11.GL_SCISSOR_TEST); + GlStateManager.popAttrib(); + + + Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y); + + for (MPanel mPanel : getChildComponents()){ + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); + GlStateManager.popAttrib(); + GlStateManager.popMatrix(); + } + } + + private int selected = 0; + + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + int width = getBounds().height- 10; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 5 + radius; + + selected = 0; + if (!getBounds().contains(relMouseX, relMouseY)) return; + + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (dx * dx + dy * dy <= radius * radius) { + double theta = (MathHelper.atan2(dx, dy) / Math.PI * 180 + 270) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.sqrt_float(dx * dx + dy * dy) / radius; + selected = 1; + } + } + { + if (10+width <= relMouseX && relMouseX <= 15 + width && + 5 <= relMouseY && relMouseY <= 5 + width) { + hsv[2] = (relMouseY - 5) / (float)width; + selected = 2; + } + } + { + if (20+width <= relMouseX && relMouseX <= 25 + width && + 5 <= relMouseY && relMouseY <= 5 + width) { + alpha = (relMouseY - 5) / (float)width; + selected = 3; + } + } + { + if (30+width <= relMouseX && relMouseX <= 35 + width && + 5 <= relMouseY && relMouseY <= 5 + width) { + chromaSpeed = (relMouseY - 5) / (float)width; + selected = 4; + } + } + update(); + } + + @Override + public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + int width = getBounds().height- 10; + float radius = width / 2f; + float circleX = 5 + radius; + float circleY = 5 + radius; + { + // check circle + float dx = relMouseX - circleX; + float dy = circleY - relMouseY; + if (selected == 1) { + double theta = (MathHelper.atan2(dx, dy) / Math.PI * 180 + 270) % 360; + hsv[0] = (float) theta / 360f; + hsv[1] = MathHelper.clamp_float(MathHelper.sqrt_float(dx * dx + dy * dy) / radius, 0, 1); + } + } + { + if (selected == 2) { + hsv[2] = MathHelper.clamp_float((relMouseY - 5) / (float)width, 0, 1); + } + if (selected == 3) { + alpha = MathHelper.clamp_float((relMouseY - 5) / (float)width, 0, 1); + } + if (selected == 4) { + chromaSpeed = MathHelper.clamp_float((relMouseY - 5) / (float)width, 0, 1); + } + } + update(); + } + + + public void update() { + color = new AColor(Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0xffffff | (MathHelper.clamp_int((int)(alpha * 255), 0, 255) << 24), true); + color.setChromaSpeed(chromaSpeed); + color.setChroma(chromaSpeed != 0); + update2(); + } + + public void update2() { + + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java index 7375122c..91a03662 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java @@ -71,8 +71,8 @@ public class RenderUtils { } 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); + double blah = ((double)(speed) * (System.currentTimeMillis() / 2)) % 360; + return Color.HSBtoRGB((float) (((blah - (x * x + y * y) / 50.0f) % 360) / 360.0f), 1,1); } public static WorldRenderer color(WorldRenderer worldRenderer, int color ){ |