Search in sources :

Example 1 with ManualEntry

use of blusunrize.lib.manual.ManualInstance.ManualEntry in project ImmersiveEngineering by BluSunrize.

the class GuiManual method keyTyped.

@Override
protected void keyTyped(char c, int i) throws IOException {
    if (this.searchField != null && this.searchField.textboxKeyTyped(c, i)) {
        String search = searchField.getText();
        if (search == null || search.trim().isEmpty()) {
            hasSuggestions = -1;
            this.initGui();
        } else {
            search = search.toLowerCase(Locale.ENGLISH);
            ArrayList<String> lHeaders = new ArrayList<String>();
            HashMap<String, String> lSpellcheck = new HashMap<String, String>();
            for (ManualEntry e : manual.manualContents.values()) {
                if (manual.showEntryInList(e)) {
                    if (manual.formatEntryName(e.getName()).toLowerCase(Locale.ENGLISH).contains(search))
                        lHeaders.add(e.getName());
                    else
                        lSpellcheck.put(manual.formatEntryName(e.getName()), e.getName());
                }
            }
            ArrayList<String> lCorrections = ManualUtils.getPrimitiveSpellingCorrections(search, lSpellcheck.keySet().toArray(new String[lSpellcheck.keySet().size()]), 4);
            for (String key : lSpellcheck.keySet()) if (!lCorrections.contains(key)) {
                ManualEntry e = manual.getEntry(lSpellcheck.get(key));
                for (IManualPage page : e.getPages()) if (page.listForSearch(search)) {
                    lHeaders.add(e.getName());
                    break;
                }
            }
            headers = lHeaders.toArray(new String[lHeaders.size()]);
            this.buttonList.set(0, new GuiClickableList(this, 0, guiLeft + 40, guiTop + 20, 100, 148, 1f, 1, headers));
            if (!lCorrections.isEmpty()) {
                GuiClickableList suggestions = new GuiClickableList(this, 11, guiLeft + 180, guiTop + 138, 100, 80, 1f, -1, lCorrections.toArray(new String[0]));
                if (hasSuggestions != -1)
                    this.buttonList.set(hasSuggestions, suggestions);
                else {
                    hasSuggestions = this.buttonList.size();
                    this.buttonList.add(suggestions);
                }
                this.suggestionHeaders = new String[lCorrections.size()];
                for (int j = 0; j < this.suggestionHeaders.length; j++) this.suggestionHeaders[j] = lSpellcheck.get(lCorrections.get(j));
            } else if (hasSuggestions != -1) {
                this.buttonList.remove(hasSuggestions);
                hasSuggestions = -1;
            }
        }
    } else {
        super.keyTyped(c, i);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry) IManualPage(blusunrize.lib.manual.IManualPage)

Example 2 with ManualEntry

use of blusunrize.lib.manual.ManualInstance.ManualEntry in project ImmersiveEngineering by BluSunrize.

the class GuiManual method drawScreen.

@Override
public void drawScreen(int mx, int my, float f) {
    manualTick++;
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    boolean uni = manual.fontRenderer.getUnicodeFlag();
    manual.fontRenderer.setUnicodeFlag(true);
    manual.entryRenderPre();
    ManualUtils.bindTexture(texture);
    this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
    if (this.searchField != null) {
        int l = searchField.getText() != null ? searchField.getText().length() * 6 : 0;
        if (l > 20)
            this.drawTexturedModalRect(guiLeft + 166, guiTop + 74, 136 + (120 - l), 238, l, 18);
        if (this.hasSuggestions != -1 && this.hasSuggestions < this.buttonList.size()) {
            this.drawTexturedModalRect(guiLeft + 174, guiTop + 100, 214, 212, 16, 26);
            int h = ((GuiClickableList) this.buttonList.get(hasSuggestions)).getFontHeight() * Math.min(((GuiClickableList) this.buttonList.get(hasSuggestions)).perPage, ((GuiClickableList) this.buttonList.get(hasSuggestions)).entries.length);
            int w = 76;
            //Top Left
            this.drawTexturedModalRect(guiLeft + 174, guiTop + 116, 230, 212, 16, 16);
            //Bottom Left
            this.drawTexturedModalRect(guiLeft + 174, guiTop + 132 + h, 230, 228, 16, 10);
            //Top Right
            this.drawTexturedModalRect(guiLeft + 190 + w, guiTop + 116, 246, 212, 10, 16);
            //Bottom Right
            this.drawTexturedModalRect(guiLeft + 190 + w, guiTop + 132 + h, 246, 228, 10, 10);
            for (int hh = 0; hh < h; hh++) {
                this.drawTexturedModalRect(guiLeft + 174, guiTop + 132 + hh, 230, 228, 16, 1);
                for (int ww = 0; ww < w; ww++) this.drawTexturedModalRect(guiLeft + 190 + ww, guiTop + 132 + hh, 246, 228, 1, 1);
                this.drawTexturedModalRect(guiLeft + 190 + w, guiTop + 132 + hh, 246, 228, 10, 1);
            }
            for (int ww = 0; ww < w; ww++) {
                this.drawTexturedModalRect(guiLeft + 190 + ww, guiTop + 116, 246, 212, 1, 16);
                this.drawTexturedModalRect(guiLeft + 190 + ww, guiTop + 132 + h, 246, 228, 1, 10);
            }
        }
    }
    if (manual.getEntry(selectedEntry) != null) {
        ManualEntry entry = manual.getEntry(selectedEntry);
        mx -= guiLeft;
        my -= guiTop;
        boolean b0 = mx > 32 && mx < 32 + 17 && my > 179 && my < 179 + 10;
        boolean b1 = mx > 135 && mx < 135 + 17 && my > 179 && my < 179 + 10;
        GL11.glEnable(GL11.GL_BLEND);
        if (page > 0)
            this.drawTexturedModalRect(guiLeft + 32, guiTop + 179, 0, 216 + (b0 ? 20 : 0), 16, 10);
        if (page < entry.getPages().length - 1)
            this.drawTexturedModalRect(guiLeft + 136, guiTop + 179, 0, 226 + (b1 ? 20 : 0), 16, 10);
        manual.titleRenderPre();
        //Title
        this.drawCenteredStringScaled(manual.fontRenderer, TextFormatting.BOLD + manual.formatEntryName(entry.getName()), guiLeft + xSize / 2, guiTop + 14, manual.getTitleColour(), 1, true);
        this.drawCenteredStringScaled(manual.fontRenderer, manual.formatEntrySubtext(entry.getName()), guiLeft + xSize / 2, guiTop + 22, manual.getSubTitleColour(), 1, true);
        //Page Number
        this.drawCenteredStringScaled(manual.fontRenderer, TextFormatting.BOLD.toString() + (page + 1), guiLeft + xSize / 2, guiTop + 183, manual.getPagenumberColour(), 1, false);
        manual.titleRenderPost();
        GL11.glColor3f(1, 1, 1);
        IManualPage mPage = (page < 0 || page >= entry.getPages().length) ? null : entry.getPages()[page];
        if (mPage != null)
            mPage.renderPage(this, guiLeft + 32, guiTop + 28, mx + guiLeft, my + guiTop);
        mx += guiLeft;
        my += guiTop;
    } else {
        String title = manual.manualContents.containsKey(selectedCategory) ? manual.formatCategoryName(selectedCategory) : manual.getManualName();
        manual.titleRenderPre();
        this.drawCenteredStringScaled(manual.fontRenderer, TextFormatting.BOLD + title, guiLeft + xSize / 2, guiTop + 12, manual.getTitleColour(), 1, true);
        manual.titleRenderPost();
    }
    if (this.searchField != null) {
        manual.fontRenderer.setUnicodeFlag(true);
        this.searchField.drawTextBox();
        if (this.hasSuggestions != -1 && this.hasSuggestions < this.buttonList.size())
            manual.fontRenderer.drawString("It looks like you meant:", guiLeft + 180, guiTop + 128, manual.getTextColour(), false);
    }
    manual.fontRenderer.setUnicodeFlag(uni);
    super.drawScreen(mx, my, f);
    GlStateManager.enableBlend();
    manual.entryRenderPost();
}
Also used : ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry) IManualPage(blusunrize.lib.manual.IManualPage)

