コード例 #1
0
ファイル: GuiAtlas.java プロジェクト: Dark32/AntiqueAtlas
 @Override
 public void initGui() {
   super.initGui();
   state.switchTo(
       NORMAL); // TODO: his causes the Export PNG progress bar to disappear when resizing game
                // window
   Keyboard.enableRepeatEvents(true);
   screenScale = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight).getScaleFactor();
   setCentered();
 }
コード例 #2
0
ファイル: GuiAtlas.java プロジェクト: Dark32/AntiqueAtlas
 /**
  * Opens a dialog window to select which file to save to, then performs rendering of the map of
  * current dimension into a PNG image.
  */
 private void exportImage(ItemStack stack) {
   boolean showMarkers = !state.is(HIDING_MARKERS);
   state.switchTo(EXPORTING_IMAGE);
   // Default file name is "Atlas <N>.png"
   File file = ExportImageUtil.selectPngFileToSave("Atlas " + stack.getItemDamage(), progressBar);
   if (file != null) {
     try {
       Log.info(
           "Exporting image from Atlas #%d to file %s",
           stack.getItemDamage(), file.getAbsolutePath());
       ExportImageUtil.exportPngImage(
           biomeData, globalMarkersData, localMarkersData, file, progressBar, showMarkers);
       Log.info("Finished exporting image");
     } catch (OutOfMemoryError e) {
       Log.error(e, "Image is too large");
       progressBar.setStatusString(I18n.format("gui.antiqueatlas.export.tooLarge"));
       return; // Don't switch to normal state yet so that the error message can be read.
     }
   }
   state.switchTo(showMarkers ? NORMAL : HIDING_MARKERS);
 }
コード例 #3
0
ファイル: GuiAtlas.java プロジェクト: Dark32/AntiqueAtlas
 private void renderMarker(Marker marker, double scale) {
   int markerX = worldXToScreenX(marker.getX());
   int markerY = worldZToScreenY(marker.getZ());
   if (!marker.isVisibleAhead() && !biomeData.hasTileAt(marker.getChunkX(), marker.getChunkZ())) {
     return;
   }
   boolean mouseIsOverMarker =
       isMouseInRadius(markerX, markerY, (int) Math.ceil(MARKER_RADIUS * scale));
   if (state.is(PLACING_MARKER)) {
     GL11.glColor4f(1, 1, 1, 0.5f);
   } else if (state.is(DELETING_MARKER)) {
     if (marker.isGlobal()) {
       GL11.glColor4f(1, 1, 1, 0.5f);
     } else {
       if (mouseIsOverMarker) {
         GL11.glColor4f(0.5f, 0.5f, 0.5f, 1);
         toDelete = marker;
       } else {
         GL11.glColor4f(1, 1, 1, 1);
         if (toDelete == marker) {
           toDelete = null;
         }
       }
     }
   } else {
     GL11.glColor4f(1, 1, 1, 1);
   }
   AtlasRenderHelper.drawFullTexture(
       MarkerTextureMap.instance().getTexture(marker.getType()),
       markerX - (double) MARKER_SIZE / 2 * scale,
       markerY - (double) MARKER_SIZE / 2 * scale,
       (int) Math.round(MARKER_SIZE * scale),
       (int) Math.round(MARKER_SIZE * scale));
   if (isMouseOver && mouseIsOverMarker && marker.getLabel().length() > 0) {
     drawTooltip(Arrays.asList(marker.getLocalizedLabel()), mc.fontRenderer);
   }
 }
コード例 #4
0
ファイル: GuiAtlas.java プロジェクト: Dark32/AntiqueAtlas
  @Override
  protected void mouseClicked(int mouseX, int mouseY, int mouseState) {
    super.mouseClicked(mouseX, mouseY, mouseState);
    if (state.is(EXPORTING_IMAGE)) {
      return; // Don't remove the progress bar.
    }

    // If clicked on the map, start dragging
    int mapX = (width - MAP_WIDTH) / 2;
    int mapY = (height - MAP_HEIGHT) / 2;
    boolean isMouseOverMap =
        mouseX >= mapX
            && mouseX <= mapX + MAP_WIDTH
            && mouseY >= mapY
            && mouseY <= mapY + MAP_HEIGHT;
    if (!state.is(NORMAL) && !state.is(HIDING_MARKERS)) {
      if (state.is(PLACING_MARKER) // If clicked on the map, place marker:
          && isMouseOverMap
          && mouseState == 0 /* left click */) {
        markerFinalizer.setMarkerData(
            player.worldObj,
            stack.getItemDamage(),
            player.dimension,
            screenXToWorldX(mouseX),
            screenYToWorldZ(mouseY));
        addChild(markerFinalizer);

        blinkingIcon.setTexture(
            MarkerTextureMap.instance().getTexture(markerFinalizer.selectedType),
            MARKER_SIZE,
            MARKER_SIZE);
        addChildBehind(markerFinalizer, blinkingIcon)
            .setRelativeCoords(
                mouseX - getGuiX() - MARKER_SIZE / 2, mouseY - getGuiY() - MARKER_SIZE / 2);

        // Need to intercept keyboard events to type in the label:
        setInterceptKeyboard(true);

        // Un-press all keys to prevent player from walking infinitely:
        KeyBinding.unPressAllKeys();

      } else if (state.is(DELETING_MARKER) // If clicked on a marker, delete it:
          && toDelete != null
          && isMouseOverMap
          && mouseState == 0) {
        AtlasAPI.getMarkerAPI()
            .deleteMarker(player.worldObj, stack.getItemDamage(), toDelete.getId());
      }
      state.switchTo(NORMAL);
    } else if (isMouseOverMap && selectedButton == null) {
      isDragging = true;
      dragMouseX = mouseX;
      dragMouseY = mouseY;
      dragMapOffsetX = mapOffsetX;
      dragMapOffsetY = mapOffsetY;
    }
  }
