コード例 #1
0
  private void drawPageIndicator(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws a page indicator above the OK button. The filled in circle represents which
        //        page we're currently on.
      {
    int x1; // First x coordinate for drawing area.
    int y1; // First y coordinate for drawing area.
    int x2; // Second x coordinate for drawing area.
    int y2; // Second y coordinate for drawing area.
    int width; // Width of drawing area.
    int height; // Height of drawing area.
    int offset; // Offset between circles.
    Graphics2D g2; // Graphics2D to change brush stroke.

    x1 = ScaledPoint.scalerToX(0.275);
    x2 = ScaledPoint.scalerToX(0.325);
    y1 = ScaledPoint.scalerToY(0.85);
    y2 = ScaledPoint.scalerToY(0.89);

    width = (x2 - x1) / 2;
    height = y2 - y1;

    offset = ScaledPoint.scalerToX(0.005) / 2;

    g2 = (Graphics2D) g;

    g2.setColor(Color.WHITE);
    g2.setStroke(new BasicStroke(1));

    if (currentPage == 0) // if we are on the first page
    {
      g.fillOval(x1 - offset, y1, width, height);
      g.drawOval(x1 + width + offset, y1, width, height);
    } else // if we are on the second page.
    {
      g.drawOval(x1 - offset, y1, width, height);
      g.fillOval(x1 + width + offset, y1, width, height);
    }
  }
コード例 #2
0
  private void drawInventory(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the inventory of the store if mode == 0, else draws the players inventory.
        //        If an item is selected, its border is highlighted white.
      {
    Graphics2D g2; // Graphics 2D object to allow for different brush stroke widths.
    Color start; // The start color for the inventory window gradient.
    Color end; // The end color for the inventory window gradient.
    int x1; // Upper-left x coordinate.
    int y1; // Upper-left y coordinate.
    int x2; // Bottom-right x coordinate.
    int y2; // Bottom-right y coordinate.
    int width; // Width of the inventory box.
    int height; // Height of the inventory box.
    int itemHeight; // The height of an item box.
    int itemY; // The y coordinate of the item.
    Item currentItem; // Item to store the current item

    g2 = (Graphics2D) g;
    start = new Color(120, 120, 220);
    end = new Color(50, 50, 150);

    x1 = inventoryPos[0].getScaledX();
    y1 = inventoryPos[0].getScaledY();
    x2 = inventoryPos[1].getScaledX();
    y2 = inventoryPos[1].getScaledY();
    width = x2 - x1;
    height = y2 - y1;

    while (height % ITEMSPERPAGE != 0) // ensure that the item boxes do not fall short of the window
    {
      height = ++y2 - y1;
    }

    itemHeight = height / ITEMSPERPAGE;

    Drawing.drawGradient(g2, start, end, x1, y1, width, height / 2);
    Drawing.drawGradient(g2, end, start, x1, y1 + height / 2, width, height / 2);

    g2.setColor(Color.BLACK);
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(--x1, --y1, ++width, height);
    g2.setColor(Color.WHITE);

    switch (store) // Chooses the current store
    {
      case 0:
        connectItems(getUserItems("Weapon", orderToSort));
        break;
      case 1:
        connectItems(getUserItems("ArmorSmith", orderToSort));
        break;
      case 2:
        connectItems(getUserItems("Accessory", orderToSort));
        break;
      case 3:
        connectItems(getUserItems("General", orderToSort));
        break;
    }

    if (mode) // Sets mode to true for user inventory and displays
    {
      connectItems(getUserItems("Player", orderToSort));
    }

    int count = 0;
    // count = currentPage * ITEMSPERPAGE ;

    try // Try loading 10 items per page
    {

      currentItem = null;
      count = currentPage * ITEMSPERPAGE;
      for (int i = 0; i < ITEMSPERPAGE; i++) // draw each item into the window
      {
        if (i > itemsArray.length - 1) // Check if i excceds the array size
        {
          return;
        }
        itemY = y1 + (itemHeight) * i;

        currentItem = itemsArray[count];

        if (itemSelected == i) // if the item was selected, highlight it
        {
          g2.drawRect(x1, itemY, width, itemHeight);
        }

        drawItem(g2, i, currentItem);

        count++;
      }

    } catch (Exception e) // Catch generic exception and print it out
    {
      System.err.println(e.toString());
      System.err.println("Oh no, not like this...");
    }
  }