diff options
author | syeyoung <cyong06@naver.com> | 2021-08-03 17:23:41 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-08-03 17:23:41 +0900 |
commit | 982e460c861579f49959c08e25505a27e9c6b3f0 (patch) | |
tree | 4cccbe086fd69f5f5be138a3eb24237e0211b76e /src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java | |
parent | d1c36c2412b98350f8336e38361e49b3655982d5 (diff) | |
download | Skyblock-Dungeons-Guide-982e460c861579f49959c08e25505a27e9c6b3f0.tar.gz Skyblock-Dungeons-Guide-982e460c861579f49959c08e25505a27e9c6b3f0.tar.bz2 Skyblock-Dungeons-Guide-982e460c861579f49959c08e25505a27e9c6b3f0.zip |
Too many changes to describe
Config gui overhaul. v2
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java | 270 |
1 files changed, 156 insertions, 114 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 904aaaee..beeff007 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/text/PanelTextParameterConfig.java @@ -21,7 +21,10 @@ package kr.syeyoung.dungeonsguide.features.text; import kr.syeyoung.dungeonsguide.config.types.AColor; import kr.syeyoung.dungeonsguide.gui.MPanel; import kr.syeyoung.dungeonsguide.gui.elements.MEditableAColor; +import kr.syeyoung.dungeonsguide.gui.elements.MPanelScaledGUI; +import kr.syeyoung.dungeonsguide.gui.elements.MScrollablePanel; import kr.syeyoung.dungeonsguide.gui.elements.MToggleButton; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -43,12 +46,15 @@ public class PanelTextParameterConfig extends MPanel { private final MEditableAColor backgroundColor; private final MToggleButton shadow; + private MScrollablePanel mScrollablePanel; + private MPanelScaledGUI rendering; + @Override public void onBoundsUpdate() { } @Override public Dimension getPreferredSize() { - return new Dimension(400, 120); + return new Dimension(400, getPanelBound().height + 20); } public PanelTextParameterConfig(final StyledTextProvider feature) { @@ -59,7 +65,6 @@ public class PanelTextParameterConfig extends MPanel { 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() { @@ -72,7 +77,6 @@ public class PanelTextParameterConfig extends MPanel { backgroundColor.setColor(new AColor(0xff555555, true)); backgroundColor.setEnableEdit(false); backgroundColor.setSize(new Dimension(15, 10)); - backgroundColor.setBounds(new Rectangle(415 , 14, 15, 10)); backgroundColor.setOnUpdate(new Runnable() { @Override public void run() { @@ -83,7 +87,6 @@ public class PanelTextParameterConfig extends MPanel { add(backgroundColor); shadow = new MToggleButton(); shadow.setSize(new Dimension(20, 10)); - shadow.setBounds(new Rectangle(275 , 30, 20, 10)); shadow.setOnToggle(new Runnable() { @Override public void run() { @@ -93,6 +96,139 @@ public class PanelTextParameterConfig extends MPanel { }); add(shadow); + mScrollablePanel = new MScrollablePanel(3); + mScrollablePanel.setHideScrollBarWhenNotNecessary(true); + add(mScrollablePanel); + + mScrollablePanel.add(rendering = new MPanelScaledGUI() { + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + super.render(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor); + + List<StyledText> texts = feature.getDummyText(); + Map<String, TextStyle> styles = feature.getStylesMap(); + List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.drawTextWithStylesAssociated(texts, 0,0, getEffectiveDimension().width, styles, StyledTextRenderer.Alignment.LEFT); + boolean bool =scissor.contains(absMousex, absMousey); + 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, relMousey0)) { + 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); + } + } + } + } + + + private int lastX; + private int lastY; + private boolean dragStart = false; + @Override + 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<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.calculate(texts, 0,0, styles); + for (StyledTextRenderer.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)) && parent.getLastAbsClip().contains(absMouseX * getScale(), absMouseY* getScale())) { + selected.clear(); + dragStart = true; + lastX = absMouseX; + lastY = absMouseY; + } + currentColor.setEnableEdit(selected.size() != 0); + PanelTextParameterConfig.this.backgroundColor.setEnableEdit(selected.size() != 0); + if (existed != selected.isEmpty()) { + if (selected.size() != 0) { + currentColor.setColor(styles.get(selected.iterator().next()).getColor()); + PanelTextParameterConfig.this.backgroundColor.setColor(styles.get(selected.iterator().next()).getBackground()); + shadow.setEnabled(styles.get(selected.iterator().next()).isShadow()); + } else { + currentColor.setColor(new AColor(0xff555555, true)); + PanelTextParameterConfig.this.backgroundColor.setColor(new AColor(0xff555555, true)); + shadow.setEnabled(false); + } + } + + if (selected.size() == 1) { + currentColor.setColor(styles.get(selected.iterator().next()).getColor()); + PanelTextParameterConfig.this.backgroundColor.setColor(styles.get(selected.iterator().next()).getBackground()); + shadow.setEnabled(styles.get(selected.iterator().next()).isShadow()); + } + } + + @Override + public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { + dragStart = false; + } + + @Override + public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + if (dragStart) { + int dx= absMouseX - lastX; + int dy= absMouseY - lastY; + int actualOFFX = (int) (dx / getScale()); + int actualOFFY = (int) (dy / getScale()); + lastX =(int) (actualOFFX * getScale())+lastX; + lastY =(int) (actualOFFY * getScale())+lastY; + mScrollablePanel.getScrollBarX().addToCurrent(-actualOFFX); + mScrollablePanel.getScrollBarY().addToCurrent(-actualOFFY); + } + } + + @Override + public Dimension getPreferredSize() { + List<StyledTextRenderer.StyleTextAssociated> calc = StyledTextRenderer.calculate(feature.getDummyText(), 0,0, feature.getStylesMap()); + int w = 0, h = 0; + for (StyledTextRenderer.StyleTextAssociated styleTextAssociated : calc) { + int endX = styleTextAssociated.getRectangle().x + styleTextAssociated.getRectangle().width; + int endY = styleTextAssociated.getRectangle().y + styleTextAssociated.getRectangle().height; + if (endX > w) w = endX; + if (endY > h) h = endY; + } + return new Dimension((int) (w * getScale()),(int) (h * getScale())); + } + + @Override + public void resize(int parentWidth, int parentHeight) { + setBounds(new Rectangle(new Point(0,0), getPreferredSize())); + } + + + @Override + public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { + if ( parent.getLastAbsClip().contains(absMouseX * getScale(), absMouseY* getScale())) { + double scale = rendering.getScale(); + if (scrollAmount > 0) { + scale += 0.1; + } else if (scrollAmount < 0) { + scale -= 0.1; + } + if (scale < 0.1) scale = 0.1f; + if (scale > 5) scale = 5.0f; + rendering.setScale(scale); + mScrollablePanel.setBounds(new Rectangle(new Point(5,5),getPanelBound())); + } + } + }); + } @@ -103,35 +239,12 @@ public class PanelTextParameterConfig extends MPanel { GlStateManager.pushMatrix(); - int width = 200, height = 100; - Gui.drawRect(0,0,getBounds().width, getBounds().height, 0xFF444444); + Dimension dim = getPanelBound(); + int width = dim.width, height = dim.height; + Gui.drawRect(0,0,getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.12f)); 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(clip.x, clip.y, clip.width, clip.height); - - GlStateManager.pushMatrix(); - GlStateManager.translate(offsetX + 5, offsetY + 5, 0); - GlStateManager.scale(scale, scale, 0); - - - List<StyledText> texts = feature.getDummyText(); - Map<String, TextStyle> styles = feature.getStylesMap(); - 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())) { - 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 (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); - } - } - } - clip(scissor.x, scissor.y, scissor.width, scissor.height); + Gui.drawRect(5,5,width+5, height+5, RenderUtils.blendAlpha(0x141414, 0.15f)); - GlStateManager.popMatrix(); GlStateManager.translate(5, height + 7, 0); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; @@ -147,96 +260,25 @@ public class PanelTextParameterConfig extends MPanel { fr.drawString("Selected Groups: "+selected, 0, 0, 0xFFBFBFBF); GlStateManager.popMatrix(); fr.drawString("Text Color: ", 0, 10, 0xFFFFFFFF); - fr.drawString("Background Color: ", 100, 10, 0xFFFFFFFF); - fr.drawString("Shadow: ", 0, 26, 0xFFFFFFFF); + fr.drawString("Background Color: ", 0, 20, 0xFFFFFFFF); + fr.drawString("Shadow: ", 0, 39, 0xFFFFFFFF); GlStateManager.popMatrix(); } - private int offsetX = 0; - private int offsetY = 0; - private float scale = 1; - - private int lastX; - private int lastY; - private boolean dragStart = false; - @Override - 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<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())) - 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(); - dragStart = true; - lastX = absMouseX; - lastY = absMouseY; - } - currentColor.setEnableEdit(selected.size() != 0); - backgroundColor.setEnableEdit(selected.size() != 0); - if (existed != selected.isEmpty()) { - if (selected.size() != 0) { - currentColor.setColor(styles.get(selected.iterator().next()).getColor()); - backgroundColor.setColor(styles.get(selected.iterator().next()).getBackground()); - shadow.setEnabled(styles.get(selected.iterator().next()).isShadow()); - } else { - currentColor.setColor(new AColor(0xff555555, true)); - backgroundColor.setColor(new AColor(0xff555555, true)); - shadow.setEnabled(false); - } - } - - if (selected.size() == 1) { - currentColor.setColor(styles.get(selected.iterator().next()).getColor()); - backgroundColor.setColor(styles.get(selected.iterator().next()).getBackground()); - shadow.setEnabled(styles.get(selected.iterator().next()).isShadow()); - } - } - - @Override - public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { - dragStart = false; + private Dimension getPanelBound(){ +// return new Dimension((getBounds().width-25)/2, 100); + return new Dimension(150,100); } @Override - public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { - if (dragStart) { - offsetX += absMouseX - lastX; - offsetY += absMouseY - lastY; - lastX = absMouseX; - lastY = absMouseY; - - if (offsetX < 0) offsetX = 0; - if (offsetY < 0) offsetY =0; - } - } + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); - @Override - public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { - if ( relMouseX0 >= 5 && relMouseX0 <= 205 && relMouseY0 >= 5 && relMouseY0 <= 105) { - if (scrollAmount > 0) { - scale += 0.1; - } else if (scrollAmount < 0) { - scale -= 0.1; - } - if (scale < 0.1) scale = 0.1f; - if (scale > 5) scale = 5.0f; - } + Dimension dim = getPanelBound(); + currentColor.setBounds(new Rectangle(75+dim.width , 14, 15, 10)); + backgroundColor.setBounds(new Rectangle(110+dim.width , 24, 15, 10)); + shadow.setBounds(new Rectangle(75+dim.width , 43, 30, 10)); + mScrollablePanel.setBounds(new Rectangle(5,5,dim.width,dim.height)); } } |