diff options
author | syeyoung <cyong06@naver.com> | 2020-12-24 11:39:29 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2020-12-24 11:39:29 +0900 |
commit | 9d82a605330cb1993a0518f6168d01e7df411ad5 (patch) | |
tree | c5caf7316c9342a4eca954d5f6fdfd5628648dd0 /src/main/java/kr | |
parent | 4bf3172187396e9eedb852a887f98d7eb276f459 (diff) | |
download | Skyblock-Dungeons-Guide-9d82a605330cb1993a0518f6168d01e7df411ad5.tar.gz Skyblock-Dungeons-Guide-9d82a605330cb1993a0518f6168d01e7df411ad5.tar.bz2 Skyblock-Dungeons-Guide-9d82a605330cb1993a0518f6168d01e7df411ad5.zip |
commando
Diffstat (limited to 'src/main/java/kr')
5 files changed, 245 insertions, 5 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/Config.java b/src/main/java/kr/syeyoung/dungeonsguide/Config.java index 07dc6d41..adbb2da4 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/Config.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/Config.java @@ -21,11 +21,11 @@ public class Config { public static boolean solver_creeper; public static boolean solver_teleport; - public static void syncConfig(Configuration configuration) { // Gets called from preInit + public static void syncConfig(boolean load) { // Gets called from preInit try { - Config.configuration = configuration; // Load config - configuration.load(); + if (load) + configuration.load(); // Read props from config DEBUG = configuration.get(Config.CATEGORY_ADVANCED, "debug","false", "Enable debug mode").getBoolean(); // Comment diff --git a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java index a9308f4c..fefc3723 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/commands/CommandDungeonsGuide.java @@ -1,10 +1,14 @@ package kr.syeyoung.dungeonsguide.commands; +import kr.syeyoung.dungeonsguide.config.GuiConfig; import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoomInfoRegistry; import kr.syeyoung.dungeonsguide.e; +import net.minecraft.client.Minecraft; 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 javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -29,6 +33,7 @@ public class CommandDungeonsGuide extends CommandBase { public void processCommand(ICommandSender sender, String[] args) { if (args.length == 0) { // open config + openConfig = true; } else if (args[0].equalsIgnoreCase("saverooms")) { DungeonRoomInfoRegistry.saveAll(e.getDungeonsGuide().getConfigDir()); sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fSuccessfully saved user generated roomdata")); @@ -60,6 +65,21 @@ public class CommandDungeonsGuide extends CommandBase { sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §e/dg loadrooms §7-§f Reloads dungeon roomdata.")); } } + + private boolean openConfig = false; + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent e) { + try { + if (openConfig && e.phase == TickEvent.Phase.START ) { + openConfig = false; + Minecraft.getMinecraft().displayGuiScreen(new GuiConfig()); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + @Override public int getRequiredPermissionLevel() { return 0; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/CategoryEditPane.java b/src/main/java/kr/syeyoung/dungeonsguide/config/CategoryEditPane.java new file mode 100755 index 00000000..6c50196d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/CategoryEditPane.java @@ -0,0 +1,132 @@ +package kr.syeyoung.dungeonsguide.config; + +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.Parameter; +import kr.syeyoung.dungeonsguide.roomedit.elements.MButton; +import kr.syeyoung.dungeonsguide.roomedit.elements.MParameter; +import kr.syeyoung.dungeonsguide.roomedit.elements.MValue; +import kr.syeyoung.dungeonsguide.roomedit.panes.DynamicEditor; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEditCreator; +import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEditRegistry; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.Property; +import scala.actors.threadpool.Arrays; + +import java.awt.*; +import java.util.*; +import java.util.List; + +public class CategoryEditPane extends MPanel implements DynamicEditor { + private ConfigCategory category; + + private MButton save; + private Map<String, MValue> parameters = new HashMap<String, MValue>(); + + public CategoryEditPane(ConfigCategory category) { + this.category = category; + buildElements(); + } + + public String typeToclass(Property.Type type) { + switch (type) { + case STRING: + return String.class.getName(); + case INTEGER: + return Integer.class.getName(); + case BOOLEAN: + return Boolean.class.getName(); + case COLOR: + return Color.class.getName(); + } + return "null"; + } + + public void buildElements() { + { + save = new MButton(); + save.setText("Save"); + save.setBackgroundColor(Color.green); + save.setBounds(new Rectangle(0,0,100,20)); + save.setOnActionPerformed(new Runnable() { + @Override + public void run() { + for (Map.Entry<String,MValue> parameter:parameters.entrySet()) { + if (parameter.getValue().getData() != null) + category.get(parameter.getKey()).setValue(parameter.getValue().getData().toString()); + } + Config.syncConfig(false); + } + }); + } + { + for (Map.Entry<String, Property> en : category.entrySet()) { + ValueEditCreator vec = ValueEditRegistry.getValueEditMap(typeToclass(en.getValue().getType())); + + MValue mParameter = new MValue(getValue(en.getValue()), Collections.emptyList()); + mParameter.setBounds(new Rectangle(0,0,bounds.width,20)); + parameters.put(en.getKey(), mParameter); + } + } + } + + private Object getValue(Property property) { + switch(property.getType()) { + case STRING: + return property.getString(); + case INTEGER: + return property.getInt(); + case BOOLEAN: + return property.getBoolean(); + } + return null; + } + + @Override + public void onBoundsUpdate() { + for (MPanel panel :getChildComponents()){ + panel.setSize(new Dimension(bounds.width, 20)); + } + } + @Override + public void resize(int parentWidth, int parentHeight) { + this.setBounds(new Rectangle(5,5,parentWidth-10,parentHeight-10)); + } + + + public void delete(MParameter parameter) { + parameters.remove(parameter); + } + + @Override + public List<String> allowedClass() { + return ValueEditRegistry.getClassesSupported(); + } + + + @Override + public List<MPanel> getChildComponents() { + ArrayList<MPanel> panels = new ArrayList<MPanel>(parameters.values()); + panels.add(save); + return panels; + } + + private int offsetY = 0; + @Override + public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) { + int heights = 0; + for (MPanel panel:getChildComponents()) { + panel.setPosition(new Point(0, -offsetY + heights)); + heights += panel.getBounds().height; + } + } + + @Override + public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) { + if (scrollAmount > 0) offsetY -= 20; + else if (scrollAmount < 0) offsetY += 20; + if (offsetY < 0) offsetY = 0; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/config/GuiConfig.java b/src/main/java/kr/syeyoung/dungeonsguide/config/GuiConfig.java new file mode 100755 index 00000000..5e5b8aac --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/config/GuiConfig.java @@ -0,0 +1,85 @@ +package kr.syeyoung.dungeonsguide.config; + +import kr.syeyoung.dungeonsguide.Config; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import kr.syeyoung.dungeonsguide.roomedit.elements.MTabbedPane; +import kr.syeyoung.dungeonsguide.roomedit.panes.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.io.IOException; + +public class GuiConfig extends GuiScreen { + + private MPanel mainPanel = new MPanel(); + + private MTabbedPane tabbedPane; + + public GuiConfig() { + MTabbedPane tabbedPane = new MTabbedPane(); + mainPanel.add(tabbedPane); + tabbedPane.setBackground2(new Color(17, 17, 17, 179)); + + for (String cate:Config.configuration.getCategoryNames()) + tabbedPane.addTab(cate, new CategoryEditPane(Config.configuration.getCategory(cate))); + this.tabbedPane = tabbedPane; + } + + @Override + public void initGui() { + super.initGui(); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + mainPanel.setBounds(new Rectangle(Math.min((scaledResolution.getScaledWidth() - 500) / 2, scaledResolution.getScaledWidth()), Math.min((scaledResolution.getScaledHeight() - 300) / 2, scaledResolution.getScaledHeight()),500,300)); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + GL11.glPushMatrix(); + GlStateManager.pushAttrib(); + mainPanel.render0(scaledResolution, new Point(0,0), new Rectangle(0,0,scaledResolution.getScaledWidth(),scaledResolution.getScaledHeight()), mouseX, mouseY, mouseX, mouseY, partialTicks); + GlStateManager.popAttrib(); + GL11.glPopMatrix(); + } + + @Override + public void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + mainPanel.keyTyped0(typedChar, keyCode); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + mainPanel.mouseClicked0(mouseX, mouseY,mouseX,mouseY, mouseButton); + } + + @Override + public void mouseReleased(int mouseX, int mouseY, int state) { + mainPanel.mouseReleased0(mouseX, mouseY,mouseX,mouseY, state); + } + + @Override + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + mainPanel.mouseClickMove0(mouseX,mouseY,mouseX,mouseY,clickedMouseButton,timeSinceLastClick); + } + + @Override + public void handleMouseInput() throws IOException { + super.handleMouseInput(); + + int i = Mouse.getEventX() * this.width / this.mc.displayWidth; + int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; + + int wheel = Mouse.getDWheel(); + if (wheel != 0) { + mainPanel.mouseScrolled0(i, j,i,j, wheel); + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/e.java b/src/main/java/kr/syeyoung/dungeonsguide/e.java index f818d35b..80440e36 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/e.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/e.java @@ -50,7 +50,9 @@ public class e implements c { skyblockStatus = new SkyblockStatus(); MinecraftForge.EVENT_BUS.register(new EventListener()); - ClientCommandHandler.instance.registerCommand(new CommandDungeonsGuide()); + CommandDungeonsGuide commandDungeonsGuide; + ClientCommandHandler.instance.registerCommand(commandDungeonsGuide = new CommandDungeonsGuide()); + MinecraftForge.EVENT_BUS.register(commandDungeonsGuide); try { DungeonRoomInfoRegistry.loadAll(configDir); @@ -78,7 +80,8 @@ public class e implements c { if (!configFile.exists()) { configDir.mkdirs(); } - Config.syncConfig( new Configuration(configFile) ); + Config.configuration = new Configuration(configFile); + Config.syncConfig( true ); } private void copy(InputStream inputStream, File f) throws IOException { FileOutputStream fos = new FileOutputStream(f); |