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/syeyoung/dungeonsguide/config | |
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/syeyoung/dungeonsguide/config')
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/config/CategoryEditPane.java | 132 | ||||
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/config/GuiConfig.java | 85 |
2 files changed, 217 insertions, 0 deletions
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); + } + } +} |