Example 3 with ManualEntry

use of blusunrize.lib.manual.ManualInstance.ManualEntry in project ImmersiveEngineering by BluSunrize.

the class GuiManual method mouseClickMove.

@Override
protected void mouseClickMove(int mx, int my, int button, long time) {
    if (lastClick != null && manual.getEntry(selectedEntry) != null && page < manual.getEntry(selectedEntry).getPages().length) {
        ManualEntry entry = manual.getEntry(selectedEntry);
        if (lastDrag == null)
            lastDrag = new int[] { mx - guiLeft, my - guiTop };
        entry.getPages()[page].mouseDragged(guiLeft + 32, guiTop + 28, lastClick[0], lastClick[1], mx - guiLeft, my - guiTop, lastDrag[0], lastDrag[1], button);
        lastDrag = new int[] { mx - guiLeft, my - guiTop };
    }
}
Also used : ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry)

Example 4 with ManualEntry

use of blusunrize.lib.manual.ManualInstance.ManualEntry in project ImmersiveEngineering by BluSunrize.

the class GuiManual method handleMouseInput.

@Override
public void handleMouseInput() throws IOException {
    super.handleMouseInput();
    int wheel = Mouse.getEventDWheel();
    if (wheel != 0 && manual.getEntry(selectedEntry) != null) {
        ManualEntry entry = manual.getEntry(selectedEntry);
        if (wheel > 0 && page > 0) {
            page--;
            this.initGui();
        } else if (wheel < 0 && page < entry.getPages().length - 1) {
            page++;
            this.initGui();
        }
    }
}
Also used : ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry)

