diff options
Diffstat (limited to 'src/main')
14 files changed, 792 insertions, 43 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java index 8eae47c4..8a00480d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/DungeonsGuide.java @@ -1,12 +1,17 @@ package kr.syeyoung.dungeonsguide; import kr.syeyoung.dungeonsguide.commands.CommandEditRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import lombok.Getter; import net.minecraft.init.Blocks; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +import java.io.File; @Mod(modid = DungeonsGuide.MODID, version = DungeonsGuide.VERSION) public class DungeonsGuide @@ -27,6 +32,18 @@ public class DungeonsGuide CommandEditRoom cc = new CommandEditRoom(); ClientCommandHandler.instance.registerCommand(cc); MinecraftForge.EVENT_BUS.register(cc); + + configDir.mkdirs(); + DungeonRoomInfoRegistry.loadAll(configDir); + + } + + @Getter + private File configDir; + + @EventHandler + public void pre(FMLPreInitializationEvent event) { + configDir = event.getModConfigurationDirectory(); } public SkyblockStatus getSkyblockStatus() { diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandLoadData.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandLoadData.java new file mode 100644 index 00000000..c1d3512e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandLoadData.java @@ -0,0 +1,27 @@ +package kr.syeyoung.dungeonsguide.commands; + +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +public class CommandLoadData extends CommandBase { + @Override + public String getCommandName() { + return "loadrooms"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "loadrooms"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + DungeonRoomInfoRegistry.loadAll(DungeonsGuide.getDungeonsGuide().getConfigDir()); + } + @Override + public int getRequiredPermissionLevel() { + return 0; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandSaveData.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandSaveData.java new file mode 100644 index 00000000..56d42d66 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandSaveData.java @@ -0,0 +1,40 @@ +package kr.syeyoung.dungeonsguide.commands; + +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import kr.syeyoung.dungeonsguide.roomedit.GuiDungeonRoomEdit; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; + +import java.awt.*; + +public class CommandSaveData extends CommandBase { + @Override + public String getCommandName() { + return "saverooms"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "saverooms"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + DungeonRoomInfoRegistry.saveAll(DungeonsGuide.getDungeonsGuide().getConfigDir()); + } + @Override + public int getRequiredPermissionLevel() { + return 0; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java index 2917bf90..f9069670 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java @@ -3,11 +3,12 @@ package kr.syeyoung.dungeonsguide.dungeon.data; import lombok.Getter; import lombok.Setter; +import java.io.Serializable; import java.util.UUID; @Getter @Setter -public class DungeonRoomInfo { +public class DungeonRoomInfo implements Serializable { public DungeonRoomInfo(short shape, byte color) { this.uuid = UUID.randomUUID(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java index a382273c..d9df6a8d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -2,6 +2,7 @@ package kr.syeyoung.dungeonsguide.dungeon.roomfinder; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; +import java.io.*; import java.util.*; public class DungeonRoomInfoRegistry { @@ -38,4 +39,34 @@ public class DungeonRoomInfoRegistry { shapeMap.get(dungeonRoomInfo.getShape()).remove(dungeonRoomInfo); uuidMap.remove(dungeonRoomInfo.getUuid()); } + + public static void saveAll(File dir) { + dir.mkdirs(); + for (DungeonRoomInfo dungeonRoomInfo : registered) { + try { + FileOutputStream fos = new FileOutputStream(new File(dir, dungeonRoomInfo.getUuid().toString() + ".roomdata")); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(dungeonRoomInfo); + oos.flush(); + oos.close(); + } catch (Exception e) {e.printStackTrace();} + } + } + + public static void loadAll(File dir) { + registered.clear(); + shapeMap.clear(); + uuidMap.clear(); + for (File f: dir.listFiles()) { + if (!f.isFile() || !f.getName().endsWith(".roomdata")) continue; + try { + FileInputStream fis = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fis); + DungeonRoomInfo dri = (DungeonRoomInfo) ois.readObject(); + ois.close(); + fis.close(); + register(dri); + } catch (Exception e) {e.printStackTrace();} + } + } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java index ba674d81..e41569d8 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java @@ -3,6 +3,9 @@ package kr.syeyoung.dungeonsguide.roomedit; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; 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 net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; @@ -22,18 +25,21 @@ public class GuiDungeonRoomEdit extends GuiScreen { public GuiDungeonRoomEdit(DungeonRoom room) { this.room = room; - mainPanel.setBackgroundColor(Color.green); - MLabel label = new MLabel(); - label.setText("blah blah is great!"); - label.setBackgroundColor(Color.BLACK); - label.setForeground(Color.white); - label.setBounds(new Rectangle(0,0,50,10)); - mainPanel.add(label); + MTabbedPane tabbedPane = new MTabbedPane(); + mainPanel.add(tabbedPane); + tabbedPane.setBackground2(new Color(17, 17, 17, 179)); + + + tabbedPane.addTab("General", new GeneralEditPane(room)); MButton mButton = new MButton(); mButton.setText("this is awesome"); mButton.setBounds(new Rectangle(30,20,50,10)); - mainPanel.add(mButton); + tabbedPane.addTab("button-o", mButton); + + MTextField mTextField = new MTextField(); + mTextField.setBounds(new Rectangle(30,20,100,30)); + tabbedPane.addTab("text-o", mTextField); } @Override @@ -41,7 +47,7 @@ public class GuiDungeonRoomEdit extends GuiScreen { super.initGui(); // update bounds ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - mainPanel.setBounds(new Rectangle((scaledResolution.getScaledWidth() - 500) / 2, (scaledResolution.getScaledHeight() - 300) / 2,500,300)); + mainPanel.setBounds(new Rectangle(Math.min((scaledResolution.getScaledWidth() - 500) / 2, scaledResolution.getScaledWidth()), Math.min((scaledResolution.getScaledHeight() - 300) / 2, scaledResolution.getScaledHeight()),500,300)); } @Override diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java index 88b918cf..aa54e0bd 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java @@ -3,8 +3,10 @@ package kr.syeyoung.dungeonsguide.roomedit; import lombok.AccessLevel; import lombok.Getter; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import org.lwjgl.opengl.GL11; import org.w3c.dom.css.Rect; @@ -12,12 +14,13 @@ import java.awt.*; import java.io.IOException; import java.util.List; import java.util.ArrayList; +import java.util.concurrent.CopyOnWriteArrayList; @Getter public class MPanel { protected Rectangle bounds = new Rectangle(0,0,0,0); // relative to parent - protected List<MPanel> childComponents = new ArrayList<MPanel>(); + protected List<MPanel> childComponents = new CopyOnWriteArrayList<MPanel>(); protected Color backgroundColor = new Color(0,0,0,0); @@ -49,6 +52,10 @@ public class MPanel { this.bounds.y = bounds.y; this.bounds.width = bounds.width; this.bounds.height = bounds.height; + + for (MPanel childComponent : childComponents) { + childComponent.resize0(bounds.width, bounds.height); + } } public void add(MPanel child) { @@ -65,42 +72,33 @@ public class MPanel { int relMousex = relMousex0 - bounds.x; int relMousey = relMousey0 - bounds.y; - GL11.glPushAttrib(GL11.GL_SCISSOR_BIT); GL11.glTranslated(bounds.x, bounds.y, 0); - Rectangle absBound = bounds.getBounds(); // 0,0 - a a + Rectangle absBound = bounds.getBounds(); absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y); Rectangle clip = determineClip(parentClip, absBound); - GlStateManager.enableBlend(); - GlStateManager.disableTexture2D(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); clip(resolution, clip.x, clip.y, clip.width, clip.height); + GL11.glPushAttrib(GL11.GL_SCISSOR_BIT); GL11.glEnable(GL11.GL_SCISSOR_TEST); - if (backgroundColor != null) - GL11.glColor4ub((byte)backgroundColor.getRed(), (byte)backgroundColor.getGreen() , (byte)backgroundColor.getBlue() , (byte)backgroundColor.getAlpha() ); - GL11.glBegin(GL11.GL_QUADS); - GL11.glVertex3i(0, 0,0); - GL11.glVertex3i(0, bounds.height,0); - GL11.glVertex3i(bounds.width, bounds.height,0); - GL11.glVertex3i(bounds.width, 0,0); - GL11.glEnd(); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); + GuiScreen.drawRect(0,0, bounds.width, bounds.height, backgroundColor.getRGB()); GL11.glPushMatrix(); - render(absMousex, absMousey, relMousex, relMousey, partialTicks); + render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip); GL11.glPopMatrix(); GL11.glDisable(GL11.GL_SCISSOR_TEST); - GL11.glPopAttrib(); + Point newPt = new Point(parentPoint.x + bounds.x, parentPoint.y + bounds.y); - for (MPanel mPanel : childComponents){ + for (MPanel mPanel : getChildComponents()){ GL11.glPushMatrix(); mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks); GL11.glPopMatrix(); @@ -122,10 +120,17 @@ public class MPanel { return new Rectangle(minX, minY, maxX - minX, maxY - minY); } - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) {} + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {} + + public void resize0(int parentWidth, int parentHeight) { + resize(parentWidth, parentHeight); + } + + public void resize(int parentWidth, int parentHeight) {} + protected void keyTyped0(char typedChar, int keyCode) { - for (MPanel childComponent : childComponents) { + for (MPanel childComponent : getChildComponents()) { childComponent.keyTyped0(typedChar, keyCode); } @@ -140,16 +145,18 @@ public class MPanel { boolean noClip = true; boolean focusedOverall = false; - for (MPanel childComponent : childComponents) { - if (childComponent.mouseClicked0(absMouseX, absMouseY, relMouseX0, relMouseY0, mouseButton)) { + for (MPanel childComponent : getChildComponents()) { + if (childComponent.mouseClicked0(absMouseX, absMouseY, relMousex, relMousey, mouseButton)) { noClip = false; focusedOverall = true; } } - if (bounds.contains(relMousex, relMousey) && noClip) { + if (bounds.contains(relMouseX0, relMouseY0) && noClip) { isFocused = true; focusedOverall = true; + } else { + isFocused = false; } mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton); @@ -162,7 +169,7 @@ public class MPanel { int relMousex = relMouseX0 - bounds.x; int relMousey = relMouseY0 - bounds.y; - for (MPanel childComponent : childComponents) { + for (MPanel childComponent : getChildComponents()) { childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state); } mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state); @@ -173,7 +180,7 @@ public class MPanel { int relMousex = relMouseX0 - bounds.x; int relMousey = relMouseY0 - bounds.y; - for (MPanel childComponent : childComponents) { + for (MPanel childComponent : getChildComponents()) { childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick); } mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick); @@ -184,7 +191,7 @@ public class MPanel { int relMousex = relMouseX0 - bounds.x; int relMousey = relMouseY0 - bounds.y; - for (MPanel childComponent : childComponents) { + for (MPanel childComponent : getChildComponents()) { childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount); } mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java index c77cb947..e32181ed 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java @@ -26,7 +26,7 @@ public class MButton extends MPanel { private Runnable onActionPerformed; @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { Dimension bounds = getSize(); Color bg = backgroundColor; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java index 1bc0c0f7..bea1601c 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java @@ -17,15 +17,32 @@ public class MLabel extends MPanel { @Setter private Color foreground = Color.white; + public static enum Alignment { + LEFT, CENTER, RIGHT; + } + @Getter + @Setter + private Alignment alignment= Alignment.LEFT; + @Override - public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { Dimension bounds = getSize(); FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; int width = renderer.getStringWidth(text); - int x = (bounds.width - width) / 2; - int y = (bounds.height - renderer.FONT_HEIGHT) / 2; - - renderer.drawString(text, x,y, foreground.getRGB()); + int x,y; + if (alignment == Alignment.CENTER) { + x = (bounds.width - width) / 2; + y = (bounds.height - renderer.FONT_HEIGHT) / 2; + } else if (alignment == Alignment.LEFT) { + x = 0; + y = (bounds.height - renderer.FONT_HEIGHT) / 2; + } else if (alignment == Alignment.RIGHT) { + x = bounds.width - width; + y = (bounds.height - renderer.FONT_HEIGHT) / 2; + } else{ + return; + } + renderer.drawString(text, x,y, 0xffffff); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabelAndElement.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabelAndElement.java new file mode 100644 index 00000000..65d23bf2 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabelAndElement.java @@ -0,0 +1,32 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; + +import java.awt.*; + +public class MLabelAndElement extends MPanel { + private MLabel label; + private MPanel element; + + public MLabelAndElement(String label, MPanel element) { + this.add(this.label = new MLabel()); + this.label.setText(label); + this.add(element); + this.element = element; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setSize(new Dimension(parentWidth, bounds.height)); + label.setBounds(new Rectangle(0,0,parentHeight / 3, bounds.height)); + element.setBounds(new Rectangle(parentWidth / 3,0,parentWidth / 3 * 2, bounds.height)); + } + + @Override + public void setBounds(Rectangle bounds) { + super.setBounds(bounds); + + label.setBounds(new Rectangle(0,0,bounds.width / 3, bounds.height)); + element.setBounds(new Rectangle(bounds.width / 3,0,bounds.width / 3 * 2, bounds.height)); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabButton.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabButton.java new file mode 100644 index 00000000..96f8d4db --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabButton.java @@ -0,0 +1,61 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; + +import java.awt.*; + +@Getter +@Setter +public class MTabButton extends MPanel { + private String text; + + private Color foreground = Color.white; + private Color hover = new Color(236, 236, 236, 64); + private Color clicked = new Color(30,30,30,0); + private Color selected = new Color(0,0,0,255); + private Color disabled = new Color(0,0,0); + + private boolean enabled = true; + + private MTabbedPane tabbedPane; + + public MTabButton(MTabbedPane tabbedPane, String key) { + this.tabbedPane = tabbedPane; + this.text = key; + } + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { + Dimension bounds = getSize(); + + Color bg = null; + if (!enabled) { + bg = disabled; + } else if (tabbedPane.getSelectedKey().equals(text)) { + bg = selected; + } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) { + bg = hover; + } + if (bg != null) + Gui.drawRect(0,0,bounds.width, bounds.height, bg.getRGB()); + + FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj; + int width = renderer.getStringWidth(text); + int x = (bounds.width - width) / 2; + int y = (bounds.height - renderer.FONT_HEIGHT) / 2; + + renderer.drawString(text, x,y, foreground.getRGB()); + } + + @Override + protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + if (new Rectangle(new Point(0,0),getSize()).contains(relMouseX, relMouseY)) { + tabbedPane.setSelectedKey(text); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabbedPane.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabbedPane.java new file mode 100644 index 00000000..48053cb6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTabbedPane.java @@ -0,0 +1,72 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import lombok.Getter; +import lombok.Setter; + +import java.awt.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MTabbedPane extends MPanel { + + private Map<String, MPanel> tabs = new HashMap<String, MPanel>(); + private Map<String, MTabButton> buttons = new HashMap<String, MTabButton>(); + + @Getter + @Setter + private String selectedKey = ""; + + @Getter + private Color background2; + + public void setBackground2(Color background2) { + this.background2 = background2; + for (MPanel value : tabs.values()) { + value.setBackgroundColor(background2); + } + for (MTabButton value : buttons.values()) { + value.setBackgroundColor(background2.brighter()); + } + } + + public void addTab(String tab, MPanel panel) { + MPanel panel2 = new MPanel() ; + panel2.add(panel); + panel2.setBackgroundColor(background2); + tabs.put(tab, panel2); + panel2.setBounds(new Rectangle(0,15,bounds.width, bounds.height-15)); + + MTabButton button = new MTabButton(this, tab); + button.setBackgroundColor(background2.brighter()); + button.setBounds(new Rectangle(buttons.size()* 50, 0, 50, 15)); + buttons.put(tab, button); + if (tabs.size() == 1) + selectedKey = tab; + } + + @Override + public List<MPanel> getChildComponents() { + ArrayList<MPanel> dynamic = new ArrayList<MPanel>(buttons.values()); + dynamic.add(tabs.get(selectedKey)); + return dynamic; + } + + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(0,0,parentWidth, parentHeight)); + for (MPanel ma:tabs.values()) + ma.setBounds(new Rectangle(0,15,parentWidth, parentHeight-15)); + } + + @Override + public void setBounds(Rectangle bounds) { + if (bounds == null) return; + this.bounds.x = bounds.x; + this.bounds.y = bounds.y; + this.bounds.width = bounds.width; + this.bounds.height = bounds.height; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTextField.java new file mode 100644 index 00000000..083bb356 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MTextField.java @@ -0,0 +1,344 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +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.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.event.KeyEvent; +import java.io.IOException; + +@Getter +public class MTextField extends MPanel { + private Color foreground = Color.white; + + private String text = "asdasdasd"; + private int cursorBlickTicker = 0; + + private int selectionStart = 0; + private int selectionEnd = 0; + + private int cursor = 0; + + private int xOffset = 0; + + public void edit(String str) { + + } + + public void setText(String text) { + this.text = text; + edit(text); + } + + + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) { + Gui.drawRect(0,0,bounds.width, bounds.height, isFocused ? Color.white.getRGB() : Color.gray.getRGB()); + Gui.drawRect(1,1,bounds.width - 2, bounds.height - 2, Color.black.getRGB()); + + Minecraft mc = Minecraft.getMinecraft(); + clip(new ScaledResolution(mc), clip.x + 1, clip.y + 1, clip.width - 2, clip.height - 2); + FontRenderer fr = mc.fontRendererObj; + int y = (bounds.height - fr.FONT_HEIGHT) / 2; + fr.drawString(text, 3 - xOffset, y, foreground.getRGB()); + // draw selection + if (isFocused) { + if (selectionStart != -1) { + int startX = fr.getStringWidth(text.substring(0, selectionStart)) - xOffset; + int endX = fr.getStringWidth(text.substring(0, selectionEnd)) - xOffset; + Gui.drawRect(3 + startX, y, 3 + endX, y + fr.FONT_HEIGHT, 0xFF00FF00); + fr.drawString(text.substring(selectionStart, selectionEnd), 3 + startX, y, foreground.getRGB()); + } + + // draw cursor + if (cursor != -1) { + int x = fr.getStringWidth(text.substring(0, cursor)) - xOffset; + cursorBlickTicker++; + if (cursorBlickTicker < 10) + Gui.drawRect(3 + x, y, 4 + x, y + fr.FONT_HEIGHT, 0xFFFFFFFF); + if (cursorBlickTicker == 20) cursorBlickTicker = 0; + } + } + } + + @Override + protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) { + Rectangle actualField = new Rectangle(1, 3,bounds.width - 2, bounds.height - 6); + if (!actualField.contains(relMouseX, relMouseY)) return; + + + + int relStartT = relMouseX-3; + int offseted = relStartT + xOffset; + + selectionStart = -1; + + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + for (int i = 0; i < text.length(); i++) { + int totalWidth = fr.getStringWidth(text.substring(0, i)); + if (offseted < totalWidth) { + cursor = i; + return; + } + } + cursor = text.length(); + } + + @Override + protected void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) { + if (!isFocused) return; + selectionStart = cursor; + selectionEnd = cursor; + + int relStartT = relMouseX-3; + int offseted = relStartT + xOffset; + System.out.println("click!" +offseted); + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + for (int i = 0; i < text.length(); i++) { + int totalWidth = fr.getStringWidth(text.substring(0, i)); + if (offseted < totalWidth) { + if (i < cursor) { + selectionStart = i; + selectionEnd = cursor; + } else { + selectionStart = cursor; + selectionEnd = i; + } + return; + } + } + selectionEnd = text.length(); + if (selectionStart == selectionEnd) { + selectionStart = -1; + } + } + + @Override + protected void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { + if (!isFocused) return; + if (scrollAmount > 0) { + xOffset += 5; + } else if (scrollAmount < 0){ + xOffset -= 5; + } + if (xOffset < 0) { + xOffset = 0; + } + int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text); + int overflow = bounds.width - 3 - width; + if (overflow >= 0) { + xOffset = 0; + } else if (width - xOffset + 10 < bounds.width) { + xOffset = width - bounds.width+10; + } + } + + @Override + protected void keyTyped(char typedChar, int keycode) { + if (!isFocused) return; + + + if (selectionStart == -1) { + if (keycode == 199) { // home + cursor = 0; + return; + } + + if (keycode == 207) { // end + cursor = text.length(); + return; + } + + if (keycode == 203) { // left + cursor--; + if (cursor < 0) cursor = 0; + return; + } + + if (keycode == 205) { // right + cursor ++; + if (cursor > text.length()) cursor = text.length(); + return; + } + + // backspace + if (keycode == 14 && cursor > 0) { + setText(this.text.substring(0, cursor - 1) + this.text.substring(cursor)); + cursor--; + return; + } + + //del + if (keycode == 211 && cursor < text.length()) { + setText(this.text.substring(0, cursor) + this.text.substring(cursor+1)); + return; + } + + // paste + boolean shouldPaste = false; + if (keycode == 47) { + if (Minecraft.isRunningOnMac) { // mac + if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) { + shouldPaste = true; + } + } else { // literally everything else + if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) { + shouldPaste = true; + } + } + } + if (shouldPaste) { + Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); + if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) { + try { + Object theText = transferable.getTransferData(DataFlavor.stringFlavor); + setText( + this.text.substring(0, this.cursor) + + theText + + this.text.substring(this.cursor)); + + cursor += theText.toString().length(); + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return; + } + + // text + if (isPrintableChar(typedChar)) { + setText( + this.text.substring(0, this.cursor) + + typedChar + + this.text.substring(this.cursor)); + this.cursor++; + return; + } + } else { + if (keycode == 199) { // home + cursor = 0; + selectionStart = -1; + return; + } + + if (keycode == 207) { // end + selectionStart = -1; + cursor = text.length(); + return; + } + + if (keycode == 203) { // left + cursor = selectionStart; + selectionStart = -1; + return; + } + + if (keycode == 205) { // right + cursor = selectionEnd; + selectionStart = -1; + return; + } + + // backspace + if (keycode == 14 && cursor > 0) { + setText(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd)); + cursor = selectionStart; + selectionStart = -1; + return; + } + + //del + if (keycode == 211 && cursor < text.length()) { + setText(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd)); + cursor = selectionStart; + selectionStart = -1; + return; + } + + // paste + boolean shouldPaste = false; + if (keycode == 47) { + if (Minecraft.isRunningOnMac) { // mac + if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) { + shouldPaste = true; + } + } else { // literally everything else + if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) { + shouldPaste = true; + } + } + } + if (shouldPaste) { + Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); + if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) { + try { + Object theText = transferable.getTransferData(DataFlavor.stringFlavor); + setText( + this.text.substring(0, this.selectionStart) + + theText + + this.text.substring(this.selectionEnd)); + cursor = this.selectionStart + theText.toString().length(); + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + selectionStart = -1; + } + return; + } + boolean shouldCopy = false; + if (keycode == 46) { + if (Minecraft.isRunningOnMac) { // mac + if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) { + shouldCopy = true; + } + } else { // literally everything else + if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) { + shouldCopy = true; + } + } + } + if (shouldCopy) { + StringSelection selection = new StringSelection(text.substring(selectionStart, selectionEnd)); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(selection, selection); + return; + } + + // text + if (isPrintableChar(typedChar)) { + setText( + this.text.substring(0, this.selectionStart) + + typedChar + + this.text.substring(this.selectionEnd)); + this.cursor = this.selectionStart + 1; + selectionStart = -1; + return; + } + } + } + public boolean isPrintableChar( char c ) { + Character.UnicodeBlock block = Character.UnicodeBlock.of( c ); + return (!Character.isISOControl(c)) && + c != KeyEvent.CHAR_UNDEFINED && + block != null && + block != Character.UnicodeBlock.SPECIALS; + } + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/GeneralEditPane.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/GeneralEditPane.java new file mode 100644 index 00000000..d8345eb6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/panes/GeneralEditPane.java @@ -0,0 +1,94 @@ +package kr.syeyoung.dungeonsguide.roomedit.panes; + +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.elements.*; + +import java.awt.*; + +public class GeneralEditPane extends MPanel { + private DungeonRoom dungeonRoom; + + private MLabelAndElement uuid; + private MLabelAndElement name; + + private MLabelAndElement shape; + private MLabelAndElement rotation; + private MLabelAndElement shape2; + + private MButton save; + + public GeneralEditPane(final DungeonRoom dungeonRoom) { + this.dungeonRoom = dungeonRoom; +System.out.println("building"); + { + MLabel la; + uuid = new MLabelAndElement("Room UUID: ", la = new MLabel()); + la.setText(dungeonRoom.getDungeonRoomInfo().getUuid().toString()); + uuid.setBounds(new Rectangle(0,0,bounds.width, 20)); + add(uuid); + } + { + MTextField la = new MTextField() { + @Override + public void edit(String str) { + System.out.println(str); + dungeonRoom.getDungeonRoomInfo().setName(str); + } + }; + name = new MLabelAndElement("Room Name: ", la); + la.setText(dungeonRoom.getDungeonRoomInfo().getName()); + name.setBounds(new Rectangle(0,20,bounds.width, 20)); + add(name); + } + + { + MLabel la; + shape = new MLabelAndElement("Room Shape: ", la = new MLabel()); + la.setText(dungeonRoom.getDungeonRoomInfo().getShape()+""); + shape.setBounds(new Rectangle(0,40,bounds.width, 20)); + add(shape); + } + + { + MLabel la; + rotation = new MLabelAndElement("Found Room Rotation: ", la = new MLabel()); + la.setText(dungeonRoom.getRoomMatcher().getRotation()+""); + rotation.setBounds(new Rectangle(0,60,bounds.width, 20)); + add(rotation); + } + { + MLabel la; + shape2 = new MLabelAndElement("Found Room Shape: ", la = new MLabel()); + la.setText(dungeonRoom.getShape()+""); + shape2.setBounds(new Rectangle(0,80,bounds.width, 20)); + add(shape2); + } + { + System.out.println("roomdata"); + if (dungeonRoom.getDungeonRoomInfo().isRegistered()) return; + System.out.println("roomdata"); + save = new MButton(); + save.setText("Save RoomData"); + save.setOnActionPerformed(new Runnable() { + @Override + public void run() { + DungeonRoomInfoRegistry.register(dungeonRoom.getDungeonRoomInfo()); + remove(save); + } + }); + save.setBackgroundColor(Color.green); + save.setBounds(new Rectangle(1,100,bounds.width-2, 20)); + System.out.println("roomdata"); + add(save); + System.out.println(save.getBounds()); + } + } + + @Override + public void resize(int parentWidth, int parentHeight) { + save.setBounds(new Rectangle(0,100,bounds.width, 20)); + this.setBounds(new Rectangle(5,5,parentWidth-10,parentHeight-10)); + } +} |