diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-15 00:40:58 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-12-15 00:40:58 +0900 |
commit | 496efb764360cd26fa40982532048aa18ae4c6be (patch) | |
tree | 483665c7501a5855ce439fbeff1c3d8ac8b15618 /src/main/java/kr/syeyoung/dungeonsguide/roomedit | |
parent | ff817d0a37b907ff1f5132b04e737413b020ecd1 (diff) | |
download | Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.tar.gz Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.tar.bz2 Skyblock-Dungeons-Guide-496efb764360cd26fa40982532048aa18ae4c6be.zip |
dungeon actions and secrets
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/roomedit')
3 files changed, 205 insertions, 4 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/gui/GuiDungeonRoomEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/gui/GuiDungeonRoomEdit.java index c332dd20..2c5a7b69 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/gui/GuiDungeonRoomEdit.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/gui/GuiDungeonRoomEdit.java @@ -6,10 +6,7 @@ import kr.syeyoung.dungeonsguide.roomedit.elements.MButton; import kr.syeyoung.dungeonsguide.roomedit.elements.MLabel; import kr.syeyoung.dungeonsguide.roomedit.elements.MTabbedPane; import kr.syeyoung.dungeonsguide.roomedit.elements.MTextField; -import kr.syeyoung.dungeonsguide.roomedit.panes.GeneralEditPane; -import kr.syeyoung.dungeonsguide.roomedit.panes.ProcessorParameterEditPane; -import kr.syeyoung.dungeonsguide.roomedit.panes.RoomDataDisplayPane; -import kr.syeyoung.dungeonsguide.roomedit.panes.SecretEditPane; +import kr.syeyoung.dungeonsguide.roomedit.panes.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; @@ -39,6 +36,7 @@ public class GuiDungeonRoomEdit extends GuiScreen { tabbedPane.addTab("General", new GeneralEditPane(room)); tabbedPane.addTab("Match", new RoomDataDisplayPane(room)); tabbedPane.addTab("Secrets", new SecretEditPane(room)); + tabbedPane.addTab("Actions", new ActionDisplayPane(room)); tabbedPane.addTab("Proc.Params", new ProcessorParameterEditPane(room)); this.tabbedPane = tabbedPane; } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionDisplayPane.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionDisplayPane.java new file mode 100644 index 00000000..974e46b5 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionDisplayPane.java @@ -0,0 +1,72 @@ +package kr.syeyoung.dungeonsguide.roomedit.panes; + +import kr.syeyoung.dungeonsguide.dungeon.actions.Action; +import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionTree; +import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonMechanic; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import kr.syeyoung.dungeonsguide.roomedit.EditingContext; +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.elements.*; +import kr.syeyoung.dungeonsguide.roomprocessor.ProcessorFactory; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Set; + +public class ActionDisplayPane extends MPanel { + private DungeonRoom dungeonRoom; + + private ActionTreeDisplayPane displayPane; + + private MTextField textField; + private MButton calculate; + public ActionDisplayPane(final DungeonRoom dungeonRoom) { + this.dungeonRoom = dungeonRoom; + + { + textField = new MTextField(); + textField.setBounds(new Rectangle(0,0,bounds.width - 100, 20)); + add(textField); + } + { + calculate = new MButton(); + calculate.setBounds(new Rectangle(bounds.width - 100,0,100, 20)); + calculate.setText("calculate"); + calculate.setOnActionPerformed(new Runnable() { + @Override + public void run() { + try { + remove(displayPane); + + String text = textField.getText(); + String target = text.split(":")[0]; + String state = text.split(":")[1]; + + DungeonMechanic mechanic = dungeonRoom.getDungeonRoomInfo().getMechanics().get(target); + Set<Action> actionSet = mechanic.getAction(state, dungeonRoom); + ActionTree tree= ActionTree.buildActionTree(actionSet, dungeonRoom); + + displayPane = new ActionTreeDisplayPane(dungeonRoom, tree); + displayPane.setBounds(new Rectangle(0,25,bounds.width,bounds.height-25)); + add(displayPane); + } catch (Throwable t) { + t.printStackTrace(); + } + } + }); + add(calculate); + } + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(5,5,parentWidth-10,parentHeight-10)); + } + + @Override + public void onBoundsUpdate() { + textField.setBounds(new Rectangle(0,0,bounds.width - 100, 20)); + calculate.setBounds(new Rectangle(bounds.width - 100,0,100, 20)); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionTreeDisplayPane.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionTreeDisplayPane.java new file mode 100644 index 00000000..20c5242d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/ActionTreeDisplayPane.java @@ -0,0 +1,131 @@ +package kr.syeyoung.dungeonsguide.roomedit.panes; + +import kr.syeyoung.dungeonsguide.dungeon.actions.Action; +import kr.syeyoung.dungeonsguide.dungeon.actions.tree.ActionTree; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.utils.RenderUtils; +import net.minecraft.block.Block; +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.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.*; + +public class ActionTreeDisplayPane extends MPanel { + + private int offsetX = 0; + private int offsetY = 0; + + private DungeonRoom dungeonRoom; + private ActionTree tree; + public ActionTreeDisplayPane(DungeonRoom dungeonRoom, ActionTree tree) { + this.dungeonRoom = dungeonRoom; + this.tree = tree; + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + GL11.glPushMatrix(); + GL11.glTranslated(-offsetX, -offsetY, 0); + renderTree(tree, 5, 5, Minecraft.getMinecraft().fontRendererObj, null, new HashMap<ActionTree, Point>()); + GL11.glPopMatrix(); + } + + public int renderTree(ActionTree actionTree, int x, int y, FontRenderer fr, Point drawLineFrom, HashMap<ActionTree, Point> drawmPoints) { + if (drawmPoints.containsKey(actionTree)) { + // recursive, fu + Point pt = drawmPoints.get(actionTree); + + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + WorldRenderer renderer = Tessellator.getInstance().getWorldRenderer(); + GlStateManager.color(255,0,0, 255); + renderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + renderer.pos(pt.x, pt.y, 0).endVertex(); + renderer.pos(drawLineFrom.x, drawLineFrom.y, 0).endVertex(); + Tessellator.getInstance().draw(); + GlStateManager.popMatrix(); + GlStateManager.popAttrib(); + return 0; + } + + Dimension dim = renderAction(actionTree.getCurrent(), x, y, fr); + if (drawLineFrom != null) { + GlStateManager.pushMatrix(); + GlStateManager.pushAttrib(); + WorldRenderer renderer = Tessellator.getInstance().getWorldRenderer(); + GlStateManager.color(255,255,255, 255); + renderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + renderer.pos(x + dim.width, y, 0).endVertex(); + renderer.pos(drawLineFrom.x, drawLineFrom.y, 0).endVertex(); + Tessellator.getInstance().draw(); + GlStateManager.popMatrix(); + GlStateManager.popAttrib(); + } + Point pt = new Point(x + dim.width / 2, y + dim.height); + + drawmPoints.put(actionTree, new Point(x + dim.width / 2, y + dim.height / 2)); + int xOff = 0; + for (ActionTree tree:actionTree.getChildren()) { + xOff += renderTree(tree, x + xOff, y + dim.height + 10, fr, pt, drawmPoints) + 10; + } + return xOff; + } + + public Dimension renderAction(Action action, int x, int y, FontRenderer fr) { + String[] lines = action.toString().split("\n"); + int maxWidth = 0; + for (String line : lines) { + if (fr.getStringWidth(line) > maxWidth) maxWidth= fr.getStringWidth(line); + } + int offset = 2; + int height = (fr.FONT_HEIGHT + offset) * lines.length; + + Gui.drawRect(x,y,x + maxWidth +10, y + height + 10, 0xff000000); + Gui.drawRect(x+1,y+1,x + maxWidth +8, y + height + 8, 0xff4d4d4d); + for (int i = 0; i < lines.length; i++) { + fr.drawString(lines[i], 5, 5 + i*(fr.FONT_HEIGHT + offset), 0xffffffff); + } + + return new Dimension(maxWidth + 10, height + 10); + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,25,parentWidth,parentHeight-25)); + } + + + private int lastX; + private int lastY; + @Override + public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + lastX = absMouseX; + lastY = absMouseY; + } + + @Override + public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + int dX = absMouseX - lastX; + int dY = absMouseY - lastY; + offsetX += dX; + offsetY += dY; + lastX = absMouseX; + lastY = absMouseY; + } +} |