コード例 #5
0
ファイル: GuiAtlas.java プロジェクト: Dark32/AntiqueAtlas
  @Override
  public void drawScreen(int mouseX, int mouseY, float par3) {
    if (DEBUG_RENDERING) {
      renderTimes[renderTimesIndex++] = System.currentTimeMillis();
      if (renderTimesIndex == renderTimes.length) {
        renderTimesIndex = 0;
        double elapsed = 0;
        for (int i = 0; i < renderTimes.length - 1; i++) {
          elapsed += renderTimes[i + 1] - renderTimes[i];
        }
        System.out.printf("GuiAtlas avg. render time: %.3f\n", elapsed / renderTimes.length);
      }
    }

    GL11.glColor4f(1, 1, 1, 1);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0); // So light detail on tiles is visible
    AtlasRenderHelper.drawFullTexture(Textures.BOOK, getGuiX(), getGuiY(), WIDTH, HEIGHT);

    if (stack == null || biomeData == null) return;

    if (state.is(DELETING_MARKER)) {
      GL11.glColor4f(1, 1, 1, 0.5f);
    }
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(
        (getGuiX() + CONTENT_X) * screenScale,
        mc.displayHeight - (getGuiY() + CONTENT_Y + MAP_HEIGHT) * screenScale,
        MAP_WIDTH * screenScale,
        MAP_HEIGHT * screenScale);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    // Find chunk coordinates of the top left corner of the map.
    // The 'roundToBase' is required so that when the map scales below the
    // threshold the tiles don't change when map position changes slightly.
    // The +-2 at the end provide margin so that tiles at the edges of
    // the page have their stitched texture correct.
    int mapStartX =
        MathUtil.roundToBase(
            (int)
                Math.floor(
                    -((double) MAP_WIDTH / 2d + mapOffsetX + 2 * tileHalfSize) / mapScale / 16d),
            tile2ChunkScale);
    int mapStartZ =
        MathUtil.roundToBase(
            (int)
                Math.floor(
                    -((double) MAP_HEIGHT / 2d + mapOffsetY + 2 * tileHalfSize) / mapScale / 16d),
            tile2ChunkScale);
    int mapEndX =
        MathUtil.roundToBase(
            (int)
                Math.ceil(
                    ((double) MAP_WIDTH / 2d - mapOffsetX + 2 * tileHalfSize) / mapScale / 16d),
            tile2ChunkScale);
    int mapEndZ =
        MathUtil.roundToBase(
            (int)
                Math.ceil(
                    ((double) MAP_HEIGHT / 2d - mapOffsetY + 2 * tileHalfSize) / mapScale / 16d),
            tile2ChunkScale);
    int mapStartScreenX = getGuiX() + WIDTH / 2 + (int) ((mapStartX << 4) * mapScale) + mapOffsetX;
    int mapStartScreenY = getGuiY() + HEIGHT / 2 + (int) ((mapStartZ << 4) * mapScale) + mapOffsetY;

    TileRenderIterator iter = new TileRenderIterator(biomeData);
    iter.setScope(
        new Rect().setOrigin(mapStartX, mapStartZ).set(mapStartX, mapStartZ, mapEndX, mapEndZ));
    iter.setStep(tile2ChunkScale);
    while (iter.hasNext()) {
      SubTileQuartet subtiles = iter.next();
      for (SubTile subtile : subtiles) {
        if (subtile == null || subtile.tile == null) continue;
        AtlasRenderHelper.drawAutotileCorner(
            BiomeTextureMap.instance().getTexture(subtile.tile),
            mapStartScreenX + subtile.x * tileHalfSize,
            mapStartScreenY + subtile.y * tileHalfSize,
            subtile.getTextureU(),
            subtile.getTextureV(),
            tileHalfSize);
      }
    }

    if (!state.is(HIDING_MARKERS)) {
      int markersStartX =
          MathUtil.roundToBase(mapStartX, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP - 1;
      int markersStartZ =
          MathUtil.roundToBase(mapStartZ, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP - 1;
      int markersEndX =
          MathUtil.roundToBase(mapEndX, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP + 1;
      int markersEndZ =
          MathUtil.roundToBase(mapEndZ, MarkersData.CHUNK_STEP) / MarkersData.CHUNK_STEP + 1;
      double iconScale = getIconScale();

      // Draw global markers:
      for (int x = markersStartX; x <= markersEndX; x++) {
        for (int z = markersStartZ; z <= markersEndZ; z++) {
          List<Marker> markers = globalMarkersData.getMarkersAtChunk(x, z);
          if (markers == null) continue;
          for (Marker marker : markers) {
            renderMarker(marker, iconScale);
          }
        }
      }

      // Draw local markers:
      if (localMarkersData != null) {
        for (int x = markersStartX; x <= markersEndX; x++) {
          for (int z = markersStartZ; z <= markersEndZ; z++) {
            List<Marker> markers = localMarkersData.getMarkersAtChunk(x, z);
            if (markers == null) continue;
            for (Marker marker : markers) {
              renderMarker(marker, iconScale);
            }
          }
        }
      }
    }

    GL11.glDisable(GL11.GL_SCISSOR_TEST);

    // Overlay the frame so that edges of the map are smooth:
    GL11.glColor4f(1, 1, 1, 1);
    AtlasRenderHelper.drawFullTexture(Textures.BOOK_FRAME, getGuiX(), getGuiY(), WIDTH, HEIGHT);
    double iconScale = getIconScale();

    // Draw player icon:
    if (!state.is(HIDING_MARKERS)) {
      // How much the player has moved from the top left corner of the map, in pixels:
      int playerOffsetX = (int) (player.posX * mapScale) + mapOffsetX;
      int playerOffsetZ = (int) (player.posZ * mapScale) + mapOffsetY;
      if (playerOffsetX < -MAP_WIDTH / 2) playerOffsetX = -MAP_WIDTH / 2;
      if (playerOffsetX > MAP_WIDTH / 2) playerOffsetX = MAP_WIDTH / 2;
      if (playerOffsetZ < -MAP_HEIGHT / 2) playerOffsetZ = -MAP_HEIGHT / 2;
      if (playerOffsetZ > MAP_HEIGHT / 2 - 2) playerOffsetZ = MAP_HEIGHT / 2 - 2;
      // Draw the icon:
      GL11.glColor4f(1, 1, 1, state.is(PLACING_MARKER) ? 0.5f : 1);
      GL11.glPushMatrix();
      GL11.glTranslated(
          getGuiX() + WIDTH / 2 + playerOffsetX, getGuiY() + HEIGHT / 2 + playerOffsetZ, 0);
      float playerRotation =
          (float) Math.round(player.rotationYaw / 360f * PLAYER_ROTATION_STEPS)
              / PLAYER_ROTATION_STEPS
              * 360f;
      GL11.glRotatef(180 + playerRotation, 0, 0, 1);
      GL11.glTranslated(-PLAYER_ICON_WIDTH / 2 * iconScale, -PLAYER_ICON_HEIGHT / 2 * iconScale, 0);
      AtlasRenderHelper.drawFullTexture(
          Textures.PLAYER,
          0,
          0,
          (int) Math.round(PLAYER_ICON_WIDTH * iconScale),
          (int) Math.round(PLAYER_ICON_HEIGHT * iconScale));
      GL11.glPopMatrix();
      GL11.glColor4f(1, 1, 1, 1);
    }

    // Draw buttons:
    super.drawScreen(mouseX, mouseY, par3);

    // Draw the semi-transparent marker attached to the cursor when placing a new marker:
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    if (state.is(PLACING_MARKER)) {
      GL11.glColor4f(1, 1, 1, 0.5f);
      AtlasRenderHelper.drawFullTexture(
          MarkerTextureMap.instance().getTexture(markerFinalizer.selectedType),
          mouseX - MARKER_SIZE / 2 * iconScale,
          mouseY - MARKER_SIZE / 2 * iconScale,
          (int) Math.round(MARKER_SIZE * iconScale),
          (int) Math.round(MARKER_SIZE * iconScale));
      GL11.glColor4f(1, 1, 1, 1);
    }

    // Draw progress overlay:
    if (state.is(EXPORTING_IMAGE)) {
      drawDefaultBackground();
      progressBar.draw((width - 100) / 2, height / 2 - 34);
    }
  }