Search in sources :

Example 1 with HudModule

use of dev.hypnotic.module.hud.HudModule in project Hypnotic-Client by Hypnotic-Development.

the class ConfigManager method loadConfig.

public boolean loadConfig() {
    try {
        String configString = new String(Files.readAllBytes(config.toPath()));
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
        Mod[] modules = gson.fromJson(configString, Mod[].class);
        HudModule[] hudModules = gson.fromJson(configString, HudModule[].class);
        for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
            if (module instanceof HudModule) {
                HudModule hudMod = (HudModule) module;
                for (HudModule configHudModule : hudModules) {
                    if (hudMod.getName().equals(configHudModule.getName())) {
                        hudMod.setX(configHudModule.getX());
                        hudMod.setY(configHudModule.getY());
                        System.out.println(hudMod.getName() + ":" + configHudModule.getX());
                    }
                }
            }
            for (Mod configModule : modules) {
                if (module.getName().equals(configModule.getName())) {
                    try {
                        if (configModule.isEnabled() && !module.isEnabled())
                            module.setEnabled(true);
                        else if (!configModule.isEnabled() && module.isEnabled())
                            module.setEnabled(false);
                        module.setKey(configModule.getKey());
                        for (Setting setting : module.settings) {
                            for (ConfigSetting cfgSetting : configModule.cfgSettings) {
                                if (setting.name.equals(cfgSetting.name)) {
                                    if (setting instanceof BooleanSetting) {
                                        ((BooleanSetting) setting).setEnabled((boolean) cfgSetting.value);
                                    }
                                    if (setting instanceof ModeSetting) {
                                        ((ModeSetting) setting).setSelected((String) cfgSetting.value);
                                    }
                                    if (setting instanceof NumberSetting) {
                                        ((NumberSetting) setting).setValue((double) cfgSetting.value);
                                    }
                                    if (setting instanceof ColorSetting) {
                                        int[] color = ((ColorSetting) setting).hexToRgbInt((String) cfgSetting.value);
                                        ((ColorSetting) setting).setRGB(color[0], color[1], color[2], color[3]);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson) HudModule(dev.hypnotic.module.hud.HudModule) IOException(java.io.IOException) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting)

Example 2 with HudModule

use of dev.hypnotic.module.hud.HudModule in project Hypnotic-Client by Hypnotic-Development.

the class SaveLoad method save.

public void save() {
    ArrayList<String> toSave = new ArrayList<String>();
    if (ModuleManager.INSTANCE == null || HudManager.INSTANCE == null)
        return;
    for (Mod mod : ModuleManager.INSTANCE.modules) {
        toSave.add("MOD:" + mod.getName() + ":" + mod.isEnabled() + ":" + mod.getKey());
    }
    for (HudModule element : HudManager.INSTANCE.hudModules) {
        toSave.add("HUD:" + element.getName() + ":" + element.getX() + ":" + element.getY());
    }
    for (Friend friend : FriendManager.INSTANCE.friends) {
        toSave.add("FRIEND:" + friend.name);
    }
    for (Frame frame : ClickGUI.INSTANCE.frames) {
        toSave.add("FRAME:" + frame.name + ":" + frame.getX() + ":" + frame.getY() + ":" + frame.isExtended());
    }
    toSave.add("FRAME:" + HudEditorScreen.INSTANCE.frame.name + ":" + HudEditorScreen.INSTANCE.frame.getX() + ":" + HudEditorScreen.INSTANCE.frame.getY() + ":" + HudEditorScreen.INSTANCE.frame.isExtended());
    toSave.add("CLICKGUI:X:" + dev.hypnotic.ui.clickgui.ClickGUI.INSTANCE.x + ":Y:" + dev.hypnotic.ui.clickgui.ClickGUI.INSTANCE.y);
    for (Waypoint waypoint : WaypointManager.INSTANCE.waypoints) {
        toSave.add("WAYPOINT:NAME:" + waypoint.getName() + ":X:" + waypoint.getX() + ":Y:" + waypoint.getY() + ":Z:" + waypoint.getZ());
    }
    try {
        PrintWriter pw = new PrintWriter(this.dataFile);
        for (String str : toSave) {
            pw.println(str);
        }
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : Frame(dev.hypnotic.ui.clickgui2.frame.Frame) Mod(dev.hypnotic.module.Mod) Friend(dev.hypnotic.config.friends.Friend) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Waypoint(dev.hypnotic.waypoint.Waypoint) HudModule(dev.hypnotic.module.hud.HudModule) PrintWriter(java.io.PrintWriter)

Example 3 with HudModule

use of dev.hypnotic.module.hud.HudModule in project Hypnotic-Client by Hypnotic-Development.

the class HudEditorScreen method mouseReleased.

@Override
public boolean mouseReleased(double mouseX, double mouseY, int button) {
    frame.mouseReleased(button);
    for (HudModule element : HudManager.INSTANCE.hudModules) {
        if (button == 0) {
            element.setDragging(false);
            element.setScaling(false);
        }
    }
    return super.mouseReleased(mouseX, mouseY, button);
}
Also used : HudModule(dev.hypnotic.module.hud.HudModule)

Example 4 with HudModule

use of dev.hypnotic.module.hud.HudModule in project Hypnotic-Client by Hypnotic-Development.

the class ConfigManager method load.

public boolean load(String name) {
    Config config = new Config(name);
    try {
        String configString = new String(Files.readAllBytes(config.getFile().toPath()));
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
        Mod[] modules = gson.fromJson(configString, Mod[].class);
        HudModule[] hudModules = gson.fromJson(configString, HudModule[].class);
        for (Mod module : ModuleManager.INSTANCE.getAllModules()) {
            for (HudModule configHudModule : hudModules) {
                HudModule hudMod = (HudModule) module;
                hudMod.setX(configHudModule.getX());
                hudMod.setY(configHudModule.getY());
            }
            for (Mod configModule : modules) {
                if (module.getName().equals(configModule.getName())) {
                    try {
                        if (configModule.isEnabled() && !module.isEnabled())
                            module.toggle();
                        else if (!configModule.isEnabled() && module.isEnabled())
                            module.setEnabled(false);
                        module.setKey(configModule.getKey());
                        if (module instanceof HudModule) {
                            HudModule hudMod = (HudModule) module;
                            HudModule configHudMod = (HudModule) configModule;
                            hudMod.setX(configHudMod.getX());
                            hudMod.setY(configHudMod.getY());
                        }
                        for (Setting setting : module.settings) {
                            for (ConfigSetting cfgSetting : configModule.cfgSettings) {
                                if (setting.name.equals(cfgSetting.name)) {
                                    if (setting instanceof BooleanSetting) {
                                        ((BooleanSetting) setting).setEnabled((boolean) cfgSetting.value);
                                    }
                                    if (setting instanceof ModeSetting) {
                                        ((ModeSetting) setting).setSelected((String) cfgSetting.value);
                                    }
                                    if (setting instanceof NumberSetting) {
                                        ((NumberSetting) setting).setValue((double) cfgSetting.value);
                                    }
                                    if (setting instanceof ColorSetting) {
                                        int[] color = ((ColorSetting) setting).hexToRgbInt((String) cfgSetting.value);
                                        ((ColorSetting) setting).setRGB(color[0], color[1], color[2], color[3]);
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Mod(dev.hypnotic.module.Mod) GsonBuilder(com.google.gson.GsonBuilder) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) ColorSetting(dev.hypnotic.settings.settingtypes.ColorSetting) Setting(dev.hypnotic.settings.Setting) ModeSetting(dev.hypnotic.settings.settingtypes.ModeSetting) KeybindSetting(dev.hypnotic.settings.settingtypes.KeybindSetting) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) BooleanSetting(dev.hypnotic.settings.settingtypes.BooleanSetting) Gson(com.google.gson.Gson) HudModule(dev.hypnotic.module.hud.HudModule) IOException(java.io.IOException) NumberSetting(dev.hypnotic.settings.settingtypes.NumberSetting)

Example 5 with HudModule

use of dev.hypnotic.module.hud.HudModule in project Hypnotic-Client by Hypnotic-Development.

the class ModuleManager method getAllModules.

// All modules including hud modules
public ArrayList<Mod> getAllModules() {
    ArrayList<Mod> mods = new ArrayList<>();
    for (Mod mod : modules) {
        mods.add(mod);
    }
    for (HudModule hudMod : HudManager.INSTANCE.hudModules) {
        mods.add(hudMod);
    }
    mods.add(OptionsScreen.INSTANCE.options);
    return mods;
}
Also used : ArrayList(java.util.ArrayList) HudModule(dev.hypnotic.module.hud.HudModule)

Aggregations

HudModule (dev.hypnotic.module.hud.HudModule)9 Mod (dev.hypnotic.module.Mod)4 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Setting (dev.hypnotic.settings.Setting)2 BooleanSetting (dev.hypnotic.settings.settingtypes.BooleanSetting)2 ColorSetting (dev.hypnotic.settings.settingtypes.ColorSetting)2 KeybindSetting (dev.hypnotic.settings.settingtypes.KeybindSetting)2 ModeSetting (dev.hypnotic.settings.settingtypes.ModeSetting)2 NumberSetting (dev.hypnotic.settings.settingtypes.NumberSetting)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Friend (dev.hypnotic.config.friends.Friend)1 EventTarget (dev.hypnotic.event.EventTarget)1 BindingScreen (dev.hypnotic.ui.BindingScreen)1 OptionsScreen (dev.hypnotic.ui.OptionsScreen)1 Frame (dev.hypnotic.ui.clickgui2.frame.Frame)1 Waypoint (dev.hypnotic.waypoint.Waypoint)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1