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());
}
}
}
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;
}
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();
}
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);
}
}
Aggregations