Search in sources :

Example 6 with Setting

use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.

the class SettingsConfig method loadFromJson.

@Override
protected void loadFromJson(JsonElement json) {
    if (!json.isJsonObject())
        return;
    HashMap<String, Feature> features = new HashMap<>();
    for (Feature feature : WurstClient.INSTANCE.navigator.getList()) features.put(feature.getName(), feature);
    for (Entry<String, JsonElement> e : json.getAsJsonObject().entrySet()) {
        if (!e.getValue().isJsonObject())
            continue;
        Feature feature = features.get(e.getKey());
        if (feature == null)
            continue;
        HashMap<String, Setting> settings = new HashMap<>();
        for (Setting setting : feature.getSettings()) settings.put(setting.getName().toLowerCase(), setting);
        for (Entry<String, JsonElement> e2 : e.getValue().getAsJsonObject().entrySet()) {
            String key = e2.getKey().toLowerCase();
            if (!settings.containsKey(key))
                continue;
            settings.get(key).fromJson(e2.getValue());
        }
    }
}
Also used : HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) Setting(net.wurstclient.settings.Setting) Feature(net.wurstclient.features.Feature)

Example 7 with Setting

use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.

the class SettingsConfig method saveToJson.

@Override
protected JsonElement saveToJson() {
    JsonObject json = new JsonObject();
    for (Feature feature : WurstClient.INSTANCE.navigator.getList()) {
        if (feature.getSettings().isEmpty())
            continue;
        JsonObject settings = new JsonObject();
        for (Setting setting : feature.getSettings()) settings.add(setting.getName(), setting.toJson());
        json.add(feature.getName(), settings);
    }
    return json;
}
Also used : Setting(net.wurstclient.settings.Setting) JsonObject(com.google.gson.JsonObject) Feature(net.wurstclient.features.Feature)

Example 8 with Setting

use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.

the class FeatureButton method handleMouseClick.

@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
    if (mouseButton != 0)
        return;
    if (!feature.getSettings().isEmpty() && mouseX > getX() + getWidth() - 12) {
        if (settingsWindow != null && !settingsWindow.isClosing()) {
            settingsWindow.close();
            settingsWindow = null;
            return;
        }
        settingsWindow = new Window(feature.getName() + " Settings");
        for (Setting setting : feature.getSettings()) settingsWindow.add(setting.getComponent());
        settingsWindow.setClosable(true);
        settingsWindow.setMinimizable(false);
        settingsWindow.pack();
        int scroll = getParent().isScrollingEnabled() ? getParent().getScrollOffset() : 0;
        int x = getParent().getX() + getParent().getWidth() + 5;
        int y = getParent().getY() + 12 + getY() + scroll;
        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
        if (x + settingsWindow.getWidth() > sr.getScaledWidth())
            x = getParent().getX() - settingsWindow.getWidth() - 5;
        if (y + settingsWindow.getHeight() > sr.getScaledHeight())
            y -= settingsWindow.getHeight() - 14;
        settingsWindow.setX(x);
        settingsWindow.setY(y);
        ClickGui gui = WurstClient.INSTANCE.getGui();
        gui.addWindow(settingsWindow);
        return;
    }
    feature.doPrimaryAction();
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) Setting(net.wurstclient.settings.Setting)

Example 9 with Setting

use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.

the class SetSliderCmd method call.

@Override
public void call(String[] args) throws CmdException {
    if (args.length != 3)
        throw new CmdSyntaxError();
    // find feature
    Feature feature = null;
    String featureName = args[0];
    for (Iterator itr = wurst.navigator.iterator(); itr.hasNext(); ) {
        Feature item = (Feature) itr.next();
        if (featureName.equalsIgnoreCase(item.getName())) {
            feature = item;
            break;
        }
    }
    if (feature == null)
        throw new CmdError("A feature named \"" + featureName + "\" could not be found.");
    // find setting
    Setting setting = null;
    String settingName = args[1].replace("_", " ");
    for (Setting featureSetting : feature.getSettings()) if (featureSetting.getName().equalsIgnoreCase(settingName)) {
        setting = featureSetting;
        break;
    }
    if (setting == null)
        throw new CmdError("A setting named \"" + settingName + "\" could not be found in " + feature.getName() + ".");
    // check that setting is slider setting
    if (!(setting instanceof SliderSetting))
        throw new CmdError(feature.getName() + " " + setting.getName() + " is not a slider setting.");
    SliderSetting sliderSetting = (SliderSetting) setting;
    // set value
    String valueName = args[2];
    if (valueName.equalsIgnoreCase("more"))
        sliderSetting.increaseValue();
    else if (valueName.equalsIgnoreCase("less"))
        sliderSetting.decreaseValue();
    else {
        // parse value
        if (!MiscUtils.isDouble(valueName))
            throw new CmdSyntaxError("Value must be a number.");
        double value = Double.parseDouble(valueName);
        // set value
        sliderSetting.setValue(value);
    }
}
Also used : SliderSetting(net.wurstclient.settings.SliderSetting) Setting(net.wurstclient.settings.Setting) Iterator(java.util.Iterator) SliderSetting(net.wurstclient.settings.SliderSetting) Feature(net.wurstclient.features.Feature)

Aggregations

Setting (net.wurstclient.settings.Setting)9 Feature (net.wurstclient.features.Feature)6 Iterator (java.util.Iterator)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 PossibleKeybind (net.wurstclient.keybinds.PossibleKeybind)2 CheckboxSetting (net.wurstclient.settings.CheckboxSetting)2 SliderSetting (net.wurstclient.settings.SliderSetting)2 JsonElement (com.google.gson.JsonElement)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 GuiButton (net.minecraft.client.gui.GuiButton)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 Mod (net.wurstclient.features.Mod)1 Keybind (net.wurstclient.keybinds.KeybindList.Keybind)1 NavigatorNewKeybindScreen (net.wurstclient.keybinds.NavigatorNewKeybindScreen)1 NavigatorRemoveKeybindScreen (net.wurstclient.keybinds.NavigatorRemoveKeybindScreen)1 ModeSetting (net.wurstclient.settings.ModeSetting)1