Java Code Examples for codechicken.lib.gui.GuiDraw#getMousePosition()

The following examples show how to use codechicken.lib.gui.GuiDraw#getMousePosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerEventHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SubscribeEvent (priority = EventPriority.LOWEST, receiveCanceled = true)//We need to be called before JEI.
public void onGuiMouseEventpre(MouseInputEvent.Pre event) {
    if (Mouse.getEventButton() == -1 || event.getGui() == null || !Mouse.getEventButtonState()) {
        return;
    }
    Point mouse = GuiDraw.getMousePosition();
    int eventButton = Mouse.getEventButton();
    if (JEIIntegrationManager.searchBoxOwner == EnumItemBrowser.JEI) {
        GuiTextFieldFilter fieldFilter = JEIIntegrationManager.getTextFieldFilter();
        if (fieldFilter != null && fieldFilter.isMouseOver(mouse.x, mouse.y)) {
            if (eventButton == 0) {
                if (fieldFilter.isFocused() && (System.currentTimeMillis() - lastSearchBoxClickTime < 500)) {//double click
                    NEIClientConfig.world.nbt.setBoolean("searchinventories", !SearchField.searchInventories());
                    NEIClientConfig.world.saveNBT();
                    lastSearchBoxClickTime = 0L;
                } else {
                    lastSearchBoxClickTime = System.currentTimeMillis();
                }
            } else if (eventButton == 1) {
                NEIClientConfig.setSearchExpression("", false);
                LayoutManager.searchField.setText("", false);
            }
        }
    }
}
 
Example 2
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SubscribeEvent
public void drawScreenPost(DrawScreenEvent.Post event) {
    GuiScreen screen = event.getGui();

    Point mousePos = GuiDraw.getMousePosition();
    List<String> tooltip = new LinkedList<>();
    ItemStack stack = ItemStack.EMPTY;
    if (instanceTooltipHandlers != null) {
        instanceTooltipHandlers.forEach(handler -> handler.handleTooltip(screen, mousePos.x, mousePos.y, tooltip));
    }

    if (screen instanceof GuiContainer) {
        if (tooltip.isEmpty() && GuiHelper.shouldShowTooltip(screen)) {
            GuiContainer container = (GuiContainer) screen;
            stack = GuiHelper.getStackMouseOver(container, false);

            if (!stack.isEmpty()) {
                tooltip.clear();
                tooltip.addAll(GuiHelper.itemDisplayNameMultiline(stack, container, false));
            }
        }
    }

    GuiDraw.drawMultiLineTip(stack, mousePos.x + 10, mousePos.y - 12, tooltip);
}
 
Example 3
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SubscribeEvent
public void foregroundRenderEvent(GuiContainerEvent.DrawForeground event) {
    GuiContainer container = event.getGuiContainer();
    GlStateTracker.pushState();
    Point mousePos = GuiDraw.getMousePosition();

    GlStateManager.translate(-container.getGuiLeft(), -container.getGuiTop(), 100F);
    drawHandlers.forEach(handler -> handler.renderObjects(container, mousePos.x, mousePos.y));

    drawHandlers.forEach(handler -> handler.postRenderObjects(container, mousePos.x, mousePos.y));

    GlStateManager.translate(container.getGuiLeft(), container.getGuiTop(), -100F);
    GuiHelper.enable3DRender();

    GlStateManager.pushMatrix();
    for (Slot slot : container.inventorySlots.inventorySlots) {
        GlStateTracker.pushState();
        drawHandlers.forEach(handler -> handler.renderSlotOverlay(container, slot));
        GlStateTracker.popState();
    }
    GlStateManager.popMatrix();

    GlStateTracker.popState();
}
 
