Search in sources :

Example 1 with NavigatorRemoveKeybindScreen

use of net.wurstclient.keybinds.NavigatorRemoveKeybindScreen 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

Rectangle (java.awt.Rectangle)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 GuiButton (net.minecraft.client.gui.GuiButton)1 Feature (net.wurstclient.features.Feature)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 PossibleKeybind (net.wurstclient.keybinds.PossibleKeybind)1 CheckboxSetting (net.wurstclient.settings.CheckboxSetting)1 Setting (net.wurstclient.settings.Setting)1 SliderSetting (net.wurstclient.settings.SliderSetting)1