diff options
author | syeyoung <cyong06@naver.com> | 2021-08-01 23:43:10 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-08-01 23:43:10 +0900 |
commit | d1c36c2412b98350f8336e38361e49b3655982d5 (patch) | |
tree | 34f2d6396f69840f623254b5c6e50c3563f5cfda /src/main/java/kr/syeyoung/dungeonsguide/gui | |
parent | 16a4367663f5ed2a909804de6d319c97c9854ecc (diff) | |
download | Skyblock-Dungeons-Guide-d1c36c2412b98350f8336e38361e49b3655982d5.tar.gz Skyblock-Dungeons-Guide-d1c36c2412b98350f8336e38361e49b3655982d5.tar.bz2 Skyblock-Dungeons-Guide-d1c36c2412b98350f8336e38361e49b3655982d5.zip |
Too many changes to describe
Config gui overhaul.
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
14 files changed, 159 insertions, 104 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java index d523c923..f086c997 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java @@ -111,6 +111,7 @@ public class MGui extends GuiScreen { try { Mouse.setNativeCursor(null); + mainPanel.setCursor(EnumCursor.DEFAULT); } catch (LWJGLException e) { e.printStackTrace(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java index 126d69b6..99010090 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java @@ -153,9 +153,9 @@ public class MPanel { GlStateManager.popAttrib(); GlStateManager.popMatrix(); if (debug && lastAbsClip.contains(absMousex, absMousey)) { - Gui.drawRect(0, 0, getBounds().width, getBounds().height, 0x2200FF00); GL11.glDisable(GL11.GL_SCISSOR_TEST); -// Gui.drawRect(0, 0, getPreferredSize().width, getPreferredSize().height, 0x220000FF); + Gui.drawRect(0, 0, getBounds().width, getBounds().height, 0x2200FF00); + Gui.drawRect(0, 0, getPreferredSize().width, getPreferredSize().height, 0x220000FF); } GL11.glDisable(GL11.GL_SCISSOR_TEST); @@ -175,7 +175,7 @@ public class MPanel { public void clip(int x, int y, int width, int height) { if (width < 0 || height < 0) return; - GL11.glScissor((int) (x * scale), Minecraft.getMinecraft().displayHeight - (int) ((y + height) * scale), (int)(width* scale), (int) (height * scale)); + GL11.glScissor((int) (x * scale), Minecraft.getMinecraft().displayHeight - (int) ((y + height) * scale), (int)(width* scale + scale) - 1, (int) (height * scale + scale) - 1); } protected Rectangle determineClip(Rectangle rect1, Rectangle rect2) { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java index 1a1f30d4..ff8061e7 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java @@ -41,6 +41,7 @@ public class MButton extends MPanel { private int background = RenderUtils.blendAlpha(0xFF141414, 0.08f); private int hover = RenderUtils.blendAlpha(0xFF141414, 0.14f); private int clicked = RenderUtils.blendAlpha(0xFF141414, 0.16f); + private int border = 0x0; private int disabled =0xFF141414; private boolean enabled = true; @@ -59,8 +60,12 @@ public class MButton extends MPanel { } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) { bg = hover; } - Gui.drawRect(0,0,getBounds().width, getBounds().height, bg); - + if (((border >> 24) & 0xFF) == 0) + Gui.drawRect(0,0,getBounds().width, getBounds().height, bg); + else { + Gui.drawRect(0, 0, getBounds().width, getBounds().height, border); + Gui.drawRect(1, 1, getBounds().width-1, getBounds().height-1, bg); + } FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; int width = renderer.getStringWidth(getText()); int x = (getBounds().width - width) / 2; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java index 20fa2c93..85b86f40 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MCollapsable.java @@ -84,7 +84,7 @@ public class MCollapsable extends MPanel { super.render0(scale, parentPoint, parentClip, absMousex, absMousey, relMousex0, relMousey0, partialTicks); clip(lastAbsClip.x, lastAbsClip.y, lastAbsClip.width, lastAbsClip.height); -// GL11.glEnable(GL11.GL_SCISSOR_TEST); + GL11.glEnable(GL11.GL_SCISSOR_TEST); GlStateManager.pushMatrix(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java index f47f1fd0..888d1e03 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MEditableAColor.java @@ -25,6 +25,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.opengl.GL11; @@ -80,7 +81,7 @@ public class MEditableAColor extends MPanel { @Override public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { if (!enableEdit) return; - if (lastAbsClip.contains(absMouseX, absMouseY) && portable == null) { + if (lastAbsClip.contains(absMouseX, absMouseY) && getTooltipsOpen() == 0) { portable = new MPortableColorEdit() { @Override public void update2() { @@ -91,11 +92,16 @@ public class MEditableAColor extends MPanel { } }; portable.setColor(color); - portable.setBounds(new Rectangle(relMouseX, relMouseY, 100, 90)); - add(portable); - } else if (portable != null && !portable.getBounds().contains(relMouseX, relMouseY)) { - remove(portable); - portable = null; + Rectangle startWith = new Rectangle((int)(absMouseX * getScale()), (int) (absMouseY* getScale()), (int) (100 * getScale()), (int) (90 * getScale())); + if (startWith.x < 10) startWith.x = 10; + if (startWith.y < 10) startWith.y = 10; + if (startWith.x + startWith.width > Minecraft.getMinecraft().displayWidth - 10) startWith.x = Minecraft.getMinecraft().displayWidth - 10 - startWith.width; + if (startWith.y + startWith.height > Minecraft.getMinecraft().displayHeight - 10) startWith.y = Minecraft.getMinecraft().displayHeight - 10 - startWith.height; + portable.setBounds(startWith); + + + portable.setScale(2.0f); + portable.open(this); } } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java index 9719f63f..8823087e 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java @@ -43,8 +43,9 @@ public class MList extends MPanel { int y = 0; for (MPanel childComponent : getChildComponents()) { Dimension preferedSize = childComponent.getPreferredSize(); - childComponent.setBounds(new Rectangle(0, y, bounds.width, Math.max(10, preferedSize.height))); - y += preferedSize.height; + int height = Math.max(10, preferedSize.height); + childComponent.setBounds(new Rectangle(0, y, bounds.width, height)); + y += height; if (gap > 0) y += gap; } @@ -57,8 +58,9 @@ public class MList extends MPanel { int h = 0; for (MPanel childComponent : getChildComponents()) { Dimension preferedSize = childComponent.getPreferredSize(); + int height = Math.max(10, preferedSize.height); if (preferedSize.width > maxW) maxW = preferedSize.width; - h += preferedSize.height; + h += height; if (gap > 0) h += gap; } return new Dimension(maxW, Math.max(0, h-gap)); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java index 4a1d30ee..169e99b5 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPanelScaledGUI.java @@ -30,15 +30,16 @@ import java.awt.*; public class MPanelScaledGUI extends MPanel { @Getter - private double scale = 1.0; + protected double scale = 1.0; - private double relativeScale; + protected double relativeScale; public void setScale(double scale) { this.scale = scale; for (MPanel childComponent : childComponents) { childComponent.resize0((int) (getBounds().width/scale), (int) (getBounds().height/scale)); } + onBoundsUpdate(); } @Override @@ -84,6 +85,7 @@ public class MPanelScaledGUI extends MPanel { GlStateManager.scale(this.scale, this.scale, 1); clip = new Rectangle((int) (clip.x / scale), (int) (clip.y / scale), (int) (clip.width / scale), (int) (clip.height / scale)); + lastAbsClip = clip; this.relativeScale = parentScale * this.scale; @@ -119,7 +121,7 @@ public class MPanelScaledGUI extends MPanel { for (MPanel mPanel : getChildComponents()){ GlStateManager.pushMatrix(); GlStateManager.pushAttrib(); - mPanel.render0(scale, newPt,clip,absMousex, absMousey, relMousex, relMousey, partialTicks); + mPanel.render0(relativeScale, newPt,clip,absMousex, absMousey, relMousex, relMousey, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java index 9bd3b130..6b2f162e 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MPortableColorEdit.java @@ -36,7 +36,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; -public class MPortableColorEdit extends MPanel { +public class MPortableColorEdit extends MTooltip { private final float[] hsv = new float[3]; private float alpha = 0; @@ -71,7 +71,7 @@ public class MPortableColorEdit extends MPanel { public void onBoundsUpdate() { super.onBoundsUpdate(); - textField.setBounds(new Rectangle(5, getBounds().height - 25, getBounds().width - 10, 20)); + textField.setBounds(new Rectangle(5, getEffectiveDimension().height - 25, getEffectiveDimension().width - 10, 20)); } public void setColor(AColor color) { @@ -88,11 +88,12 @@ public class MPortableColorEdit extends MPanel { @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + Dimension size = getEffectiveDimension(); - Gui.drawRect(0,0,getSize().width,getSize().height, 0xff333333); - Gui.drawRect(1,1,getSize().width-1,getSize().height-1, 0xffa1a1a1); + Gui.drawRect(0,0,size.width,size.height, 0xff333333); + Gui.drawRect(1,1,size.width-1,size.height-1, 0xffa1a1a1); - int width = getBounds().height- 35; + int width = size.height- 35; Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); int shademodel = GL11.glGetInteger(GL11.GL_SHADE_MODEL); @@ -200,60 +201,20 @@ public class MPortableColorEdit extends MPanel { GlStateManager.color(1,1,1,1); } - @Override - public void render0(double scale, 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; -this.scale =scale; - clip(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(scale, newPt, new Rectangle(newPt, new Dimension(getBounds().getSize())), 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- 35; + int width = getEffectiveDimension().height- 35; float radius = width / 2f; float circleX = 5 + radius; float circleY = 5 + radius; selected = 0; - if (!getBounds().contains(relMouseX, relMouseY)) return; + if (!lastAbsClip.contains(absMouseX, absMouseY)) { + close(); + return; + } { // check circle @@ -292,7 +253,7 @@ this.scale =scale; @Override public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { - int width = getBounds().height- 35; + int width = getEffectiveDimension().height- 35; float radius = width / 2f; float circleX = 5 + radius; float circleY = 5 + radius; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java index 1797297a..82e91dab 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java @@ -42,6 +42,30 @@ public class MScrollBar extends MPanel { @Setter private int width = 10; + public void setMax(int max) { + this.max = max; + + current = MathHelper.clamp_int(current, min, max - thumbSize); + if (max - min < thumbSize) current = min; + if (onUpdate != null) onUpdate.run(); + } + + public void setMin(int min) { + this.min = min; + + current = MathHelper.clamp_int(current, min, max - thumbSize); + if (max - min < thumbSize) current = min; + if (onUpdate != null) onUpdate.run(); + } + + public void setThumbSize(int thumbSize) { + this.thumbSize = thumbSize; + + current = MathHelper.clamp_int(current, min, max - thumbSize); + if (max - min < thumbSize) current = min; + if (onUpdate != null) onUpdate.run(); + } + public void addToCurrent(int dv) { int current2 = current + dv; @@ -72,6 +96,12 @@ public class MScrollBar extends MPanel { this.onUpdate = onUpdate; } + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + lastThumbRect.width = 0; lastThumbRect.height = 0; + } + private Rectangle lastThumbRect = new Rectangle(); @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { @@ -156,7 +186,8 @@ public class MScrollBar extends MPanel { public void mouseMoved(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0) { if (grabbed) setCursor(EnumCursor.CLOSED_HAND); - else if (lastThumbRect.contains(relMouseX0, relMouseY0)) + else if (lastThumbRect.contains(relMouseX0, relMouseY0)) { setCursor(EnumCursor.OPEN_HAND); + } } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java index 42a3cb91..d09b7c5a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java @@ -102,9 +102,9 @@ public class MScrollablePanel extends MPanel { public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { super.render(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor); - boolean hideX = false, hideY = false; - if (bounds.width > contentAreaDim.width && hideScrollBarWhenNotNecessary) hideX = true; - if (bounds.height > contentAreaDim.height && hideScrollBarWhenNotNecessary) hideY = true; + boolean hideX = (axis & 2) == 0, hideY = (axis & 1) == 0; + if (bounds.width >= contentAreaDim.width && hideScrollBarWhenNotNecessary) hideX = true; + if (bounds.height >= contentAreaDim.height && hideScrollBarWhenNotNecessary) hideY = true; if (axis == 3 && !(hideX && hideY)) { Gui.drawRect(scrollBarX.getBounds().width, scrollBarY.getBounds().height, getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.03f)); } @@ -161,6 +161,7 @@ public class MScrollablePanel extends MPanel { scrollBarX.setThumbSize(viewPort.getBounds().width); scrollBarY.setThumbSize(viewPort.getBounds().height); + evalulateContentArea(); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java index 95882085..7666865a 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java @@ -48,6 +48,8 @@ public class MStringSelectionButton extends MPanel { dec = new MButton(); dec.setText("<"); add(dec); inc = new MButton(); inc.setText(">"); add(inc); selected = new MLabel(); updateSelected(); add(selected); + selected.setBackgroundColor(Color.black); + selected.setAlignment(MLabel.Alignment.CENTER); dec.setOnActionPerformed(new Runnable() { @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java index 6054a68f..b61837a4 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java @@ -22,11 +22,13 @@ import kr.syeyoung.dungeonsguide.gui.MPanel; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import kr.syeyoung.dungeonsguide.utils.cursor.EnumCursor; import lombok.Getter; +import lombok.Setter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.MathHelper; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; @@ -39,8 +41,11 @@ import java.io.IOException; @Getter public class MTextField extends MPanel { private final Color foreground = Color.white; + private final Color placeHolderColor = Color.lightGray; private String text = ""; + @Setter + private String placeHolder = ""; private int cursorBlickTicker = 0; private int selectionStart = 0; @@ -62,9 +67,22 @@ public class MTextField extends MPanel { edit(text); } + private void setCursor0(int cursor) { + if (cursor > text.length()) cursor = text.length(); + if (cursor < 0) cursor = 0; + this.cursor = cursor; + + + int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text.substring(0, cursor)); + int cursorX = width + 3- xOffset; + cursorX = MathHelper.clamp_int(cursorX,10, getBounds().width - 10); + xOffset = width+ 3 - cursorX; + xOffset = MathHelper.clamp_int(xOffset, 0,Math.max(0, Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) - getBounds().width+10)); + } @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { + clip(clip.x - 1, clip.y - 1, clip.width +2, clip.height + 2); Gui.drawRect(0,0,getBounds().width, getBounds().height, isFocused ? Color.white.getRGB() : Color.gray.getRGB()); Gui.drawRect(1,1,getBounds().width - 1, getBounds().height - 1, Color.black.getRGB()); @@ -76,6 +94,8 @@ public class MTextField extends MPanel { GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); fr.drawString(text, 3 - xOffset, y, foreground.getRGB()); + if (text.isEmpty()) + fr.drawString(placeHolder, 3, y, placeHolderColor.getRGB()); // draw selection if (isFocused) { if (selectionStart != -1) { @@ -90,7 +110,7 @@ public class MTextField extends MPanel { // draw cursor if (cursor != -1) { - if (cursor > text.length()) cursor = text.length(); + if (cursor > text.length()) setCursor0(text.length()); int x = fr.getStringWidth(text.substring(0, cursor)) - xOffset; cursorBlickTicker++; if (cursorBlickTicker < 10) @@ -120,11 +140,11 @@ public class MTextField extends MPanel { for (int i = 0; i < text.length(); i++) { int totalWidth = fr.getStringWidth(text.substring(0, i)); if (offseted < totalWidth) { - cursor = i; + setCursor0(i); return; } } - cursor = text.length(); + setCursor0(text.length()); } @Override @@ -184,31 +204,35 @@ public class MTextField extends MPanel { if (selectionStart == -1) { if (keycode == 199) { // home - cursor = 0; + setCursor0(0); + xOffset = 0; return; } if (keycode == 207) { // end - cursor = text.length(); + setCursor0(text.length()); + + int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text); + xOffset = Integer.max(0, width - getBounds().width+10); return; } if (keycode == 203) { // left - cursor--; - if (cursor < 0) cursor = 0; + setCursor0(this.cursor-1);; + if (cursor < 0) setCursor0(0); return; } if (keycode == 205) { // right - cursor ++; - if (cursor > text.length()) cursor = text.length(); + setCursor0(this.cursor+1); + if (cursor > text.length()) setCursor0(text.length()); return; } // backspace if (keycode == 14 && cursor > 0) { - setText0(this.text.substring(0, cursor - 1) + this.text.substring(cursor)); - cursor--; + setText0(this.text.substring(0, cursor-1) + this.text.substring(cursor)); + setCursor0(this.cursor-1); return; } @@ -257,30 +281,33 @@ public class MTextField extends MPanel { this.text.substring(0, this.cursor) + typedChar + this.text.substring(this.cursor)); - this.cursor++; + this.setCursor0(this.cursor+1);; return; } } else { if (keycode == 199) { // home - cursor = 0; + setCursor0(0); selectionStart = -1; + xOffset =0; return; } if (keycode == 207) { // end selectionStart = -1; - cursor = text.length(); + setCursor0(text.length()); + int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text); + xOffset = Integer.max(0, width - getBounds().width+10); return; } if (keycode == 203) { // left - cursor = selectionStart; + setCursor0(selectionStart); selectionStart = -1; return; } if (keycode == 205) { // right - cursor = selectionEnd; + setCursor0(selectionEnd); selectionStart = -1; return; } @@ -288,7 +315,7 @@ public class MTextField extends MPanel { // backspace if (keycode == 14 && cursor > 0) { setText0(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd)); - cursor = selectionStart; + setCursor0(selectionStart); selectionStart = -1; return; } @@ -296,7 +323,7 @@ public class MTextField extends MPanel { //del if (keycode == 211 && cursor < text.length()) { setText0(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd)); - cursor = selectionStart; + setCursor0(selectionStart); selectionStart = -1; return; } @@ -323,7 +350,7 @@ public class MTextField extends MPanel { this.text.substring(0, this.selectionStart) + theText + this.text.substring(this.selectionEnd)); - cursor = this.selectionStart + theText.toString().length(); + setCursor0(this.selectionStart + theText.toString().length()); } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { @@ -358,7 +385,7 @@ public class MTextField extends MPanel { this.text.substring(0, this.selectionStart) + typedChar + this.text.substring(this.selectionEnd)); - this.cursor = this.selectionStart + 1; + this.setCursor0(this.selectionStart + 1); selectionStart = -1; return; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java index d3a3fe06..5709906f 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java @@ -38,14 +38,16 @@ public class MToggleButton extends MPanel { private boolean enabled = true; private Runnable onToggle; + private int border = 0xFF333333, background = 0xFF171717; + @Override public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { Dimension bounds = getSize(); int gap = 1; - Gui.drawRect(0, 0, bounds.width, bounds.height, 0xFF333333); - Gui.drawRect(gap, gap, bounds.width-gap, bounds.height-gap, 0xFF171717); + Gui.drawRect(0, 0, bounds.width, bounds.height, border); + Gui.drawRect(gap, gap, bounds.width-gap, bounds.height-gap, background); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java index 7492f17d..89967f5b 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java @@ -28,7 +28,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; -public class MTooltip extends MPanel { +public class MTooltip extends MPanelScaledGUI { @Getter @Setter private MRootPanel root; @@ -50,22 +50,37 @@ public class MTooltip extends MPanel { return super.getTooltipsOpen() - 1; } - public void render0(double scale, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a - int relMousex = relMousex0 - getBounds().x; - int relMousey = relMousey0 - getBounds().y; + @Override + public void render0(double parentScale, Point parentPoint, Rectangle parentClip, int absMousex0, int absMousey0, int relMousex0, int relMousey0, float partialTicks) { + lastParentPoint = parentPoint; GlStateManager.translate(getBounds().x, getBounds().y, 300); GlStateManager.color(1,1,1,0); + Rectangle absBound = getBounds().getBounds(); + absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y); + + Rectangle clip = absBound; + lastAbsClip = clip; + + if (clip.getSize().height * clip.getSize().width == 0) return; + + int absMousex = (int) (absMousex0 / scale), absMousey = (int) (absMousey0 / scale); + int relMousex = (int) ((relMousex0 - getBounds().x) / scale); + int relMousey = (int) ((relMousey0 - getBounds().y) /scale); + + // FROM HERE, IT IS SCALED - Rectangle clip = getBounds().getBounds(); + GlStateManager.scale(this.scale, this.scale, 1); + clip = new Rectangle((int) (clip.x / scale), (int) (clip.y / scale), (int) (clip.width / scale), (int) (clip.height / scale)); + lastAbsClip = clip; GlStateManager.pushAttrib(); GL11.glEnable(GL11.GL_SCISSOR_TEST); - this.scale = scale; + this.relativeScale = parentScale * this.scale; clip(clip.x, clip.y, clip.width, clip.height); GlStateManager.pushAttrib(); - GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB()); + GuiScreen.drawRect(0,0, (int) (getBounds().width / scale), (int) (getBounds().height / scale), backgroundColor.getRGB()); GlStateManager.enableBlend(); GlStateManager.popAttrib(); @@ -79,12 +94,12 @@ public class MTooltip extends MPanel { GlStateManager.popAttrib(); - Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y); + Point newPt = new Point((int) ((parentPoint.x + getBounds().x) / scale), (int) ((parentPoint.y + getBounds().y) / scale)); for (MPanel mPanel : getChildComponents()){ GlStateManager.pushMatrix(); GlStateManager.pushAttrib(); - mPanel.render0(scale, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); + mPanel.render0(relativeScale, newPt,clip,absMousex, absMousey, relMousex, relMousey, partialTicks); GlStateManager.popAttrib(); GlStateManager.popMatrix(); } |