Example 4
Source File: ItemPanel.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
    if (KeyBindings.get("nei.options.keys.gui.next").isActiveAndMatches(keyID)) {
        scroll(1);
        return true;
    }
    if (KeyBindings.get("nei.options.keys.gui.prev").isActiveAndMatches(keyID)) {
        scroll(-1);
        return true;
    }

    Point mouse = GuiDraw.getMousePosition();
    ItemPanelSlot hoverSlot = getSlotMouseOver(mouse.x, mouse.y);
    if (hoverSlot != null && draggedStack.isEmpty()) {
        ItemStack item = hoverSlot.item;
        if (KeyBindings.get("nei.options.keys.gui.recipe").isActiveAndMatches(keyID)) {
            JEIIntegrationManager.openRecipeGui(item);
            return true;
        } else if (KeyBindings.get("nei.options.keys.gui.usage").isActiveAndMatches(keyID)) {
            JEIIntegrationManager.openUsageGui(item);
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: RecipeHandlerBase.java    From NEI-Integration with MIT License 6 votes vote down vote up
protected boolean transferFluidTank(GuiRecipe guiRecipe, int recipe, boolean usage) {
    CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
    Point mousepos = GuiDraw.getMousePosition();
    Point offset = guiRecipe.getRecipePosition(recipe);
    Point relMouse = new Point(mousepos.x - (guiRecipe.width - 176) / 2 - offset.x, mousepos.y - (guiRecipe.height - 166) / 2 - offset.y);
    
    if (crecipe.getFluidTanks() != null) {
        for (PositionedFluidTank tank : crecipe.getFluidTanks()) {
            if (tank.position.contains(relMouse)) {
                return tank.transfer(usage);
            }
        }
    }
    
    return false;
}
 
Example 6
Source File: PneumaticCraftPlugins.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> handleTooltip(GuiRecipe guiRecipe, List<String> currenttip, int recipe){
    //  super.handleTooltip(guiRecipe, currenttip, recipe);
    MultipleInputOutputRecipe r = (MultipleInputOutputRecipe)arecipes.get(recipe);
    if(GuiContainerManager.shouldShowTooltip(guiRecipe)) {
        Point mouse = GuiDraw.getMousePosition();
        Point offset = guiRecipe.getRecipePosition(recipe);
        Point relMouse = new Point(mouse.x - (guiRecipe.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - 166) / 2 - offset.y);

        for(IGuiWidget widget : r.tooltipWidgets) {
            if(widget.getBounds().contains(relMouse)) {
                widget.addTooltip(mouse.x, mouse.y, currenttip, false);
            }
        }
        if(r.tempWidget != null) {
            if(r.tempWidget.getBounds().contains(relMouse)) {
                r.heatExchanger.setTemperature(r.tempWidget.getScales()[0]);
                r.tempWidget.addTooltip(mouse.x, mouse.y, currenttip, false);
            }
        }
    }
    return currenttip;
}
 
Example 7
Source File: GuiRecipe.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public boolean isMouseOver(PositionedStack stack, int recipe) {
    Slot stackSlot = slotcontainer.getSlotWithStack(stack, getRecipePosition(recipe).x, getRecipePosition(recipe).y);
    Point mousepos = GuiDraw.getMousePosition();
    Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);

    return stackSlot == mouseoverSlot;
}
 
Example 8
Source File: FireworkRecipeHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe) {
    currenttip = super.handleTooltip(gui, currenttip, recipe);
    Point mousepos = GuiDraw.getMousePosition();
    Point relMouse = new Point(mousepos.x - gui.guiLeft, mousepos.y - gui.guiTop);
    Point recipepos = gui.getRecipePosition(recipe);
    if (currenttip.isEmpty() && GuiContainerManager.getStackMouseOver(gui) == null && new Rectangle(recipepos.x, recipepos.y, 166, 55).contains(relMouse)) {
        currenttip.add(NEIClientUtils.translate("recipe.firework.tooltip" + ((CachedFireworkRecipe) arecipes.get(recipe)).recipeType));
    }
    return currenttip;
}
 
