diff options
author | syeyoung <cyong06@naver.com> | 2020-12-31 12:46:10 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2020-12-31 12:46:10 +0900 |
commit | a09e7553a93a177df7a6a3c7db5a1383b08a2416 (patch) | |
tree | 6e675c819c06438b8ca4303b9890a3d0261ccb34 /src/main/java/kr | |
parent | 60a6f9ce3bd9a87bc540397740bca13f1dbc4dc8 (diff) | |
download | Skyblock-Dungeons-Guide-a09e7553a93a177df7a6a3c7db5a1383b08a2416.tar.gz Skyblock-Dungeons-Guide-a09e7553a93a177df7a6a3c7db5a1383b08a2416.tar.bz2 Skyblock-Dungeons-Guide-a09e7553a93a177df7a6a3c7db5a1383b08a2416.zip |
gui feature, listeners, and editing gui
Diffstat (limited to 'src/main/java/kr')
11 files changed, 227 insertions, 8 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/MFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/config/MFeature.java index 407c33bd..f151b77f 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/MFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/MFeature.java @@ -1,5 +1,6 @@ package kr.syeyoung.dungeonsguide.config; +import kr.syeyoung.dungeonsguide.config.guiconfig.GuiGuiLocationConfig; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.roomedit.MPanel; @@ -8,6 +9,7 @@ import kr.syeyoung.dungeonsguide.roomedit.elements.MLabel; import kr.syeyoung.dungeonsguide.roomedit.elements.MStringSelectionButton; import lombok.Getter; import lombok.Setter; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import scala.actors.threadpool.Arrays; @@ -35,6 +37,12 @@ public class MFeature extends MPanel { if (abstractFeature instanceof GuiFeature) { MButton button = new MButton(); button.setText("GUI"); + button.setOnActionPerformed(new Runnable() { + @Override + public void run() { + Minecraft.getMinecraft().displayGuiScreen(new GuiGuiLocationConfig()); + } + }); addons.add(button); add(button); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java index 7d689cdb..75021e66 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/GuiGuiLocationConfig.java @@ -1,8 +1,11 @@ package kr.syeyoung.dungeonsguide.config.guiconfig; +import kr.syeyoung.dungeonsguide.config.GuiConfig; import kr.syeyoung.dungeonsguide.features.AbstractFeature; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.elements.MButton; import kr.syeyoung.dungeonsguide.roomedit.elements.MTabbedPane; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -21,7 +24,27 @@ public class GuiGuiLocationConfig extends GuiScreen { private MPanel mainPanel = new MPanel(); public GuiGuiLocationConfig() { - + for (AbstractFeature feature : FeatureRegistry.getFeatureList()) { + if (feature instanceof GuiFeature) { + mainPanel.add(new PanelDelegate((GuiFeature) feature)); + } + } + { + MButton button = new MButton() { + @Override + public void resize(int parentWidth, int parentHeight) { + setBounds(new Rectangle(parentWidth-100,parentHeight-30,100,30)); + } + }; + button.setText("back"); + button.setOnActionPerformed(new Runnable() { + @Override + public void run() { + Minecraft.getMinecraft().displayGuiScreen(new GuiConfig()); + } + }); + mainPanel.add(button); + } } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java index e91f5733..fd8b3f25 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/guiconfig/PanelDelegate.java @@ -2,6 +2,8 @@ package kr.syeyoung.dungeonsguide.config.guiconfig; import kr.syeyoung.dungeonsguide.features.GuiFeature; import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import net.minecraft.client.gui.Gui; +import org.w3c.dom.css.Rect; import java.awt.*; @@ -17,22 +19,95 @@ public class PanelDelegate extends MPanel { } @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + public void render(int absMousex, int absMousey, int relMouseX, int relMouseY, float partialTicks, Rectangle scissor) { guiFeature.drawDemo(partialTicks); + + Gui.drawRect(0,0, 3, 3, 0x55777777); + Gui.drawRect(0, getBounds().height - 3, 3, 3, 0x55777777); + Gui.drawRect(getBounds().width - 3,0, 3, 3, 0x55777777); + Gui.drawRect(getBounds().width - 3,getBounds().height - 3, 3, 3, 0x55777777); + if (lastAbsClip.contains(absMousex, absMousey)) { + if (relMouseX < 3 && relMouseY < 3) { + Gui.drawRect(0,0, 3, 3, 0x55FFFFFF); + } else if (relMouseX < 3 && relMouseY > getBounds().height - 3) { + Gui.drawRect(0, getBounds().height - 3, 3, 3, 0x55FFFFFF); + } else if (relMouseX > getBounds().width - 3 && relMouseY < getBounds().height - 3) { + Gui.drawRect(getBounds().width - 3,getBounds().height - 3, 3, 3, 0x55FFFFFF); + } else if (relMouseX > getBounds().width - 3 && relMouseY < 3) { + Gui.drawRect(getBounds().width - 3,0, 3, 3, 0x55FFFFFF); + } else { + Gui.drawRect(0,0, getBounds().width, getBounds().height, 0x55FFFFFF); + } + } } + private int selectedPart = 0; + + private int lastX = 0; + private int lastY = 0; + + @Override public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { - + if (!lastAbsClip.contains(absMouseX, absMouseY)) return; + if (relMouseX < 3 && relMouseY < 3) { + selectedPart = 0; + } else if (relMouseX < 3 && relMouseY > getBounds().height - 3) { + selectedPart = 2; + } else if (relMouseX > getBounds().width - 3 && relMouseY < getBounds().height - 3) { + selectedPart = 3; + } else if (relMouseX > getBounds().width - 3 && relMouseY < 3) { + selectedPart = 1; + } else { + selectedPart = -1; + } + lastX = absMouseX; + lastY = absMouseY; } @Override public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) { - + selectedPart = 0; } @Override public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + int dx = absMouseX - lastX; + int dy = absMouseY - lastY; + if (selectedPart > 0) { + boolean revChangeX = (selectedPart & 0x1) == 0; + boolean revChangeY = (selectedPart & 0x2) == 0; + Rectangle rectangle = guiFeature.getFeatureRect().getBounds(); + int prevWidth = rectangle.width; + int prevHeight= rectangle.height; + + rectangle.width = prevWidth + dx; + rectangle.height = prevHeight + dy; + + if (guiFeature.isKeepRatio()) { + double ratio = guiFeature.getDefaultRatio(); + int width1 = rectangle.width; + int height1 = (int) (width1 / ratio); + + int width2 = (int) (rectangle.height * ratio); + int height2 = rectangle.height; + + if (width1 * height1 < width2 * height2) { + rectangle.width = width1; + rectangle.height = height1; + } else { + rectangle.width = width2; + rectangle.height= height2; + } + } + if (revChangeX) rectangle.x -= (rectangle.width - prevWidth); + if (revChangeY) rectangle.y -= (rectangle.height - prevHeight); + guiFeature.setFeatureRect(rectangle); + } else if (selectedPart == -1){ + Rectangle rectangle = guiFeature.getFeatureRect().getBounds(); + rectangle.translate(dx, dy); + guiFeature.setFeatureRect(rectangle); + } } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index 13c16d5d..5af7fb15 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -4,6 +4,7 @@ import kr.syeyoung.dungeonsguide.commands.*; import kr.syeyoung.dungeonsguide.config.Config; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; import kr.syeyoung.dungeonsguide.eventlistener.DungeonListener; +import kr.syeyoung.dungeonsguide.eventlistener.FeatureListener; import kr.syeyoung.dungeonsguide.eventlistener.ItemGuiListener; import kr.syeyoung.dungeonsguide.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.utils.AhUtils; @@ -54,6 +55,7 @@ public class e implements c { CommandDungeonsGuide commandDungeonsGuide; ClientCommandHandler.instance.registerCommand(commandDungeonsGuide = new CommandDungeonsGuide()); MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); + MinecraftForge.EVENT_BUS.register(new FeatureListener()); AhUtils.registerTimer(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java new file mode 100644 index 00000000..cc4246da --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/FeatureListener.java @@ -0,0 +1,65 @@ +package kr.syeyoung.dungeonsguide.eventlistener; + +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.e; +import kr.syeyoung.dungeonsguide.features.*; +import kr.syeyoung.dungeonsguide.features.listener.ChatListener; +import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener; +import kr.syeyoung.dungeonsguide.features.listener.WorldRenderListener; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class FeatureListener { + @SubscribeEvent + public void onRender(RenderGameOverlayEvent.Post postRender) { + try { + if (postRender.type != RenderGameOverlayEvent.ElementType.TEXT) return; + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnSkyblock()) return; + + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature instanceof ScreenRenderListener) { + ((ScreenRenderListener) abstractFeature).drawScreen(postRender.partialTicks); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + + @SubscribeEvent + public void onRenderWorld(RenderWorldLastEvent postRender) { + try { + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnSkyblock()) return; + + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature instanceof WorldRenderListener) { + ((WorldRenderListener) abstractFeature).drawWorld(postRender.partialTicks); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + + @SubscribeEvent + public void onRenderWorld(ClientChatReceivedEvent postRender) { + try { + SkyblockStatus skyblockStatus = (SkyblockStatus) e.getDungeonsGuide().getSkyblockStatus(); + if (!skyblockStatus.isOnSkyblock()) return; + + for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) { + if (abstractFeature instanceof ChatListener) { + ((ChatListener) abstractFeature).onChat(postRender); + } + } + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java index cec8492c..2e2105b6 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/AbstractFeature.java @@ -34,9 +34,6 @@ public abstract class AbstractFeature { @Setter private boolean enabled = true; - public void drawWorld(float partialTicks) {} - public void drawScreen(float partialTicks) {} - public List<FeatureParameter> getParameters() { return new ArrayList<FeatureParameter>(parameters.values()); } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureCooldownCounter.java b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureCooldownCounter.java new file mode 100644 index 00000000..e5e0b1b6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/FeatureCooldownCounter.java @@ -0,0 +1,27 @@ +package kr.syeyoung.dungeonsguide.features; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import org.lwjgl.opengl.GL11; + +public class FeatureCooldownCounter extends GuiFeature { + protected FeatureCooldownCounter() { + super("QoL", "Dungeon Cooldown Counter", "Counts 10 seconds after leaving dungeon", "qol.cooldown", true, 100, 50); + } + + @Override + public void drawHUD(float partialTicks) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + double scale = getFeatureRect().getHeight() / fr.FONT_HEIGHT; + GL11.glScaled(scale, scale, 0); + fr.drawString("Cooldown: 1s", 0,0,0xFFFFFFFF); + } + + @Override + public void drawDemo(float partialTicks) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + double scale = getFeatureRect().getHeight() / fr.FONT_HEIGHT; + GL11.glScaled(scale, scale, 0); + fr.drawString("Cooldown: 1s", 0,0,0xFFFFFFFF); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java index f74e417d..d47b6c34 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/GuiFeature.java @@ -2,6 +2,7 @@ package kr.syeyoung.dungeonsguide.features; import com.google.gson.JsonObject; import kr.syeyoung.dungeonsguide.config.types.TypeConverterRegistry; +import kr.syeyoung.dungeonsguide.features.listener.ScreenRenderListener; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -13,7 +14,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; @Getter -public abstract class GuiFeature extends AbstractFeature { +public abstract class GuiFeature extends AbstractFeature implements ScreenRenderListener { @Setter private Rectangle featureRect; @Setter(value = AccessLevel.PROTECTED) @@ -22,17 +23,21 @@ public abstract class GuiFeature extends AbstractFeature { private int defaultWidth; @Setter(value = AccessLevel.PROTECTED) private int defaultHeight; + private double defaultRatio; protected GuiFeature(String category, String name, String description, String key, boolean keepRatio, int width, int height) { super(category, name, description, key); this.keepRatio = keepRatio; this.defaultWidth = width; this.defaultHeight = height; + this.defaultRatio = defaultWidth / (double)defaultHeight; this.featureRect = new Rectangle(0, 0, width, height); } @Override public void drawScreen(float partialTicks) { + if (!isEnabled()) return; + clip(new ScaledResolution(Minecraft.getMinecraft()), featureRect.x, featureRect.y, featureRect.width, featureRect.height); GL11.glPushAttrib(GL11.GL_SCISSOR_BIT); GL11.glEnable(GL11.GL_SCISSOR_TEST); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ChatListener.java b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ChatListener.java new file mode 100644 index 00000000..13989245 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ChatListener.java @@ -0,0 +1,7 @@ +package kr.syeyoung.dungeonsguide.features.listener; + +import net.minecraftforge.client.event.ClientChatReceivedEvent; + +public interface ChatListener { + void onChat(ClientChatReceivedEvent clientChatReceivedEvent); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ScreenRenderListener.java b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ScreenRenderListener.java new file mode 100644 index 00000000..4a659a80 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/ScreenRenderListener.java @@ -0,0 +1,5 @@ +package kr.syeyoung.dungeonsguide.features.listener; + +public interface ScreenRenderListener { + void drawScreen(float partialTicks); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/features/listener/WorldRenderListener.java b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/WorldRenderListener.java new file mode 100644 index 00000000..3815453d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/features/listener/WorldRenderListener.java @@ -0,0 +1,5 @@ +package kr.syeyoung.dungeonsguide.features.listener; + +public interface WorldRenderListener { + void drawWorld(float partialTicks); +} |