Search in sources :

Example 1 with MouseScroll

use of io.xol.chunkstories.api.input.Mouse.MouseScroll in project chunkstories by Hugobros3.

the class Ingame method handleInput.

@Override
public boolean handleInput(Input input) {
    // Block inputs if chatting
    if (input.equals("chat")) {
        gameWindow.setLayer(chatManager.new ChatPanelOverlay(gameWindow, this));
        focus(false);
        guiHidden = false;
        return true;
    } else if (input.equals("hideGui")) {
        guiHidden = !guiHidden;
        return true;
    } else if (input.equals("screenshot")) {
        chatManager.insert(world.getWorldRenderer().screenShot());
    } else if (input.equals("toggleDebugInfo")) {
        OptionBoolean debugInfo = (OptionBoolean) client.getConfiguration().getOption("client.debug.showDebugInfo");
        debugInfo.toggle();
        guiHidden = false;
        return true;
    } else if (input.equals("takeCubemap")) {
        // shouldTakeACubemap = true;
        return true;
    // CTRL-F12 reloads
    } else if (input.equals("reloadContent")) {
        // Rebuild the mod FS
        gameWindow.getClient().reloadAssets();
        // Reload plugins
        world.getPluginManager().reloadPlugins();
        // Mark some caches dirty
        world.getWorldRenderer().reloadContentSpecificStuff();
        return true;
    // CTRL-R redraws chunks
    } else if (input.equals("redrawChunks")) {
        ((ClientParticlesRenderer) world.getParticlesManager()).cleanAllParticles();
        world.redrawEverything();
        world.getWorldRenderer().flagChunksModified();
        return true;
    // Item slots selection
    } else if (input.getName().startsWith("inventorySlot")) {
        int requestedInventorySlot = Integer.parseInt(input.getName().replace("inventorySlot", ""));
        // Match zero onto last slot
        if (requestedInventorySlot == 0)
            requestedInventorySlot = 10;
        // Map to zero-indexed inventory
        requestedInventorySlot--;
        if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
            // Do not accept request to select non-existent inventories slots
            if (requestedInventorySlot > ((EntityWithInventory) playerEntity).getInventory().getWidth())
                return false;
            ItemPile p = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(requestedInventorySlot, 0);
            if (p != null)
                requestedInventorySlot = p.getX();
            ((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(requestedInventorySlot);
        }
        return true;
    } else if (input.equals("exit")) /* Exit brings up the pause menu */
    {
        focus(false);
        guiHidden = false;
        gameWindow.setLayer(new PauseMenu(gameWindow, this));
        return true;
    } else if (input instanceof MouseScroll) {
        MouseScroll ms = (MouseScroll) input;
        if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
            ItemPile selected = null;
            int selectedInventorySlot = ((EntityWithSelectedItem) playerEntity).getSelectedItemIndex();
            int originalSlot = selectedInventorySlot;
            if (ms.amount() < 0) {
                selectedInventorySlot %= ((EntityWithInventory) playerEntity).getInventory().getWidth();
                selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
                if (selected != null)
                    selectedInventorySlot += selected.getItem().getDefinition().getSlotsWidth();
                else
                    selectedInventorySlot++;
            } else {
                selectedInventorySlot--;
                if (selectedInventorySlot < 0)
                    selectedInventorySlot += ((EntityWithInventory) playerEntity).getInventory().getWidth();
                selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
                if (selected != null)
                    selectedInventorySlot = selected.getX();
            }
            // Switch slot
            if (originalSlot != selectedInventorySlot)
                ((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(selectedInventorySlot);
            return true;
        }
    }
    return false;
}
Also used : EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) EntityWithSelectedItem(io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem) ChatPanelOverlay(io.xol.chunkstories.gui.layer.ingame.ChatManager.ChatPanelOverlay) OptionBoolean(io.xol.chunkstories.api.util.Configuration.OptionBoolean) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) ClientParticlesRenderer(io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)

Example 2 with MouseScroll

use of io.xol.chunkstories.api.input.Mouse.MouseScroll in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputPressed.

public boolean onInputPressed(Input input) {
    if (input.equals("fullscreen")) {
        gameWindow.toggleFullscreen();
        return true;
    }
    // System.out.println("Input pressed "+input.getName());
    // Try the client-side event press
    ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
        if (event.isCancelled())
            return false;
    }
    // Try the GUI handling
    Layer layer = gameWindow.getLayer();
    if (layer.handleInput(input))
        return true;
    // System.out.println("wasn't handled");
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        // MouseScroll inputs are strictly client-side
        if (!(input instanceof MouseScroll)) {
            ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
            PacketInput packet = new PacketInput(world);
            packet.input = input;
            packet.isPressed = true;
            connection.pushPacket(packet);
        }
        return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
    } else {
        PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        if (event2.isCancelled())
            return false;
    // entity.handleInteraction(input, entity.getControllerComponent().getController());
    }
    // Handle interaction locally
    return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) ClientInputPressedEvent(io.xol.chunkstories.api.events.client.ClientInputPressedEvent) World(io.xol.chunkstories.api.world.World) Layer(io.xol.chunkstories.api.gui.Layer) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)

Example 3 with MouseScroll

use of io.xol.chunkstories.api.input.Mouse.MouseScroll in project chunkstories by Hugobros3.

the class ModsSelection method handleInput.

@Override
public boolean handleInput(Input input) {
    if (input instanceof MouseScroll) {
        MouseScroll ms = (MouseScroll) input;
        modsContainer.scroll(ms.amount() > 0);
        return true;
    }
    return super.handleInput(input);
}
Also used : MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll)

Aggregations

MouseScroll (io.xol.chunkstories.api.input.Mouse.MouseScroll)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1 EntityWithSelectedItem (io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem)1 ClientInputPressedEvent (io.xol.chunkstories.api.events.client.ClientInputPressedEvent)1 PlayerInputPressedEvent (io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)1 Layer (io.xol.chunkstories.api.gui.Layer)1 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)1 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)1 OptionBoolean (io.xol.chunkstories.api.util.Configuration.OptionBoolean)1 World (io.xol.chunkstories.api.world.World)1 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)1 ChatPanelOverlay (io.xol.chunkstories.gui.layer.ingame.ChatManager.ChatPanelOverlay)1 PacketInput (io.xol.chunkstories.net.packets.PacketInput)1 ClientParticlesRenderer (io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1