Search in sources :

Example 1 with Feature

use of net.wurstclient.features.Feature in project Wurst-MC-1.12 by Wurst-Imperium.

the class ClickGui method init.

public void init() {
    LinkedHashMap<Category, Window> windowMap = new LinkedHashMap<>();
    for (Category category : Category.values()) windowMap.put(category, new Window(category.getName()));
    ArrayList<Feature> features = new ArrayList<>();
    features.addAll(WurstClient.INSTANCE.mods.getAllMods());
    features.addAll(WurstClient.INSTANCE.commands.getAllCommands());
    features.addAll(WurstClient.INSTANCE.special.getAllFeatures());
    for (Feature f : features) if (f.getCategory() != null)
        windowMap.get(f.getCategory()).add(new FeatureButton(f));
    windows.addAll(windowMap.values());
    int x = 5;
    int y = 5;
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    for (Window window : windows) {
        window.pack();
        window.setMinimized(true);
        if (x + window.getWidth() + 5 > sr.getScaledWidth()) {
            x = 5;
            y += 18;
        }
        window.setX(x);
        window.setY(y);
        x += window.getWidth() + 5;
    }
    JsonObject json;
    try (BufferedReader reader = Files.newBufferedReader(windowsFile)) {
        json = JsonUtils.jsonParser.parse(reader).getAsJsonObject();
    } catch (NoSuchFileException e) {
        saveWindows();
        return;
    } catch (Exception e) {
        System.out.println("Failed to load " + windowsFile.getFileName());
        e.printStackTrace();
        saveWindows();
        return;
    }
    for (Window window : windows) {
        JsonElement jsonWindow = json.get(window.getTitle());
        if (jsonWindow == null || !jsonWindow.isJsonObject())
            continue;
        JsonElement jsonX = jsonWindow.getAsJsonObject().get("x");
        if (jsonX.isJsonPrimitive() && jsonX.getAsJsonPrimitive().isNumber())
            window.setX(jsonX.getAsInt());
        JsonElement jsonY = jsonWindow.getAsJsonObject().get("y");
        if (jsonY.isJsonPrimitive() && jsonY.getAsJsonPrimitive().isNumber())
            window.setY(jsonY.getAsInt());
        JsonElement jsonMinimized = jsonWindow.getAsJsonObject().get("minimized");
        if (jsonMinimized.isJsonPrimitive() && jsonMinimized.getAsJsonPrimitive().isBoolean())
            window.setMinimized(jsonMinimized.getAsBoolean());
        JsonElement jsonPinned = jsonWindow.getAsJsonObject().get("pinned");
        if (jsonPinned.isJsonPrimitive() && jsonPinned.getAsJsonPrimitive().isBoolean())
            window.setPinned(jsonPinned.getAsBoolean());
    }
    saveWindows();
}
Also used : Category(net.wurstclient.features.Category) ArrayList(java.util.ArrayList) NoSuchFileException(java.nio.file.NoSuchFileException) JsonObject(com.google.gson.JsonObject) Feature(net.wurstclient.features.Feature) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ScaledResolution(net.minecraft.client.gui.ScaledResolution) JsonElement(com.google.gson.JsonElement) BufferedReader(java.io.BufferedReader)

Example 2 with Feature

use of net.wurstclient.features.Feature 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();
}
Also used : Setting(net.wurstclient.settings.Setting) CheckboxSetting(net.wurstclient.settings.CheckboxSetting) Iterator(java.util.Iterator) Feature(net.wurstclient.features.Feature) CheckboxSetting(net.wurstclient.settings.CheckboxSetting)

Example 3 with Feature

use of net.wurstclient.features.Feature 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);
    }
}
Also used : ModeSetting(net.wurstclient.settings.ModeSetting) Setting(net.wurstclient.settings.Setting) ModeSetting(net.wurstclient.settings.ModeSetting) Iterator(java.util.Iterator) Feature(net.wurstclient.features.Feature)

Example 4 with Feature

use of net.wurstclient.features.Feature in project Wurst-MC-1.12 by Wurst-Imperium.

the class TabGui method render.

public void render(float partialTicks) {
    if (tabGuiSpf.isHidden())
        return;
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glPushMatrix();
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    int x = 2;
    int y = 23;
    GL11.glTranslatef(x, y, 0);
    drawBox(0, 0, width, height);
    int factor = sr.getScaleFactor();
    GL11.glScissor(x * factor, (sr.getScaledHeight() - height - y) * factor, width * factor, height * factor);
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    int textY = -2;
    for (int i = 0; i < tabs.size(); i++) {
        String tabName = tabs.get(i).name;
        if (i == selected)
            tabName = (tabOpened ? "<" : ">") + tabName;
        Fonts.segoe18.drawString(tabName, 2, textY, 0xffffffff);
        textY += 10;
    }
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    if (tabOpened) {
        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        Tab tab = tabs.get(selected);
        int tabX = x + width + 2;
        int tabY = y;
        GL11.glTranslatef(width + 2, 0, 0);
        drawBox(0, 0, tab.width, tab.height);
        GL11.glScissor(tabX * factor, (sr.getScaledHeight() - tab.height - tabY) * factor, tab.width * factor, tab.height * factor);
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        int tabTextY = -2;
        for (int i = 0; i < tab.features.size(); i++) {
            Feature feature = tab.features.get(i);
            String fName = feature.getName();
            if (feature.isEnabled())
                if (feature.isBlocked())
                    fName = "�c" + fName + "�r";
                else
                    fName = "�a" + fName + "�r";
            if (i == tab.selected)
                fName = ">" + fName;
            Fonts.segoe18.drawString(fName, 2, tabTextY, 0xffffffff);
            tabTextY += 10;
        }
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_CULL_FACE);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) Feature(net.wurstclient.features.Feature)

Example 5 with Feature

use of net.wurstclient.features.Feature 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));
}
Also used : PossibleKeybind(net.wurstclient.keybinds.PossibleKeybind) Mod(net.wurstclient.features.Mod) HashMap(java.util.HashMap) Setting(net.wurstclient.settings.Setting) SliderSetting(net.wurstclient.settings.SliderSetting) CheckboxSetting(net.wurstclient.settings.CheckboxSetting) Rectangle(java.awt.Rectangle) TreeMap(java.util.TreeMap) NavigatorNewKeybindScreen(net.wurstclient.keybinds.NavigatorNewKeybindScreen) Feature(net.wurstclient.features.Feature) NavigatorRemoveKeybindScreen(net.wurstclient.keybinds.NavigatorRemoveKeybindScreen) GuiButton(net.minecraft.client.gui.GuiButton) Keybind(net.wurstclient.keybinds.KeybindList.Keybind) PossibleKeybind(net.wurstclient.keybinds.PossibleKeybind)

Aggregations

Feature (net.wurstclient.features.Feature)11 Setting (net.wurstclient.settings.Setting)6 Iterator (java.util.Iterator)4 HashMap (java.util.HashMap)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 Rectangle (java.awt.Rectangle)2 ArrayList (java.util.ArrayList)2 ScaledResolution (net.minecraft.client.gui.ScaledResolution)2 WurstClient (net.wurstclient.WurstClient)2 CheckboxSetting (net.wurstclient.settings.CheckboxSetting)2 SliderSetting (net.wurstclient.settings.SliderSetting)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1