Example 9
Source File: GuiRecipe.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public boolean isMouseOver(PositionedStack stack, int recipe) {
    Slot stackSlot = slotcontainer.getSlotWithStack(stack, getRecipePosition(recipe).x, getRecipePosition(recipe).y);
    Point mousepos = GuiDraw.getMousePosition();
    Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);

    return stackSlot == mouseoverSlot;
}
 
Example 10
Source File: FireworkRecipeHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public List<String> handleTooltip(GuiRecipe gui, List<String> currenttip, int recipe) {
    currenttip = super.handleTooltip(gui, currenttip, recipe);
    Point mousepos = GuiDraw.getMousePosition();
    Point relMouse = new Point(mousepos.x - gui.guiLeft, mousepos.y - gui.guiTop);
    Point recipepos = gui.getRecipePosition(recipe);
    if (currenttip.isEmpty() && GuiContainerManager.getStackMouseOver(gui) == null &&
            new Rectangle(recipepos.x, recipepos.y, 166, 55).contains(relMouse))
        currenttip.add(NEIClientUtils.translate(
                "recipe.firework.tooltip" + ((CachedFireworkRecipe) arecipes.get(recipe)).recipeType));
    return currenttip;
}
 
Example 11
Source File: RecipeHandlerBase.java    From NEI-Integration with MIT License 5 votes vote down vote up
@Override
public List<String> handleTooltip(GuiRecipe guiRecipe, List<String> currenttip, int recipe) {
    super.handleTooltip(guiRecipe, currenttip, recipe);
    CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
    if (GuiContainerManager.shouldShowTooltip(guiRecipe)) {
        Point mouse = GuiDraw.getMousePosition();
        Point offset = guiRecipe.getRecipePosition(recipe);
        Point relMouse = new Point(mouse.x - (guiRecipe.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - 166) / 2 - offset.y);
        
        currenttip = this.provideTooltip(guiRecipe, currenttip, crecipe, relMouse);
    }
    return currenttip;
}
 
Example 12
Source File: RecipeHandlerBase.java    From NEI-Integration with MIT License 5 votes vote down vote up
@Override
public List<String> handleItemTooltip(GuiRecipe guiRecipe, ItemStack itemStack, List<String> currenttip, int recipe) {
    super.handleItemTooltip(guiRecipe, itemStack, currenttip, recipe);
    CachedBaseRecipe crecipe = (CachedBaseRecipe) this.arecipes.get(recipe);
    Point mouse = GuiDraw.getMousePosition();
    Point offset = guiRecipe.getRecipePosition(recipe);
    Point relMouse = new Point(mouse.x - (guiRecipe.width - 176) / 2 - offset.x, mouse.y - (guiRecipe.height - 166) / 2 - offset.y);
    
    currenttip = this.provideItemTooltip(guiRecipe, itemStack, currenttip, crecipe, relMouse);
    return currenttip;
}
 
Example 13
Source File: GuiContainerWidget.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public void handleMouseInput() throws IOException {
    super.handleMouseInput();
    int i = Mouse.getEventDWheel();
    if (i != 0) {
        Point p = GuiDraw.getMousePosition();
        int scroll = i > 0 ? 1 : -1;
        for (GuiWidget widget : widgets)
            widget.mouseScrolled(p.x, p.y, scroll);
    }
}
 
Example 14
Source File: GuiScreenWidget.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public void handleMouseInput() throws IOException {
    super.handleMouseInput();
    int i = Mouse.getEventDWheel();
    if (i != 0) {
        Point p = GuiDraw.getMousePosition();
        int scroll = i > 0 ? 1 : -1;
        for (GuiWidget widget : widgets)
            widget.mouseScrolled(p.x, p.y, scroll);
    }
}
 
Example 15
Source File: SubsetWidget.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public void update() {
    Point mouse = GuiDraw.getMousePosition();
    updateVisiblity(mouse.x, mouse.y);
    saveHidden();
}
 
Example 16
Source File: SubsetWidget.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public void update() {
    Point mouse = GuiDraw.getMousePosition();
    updateVisiblity(mouse.x, mouse.y);
    saveHidden();
}