Example 5 with ManualEntry

use of blusunrize.lib.manual.ManualInstance.ManualEntry in project ImmersiveEngineering by BluSunrize.

the class GuiManual method initGui.

@Override
public void initGui() {
    if (Minecraft.getMinecraft().gameSettings.guiScale == 1) {
        Minecraft.getMinecraft().gameSettings.guiScale = 2;
        ScaledResolution res = new ScaledResolution(this.mc);
        this.width = res.getScaledWidth();
        this.height = res.getScaledHeight();
        Minecraft.getMinecraft().gameSettings.guiScale = 1;
    }
    this.manual.openManual();
    guiLeft = (this.width - this.xSize) / 2;
    guiTop = (this.height - this.ySize) / 2;
    boolean textField = false;
    this.buttonList.clear();
    this.pageButtons.clear();
    headers = new String[0];
    suggestionHeaders = new String[0];
    hasSuggestions = -1;
    if (manual.getEntry(selectedEntry) != null) {
        ManualEntry entry = manual.getEntry(selectedEntry);
        IManualPage mPage = (page < 0 || page >= entry.getPages().length) ? null : entry.getPages()[page];
        if (mPage != null)
            mPage.initPage(this, guiLeft + 32, guiTop + 28, pageButtons);
        buttonList.addAll(pageButtons);
    } else if (manual.getSortedCategoryList() == null || manual.getSortedCategoryList().length <= 1) {
        ArrayList<String> lHeaders = new ArrayList<String>();
        for (ManualEntry e : manual.manualContents.values()) if (manual.showEntryInList(e))
            lHeaders.add(e.getName());
        headers = lHeaders.toArray(new String[lHeaders.size()]);
        this.buttonList.add(new GuiClickableList(this, 0, guiLeft + 40, guiTop + 20, 100, 168, 1f, 1, headers));
        textField = true;
    } else if (manual.manualContents.containsKey(selectedCategory)) {
        ArrayList<String> lHeaders = new ArrayList<String>();
        for (ManualEntry e : manual.manualContents.get(selectedCategory)) if (manual.showEntryInList(e))
            lHeaders.add(e.getName());
        headers = lHeaders.toArray(new String[lHeaders.size()]);
        this.buttonList.add(new GuiClickableList(this, 0, guiLeft + 40, guiTop + 20, 100, 168, 1f, 1, headers));
        textField = true;
    } else {
        ArrayList<String> lHeaders = new ArrayList<String>();
        for (String cat : manual.getSortedCategoryList()) if (manual.showCategoryInList(cat))
            lHeaders.add(cat);
        headers = lHeaders.toArray(new String[lHeaders.size()]);
        this.buttonList.add(new GuiClickableList(this, 0, guiLeft + 40, guiTop + 20, 100, 168, 1f, 0, headers));
        textField = true;
    }
    if (manual.manualContents.containsKey(selectedCategory) || manual.getEntry(selectedEntry) != null)
        this.buttonList.add(new GuiButtonManualNavigation(this, 1, guiLeft + 24, guiTop + 10, 10, 10, 0));
    if (textField) {
        Keyboard.enableRepeatEvents(true);
        searchField = new GuiTextField(99, this.fontRendererObj, guiLeft + 166, guiTop + 78, 120, 12);
        searchField.setTextColor(-1);
        searchField.setDisabledTextColour(-1);
        searchField.setEnableBackgroundDrawing(false);
        searchField.setMaxStringLength(17);
        searchField.setFocused(true);
        searchField.setCanLoseFocus(false);
    } else if (searchField != null)
        searchField = null;
}
Also used : ArrayList(java.util.ArrayList) ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry) IManualPage(blusunrize.lib.manual.IManualPage)

Aggregations

ManualEntry (blusunrize.lib.manual.ManualInstance.ManualEntry)6 IManualPage (blusunrize.lib.manual.IManualPage)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1