use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.
the class SetCheckboxCmd 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 checkbox setting
if (!(setting instanceof CheckboxSetting))
throw new CmdError(feature.getName() + " " + setting.getName() + " is not a checkbox setting.");
CheckboxSetting checkboxSetting = (CheckboxSetting) setting;
// set check
String valueName = args[2];
if (valueName.equalsIgnoreCase("on"))
checkboxSetting.setChecked(true);
else if (valueName.equalsIgnoreCase("off"))
checkboxSetting.setChecked(false);
else if (valueName.equalsIgnoreCase("toggle"))
checkboxSetting.toggle();
else
throw new CmdSyntaxError();
}
use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.
the class SetModeCmd 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 mode setting
if (!(setting instanceof ModeSetting))
throw new CmdError(feature.getName() + " " + setting.getName() + " is not a mode setting.");
ModeSetting modeSetting = (ModeSetting) setting;
// set mode
String modeName = args[2].replace("_", " ");
if (modeName.equalsIgnoreCase("next"))
modeSetting.nextMode();
else if (modeName.equalsIgnoreCase("prev"))
modeSetting.prevMode();
else {
// find mode
int mode = modeSetting.indexOf(modeName);
if (mode == -1)
throw new CmdError("A " + feature.getName() + " " + setting.getName() + " named \"" + modeName + "\" could not be found.");
// set mode
modeSetting.setSelected(mode);
}
}
use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.
the class Mod method getPossibleKeybinds.
@Override
public final ArrayList<PossibleKeybind> getPossibleKeybinds() {
// mod keybinds
String dotT = ".t " + name.toLowerCase();
ArrayList<PossibleKeybind> possibleKeybinds = new ArrayList<>(Arrays.asList(new PossibleKeybind(dotT, "Toggle " + name), new PossibleKeybind(dotT + " on", "Enable " + name), new PossibleKeybind(dotT + " off", "Disable " + name)));
// settings keybinds
for (Setting setting : getSettings()) possibleKeybinds.addAll(setting.getPossibleKeybinds(name));
return possibleKeybinds;
}
use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.
the class NavigatorFeatureScreen method onResize.
@Override
protected void onResize() {
buttonDatas.clear();
// primary button
String primaryAction = feature.getPrimaryAction();
boolean hasPrimaryAction = !primaryAction.isEmpty();
boolean hasHelp = !feature.getHelpPage().isEmpty();
if (hasPrimaryAction) {
primaryButton = new GuiButton(0, width / 2 - 151, height - 65, hasHelp ? 149 : 302, 18, primaryAction);
buttonList.add(primaryButton);
}
// help button
if (hasHelp)
buttonList.add(new GuiButton(1, width / 2 + (hasPrimaryAction ? 2 : -151), height - 65, hasPrimaryAction ? 149 : 302, 20, "Help"));
// type
text = "Type: " + feature.getType();
// category
if (feature.getCategory() != null)
text += ", Category: " + feature.getCategory().getName();
// description
String description = feature.getDescription();
if (!description.isEmpty())
text += "\n\nDescription:\n" + description;
// area
Rectangle area = new Rectangle(middleX - 154, 60, 308, height - 103);
// settings
ArrayList<Setting> settings = feature.getSettings();
if (!settings.isEmpty()) {
text += "\n\nSettings:";
window.setY(Fonts.segoe15.getStringHeight(text) + 2);
sliders.clear();
checkboxes.clear();
for (int i = 0; i < Math.ceil(window.getInnerHeight() / 9.0); i++) text += "\n";
for (Setting setting : settings) if (setting.getComponent() == null)
setting.addToFeatureScreen(this);
}
// keybinds
ArrayList<PossibleKeybind> possibleKeybinds = feature.getPossibleKeybinds();
if (!possibleKeybinds.isEmpty()) {
// heading
text += "\n\nKeybinds:";
// add keybind button
ButtonData addKeybindButton = new ButtonData(area.x + area.width - 16, area.y + Fonts.segoe15.getStringHeight(text) - 7, 12, 8, "+", 0x00ff00) {
@Override
public void press() {
// add keybind
mc.displayGuiScreen(new NavigatorNewKeybindScreen(possibleKeybinds, NavigatorFeatureScreen.this));
}
};
buttonDatas.add(addKeybindButton);
// keybind list
HashMap<String, String> possibleKeybindsMap = new HashMap<>();
for (PossibleKeybind possibleKeybind : possibleKeybinds) possibleKeybindsMap.put(possibleKeybind.getCommand(), possibleKeybind.getDescription());
TreeMap<String, PossibleKeybind> existingKeybinds = new TreeMap<>();
boolean noKeybindsSet = true;
for (int i = 0; i < WurstClient.INSTANCE.getKeybinds().size(); i++) {
Keybind keybind = WurstClient.INSTANCE.getKeybinds().get(i);
String commands = keybind.getCommands();
commands = commands.replace(";", "�").replace("��", ";");
for (String command : commands.split("�")) {
command = command.trim();
String keybindDescription = possibleKeybindsMap.get(command);
if (keybindDescription != null) {
if (noKeybindsSet)
noKeybindsSet = false;
text += "\n" + keybind.getKey() + ": " + keybindDescription;
existingKeybinds.put(keybind.getKey(), new PossibleKeybind(command, keybindDescription));
} else if (feature instanceof Mod && command.equalsIgnoreCase(feature.getName())) {
if (noKeybindsSet)
noKeybindsSet = false;
text += "\n" + keybind.getKey() + ": " + "Toggle " + feature.getName();
existingKeybinds.put(keybind.getKey(), new PossibleKeybind(command, "Toggle " + feature.getName()));
}
}
}
if (noKeybindsSet)
text += "\nNone";
else {
// remove keybind button
buttonDatas.add(new ButtonData(addKeybindButton.x, addKeybindButton.y, addKeybindButton.width, addKeybindButton.height, "-", 0xff0000) {
@Override
public void press() {
// remove keybind
mc.displayGuiScreen(new NavigatorRemoveKeybindScreen(existingKeybinds, NavigatorFeatureScreen.this));
}
});
addKeybindButton.x -= 16;
}
}
// see also
Feature[] seeAlso = feature.getSeeAlso();
if (seeAlso.length != 0) {
text += "\n\nSee also:";
for (Feature seeAlsoFeature : seeAlso) {
int y = 60 + getTextHeight() + 2;
String name = seeAlsoFeature.getName();
text += "\n- " + name;
buttonDatas.add(new ButtonData(middleX - 148, y, Fonts.segoe15.getStringWidth(name) + 1, 8, "", 0x404040) {
@Override
public void press() {
mc.displayGuiScreen(new NavigatorFeatureScreen(seeAlsoFeature, parent));
}
});
}
}
// text height
setContentHeight(Fonts.segoe15.getStringHeight(text));
}
use of net.wurstclient.settings.Setting in project Wurst-MC-1.12 by Wurst-Imperium.
the class NavigatorConfig method loadFromJson.
@Override
protected void loadFromJson(JsonElement json) {
WurstClient.INSTANCE.navigator.forEach((feature) -> {
String featureName = feature.getName();
if (!json.getAsJsonObject().has(featureName))
return;
JsonObject jsonFeature = json.getAsJsonObject().get(featureName).getAsJsonObject();
// load preference
if (jsonFeature.has("preference"))
WurstClient.INSTANCE.navigator.setPreference(featureName, jsonFeature.get("preference").getAsLong());
// load settings
if (jsonFeature.has("settings")) {
JsonObject jsonSettings = jsonFeature.get("settings").getAsJsonObject();
for (Setting setting : feature.getSettings()) try {
setting.legacyFromJson(jsonSettings);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Aggregations