Search in sources :

Example 6 with Feature

use of net.wurstclient.features.Feature 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 Feature

use of net.wurstclient.features.Feature 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 Feature

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

the class Navigator method getSearchResults.

public void getSearchResults(ArrayList<Feature> list, String query) {
    // clear display list
    list.clear();
    // add search results
    for (Feature mod : navigatorList) if (mod.getName().toLowerCase().contains(query) || mod.getSearchTags().toLowerCase().contains(query) || mod.getDescription().toLowerCase().contains(query))
        list.add(mod);
    Comparator<String> c = (o1, o2) -> {
        int index1 = o1.toLowerCase().indexOf(query);
        int index2 = o2.toLowerCase().indexOf(query);
        if (index1 == index2)
            return 0;
        else if (index1 == -1)
            return 1;
        else if (index2 == -1)
            return -1;
        else
            return index1 - index2;
    };
    // sort search results
    list.sort(Comparator.comparing(Feature::getName, c).thenComparing(Feature::getSearchTags, c).thenComparing(Feature::getDescription, c));
}
Also used : Consumer(java.util.function.Consumer) List(java.util.List) AnalyticsManager(net.wurstclient.analytics.AnalyticsManager) Iterator(java.util.Iterator) WurstClient(net.wurstclient.WurstClient) HashMap(java.util.HashMap) Feature(net.wurstclient.features.Feature) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Feature(net.wurstclient.features.Feature)

Example 9 with Feature

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

the class NavigatorMainScreen method onRender.

@Override
protected void onRender(int mouseX, int mouseY, float partialTicks) {
    boolean clickTimerNotRunning = clickTimer == -1;
    // search bar
    if (clickTimerNotRunning) {
        Fonts.segoe22.drawString("Search: ", middleX - 150, 32, 0xffffff);
        searchBar.drawTextBox();
        glDisable(GL_TEXTURE_2D);
    }
    // feature list
    int x = middleX - 50;
    if (clickTimerNotRunning)
        hoveredFeature = -1;
    RenderUtils.scissorBox(0, 59, width, height - 42);
    glEnable(GL_SCISSOR_TEST);
    for (int i = Math.max(-scroll * 3 / 20 - 3, 0); i < navigatorDisplayList.size(); i++) {
        // y position
        int y = 60 + i / 3 * 20 + scroll;
        if (y < 40)
            continue;
        if (y > height - 40)
            break;
        // x position
        int xi = 0;
        switch(i % 3) {
            case 0:
                xi = x - 104;
                break;
            case 1:
                xi = x;
                break;
            case 2:
                xi = x + 104;
                break;
        }
        // feature & area
        Feature feature = navigatorDisplayList.get(i);
        Rectangle area = new Rectangle(xi, y, 100, 16);
        // click animation
        if (!clickTimerNotRunning) {
            if (i != hoveredFeature)
                continue;
            float factor;
            if (expanding)
                if (clickTimer == 4)
                    factor = 1F;
                else
                    factor = (clickTimer + partialTicks) / 4F;
            else if (clickTimer == 0)
                factor = 0F;
            else
                factor = (clickTimer - partialTicks) / 4F;
            float antiFactor = 1 - factor;
            area.x = (int) (area.x * antiFactor + (middleX - 154) * factor);
            area.y = (int) (area.y * antiFactor + 60 * factor);
            area.width = (int) (area.width * antiFactor + 308 * factor);
            area.height = (int) (area.height * antiFactor + (height - 103) * factor);
            drawBackgroundBox(area.x, area.y, area.x + area.width, area.y + area.height);
        } else {
            // color
            boolean hovering = area.contains(mouseX, mouseY);
            if (hovering)
                hoveredFeature = i;
            if (feature.isEnabled())
                if (feature.isBlocked())
                    glColor4f(hovering ? 1F : 0.875F, 0F, 0F, 0.5F);
                else
                    glColor4f(0F, hovering ? 1F : 0.875F, 0F, 0.5F);
            else if (hovering)
                glColor4f(0.375F, 0.375F, 0.375F, 0.5F);
            else
                glColor4f(0.25F, 0.25F, 0.25F, 0.5F);
            // box & shadow
            drawBox(area.x, area.y, area.x + area.width, area.y + area.height);
            // separator
            int bx1 = area.x + area.width - area.height;
            int by1 = area.y + 2;
            int by2 = by1 + area.height - 4;
            glBegin(GL_LINES);
            {
                glVertex2i(bx1, by1);
                glVertex2i(bx1, by2);
            }
            glEnd();
            // hovering
            if (hovering)
                hoveringArrow = mouseX >= bx1;
            // arrow positions
            double oneThrird = area.height / 3D;
            double twoThrirds = area.height * 2D / 3D;
            double ax1 = bx1 + oneThrird - 2D;
            double ax2 = bx1 + twoThrirds + 2D;
            double ax3 = bx1 + area.height / 2D;
            double ay1 = area.y + oneThrird;
            double ay2 = area.y + twoThrirds;
            // arrow
            glColor4f(0f, 1f, 0f, hovering ? 0.75f : 0.375f);
            glBegin(GL_TRIANGLES);
            {
                glVertex2d(ax1, ay1);
                glVertex2d(ax2, ay1);
                glVertex2d(ax3, ay2);
            }
            glEnd();
            // arrow shadow
            glLineWidth(1f);
            glColor4f(0.125f, 0.125f, 0.125f, hovering ? 0.75f : 0.5f);
            glBegin(GL_LINE_LOOP);
            {
                glVertex2d(ax1, ay1);
                glVertex2d(ax2, ay1);
                glVertex2d(ax3, ay2);
            }
            glEnd();
            // text
            if (clickTimerNotRunning) {
                String buttonText = feature.getName();
                Fonts.segoe15.drawString(buttonText, area.x + 4, area.y + 2, 0xffffff);
                glDisable(GL_TEXTURE_2D);
            }
        }
    }
    glDisable(GL_SCISSOR_TEST);
}
Also used : Rectangle(java.awt.Rectangle) Feature(net.wurstclient.features.Feature)

Example 10 with Feature

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

the class NavigatorMainScreen method onMouseClick.

@Override
protected void onMouseClick(int x, int y, int button) {
    if (clickTimer == -1 && hoveredFeature != -1)
        if (button == 0 && (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || hoveringArrow) || button == 2)
            // arrow click, shift click, wheel click
            expanding = true;
        else if (button == 0) {
            // left click
            Feature feature = navigatorDisplayList.get(hoveredFeature);
            if (feature.getPrimaryAction().isEmpty())
                expanding = true;
            else {
                feature.doPrimaryAction();
                WurstClient wurst = WurstClient.INSTANCE;
                wurst.navigator.addPreference(feature.getName());
                ConfigFiles.NAVIGATOR.save();
            }
        } else if (button == 1) {
            // right click
            Feature feature = navigatorDisplayList.get(hoveredFeature);
            if (feature.getHelpPage().isEmpty())
                return;
            MiscUtils.openLink("https://www.wurstclient.net/wiki/" + feature.getHelpPage() + "/");
            WurstClient wurst = WurstClient.INSTANCE;
            wurst.navigator.addPreference(feature.getName());
            ConfigFiles.NAVIGATOR.save();
            wurst.navigator.analytics.trackEvent("help", "open", feature.getName());
        }
}
Also used : WurstClient(net.wurstclient.WurstClient) Feature(net.wurstclient.features.Feature)

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