Esempio n. 1
0
  /** To be called every time the sorting key is pressed. Sorts the inventory. */
  public final void onSortingKeyPressed() {
    synchronized (this) {

      // Check config loading success
      if (!cfgManager.makeSureConfigurationIsLoaded()) {
        return;
      }

      // Check current GUI
      apn guiScreen = getCurrentScreen();
      if (guiScreen == null || (isValidChest(guiScreen) || isValidInventory(guiScreen))) {
        // Sorting!
        handleSorting(guiScreen);
      }
    }
  }
Esempio n. 2
0
  private void handleMiddleClick(apn guiScreen) {

    if (Mouse.isButtonDown(2)) {

      if (!cfgManager.makeSureConfigurationIsLoaded()) {
        return;
      }
      InvTweaksConfig config = cfgManager.getConfig();

      // Check that middle click sorting is allowed
      if (config
          .getProperty(InvTweaksConfig.PROP_ENABLE_MIDDLE_CLICK)
          .equals(InvTweaksConfig.VALUE_TRUE)) {

        if (!chestAlgorithmButtonDown) {
          chestAlgorithmButtonDown = true;

          InvTweaksContainerManager containerMgr = new InvTweaksContainerManager(mc);
          pr slotAtMousePosition = containerMgr.getSlotAtMousePosition();
          InvTweaksContainerSection target = null;
          if (slotAtMousePosition != null) {
            target = containerMgr.getSlotSection(getSlotNumber(slotAtMousePosition));
          }

          if (isValidChest(guiScreen)) {

            // Check if the middle click target the chest or the inventory
            // (copied GuiContainer.getSlotAtPosition algorithm)
            aqh guiContainer = asGuiContainer(guiScreen);

            if (InvTweaksContainerSection.CHEST.equals(target)) {

              // Play click
              playClick();

              long timestamp = System.currentTimeMillis();
              if (timestamp - chestAlgorithmClickTimestamp
                  > InvTweaksConst.CHEST_ALGORITHM_SWAP_MAX_INTERVAL) {
                chestAlgorithm = InvTweaksHandlerSorting.ALGORITHM_DEFAULT;
              }
              try {
                new InvTweaksHandlerSorting(
                        mc,
                        cfgManager.getConfig(),
                        InvTweaksContainerSection.CHEST,
                        chestAlgorithm,
                        getContainerRowSize(guiContainer))
                    .sort();
              } catch (Exception e) {
                logInGameError("invtweaks.sort.chest.error", e);
                e.printStackTrace();
              }
              chestAlgorithm = (chestAlgorithm + 1) % 3;
              chestAlgorithmClickTimestamp = timestamp;

            } else if (InvTweaksContainerSection.INVENTORY_HOTBAR.equals(target)
                || (InvTweaksContainerSection.INVENTORY_NOT_HOTBAR.equals(target))) {
              handleSorting(guiScreen);
            }

          } else if (isValidInventory(guiScreen)) {

            /*
                         	 // Crafting stacks evening (hook ready, TODO implement algorithm)
                         	 if (InvTweaksContainerSection.CRAFTING_IN.equals(target)) {
                                 try {
            	new InvTweaksHandlerSorting(mc, cfgManager.getConfig(),
            	        InvTweaksContainerSection.CRAFTING_IN,
            	        InvTweaksHandlerSorting.ALGORITHM_EVEN_STACKS,
            	        (containerMgr.getSize(target) == 9) ? 3 : 2).sort();
            } catch (Exception e) {
                                     logInGameError("invtweaks.sort.crafting.error", e);
                                     e.printStackTrace();
            }
                             }*/

            handleSorting(guiScreen);
          }
        }
      }
    } else {
      chestAlgorithmButtonDown = false;
    }
  }
Esempio n. 3
0
  private void handleConfigSwitch() {

    InvTweaksConfig config = cfgManager.getConfig();
    apn currentScreen = getCurrentScreen();

    // Switch between configurations (shortcut)
    InvTweaksShortcutMapping switchMapping =
        cfgManager
            .getShortcutsHandler()
            .isShortcutDown(InvTweaksShortcutType.MOVE_TO_SPECIFIC_HOTBAR_SLOT);
    if (isSortingShortcutDown() && switchMapping != null) {
      String newRuleset = null;
      int pressedKey = switchMapping.getKeyCodes().get(0);
      if (pressedKey >= Keyboard.KEY_1 && pressedKey <= Keyboard.KEY_9) {
        newRuleset = config.switchConfig(pressedKey - Keyboard.KEY_1);
      } else {
        switch (pressedKey) {
          case Keyboard.KEY_NUMPAD1:
            newRuleset = config.switchConfig(0);
            break;
          case Keyboard.KEY_NUMPAD2:
            newRuleset = config.switchConfig(1);
            break;
          case Keyboard.KEY_NUMPAD3:
            newRuleset = config.switchConfig(2);
            break;
          case Keyboard.KEY_NUMPAD4:
            newRuleset = config.switchConfig(3);
            break;
          case Keyboard.KEY_NUMPAD5:
            newRuleset = config.switchConfig(4);
            break;
          case Keyboard.KEY_NUMPAD6:
            newRuleset = config.switchConfig(5);
            break;
          case Keyboard.KEY_NUMPAD7:
            newRuleset = config.switchConfig(6);
            break;
          case Keyboard.KEY_NUMPAD8:
            newRuleset = config.switchConfig(7);
            break;
          case Keyboard.KEY_NUMPAD9:
            newRuleset = config.switchConfig(8);
            break;
        }
      }

      if (newRuleset != null) {
        logInGame(
            String.format(InvTweaksLocalization.get("invtweaks.loadconfig.enabled"), newRuleset),
            true);
        // Hack to prevent 2nd way to switch configs from being enabled
        sortingKeyPressedDate = Integer.MAX_VALUE;
      }
    }

    // Switch between configurations (by holding the sorting key)
    if (isSortingShortcutDown()) {
      long currentTime = System.currentTimeMillis();
      if (sortingKeyPressedDate == 0) {
        sortingKeyPressedDate = currentTime;
      } else if (currentTime - sortingKeyPressedDate > InvTweaksConst.RULESET_SWAP_DELAY
          && sortingKeyPressedDate != Integer.MAX_VALUE) {
        String previousRuleset = config.getCurrentRulesetName();
        String newRuleset = config.switchConfig();
        // Log only if there is more than 1 ruleset
        if (previousRuleset != null && newRuleset != null && !previousRuleset.equals(newRuleset)) {
          logInGame(
              String.format(InvTweaksLocalization.get("invtweaks.loadconfig.enabled"), newRuleset),
              true);
          handleSorting(currentScreen);
        }
        sortingKeyPressedDate = currentTime;
      }
    } else {
      sortingKeyPressedDate = 0;
    }
  }