示例#1
1
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();

    mc.getTextureManager().bindTexture(skrivemaskinegui);

    this.drawTexturedModalRect(this.width / 2 - 128, this.height / 2 - 128, 0, 0, 256, 256);

    /* this is where the editor reads keys and writes to the screen */
    if (org.lwjgl.input.Keyboard.getEventKeyState()) {
      //
      if (isAllowedDeletion()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedNewLine()) {
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, '\n');
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedLeftArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (isAllowedRightArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
        text.deleteCharAt(cursorLocation);
        for (int i = 0; i < 3; i++) {
          text.insert(cursorLocation, " ");
          cursorLocation++;
        }
        text.insert(cursorLocation, cursor); // moving cursor

      } else {
        if (isAllowedCharacters()) {
          // System.out.println(org.lwjgl.input.Keyboard.getEventKey());
          text.deleteCharAt(cursorLocation);
          text.insert(cursorLocation, org.lwjgl.input.Keyboard.getEventCharacter());
          cursorLocation++;
          text.insert(cursorLocation, cursor); // moving cursor
        }
      }

      org.lwjgl.input.Keyboard.destroy();
    } else if (!org.lwjgl.input.Keyboard.isCreated()) {
      try {
        org.lwjgl.input.Keyboard.create();
      } catch (Exception e) {
      }
    }

    /* writes the text string to the screen */
    renderer.drawSplitString(
        text.toString(), this.width / 2 - 118, this.height / 2 - 119, 238, 0xFFFFF0);

    super.drawScreen(mouseX, mouseY, partialTicks);
  }
示例#2
0
 @Override
 public void close() {
   AL.destroy();
   Display.destroy();
   org.lwjgl.input.Mouse.destroy();
   org.lwjgl.input.Keyboard.destroy();
 }
示例#3
0
 public void shutdownMinecraftApplet() {
   try {
     statFileWriter.func_27175_b();
     statFileWriter.syncStats();
     if (mcApplet != null) {
       mcApplet.clearApplet();
     }
     try {
       if (downloadResourcesThread != null) {
         downloadResourcesThread.closeMinecraft();
       }
     } catch (Exception exception) {
     }
     System.out.println("Stopping!");
     try {
       changeWorld1(null);
     } catch (Throwable throwable) {
     }
     try {
       GLAllocation.deleteTexturesAndDisplayLists();
     } catch (Throwable throwable1) {
     }
     sndManager.closeMinecraft();
     Mouse.destroy();
     Keyboard.destroy();
   } finally {
     Display.destroy();
     if (!hasCrashed) {
       System.exit(0);
     }
   }
   System.gc();
 }
  private static void destroyWindow() {
    if (!window_created) {
      return;
    }
    if (parent != null) {
      parent.removeComponentListener(component_listener);
    }
    releaseDrawable();

    // Automatically destroy keyboard & mouse
    if (Mouse.isCreated()) {
      Mouse.destroy();
    }
    if (Keyboard.isCreated()) {
      Keyboard.destroy();
    }
    display_impl.destroyWindow();
    window_created = false;
  }
示例#5
0
 /** When Minecraft gains focus, reset all pressed keys to avoid the "stuck keys" bug. */
 private void unlockKeysIfNecessary() {
   boolean hasFocus = Display.isActive();
   if (!hadFocus && hasFocus) {
     Keyboard.destroy();
     boolean firstTry = true;
     while (!Keyboard.isCreated()) {
       try {
         Keyboard.create();
       } catch (LWJGLException e) {
         if (firstTry) {
           logInGameError("invtweaks.keyboardfix.error", e);
           firstTry = false;
         }
       }
     }
     if (!firstTry) {
       logInGame("invtweaks.keyboardfix.recover");
     }
   }
   hadFocus = hasFocus;
 }
  /**
   * *************************************************************************************************************************************************************************************************
   * Deinitialization and clean up.
   * ************************************************************************************************************************************************************************************************
   */
  private void deInit() {

    Keyboard.destroy();
    Display.destroy();
  }
示例#7
0
 public static void dispose() {
   Display.destroy();
   Mouse.destroy();
   Keyboard.destroy();
 }
示例#8
0
  public void run(Map<String, String> parameters) {
    DisplayManager.create();
    DisplayManager displayManager = DisplayManager.getInstance();
    displayManager.setWindowTitle(TITLE);
    ObjectObserver objectObserver = new ObjectObserverMoteJ();
    WindowManager windowManager = null;

    try {
      for (DisplayMode mode : displayManager.getAvailableDisplayModes()) {
        log.info(mode.getWidth() + "x" + mode.getHeight() + ":" + mode.getBitsPerPixel());
      }
      displayMode = displayManager.getDisplayMode(800, 600, 32);
      displayManager.createDisplay(displayMode);
      Keyboard.create();

      objectObserver.initialize(parameters);

      WindowManager.create(displayManager, objectObserver);
      windowManager = WindowManager.getInstance();
      windowManager.getWindowManagerCalibrator().addWindowManagerCalibratorListener(this);

      FrameMeter frameMeter = new FrameMeter();
      calibrationRequested = true;
      isCalibrated = false;
      isRunning = true;
      while (isRunning) {
        if (Display.isCloseRequested()) {
          break;
        }

        while (Keyboard.next()) {
          if (Keyboard.getEventKey() == Keyboard.KEY_F) {
            if (Keyboard.getEventKeyState()) {
              displayManager.setFullScreen(!displayManager.isFullScreen());
            }
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
            isRunning = false;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_C) {
            calibrationRequested = true;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_UP) {
            ballSpeed += 0.1f;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
            ballSpeed -= 0.1f;
          }
        }

        if (calibrationRequested) {
          windowManager.calibrate();
          calibrationRequested = false;
          isCalibrated = false;
        } else if (isCalibrated) {
          windowManager.setCursorCollection(new CursorCollectionDefault());

          log.info("Loading images...");
          loadImages();
          isCalibrated = false;

          gameState = GameState.Ready;
        }

        if (frameMeter.update()) {
          displayManager.setWindowTitle(TITLE + " - " + frameMeter.getFps() + " fps");
        }

        // game state
        if (gameState != null) {
          if (gameState.equals(GameState.Ready)) {
            onGameStateReady();
          } else if (gameState.equals(GameState.Start)) {
            onGameStateStart();
          } else if (gameState.equals(GameState.Playing)) {
            onGameStatePlaying();
          } else if (gameState.equals(GameState.End)) {
            onGameStateEnd();
          }
        }

        windowManager.update();
        Thread.sleep(30);
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        if (windowManager != null) {
          windowManager.destroy();
        }
        Keyboard.destroy();
        displayManager.destroy();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    }
  }